refactor: Issues #177 change files API done.
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import loadingStore from './loading.js';
|
|
||||||
import pinia from '@/stores/main.js'
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import apiError from '@/module/apiError.js';
|
import apiError from '@/module/apiError.js';
|
||||||
|
|
||||||
const loading = loadingStore(pinia);
|
|
||||||
|
|
||||||
export default defineStore('filesStore', {
|
export default defineStore('filesStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
allFilter: [
|
allFilter: [
|
||||||
@@ -37,6 +33,13 @@ export default defineStore('filesStore', {
|
|||||||
ownerName: '',
|
ownerName: '',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
allEventFiles: [
|
||||||
|
{
|
||||||
|
parentLog: '',
|
||||||
|
fileType: '',
|
||||||
|
ownerName: '',
|
||||||
|
}
|
||||||
|
],
|
||||||
switchFilesTagData: {
|
switchFilesTagData: {
|
||||||
ALL: ['Log', 'Filter', 'Rule', 'Design'],
|
ALL: ['Log', 'Filter', 'Rule', 'Design'],
|
||||||
DISCOVER: ['Log', 'Filter', 'Rule'],
|
DISCOVER: ['Log', 'Filter', 'Rule'],
|
||||||
@@ -51,12 +54,7 @@ export default defineStore('filesStore', {
|
|||||||
* Get allFiles and switch files tag
|
* Get allFiles and switch files tag
|
||||||
*/
|
*/
|
||||||
allFiles: state => {
|
allFiles: state => {
|
||||||
let result = [
|
let result = state.allEventFiles;
|
||||||
...state.allEventLog,
|
|
||||||
...state.allFilter,
|
|
||||||
...state.allConformanceLog,
|
|
||||||
...state.allConformanceFilter,
|
|
||||||
];
|
|
||||||
let data = state.switchFilesTagData;
|
let data = state.switchFilesTagData;
|
||||||
let filesTag = state.filesTag;
|
let filesTag = state.filesTag;
|
||||||
|
|
||||||
@@ -163,6 +161,51 @@ export default defineStore('filesStore', {
|
|||||||
apiError(error, 'Failed to load the filters.');
|
apiError(error, 'Failed to load the filters.');
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Fetch All Files api
|
||||||
|
*/
|
||||||
|
async fetchAllFiles() {
|
||||||
|
const api = '/api/files';
|
||||||
|
let icon = '';
|
||||||
|
let fileType = '';
|
||||||
|
let parentLog = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(api);
|
||||||
|
|
||||||
|
this.allEventFiles = response.data;
|
||||||
|
this.allEventFiles.map(o => {
|
||||||
|
switch (o.type) {
|
||||||
|
case 'log':
|
||||||
|
icon = 'work_history';
|
||||||
|
fileType = 'Log';
|
||||||
|
parentLog = o.name;
|
||||||
|
break;
|
||||||
|
case 'filter':
|
||||||
|
icon = 'tornado';
|
||||||
|
fileType = 'Filter';
|
||||||
|
parentLog = o.parent.name;
|
||||||
|
break;
|
||||||
|
case 'log-check':
|
||||||
|
case 'filter-check':
|
||||||
|
icon = 'local_police';
|
||||||
|
fileType = 'Rule';
|
||||||
|
parentLog = o.parent.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
o.icon = icon;
|
||||||
|
o.parentLog = parentLog;
|
||||||
|
o.fileType = fileType;
|
||||||
|
o.ownerName = o.owner.name;
|
||||||
|
o.updated_base = o.updated_at;
|
||||||
|
o.accessed_base = o.accessed_at;
|
||||||
|
o.updated_at = moment(o.updated_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm');
|
||||||
|
o.accessed_at = o.accessed_at ? moment(o.accessed_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm') : null;
|
||||||
|
});
|
||||||
|
} catch(error) {
|
||||||
|
apiError(error, 'Failed to load the files.');
|
||||||
|
};
|
||||||
|
},
|
||||||
// fetchRule(){o.icon = local_police}
|
// fetchRule(){o.icon = local_police}
|
||||||
// fetchDesign(){o.icon = shape_line}
|
// fetchDesign(){o.icon = shape_line}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ export default {
|
|||||||
const loadingStore = LoadingStore();
|
const loadingStore = LoadingStore();
|
||||||
const conformanceStore = ConformanceStore();
|
const conformanceStore = ConformanceStore();
|
||||||
const { isLoading } = storeToRefs(loadingStore);
|
const { isLoading } = storeToRefs(loadingStore);
|
||||||
const { allConformanceLog, allConformanceFilter } = storeToRefs(filesStore);
|
const { allFiles } = storeToRefs(filesStore);
|
||||||
const { conformanceLogId, conformanceFilterId, conformanceLogCreateCheckId, conformanceFilterCreateCheckId, conformanceLogTempCheckId, conformanceFilterTempCheckId, selectedRuleType, selectedActivitySequence, selectedMode, selectedProcessScope, selectedActSeqMore, selectedActSeqFromTo, conformanceRuleData, conformanceTempReportData, conformanceFileName } = storeToRefs(conformanceStore);
|
const { conformanceLogId, conformanceFilterId, conformanceLogCreateCheckId, conformanceFilterCreateCheckId, conformanceLogTempCheckId, conformanceFilterTempCheckId, selectedRuleType, selectedActivitySequence, selectedMode, selectedProcessScope, selectedActSeqMore, selectedActSeqFromTo, conformanceRuleData, conformanceTempReportData, conformanceFileName } = storeToRefs(conformanceStore);
|
||||||
|
|
||||||
return { filesStore, allConformanceLog, allConformanceFilter, isLoading, conformanceLogId, conformanceFilterId, conformanceLogCreateCheckId, conformanceFilterCreateCheckId, conformanceLogTempCheckId, conformanceFilterTempCheckId, conformanceStore, selectedRuleType, selectedActivitySequence, selectedMode, selectedProcessScope, selectedActSeqMore, selectedActSeqFromTo, conformanceRuleData, conformanceTempReportData, conformanceFileName }
|
return { filesStore, allFiles, isLoading, conformanceLogId, conformanceFilterId, conformanceLogCreateCheckId, conformanceFilterCreateCheckId, conformanceLogTempCheckId, conformanceFilterTempCheckId, conformanceStore, selectedRuleType, selectedActivitySequence, selectedMode, selectedProcessScope, selectedActSeqMore, selectedActSeqFromTo, conformanceRuleData, conformanceTempReportData, conformanceFileName }
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
StatusBar,
|
StatusBar,
|
||||||
@@ -50,8 +50,8 @@ export default {
|
|||||||
this.conformanceLogId = params.checkFileId;
|
this.conformanceLogId = params.checkFileId;
|
||||||
this.conformanceLogCreateCheckId = params.checkId;
|
this.conformanceLogCreateCheckId = params.checkId;
|
||||||
// 為複寫 Modal 取得 fileName
|
// 為複寫 Modal 取得 fileName
|
||||||
await this.filesStore.fetchConformanceLog();
|
await this.filesStore.fetchAllFiles();
|
||||||
await this.allConformanceLog.forEach(file => {
|
await this.allFiles.forEach(file => {
|
||||||
if(file.id == this.conformanceLogCreateCheckId) return this.conformanceFileName = file.name;
|
if(file.id == this.conformanceLogCreateCheckId) return this.conformanceFileName = file.name;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -59,8 +59,8 @@ export default {
|
|||||||
this.conformanceFilterId = params.checkFileId;
|
this.conformanceFilterId = params.checkFileId;
|
||||||
this.conformanceFilterCreateCheckId = params.checkId;
|
this.conformanceFilterCreateCheckId = params.checkId;
|
||||||
// 為複寫 Modal 取得 fileName
|
// 為複寫 Modal 取得 fileName
|
||||||
await this.filesStore.fetchConformanceFilter();
|
await this.filesStore.fetchAllFiles();
|
||||||
await this.allConformanceFilter.forEach(file => {
|
await this.allFiles.forEach(file => {
|
||||||
if(file.id == this.conformanceFilterCreateCheckId) return this.conformanceFileName = file.name;
|
if(file.id == this.conformanceFilterCreateCheckId) return this.conformanceFileName = file.name;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,8 +138,8 @@
|
|||||||
let fileId;
|
let fileId;
|
||||||
let params;
|
let params;
|
||||||
|
|
||||||
switch (file.fileType) {
|
switch (file.type) {
|
||||||
case 'Log':
|
case 'log':
|
||||||
this.createFilterId = null;
|
this.createFilterId = null;
|
||||||
this.baseLogId = file.id;
|
this.baseLogId = file.id;
|
||||||
fileId = file.id;
|
fileId = file.id;
|
||||||
@@ -148,9 +148,9 @@
|
|||||||
this.$router.push({name: 'Map', params: params});
|
this.$router.push({name: 'Map', params: params});
|
||||||
// this.$router.push({name: 'Map', params: params, query: params});
|
// this.$router.push({name: 'Map', params: params, query: params});
|
||||||
break;
|
break;
|
||||||
case 'Filter':
|
case 'filter':
|
||||||
this.createFilterId = file.id;
|
this.createFilterId = file.id;
|
||||||
this.baseLogId = file.log.id;
|
this.baseLogId = file.parent.id;
|
||||||
fileId = file.id;
|
fileId = file.id;
|
||||||
type = 'filter';
|
type = 'filter';
|
||||||
params = { type: type, fileId: fileId };
|
params = { type: type, fileId: fileId };
|
||||||
@@ -158,26 +158,23 @@
|
|||||||
// this.$router.push({name: 'Map', params: params, query: params});
|
// this.$router.push({name: 'Map', params: params, query: params});
|
||||||
break;
|
break;
|
||||||
// 先不考慮 MAP 只做 CONFORMANCE
|
// 先不考慮 MAP 只做 CONFORMANCE
|
||||||
case 'Rule':
|
case 'log-check':
|
||||||
// path: "/:type/:checkType/:checkId/conformance/:checkFileId"
|
// path: "/:type/:checkType/:checkId/conformance/:checkFileId"
|
||||||
type = 'rule';
|
type = 'rule';
|
||||||
if(file.log){
|
params = { type: type, checkType: 'log', checkId: file.id, checkFileId: file.parent.id };
|
||||||
params = { type: type, checkType: 'log', checkId: file.id, checkFileId: file.log.id };
|
|
||||||
this.$router.push({name: 'CheckConformance', params: params});
|
this.$router.push({name: 'CheckConformance', params: params});
|
||||||
} else if(file.filter) {
|
break
|
||||||
params = { type: type, checkType: 'filter', checkId: file.id, checkFileId: file.filter.id };
|
case 'filter-check':
|
||||||
|
type = 'rule';
|
||||||
|
params = { type: type, checkType: 'filter', checkId: file.id, checkFileId: file.parent.id };
|
||||||
this.$router.push({name: 'CheckConformance', params: params});
|
this.$router.push({name: 'CheckConformance', params: params});
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.store.fetchEventLog();
|
this.store.fetchAllFiles();
|
||||||
this.store.fetchFilter();
|
|
||||||
this.store.fetchConformanceLog();
|
|
||||||
this.store.fetchConformanceFilter();
|
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user