Fixed pagination errors on the Task page, updated to the correct API calls to get that data.
This commit is contained in:
parent
59e21a51f2
commit
84c7eb0580
3 changed files with 59 additions and 81 deletions
|
|
@ -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
|
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()
|
@frappe.whitelist()
|
||||||
def get_job_task_list(job_id=""):
|
def get_job_task_list(job_id=""):
|
||||||
if job_id:
|
if job_id:
|
||||||
|
|
@ -56,15 +15,12 @@ def get_job_task_list(job_id=""):
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_tasks_table_data(filters={}, sortings=[], page=1, page_size=10):
|
def get_tasks_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||||
"""Get paginated job table data with filtering and sorting support."""
|
"""Get paginated task table data with filtering and sorting support."""
|
||||||
print("DEBUG: Raw job options received:", filters, sortings, page, page_size)
|
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)
|
count = frappe.db.count("Task", filters=processed_filters)
|
||||||
|
|
||||||
tasks = frappe.db.get_all(
|
tasks = frappe.db.get_all(
|
||||||
|
|
@ -82,9 +38,14 @@ def get_tasks_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||||
tableRow = {}
|
tableRow = {}
|
||||||
tableRow["id"] = task["name"]
|
tableRow["id"] = task["name"]
|
||||||
tableRow["subject"] = task["subject"]
|
tableRow["subject"] = task["subject"]
|
||||||
|
tableRow["project"] = task["project"]
|
||||||
tableRow["address"] = task.get("custom_property", "")
|
tableRow["address"] = task.get("custom_property", "")
|
||||||
tableRow["status"] = task.get("status", "")
|
tableRow["status"] = task.get("status", "")
|
||||||
tableRows.append(tableRow)
|
tableRows.append(tableRow)
|
||||||
|
|
||||||
data_table_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
data_table_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||||
return build_success_response(data_table_dict)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -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_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";
|
const FRAPPE_GET_JOB_TEMPLATES_METHOD = "custom_ui.api.db.jobs.get_job_templates";
|
||||||
// Task methods
|
// 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
|
// Invoice methods
|
||||||
const FRAPPE_GET_INVOICES_METHOD = "custom_ui.api.db.invoices.get_invoice_table_data";
|
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";
|
const FRAPPE_UPSERT_INVOICE_METHOD = "custom_ui.api.db.invoices.upsert_invoice";
|
||||||
|
|
@ -359,20 +359,28 @@ class Api {
|
||||||
const actualSortField = sorting?.field || sortField;
|
const actualSortField = sorting?.field || sortField;
|
||||||
const actualSortOrder = sorting?.order || sortOrder;
|
const actualSortOrder = sorting?.order || sortOrder;
|
||||||
|
|
||||||
const options = {
|
//const options = {
|
||||||
page: page + 1, // Backend expects 1-based pages
|
// page: page + 1, // Backend expects 1-based pages
|
||||||
page_size: pageSize,
|
// page_size: pageSize,
|
||||||
filters,
|
// filters,
|
||||||
sorting:
|
// sorting:
|
||||||
actualSortField && actualSortOrder
|
// actualSortField && actualSortOrder
|
||||||
|
// ? `${actualSortField} ${actualSortOrder === -1 ? "desc" : "asc"}`
|
||||||
|
// : null,
|
||||||
|
// for_table: true,
|
||||||
|
//};
|
||||||
|
|
||||||
|
const sortings = actualSortField && actualSortOrder
|
||||||
? `${actualSortField} ${actualSortOrder === -1 ? "desc" : "asc"}`
|
? `${actualSortField} ${actualSortOrder === -1 ? "desc" : "asc"}`
|
||||||
: null,
|
: null;
|
||||||
for_table: true,
|
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, {
|
||||||
|
filters,
|
||||||
const result = await this.request(FRAPPE_GET_TASKS_METHOD, { options });
|
sorting,
|
||||||
|
page: page + 1,
|
||||||
|
pageSize,
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ const currentFilters = computed(() => {
|
||||||
|
|
||||||
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: "Job", fieldName: "project", type: "link", sortable: true,
|
||||||
onLinkClick: (link, rowData) => handleProjectClick(link, rowData)
|
onLinkClick: (link, rowData) => handleProjectClick(link, rowData)
|
||||||
},
|
},
|
||||||
{ label: "Address", fieldName: "address", type: "link", sortable: true,
|
{ label: "Address", fieldName: "address", type: "link", sortable: true,
|
||||||
|
|
@ -154,6 +154,14 @@ const handlePropertyClick = (link, rowData) => {
|
||||||
// router.push(`/task?taskId=${rowData.name}`);
|
// router.push(`/task?taskId=${rowData.name}`);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => filtersStore.getTableFilters("clients"),
|
||||||
|
async () => {
|
||||||
|
await refreshStatusCounts();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
// Load initial data
|
// Load initial data
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
notifications.addWarning("Tasks page coming soon");
|
notifications.addWarning("Tasks page coming soon");
|
||||||
|
|
@ -173,6 +181,7 @@ onMounted(async () => {
|
||||||
first: initialPagination.first,
|
first: initialPagination.first,
|
||||||
sortField: initialSorting.field || initialPagination.sortField,
|
sortField: initialSorting.field || initialPagination.sortField,
|
||||||
sortOrder: initialSorting.order || initialPagination.sortOrder,
|
sortOrder: initialSorting.order || initialPagination.sortOrder,
|
||||||
|
filters: initialFilters,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue