storeData insignia,insigniaType

This commit is contained in:
AnandaTon 2023-06-13 15:07:18 +07:00
parent b5069d1991
commit 293d8b7c6e
3 changed files with 286 additions and 74 deletions

View file

@ -303,8 +303,8 @@ const { loaderPage } = dataStore;
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { success, dateText, messageError, showLoader, hideLoader } = mixin; const { success, dateText, messageError, showLoader, hideLoader } = mixin;
const store = useManageDataStore(); const store = useManageDataStore();
const { manageData, changeManageColumns } = store; const { manageData, changeManageColumns, getInsignia, dataInsignia } = store;
const rows = ref<RequestItemsHistoryObject[]>([]); //list data table const rows = ref<RequestItemsHistoryObject[]>(dataInsignia); //list data table
const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history
const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history
const tittleHistory = ref<string>("ประวัติแก้ไขชื่อเครื่องราชฯ"); // const tittleHistory = ref<string>("ประวัติแก้ไขชื่อเครื่องราชฯ"); //
@ -574,46 +574,51 @@ const $q = useQuasar();
/** /**
* งก get data าส * งก get data าส
*/ */
const fetchData = async () => { const fetchData = async (load: boolean = false) => {
await props.fetchDataComponent(); await props.fetchDataComponent();
rows.value.splice(0); const result = await getInsignia(false, load);
showLoader(); version.value = result.version; // published= draft=
await http idVersion.value = result.idversion; // id mongodb
.get(config.API.listInsigniaHistory) rows.value = result.data;
.then((res) => { updateData.value = false;
let data = res.data.result; // rows.value.splice(0);
version.value = data.version; // published= draft= // showLoader();
idVersion.value = data.id; // id mongodb // await http
data.items.map((e: RequestItemsHistoryObject) => { // .get(config.API.listInsigniaHistory)
rows.value.push({ // .then((res) => {
id: e.id, // let data = res.data.result;
name: e.name, // version.value = data.version; // published= draft=
shortName: e.shortName, // idVersion.value = data.id; // id mongodb
level: e.level, // data.items.map((e: RequestItemsHistoryObject) => {
createdAt: e.createdAt, // rows.value.push({
lastUpdatedAt: e.lastUpdatedAt, // id: e.id,
lastUpdateFullName: e.lastUpdateFullName, // name: e.name,
isActive: e.isActive, // shortName: e.shortName,
createdFullName: e.createdFullName, // level: e.level,
createdUserId: e.createdUserId, // createdAt: e.createdAt,
lastUpdateUserId: e.lastUpdateUserId, // lastUpdatedAt: e.lastUpdatedAt,
insigniaType: e.insigniaType, // lastUpdateFullName: e.lastUpdateFullName,
note: e.note, // isActive: e.isActive,
}); // createdFullName: e.createdFullName,
}); // createdUserId: e.createdUserId,
rows.value.sort( // lastUpdateUserId: e.lastUpdateUserId,
( // insigniaType: e.insigniaType,
firstItem: RequestItemsHistoryObject, // note: e.note,
secondItem: RequestItemsHistoryObject // });
) => firstItem.level - secondItem.level // });
); // rows.value.sort(
}) // (
.catch((e) => { // firstItem: RequestItemsHistoryObject,
messageError($q, e); // secondItem: RequestItemsHistoryObject
}) // ) => firstItem.level - secondItem.level
.finally(async () => { // );
await fetchinsigniaType(); // })
}); // .catch((e) => {
// messageError($q, e);
// })
// .finally(async () => {
// await fetchinsigniaType();
// });
}; };
/** /**

View file

@ -204,8 +204,9 @@ const { loaderPage } = dataStore;
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { success, dateText, messageError, showLoader, hideLoader } = mixin; const { success, dateText, messageError, showLoader, hideLoader } = mixin;
const store = useManageDataStore(); const store = useManageDataStore();
const { manageData, changeManageColumns } = store; const { manageData, changeManageColumns, getInsigniaType, dataInsigniaType } =
const rows = ref<RequestItemsHistoryObject[]>([]); //list data table store;
const rows = ref<RequestItemsHistoryObject[]>(dataInsigniaType); //list data table
const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history
const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history
const tittleHistory = ref<string>("ประวัติแก้ไขลำดับชั้นเครื่องราชฯ"); // const tittleHistory = ref<string>("ประวัติแก้ไขลำดับชั้นเครื่องราชฯ"); //
@ -363,37 +364,42 @@ const $q = useQuasar();
/** /**
* งก get data าส * งก get data าส
*/ */
const fetchData = async () => { const fetchData = async (load: boolean = false) => {
await props.fetchDataComponent(); await props.fetchDataComponent();
rows.value.splice(0); const result = await getInsigniaType(false, load);
showLoader(); version.value = result.version; // published= draft=
await http idVersion.value = result.idversion; // id mongodb
.get(config.API.listInsigniaTypeHistory) rows.value = result.data;
.then((res) => { updateData.value = false;
let data = res.data.result; // rows.value.splice(0);
version.value = data.version; // published= draft= // showLoader();
idVersion.value = data.id; // id mongodb // await http
data.items.map((e: RequestItemsHistoryObject) => { // .get(config.API.listInsigniaTypeHistory)
rows.value.push({ // .then((res) => {
id: e.id, // let data = res.data.result;
name: e.name, // version.value = data.version; // published= draft=
createdAt: e.createdAt, // idVersion.value = data.id; // id mongodb
lastUpdatedAt: e.lastUpdatedAt, // data.items.map((e: RequestItemsHistoryObject) => {
lastUpdateFullName: e.lastUpdateFullName, // rows.value.push({
isActive: e.isActive, // id: e.id,
createdFullName: e.createdFullName, // name: e.name,
createdUserId: e.createdUserId, // createdAt: e.createdAt,
lastUpdateUserId: e.lastUpdateUserId, // lastUpdatedAt: e.lastUpdatedAt,
}); // lastUpdateFullName: e.lastUpdateFullName,
}); // isActive: e.isActive,
}) // createdFullName: e.createdFullName,
.catch((e) => { // createdUserId: e.createdUserId,
messageError($q, e); // lastUpdateUserId: e.lastUpdateUserId,
}) // });
.finally(() => { // });
updateData.value = false; // })
hideLoader(); // .catch((e) => {
}); // messageError($q, e);
// })
// .finally(() => {
// updateData.value = false;
// hideLoader();
// });
}; };
/** /**

View file

@ -5,7 +5,8 @@ import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { RequestItemsHistoryObject } from "@/modules/01_metadata/interface/request/person/Prefix"; import type { RequestItemsHistoryObject } from "@/modules/01_metadata/interface/request/person/Prefix";
import type { RequestItemsHistoryObject as InsigniaResponse } from "@/modules/01_metadata/interface/request/insignia/Insignia";
import type { RequestItemsHistoryObject as InsigniaTypeResponse } from "@/modules/01_metadata/interface/request/insignia/InsigniaType";
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { success, messageError, showLoader, hideLoader } = mixin; const { success, messageError, showLoader, hideLoader } = mixin;
@ -13,6 +14,11 @@ const { success, messageError, showLoader, hideLoader } = mixin;
export const useManageDataStore = defineStore("manage", () => { export const useManageDataStore = defineStore("manage", () => {
const dataPrefix = ref<RequestItemsHistoryObject[]>([]); //list data table const dataPrefix = ref<RequestItemsHistoryObject[]>([]); //list data table
const draftPrefix = ref<RequestItemsHistoryObject[]>([]); //list data table const draftPrefix = ref<RequestItemsHistoryObject[]>([]); //list data table
const dataInsignia = ref<InsigniaResponse[]>([]); //list data table
const draftInsignia = ref<InsigniaResponse[]>([]); //list data table
const dataInsigniaType = ref<InsigniaTypeResponse[]>([]); //list data table
const draftInsigniaType = ref<InsigniaTypeResponse[]>([]); //list data table
const storeIdVersion = ref<string>(""); //id data ใน mongodb const storeIdVersion = ref<string>(""); //id data ใน mongodb
const storeVersion = ref<string>("published"); //รายการข้อมูลล่าสุดได้เผยแพร่หรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่ const storeVersion = ref<string>("published"); //รายการข้อมูลล่าสุดได้เผยแพร่หรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
interface manage { interface manage {
@ -269,6 +275,64 @@ export const useManageDataStore = defineStore("manage", () => {
} }
}; };
const getInsigniaType = async (
selector: boolean = false,
newFetch: boolean = false
) => {
if (dataInsignia.value.length === 0) {
await fetchInsigniaType(true, selector);
return {
data: draftInsigniaType.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
} else {
if (newFetch) {
await fetchInsigniaType(true, selector);
return {
data: draftInsigniaType.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
} else {
return {
data: draftInsigniaType.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
}
}
};
const getInsignia = async (
selector: boolean = false,
newFetch: boolean = false
) => {
if (dataInsignia.value.length === 0) {
await fetchInsignia(true, selector);
return {
data: draftInsignia.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
} else {
if (newFetch) {
await fetchInsignia(true, selector);
return {
data: draftInsignia.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
} else {
return {
data: draftInsignia.value,
version: storeVersion.value,
idversion: storeIdVersion.value,
};
}
}
};
const fetchPrefix = async (loader: boolean, selector: boolean) => { const fetchPrefix = async (loader: boolean, selector: boolean) => {
let apiPrefix = ""; let apiPrefix = "";
if (loader) { if (loader) {
@ -316,8 +380,143 @@ export const useManageDataStore = defineStore("manage", () => {
}); });
}; };
const fetchInsignia = async (loader: boolean, selector: boolean) => {
let apiInsignia = "";
if (loader) {
showLoader();
}
if (selector) {
apiInsignia = config.API.insignia;
} else {
apiInsignia = config.API.listInsigniaHistory;
}
await http
.get(apiInsignia)
.then((res) => {
const data = res.data.result;
let rows: InsigniaResponse[] = [];
if (selector) {
data.map((e: InsigniaResponse) => {
rows.push({
id: e.id,
name: e.name,
shortName: e.shortName,
level: e.level,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
lastUpdateFullName: e.lastUpdateFullName,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateUserId: e.lastUpdateUserId,
insigniaType: e.insigniaType,
note: e.note,
});
});
} else {
storeVersion.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
storeIdVersion.value = data.id; //เลข id ใน mongodb
data.items.map((e: InsigniaResponse) => {
rows.push({
id: e.id,
name: e.name,
shortName: e.shortName,
level: e.level,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
lastUpdateFullName: e.lastUpdateFullName,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateUserId: e.lastUpdateUserId,
insigniaType: e.insigniaType,
note: e.note,
});
});
}
draftInsignia.value = rows;
if (loader) {
dataInsignia.value = rows;
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
if (loader) {
hideLoader();
}
});
};
const fetchInsigniaType = async (loader: boolean, selector: boolean) => {
let apiInsigniaType = "";
if (loader) {
showLoader();
}
if (selector) {
apiInsigniaType = config.API.insigniaType;
} else {
apiInsigniaType = config.API.listInsigniaTypeHistory;
}
await http
.get(apiInsigniaType)
.then((res) => {
const data = res.data.result;
let rows: RequestItemsHistoryObject[] = [];
if (selector) {
data.map((e: RequestItemsHistoryObject) => {
rows.push({
id: e.id,
name: e.name,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
lastUpdateFullName: e.lastUpdateFullName,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateUserId: e.lastUpdateUserId,
});
});
} else {
storeVersion.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
storeIdVersion.value = data.id; //เลข id ใน mongodb
data.items.map((e: RequestItemsHistoryObject) => {
rows.push({
id: e.id,
name: e.name,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
lastUpdateFullName: e.lastUpdateFullName,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateUserId: e.lastUpdateUserId,
});
});
}
draftInsigniaType.value = rows;
if (loader) {
dataInsigniaType.value = rows;
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
if (loader) {
hideLoader();
}
});
};
return { return {
dataPrefix, dataPrefix,
dataInsignia,
dataInsigniaType,
storeIdVersion, storeIdVersion,
storeVersion, storeVersion,
manageData, manageData,
@ -325,5 +524,7 @@ export const useManageDataStore = defineStore("manage", () => {
changeManageCurrentTab, changeManageCurrentTab,
changeManageLink, changeManageLink,
changeManageColumns, changeManageColumns,
getInsignia,
getInsigniaType,
}; };
}); });