Professional Documents
Culture Documents
TOT+Script+New+2022
TOT+Script+New+2022
TOT+Script+New+2022
// @grant none
// @run-at document-end
// ==/UserScript==
window.globalThat = {};
function submitTot(tots){
var newProcess = window.vueInstance.selectedLaborProcess;
var newFunction= window.vueInstance.selectedLaborFunction;
tots.forEach(function(tot){
var enc = encodeURIComponent;
if(window.location.pathname.includes("ppa")){
line = line.replace("warehouseId","oldWarehouseId");
var loc = line.search("&newLaborProcessId");
line = line.slice(0,loc)+"&warehouseId="+enc(whId)+line.slice(loc);
loc = line.search("&newLaborFunctionId");
line = line.slice(0,loc) + "&newJobRole=" + newFunction.replaceAll(" ",
"+");
}
$.ajax({
url: $(this).attr('action'),
type: 'POST',
data: line,
success: function(response){
window.vueInstance.processResponse(response,tot[tot.length-
1],newProcess,newFunction);
}
});
});
};
window.globalThat.sublist = sublist;
window.globalThat.submitTot = submitTot;
(function() {
var editables = document.getElementsByClassName('editable');
//added to fix issues at other warehouses due to example editables and punch
editing
var i;
var editablesArray = [];
for(i = 0; i < editables.length; i++){
if(!editables[i].className.includes("example") &&
editables[i].parentNode.hasAttribute("onclick") &&
editables[i].parentNode.attributes.onclick.nodeValue.startsWith("firePopup")) {
editablesArray.push(editables[i]);
}
}
},
watch: {
selectedLaborProcess: () => {this.vueInstance.newSubList;},
totParams: () => {this.vueInstance.updateTotalDuration;}
},
created:function(){
var savedProcess = window.localStorage.getItem("totProcess");
var savedFunction = window.localStorage.getItem("totFunction");
if(savedProcess != null){
this.selectedLaborProcess = savedProcess;
}
var total = 0;
var title = document.getElementsByClassName("title")[0];
this.totParams.forEach(bar => (total +=
this.getDuration(bar[1],bar[3])));
title.innerText = title.innerText + "("+Math.round(total)+"m)";
},
computed: {
newSubList(){
if(window.location.pathname.includes("ppaTimeDetails")){
var selectedLabel = this.processOptions.filter(x => x.value ==
this.selectedLaborProcess)[0].label;
var funclist =
processes[selectedLabel].attributes.job_role.sort();
this.functionOptions = [this.functionOptions[0]];
funclist.forEach(x =>
this.functionOptions.push({laborFunctionId: x,laborFunctionName: x}));
if(this.loadLastCoded){
this.selectedLaborFunction = this.functionOptions.find(obj
=> {return obj.laborFunctionName ===
this.lastCodedFunction}).laborFunctionId.toString();
this.loadLastCoded = false
}
}
else{
this.seekFunctions(false);
return sublist(this.selectedLaborProcess, (result) => {
this.functionOptions = result.laborFunctions.sort((a, b) =>
(a.laborFunctionName > b.laborFunctionName) ? 1 : -1 );
this.seekFunctions(true);
});
}
},
updateTotalDuration(){
var total = 0;
this.totParams.filter(p=> p[p.length-1]==true).forEach(bar =>
(total += this.getDuration(bar[1],bar[3])));
if(total>0){
this.message2 = (Math.round(total*10)/10).toString() + "
minutes selected";
}
else this.message2 ="";
},
},
methods: {
fireTots() {
//update select menu defaults
window.localStorage.setItem("totProcess",this.selectedLaborProcess);
window.localStorage.setItem("totFunction",this.selectedLaborFunction);
if(foundEdited){
this.lastCodedProcess = lcp;
this.lastCodedFunction = lcf;
var lastProcessCode = this.processOptions.find(obj => {return
obj.label === lcp}).value;
//if the parameters for the bar are included, we assume it's a
normal response.
if(totParams[totIndex].every(x => response.includes(x))){
var proc = this.processOptions.filter(x => x.value == procId)
[0].label;
var func = this.functionOptions.filter(x=> x.laborFunctionId ==
Number(funcId))[0].laborFunctionName;
this.totParams[totIndex][4] = proc;
this.totParams[totIndex][5] = func;
this.submittedlist.push(totIndex);
this.$forceUpdate();
}
else{
}
},
getDuration(date1,date2) {
date1 = new Date(date1);
date2 = date2.length > 0 ? new Date(date2) : this.now;
return Math.abs((date2 - date1)/60000);
},
breakIntersection(totStart,totEnd){
if(!breaksEnabled){
return "";
}
var breaks = [break1.split('-'), break2.split('-'),
break3.split('-')];
totStart = new Date(totStart);
totEnd = new Date(totEnd);
var dayRollover = !(totStart.getDate() == totEnd.getDate() &&
totStart.getMonth() == totEnd.getMonth() && totStart.getYear == totEnd.getYear);
var barrange = [[totStart.getHours(),totStart.getMinutes()],
[totEnd.getHours(),totEnd.getMinutes()]];
return h*60 + m;
}
<table align="center">
<tbody>
<tr v-for="(tot, totRow) in totParams">
<td v-for="(attr, index) of tot">
<template v-if="index==6">
<input type="checkbox" v-model="totParams[totRow][index]">
</template>
<template v-else-if="index==0 || index==2">
{{tot[index].length > 0 ? tot[index].substring(0,5) +
tot[index].substring(10,16) : "(current)"}}
</template>
<template v-else-if="index==1">
{{breakIntersection(tot[1],tot[3])}}
</template>
<template v-else-if="index==3">
{{Math.round(getDuration(tot[1],tot[3])).toString()+"m"}}
</template>
<template v-else-if="submittedlist.includes(totRow)" color="green">
{{ attr }}
</template>
<template v-else>
{{ attr }}
</template>
</td>
</tr>
</tbody>
</table>
<div>
<select v-model="selectedLaborProcess">
<option v-for="process in processOptions" v-bind:value="process.value">
{{process.label}}
</option>
</select>
<select v-model="selectedLaborFunction">
<option v-for="func in functionOptions" v-
bind:value="func.laborFunctionId">
{{func.laborFunctionName}}
</option>
</select>
</div>
<button @click="selectAllBars()">Select All</button>
<button @click="loadLastCodedBar()">Prev. Task</button>
<button @click="fireTots()">Submit</button>
<div>
{{message}}
</div>
<div>
{{message2}}
</div>
</div>
`,
}).$mount(root);
//console.log(totParams);
})();