Improve message for invalid headers in validation

This commit is contained in:
jrenslin committed 2023-05-16 14:44:21 +02:00
1 parent b9f83b7dcc
commit cc39f204d1
3 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -92,7 +92,7 @@ class CsvxmlValidator {
for (let header of headers) {
if (this.fieldList[header] === undefined) {
this.errors.parsing.push("Invalid column " + header + " detected! Please remove this column or use the appropriate name!");
this.errors.parsing.push("Invalid column \"" + header + "\" detected! Please remove this column or use the appropriate name!");
}
}
+1 -1
View File
@@ -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 c in a){if(a[c]==='')continue;if(this.fieldList[c]===void 0)continue;const d=this.fieldList[c].dependsOn;if(d===void 0)continue;for(let e of d)a[e]===''&&(console.error("Dependency issue at column "+c+": Corresponding column "+e+" is missing [on line "+b+"]"),console.log(a),this.errors.dependentColumns.push("Dependency issue at column "+c+" (current value: "+a[c]+"): Corresponding column "+e+" is empty [on line "+b+"]"))}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<b.clientY+a.clientHeight?(a.style.top="",a.style.bottom=window.innerHeight-b.clientY+"px"):(a.style.bottom="",a.style.top=b.clientY+4+"px"),window.innerWidth<b.clientX+a.clientWidth?(a.style.left="",a.style.right=window.innerWidth-b.clientX+"px"):(a.style.right="",a.style.left=b.clientX+3+"px")}static positionMobile(a){window.matchMedia&&window.matchMedia('(max-width:75em)').matches&&(a.style.left="",a.style.right="",a.style.top="",a.style.bottom="",a.classList.contains("atBottom")===!1&&a.classList.add("atBottom"))}static triggerMouseMove(b){const a=document.getElementById("newToolTipMain");if(a===void 0||a===null)return;CsvxmlTooltip.getDirection(b,a),CsvxmlTooltip.positionMobile(a)}static triggerMouseOut(b){const a=document.getElementById("newToolTipMain");a!==void 0&&a!==null&&(a.classList.remove("visible"),document.body.removeChild(a)),b.target.removeEventListener('mouseout',CsvxmlTooltip.triggerMouseOut)}static bindTooltipToElement(a,b,c){a.addEventListener('mouseover',function(e){let d=document.getElementById("newToolTipMain");if(d!==null)return;d=document.createElement("div"),d.classList.add("newToolTip"),d.id="newToolTipMain",d.setAttribute("data-title",b),d.appendChild(c),document.body.appendChild(d),d.classList.add("visible"),CsvxmlTooltip.getDirection(e,d),CsvxmlTooltip.positionMobile(d),d.addEventListener("mouseout",function(b){const a=document.getElementById("newToolTipMain");a!==void 0&&a!==null&&(a.classList.remove("visible"),document.body.reLine truncated
"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 c in a){if(a[c]==='')continue;if(this.fieldList[c]===void 0)continue;const d=this.fieldList[c].dependsOn;if(d===void 0)continue;for(let e of d)a[e]===''&&(console.error("Dependency issue at column "+c+": Corresponding column "+e+" is missing [on line "+b+"]"),console.log(a),this.errors.dependentColumns.push("Dependency issue at column "+c+" (current value: "+a[c]+"): Corresponding column "+e+" is empty [on line "+b+"]"))}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<b.clientY+a.clientHeight?(a.style.top="",a.style.bottom=window.innerHeight-b.clientY+"px"):(a.style.bottom="",a.style.top=b.clientY+4+"px"),window.innerWidth<b.clientX+a.clientWidth?(a.style.left="",a.style.right=window.innerWidth-b.clientX+"px"):(a.style.right="",a.style.left=b.clientX+3+"px")}static positionMobile(a){window.matchMedia&&window.matchMedia('(max-width:75em)').matches&&(a.style.left="",a.style.right="",a.style.top="",a.style.bottom="",a.classList.contains("atBottom")===!1&&a.classList.add("atBottom"))}static triggerMouseMove(b){const a=document.getElementById("newToolTipMain");if(a===void 0||a===null)return;CsvxmlTooltip.getDirection(b,a),CsvxmlTooltip.positionMobile(a)}static triggerMouseOut(b){const a=document.getElementById("newToolTipMain");a!==void 0&&a!==null&&(a.classList.remove("visible"),document.body.removeChild(a)),b.target.removeEventListener('mouseout',CsvxmlTooltip.triggerMouseOut)}static bindTooltipToElement(a,b,c){a.addEventListener('mouseover',function(e){let d=document.getElementById("newToolTipMain");if(d!==null)return;d=document.createElement("div"),d.classList.add("newToolTip"),d.id="newToolTipMain",d.setAttribute("data-title",b),d.appendChild(c),document.body.appendChild(d),d.classList.add("visible"),CsvxmlTooltip.getDirection(e,d),CsvxmlTooltip.positionMobile(d),d.addEventListener("mouseout",function(b){const a=document.getElementById("newToolTipMain");a!==void 0&&a!==null&&(a.classList.remove("visible"),document.body.Line truncated
+2 -2
View File
@@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.min.css?6460ff5ed53ac" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.min.css?64635020d495a" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#aa4400" />
@@ -27,7 +27,7 @@
</head>
<body class="loading">
<script src="assets/js/csvxmlV2.min.js?6460ff5ed53ae" type="text/javascript" async></script>
<script src="assets/js/csvxmlV2.min.js?64635020d495b" type="text/javascript" async></script>
</body>
</html>