diff --git a/src/api/index.ts b/src/api/index.ts index bf56f79fb..292285657 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -40,6 +40,7 @@ const config = ref({ API_URI_PROFILE_SERVICE: `${window.location.protocol}//${window.location.host}/api/v1`, API_CANDIDATE_URI: `${window.location.protocol}//${window.location.host}/api/v1`, API_REPORT_URI: `${window.location.protocol}//${window.location.host}/api/v1`, + API_PLACEMENT_URI: `${window.location.protocol}//${window.location.host}/api/v1`, API_URI_ORG_TREE: "https://s3cluster.frappet.com/bma-ehr-fpt/organization/strueture/tree_20230707_115124.json", MEET_URI: "meet.frappet.com", diff --git a/src/modules/05_placement/components/PersonalList/OrgTree.vue b/src/modules/05_placement/components/PersonalList/OrgTree.vue index 994f207f7..62a7439cb 100644 --- a/src/modules/05_placement/components/PersonalList/OrgTree.vue +++ b/src/modules/05_placement/components/PersonalList/OrgTree.vue @@ -17,6 +17,7 @@ const noData = ref("ไม่พบข้อมูลผังโคร const checkValidate = ref(false); const myFormPosition = ref(); const selected = ref(""); +const selectedFile = ref(""); // Set form field let dataForm = reactive({ @@ -33,18 +34,37 @@ let dataForm = reactive({ positionSalaryAmount: null, }); -onMounted(() => { - loadTreeData(); - fetchplacementPosition(); +onMounted(async () => { + await fetchPublishFile(); + await loadTreeData(); + await fetchplacementPosition(); }); +const fetchPublishFile = async () => { + await http + .get(config.API.getPublishFileHistory) + .then((res) => { + let data = res.data.result; + selectedFile.value = data[0].fileName; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + hideLoader(); + }); +}; // โหลดข้อมูลโครงสร้างจาก json const treeData = ref>([]); const loadTreeData = async () => { await http - .get(config.API.orgTree) + .get(`${config.s3ClusterUrl}${selectedFile.value}`) .then((res: any) => { treeData.value = res.data; + + // Filter objects with "name" null + const filteredData = res.data.filter(filterByPersonIdNull); + treeData.value = filteredData; }) .catch((e: any) => { messageError($q, e); @@ -53,6 +73,18 @@ const loadTreeData = async () => { hideLoader(); }); }; + +function filterByPersonIdNull(obj: any) { + if (obj.name === null) { + return true; + } + if (obj.children && obj.children.length > 0) { + obj.children = obj.children.filter(filterByPersonIdNull); + return obj.children.length > 0; + } + return false; +} + // โหลด position const placementPosition = ref([]); const fetchplacementPosition = async () => {