diff --git a/public/mix-manifest.json b/public/mix-manifest.json index c2e33c7..f2c42a4 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,7 +1,7 @@ { - "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=4847412d26df3751ad72", - "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=699e97e5478a8b27b4be", - "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=d5ca1cf63c2e4544f6b6", - "/js/vue/Modules/Reservation/app.js": "/js/vue/Modules/Reservation/app.js?id=7ab20db7cfde020f6cb6", - "/js/vue/User/app.js": "/js/vue/User/app.js?id=f1566018c426ca450fe9" + "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=55c57f662ec7c52589b1", + "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=e222dda6bbccb6d90fcc", + "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=fb610c26ce0a747f468e", + "/js/vue/Modules/Reservation/app.js": "/js/vue/Modules/Reservation/app.js?id=16924447beb3df78bf32", + "/js/vue/User/app.js": "/js/vue/User/app.js?id=1559d9dd3150396bff20" } diff --git a/resources/js/Global/utils/common/ProcessTreeArray.js b/resources/js/Global/utils/common/ProcessTreeArray.js new file mode 100644 index 0000000..1f15b4d --- /dev/null +++ b/resources/js/Global/utils/common/ProcessTreeArray.js @@ -0,0 +1,240 @@ +// const convertTreeToList = (data) => { +// var arrayList = []; + +// function recursiveFunction(array) { +// for (const iterator of array) { +// if (iterator.children && iterator.children.length) { +// let clone = Object.assign({}, iterator); +// delete clone.children; +// arrayList.push(clone); +// let list = recursiveFunction(iterator.children); +// arrayList.concat(list); +// } else { +// arrayList.push(iterator); +// } +// } +// return arrayList; +// } + +// return recursiveFunction(data); +// }; +const convertTreeToList = data => { + var arrayList = {}; + + function recursiveFunction( + array, + level, + hierarchy = [], + hierarchy_id = [], + parent_id = null + ) { + for (const key in array) { + if (array.hasOwnProperty(key)) { + let new_hierarchy = [...hierarchy]; + let new_hierarchy_id = [...hierarchy_id]; + new_hierarchy.push(key); + new_hierarchy_id.push(array[key].id); + let clone = Object.assign({}, array[key]); + + //set level + clone.lvl = level; + //set level + clone.parent_id = parent_id; + //set hierarchy key Base Tree Array + clone.hierarchy = new_hierarchy; + //set hierarchy id Base Tree Array + clone.hierarchy_id = new_hierarchy_id; + //set hasChildren + clone.hasChildren = false; + + delete clone.children; + arrayList[clone.id] = clone; + if (array[key].children && array[key].children.length) { + arrayList[clone.id].hasChildren = true; + recursiveFunction( + array[key].children, + level + 1, + new_hierarchy, + new_hierarchy_id, + array[key].id + ); + } + } + } + return arrayList; + } + + return recursiveFunction(data, 1); +}; +const listSearchSelect = Options => { + let treeArray = Options.array ? Options.array : []; + var listArray = Options.list ? Options.list : convertTreeToList(treeArray); + var fromLevel = Options.fromLevel ? Options.fromLevel : 1; + var justLevel = Options.justLevel ? Options.justLevel : null; + var untilLevel = Options.upToLevel ? Options.upToLevel : "End"; + var headerLevel = Options.titleLevel ? Options.titleLevel : null; + var seperator = Options.seperator ? Options.seperator : " >> "; + var selectedIds = Options.selectedIds ? Options.selectedIds : getEndIds(); + var showVarible = Options.variableShow ? Options.variableShow : "name"; + var hasDivider = Options.hasDivider ? Options.hasDivider : true; + var list = []; + + return process(); + + function process() { + var headers = []; + for (const index in listArray) { + if (listArray.hasOwnProperty(index)) { + if (selectedIds.includes(listArray[index].id)) { + var name = ""; + var group = ""; + for (const key in listArray[index].hierarchy_id) { + if (listArray[index].hierarchy_id.hasOwnProperty(key)) { + let item = listArray[listArray[index].hierarchy_id[key]]; + if (fromLevel <= key + 1) { + name += item[showVarible] + seperator; + } + if (headerLevel && headerLevel == key + 1) { + group = item[showVarible]; + headers.push(item[showVarible]); + } + } + } + name = name.replace(new RegExp(seperator + "$"), ""); + list.push({ id: listArray[index].id, lastName: listArray[index][showVarible], name: name, group: group }); + } + } + } + if (headers.length) { + let uniqueHeaders = [...new Set(headers)]; + var newList =[]; + for (const iterator of uniqueHeaders) { + newList.push({ header: iterator }); + let arrayGrop = list.filter(x => x.group == iterator); + newList = [...newList, ...arrayGrop]; + if (hasDivider) { + newList.push({ divider: true }); + } + } + list = [...newList]; + } + return list; + } + + function getEndIds() { + var ids = []; + for (const key in listArray) { + if (listArray.hasOwnProperty(key)) { + if (justLevel) { + if (listArray[key].lvl == justLevel) { + ids.push(listArray[key].id); + } + } else if (untilLevel == "End") { + if (listArray[key].hasChildren == false) { + ids.push(listArray[key].id); + } + } else { + if (listArray[key].lvl <= untilLevel && listArray[key].hasChildren == false || listArray[key].lvl == untilLevel) { + ids.push(listArray[key].id); + } + } + } + } + return ids; + } +}; +const deleteTreeArray = (treeArray, id, listArray = null) => { + if (!listArray) { + listArray = convertTreeToList(treeArray); + } + + let hierarchy = listArray[id].hierarchy; + let array = treeArray; + for (const key in hierarchy) { + if (hierarchy.hasOwnProperty(key)) { + if (key == 0) { + if (hierarchy.length - 1 == key) { + array.splice([hierarchy[key]], 1); + } else { + array = array[hierarchy[key]]; + } + } else { + if (hierarchy.length - 1 == key) { + array["children"].splice([hierarchy[key]], 1); + } else { + array = array["children"][hierarchy[key]]; + } + } + } + } + return treeArray; +}; +const updateTreeArray = (treeArray, update, id, listArray = null) => { + if (!listArray) { + listArray = convertTreeToList(treeArray); + } + let hierarchy = listArray[id].hierarchy; + let array = treeArray; + for (const key in hierarchy) { + if (hierarchy.hasOwnProperty(key)) { + if (key == 0) { + if (hierarchy.length - 1 == key) { + update["children"] = array[hierarchy[key]]["children"]; + array[hierarchy[key]] = update; + } else { + array = array[hierarchy[key]]; + } + } else { + if (hierarchy.length - 1 == key) { + update["children"] = array[hierarchy[key]]["children"]; + array["children"][hierarchy[key]] = update; + } else { + array = array["children"][hierarchy[key]]; + } + } + } + } + return treeArray; +}; +const insertTreeArray = ( + treeArray, + store, + parent_id = null, + listArray = null +) => { + let array = treeArray; + if (!parent_id) { + treeArray.push(store); + return treeArray; + } + if (!listArray) { + listArray = convertTreeToList(treeArray); + } + let hierarchy = listArray[parent_id].hierarchy; + for (const key in hierarchy) { + if (hierarchy.hasOwnProperty(key)) { + if (key == 0) { + if (hierarchy.length - 1 == key) { + array[hierarchy[key]]["children"].push(store); + } else { + array = array[hierarchy[key]]; + } + } else { + if (hierarchy.length - 1 == key) { + array["children"][hierarchy[key]]["children"].push(store); + } else { + array = array["children"][hierarchy[key]]; + } + } + } + } + return treeArray; +}; + +export { + convertTreeToList, + insertTreeArray, + updateTreeArray, + deleteTreeArray, + listSearchSelect +}; diff --git a/resources/js/Global/utils/common/convertStructureTreeToList.js b/resources/js/Global/utils/common/convertStructureTreeToList.js deleted file mode 100644 index 541fead..0000000 --- a/resources/js/Global/utils/common/convertStructureTreeToList.js +++ /dev/null @@ -1,20 +0,0 @@ -export default (data) => { - var arrayList = []; - - function recursiveFunction(array) { - for (const iterator of array) { - if (iterator.children && iterator.children.length) { - let clone = Object.assign({}, iterator); - delete clone.children; - arrayList.push(clone); - let list = recursiveFunction(iterator.children); - arrayList.concat(list); - } else { - arrayList.push(iterator); - } - } - return arrayList; - } - - return recursiveFunction(data); -}; \ No newline at end of file