@drax/dashboard-vue 2.9.0 → 2.11.0

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
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.9.0",
6
+ "version": "2.11.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
@@ -22,9 +22,9 @@
22
22
  "format": "prettier --write src/"
23
23
  },
24
24
  "dependencies": {
25
- "@drax/crud-front": "^2.0.0",
26
- "@drax/crud-share": "^2.8.0",
27
- "@drax/dashboard-front": "^2.8.0"
25
+ "@drax/crud-front": "^2.11.0",
26
+ "@drax/crud-share": "^2.11.0",
27
+ "@drax/dashboard-front": "^2.11.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "pinia": "^3.0.4",
@@ -46,5 +46,5 @@
46
46
  "vue-tsc": "^3.2.4",
47
47
  "vuetify": "^3.11.8"
48
48
  },
49
- "gitHead": "2bc9b59a45c762bd32403dce14db2693be34dcc7"
49
+ "gitHead": "8919d31d4d9512e48ac461b0876dc85a5849daea"
50
50
  }
@@ -12,12 +12,13 @@ import type {
12
12
  import {useI18n} from "vue-i18n"
13
13
  import CrudFormField from "@drax/crud-vue/src/components/CrudFormField.vue";
14
14
  import {useFilterIcon} from "@drax/crud-vue";
15
+ import {useDynamicFilters} from "@drax/crud-vue/src/composables/UseDynamicFilters.ts";
15
16
 
16
17
  const props = defineProps({
17
18
  modelValue: {type: Object as PropType<IDashboardCard>, required: true}
18
19
  });
19
20
  const {filterIcon} = useFilterIcon()
20
- const {t, te} = useI18n()
21
+ const {t} = useI18n()
21
22
 
22
23
  const emit = defineEmits(['update:modelValue', 'save', 'cancel']);
23
24
 
@@ -122,92 +123,19 @@ function onEntityChange() {
122
123
  }
123
124
  }
124
125
 
125
- const fieldI18n = computed(() => {
126
- return (field: IEntityCrudFilter) => {
127
- return te(entitySelected.value?.name?.toLowerCase() + ".field." + field.name) ? t(entitySelected.value?.name?.toLowerCase() + ".field." + field.name) : field.label
128
- }
129
- })
130
-
131
- const selectableFields = computed(() => {
132
- return entitySelected.value ?
133
- entitySelected.value.fields
134
- .filter((f: any) => !['fullFile', 'object', 'array.object'].includes(f.type))
135
- .map((f: any) => ({title: fieldI18n.value(f), value: f.name}))
136
- : []
137
- })
138
-
139
- const dynamicFilter = computed(() => {
140
- return (index: number) => {
141
- return filters.value[index]
142
- }
143
- })
144
-
145
- const operations = [
146
- {title: t('operation.equals'), value: 'eq'},
147
- {title: t('operation.notEquals'), value: 'ne'},
148
- {title: t('operation.contains'), value: 'like'},
149
- {title: t('operation.greaterThan'), value: 'gt'},
150
- {title: t('operation.lessThan'), value: 'lt'},
151
- {title: t('operation.greaterThanOrEqual'), value: 'gte'},
152
- {title: t('operation.lessThanOrEqual'), value: 'lte'},
153
- ]
154
-
155
- function removeFilter(index: number) {
156
- if (filters.value) {
157
- filters.value.splice(index, 1)
158
- }
159
- }
160
-
161
- function addFilter() {
162
- const filter: IEntityCrudFilter = {
163
- default: undefined,
164
- label: "",
165
- name: '',
166
- operator: 'eq',
167
- type: 'string',
168
- permission: '',
169
- value: ''
170
- }
171
- if (filters.value) {
172
- filters.value.push(filter)
173
- }
174
- }
175
-
176
- function normalizeFieldType(type: string): IEntityCrudFieldTypes {
177
- if (type === 'array.ref') return 'ref';
178
- if (type === 'array.string') return 'string';
179
- if (type === 'longString') return 'string';
180
- if (type === 'array.number') return 'number';
181
- if (type === 'array.enum') return 'enum';
182
- return type as IEntityCrudFieldTypes;
183
- }
184
-
185
- function onUpdateField(index: number, val: string) {
186
- const field = entitySelected.value.fields.find((e: any) => e.name === val)
187
- let filter = dynamicFilter.value(index)
188
- if (!filter) {
189
- return
190
- }
191
- filter.value = null
192
- if (!field) return
193
-
194
- if (field.ref) {
195
- filter.ref = field.ref
196
- }
197
- if (field.refDisplay) {
198
- filter.refDisplay = field.refDisplay
199
- }
200
- if (field.enum) {
201
- filter.enum = field.enum
202
- }
203
- if (field.type) {
204
- filter.type = normalizeFieldType(field.type)
205
- if(field.type === 'boolean'){
206
- filter.value = false
207
- }
208
- }
209
- }
210
-
126
+ const {
127
+ dynamicFilter,
128
+ selectableFields,
129
+ getOperations,
130
+ isValueRequired,
131
+ onUpdateField,
132
+ addFilter,
133
+ removeFilter
134
+ } = useDynamicFilters(
135
+ computed(() => form.value.entity),
136
+ computed(() => entitySelected.value.fields || []),
137
+ filters
138
+ )
211
139
 
212
140
  </script>
213
141
 
@@ -273,22 +201,23 @@ function onUpdateField(index: number, val: string) {
273
201
  density="compact"
274
202
  variant="outlined"
275
203
  hide-details
276
- @update:modelValue="(v:string) => onUpdateField(index, v)"
204
+ @update:modelValue="() => onUpdateField(index, true)"
277
205
  />
278
206
  </v-col>
279
207
  <v-col cols="12" sm="3">
280
208
  <v-select
281
- :items="operations"
209
+ :items="getOperations(index)"
282
210
  v-model="dynamicFilter(index)!.operator"
283
211
  :label="t('crud.operator')"
284
212
  density="compact"
285
213
  variant="outlined"
286
214
  hide-details
215
+ @update:modelValue="() => onUpdateField(index)"
287
216
  />
288
217
  </v-col>
289
218
  <v-col cols="12" sm="4">
290
219
  <crud-form-field
291
- v-if="entitySelected"
220
+ v-if="entitySelected && isValueRequired(index)"
292
221
  :field="filter"
293
222
  :entity="entitySelected"
294
223
  v-model="dynamicFilter(index)!.value"
@@ -314,7 +243,7 @@ function onUpdateField(index: number, val: string) {
314
243
  </v-col>
315
244
 
316
245
  <v-col cols="12">
317
- <v-btn small variant="outlined" color="primary" @click="addFilter">+ {{ t('action.addFilter') }}</v-btn>
246
+ <v-btn size="small" variant="outlined" color="primary" @click="addFilter">+ {{ t('action.addFilter') }}</v-btn>
318
247
  </v-col>
319
248
 
320
249
  </v-row>
@@ -59,8 +59,8 @@ const deleteCard = (index: number) => {
59
59
  valueModel.value.cards?.splice(index, 1);
60
60
  if (editingCardIndex.value === index) {
61
61
  editingCardIndex.value = null;
62
- emit("dashboardUpdated")
63
62
  }
63
+ emit("dashboardUpdated")
64
64
  }
65
65
  };
66
66