From 3c101e6564a78856722cc58081fda05e96fadaee Mon Sep 17 00:00:00 2001 From: DK Jang Date: Mon, 16 Dec 2024 11:19:40 -0500 Subject: [PATCH] Updates in BYOR data convert options (#817) * temp save * temp save * temp save * tabs with multiple datatables implemented * multi tab data tables completed * Subsection type "api" added. * field_page_mode issue resolved. * BYOR a new option "sub to top" is added to "data convert" option * Data convert "split" updated --- src/modules/hugeampkpncms.js | 8 +-- src/utils/dataConvert.js | 99 +++++++++++++++++++++++++++--------- 2 files changed, 80 insertions(+), 27 deletions(-) diff --git a/src/modules/hugeampkpncms.js b/src/modules/hugeampkpncms.js index 6a5a2e72d..0c635013e 100644 --- a/src/modules/hugeampkpncms.js +++ b/src/modules/hugeampkpncms.js @@ -67,10 +67,10 @@ export default { "https://hugeampkpncms.org/view/rest/get_research_page_access?pageid=" + param.pageID ).then(resp => resp.json()); //check for cookie if dev mode - if(json[0].field_page_mode==='dev'){ + if (!!json[0].field_page_mode && json[0].field_page_mode === 'dev') { const cookieCheck = Vue.$cookies.get(`KPN_${param.pageID}`); //login if cookie exists - if(cookieCheck) context.dispatch("getResearchDevPage", {pageID: param.pageID, devID: cookieCheck.u, devPW: cookieCheck.p}); + if (cookieCheck) context.dispatch("getResearchDevPage", { pageID: param.pageID, devID: cookieCheck.u, devPW: cookieCheck.p }); } // set the data context.commit("setResearchMode", json); @@ -96,9 +96,9 @@ export default { "https://hugeampkpncms.org/view/rest/get_research_page_dev?pageid=" + param.pageID + "&&devid=" + param.devID + "&&devpw=" + param.devPW ).then(resp => resp.json()); //if login successful, and user wants to be remembered - if(json.length>0 && param.devCK){ + if (json.length > 0 && param.devCK) { //set cookie for 14 days - const cookieValues = {u: param.devID, p: param.devPW}; + const cookieValues = { u: param.devID, p: param.devPW }; Vue.$cookies.set(`KPN_${param.pageID}`, cookieValues, "14d");//14 days //30MIN } // set the data diff --git a/src/utils/dataConvert.js b/src/utils/dataConvert.js index d03d0b467..22b730fe5 100644 --- a/src/utils/dataConvert.js +++ b/src/utils/dataConvert.js @@ -80,6 +80,45 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) { let cType = c.type; switch (cType) { + case "sub to top": + + let subList = d; + + if (!!c["sub path"]) { + c["sub path"].map(path => { + subList = subList[path]; + }) + } + + if (!!subList) { + let subRow; + + if (!!c["copy by"]) { + + switch (c["copy by"]) { + + case "condition": + + if (c["condition"]["type"] == "equal to") { + + subList.map(row => { + //console.log("field", row[c["condition"]["field"]], c["condition"]["value"]) + + if (row[c["condition"]["field"]] == c["condition"]["value"]) { + subRow = row + } + }) + } + + break; + } + } + + tempObj[c["field name"]] = subRow[c["raw field"]]; + } + + break; + case "join": tempObj[c["field name"]] = joinValues(c["fields to join"], c["join by"], d); d[c["field name"]] = tempObj[c["field name"]]; @@ -94,28 +133,42 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) { let newFields = c["field name"]; let newFieldValues = []; - let string2Split = d[c["field to split"]]; - let loopIndex = 1; - c["split by"].map(s => { - - let [key, ...rest] = string2Split.split(s); - string2Split = rest.join(s) - - if (loopIndex < c["split by"].length) { - newFieldValues.push(key) - } else if (loopIndex = c["split by"].length) { - newFieldValues.push(key) - newFieldValues.push(rest.join(s)) - } - loopIndex++; - }) + let string2Split = (!!tempObj[c["field to split"]]) ? tempObj[c["field to split"]] : d[c["field to split"]]; + + //console.log('c["field name"]', c["field name"]); + + if (!!string2Split) { + let loopIndex = 1; + c["split by"].map(s => { + + let [key, ...rest] = string2Split.split(s); + string2Split = rest.join(s) + + if (loopIndex < c["split by"].length) { + newFieldValues.push(key) + } else if (loopIndex = c["split by"].length) { + newFieldValues.push(key) + newFieldValues.push(rest.join(s)) + } + loopIndex++; + }) + + //console.log("newFieldValues", newFieldValues); + + loopIndex = 0; + newFields.map(f => { + tempObj[f] = newFieldValues[loopIndex]; + d[f] = tempObj[f]; + + + + loopIndex++; + }) + + console.log(tempObj); + } + - loopIndex = 0; - newFields.map(f => { - tempObj[f] = newFieldValues[loopIndex]; - d[f] = tempObj[f]; - loopIndex++; - }) break; @@ -126,7 +179,6 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) { case "calculate": - let calType = c["calculation type"]; switch (calType) { @@ -140,7 +192,8 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) { let calcString = ""; c["expression"].map(e => { - let eValue = !!["+", "-", "*", "/", "(", ")"].includes(e) ? e : (typeof e === 'number') ? e : d[e]; + let eValue = !!["+", "-", "*", "/", "(", ")"].includes(e) ? e : (typeof e === 'number') ? e : + (!!tempObj[e] || tempObj[e] === 0) ? (tempObj[e] === 0) ? 0 : tempObj[e] : (d[e] === 0) ? 0 : d[e]; calcString += eValue; });