Convert all store files from JavaScript to TypeScript
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
469
src/stores/conformance.ts
Normal file
469
src/stores/conformance.ts
Normal file
@@ -0,0 +1,469 @@
|
||||
import { defineStore } from "pinia";
|
||||
import moment from "moment";
|
||||
import { Decimal } from 'decimal.js';
|
||||
import abbreviateNumber from '@/module/abbreviateNumber.js';
|
||||
import apiClient from "@/api/client.js";
|
||||
import apiError from '@/module/apiError.js';
|
||||
|
||||
export const useConformanceStore = defineStore('conformanceStore', {
|
||||
state: () => ({
|
||||
conformanceLogId: null, // log 檔
|
||||
conformanceFilterId: null, // filter 檔
|
||||
conformanceLogTempCheckId: null, // log 檔存檔前的 check Id
|
||||
conformanceFilterTempCheckId: null, // Filter 檔存檔前的 check Id
|
||||
conformanceLogCreateCheckId: null, // log 檔存檔後的 check Id(rule)
|
||||
conformanceFilterCreateCheckId: null, // Filter 檔存檔後的 check Id(rule)
|
||||
allConformanceTask: [],
|
||||
allCfmSeqStart: [],
|
||||
allCfmSeqEnd: [],
|
||||
allProcessingTime: {},
|
||||
allWaitingTime: {},
|
||||
allCycleTime: {},
|
||||
allConformanceTempReportData: null,
|
||||
allRouteFile: null,
|
||||
allIssueTraces: null,
|
||||
allTaskSeq: null,
|
||||
allCases: null,
|
||||
allLoopTraces: null,
|
||||
allLoopTaskSeq: null,
|
||||
allLoopCases: null,
|
||||
selectedRuleType: 'Have activity', // radio
|
||||
selectedActivitySequence: 'Start & End', // radio
|
||||
selectedMode: 'Directly follows', // radio
|
||||
selectedProcessScope: 'End to end', // radio
|
||||
selectedActSeqMore: 'All', // radio
|
||||
selectedActSeqFromTo: 'From', // radio
|
||||
infinite404: null,
|
||||
isStartSelected: null, // start & end 連動先選擇 start
|
||||
isEndSelected: null, // start & end 連動先選擇 end
|
||||
conformanceRuleData: null, // create checkId's data to save
|
||||
isUpdateConformance: false, // 成功儲存後要跳 Modal
|
||||
conformanceFileName: null, // 儲存成功的 Modal 用
|
||||
}),
|
||||
getters: {
|
||||
conformanceAllTasks: state => {
|
||||
return state.allConformanceTask;
|
||||
},
|
||||
conformanceTask: state => {
|
||||
return state.allConformanceTask.map(i => i.label);
|
||||
},
|
||||
cfmSeqStart: state => {
|
||||
return state.allCfmSeqStart;
|
||||
},
|
||||
cfmSeqEnd: state => {
|
||||
return state.allCfmSeqEnd;
|
||||
},
|
||||
cfmPtEteWhole: state => {
|
||||
return state.allProcessingTime.end_to_end.whole;
|
||||
},
|
||||
cfmPtEteStart: state => {
|
||||
return state.allProcessingTime.end_to_end.starts_with;
|
||||
},
|
||||
cfmPtEteEnd: state => {
|
||||
return state.allProcessingTime.end_to_end.ends_with;
|
||||
},
|
||||
cfmPtEteSE: state => {
|
||||
return state.allProcessingTime.end_to_end.start_end;
|
||||
},
|
||||
cfmPtPStart: state => {
|
||||
return state.allProcessingTime.partial.starts_with;
|
||||
},
|
||||
cfmPtPEnd: state => {
|
||||
return state.allProcessingTime.partial.ends_with;
|
||||
},
|
||||
cfmPtPSE: state => {
|
||||
return state.allProcessingTime.partial.start_end;
|
||||
},
|
||||
cfmWtEteWhole: state => {
|
||||
return state.allWaitingTime.end_to_end.whole;
|
||||
},
|
||||
cfmWtEteStart: state => {
|
||||
return state.allWaitingTime.end_to_end.starts_with;
|
||||
},
|
||||
cfmWtEteEnd: state => {
|
||||
return state.allWaitingTime.end_to_end.ends_with;
|
||||
},
|
||||
cfmWtEteSE: state => {
|
||||
return state.allWaitingTime.end_to_end.start_end;
|
||||
},
|
||||
cfmWtPStart: state => {
|
||||
return state.allWaitingTime.partial.starts_with;
|
||||
},
|
||||
cfmWtPEnd: state => {
|
||||
return state.allWaitingTime.partial.ends_with;
|
||||
},
|
||||
cfmWtPSE: state => {
|
||||
return state.allWaitingTime.partial.start_end;
|
||||
},
|
||||
cfmCtEteWhole: state => {
|
||||
return state.allCycleTime.end_to_end.whole;
|
||||
},
|
||||
cfmCtEteStart: state => {
|
||||
return state.allCycleTime.end_to_end.starts_with;
|
||||
},
|
||||
cfmCtEteEnd: state => {
|
||||
return state.allCycleTime.end_to_end.ends_with;
|
||||
},
|
||||
cfmCtEteSE: state => {
|
||||
return state.allCycleTime.end_to_end.start_end;
|
||||
},
|
||||
conformanceTempReportData: state => {
|
||||
return state.allConformanceTempReportData;
|
||||
},
|
||||
routeFile: state => {
|
||||
return state.allRouteFile;
|
||||
},
|
||||
issueTraces: state => {
|
||||
return state.allIssueTraces;
|
||||
},
|
||||
taskSeq: state => {
|
||||
return state.allTaskSeq;
|
||||
},
|
||||
cases: state => {
|
||||
if(state.allCases !== null){
|
||||
const newData = state.allCases.map(c => {
|
||||
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:mm');
|
||||
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:mm');
|
||||
c.facets.forEach(fac => {
|
||||
switch(fac.type) {
|
||||
case 'dummy': //sonar-qube
|
||||
case 'duration-list':
|
||||
fac.value = fac.value.map(v => v !== null ? abbreviateNumber(new Decimal(v.toFixed(2))) : null);
|
||||
fac.value = (fac.value).map(v => v.trim()).join(', ');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return fac;
|
||||
});
|
||||
c.attributes.forEach(att => {
|
||||
switch (att.type) {
|
||||
case 'date':
|
||||
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:MM:ss') : null;
|
||||
break;
|
||||
case 'float':
|
||||
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
|
||||
break
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return att;
|
||||
});
|
||||
const { facets, attributes, ...rest } = c;
|
||||
return { ...rest, facets, attributes };
|
||||
});
|
||||
return newData
|
||||
};
|
||||
},
|
||||
loopTraces: state => {
|
||||
return state.allLoopTraces;
|
||||
},
|
||||
loopTaskSeq: state => {
|
||||
return state.allLoopTaskSeq;
|
||||
},
|
||||
loopCases: state => {
|
||||
if(state.allLoopCases !== null){
|
||||
const newData = state.allLoopCases.map(c => {
|
||||
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:mm');
|
||||
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:mm');
|
||||
c.attributes.forEach(att => {
|
||||
switch (att.type) {
|
||||
case 'date':
|
||||
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:mm:ss') : null;
|
||||
break;
|
||||
case 'float':
|
||||
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
|
||||
break
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return att;
|
||||
});
|
||||
return c;
|
||||
});
|
||||
return newData;
|
||||
};
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* fetch Log Conformance Parameters api for Rule Settings.
|
||||
*/
|
||||
async getConformanceParams() {
|
||||
const logId = this.conformanceLogId;
|
||||
const filterId = this.conformanceFilterId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterId !== null) {
|
||||
api = `/api/filter-checks/params?filter_id=${filterId}`;
|
||||
}
|
||||
else {
|
||||
api = `/api/log-checks/params?log_id=${logId}`;
|
||||
}
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allConformanceTask = response.data.tasks;
|
||||
this.allCfmSeqStart = response.data.sources;
|
||||
this.allCfmSeqEnd = response.data.sinks;
|
||||
this.allProcessingTime = response.data.processing_time;
|
||||
this.allWaitingTime = response.data.waiting_time;
|
||||
this.allCycleTime = response.data.cycle_time;
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to load the Conformance Parameters.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Creates a new temporary check for a log.
|
||||
* @param {object} data 送給後端的 data
|
||||
*/
|
||||
async addConformanceCheckId(data) {
|
||||
const logId = this.conformanceLogId;
|
||||
const filterId = this.conformanceFilterId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterId !== null) {
|
||||
api = `/api/temp-filter-checks?filter_id=${filterId}`;
|
||||
}
|
||||
else {
|
||||
api = `/api/temp-log-checks?log_id=${logId}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiClient.post(api, data);
|
||||
if(filterId !== null) {
|
||||
this.conformanceFilterTempCheckId = response.data.id;
|
||||
}
|
||||
else {
|
||||
this.conformanceLogTempCheckId = response.data.id;
|
||||
}
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to add the Temporary Check for a file.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get the Temporary Log Conformance Report
|
||||
* @param {boolean} getRouteFile 是否為了取得 route file 而呼叫?使用在非 Conformance page
|
||||
*/
|
||||
async getConformanceReport(getRouteFile = false) {
|
||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 Temp 再判斷原 ID;先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterTempCheckId !== null) {
|
||||
api = `/api/temp-filter-checks/${filterTempCheckId}`;
|
||||
}
|
||||
else if(logTempCheckId !== null) {
|
||||
api = `/api/temp-log-checks/${logTempCheckId}`;
|
||||
}
|
||||
else if(filterCreateCheckId !== null) {
|
||||
api = `/api/filter-checks/${filterCreateCheckId}`;
|
||||
}
|
||||
else if(logCreateCheckId !== null) {
|
||||
api = `/api/log-checks/${logCreateCheckId}`;
|
||||
}
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
if(!getRouteFile) {
|
||||
this.allConformanceTempReportData = response.data
|
||||
} else {
|
||||
this.allRouteFile = response.data.file;
|
||||
}
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to Get the Temporary Log Conformance Report.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get the detail of a temporary log conformance issue.
|
||||
* @param {number} issueNo Issues 編號
|
||||
*/
|
||||
async getConformanceIssue(issueNo) {
|
||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterTempCheckId !== null) {
|
||||
api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}`;
|
||||
}
|
||||
else if(logTempCheckId !== null) {
|
||||
api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}`;
|
||||
}
|
||||
else if(filterCreateCheckId !== null) {
|
||||
api = `/api/filter-checks/${filterCreateCheckId}/issues/${issueNo}`;
|
||||
}
|
||||
else if(logCreateCheckId !== null) {
|
||||
api = `/api/log-checks/${logCreateCheckId}/issues/${issueNo}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allIssueTraces = response.data.traces;
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get the Trace Details of a Temporary Log Conformance lssue.
|
||||
* @param {number} issueNo Issues 編號
|
||||
* @param {number} traceId, Trace 編號
|
||||
* @param {number} start Trace 要從哪個編號開始載入
|
||||
*/
|
||||
async getConformanceTraceDetail(issueNo, traceId, start) {
|
||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterTempCheckId !== null) {
|
||||
api = `/api/temp-filter-checks/${filterTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
}
|
||||
else if(logTempCheckId !== null) {
|
||||
api = `/api/temp-log-checks/${logTempCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
}
|
||||
else if(filterCreateCheckId !== null) {
|
||||
api = `/api/filter-checks/${filterCreateCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
}
|
||||
else if(logCreateCheckId !== null) {
|
||||
api = `/api/log-checks/${logCreateCheckId}/issues/${issueNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allTaskSeq = response.data.task_seq;
|
||||
this.allCases = response.data.cases;
|
||||
return response.data.cases;
|
||||
} catch(error) {
|
||||
if(error.response.status === 404) {
|
||||
this.infinite404 = 404;
|
||||
return;
|
||||
}
|
||||
apiError(error, 'Failed to Get the detail of a temporary log conformance issue.');
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get the Details of a Temporary Log Conformance Loop.
|
||||
* @param {number} loopNo loop 編號
|
||||
*/
|
||||
async getConformanceLoop(loopNo) {
|
||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}`;
|
||||
else if(logTempCheckId !== null) api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}`;
|
||||
else if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}/loops/${loopNo}`;
|
||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}/loops/${loopNo}`;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allLoopTraces = response.data.traces;
|
||||
} catch(error) {
|
||||
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Get the Trace Details of a Temporary Log Conformance Loops.
|
||||
* @param {number} loopNo loop 編號
|
||||
* @param {number} traceId, Trace 編號
|
||||
* @param {number} start Trace 要從哪個編號開始載入
|
||||
*/
|
||||
async getConformanceLoopsTraceDetail(loopNo, traceId, start) {
|
||||
const logTempCheckId = this.conformanceLogTempCheckId;
|
||||
const filterTempCheckId = this.conformanceFilterTempCheckId;
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterTempCheckId !== null) api = `/api/temp-filter-checks/${filterTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
else if(logTempCheckId !== null) api = `/api/temp-log-checks/${logTempCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
else if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}/loops/${loopNo}/traces/${traceId}?start=${start}&page_size=20`;
|
||||
|
||||
try {
|
||||
const response = await apiClient.get(api);
|
||||
this.allLoopTaskSeq = response.data.task_seq;
|
||||
this.allLoopCases = response.data.cases;
|
||||
return response.data.cases;
|
||||
} catch(error) {
|
||||
if(error.response.status === 404) {
|
||||
this.infinite404 = 404;
|
||||
return;
|
||||
}
|
||||
apiError(error, 'Failed to Get the detail of a temporary log conformance loop.');
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Add a New Log Conformance Check, Save the log file.
|
||||
* @param {string} value file's name
|
||||
*/
|
||||
async addConformanceCreateCheckId(value) {
|
||||
const logId = this.conformanceLogId;
|
||||
const filterId = this.conformanceFilterId;
|
||||
let api = '';
|
||||
const data = {
|
||||
name: value,
|
||||
rule: this.conformanceRuleData
|
||||
};
|
||||
|
||||
// 先判斷 filter 檔,再判斷 log 檔。
|
||||
if(filterId !== null) api = `/api/filter-checks?filter_id=${filterId}`;
|
||||
else api = `/api/log-checks?log_id=${logId}`;
|
||||
|
||||
try {
|
||||
const response = await apiClient.post(api, data);
|
||||
if(filterId !== null) {
|
||||
this.conformanceFilterCreateCheckId = response.data.id;
|
||||
this.conformanceFilterTempCheckId = null;
|
||||
}
|
||||
else {
|
||||
this.conformanceLogCreateCheckId = response.data.id;
|
||||
this.conformanceLogTempCheckId= null;
|
||||
}
|
||||
}catch(error) {
|
||||
apiError(error, 'Failed to add the Conformance Check for a file.');
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Update an Existing Conformance Check, log and filter
|
||||
*/
|
||||
async updateConformance() {
|
||||
const logCreateCheckId = this.conformanceLogCreateCheckId;
|
||||
const filterCreateCheckId = this.conformanceFilterCreateCheckId;
|
||||
let api = '';
|
||||
const data = this.conformanceRuleData;
|
||||
|
||||
// 先判斷有無 Temp ID,再判斷原始檔 ID
|
||||
if(filterCreateCheckId !== null) api = `/api/filter-checks/${filterCreateCheckId}`;
|
||||
else if(logCreateCheckId !== null) api = `/api/log-checks/${logCreateCheckId}`;
|
||||
|
||||
try {
|
||||
const response = await apiClient.put(api, data);
|
||||
this.isUpdateConformance = response.status === 200;
|
||||
this.conformanceLogTempCheckId = null;
|
||||
this.conformanceFilterTempCheckId = null;
|
||||
}catch(error) {
|
||||
apiError(error, 'Failed to update an Existing Conformance.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Set the state value of conformance log creation check ID
|
||||
* @param {string} createCheckID
|
||||
*/
|
||||
setConformanceLogCreateCheckId(createCheckID) {
|
||||
this.conformanceLogCreateCheckId = createCheckID;
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user