refactor submitConformance

This commit is contained in:
Cindy Chang
2024-07-22 15:20:31 +08:00
parent 28cdf9822d
commit 5230a3a99b

View File

@@ -759,7 +759,7 @@ export default {
* Apply button 發送選項,取得 Check Id.
*/
async submitConformance() {
let dataToSave ;
let dataToSave;
this.selectDurationTime = await {
min: this.selectTimeRangeMin,
@@ -769,17 +769,58 @@ export default {
switch (this.selectedRuleType) {
case 'Have activity': // Rule Type 選 Have activity 的行為
dataToSave = {
dataToSave = this.getHaveActivityData();
break;
case 'Activity sequence': // Rule Type 選 Activity sequence 的行為
dataToSave = this.getActivitySequenceData();
break;
case 'Activity duration': // Rule Type 選 Activity duration 的行為
dataToSave = this.getActivityDurationData();
break;
case 'Processing time': // Rule Type 選 Processing time 的行為
dataToSave = this.getProcessingTimeData();
break;
case 'Waiting time': // Rule Type 選 Waiting time 的行為
dataToSave = this.getWaitingTimeData();
break;
case 'Cycle time': // Rule Type 選 Cycle time 的行為
dataToSave = this.getCycleTimeData();
break;
}
if (dataToSave.min > dataToSave.max) {
return this.$toast.error(i18next.t("Conformance.PleaseCheckTimeRange"));
}
if (JSON.stringify(dataToSave) === JSON.stringify(this.isSubmittedData)) {
return this.$toast.error(i18next.t("Conformance.PleaseSetNewRule"));
}
this.isLoading = true;
this.isAlreadySubmit = true;
this.isSubmittedData = dataToSave; // 已 Apply 後,沒有重新改變規則的 Data
this.conformanceRuleData = dataToSave; // 給存檔的 Data
await this.conformanceStore.addConformanceCheckId(dataToSave);
await this.conformanceStore.getConformanceReport();
this.isShowBarOpen = false;
this.isLoading = false;
// Results page Cover Plate
this.$emitter.emit('coverPlate', false);
this.$toast.success(i18next.t("Conformance.RuleApplied"));
},
getHaveActivityData() {
const dataToSave = {
type: 'contains-tasks',
tasks: this.selectConformanceTask,
};
// 其他 isSubmittedData 為 null
this.isSubmitReset();
this.isSubmitTask = this.selectConformanceTask;
break;
case 'Activity sequence': // Rule Type 選 Activity sequence 的行為
return dataToSave;
},
getActivitySequenceData() {
let dataToSave;
switch (this.selectedActivitySequence) {
case 'Start & End': // Activity Sequence 選 Start & End 的行為
case 'Start & End':
dataToSave = {
type: 'start-end',
starts_with: this.selectCfmSeqStart,
@@ -787,12 +828,20 @@ export default {
};
this.isSubmitReset();
this.isSubmitStartAndEnd = [
{category: 'Start', task: this.selectCfmSeqStart},
{category: 'End', task: this.selectCfmSeqEnd},
{ category: 'Start', task: this.selectCfmSeqStart },
{ category: 'End', task: this.selectCfmSeqEnd },
];
this.isSubmitShowDataSeq = this.setSubmitShowDataByStartEnd(this.selectCfmSeqStart, this.selectCfmSeqEnd);
break;
case 'Sequence': // Activity Sequence 選 Sequence 的行為
case 'Sequence':
dataToSave = this.getSequenceData();
break;
}
return dataToSave;
},
getSequenceData() {
let dataToSave;
switch (this.selectedMode) {
case 'Directly follows':
dataToSave = {
@@ -811,24 +860,17 @@ export default {
this.isSubmitCfmSeqEventually = JSON.parse(JSON.stringify(this.selectCfmSeqEventually));
break;
case 'Short loop(s)':
dataToSave = {
type: 'short-loops',
};
dataToSave = { type: 'short-loops' };
break;
case 'Self loop(s)':
dataToSave = {
type: 'self-loops',
};
break;
default:
break;
};
default:
dataToSave = { type: 'self-loops' };
break;
}
break;
case 'Activity duration': // Rule Type 選 Activity duration 的行為
dataToSave = {
return dataToSave;
},
getActivityDurationData() {
const dataToSave = {
type: 'task-duration',
task: this.selectDurationData[0],
min: this.selectDurationTime.min,
@@ -837,10 +879,24 @@ export default {
this.isSubmitReset();
this.isSubmitDurationData = this.selectDurationData;
this.isSubmitDurationTime.rule = this.selectDurationTime;
break;
case 'Processing time': // Rule Type 選 Processing time 的行為
return dataToSave;
},
getProcessingTimeData() {
let dataToSave;
switch (this.selectedProcessScope) {
case 'End to end':
dataToSave = this.getEndToEndProcessingTimeData();
break;
case 'Partial':
dataToSave = this.getPartialProcessingTimeData();
break;
}
return dataToSave;
},
getEndToEndProcessingTimeData() {
let dataToSave;
switch (this.selectedActSeqMore) {
case 'All':
dataToSave = {
@@ -859,9 +915,7 @@ export default {
type: 'processing-time-end-to-end-starts-with',
};
this.isSubmitReset();
this.isSubmitCfmPtEteStart = [
{category: 'Start', task: this.selectCfmPtEteStart},
];
this.isSubmitCfmPtEteStart = [{ category: 'Start', task: this.selectCfmPtEteStart }];
this.isSubmitTimeCfmPtEteStart.rule = this.selectDurationTime;
break;
case 'End':
@@ -872,9 +926,7 @@ export default {
type: 'processing-time-end-to-end-ends-with',
};
this.isSubmitReset();
this.isSubmitCfmPtEteEnd = [
{category: 'End', task: this.selectCfmPtEteEnd},
];
this.isSubmitCfmPtEteEnd = [{ category: 'End', task: this.selectCfmPtEteEnd }];
this.isSubmitTimeCfmPtEteEnd.rule = this.selectDurationTime;
break;
case 'Start & End':
@@ -887,15 +939,18 @@ export default {
};
this.isSubmitReset();
this.isSubmitCfmPtEteSE = [
{category: 'Start', task: this.selectCfmPtEteSEStart},
{category: 'End', task: this.selectCfmPtEteSEEnd},
{ category: 'Start', task: this.selectCfmPtEteSEStart },
{ category: 'End', task: this.selectCfmPtEteSEEnd },
];
this.isSubmitTimeCfmPtEteSE.rule = this.selectDurationTime;
this.isSubmitShowDataPtEte = this.setSubmitShowDataByStartEnd(this.selectCfmPtEteSEStart, this.selectCfmPtEteSEEnd);
break;
};
break;
case 'Partial':
}
return dataToSave;
},
getPartialProcessingTimeData() {
let dataToSave;
switch (this.selectedActSeqFromTo) {
case 'From':
dataToSave = {
@@ -905,9 +960,7 @@ export default {
type: 'processing-time-partial-starts-with',
};
this.isSubmitReset();
this.isSubmitCfmPtPStart = [
{category: 'From', task: this.selectCfmPtPStart},
];
this.isSubmitCfmPtPStart = [{ category: 'From', task: this.selectCfmPtPStart }];
this.isSubmitTimeCfmPtPStart.rule = this.selectDurationTime;
break;
case 'To':
@@ -918,15 +971,10 @@ export default {
type: 'processing-time-partial-ends-with',
};
this.isSubmitReset();
this.isSubmitCfmPtPEnd = [
{category: 'To', task: this.selectCfmPtPEnd},
];
this.isSubmitCfmPtPEnd = [{ category: 'To', task: this.selectCfmPtPEnd }];
this.isSubmitTimeCfmPtPEnd.rule = this.selectDurationTime;
break;
case 'From & To':
// If user didn't click any start-end radio button this time,
// the start, end value might be null as their initial values are.
// So we need to use the earliest value stored in pinia.
dataToSave = {
start: this.selectCfmPtPSEStart ? this.selectCfmPtPSEStart : this.activityRadioData.task[0],
end: this.selectCfmPtPSEEnd ? this.selectCfmPtPSEEnd : this.activityRadioData.task[this.activityRadioData.task.length - 1],
@@ -936,23 +984,31 @@ export default {
};
this.isSubmitReset();
this.isSubmitCfmPtPSE = [
{category: 'From', task: this.selectCfmPtPSEStart},
{category: 'To', task: this.selectCfmPtPSEEnd},
{ category: 'From', task: this.selectCfmPtPSEStart },
{ category: 'To', task: this.selectCfmPtPSEEnd },
];
this.isSubmitTimeCfmPtPSE.rule = this.selectDurationTime;
this.isSubmitShowDataPtP = this.setSubmitShowDataByStartEnd(this.selectCfmPtPSEStart, this.selectCfmPtPSEEnd);
break;
default:
break;
};
break;
default:
break;
};
break;
case 'Waiting time': // Rule Type 選 Waiting time 的行為
}
return dataToSave;
},
getWaitingTimeData() {
let dataToSave;
switch (this.selectedProcessScope) {
case 'End to end':
dataToSave = this.getEndToEndWaitingTimeData();
break;
case 'Partial':
dataToSave = this.getPartialWaitingTimeData();
break;
}
return dataToSave;
},
getEndToEndWaitingTimeData() {
let dataToSave;
switch (this.selectedActSeqMore) {
case 'All':
dataToSave = {
@@ -971,9 +1027,7 @@ export default {
type: 'waiting-time-end-to-end-starts-with',
};
this.isSubmitReset();
this.isSubmitCfmWtEteStart = [
{category: 'Start', task: this.selectCfmWtEteStart},
];
this.isSubmitCfmWtEteStart = [{ category: 'Start', task: this.selectCfmWtEteStart }];
this.isSubmitTimeCfmWtEteStart.rule = this.selectDurationTime;
break;
case 'End':
@@ -984,9 +1038,7 @@ export default {
type: 'waiting-time-end-to-end-ends-with',
};
this.isSubmitReset();
this.isSubmitCfmWtEteEnd = [
{category: 'End', task: this.selectCfmWtEteEnd},
];
this.isSubmitCfmWtEteEnd = [{ category: 'End', task: this.selectCfmWtEteEnd }];
this.isSubmitTimeCfmWtEteEnd.rule = this.selectDurationTime;
break;
case 'Start & End':
@@ -999,17 +1051,18 @@ export default {
};
this.isSubmitReset();
this.isSubmitCfmWtEteSE = [
{category: 'Start', task: this.selectCfmWtEteSEStart},
{category: 'End', task: this.selectCfmWtEteSEEnd},
{ category: 'Start', task: this.selectCfmWtEteSEStart },
{ category: 'End', task: this.selectCfmWtEteSEEnd },
];
this.isSubmitTimeCfmWtEteSE.rule = this.selectDurationTime;
this.isSubmitShowDataWtEte = this.setSubmitShowDataByStartEnd(this.selectCfmWtEteSEStart, this.selectCfmWtEteSEEnd);
break;
default:
break;
};
break;
case 'Partial':
}
return dataToSave;
},
getPartialWaitingTimeData() {
let dataToSave;
switch (this.selectedActSeqFromTo) {
case 'From':
dataToSave = {
@@ -1019,9 +1072,7 @@ export default {
type: 'waiting-time-partial-starts-with',
};
this.isSubmitReset();
this.isSubmitCfmWtPStart = [
{category: 'From', task: this.selectCfmWtPStart},
];
this.isSubmitCfmWtPStart = [{ category: 'From', task: this.selectCfmWtPStart }];
this.isSubmitTimeCfmWtPStart.rule = this.selectDurationTime;
break;
case 'To':
@@ -1032,9 +1083,7 @@ export default {
type: 'waiting-time-partial-ends-with',
};
this.isSubmitReset();
this.isSubmitCfmWtPEnd = [
{category: 'To', task: this.selectCfmWtPEnd},
];
this.isSubmitCfmWtPEnd = [{ category: 'To', task: this.selectCfmWtPEnd }];
this.isSubmitTimeCfmWtPEnd.rule = this.selectDurationTime;
break;
case 'From & To':
@@ -1047,21 +1096,18 @@ export default {
};
this.isSubmitReset();
this.isSubmitCfmWtPSE = [
{category: 'From', task: this.selectCfmWtPSEStart},
{category: 'To', task: this.selectCfmWtPSEEnd},
{ category: 'From', task: this.selectCfmWtPSEStart },
{ category: 'To', task: this.selectCfmWtPSEEnd },
];
this.isSubmitTimeCfmWtPSE.rule = this.selectDurationTime;
this.isSubmitShowDataWtP = this.setSubmitShowDataByStartEnd(this.selectCfmWtPSEStart, this.selectCfmWtPSEEnd);
break;
default:
break;
};
break;
default:
break;
};
break;
case 'Cycle time': // Rule Type 選 Cycle time 的行為
}
return dataToSave;
},
getCycleTimeData() {
let dataToSave;
switch (this.selectedActSeqMore) {
case 'All':
dataToSave = {
@@ -1080,9 +1126,7 @@ export default {
type: 'cycle-time-end-to-end-starts-with',
};
this.isSubmitReset();
this.isSubmitCfmCtEteStart = [
{category: 'Start', task: this.selectCfmCtEteStart},
];
this.isSubmitCfmCtEteStart = [{ category: 'Start', task: this.selectCfmCtEteStart }];
this.isSubmitTimeCfmCtEteStart.rule = this.selectDurationTime;
break;
case 'End':
@@ -1093,9 +1137,7 @@ export default {
type: 'cycle-time-end-to-end-ends-with',
};
this.isSubmitReset();
this.isSubmitCfmCtEteEnd = [
{category: 'End', task: this.selectCfmCtEteEnd},
];
this.isSubmitCfmCtEteEnd = [{ category: 'End', task: this.selectCfmCtEteEnd }];
this.isSubmitTimeCfmCtEteEnd.rule = this.selectDurationTime;
break;
case 'Start & End':
@@ -1108,35 +1150,14 @@ export default {
};
this.isSubmitReset();
this.isSubmitCfmCtEteSE = [
{category: 'Start', task: this.selectCfmCtEteSEStart},
{category: 'End', task: this.selectCfmCtEteSEEnd},
{ category: 'Start', task: this.selectCfmCtEteSEStart },
{ category: 'End', task: this.selectCfmCtEteSEEnd },
];
this.isSubmitTimeCfmCtEteSE.rule = this.selectDurationTime;
this.isSubmitShowDataCt = this.setSubmitShowDataByStartEnd(this.selectCfmCtEteSEStart, this.selectCfmCtEteSEEnd);
break;
default:
break;
};
break;
};
if(dataToSave.min > dataToSave.max) {
return this.$toast.error(i18next.t("Conformance.PleaseCheckTimeRange"));
}
if(JSON.stringify(dataToSave) === JSON.stringify(this.isSubmittedData)) {
return this.$toast.error(i18next.t("Conformance.PleaseSetNewRule"));
}
this.isLoading = true;
this.isAlreadySubmit = true;
this.isSubmittedData = dataToSave; // 已 Apply 後,沒有重新改變規則的 Data
this.conformanceRuleData = dataToSave; // 給存檔的 Data
await this.conformanceStore.addConformanceCheckId(dataToSave);
await this.conformanceStore.getConformanceReport();
this.isShowBarOpen = false;
this.isLoading = false;
// Results page Cover Plate
this.$emitter.emit('coverPlate', false);
this.$toast.success(i18next.t("Conformance.RuleApplied"));
return dataToSave;
},
/**
* 設置根據類別的任務選擇邏輯