adminforth 2.4.0-next.157 → 2.4.0-next.159
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/dist/spa/src/adminforth.ts +14 -10
- package/dist/spa/src/components/Filters.vue +1 -1
- package/dist/spa/src/stores/filters.ts +28 -2
- package/dist/spa/src/types/FrontendAPI.ts +10 -0
- package/dist/spa/src/views/ListView.vue +2 -2
- package/dist/types/FrontendAPI.d.ts +10 -0
- package/dist/types/FrontendAPI.d.ts.map +1 -1
- package/dist/types/FrontendAPI.js.map +1 -1
- package/package.json +1 -1
|
@@ -120,23 +120,27 @@ class FrontendAPI implements FrontendAPIInterface {
|
|
|
120
120
|
listFilterValidation(filter: FilterParams): boolean {
|
|
121
121
|
if(router.currentRoute.value.meta.type !== 'list'){
|
|
122
122
|
throw new Error(`Cannot use ${this.setListFilter.name} filter on a list page`)
|
|
123
|
-
} else {
|
|
124
|
-
console.log(this.coreStore.resourceColumnsWithFilters,'core store')
|
|
125
|
-
const filterField = this.coreStore.resourceColumnsWithFilters.find((col: AdminForthResourceColumnCommon) => col.name === filter.field)
|
|
126
|
-
if(!filterField){
|
|
127
|
-
throw new Error(`Field ${filter.field} is not available for filtering`)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
123
|
}
|
|
131
124
|
return true
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
setListFilter(filter: FilterParams): void {
|
|
135
128
|
if(this.listFilterValidation(filter)){
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
const existingFilterIndex = this.filtersStore.filters.findIndex((f: any) => {
|
|
130
|
+
return f.field === filter.field && f.operator === filter.operator
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if(existingFilterIndex !== -1){
|
|
134
|
+
// Update existing filter instead of throwing error
|
|
135
|
+
const filters = [...this.filtersStore.filters];
|
|
136
|
+
if (filter.value === undefined) {
|
|
137
|
+
filters.splice(existingFilterIndex, 1);
|
|
138
|
+
} else {
|
|
139
|
+
filters[existingFilterIndex] = filter;
|
|
140
|
+
}
|
|
141
|
+
this.filtersStore.setFilters(filters);
|
|
138
142
|
} else {
|
|
139
|
-
this.filtersStore.setFilter(filter)
|
|
143
|
+
this.filtersStore.setFilter(filter);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
}
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
|
|
137
137
|
<div class="flex justify-end gap-2">
|
|
138
138
|
<button
|
|
139
|
-
:disabled="!filtersStore.
|
|
139
|
+
:disabled="!filtersStore.visibleFiltersCount"
|
|
140
140
|
type="button"
|
|
141
141
|
class="flex items-center py-1 px-3 text-sm font-medium text-lightFiltersClearAllButtonText focus:outline-none bg-lightFiltersClearAllButtonBackground rounded border border-lightFiltersClearAllButtonBorder hover:bg-lightFiltersClearAllButtonBackgroundHover hover:text-lightFiltersClearAllButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightFiltersClearAllButtonFocus dark:focus:ring-darkFiltersClearAllButtonFocus dark:bg-darkFiltersClearAllButtonBackground dark:text-darkFiltersClearAllButtonText dark:border-darkFiltersClearAllButtonBorder dark:hover:text-darkFiltersClearAllButtonTextHover dark:hover:bg-darkFiltersClearAllButtonBackgroundHover disabled:opacity-50 disabled:cursor-not-allowed"
|
|
142
142
|
@click="clear">{{ $t('Clear all') }}</button>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ref, type Ref } from 'vue';
|
|
1
|
+
import { ref, computed, type Ref } from 'vue';
|
|
2
2
|
import { defineStore } from 'pinia';
|
|
3
|
+
import { useCoreStore } from './core';
|
|
3
4
|
|
|
4
5
|
export const useFiltersStore = defineStore('filters', () => {
|
|
5
6
|
const filters: Ref<any[]> = ref([]);
|
|
6
7
|
const sort: Ref<any> = ref({});
|
|
8
|
+
const coreStore = useCoreStore();
|
|
7
9
|
|
|
8
10
|
const setSort = (s: any) => {
|
|
9
11
|
sort.value = s;
|
|
@@ -23,5 +25,29 @@ export const useFiltersStore = defineStore('filters', () => {
|
|
|
23
25
|
const clearFilters = () => {
|
|
24
26
|
filters.value = [];
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
const shouldFilterBeHidden = (fieldName: string) => {
|
|
30
|
+
if (coreStore.resource?.columns) {
|
|
31
|
+
const column = coreStore.resource.columns.find((col: any) => col.name === fieldName);
|
|
32
|
+
if (column?.showIn?.filter !== true) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const visibleFiltersCount = computed(() => {
|
|
40
|
+
return filters.value.filter(f => !shouldFilterBeHidden(f.field)).length;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
setFilter,
|
|
45
|
+
getFilters,
|
|
46
|
+
clearFilters,
|
|
47
|
+
filters,
|
|
48
|
+
setFilters,
|
|
49
|
+
setSort,
|
|
50
|
+
getSort,
|
|
51
|
+
visibleFiltersCount
|
|
52
|
+
}
|
|
27
53
|
})
|
|
@@ -87,12 +87,19 @@ export interface FrontendAPIInterface {
|
|
|
87
87
|
* Works only when user located on the list page. If filter already exists, it will be replaced with the new one.
|
|
88
88
|
* Can be used to set filter from charts or other components in pageInjections.
|
|
89
89
|
*
|
|
90
|
+
* Filters are automatically marked as hidden (won't count in badge) if:
|
|
91
|
+
* - Column has showIn.filter: false
|
|
92
|
+
*
|
|
90
93
|
* Example:
|
|
91
94
|
*
|
|
92
95
|
* ```ts
|
|
93
96
|
* import adminforth from '@/adminforth'
|
|
94
97
|
*
|
|
98
|
+
* // Regular filter (will show in badge if column.showIn.filter !== false)
|
|
95
99
|
* adminforth.list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
100
|
+
*
|
|
101
|
+
* // Hidden filter (won't show in badge if column.showIn.filter === false)
|
|
102
|
+
* adminforth.list.setFilter({field: 'internal_status', operator: 'eq', value: 'active'})
|
|
96
103
|
* ```
|
|
97
104
|
*
|
|
98
105
|
* Please note that you can set/update filter even for fields which have showIn.filter=false in resource configuration.
|
|
@@ -106,6 +113,9 @@ export interface FrontendAPIInterface {
|
|
|
106
113
|
* DEPRECATED: does the same as setFilter, kept for backward compatibility
|
|
107
114
|
* Update a filter in the list
|
|
108
115
|
*
|
|
116
|
+
* Filters visibility in badge is automatically determined by column configuration:
|
|
117
|
+
* - Hidden if column has showIn.filter: false
|
|
118
|
+
*
|
|
109
119
|
* Example:
|
|
110
120
|
*
|
|
111
121
|
* ```ts
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
{{ $t('Filter') }}
|
|
93
93
|
<span
|
|
94
94
|
class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400"
|
|
95
|
-
v-if="filtersStore.
|
|
96
|
-
{{ filtersStore.
|
|
95
|
+
v-if="filtersStore.visibleFiltersCount">
|
|
96
|
+
{{ filtersStore.visibleFiltersCount }}
|
|
97
97
|
</span>
|
|
98
98
|
</button>
|
|
99
99
|
|
|
@@ -80,12 +80,19 @@ export interface FrontendAPIInterface {
|
|
|
80
80
|
* Works only when user located on the list page. If filter already exists, it will be replaced with the new one.
|
|
81
81
|
* Can be used to set filter from charts or other components in pageInjections.
|
|
82
82
|
*
|
|
83
|
+
* Filters are automatically marked as hidden (won't count in badge) if:
|
|
84
|
+
* - Column has showIn.filter: false
|
|
85
|
+
*
|
|
83
86
|
* Example:
|
|
84
87
|
*
|
|
85
88
|
* ```ts
|
|
86
89
|
* import adminforth from '@/adminforth'
|
|
87
90
|
*
|
|
91
|
+
* // Regular filter (will show in badge if column.showIn.filter !== false)
|
|
88
92
|
* adminforth.list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
93
|
+
*
|
|
94
|
+
* // Hidden filter (won't show in badge if column.showIn.filter === false)
|
|
95
|
+
* adminforth.list.setFilter({field: 'internal_status', operator: 'eq', value: 'active'})
|
|
89
96
|
* ```
|
|
90
97
|
*
|
|
91
98
|
* Please note that you can set/update filter even for fields which have showIn.filter=false in resource configuration.
|
|
@@ -98,6 +105,9 @@ export interface FrontendAPIInterface {
|
|
|
98
105
|
* DEPRECATED: does the same as setFilter, kept for backward compatibility
|
|
99
106
|
* Update a filter in the list
|
|
100
107
|
*
|
|
108
|
+
* Filters visibility in badge is automatically determined by column configuration:
|
|
109
|
+
* - Hidden if column has showIn.filter: false
|
|
110
|
+
*
|
|
101
111
|
* Example:
|
|
102
112
|
*
|
|
103
113
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendAPI.d.ts","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,MAAM,YAAY,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,yBAAyB,CAAC;IACpC;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAE;CACrC,CAAA;AAED,MAAM,WAAW,oBAAoB;IAEjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,EAAC,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAG3D,IAAI,EAAE;QAEF;;WAEG;QACH,OAAO,IAAI,OAAO,CAAC;YAAE,KAAK,CAAC,EAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAExC;;;;WAIG;QACH,aAAa,IAAI,OAAO,CAAC;YAAE,KAAK,CAAC,EAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAE9C;;WAEG;QACH,gBAAgB,CAAE,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC;YA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M,EAAE,YAAY,GAAG,IAAI,CAAC;QAEzC;;WAEG;QACH,YAAY,IAAI,IAAI,CAAC;KACxB,CAAA;IAED,IAAI,EAAE;QACF;;;WAGG;QACH,OAAO,IAAI,IAAI,CAAC;KACnB,CAAA;IAED,IAAI,EAAE;QACF;;WAEG;QACH,iBAAiB,IAAI,IAAI,CAAC;KAC7B,CAAA;IAED;;OAEG;IACH,qBAAqB,IAAI,IAAI,CAAC;CACjC;AAED,MAAM,MAAM,aAAa,GAAG;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CAEf,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,OAAO,YAAY,CAAC;IAEnD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;CAE3C,CAAA;AAID,oBAAY,YAAY;IACpB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;CACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendAPI.js","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrontendAPI.js","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"AA4MA,MAAM,CAAN,IAAY,YAKT;AALH,WAAY,YAAY;IACpB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,6BAAa,CAAA;AACf,CAAC,EALS,YAAY,KAAZ,YAAY,QAKrB"}
|