@bildvitta/quasar-ui-asteroid 3.0.0-beta.13 → 3.0.0-beta.16

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.
@@ -355,6 +355,14 @@
355
355
  "description": "Altera ordem dos campos.",
356
356
  "type": "array"
357
357
  },
358
+ "qas-form-view/before-fetch": {
359
+ "description": "Callback para controlar como funciona o comportamento do fetch.",
360
+ "type": "function"
361
+ },
362
+ "qas-form-view/before-submit": {
363
+ "description": "Callback para controlar como funciona o comportamento do submit.",
364
+ "type": "function"
365
+ },
358
366
  "qas-form-view/cancel-button-label": {
359
367
  "description": "Rótulo do botão \"cancelar\".",
360
368
  "type": "string"
@@ -567,6 +575,10 @@
567
575
  "description": "Controla se exibe ou não seção de actions, onde fica o Ícone de redirecionamento.",
568
576
  "type": "boolean"
569
577
  },
578
+ "qas-list-view/before-fetch": {
579
+ "description": "Callback para controlar como funciona o comportamento do fetchList.",
580
+ "type": "function"
581
+ },
570
582
  "qas-list-view/entity": {
571
583
  "description": "Entidade da store, por exemplo se tiver que trabalhar com modulo de usuários, teremos o model \"users\" na store, que vai ser nossa \"entity\".",
572
584
  "type": "string"
@@ -611,6 +623,10 @@
611
623
  "description": "Controla o [pull-to-refresh](https://quasar.dev/vue-components/pull-to-refresh#basic).",
612
624
  "type": "boolean"
613
625
  },
626
+ "qas-list-view/use-results-area-only": {
627
+ "description": "Controla se irá sempre ser exibido os resultados independente se não há nenhum resultado a ser exibido.",
628
+ "type": "boolean"
629
+ },
614
630
  "qas-map/center-position": {
615
631
  "description": "Opções de localização onde o mapa vai ser centralizado.",
616
632
  "type": "object"
@@ -663,6 +679,10 @@
663
679
  "description": "Espaçamento entre cada campo.",
664
680
  "type": "string"
665
681
  },
682
+ "qas-nested-fields/identifier-item-key": {
683
+ "description": "Define um identificador para o item. O identificador será utilizado para validar exclusão do item, por exemplo.",
684
+ "type": "string"
685
+ },
666
686
  "qas-nested-fields/model-value": {
667
687
  "description": "Model do componente",
668
688
  "type": "array"
@@ -991,6 +1011,10 @@
991
1011
  "description": "Rótulo do uploader.",
992
1012
  "type": "string"
993
1013
  },
1014
+ "qas-single-view/before-fetch": {
1015
+ "description": "Callback para controlar como funciona o comportamento do fetchSingle.",
1016
+ "type": "function"
1017
+ },
994
1018
  "qas-single-view/custom-id": {
995
1019
  "description": "Por padrão, o componente vai pegar o \"id\" que vem como parâmetro na url, caso queira que o id seja diferente da url, use esta prop.",
996
1020
  "type": "string"
@@ -189,6 +189,8 @@
189
189
  },
190
190
  "qas-form-view": {
191
191
  "attributes": [
192
+ "before-fetch",
193
+ "before-submit",
192
194
  "cancel-button-label",
193
195
  "cancel-route",
194
196
  "custom-id",
@@ -277,6 +279,7 @@
277
279
  },
278
280
  "qas-list-view": {
279
281
  "attributes": [
282
+ "before-fetch",
280
283
  "entity",
281
284
  "errors",
282
285
  "fetching",
@@ -287,7 +290,8 @@
287
290
  "url",
288
291
  "use-boundary",
289
292
  "use-filter",
290
- "use-refresh"
293
+ "use-refresh",
294
+ "use-results-area-only"
291
295
  ],
292
296
  "description": "Componente para C.R.U.D. responsável pela parte de listagem (Read)."
293
297
  },
@@ -311,6 +315,7 @@
311
315
  "fields-props",
312
316
  "form-columns",
313
317
  "form-gutter",
318
+ "identifier-item-key",
314
319
  "model-value",
315
320
  "row-label",
316
321
  "row-object",
@@ -453,6 +458,7 @@
453
458
  },
454
459
  "qas-single-view": {
455
460
  "attributes": [
461
+ "before-fetch",
456
462
  "custom-id",
457
463
  "entity",
458
464
  "errors",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.0.0-beta.13",
4
+ "version": "3.0.0-beta.16",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "dist/asteroid.cjs.min.js",
@@ -4,7 +4,7 @@
4
4
  <slot name="header" />
5
5
  </header>
6
6
 
7
- <q-form ref="form" @submit="submit">
7
+ <q-form ref="form" @submit="submitHandler">
8
8
  <slot />
9
9
 
10
10
  <slot v-if="useActions" name="actions">
@@ -122,6 +122,11 @@ export default {
122
122
  useSubmitButton: {
123
123
  default: true,
124
124
  type: Boolean
125
+ },
126
+
127
+ beforeSubmit: {
128
+ default: null,
129
+ type: Function
125
130
  }
126
131
  },
127
132
 
@@ -215,7 +220,7 @@ export default {
215
220
 
216
221
  window.addEventListener('delete-success', this.setIgnoreRouterGuard)
217
222
 
218
- this.fetch()
223
+ this.mx_fetchHandler({ form: true, id: this.id, url: this.fetchURL }, this.fetch)
219
224
  },
220
225
 
221
226
  onUnmounted () {
@@ -350,6 +355,7 @@ export default {
350
355
  const { addRoute } = useHistory()
351
356
 
352
357
  this.defaultDialogProps.ok.onClick = () => addRoute(this.$route)
358
+
353
359
  this.defaultDialogProps.cancel.onClick = next
354
360
  },
355
361
 
@@ -369,17 +375,35 @@ export default {
369
375
  })
370
376
  },
371
377
 
372
- async submit (event) {
373
- if (this.disable) return null
374
-
378
+ /**
379
+ * Se existe a propriedade com callback "beforeSubmit", então o controle de quando e como chamar o método "submit"
380
+ * está sendo controlado fora do QasFormView, se não existir a propriedade "beforeSubmit", então o controle do método
381
+ * submit é feito pelo próprio QasFormView, chamado pelo evento @submit.
382
+ */
383
+ submitHandler (event) {
375
384
  if (event) {
376
385
  event.preventDefault()
377
386
  }
378
387
 
388
+ const hasBeforeSubmit = typeof this.beforeSubmit === 'function'
389
+
390
+ if (hasBeforeSubmit) {
391
+ return this.beforeSubmit({
392
+ payload: { id: this.id, payload: this.modelValue, url: this.url },
393
+ resolve: payload => this.submit(payload)
394
+ })
395
+ }
396
+
397
+ this.submit()
398
+ },
399
+
400
+ async submit (externalPayload = {}) {
401
+ if (this.disable) return null
402
+
379
403
  this.isSubmitting = true
380
404
 
381
405
  try {
382
- const payload = { id: this.id, payload: this.modelValue, url: this.url }
406
+ const payload = { id: this.id, payload: this.modelValue, url: this.url, ...externalPayload }
383
407
 
384
408
  this.$qas.logger.group(
385
409
  `QasFormView - submit -> payload do ${this.entity}/${this.mode}`, [payload]
@@ -4,6 +4,18 @@ meta:
4
4
  desc: Componente para C.R.U.D. responsável pela pela criação (Create) e edição (Update).
5
5
 
6
6
  props:
7
+ before-fetch:
8
+ desc: Callback para controlar como funciona o comportamento do fetch.
9
+ default: null
10
+ type: Function
11
+ examples: ['beforeFetch({ payload, resolve })']
12
+
13
+ before-submit:
14
+ desc: Callback para controlar como funciona o comportamento do submit.
15
+ default: null
16
+ type: Function
17
+ examples: ['beforeSubmit({ payload, resolve })']
18
+
7
19
  cancel-button-label:
8
20
  desc: Rótulo do botão "cancelar".
9
21
  default: Cancelar
@@ -10,7 +10,7 @@
10
10
  </slot>
11
11
 
12
12
  <main class="relative-position">
13
- <div v-if="hasResults">
13
+ <div v-if="showResults">
14
14
  <slot />
15
15
  </div>
16
16
 
@@ -72,6 +72,10 @@ export default {
72
72
  useFilter: {
73
73
  default: true,
74
74
  type: Boolean
75
+ },
76
+
77
+ useResultsAreaOnly: {
78
+ type: Boolean
75
79
  }
76
80
  },
77
81
 
@@ -107,13 +111,17 @@ export default {
107
111
 
108
112
  totalPages () {
109
113
  return this.$store.getters[`${this.entity}/totalPages`]
114
+ },
115
+
116
+ showResults () {
117
+ return this.hasResults || this.useResultsAreaOnly
110
118
  }
111
119
  },
112
120
 
113
121
  watch: {
114
122
  $route (to, from) {
115
123
  if (to.name === from.name) {
116
- this.fetchList()
124
+ this.mx_fetchHandler({ ...this.mx_context, url: this.url }, this.fetchList)
117
125
  this.setCurrentPage()
118
126
  }
119
127
  },
@@ -128,7 +136,8 @@ export default {
128
136
  },
129
137
 
130
138
  created () {
131
- this.fetchList()
139
+ this.mx_fetchHandler({ ...this.mx_context, url: this.url }, this.fetchList)
140
+
132
141
  this.setCurrentPage()
133
142
  },
134
143
 
@@ -138,16 +147,14 @@ export default {
138
147
  this.$router.push({ query })
139
148
  },
140
149
 
141
- async fetchList (filters = {}) {
150
+ async fetchList (externalPayload = {}) {
142
151
  this.mx_isFetching = true
143
152
 
144
- const hasFilters = !!Object.keys(filters).length
145
-
146
153
  try {
147
154
  const payload = {
148
155
  ...this.mx_context,
149
156
  url: this.url,
150
- ...(hasFilters && { filters })
157
+ ...externalPayload
151
158
  }
152
159
 
153
160
  this.$qas.logger.group(
@@ -171,7 +178,7 @@ export default {
171
178
  this.$emit('fetch-success', response)
172
179
 
173
180
  this.$qas.logger.group(
174
- `QasListView - fetchSingle -> resposta da action ${this.entity}/fetchList`, [response]
181
+ `QasListView - fetchList -> resposta da action ${this.entity}/fetchList`, [response]
175
182
  )
176
183
  } catch (error) {
177
184
  this.mx_fetchError(error)
@@ -4,6 +4,12 @@ meta:
4
4
  desc: Componente para C.R.U.D. responsável pela parte de listagem (Read).
5
5
 
6
6
  props:
7
+ before-fetch:
8
+ desc: Callback para controlar como funciona o comportamento do fetchList.
9
+ default: null
10
+ type: Function
11
+ examples: ['beforeFetch({ payload, resolve, done })']
12
+
7
13
  entity:
8
14
  desc: Entidade da store, por exemplo se tiver que trabalhar com modulo de usuários, teremos o model "users" na store, que vai ser nossa "entity".
9
15
  required: true
@@ -67,6 +73,10 @@ props:
67
73
  default: true
68
74
  type: Boolean
69
75
 
76
+ use-results-area-only:
77
+ desc: Controla se irá sempre ser exibido os resultados independente se não há nenhum resultado a ser exibido.
78
+ type: Boolean
79
+
70
80
  slots:
71
81
  default:
72
82
  desc: 'Slot para ter o conteúdo principal (dentro do main).'
@@ -159,6 +159,11 @@ export default {
159
159
  }
160
160
  },
161
161
 
162
+ identifierItemKey: {
163
+ type: String,
164
+ default: 'uuid'
165
+ },
166
+
162
167
  rowLabel: {
163
168
  type: String,
164
169
  default: ''
@@ -261,13 +266,8 @@ export default {
261
266
  modelValue: {
262
267
  handler (value) {
263
268
  this.nested = extend(true, [], value)
264
- },
265
- immediate: true
266
- },
267
269
 
268
- field: {
269
- handler () {
270
- !this.modelValue.length && this.setDefaultNestedValue()
270
+ if (!this.nested.length) return this.setDefaultNestedValue()
271
271
  },
272
272
  immediate: true
273
273
  }
@@ -276,6 +276,11 @@ export default {
276
276
  methods: {
277
277
  add (row = {}) {
278
278
  const payload = { ...this.rowObject, ...row }
279
+ const hasIdentifierKey = payload[this.identifierItemKey]
280
+
281
+ if (hasIdentifierKey) {
282
+ delete payload[this.identifierItemKey]
283
+ }
279
284
 
280
285
  this.nested.push(payload)
281
286
 
@@ -301,7 +306,7 @@ export default {
301
306
  },
302
307
 
303
308
  destroy (index, row) {
304
- this.useRemoveOnDestroy
309
+ !row[this.identifierItemKey] || this.useRemoveOnDestroy
305
310
  ? this.nested.splice(index, 1)
306
311
  : this.nested.splice(index, 1, { [this.destroyKey]: true, ...row })
307
312
 
@@ -56,6 +56,12 @@ props:
56
56
  type: String
57
57
  examples: [xs, sm, md, lg, xl]
58
58
 
59
+ identifier-item-key:
60
+ desc: Define um identificador para o item. O identificador será utilizado para validar exclusão do item, por exemplo.
61
+ default: uuid
62
+ type: String
63
+ examples: [id, uuid, slug]
64
+
59
65
  model-value:
60
66
  desc: Model do componente
61
67
  default: []
@@ -66,7 +66,9 @@ export default {
66
66
 
67
67
  watch: {
68
68
  $route (to, from) {
69
- to.name === from.name && this.fetchSingle()
69
+ if (to.name === from.name) {
70
+ this.mx_fetchHandler({ id: this.id, url: this.url }, this.fetchSingle)
71
+ }
70
72
  },
71
73
 
72
74
  resultModel (value) {
@@ -75,15 +77,15 @@ export default {
75
77
  },
76
78
 
77
79
  created () {
78
- this.fetchSingle()
80
+ this.mx_fetchHandler({ id: this.id, url: this.url }, this.fetchSingle)
79
81
  },
80
82
 
81
83
  methods: {
82
- async fetchSingle (params = {}) {
84
+ async fetchSingle (externalPayload = {}) {
83
85
  this.mx_isFetching = true
84
86
 
85
87
  try {
86
- const payload = { id: this.id, url: this.url, params }
88
+ const payload = { id: this.id, url: this.url, ...externalPayload }
87
89
 
88
90
  this.$qas.logger.group(
89
91
  `QasSingleView - fetchSingle -> payload do parâmetro do ${this.entity}/fetchSingle`,
@@ -4,6 +4,12 @@ meta:
4
4
  desc: Componente para C.R.U.D. responsável pela visualização (Read) ou conhecido também como "show".
5
5
 
6
6
  props:
7
+ before-fetch:
8
+ desc: Callback para controlar como funciona o comportamento do fetchSingle.
9
+ default: null
10
+ type: Function
11
+ examples: ['beforeFetch({ payload, resolve, done })']
12
+
7
13
  custom-id:
8
14
  desc: Por padrão, o componente vai pegar o "id" que vem como parâmetro na url, caso queira que o id seja diferente da url, use esta prop.
9
15
  type: String
@@ -35,6 +35,11 @@ export default {
35
35
  useBoundary: {
36
36
  default: true,
37
37
  type: Boolean
38
+ },
39
+
40
+ beforeFetch: {
41
+ default: null,
42
+ type: Function
38
43
  }
39
44
  },
40
45
 
@@ -50,7 +55,7 @@ export default {
50
55
  mx_errors: {},
51
56
  mx_fields: {},
52
57
  mx_metadata: {},
53
-
58
+ mx_cancelBeforeFetch: false,
54
59
  mx_isFetching: false
55
60
  }
56
61
  },
@@ -116,6 +121,22 @@ export default {
116
121
 
117
122
  this.$emit(`update:${key}`, models[key])
118
123
  }
124
+ },
125
+
126
+ mx_fetchHandler (payload, resolve) {
127
+ const hasBeforeFetch = typeof this.beforeFetch === 'function'
128
+
129
+ if (hasBeforeFetch && !this.mx_cancelBeforeFetch) {
130
+ return this.beforeFetch({
131
+ payload,
132
+ resolve: payload => resolve(payload),
133
+ done: () => {
134
+ this.mx_cancelBeforeFetch = true
135
+ }
136
+ })
137
+ }
138
+
139
+ resolve()
119
140
  }
120
141
  }
121
142
  }