Discover: Filters Save done.

This commit is contained in:
chiayin
2023-05-02 17:02:05 +08:00
parent 378d6ea550
commit c1df89fefb
7 changed files with 107 additions and 39 deletions

View File

@@ -50,7 +50,7 @@ import filesStore from '@/stores/files.js';
import AllMapDataStore from '@/stores/allMapData.js'; import AllMapDataStore from '@/stores/allMapData.js';
import IconSearch from '@/components/icons/IconSearch.vue'; import IconSearch from '@/components/icons/IconSearch.vue';
import IconSetting from '@/components/icons/IconSetting.vue'; import IconSetting from '@/components/icons/IconSetting.vue';
import { saveFilter } from '@/module/alertModal.js'; import { saveFilter, savedSuccessfully } from '@/module/alertModal.js';
export default { export default {
data() { data() {
@@ -72,22 +72,38 @@ export default {
}, },
watch: { watch: {
'$route':'getNavViewName', '$route':'getNavViewName',
filterName: function(newVal, oldVal) {
this.filterName = newVal;
},
// createfilterId: function(newVal, oldVal) {
// // this.filterName = newVal;
// console.log(newVal);
// console.log(oldVal);
// },
postRuleData: function(newVal, oldVal) {
// this.filterName = newVal;
console.log(newVal);
console.log(oldVal);
},
}, },
setup() { setup() {
const store = filesStore(); const store = filesStore();
const allMapDataStore = AllMapDataStore(); const allMapDataStore = AllMapDataStore();
const { tempFilterId } = storeToRefs(allMapDataStore); const { tempFilterId, createfilterId, filterName, postRuleData, isUpdataFilter } = storeToRefs(allMapDataStore);
return { store, allMapDataStore, tempFilterId} return { store, allMapDataStore, tempFilterId, createfilterId, filterName, postRuleData, isUpdataFilter}
}, },
components: { components: {
IconSearch, IconSearch,
IconSetting, IconSetting,
saveFilter saveFilter,
savedSuccessfully
}, },
mounted() { mounted() {
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false; this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
this.getNavViewName(); this.getNavViewName();
let filterId = this.$route.params.filterId;
this.createfilterId = filterId;
}, },
methods: { methods: {
switchNavItem(event) { switchNavItem(event) {
@@ -98,10 +114,15 @@ export default {
}, },
showAlert() { showAlert() {
// 先判斷有沒有 filter Id有就儲存 return沒有就往下走 // 先判斷有沒有 filter Id有就儲存 return沒有就往下走
// 沒有 filter Id, 有暫存 tempFilterId Id 可以另存新檔 // 沒有 filter Id, 有暫存 tempFilterId Id 可以另存新檔
if(this.createfilterId) {
this.allMapDataStore.updataFilter();
console.log(this.isUpdataFilter);
if(this.isUpdataFilter) savedSuccessfully(this.filterName);
}else{
saveFilter(this.allMapDataStore.addFilterId); saveFilter(this.allMapDataStore.addFilterId);
} }
}
}, },
} }
</script> </script>

View File

@@ -35,7 +35,12 @@ export async function saveFilter(addFilterId) {
// 存檔成功 // 存檔成功
if(isConfirmed) await addFilterId(filterName); if(isConfirmed) await addFilterId(filterName);
// 顯示儲存完成 // 顯示儲存完成
if (value) { if (value) savedSuccessfully(value);
// 清空欄位
filterName = '';
}
export async function savedSuccessfully(value) {
await Swal.fire({ await Swal.fire({
title: 'SAVE COMPLETE', title: 'SAVE COMPLETE',
html: `<span class="text-primary">${value}</span> has been saved in Lucia.`, html: `<span class="text-primary">${value}</span> has been saved in Lucia.`,
@@ -44,10 +49,7 @@ export async function saveFilter(addFilterId) {
iconColor: '#0099FF', iconColor: '#0099FF',
customClass: customClass customClass: customClass
}) })
}; };
// 清空欄位
filterName = '';
}
export async function leaveFilter(next, addFilterId) { export async function leaveFilter(next, addFilterId) {
const result = await Swal.fire({ const result = await Swal.fire({

View File

@@ -40,15 +40,15 @@ const routes = [
component: Files, component: Files,
}, },
{ {
path: "/discover/:logId", path: "/discover/logs/:logId",
name: "Discover", name: "DiscoverLog",
component: Discover, component: Discover,
},
// 先注意,之後思考是否修改,網址打 discover 時,要跳預設的頁面 {
// path: "discover", path: "/discover/filters/:filterId",
// redirect: 'discover/12345' name: "DiscoverFilter",
component: Discover,
} },
] ]
}, },
{ {

View File

@@ -16,6 +16,7 @@ export default defineStore('allMapDataStore', {
traceId: 1, traceId: 1,
tempFilterId: null, tempFilterId: null,
createFilterId: null, createFilterId: null,
filterName: null,
allProcessMap: {}, allProcessMap: {},
allBpmn: {}, allBpmn: {},
allStats: {}, allStats: {},
@@ -35,6 +36,7 @@ export default defineStore('allMapDataStore', {
ruleData: [], // Funnle view's data ruleData: [], // Funnle view's data
isRuleData: [], // toggle button data isRuleData: [], // toggle button data
allFunnelData: [], allFunnelData: [],
isUpdataFilter: false, // 是否成功儲存 Filter 檔
}), }),
getters: { getters: {
processMap: state => { processMap: state => {
@@ -190,6 +192,9 @@ export default defineStore('allMapDataStore', {
$toast.default('Failed to load the Filter Parameters.',{position: 'bottom'}); $toast.default('Failed to load the Filter Parameters.',{position: 'bottom'});
}; };
}, },
/**
* Test if the Filter Rules Result in Any Data
*/
async checkHasResult() { async checkHasResult() {
let logId = this.logId; let logId = this.logId;
const api = `/api/filters/has-result?log_id=${logId}`; const api = `/api/filters/has-result?log_id=${logId}`;
@@ -209,6 +214,9 @@ export default defineStore('allMapDataStore', {
$toast.default('Failed to load the Has Result.',{position: 'bottom'}); $toast.default('Failed to load the Has Result.',{position: 'bottom'});
}; };
}, },
/**
* Add a New Temporary Filter
*/
async addTempFilterId() { async addTempFilterId() {
let logId = this.logId; let logId = this.logId;
const api = `/api/temp-filters?log_id=${logId}`; const api = `/api/temp-filters?log_id=${logId}`;
@@ -228,6 +236,9 @@ export default defineStore('allMapDataStore', {
$toast.default('Failed to add the Temporary Filters.',{position: 'bottom'}); $toast.default('Failed to add the Temporary Filters.',{position: 'bottom'});
}; };
}, },
/**
* Add a New Filter
*/
async addFilterId(value) { async addFilterId(value) {
let logId = this.logId; let logId = this.logId;
const api = `/api/filters?log_id=${logId}`; const api = `/api/filters?log_id=${logId}`;
@@ -251,7 +262,7 @@ export default defineStore('allMapDataStore', {
}; };
}, },
/** /**
* Fetch event logs api * Get Filter Detail
*/ */
async fetchFunnel(createfilterId) { async fetchFunnel(createfilterId) {
const api = `/api/filters/${createfilterId}`; const api = `/api/filters/${createfilterId}`;
@@ -260,6 +271,8 @@ export default defineStore('allMapDataStore', {
try { try {
const response = await this.$axios.get(api); const response = await this.$axios.get(api);
this.temporaryData = response.data.rules; this.temporaryData = response.data.rules;
this.logId = response.data.log.id;
this.filterName = response.data.name;
}catch(error) { }catch(error) {
this.httpStatus = error.request.status; this.httpStatus = error.request.status;
await delay(); await delay();
@@ -267,9 +280,30 @@ export default defineStore('allMapDataStore', {
await delay(1000); await delay(1000);
loading.isLoading = false; loading.isLoading = false;
await delay(500); await delay(500);
$toast.default('Failed to load the Filters.',{position: 'bottom'}); $toast.default('Failed to get Filter Detail.',{position: 'bottom'});
} }
} }
}, },
/**
* Updata an Existing Filter
*/
async updataFilter() {
let createFilterId = this.createFilterId
const api = `/api/filters/${createFilterId}`;
const data = this.postRuleData;
try {
const response = await this.$axios.put(api, data);
this.isUpdataFilter = response.data.is_modified;
}catch(error) {
this.httpStatus = error.request.status;
await delay();
loading.isLoading = true;
await delay(1000);
loading.isLoading = false;
await delay(500);
$toast.default('Failed to updata an Existing Filter.',{position: 'bottom'});
}
}
}, },
}) })

View File

@@ -68,9 +68,9 @@ export default {
const loadingStore = LoadingStore(); const loadingStore = LoadingStore();
const allMapDataStore = AllMapDataStore(); const allMapDataStore = AllMapDataStore();
const { isLoading } = storeToRefs(loadingStore); const { isLoading } = storeToRefs(loadingStore);
const { processMap, bpmn, stats, insights, traces, traceTaskSeq, cases, filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe, filterTrace, temporaryData, isRuleData, ruleData, createFilterId } = storeToRefs(allMapDataStore); const { processMap, bpmn, stats, insights, traces, traceTaskSeq, cases, filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe, filterTrace, temporaryData, isRuleData, ruleData, logId, createFilterId } = storeToRefs(allMapDataStore);
return { isLoading, processMap, bpmn, stats, insights, traces, traceTaskSeq, cases, filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe, filterTrace, createFilterId, temporaryData, isRuleData, ruleData, allMapDataStore} return { isLoading, processMap, bpmn, stats, insights, traces, traceTaskSeq, cases, filterTasks, filterStartToEnd, filterEndToStart, filterTimeframe, filterTrace, logId, createFilterId, temporaryData, isRuleData, ruleData, allMapDataStore}
}, },
components: { components: {
SidebarView, SidebarView,
@@ -294,15 +294,22 @@ export default {
}, },
}, },
async created() { async created() {
this.allMapDataStore.logId = this.$route.params.logId; // Log 檔前往 DiscoverLog 頁, Filter 檔前往 DiscoverFilter 頁
if(this.$route.name === 'DiscoverLog'){
this.logId = this.$route.params.logId;
}else if(this.$route.name === 'DiscoverFilter') {
this.createFilterId = this.$route.params.filterId;
// 取得 logID 和上次儲存的 Funnel
await this.allMapDataStore.fetchFunnel(this.createFilterId);
this.isRuleData = await Array.from(this.temporaryData);
this.ruleData = await this.isRuleData.map(e => this.$refs.sidevarFilterRef.setRule(e));
}
// 取得 logId 後才 call api
await this.allMapDataStore.getAllMapData(); await this.allMapDataStore.getAllMapData();
await this.allMapDataStore.getAllTrace(); await this.allMapDataStore.getAllTrace();
await this.allMapDataStore.getTraceDetail(); await this.allMapDataStore.getTraceDetail();
this.createCy(this.mapType); this.createCy(this.mapType);
await this.allMapDataStore.getFilterParams(); await this.allMapDataStore.getFilterParams();
await this.allMapDataStore.fetchFunnel(this.createFilterId)
this.isRuleData = await Array.from(this.temporaryData);
this.ruleData = await this.isRuleData.map(e => this.$refs.sidevarFilterRef.setRule(e));
this.isLoading = true; this.isLoading = true;
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));

View File

@@ -133,16 +133,19 @@
*/ */
enterDiscover(file){ enterDiscover(file){
let logId; let logId;
let filterId;
if(file.fileType === 'Log'){ if(file.fileType === 'Log'){
logId = file.id;
this.createFilterId = null; this.createFilterId = null;
logId = file.id;
this.$router.push({name: 'DiscoverLog', params: { logId: logId }})
} }
else if(file.fileType === 'Filter') { else if(file.fileType === 'Filter') {
this.createFilterId = file.id; this.createFilterId = file.id;
logId = file.log.id; filterId = file.id;
this.$router.push({name: 'DiscoverFilter', params: { filterId: filterId }})
}
} }
this.$router.push({ name: 'Discover', params: { logId: logId }});
},
}, },
mounted() { mounted() {
this.store.fetchEventLog(); this.store.fetchEventLog();

View File

@@ -33,7 +33,8 @@ export default {
}, },
watch: { watch: {
$route: function(to, from) { $route: function(to, from) {
if(to.name !== 'Discover') { // 離開 DiscoverLog 頁要將 Funnel 的規則刪除, DiscoverFilter 會帶上次儲存的 Funnel, 所以不用錯做
if(to.name !== 'DiscoverLog') {
this.tempFilterId = null; this.tempFilterId = null;
this.temporaryData = [] this.temporaryData = []
this.postRuleData = [] this.postRuleData = []
@@ -60,7 +61,7 @@ export default {
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
// 離開 Discover 頁時判斷是否有無資料和需要存檔 // 離開 Discover 頁時判斷是否有無資料和需要存檔
if (from.name === 'Discover' && this.tempFilterId) { if ((from.name === 'DiscoverLog' || from.name === 'DiscoverFilter') && this.tempFilterId) {
leaveFilter(next, this.allMapDataStore.addFilterId) leaveFilter(next, this.allMapDataStore.addFilterId)
} else { } else {
next(); next();