This commit is contained in:
2022-03-28 18:08:38 +00:00
parent 96f39b132d
commit f9dc0e9927

View File

@@ -135,6 +135,8 @@ export default {
if (res.data) { if (res.data) {
dat = 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"); //console.log("Done parseCSVFile");
} else { } else {
dat = await parseJSONFile(this.uploadFile); dat = await parseJSONFile(this.uploadFile);
@@ -153,7 +155,10 @@ export default {
// "The processed data AFTER cleaning is ", // "The processed data AFTER cleaning is ",
// JSON.stringify(dat) // JSON.stringify(dat)
// ); // );
// eslint-disable-next-line no-debugger
//debugger;
//console.log("Flattened:", Flatten(dat));
console.log( console.log(
"if it was csv it should look like this:", "if it was csv it should look like this:",
Papa.unparse(dat) 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 // Open local json file, read, parse and return results as JSON, handle errors if any
@@ -402,6 +431,20 @@ function cleanData(dat, atype) {
] ]
); );
break; 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 //Strip out any records that have fields not on our allowed list