JSFiddle - React, Tailwind, and code Playground
by Michael Prosser
JavaScript
class FormDataOptimizer {
constructor(formData){
this.formObject = formData.formObject;
this.lotoConfiguration = formData.lotoConfiguration;
// by default load nothing
this.requires_facilities = false;
this.requires_facilities_pseudo = false;
this.requires_employees = false;
this.requires_employees_pseudo = false;
this.requires_managers = false;
this.requires_managers_pseudo = false;
this.requires_equipment = false;
this.requires_equipment_pseudo = false;
this.requires_ppe = false;
this.requires_ppe_pseudo = false;
this.requires_compliancedocuments = false;
this.requires_compliancedocuments_pseudo = false;
this.requires_loto = false;
// now determine what we actually need to load
if(typeof(this.lotoConfiguration.component_enabled)){
if(this.lotoConfiguration.component_enabled){
this.requires_loto = true;
}
}
// loop through rows
for(let i=0;i<this.formObject.length;i++){
// loop through cells
for(let j=0;j<this.formObject[i].length;j++){
let item = this.formObject[i][j];
if(item.ui == 'component'){
if(item.options.type == 'data-list'){
this.requires_equipment = true;
this.requires_equipment_pseudo = true;
} else if(item.options.type == 'data'){
// a data component so find what data set we need to enable
switch(item.options['data-table']){
case "facilities":
this.requires_facilities = true;
break;
case "students":
this.requires_employees = true;
break;
case "instructors":
this.requires_managers = true;
break;
case "agGear_equipment":
this.requires_equipment = true;
break;
...