@drax/crud-vue 2.7.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.7.0",
6
+ "version": "2.11.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
@@ -24,9 +24,9 @@
24
24
  "format": "prettier --write src/"
25
25
  },
26
26
  "dependencies": {
27
- "@drax/common-front": "^2.6.0",
28
- "@drax/crud-front": "^2.0.0",
29
- "@drax/crud-share": "^2.4.0",
27
+ "@drax/common-front": "^2.11.0",
28
+ "@drax/crud-front": "^2.11.0",
29
+ "@drax/crud-share": "^2.11.0",
30
30
  "@drax/media-vue": "^2.2.1"
31
31
  },
32
32
  "peerDependencies": {
@@ -50,5 +50,5 @@
50
50
  "vue-tsc": "^3.2.4",
51
51
  "vuetify": "^3.11.8"
52
52
  },
53
- "gitHead": "6914eb5bfd532fb5e510b95c7d17b5b2ada8b07d"
53
+ "gitHead": "8919d31d4d9512e48ac461b0876dc85a5849daea"
54
54
  }
package/src/EntityCrud.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import type {
2
2
  IEntityCrud, IEntityCrudForm, IEntityCrudHeader, IEntityCrudRefs,
3
3
  IEntityCrudRules, IEntityCrudField, IEntityCrudPermissions,
4
- IDraxCrudProvider, IEntityCrudFilter, IEntityCrudFormFilter, IEntityCrudFieldVariant
4
+ IDraxCrudProvider, IEntityCrudFilter, IEntityCrudFieldVariant, IDraxFieldFilter
5
5
  } from "@drax/crud-share";
6
6
 
7
7
 
8
+
8
9
  class EntityCrud implements IEntityCrud {
9
10
 
10
11
  name: string = ''
@@ -125,11 +126,11 @@ class EntityCrud implements IEntityCrud {
125
126
  }
126
127
 
127
128
 
128
- get formFilters(): IEntityCrudFormFilter[] {
129
+ get formFilters(): IDraxFieldFilter[] {
129
130
  return this.filters.map(
130
131
  (filter: IEntityCrudFilter) =>
131
132
  ({field: filter.name, value: filter.default ? filter.default : null, operator: (filter.operator ? filter.operator : 'eq')})
132
- ) as IEntityCrudFormFilter[]
133
+ ) as IDraxFieldFilter[]
133
134
  }
134
135
 
135
136
  get refs(): IEntityCrudRefs {
@@ -138,7 +139,7 @@ class EntityCrud implements IEntityCrud {
138
139
 
139
140
  getRef(ref: string): IEntityCrud {
140
141
  if (!this.refs.hasOwnProperty(ref)) {
141
- throw new Error("Ref not found: " + ref)
142
+ throw new Error("Ref not found: " + ref + " Refs Available: " + Object.getOwnPropertyNames(this.refs).join(", "))
142
143
  }
143
144
 
144
145
  return this.refs[ref] as IEntityCrud
@@ -238,6 +239,14 @@ class EntityCrud implements IEntityCrud {
238
239
  return true
239
240
  }
240
241
 
242
+ get filtersEnable(){
243
+ return true
244
+ }
245
+
246
+ get dynamicFiltersEnable(){
247
+ return true
248
+ }
249
+
241
250
  get filterButtons() {
242
251
  return true
243
252
  }
@@ -1,11 +1,13 @@
1
1
  <script setup lang="ts">
2
- import {onBeforeMount, type PropType} from "vue";
2
+ import {computed, onBeforeMount, type PropType} from "vue";
3
3
  import type {IEntityCrud} from "@drax/crud-share";
4
- import CrudList from "./CrudList.vue";
4
+ import CrudListTable from "./CrudListTable.vue";
5
+ import CrudListGallery from "./CrudListGallery.vue";
5
6
  import CrudForm from "./CrudForm.vue";
6
7
  import CrudNotify from "./CrudNotify.vue";
7
8
  import CrudDialog from "./CrudDialog.vue";
8
9
  import {useCrud} from "../composables/UseCrud";
10
+ import {useDisplay} from 'vuetify'
9
11
 
10
12
  const {entity} = defineProps({
11
13
  entity: {type: Object as PropType<IEntityCrud>, required: true},
@@ -24,6 +26,22 @@ onBeforeMount(() => {
24
26
 
25
27
  const emit = defineEmits(['created', 'updated', 'deleted', 'viewed', 'canceled'])
26
28
 
29
+ const listComponent = computed(() => {
30
+ const listMode = entity?.listMode
31
+ switch (listMode){
32
+ case 'responsive':
33
+ return xs.value ? CrudListGallery : CrudListTable
34
+ case 'gallery':
35
+ return CrudListGallery
36
+ case 'table':
37
+ return CrudListTable
38
+ default:
39
+ return xs.value ? CrudListGallery : CrudListTable
40
+ }
41
+ })
42
+
43
+ const {xs} = useDisplay()
44
+
27
45
 
28
46
  </script>
29
47
 
@@ -31,7 +49,8 @@ const emit = defineEmits(['created', 'updated', 'deleted', 'viewed', 'canceled']
31
49
  <v-container :fluid="entity.containerFluid" class="mt-5">
32
50
  <v-card :class="entity.cardClass" :density="entity.cardDensity">
33
51
 
34
- <crud-list
52
+ <component
53
+ :is="listComponent"
35
54
  :entity="entity"
36
55
  @create="onCreate"
37
56
  @edit="onEdit"
@@ -66,13 +85,18 @@ const emit = defineEmits(['created', 'updated', 'deleted', 'viewed', 'canceled']
66
85
  </slot>
67
86
  </template>
68
87
 
88
+ <template v-slot:item="{item}">
89
+ <slot name="item" v-bind="{item}">
90
+ </slot>
91
+ </template>
92
+
69
93
 
70
94
  <template v-slot:item.actions="{item}">
71
95
  <slot name="item.actions" v-bind="{item}">
72
96
  </slot>
73
97
  </template>
74
98
 
75
- </crud-list>
99
+ </component>
76
100
  </v-card>
77
101
 
78
102
  <crud-dialog
@@ -3,7 +3,7 @@ import { computed, type PropType } from 'vue'
3
3
  import type { IEntityCrud } from '@drax/crud-share'
4
4
  import { useCrudStore } from '../stores/UseCrudStore'
5
5
  import { useI18n } from 'vue-i18n'
6
- import { useFilterIcon } from '../composables/useFilterIcon'
6
+ import { useFilterIcon } from '../composables/UseFilterIcon'
7
7
  import CrudRefDisplay from "./CrudRefDisplay.vue";
8
8
  import {formatDate} from "@drax/common-front"
9
9
 
@@ -92,7 +92,7 @@ const removeFilter = (index: number) => {
92
92
  const filterDef = props.entity.filters[index]
93
93
 
94
94
  // Resetear al valor por defecto
95
- filter.value = filterDef.default
95
+ filter.value = filterDef?.default
96
96
 
97
97
  // Emitir evento para aplicar filtros
98
98
  emit('filterRemoved')
@@ -146,14 +146,14 @@ defineEmits(['updateValue'])
146
146
  :title="item.raw[itemTitle]"
147
147
  :color="item.raw?.color"
148
148
  :base-color="item.raw?.color"
149
- :prepend-icon="item.raw?.icon"
149
+ :prepend-icon="typeof item.raw?.icon=== 'string' ? item.raw?.icon : null"
150
150
  />
151
151
  </template>
152
152
 
153
153
  <template v-slot:selection="{item}">
154
154
  <v-chip tile density="compact"
155
155
  :color="item.raw?.color"
156
- :prepend-icon="item.raw?.icon"
156
+ :prepend-icon="typeof item.raw?.icon=== 'string' ? item.raw?.icon : null"
157
157
  >
158
158
  {{ item.raw[itemTitle] }}
159
159
  </v-chip>
@@ -203,14 +203,14 @@ defineEmits(['updateValue'])
203
203
  :title="item.raw[itemTitle]"
204
204
  :color="item.raw?.color"
205
205
  :base-color="item.raw?.color"
206
- :prepend-icon="item.raw?.icon"
206
+ :prepend-icon="typeof item.raw?.icon=== 'string' ? item.raw?.icon : null"
207
207
  />
208
208
  </template>
209
209
 
210
210
  <template v-slot:selection="{item}">
211
211
  <v-chip tile density="compact"
212
212
  :color="item.raw?.color"
213
- :prepend-icon="item.raw?.icon"
213
+ :prepend-icon="typeof item.raw?.icon=== 'string' ? item.raw?.icon : null"
214
214
  >
215
215
  {{ item.raw[itemTitle] }}
216
216
  </v-chip>
@@ -2,18 +2,16 @@
2
2
  import {computed, type PropType} from "vue";
3
3
  import CrudFormField from "./CrudFormField.vue";
4
4
  import type {IEntityCrud, IEntityCrudFilter} from "@drax/crud-share";
5
- import {useI18n} from "vue-i18n";
6
5
  import {useAuth} from "@drax/identity-vue";
7
- import {useFilterIcon} from "../composables/useFilterIcon";
6
+ import {useFilterIcon} from "../composables/UseFilterIcon";
8
7
 
9
- const {t} = useI18n()
10
8
  const valueModel = defineModel({type: [Object]})
11
9
  const {hasPermission} = useAuth()
12
10
  const {filterIcon} = useFilterIcon()
13
11
 
14
- const {entity, actionButtons} = defineProps({
12
+ const {entity, autoFilter} = defineProps({
15
13
  entity: {type: Object as PropType<IEntityCrud>, required: true},
16
- actionButtons: {type: Boolean, default: false},
14
+ autoFilter: {type: Boolean, default: false}
17
15
  })
18
16
 
19
17
  const aFields = computed(() => {
@@ -24,13 +22,15 @@ function filter() {
24
22
  emit('applyFilter')
25
23
  }
26
24
 
25
+ /*
27
26
  function clear() {
28
27
  emit('clearFilter')
29
28
  }
29
+ */
30
30
 
31
31
  function onUpdateValue(){
32
- if(!actionButtons){
33
- emit('applyFilter')
32
+ if(autoFilter){
33
+ filter()
34
34
  }
35
35
  }
36
36
 
@@ -69,14 +69,6 @@ const emit = defineEmits(['applyFilter', 'clearFilter'])
69
69
 
70
70
  </v-row>
71
71
 
72
- <v-card-actions v-if="actionButtons" class="pb-0">
73
- <v-spacer />
74
- <v-btn variant="text" density="compact" :class="entity.cleanFilterClass" @click="clear">{{ t('action.clear') }}</v-btn>
75
- <v-btn variant="flat" density="compact" :class="entity.applyFilterClass" @click="filter">
76
- {{ t('action.filter') }}
77
- </v-btn>
78
- </v-card-actions>
79
-
80
72
  </v-card>
81
73
  </template>
82
74
 
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ import {useI18n} from "vue-i18n";
3
+ import type {PropType} from "vue";
4
+ import type {IEntityCrud} from "@drax/crud-share";
5
+ const {t} = useI18n()
6
+
7
+ const {entity} = defineProps({
8
+ entity: {type: Object as PropType<IEntityCrud>, required: true},
9
+ })
10
+
11
+ function filter() {
12
+ emit('applyFilter')
13
+ }
14
+
15
+ function clear() {
16
+ emit('clearFilter')
17
+ }
18
+
19
+ const emit = defineEmits(['applyFilter', 'clearFilter'])
20
+
21
+ </script>
22
+
23
+ <template>
24
+
25
+ <v-card-actions class="pb-0">
26
+ <v-spacer />
27
+ <v-btn variant="text" density="compact" :class="entity.cleanFilterClass" @click="clear">{{ t('action.clear') }}</v-btn>
28
+ <v-btn variant="flat" density="compact" :class="entity.applyFilterClass" @click="filter">
29
+ {{ t('action.filter') }}
30
+ </v-btn>
31
+ </v-card-actions>
32
+
33
+ </template>
34
+
35
+ <style scoped>
36
+
37
+ </style>
@@ -0,0 +1,146 @@
1
+ <script setup lang="ts">
2
+ import {computed, type PropType} from "vue";
3
+ import CrudFormField from "./CrudFormField.vue";
4
+ import type {IEntityCrud, IEntityCrudFilter} from "@drax/crud-share";
5
+ import {useI18n} from "vue-i18n";
6
+ import {useAuth} from "@drax/identity-vue";
7
+ import {useFilterIcon} from "../composables/UseFilterIcon";
8
+ import {useCrudStore} from "../stores/UseCrudStore";
9
+ import {useEntityStore} from "../stores/UseEntityStore";
10
+ import {useDynamicFilters} from "../composables/UseDynamicFilters.ts";
11
+
12
+ const {t, te} = useI18n()
13
+ const valueModel = defineModel({type: [Object]})
14
+ const {hasPermission} = useAuth()
15
+ const {filterIcon} = useFilterIcon()
16
+
17
+
18
+ const {entity, autoFilter} = defineProps({
19
+ entity: {type: Object as PropType<IEntityCrud>, required: true},
20
+ autoFilter: {type: Boolean, default: false}
21
+ })
22
+
23
+ const store = useCrudStore(entity?.name)
24
+ const entityStore = useEntityStore();
25
+ const storeEntity = entityStore.entities.find((e: any) => e.name === entity.name)
26
+
27
+ const aFields = computed(() => {
28
+ return store.dynamicFilters
29
+ .filter((field: IEntityCrudFilter) => !field.permission || hasPermission(field.permission))
30
+ })
31
+
32
+
33
+ const filtersRef = computed({
34
+ get: () => store.dynamicFilters,
35
+ set: v => store.dynamicFilters = v
36
+ })
37
+
38
+ const {
39
+ dynamicFilter,
40
+ selectableFields,
41
+ getOperations,
42
+ isValueRequired,
43
+ onUpdateField,
44
+ addFilter,
45
+ removeFilter
46
+ } = useDynamicFilters(
47
+ computed(() => entity.name),
48
+ computed(() => storeEntity?.fields || []),
49
+ filtersRef
50
+ )
51
+
52
+ function filter() {
53
+ emit('applyFilter')
54
+ }
55
+
56
+ /*
57
+ function clear() {
58
+ emit('clearFilter')
59
+ }
60
+ */
61
+
62
+ function onUpdateValue() {
63
+ if (autoFilter) {
64
+ filter()
65
+ }
66
+ }
67
+
68
+
69
+
70
+ const emit = defineEmits(['applyFilter', 'clearFilter'])
71
+
72
+ </script>
73
+
74
+ <template>
75
+ <v-row dense class="mt-4">
76
+ <v-col v-for="(filter,index) in aFields"
77
+ :key="filter.name"
78
+ cols="12" class="tdash"
79
+ >
80
+ <v-row >
81
+ <v-col cols="12" sm="4">
82
+ <v-select
83
+ :items="selectableFields"
84
+ v-model="dynamicFilter(index)!.name"
85
+ :label="t('crud.field')"
86
+ density="compact"
87
+ variant="outlined"
88
+ hide-details
89
+ @update:modelValue="(v:string) => onUpdateField(index, true)"
90
+ />
91
+ </v-col>
92
+ <v-col cols="12" sm="3">
93
+ <v-select
94
+ :items="getOperations(index)"
95
+ v-model="dynamicFilter(index)!.operator"
96
+ :label="t('crud.operator')"
97
+ density="compact"
98
+ variant="outlined"
99
+ hide-details
100
+ @update:modelValue="(v:string) => onUpdateField(index)"
101
+ />
102
+ </v-col>
103
+ <v-col cols="10" sm="4">
104
+ <crud-form-field
105
+ v-if="isValueRequired(index)"
106
+ :field="filter"
107
+ :entity="entity"
108
+ v-model="dynamicFilter(index)!.value"
109
+ :clearable="true"
110
+ density="compact"
111
+ variant="outlined"
112
+ :prepend-inner-icon="filterIcon(filter)"
113
+ hide-details
114
+ @updateValue="onUpdateValue"
115
+ />
116
+ </v-col>
117
+ <v-col cols="2" sm="1">
118
+ <v-btn @click="removeFilter(index)"
119
+ icon="mdi-delete"
120
+ class="mr-1"
121
+ variant="text"
122
+ color="red"
123
+ >
124
+ </v-btn>
125
+ </v-col>
126
+ </v-row>
127
+
128
+
129
+ </v-col>
130
+
131
+ <v-col cols="12">
132
+ <v-btn size="small" variant="outlined" color="primary" @click="addFilter">+ {{ t('action.addFilter') }}</v-btn>
133
+ </v-col>
134
+
135
+ </v-row>
136
+
137
+ </template>
138
+
139
+ <style scoped>
140
+ .tdash{
141
+ border-bottom-width: 0.5px;
142
+ border-bottom-color: lightgray;
143
+ border-bottom-style: dashed;
144
+ margin-bottom: 10px;
145
+ }
146
+ </style>
@@ -16,6 +16,8 @@ import type {IEntityCrud} from "@drax/crud-share";
16
16
  import {useI18n} from "vue-i18n";
17
17
  import CrudFilters from "./CrudFilters.vue";
18
18
  import { useCrudColumns } from "../composables/UseCrudColumns";
19
+ import CrudFiltersDynamic from "./CrudFiltersDynamic.vue";
20
+ import CrudFiltersAction from "./CrudFiltersAction.vue";
19
21
 
20
22
  const {t, te} = useI18n()
21
23
  const {hasPermission} = useAuth()
@@ -133,25 +135,45 @@ defineEmits(['import', 'export', 'create', 'update', 'delete', 'view', 'edit'])
133
135
  <v-card-text class="pt-0">
134
136
  <slot name="filters" v-bind="{filters}"></slot>
135
137
 
136
- <crud-filters
137
- v-if="!$slots.filters"
138
- :entity="entity"
139
- v-model="filters"
140
- :action-buttons="entity.filterButtons"
141
- @clearFilter="clearFilters()"
142
- @applyFilter="applyFilters()"
143
- >
144
-
145
- <template v-for="iFilter in entity.filters"
146
- :key="iFilter.name"
147
- v-slot:[`filter.${iFilter.name}`]="{filter, filterIndex}"
138
+ <v-card variant="flat" v-if="!$slots.filters">
139
+
140
+ <crud-filters
141
+ v-if="entity.filtersEnable"
142
+ :entity="entity"
143
+ v-model="filters"
144
+ :auto-filter="!entity.filterButtons"
145
+ @clearFilter="clearFilters()"
146
+ @applyFilter="applyFilters()"
147
+ >
148
+
149
+ <template v-for="iFilter in entity.filters"
150
+ :key="iFilter.name"
151
+ v-slot:[`filter.${iFilter.name}`]="{filter, filterIndex}"
152
+ >
153
+ <slot v-if="$slots[`filter.${iFilter.name}`]"
154
+ :name="`filter.${iFilter.name}`"
155
+ v-bind="{filter, filterIndex}"
156
+ />
157
+ </template>
158
+ </crud-filters>
159
+
160
+ <crud-filters-dynamic
161
+ v-if="entity.dynamicFiltersEnable"
162
+ :entity="entity"
163
+ v-model="filters"
164
+ :auto-filter="!entity.filterButtons"
165
+ @clearFilter="clearFilters()"
166
+ @applyFilter="applyFilters()"
148
167
  >
149
- <slot v-if="$slots[`filter.${iFilter.name}`]"
150
- :name="`filter.${iFilter.name}`"
151
- v-bind="{filter, filterIndex}"
152
- />
153
- </template>
154
- </crud-filters>
168
+ </crud-filters-dynamic>
169
+
170
+ <crud-filters-action v-if="entity.filterButtons"
171
+ :entity="entity"
172
+ @clearFilter="clearFilters()"
173
+ @applyFilter="applyFilters()"
174
+ ></crud-filters-action>
175
+ </v-card>
176
+
155
177
  </v-card-text>
156
178
 
157
179
  </v-card>