From f9dc0e99274d7f82fe5c14c1c03c2031b09dc48a Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 28 Mar 2022 18:08:38 +0000 Subject: [PATCH] --- ayanova/src/views/adm-import.vue | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ayanova/src/views/adm-import.vue b/ayanova/src/views/adm-import.vue index 82184826..56915972 100644 --- a/ayanova/src/views/adm-import.vue +++ b/ayanova/src/views/adm-import.vue @@ -135,6 +135,8 @@ export default { if (res.data) { dat = res.data; } + //transform the input csv if it's not a direct match to json (part assembly etc) + transform(dat, this.ayaType); //console.log("Done parseCSVFile"); } else { dat = await parseJSONFile(this.uploadFile); @@ -153,7 +155,10 @@ export default { // "The processed data AFTER cleaning is ", // JSON.stringify(dat) // ); + // eslint-disable-next-line no-debugger + //debugger; + //console.log("Flattened:", Flatten(dat)); console.log( "if it was csv it should look like this:", Papa.unparse(dat) @@ -280,6 +285,30 @@ async function parseCSVFile(file) { }); } +////////////////////////////////////////////////////////// +// +// reformat JSON that was imported for types that need +// to be transformed (partassembly etc) +// +function transform(dat, atype) { + switch (atype) { + case window.$gz.type.PartAssembly: + //json from csv needs reformatting + dat.forEach(z => { + var newItems = []; + z.Items.split(",").forEach(x => { + let o = x.split("|"); + newItems.push({ + PartNameViz: o[0], + Quantity: Number.parseFloat(o[1]) + }); + }); + z.Items = newItems; + }); + break; + } +} + ////////////////////////////////////////////////////////// // // Open local json file, read, parse and return results as JSON, handle errors if any @@ -402,6 +431,20 @@ function cleanData(dat, atype) { ] ); break; + case window.$gz.type.PartAssembly: + allowedProps.push( + ...[ + "Name", + "Active", + "Notes", + "Wiki", + "Tags", + "Items", + "PartNameViz", + "Quantity" + ] + ); + break; } //Strip out any records that have fields not on our allowed list