Compare commits
No commits in common. "59e21a51f286da5554c37a5557daf50e1f979f93" and "3a9bc2f6b2d37c5293d612ced9f2734f4098afb5" have entirely different histories.
59e21a51f2
...
3a9bc2f6b2
1 changed files with 71 additions and 59 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<h2>Tasks</h2>
|
<h2>Admin Tasks</h2>
|
||||||
<!-- Todo Chart Section -->
|
<!-- Todo Chart Section -->
|
||||||
<div class = "widgets-grid">
|
<div class = "widgets-grid">
|
||||||
<!-- Widget Cards go here if needed -->
|
<!-- Widget Cards go here if needed -->
|
||||||
|
|
@ -8,8 +8,6 @@
|
||||||
<DataTable
|
<DataTable
|
||||||
:data="tableData"
|
:data="tableData"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:filters="filters"
|
|
||||||
:tableActions="tableActions"
|
|
||||||
tableName="tasks"
|
tableName="tasks"
|
||||||
:lazy="true"
|
:lazy="true"
|
||||||
:totalRecords="totalRecords"
|
:totalRecords="totalRecords"
|
||||||
|
|
@ -20,7 +18,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import DataTable from "../common/DataTable.vue";
|
import DataTable from "../common/DataTable.vue";
|
||||||
import { ref, onMounted, watch, computed } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import Api from "../../api";
|
import Api from "../../api";
|
||||||
import { useLoadingStore } from "../../stores/loading";
|
import { useLoadingStore } from "../../stores/loading";
|
||||||
|
|
@ -37,19 +35,10 @@ const tableData = ref([]);
|
||||||
const totalRecords = ref(0);
|
const totalRecords = ref(0);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
|
|
||||||
// Computed property to get current filters for the chart
|
|
||||||
const currentFilters = computed(() => {
|
|
||||||
return filtersStore.getTableFilters("tasks");
|
|
||||||
});
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ label: "Task", fieldName: "subject", type: "text", sortable: true, filterable: true },
|
{ label: "Task", fieldName: "subject", type: "text", sortable: true, filterable: true },
|
||||||
{ label: "Project", fieldName: "project", type: "link", sortable: true,
|
{ label: "Project", fieldName: "project", type: "link", sortable: true },
|
||||||
onLinkClick: (link, rowData) => handleProjectClick(link, rowData)
|
{ label: "Address", fieldName: "address", type: "text", sortable: true },
|
||||||
},
|
|
||||||
{ label: "Address", fieldName: "address", type: "link", sortable: true,
|
|
||||||
onLinkClick: (link, rowData) => handlePropertyClick(link, rowData)
|
|
||||||
},
|
|
||||||
{ label: "Type", fieldName: "type", type: "text", sortable: true },
|
{ label: "Type", fieldName: "type", type: "text", sortable: true },
|
||||||
{ label: "Overall Status", fieldName: "status", type: "status", sortable: true },
|
{ label: "Overall Status", fieldName: "status", type: "status", sortable: true },
|
||||||
];
|
];
|
||||||
|
|
@ -70,25 +59,19 @@ const handleLazyLoad = async (event) => {
|
||||||
try {
|
try {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
|
||||||
// If this is a sort event, update the store first
|
// Get sorting information from filters store first (needed for cache key)
|
||||||
if (event.sortField !== undefined && event.sortOrder !== undefined) {
|
const sorting = filtersStore.getTableSorting("tasks");
|
||||||
console.log("Sort event detected - updating store with:", {
|
console.log("Current sorting state:", sorting);
|
||||||
sortField: event.sortField,
|
|
||||||
sortOrder: event.sortOrder,
|
|
||||||
orderType: typeof event.sortOrder,
|
|
||||||
});
|
|
||||||
filtersStore.updateTableSorting("tasks", event.sortField, event.sortOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get sorting information from filters store in backend format
|
|
||||||
const sortingArray = filtersStore.getTableSortingForBackend("tasks");
|
|
||||||
console.log("Current sorting array for backend:", sortingArray);
|
|
||||||
|
|
||||||
// Get pagination parameters
|
// Get pagination parameters
|
||||||
const paginationParams = {
|
const paginationParams = {
|
||||||
page: event.page || 0,
|
page: event.page || 0,
|
||||||
pageSize: event.rows || 10,
|
pageSize: event.rows || 10,
|
||||||
}; // Get filters (convert PrimeVue format to API format)
|
sortField: event.sortField,
|
||||||
|
sortOrder: event.sortOrder,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get filters (convert PrimeVue format to API format)
|
||||||
const filters = {};
|
const filters = {};
|
||||||
if (event.filters) {
|
if (event.filters) {
|
||||||
Object.keys(event.filters).forEach((key) => {
|
Object.keys(event.filters).forEach((key) => {
|
||||||
|
|
@ -98,25 +81,41 @@ const handleLazyLoad = async (event) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// For cache key, use primary sort field/order for compatibility
|
// Clear cache when filters or sorting are active to ensure fresh data
|
||||||
const primarySortField = filtersStore.getPrimarySortField("tasks") || event.sortField;
|
const hasActiveFilters = Object.keys(filters).length > 0;
|
||||||
const primarySortOrder = filtersStore.getPrimarySortOrder("tasks") || event.sortOrder;
|
const hasActiveSorting = paginationParams.sortField && paginationParams.sortOrder;
|
||||||
|
if (hasActiveFilters || hasActiveSorting) {
|
||||||
|
paginationStore.clearTableCache("tasks");
|
||||||
|
}
|
||||||
|
|
||||||
// Always fetch fresh data from API (cache only stores pagination/filter/sort state, not data)
|
// Check cache first
|
||||||
// Call API with pagination, filters, and sorting in backend format
|
const cachedData = paginationStore.getCachedPage(
|
||||||
console.log("Making API call with:", {
|
"tasks",
|
||||||
paginationParams,
|
paginationParams.page,
|
||||||
|
paginationParams.pageSize,
|
||||||
|
sorting.field || paginationParams.sortField,
|
||||||
|
sorting.order || paginationParams.sortOrder,
|
||||||
filters,
|
filters,
|
||||||
sortingArray,
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await Api.getPaginatedTaskDetails(
|
|
||||||
paginationParams,
|
|
||||||
filters,
|
|
||||||
sortingArray,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("API response:", result);
|
if (cachedData) {
|
||||||
|
// Use cached data
|
||||||
|
tableData.value = cachedData.records;
|
||||||
|
totalRecords.value = cachedData.totalRecords;
|
||||||
|
paginationStore.setTotalRecords("tasks", cachedData.totalRecords);
|
||||||
|
|
||||||
|
console.log("Loaded from cache:", {
|
||||||
|
records: cachedData.records.length,
|
||||||
|
total: cachedData.totalRecords,
|
||||||
|
page: paginationParams.page + 1,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Making API call with:", { paginationParams, filters });
|
||||||
|
|
||||||
|
// Call API with pagination, filters, and sorting
|
||||||
|
const result = await Api.getPaginatedTaskDetails(paginationParams, filters, sorting);
|
||||||
|
|
||||||
// Update local state - extract from pagination structure
|
// Update local state - extract from pagination structure
|
||||||
tableData.value = result.data;
|
tableData.value = result.data;
|
||||||
|
|
@ -124,8 +123,35 @@ const handleLazyLoad = async (event) => {
|
||||||
|
|
||||||
// Update pagination store with new total
|
// Update pagination store with new total
|
||||||
paginationStore.setTotalRecords("tasks", result.pagination.total);
|
paginationStore.setTotalRecords("tasks", result.pagination.total);
|
||||||
|
|
||||||
|
console.log("Updated pagination state:", {
|
||||||
|
tableData: tableData.value.length,
|
||||||
|
totalRecords: totalRecords.value,
|
||||||
|
storeTotal: paginationStore.getTablePagination("tasks").totalRecords,
|
||||||
|
storeTotalPages: paginationStore.getTotalPages("tasks"),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cache the result
|
||||||
|
paginationStore.setCachedPage(
|
||||||
|
"tasks",
|
||||||
|
paginationParams.page,
|
||||||
|
paginationParams.pageSize,
|
||||||
|
sorting.field || paginationParams.sortField,
|
||||||
|
sorting.order || paginationParams.sortOrder,
|
||||||
|
filters,
|
||||||
|
{
|
||||||
|
records: result.data,
|
||||||
|
totalRecords: result.pagination.total,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("Loaded from API:", {
|
||||||
|
records: result.data.length,
|
||||||
|
total: result.pagination.total,
|
||||||
|
page: paginationParams.page + 1,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading task data:", error);
|
console.error("Error loading job data:", error);
|
||||||
// You could also show a toast or other error notification here
|
// You could also show a toast or other error notification here
|
||||||
tableData.value = [];
|
tableData.value = [];
|
||||||
totalRecords.value = 0;
|
totalRecords.value = 0;
|
||||||
|
|
@ -134,20 +160,6 @@ const handleLazyLoad = async (event) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProjectClick = (link, rowData) => {
|
|
||||||
console.log("DEBUG: Project Link Clicked.");
|
|
||||||
const jobId = encodeURIComponent(rowData.project);
|
|
||||||
router.push(`/job?jobId=${jobId}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePropertyClick = (link, rowData) => {
|
|
||||||
console.log("DEBUG: Property Link Clicked.");
|
|
||||||
const client = encodeURIComponent(rowData.customerName);
|
|
||||||
const address = encodeURIComponent(rowData.address);
|
|
||||||
router.push(`/property?client=${client}&address=${address}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// If we implement a Task Detail View, this may be helpful
|
// If we implement a Task Detail View, this may be helpful
|
||||||
//const handleRowClick = (event) => {
|
//const handleRowClick = (event) => {
|
||||||
// const rowData = event.data;
|
// const rowData = event.data;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue