From 60bf81d4392f6067a54fa6138620cf59c097d62e Mon Sep 17 00:00:00 2001 From: faiztyanirh Date: Wed, 8 Apr 2026 13:58:34 +0700 Subject: [PATCH] change edit to patch on many pages --- .../dictionary/account/api/account-api.js | 4 ++-- .../account/config/account-config.js | 8 +++---- .../dictionary/account/page/edit-page.svelte | 22 ++++++++++++++++++- .../container/config/container-config.js | 2 +- .../department/api/department-api.js | 4 ++-- .../department/config/department-config.js | 4 ++-- .../department/page/edit-page.svelte | 22 ++++++++++++++++++- .../discipline/api/discipline-api.js | 4 ++-- .../discipline/config/discipline-config.js | 2 ++ .../config/discipline-form-config.js | 19 ++++++++++++++++ .../discipline/page/edit-page.svelte | 22 ++++++++++++++++++- .../location/config/location-config.js | 6 ++--- .../dictionary/site/api/site-api.js | 4 ++-- .../dictionary/site/config/site-config.js | 21 +++++------------- .../dictionary/site/page/edit-page.svelte | 22 ++++++++++++++++++- .../workstation/api/workstation-api.js | 4 ++-- .../workstation/config/workstation-config.js | 6 +++-- .../config/workstation-form-config.js | 11 ++++++---- .../workstation/page/edit-page.svelte | 22 ++++++++++++++++++- src/routes/dictionary/department/+page.svelte | 1 + src/routes/dictionary/discipline/+page.svelte | 1 + src/routes/dictionary/site/+page.svelte | 1 + .../dictionary/workstation/+page.svelte | 1 + 23 files changed, 166 insertions(+), 47 deletions(-) diff --git a/src/lib/components/dictionary/account/api/account-api.js b/src/lib/components/dictionary/account/api/account-api.js index 2986020..d1b39df 100644 --- a/src/lib/components/dictionary/account/api/account-api.js +++ b/src/lib/components/dictionary/account/api/account-api.js @@ -14,6 +14,6 @@ export async function createAccount(newAccountForm) { return await create(API.ACCOUNT, newAccountForm) } -export async function editAccount(editAccountForm) { - return await update(API.ACCOUNT, editAccountForm) +export async function editAccount(editAccountForm, id) { + return await update(API.ACCOUNT, editAccountForm, id) } \ No newline at end of file diff --git a/src/lib/components/dictionary/account/config/account-config.js b/src/lib/components/dictionary/account/config/account-config.js index d1d5690..de85664 100644 --- a/src/lib/components/dictionary/account/config/account-config.js +++ b/src/lib/components/dictionary/account/config/account-config.js @@ -35,9 +35,10 @@ export const detailSections = [ { class: "space-y-3", fields: [ - { key: "Country", label: "Country" }, - { key: "Province", label: "Province" }, - { key: "City", label: "City" }, + { key: "CountryLabel", label: "Country" }, + { key: "ProvinceLabel", label: "Province" }, + { key: "CityLabel", label: "City" }, + { key: "ZIP", label: "ZIP" }, ] }, { @@ -46,7 +47,6 @@ export const detailSections = [ { key: "Street_1", label: "Street 1" }, { key: "Street_2", label: "Street 2" }, { key: "Street_3", label: "Street 3" }, - { key: "ZIP", label: "ZIP" }, ] } ] diff --git a/src/lib/components/dictionary/account/page/edit-page.svelte b/src/lib/components/dictionary/account/page/edit-page.svelte index aaff3bf..986cc3f 100644 --- a/src/lib/components/dictionary/account/page/edit-page.svelte +++ b/src/lib/components/dictionary/account/page/edit-page.svelte @@ -6,6 +6,7 @@ import { untrack } from "svelte"; import { API } from "$lib/config/api"; import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte"; + import { getChangedFields } from "$lib/utils/getChangedFields"; let props = $props(); @@ -50,7 +51,24 @@ }); async function handleEdit() { - const result = await formState.save(masterDetail.mode); + const currentPayload = formState.form; + const originalPayload = masterDetail.formSnapshot; + + const changedFields = getChangedFields(originalPayload, currentPayload); + + if (Object.keys(changedFields).length === 0) { + toast('No changes detected'); + return; + } + + const payload = { + AccountID: formState.form.AccountID, + ...changedFields + }; + + console.log('Payload:', payload); + + const result = await formState.save(masterDetail.mode, payload); if (result.status === 'success') { console.log('Account updated successfully'); @@ -58,6 +76,8 @@ masterDetail.exitForm(true); } else { console.error('Failed to update account:', result.message); + const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update account'; + toast.error(errorMessages) } } diff --git a/src/lib/components/dictionary/container/config/container-config.js b/src/lib/components/dictionary/container/config/container-config.js index e89e757..15d2f2f 100644 --- a/src/lib/components/dictionary/container/config/container-config.js +++ b/src/lib/components/dictionary/container/config/container-config.js @@ -29,7 +29,7 @@ export const detailSections = [ class: "grid grid-cols-2 gap-4 items-center", fields: [ { key: "ConClassLabel", label: "Container Class" }, - { key: "Color", label: "Color" }, + { key: "ColorLabel", label: "Color" }, { key: "AdditiveLabel", label: "Additive" }, ] }, diff --git a/src/lib/components/dictionary/department/api/department-api.js b/src/lib/components/dictionary/department/api/department-api.js index b9b032f..ab534dc 100644 --- a/src/lib/components/dictionary/department/api/department-api.js +++ b/src/lib/components/dictionary/department/api/department-api.js @@ -13,6 +13,6 @@ export async function createDepartment(newDepartmentForm) { return await create(API.DEPARTMENT, newDepartmentForm) } -export async function editDepartment(editDepartmentForm) { - return await update(API.DEPARTMENT, editDepartmentForm) +export async function editDepartment(editDepartmentForm, id) { + return await update(API.DEPARTMENT, editDepartmentForm, id) } \ No newline at end of file diff --git a/src/lib/components/dictionary/department/config/department-config.js b/src/lib/components/dictionary/department/config/department-config.js index e2206e3..1863679 100644 --- a/src/lib/components/dictionary/department/config/department-config.js +++ b/src/lib/components/dictionary/department/config/department-config.js @@ -20,8 +20,8 @@ export const detailSections = [ { class: "grid grid-cols-2 gap-4 items-center", fields: [ - { key: "SiteID", label: "Site" }, - { key: "DisciplineID", label: "Discipline" }, + { key: "SiteName", label: "Site" }, + { key: "DisciplineName", label: "Discipline" }, { key: "DepartmentCode", label: "Department Code" }, { key: "DepartmentName", label: "Department Name" }, ] diff --git a/src/lib/components/dictionary/department/page/edit-page.svelte b/src/lib/components/dictionary/department/page/edit-page.svelte index 0411b91..d8d8e31 100644 --- a/src/lib/components/dictionary/department/page/edit-page.svelte +++ b/src/lib/components/dictionary/department/page/edit-page.svelte @@ -6,6 +6,7 @@ import { untrack } from "svelte"; import { API } from "$lib/config/api"; import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte"; + import { getChangedFields } from "$lib/utils/getChangedFields"; let props = $props(); @@ -38,7 +39,24 @@ }); async function handleEdit() { - const result = await formState.save(masterDetail.mode); + const currentPayload = formState.form; + const originalPayload = masterDetail.formSnapshot; + + const changedFields = getChangedFields(originalPayload, currentPayload); + + if (Object.keys(changedFields).length === 0) { + toast('No changes detected'); + return; + } + + const payload = { + DepartmentID: formState.form.DepartmentID, + ...changedFields + }; + + console.log('Payload:', payload); + + const result = await formState.save(masterDetail.mode, payload); if (result.status === 'success') { console.log('Department updated successfully'); @@ -46,6 +64,8 @@ masterDetail.exitForm(true); } else { console.error('Failed to update department:', result.message); + const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update department'; + toast.error(errorMessages) } } diff --git a/src/lib/components/dictionary/discipline/api/discipline-api.js b/src/lib/components/dictionary/discipline/api/discipline-api.js index 345c51a..8bb384c 100644 --- a/src/lib/components/dictionary/discipline/api/discipline-api.js +++ b/src/lib/components/dictionary/discipline/api/discipline-api.js @@ -13,6 +13,6 @@ export async function createDiscipline(newDisciplineForm) { return await create(API.DISCIPLINE, newDisciplineForm) } -export async function editDiscipline(editDisciplineForm) { - return await update(API.DISCIPLINE, editDisciplineForm) +export async function editDiscipline(editDisciplineForm, id) { + return await update(API.DISCIPLINE, editDisciplineForm, id) } \ No newline at end of file diff --git a/src/lib/components/dictionary/discipline/config/discipline-config.js b/src/lib/components/dictionary/discipline/config/discipline-config.js index 086ca81..185b557 100644 --- a/src/lib/components/dictionary/discipline/config/discipline-config.js +++ b/src/lib/components/dictionary/discipline/config/discipline-config.js @@ -24,6 +24,8 @@ export const detailSections = [ { key: "Parent", label: "Parent" }, { key: "DisciplineCode", label: "Discipline Code" }, { key: "DisciplineName", label: "Discipline Name" }, + { key: "SeqSrc", label: "Sequence on Screen" }, + { key: "SeqRpt", label: "Sequence on Report" }, ] }, ]; diff --git a/src/lib/components/dictionary/discipline/config/discipline-form-config.js b/src/lib/components/dictionary/discipline/config/discipline-form-config.js index 92e97d4..480b445 100644 --- a/src/lib/components/dictionary/discipline/config/discipline-form-config.js +++ b/src/lib/components/dictionary/discipline/config/discipline-form-config.js @@ -13,6 +13,8 @@ export const disciplineInitialForm = { Parent: '', DisciplineCode: '', DisciplineName: '', + SeqScr: '', + SeqRpt: '', }; export const disciplineDefaultErrors = { @@ -66,6 +68,23 @@ export const disciplineFormFields = [ }, ] }, + { + type: "row", + columns: [ + { + key: "SeqSrc", + label: "Sequence on Screen", + required: false, + type: "number", + }, + { + key: "SeqRpt", + label: "Sequence on Report", + required: false, + type: "number", + }, + ] + }, ] }, ]; diff --git a/src/lib/components/dictionary/discipline/page/edit-page.svelte b/src/lib/components/dictionary/discipline/page/edit-page.svelte index e2f0880..c7da88a 100644 --- a/src/lib/components/dictionary/discipline/page/edit-page.svelte +++ b/src/lib/components/dictionary/discipline/page/edit-page.svelte @@ -6,6 +6,7 @@ import { untrack } from "svelte"; import { API } from "$lib/config/api"; import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte"; + import { getChangedFields } from "$lib/utils/getChangedFields"; let props = $props(); @@ -38,7 +39,24 @@ }); async function handleEdit() { - const result = await formState.save(masterDetail.mode); + const currentPayload = formState.form; + const originalPayload = masterDetail.formSnapshot; + + const changedFields = getChangedFields(originalPayload, currentPayload); + + if (Object.keys(changedFields).length === 0) { + toast('No changes detected'); + return; + } + + const payload = { + DisciplineID: formState.form.DisciplineID, + ...changedFields + }; + + console.log('Payload:', payload); + + const result = await formState.save(masterDetail.mode, payload); if (result.status === 'success') { console.log('Discipline updated successfully'); @@ -46,6 +64,8 @@ masterDetail.exitForm(true); } else { console.error('Failed to update discipline:', result.message); + const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update discipline'; + toast.error(errorMessages) } } diff --git a/src/lib/components/dictionary/location/config/location-config.js b/src/lib/components/dictionary/location/config/location-config.js index 41aebae..c6883f2 100644 --- a/src/lib/components/dictionary/location/config/location-config.js +++ b/src/lib/components/dictionary/location/config/location-config.js @@ -30,7 +30,7 @@ export const detailSections = [ { key: "Parent", label: "Parent" }, { key: "LocCode", label: "Location Code" }, { key: "LocFull", label: "Location Name" }, - { key: "LocType", label: "Location Type" }, + { key: "LocTypeLabel", label: "Location Type" }, { key: "Description", label: "Description" }, ] }, @@ -41,8 +41,8 @@ export const detailSections = [ { class: "space-y-3", fields: [ - { key: "Province", label: "Province" }, - { key: "City", label: "City" }, + { key: "ProvinceLabel", label: "Province" }, + { key: "CityLabel", label: "City" }, { key: "PostCode", label: "Post Code" }, { key: "Email", label: "Email" }, ] diff --git a/src/lib/components/dictionary/site/api/site-api.js b/src/lib/components/dictionary/site/api/site-api.js index cb61a4c..d9d74b6 100644 --- a/src/lib/components/dictionary/site/api/site-api.js +++ b/src/lib/components/dictionary/site/api/site-api.js @@ -13,6 +13,6 @@ export async function createSite(newSiteForm) { return await create(API.SITE, newSiteForm) } -export async function editSite(editSiteForm) { - return await update(API.SITE, editSiteForm) +export async function editSite(editSiteForm, id) { + return await update(API.SITE, editSiteForm, id) } \ No newline at end of file diff --git a/src/lib/components/dictionary/site/config/site-config.js b/src/lib/components/dictionary/site/config/site-config.js index 3ea77ab..c0029f0 100644 --- a/src/lib/components/dictionary/site/config/site-config.js +++ b/src/lib/components/dictionary/site/config/site-config.js @@ -27,22 +27,11 @@ export const detailSections = [ ] }, { - title: "", - class: "grid grid-cols-2 gap-4", - groups: [ - { - class: "space-y-3", - fields: [ - { key: "SiteType", label: "Site Type" }, - ] - }, - { - class: "space-y-3", - fields: [ - { key: "SiteClass", label: "Site Class" }, - ] - } - ] + class: "grid grid-cols-2 gap-4 items-center", + fields: [ + { key: "SiteType", label: "Site Type" }, + { key: "SiteClass", label: "Site Class" }, + ], }, ]; diff --git a/src/lib/components/dictionary/site/page/edit-page.svelte b/src/lib/components/dictionary/site/page/edit-page.svelte index f837a63..577c4d7 100644 --- a/src/lib/components/dictionary/site/page/edit-page.svelte +++ b/src/lib/components/dictionary/site/page/edit-page.svelte @@ -6,6 +6,7 @@ import { untrack } from "svelte"; import { API } from "$lib/config/api"; import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte"; + import { getChangedFields } from "$lib/utils/getChangedFields"; let props = $props(); @@ -38,7 +39,24 @@ }); async function handleEdit() { - const result = await formState.save(masterDetail.mode); + const currentPayload = formState.form; + const originalPayload = masterDetail.formSnapshot; + + const changedFields = getChangedFields(originalPayload, currentPayload); + + if (Object.keys(changedFields).length === 0) { + toast('No changes detected'); + return; + } + + const payload = { + SiteID: formState.form.SiteID, + ...changedFields + }; + + console.log('Payload:', payload); + + const result = await formState.save(masterDetail.mode, payload); if (result.status === 'success') { console.log('Site updated successfully'); @@ -46,6 +64,8 @@ masterDetail.exitForm(true); } else { console.error('Failed to update site:', result.message); + const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update site'; + toast.error(errorMessages) } } diff --git a/src/lib/components/dictionary/workstation/api/workstation-api.js b/src/lib/components/dictionary/workstation/api/workstation-api.js index 792b793..0d64694 100644 --- a/src/lib/components/dictionary/workstation/api/workstation-api.js +++ b/src/lib/components/dictionary/workstation/api/workstation-api.js @@ -13,6 +13,6 @@ export async function createWorkstation(newWorkstationForm) { return await create(API.WORKSTATION, newWorkstationForm) } -export async function editWorkstation(editWorkstationForm) { - return await update(API.WORKSTATION, editWorkstationForm) +export async function editWorkstation(editWorkstationForm, id) { + return await update(API.WORKSTATION, editWorkstationForm, id) } \ No newline at end of file diff --git a/src/lib/components/dictionary/workstation/config/workstation-config.js b/src/lib/components/dictionary/workstation/config/workstation-config.js index 6140bb2..98d338e 100644 --- a/src/lib/components/dictionary/workstation/config/workstation-config.js +++ b/src/lib/components/dictionary/workstation/config/workstation-config.js @@ -20,10 +20,12 @@ export const detailSections = [ { class: "grid grid-cols-2 gap-4 items-center", fields: [ - { key: "DepartmentID", label: "Department" }, - { key: "Type", label: "Type" }, + { key: "DepartmentName", label: "Department" }, + { key: "TypeLabel", label: "Type" }, { key: "WorkstationCode", label: "Workstation Code" }, { key: "WorkstationName", label: "Workstation Name" }, + { key: "LinkToName", label: "Link To" }, + { key: "isEnableLabel", label: "Enable" }, ] }, ]; diff --git a/src/lib/components/dictionary/workstation/config/workstation-form-config.js b/src/lib/components/dictionary/workstation/config/workstation-form-config.js index 680df9e..f26d186 100644 --- a/src/lib/components/dictionary/workstation/config/workstation-form-config.js +++ b/src/lib/components/dictionary/workstation/config/workstation-form-config.js @@ -14,7 +14,7 @@ export const workstationInitialForm = { WorkstationName: '', Type: '', LinkTo: '', - Enable: '', + isEnable: '1', }; export const workstationDefaultErrors = { @@ -84,11 +84,14 @@ export const workstationFormFields = [ labelKey: "WorkstationName", }, { - key: "Enable", + key: "isEnable", label: "Enable", required: false, - type: "select", - optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/enable_disable`, + type: "toggle", + optionsToggle: [ + { value: 0, label: 'Disabled' }, + { value: 1, label: 'Enabled' } + ] }, ] }, diff --git a/src/lib/components/dictionary/workstation/page/edit-page.svelte b/src/lib/components/dictionary/workstation/page/edit-page.svelte index 7a13800..b20b1d8 100644 --- a/src/lib/components/dictionary/workstation/page/edit-page.svelte +++ b/src/lib/components/dictionary/workstation/page/edit-page.svelte @@ -6,6 +6,7 @@ import { untrack } from "svelte"; import { API } from "$lib/config/api"; import ReusableAlertDialog from "$lib/components/reusable/reusable-alert-dialog.svelte"; + import { getChangedFields } from "$lib/utils/getChangedFields"; let props = $props(); @@ -38,7 +39,24 @@ }); async function handleEdit() { - const result = await formState.save(masterDetail.mode); + const currentPayload = formState.form; + const originalPayload = masterDetail.formSnapshot; + + const changedFields = getChangedFields(originalPayload, currentPayload); + + if (Object.keys(changedFields).length === 0) { + toast('No changes detected'); + return; + } + + const payload = { + WorkstationID: formState.form.WorkstationID, + ...changedFields + }; + + console.log('Payload:', payload); + + const result = await formState.save(masterDetail.mode, payload); if (result.status === 'success') { console.log('Workstation updated successfully'); @@ -46,6 +64,8 @@ masterDetail.exitForm(true); } else { console.error('Failed to update workstation:', result.message); + const errorMessages = result.messages ? Object.values(result.messages).join('\n') : 'Failed to update workstation'; + toast.error(errorMessages) } } diff --git a/src/routes/dictionary/department/+page.svelte b/src/routes/dictionary/department/+page.svelte index 757921d..0d32916 100644 --- a/src/routes/dictionary/department/+page.svelte +++ b/src/routes/dictionary/department/+page.svelte @@ -20,6 +20,7 @@ modeOpt: 'default', saveEndpoint: createDepartment, editEndpoint: editDepartment, + idKey: 'DepartmentID', } }); diff --git a/src/routes/dictionary/discipline/+page.svelte b/src/routes/dictionary/discipline/+page.svelte index 5f75961..514c4f1 100644 --- a/src/routes/dictionary/discipline/+page.svelte +++ b/src/routes/dictionary/discipline/+page.svelte @@ -20,6 +20,7 @@ modeOpt: 'default', saveEndpoint: createDiscipline, editEndpoint: editDiscipline, + idKey: 'DisciplineID', } }); diff --git a/src/routes/dictionary/site/+page.svelte b/src/routes/dictionary/site/+page.svelte index db032a9..97e25e4 100644 --- a/src/routes/dictionary/site/+page.svelte +++ b/src/routes/dictionary/site/+page.svelte @@ -20,6 +20,7 @@ modeOpt: 'default', saveEndpoint: createSite, editEndpoint: editSite, + idKey: 'SiteID', } }); diff --git a/src/routes/dictionary/workstation/+page.svelte b/src/routes/dictionary/workstation/+page.svelte index a9b05bc..d480b70 100644 --- a/src/routes/dictionary/workstation/+page.svelte +++ b/src/routes/dictionary/workstation/+page.svelte @@ -20,6 +20,7 @@ modeOpt: 'default', saveEndpoint: createWorkstation, editEndpoint: editWorkstation, + idKey: 'WorkstationID', } });