From 84c7eb0580cf0c874abf77a9c2515b7dbf807423 Mon Sep 17 00:00:00 2001 From: rocketdebris Date: Tue, 13 Jan 2026 11:54:13 -0500 Subject: [PATCH] Fixed pagination errors on the Task page, updated to the correct API calls to get that data. --- custom_ui/api/db/tasks.py | 95 ++++++++----------------- frontend/src/api.js | 34 +++++---- frontend/src/components/pages/Tasks.vue | 11 ++- 3 files changed, 59 insertions(+), 81 deletions(-) diff --git a/custom_ui/api/db/tasks.py b/custom_ui/api/db/tasks.py index 220aba6..f849aea 100644 --- a/custom_ui/api/db/tasks.py +++ b/custom_ui/api/db/tasks.py @@ -2,47 +2,6 @@ import frappe from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response -@frappe.whitelist() -def get_job_task_table_data(filters={}, sortings={}, page=1, page_size=10): - """Get paginated job tasks table data with filtering and sorting support.""" - print("DEBUG: raw task options received:", filters, sortings, page, page_size) - - processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size) - - print("DEBUG: Processed Filters:", processed_filters) - - if is_or: - count = frappe.db.sql(*get_count_or_filters("Task", filters))[0][0] - else: - count = frappe.db.count("Task", filters=filters) - - print(f"DEBUG: Number of tasks returned: {count}") - - tasks = frappe.db.get_all( - "Task", - fields=["*"], - filters=filters, - limit=page_size, - start=(page - 1) * page_size, - order_by=processed_sortings - ) - - tableRows = [] - for task in tasks: - print("DEBUG: Processing task:", task) - tableRow = {} - tableRow["id"] = task["name"] - tableRow["subject"] = task["subject"] - tableRow["project"] = task["project"] - tableRow["address"] = task.get("custom_property", "") - tableRow["status"] = task.get("status", "") - tableRow["type"] = task.get("type", "") - tableRows.append(tableRow) - - table_data_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size) - return build_success_response(table_data_dict) - - @frappe.whitelist() def get_job_task_list(job_id=""): if job_id: @@ -56,35 +15,37 @@ def get_job_task_list(job_id=""): @frappe.whitelist() def get_tasks_table_data(filters={}, sortings=[], page=1, page_size=10): - """Get paginated job table data with filtering and sorting support.""" - print("DEBUG: Raw job options received:", filters, sortings, page, page_size) + """Get paginated task table data with filtering and sorting support.""" + try: + print("DEBUG: Raw task options received:", filters, sortings, page, page_size) - processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size) + processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size) - # Handle count with proper OR filter support - if is_or: - count = frappe.db.sql(*get_count_or_filters("Task", processed_filters))[0][0] - else: count = frappe.db.count("Task", filters=processed_filters) - tasks = frappe.db.get_all( - "Task", - fields=["*"], - filters=processed_filters if not is_or else None, - or_filters=processed_filters if is_or else None, - limit=page_size, - start=(page - 1) * page_size, - order_by=processed_sortings - ) + tasks = frappe.db.get_all( + "Task", + fields=["*"], + filters=processed_filters if not is_or else None, + or_filters=processed_filters if is_or else None, + limit=page_size, + start=(page - 1) * page_size, + order_by=processed_sortings + ) - tableRows = [] - for task in tasks: - tableRow = {} - tableRow["id"] = task["name"] - tableRow["subject"] = task["subject"] - tableRow["address"] = task.get("custom_property", "") - tableRow["status"] = task.get("status", "") - tableRows.append(tableRow) + tableRows = [] + for task in tasks: + tableRow = {} + tableRow["id"] = task["name"] + tableRow["subject"] = task["subject"] + tableRow["project"] = task["project"] + tableRow["address"] = task.get("custom_property", "") + tableRow["status"] = task.get("status", "") + tableRows.append(tableRow) - data_table_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size) - return build_success_response(data_table_dict) + data_table_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size) + return build_success_response(data_table_dict) + except frappe.ValidationError as ve: + return build_error_response(str(ve), 400) + except Exception as e: + return build_error_response(str(e), 500) diff --git a/frontend/src/api.js b/frontend/src/api.js index 0a3f447..516c2c8 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -22,7 +22,7 @@ const FRAPPE_GET_JOB_TASK_LIST_METHOD = "custom_ui.api.db.jobs.get_job_task_tabl const FRAPPE_GET_INSTALL_PROJECTS_METHOD = "custom_ui.api.db.jobs.get_install_projects"; const FRAPPE_GET_JOB_TEMPLATES_METHOD = "custom_ui.api.db.jobs.get_job_templates"; // Task methods -const FRAPPE_GET_TASKS_METHOD = "custom_ui.api.db.tasks.get_job_task_table_data"; +const FRAPPE_GET_TASKS_METHOD = "custom_ui.api.db.tasks.get_tasks_table_data"; // Invoice methods const FRAPPE_GET_INVOICES_METHOD = "custom_ui.api.db.invoices.get_invoice_table_data"; const FRAPPE_UPSERT_INVOICE_METHOD = "custom_ui.api.db.invoices.upsert_invoice"; @@ -359,20 +359,28 @@ class Api { const actualSortField = sorting?.field || sortField; const actualSortOrder = sorting?.order || sortOrder; - const options = { - page: page + 1, // Backend expects 1-based pages - page_size: pageSize, - filters, - sorting: - actualSortField && actualSortOrder + //const options = { + // page: page + 1, // Backend expects 1-based pages + // page_size: pageSize, + // filters, + // sorting: + // actualSortField && actualSortOrder + // ? `${actualSortField} ${actualSortOrder === -1 ? "desc" : "asc"}` + // : null, + // for_table: true, + //}; + + const sortings = actualSortField && actualSortOrder ? `${actualSortField} ${actualSortOrder === -1 ? "desc" : "asc"}` - : null, - for_table: true, - }; + : null; + console.log("DEBUG: API - Sending task options to backend:", page, pageSize, filters, sortings); - console.log("DEBUG: API - Sending task options to backend:", options); - - const result = await this.request(FRAPPE_GET_TASKS_METHOD, { options }); + const result = await this.request(FRAPPE_GET_TASKS_METHOD, { + filters, + sorting, + page: page + 1, + pageSize, + }); return result; } diff --git a/frontend/src/components/pages/Tasks.vue b/frontend/src/components/pages/Tasks.vue index 2630b06..2824c68 100644 --- a/frontend/src/components/pages/Tasks.vue +++ b/frontend/src/components/pages/Tasks.vue @@ -44,7 +44,7 @@ const currentFilters = computed(() => { const columns = [ { label: "Task", fieldName: "subject", type: "text", sortable: true, filterable: true }, - { label: "Project", fieldName: "project", type: "link", sortable: true, + { label: "Job", fieldName: "project", type: "link", sortable: true, onLinkClick: (link, rowData) => handleProjectClick(link, rowData) }, { label: "Address", fieldName: "address", type: "link", sortable: true, @@ -154,6 +154,14 @@ const handlePropertyClick = (link, rowData) => { // router.push(`/task?taskId=${rowData.name}`); //} +watch( + () => filtersStore.getTableFilters("clients"), + async () => { + await refreshStatusCounts(); + }, + { deep: true }, +); + // Load initial data onMounted(async () => { notifications.addWarning("Tasks page coming soon"); @@ -173,6 +181,7 @@ onMounted(async () => { first: initialPagination.first, sortField: initialSorting.field || initialPagination.sortField, sortOrder: initialSorting.order || initialPagination.sortOrder, + filters: initialFilters, }); });