@bildvitta/quasar-ui-asteroid 3.13.0-beta.5 → 3.13.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.13.0-beta.5",
4
+ "version": "3.13.0-beta.6",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "dist/asteroid.cjs.min.js",
@@ -20,7 +20,21 @@
20
20
  <slot name="image">
21
21
  <q-img class="rounded-borders" height="100%" :src="card.url" v-bind="imageProps">
22
22
  <template #error>
23
- <slot name="image-error" />
23
+ <div :class="errorClasses">
24
+ <div class="text-center">
25
+ <slot name="image-error-icon">
26
+ <div v-if="errorIcon">
27
+ <q-icon :name="errorIcon" size="sm" />
28
+ </div>
29
+ </slot>
30
+
31
+ <slot name="image-error">
32
+ <div>
33
+ {{ errorMessage }}
34
+ </div>
35
+ </slot>
36
+ </div>
37
+ </div>
24
38
  </template>
25
39
  </q-img>
26
40
  </slot>
@@ -53,6 +67,16 @@ export default {
53
67
  type: Boolean
54
68
  },
55
69
 
70
+ errorIcon: {
71
+ type: String,
72
+ default: ''
73
+ },
74
+
75
+ errorMessage: {
76
+ type: String,
77
+ default: ''
78
+ },
79
+
56
80
  gridGeneratorProps: {
57
81
  type: Object,
58
82
  default: () => ({})
@@ -108,6 +132,19 @@ export default {
108
132
  'text-grey-9': !this.disable,
109
133
  'q-mb-md': this.hasActions || this.card.name
110
134
  }
135
+ },
136
+
137
+ errorClasses () {
138
+ return [
139
+ 'bg-grey-4',
140
+ 'flex',
141
+ 'full-height',
142
+ 'full-width',
143
+ 'items-center',
144
+ 'justify-center',
145
+ 'text-grey-9',
146
+ 'text-subtitle2'
147
+ ]
111
148
  }
112
149
  }
113
150
  }
@@ -9,6 +9,16 @@ props:
9
9
  default: {}
10
10
  type: Object
11
11
 
12
+ error-icon:
13
+ desc: Ícone que aparecerá quando uma imagem falhar ao carregar.
14
+ default: ''
15
+ type: String
16
+
17
+ error-message:
18
+ desc: Texto que aparecerá quando uma imagem falhar ao carregar.
19
+ default: ''
20
+ type: String
21
+
12
22
  card:
13
23
  desc: Informações do card, como name (nome) e url.
14
24
  default: {}
@@ -41,6 +51,9 @@ slots:
41
51
  image-error:
42
52
  desc: Slot para acessar o conteúdo da imagem quando existe algum erro com a imagem.
43
53
 
54
+ image-error-icon:
55
+ desc: Slot para acessar o conteúdo de ícone quando existe algum erro com a imagem.
56
+
44
57
  header:
45
58
  desc: Slot para acessar o conteúdo do cabeçalho.
46
59
 
@@ -116,7 +116,7 @@ export default {
116
116
  },
117
117
 
118
118
  galleryCardProps: {
119
- type: Object,
119
+ type: [Object, Function],
120
120
  default: () => ({})
121
121
  },
122
122
 
@@ -1,28 +1,6 @@
1
1
  <template>
2
2
  <div>
3
3
  <qas-gallery-card v-bind="defaultGalleryCardProps">
4
- <!-- este template é para quando existe um erro carregar uma imagem de um arquivo como PDF, DOCX. -->
5
- <template #image-error>
6
- <div class="text-uppercase" :class="errorClasses">
7
- {{ fileType }}
8
- </div>
9
- </template>
10
-
11
- <!-- este template é para quando existe um erro ao fazer um UPLOAD! -->
12
- <template v-if="hasError" #image>
13
- <div :class="errorClasses">
14
- <div class="q-pa-sm text-center">
15
- <div>
16
- <q-icon name="sym_r_cancel" size="sm" />
17
- </div>
18
-
19
- <div class="q-mt-sm">
20
- Falha ao carregar arquivo.
21
- </div>
22
- </div>
23
- </div>
24
- </template>
25
-
26
4
  <template v-if="hasGenerator" #bottom>
27
5
  <div>
28
6
  <qas-grid-generator v-if="hasGridGenerator" v-bind="defaultGridGeneratorProps" />
@@ -80,7 +58,7 @@ export default {
80
58
  },
81
59
 
82
60
  galleryCardProps: {
83
- type: Object,
61
+ type: [Object, Function],
84
62
  default: () => ({})
85
63
  },
86
64
 
@@ -112,7 +90,8 @@ export default {
112
90
  data () {
113
91
  return {
114
92
  dialogValues: {},
115
- showDialog: false
93
+ showDialog: false,
94
+ hasErrorOnUploadedFile: false
116
95
  }
117
96
  },
118
97
 
@@ -136,21 +115,67 @@ export default {
136
115
  }
137
116
  },
138
117
 
118
+ normalizedCardGalleryProps () {
119
+ const isFunction = typeof this.galleryCardProps === 'function'
120
+
121
+ const functionPayload = {
122
+ hasError: this.hasErrorOnUploadedFile,
123
+ file: this.file
124
+ }
125
+
126
+ return (isFunction ? this.galleryCardProps(functionPayload) : this.galleryCardProps) || {}
127
+ },
128
+
139
129
  defaultGalleryCardProps () {
140
- const { list, buttonProps, ...actionsMenuProps } = this.galleryCardProps.actionsMenuProps || {}
130
+ const {
131
+ list,
132
+ imageProps,
133
+
134
+ buttonProps: btnProps,
135
+ errorMessage: error,
136
+ errorIcon: icon,
137
+
138
+ ...actionsMenuProps
139
+ } = this.normalizedCardGalleryProps
140
+
141
+ /**
142
+ * Quando hasError for "true", significa que é falha ao enviar o arquivo ao servidor (upload), e nestes casos:
143
+ *
144
+ * buttonProps: deve sempre ser possível excluir a imagem, por isso o disable do botão é "false".
145
+ * errorMessage: o label do erro deve ser "Falha ao carregar arquivo."
146
+ * errorIcon: o ícone do erro deve ser "sym_r_cancel".
147
+ */
148
+ const buttonProps = this.hasError ? { ...btnProps, disable: false } : btnProps
149
+ const errorMessage = this.hasError ? 'Falha ao carregar arquivo.' : error || this.fileType
150
+ const errorIcon = this.hasError ? 'sym_r_cancel' : icon
141
151
 
142
152
  return {
143
- ...this.galleryCardProps,
144
153
  disable: this.hasError,
145
154
 
155
+ ...this.normalizedCardGalleryProps,
156
+
157
+ errorIcon,
158
+ errorMessage,
159
+
160
+ imageProps: {
161
+ ...imageProps,
162
+
163
+ // callback para sinalizar que houve erro em arquivos já upados.
164
+ onError: () => {
165
+ this.hasErrorOnUploadedFile = true
166
+
167
+ this.galleryCardProps.imageProps?.onError?.()
168
+ }
169
+ },
170
+
146
171
  actionsMenuProps: {
172
+ ...actionsMenuProps,
173
+
147
174
  buttonProps: {
148
175
  disable: false,
149
176
  ...buttonProps
150
177
  },
151
178
 
152
- ...actionsMenuProps,
153
-
154
179
  list: {
155
180
  ...(
156
181
  this.hasEditButton &&
@@ -216,21 +241,8 @@ export default {
216
241
  }
217
242
  },
218
243
 
219
- errorClasses () {
220
- return [
221
- 'bg-grey-4',
222
- 'flex',
223
- 'full-height',
224
- 'full-width',
225
- 'items-center',
226
- 'justify-center',
227
- 'text-grey-9',
228
- 'text-subtitle2'
229
- ]
230
- },
231
-
232
244
  fileName () {
233
- return this.url.split('/').pop()
245
+ return this.url ? this.url.split('/').pop() : ''
234
246
  },
235
247
 
236
248
  fileType () {
@@ -259,6 +271,7 @@ export default {
259
271
 
260
272
  hasFormFields () {
261
273
  const { fields } = this.defaultFormGeneratorProps
274
+
262
275
  return !!Object.keys(fields).length
263
276
  },
264
277
 
@@ -288,7 +301,19 @@ export default {
288
301
  },
289
302
 
290
303
  normalizedModelValue () {
291
- return this.useObjectModel && !this.hasError ? this.currentModelValue : this.file
304
+ return (
305
+ this.useObjectModel && !this.hasError
306
+ ? this.currentModelValue
307
+
308
+ /**
309
+ * Quando da erro ao enviar, a url não é enviada no model, desta forma para aparecer a imagem
310
+ * de "Falha ao enviar arquivo." é necessário que a "url" exista, então é criada uma url fake.
311
+ *
312
+ * Obs: esta URL fake é usada apenas para aparecer a imagem de "Falha ao enviar arquivo."
313
+ * e não é adicionada ao model.
314
+ */
315
+ : { url: this.url || 'error-on-upload-file', ...this.file }
316
+ )
292
317
  },
293
318
 
294
319
  url () {