From 3ee4174863337542b228509d9219d2984dcea19a Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 10 May 2023 16:45:01 +0200 Subject: [PATCH] Display line number when validation files because of field dependencies --- public/assets/js/csvxmlV2.js | 4 ++-- public/assets/js/csvxmlV2.min.js | 2 +- public/index.htm | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/assets/js/csvxmlV2.js b/public/assets/js/csvxmlV2.js index 05d543e..be6e589 100644 --- a/public/assets/js/csvxmlV2.js +++ b/public/assets/js/csvxmlV2.js @@ -141,9 +141,9 @@ class CsvxmlValidator { for (let dependency of dependencies) { if (line[dependency] === '') { - console.error("Dependency issue at column " + fieldName + ": Corresponding column " + dependency + " is missing"); + console.error("Dependency issue at column " + fieldName + ": Corresponding column " + dependency + " is missing [on line " + lineCounter + "]"); console.log(line); - this.errors.dependentColumns.push("Dependency issue at column " + fieldName + " (current value: " + line[fieldName] + "): Corresponding column " + dependency + " is empty"); + this.errors.dependentColumns.push("Dependency issue at column " + fieldName + " (current value: " + line[fieldName] + "): Corresponding column " + dependency + " is empty [on line " + lineCounter + "]"); } } } diff --git a/public/assets/js/csvxmlV2.min.js b/public/assets/js/csvxmlV2.min.js index 319d211..9b7277c 100644 --- a/public/assets/js/csvxmlV2.min.js +++ b/public/assets/js/csvxmlV2.min.js @@ -1 +1 @@ -"use strict";'serviceWorker'in navigator&&(console.log("Registering service worker"),navigator.serviceWorker.register('/sw.js'));class CsvxmlValidator{fieldList;toValidate;errors;constructor(c,d){this.errors={parsing:[],mandatoryTags:[],duplicateInvNos:[],dependentColumns:[],controlledLists:[],mainImageResource:[]},this.fieldList=Object.freeze(c);const a=Papa.parse(d.trim(),{delimiter:";",escapeChar:'"',skipEmptyLines:!0,header:!0});if(a.errors.length!==0){console.log("Errors encountered: "),console.error(a.errors);let b='';for(let c of a.errors)b+=c.type+': '+c.message+"\n";window.alert(b)}let b=a.data;this.toValidate=b,b.length===0&&alert("Error: No lines of content identified"),this.validate()}validate(){this.validateMandatoryTagsPresent(),this.validateInvalidTagsPresent(),this.checkDuplicateInvNos(),this.checkDependentColumns(),this.checkControlledLists()}validateMandatoryTagsPresent(){let a=[];for(let b in this.fieldList)this.fieldList[b].required===!0&&a.push(b);console.log(this.toValidate);let b=1;for(let c of this.toValidate){for(let d of a)(c[d]===void 0||c[d]===null||c[d]==='')&&this.errors.mandatoryTags.push("Missing or empty mandatory tag "+d+" on line "+b);b++}}validateInvalidTagsPresent(){const a=Object.keys(this.toValidate[0]);for(let b of a)this.fieldList[b]===void 0&&this.errors.parsing.push("Invalid column "+b+" detected! Please remove this column or use the appropriate name!")}checkDuplicateInvNos(){let a=[],b=1;for(let c of this.toValidate)a.includes(c.inventory_number)&&this.errors.duplicateInvNos.push("Duplicate inventory number "+c.inventory_number+" on line "+b),a.push(c.inventory_number),b++}checkDependentColumns(){const a=Object.keys(this.toValidate[0]);for(let b of a){if(this.fieldList[b]===void 0||this.fieldList[b].dependsOn===void 0||this.fieldList[b].dependsOn===null)continue;let c=this.fieldList[b].dependsOn;for(let d of c)a.includes(d)===!1&&(console.error("Dependency issue at column "+b+": Corresponding column "+d+" is missing"),console.log(a),this.errors.dependentColumns.push("Dependency issue at column "+b+": Corresponding column "+d+" is missing"))}let b=1;for(let a of this.toValidate){for(let b in a){if(a[b]==='')continue;if(this.fieldList[b]===void 0)continue;const c=this.fieldList[b].dependsOn;if(c===void 0)continue;for(let d of c)a[d]===''&&(console.error("Dependency issue at column "+b+": Corresponding column "+d+" is missing"),console.log(a),this.errors.dependentColumns.push("Dependency issue at column "+b+" (current value: "+a[b]+"): Corresponding column "+d+" is empty"))}b++}}checkControlledLists(){let a=1;for(let b of this.toValidate){for(let c in b){if(this.fieldList[c]===void 0){console.log("Undefined but requested field "+c);continue}const d=this.fieldList[c].allowedValues;if(d===void 0||d===null)continue;if(Object.values(d).length===0||Object.values(d).includes(b[c]))continue;if(b[c]==='')continue;this.errors.controlledLists.push("Disallowed value used for column "+c+" at line "+a+" (Allowed values are: "+Object.values(d).join(", ")+"; current value is "+b[c]+")")}a++}}checkMainImageResource(){}isValid(){for(let a in this.errors)if(this.errors[a].length!==0)return!1;return!0}generateXml(){let a=[],b=document.implementation.createDocument(null,"record");for(let c of this.toValidate){let d=b.createElement("record");for(let a in c){const e=b.createElement(a);e.textContent=c[a],d.appendChild(e)}a.push(d)}return a}}class CsvxmlTooltip{static getDirection(b,a){window.innerHeight - + @@ -27,7 +27,7 @@ - + \ No newline at end of file