moving towards real data
This commit is contained in:
parent
ac3c05cb78
commit
40c4a5a37f
8 changed files with 303 additions and 84 deletions
|
|
@ -7,13 +7,15 @@ const FRAPPE_UPSERT_CLIENT_METHOD = "custom_ui.api.db.upsert_client";
|
|||
|
||||
class Api {
|
||||
static async request(frappeMethod, args = {}) {
|
||||
args = DataUtils.toSnakeCaseObject(args);
|
||||
try {
|
||||
const response = await frappe.call({
|
||||
let response = await frappe.call({
|
||||
method: frappeMethod,
|
||||
args: {
|
||||
...args,
|
||||
},
|
||||
});
|
||||
response = DataUtils.toCamelCaseObject(response);
|
||||
console.log("DEBUG: API - Request Response: ", response);
|
||||
return response.message;
|
||||
} catch (error) {
|
||||
|
|
@ -24,39 +26,26 @@ class Api {
|
|||
}
|
||||
|
||||
static async getClientDetails(options = {}) {
|
||||
const {
|
||||
forTable = true,
|
||||
page = 0,
|
||||
pageSize = 10,
|
||||
filters = {},
|
||||
sortField = null,
|
||||
sortOrder = null,
|
||||
searchTerm = null,
|
||||
} = options;
|
||||
return await this.request("custom_ui.api.db.get_clients", { options });
|
||||
|
||||
console.log("DEBUG: API - getClientDetails called with options:", options);
|
||||
|
||||
// Build filters for the Address query
|
||||
let addressFilters = {};
|
||||
|
||||
// Add search functionality across multiple fields
|
||||
if (searchTerm) {
|
||||
// Note: This is a simplified version. You might want to implement
|
||||
// full-text search on the backend for better performance
|
||||
// Handle fullName filter by searching in multiple fields
|
||||
// Since fullName is constructed from customer_name + address_line1 + city + state,
|
||||
// we need to search across these fields
|
||||
if (filters.addressTitle && filters.addressTitle.value) {
|
||||
const searchTerm = filters.addressTitle.value;
|
||||
// Search in address fields - this is a simplified approach
|
||||
// In a real implementation, you'd want to join with Customer table and search across all fields
|
||||
addressFilters.address_line1 = ["like", `%${searchTerm}%`];
|
||||
}
|
||||
|
||||
// Add any custom filters
|
||||
// Add any other custom filters
|
||||
Object.keys(filters).forEach((key) => {
|
||||
if (filters[key] && filters[key].value) {
|
||||
// Map frontend filter names to backend field names if needed
|
||||
switch (key) {
|
||||
case "fullName":
|
||||
// This will need special handling since fullName is constructed
|
||||
// For now, we'll search in address_line1 or city
|
||||
addressFilters.address_line1 = ["like", `%${filters[key].value}%`];
|
||||
break;
|
||||
if (filters[key] && filters[key].value && key !== "fullName") {
|
||||
// Map other frontend filter names to backend field names if needed
|
||||
switch (
|
||||
key
|
||||
// Add other filter mappings as needed
|
||||
) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -161,20 +150,15 @@ class Api {
|
|||
});
|
||||
}
|
||||
|
||||
// Apply client-side filtering for constructed fields like fullName
|
||||
// Since we're applying filters at the database level, use the fetched data as-is
|
||||
let filteredData = data;
|
||||
if (filters.fullName && filters.fullName.value && forTable) {
|
||||
const searchValue = filters.fullName.value.toLowerCase();
|
||||
filteredData = data.filter((item) =>
|
||||
item.fullName.toLowerCase().includes(searchValue),
|
||||
);
|
||||
}
|
||||
|
||||
console.log("DEBUG: API - Fetched Client Details:", {
|
||||
total: totalCount,
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
returned: filteredData.length,
|
||||
filtersApplied: Object.keys(addressFilters).length > 0,
|
||||
});
|
||||
|
||||
// Return paginated response with metadata
|
||||
|
|
@ -198,7 +182,7 @@ class Api {
|
|||
// ...job,
|
||||
// stepProgress: DataUtils.calculateStepProgress(job.steps),
|
||||
//}));
|
||||
const projects = await this.getDocsList("Project")
|
||||
const projects = await this.getDocsList("Project");
|
||||
const data = [];
|
||||
for (let prj of projects) {
|
||||
let project = await this.getDetailedDoc("Project", prj.name);
|
||||
|
|
@ -207,7 +191,7 @@ class Api {
|
|||
customInstallationAddress: project.custom_installation_address,
|
||||
customer: project.customer,
|
||||
status: project.status,
|
||||
percentComplete: project.percent_complete
|
||||
percentComplete: project.percent_complete,
|
||||
};
|
||||
data.push(tableRow);
|
||||
}
|
||||
|
|
@ -249,8 +233,7 @@ class Api {
|
|||
const { page = 0, pageSize = 10, sortField = null, sortOrder = null } = paginationParams;
|
||||
|
||||
const options = {
|
||||
forTable: true,
|
||||
page,
|
||||
page: page + 1,
|
||||
pageSize,
|
||||
filters,
|
||||
sortField,
|
||||
|
|
@ -260,8 +243,7 @@ class Api {
|
|||
const result = await this.getClientDetails(options);
|
||||
|
||||
return {
|
||||
data: result.data,
|
||||
totalRecords: result.pagination.total,
|
||||
...result,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -277,10 +259,13 @@ class Api {
|
|||
const docs = await frappe.db.get_list(doctype, {
|
||||
fields,
|
||||
filters,
|
||||
start: page * pageLength,
|
||||
start: start,
|
||||
limit: pageLength,
|
||||
});
|
||||
console.log(`DEBUG: API - Fetched ${doctype} list: `, docs);
|
||||
console.log(
|
||||
`DEBUG: API - Fetched ${doctype} list (page ${page + 1}, start ${start}): `,
|
||||
docs,
|
||||
);
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue