finish client table for now

This commit is contained in:
Casey 2025-11-07 07:50:19 -06:00
parent 60d3f35988
commit f4d04e90a9
6 changed files with 254 additions and 106 deletions

View file

@ -4,29 +4,9 @@ import { FilterMatchMode } from "@primevue/core";
export const useFiltersStore = defineStore("filters", {
state: () => ({
// Store filters by table/component name
tableFilters: {
clients: {
addressName: { value: null, matchMode: FilterMatchMode.CONTAINS },
},
jobs: {
customer: { value: null, matchMode: FilterMatchMode.CONTAINS },
jobId: { value: null, matchMode: FilterMatchMode.CONTAINS },
},
timesheets: {
employee: { value: null, matchMode: FilterMatchMode.CONTAINS },
customer: { value: null, matchMode: FilterMatchMode.CONTAINS },
},
warranties: {
customer: { value: null, matchMode: FilterMatchMode.CONTAINS },
warrantyId: { value: null, matchMode: FilterMatchMode.CONTAINS },
address: { value: null, matchMode: FilterMatchMode.CONTAINS },
assignedTechnician: { value: null, matchMode: FilterMatchMode.CONTAINS },
},
routes: {
technician: { value: null, matchMode: FilterMatchMode.CONTAINS },
routeId: { value: null, matchMode: FilterMatchMode.CONTAINS },
},
},
tableFilters: {},
// Store sorting by table/component name
tableSorting: {},
}),
actions: {
// Generic method to get filters for a specific table
@ -34,6 +14,11 @@ export const useFiltersStore = defineStore("filters", {
return this.tableFilters[tableName] || {};
},
// Generic method to get sorting for a specific table
getTableSorting(tableName) {
return this.tableSorting[tableName] || { field: null, order: null };
},
// Generic method to update a specific filter
updateTableFilter(tableName, fieldName, value, matchMode = null) {
if (!this.tableFilters[tableName]) {
@ -52,6 +37,15 @@ export const useFiltersStore = defineStore("filters", {
}
},
// Generic method to update sorting for a table
updateTableSorting(tableName, field, order) {
if (!this.tableSorting[tableName]) {
this.tableSorting[tableName] = { field: null, order: null };
}
this.tableSorting[tableName].field = field;
this.tableSorting[tableName].order = order;
},
// Method to clear all filters for a table
clearTableFilters(tableName) {
if (this.tableFilters[tableName]) {
@ -61,6 +55,19 @@ export const useFiltersStore = defineStore("filters", {
}
},
// Method to clear sorting for a table
clearTableSorting(tableName) {
if (this.tableSorting[tableName]) {
this.tableSorting[tableName] = { field: null, order: null };
}
},
// Method to clear both filters and sorting for a table
clearTableState(tableName) {
this.clearTableFilters(tableName);
this.clearTableSorting(tableName);
},
// Method to initialize filters for a table if they don't exist
initializeTableFilters(tableName, columns) {
if (!this.tableFilters[tableName]) {
@ -77,14 +84,43 @@ export const useFiltersStore = defineStore("filters", {
});
},
// Method to initialize sorting for a table
initializeTableSorting(tableName) {
if (!this.tableSorting[tableName]) {
this.tableSorting[tableName] = { field: null, order: null };
}
},
// Method to get active filters count
getActiveFiltersCount(tableName) {
const filters = this.getTableFilters(tableName);
return Object.values(filters).filter(
(filter) => filter.value && filter.value.trim() !== "",
).length;
},
// Method to check if sorting is active
isSortingActive(tableName) {
const sorting = this.getTableSorting(tableName);
return sorting.field !== null && sorting.order !== null;
},
// Method to get all table state (filters + sorting)
getTableState(tableName) {
return {
filters: this.getTableFilters(tableName),
sorting: this.getTableSorting(tableName),
};
},
// Legacy method for backward compatibility
setClientNameFilter(filterValue) {
this.updateTableFilter("clients", "addressName", filterValue);
this.updateTableFilter("clients", "addressTitle", filterValue);
},
// Getter for legacy compatibility
get clientNameFilter() {
return this.tableFilters?.clients?.addressName?.value || "";
return this.tableFilters?.clients?.addressTitle?.value || "";
},
},
});