Discover: fix filter's save done.

This commit is contained in:
chiayin
2023-05-03 13:25:18 +08:00
parent 51b56c0ccb
commit 162af24a2a
5 changed files with 32 additions and 24 deletions

View File

@@ -25,7 +25,7 @@
</div> </div>
</div> </div>
<!-- Button --> <!-- Button -->
<div class=""> <div>
<div class="float-right space-x-4 px-4 py-2"> <div class="float-right space-x-4 px-4 py-2">
<button type="button" class="btn btn-sm " :class="[ temporaryData.length === 0 ? 'btn-disable' : 'btn-neutral']" :disabled="temporaryData.length === 0" @click="deleteRule('all')">Delete All</button> <button type="button" class="btn btn-sm " :class="[ temporaryData.length === 0 ? 'btn-disable' : 'btn-neutral']" :disabled="temporaryData.length === 0" @click="deleteRule('all')">Delete All</button>
<button type="button" class="btn btn-sm" :class="[ temporaryData.length === 0 ? 'btn-disable' : 'btn-neutral']" :disabled="temporaryData.length === 0" @click="submitAll">Apply All</button> <button type="button" class="btn btn-sm" :class="[ temporaryData.length === 0 ? 'btn-disable' : 'btn-neutral']" :disabled="temporaryData.length === 0" @click="submitAll">Apply All</button>
@@ -61,11 +61,14 @@ export default {
if(!e) this.temporaryData[index] = 0; if(!e) this.temporaryData[index] = 0;
else this.temporaryData[index] = rule; else this.temporaryData[index] = rule;
}, },
// header:Funnel 刪除全部的 Funnel /**
* header:Funnel 刪除全部的 Funnel
*/
deleteRule(index) { deleteRule(index) {
if(index === 'all') { if(index === 'all') {
this.temporaryData = []; this.temporaryData = [];
this.isRuleData = []; this.isRuleData = [];
this.ruleData = [];
this.$toast.success('All deleted.'); this.$toast.success('All deleted.');
}else{ }else{
this.$toast.success(`Delete ${this.ruleData[index].label}.`); this.$toast.success(`Delete ${this.ruleData[index].label}.`);
@@ -74,7 +77,9 @@ export default {
this.ruleData.splice(index, 1); this.ruleData.splice(index, 1);
} }
}, },
// header:Funnel 發送暫存的選取資料 /**
* header:Funnel 發送暫存的選取資料
*/
async submitAll() { async submitAll() {
this.postRuleData = this.temporaryData.filter(item => item !== 0); // 取得 submit 的資料,有 toggle button 的話,找出並刪除陣列中為 0 的項目 this.postRuleData = this.temporaryData.filter(item => item !== 0); // 取得 submit 的資料,有 toggle button 的話,找出並刪除陣列中為 0 的項目
if(!this.postRuleData?.length) return this.$toast.error('Not selected'); if(!this.postRuleData?.length) return this.$toast.error('Not selected');

View File

@@ -439,7 +439,7 @@ export default {
}else { }else {
this.temporaryData.push(...postData); this.temporaryData.push(...postData);
this.isRuleData.push(...postData); this.isRuleData.push(...postData);
this.ruleData.push(this.setRule(...postData)); this.ruleData.push(...postData.map(e => this.setRule(e)))
} }
this.reset(false); this.reset(false);
this.isLoading = true; this.isLoading = true;

View File

@@ -36,7 +36,7 @@
<!-- Other Page: Save and Download --> <!-- Other Page: Save and Download -->
<!-- Save data 跳重新命名沒有 data 跳要不要儲存沒有動都不跳 --> <!-- Save data 跳重新命名沒有 data 跳要不要儲存沒有動都不跳 -->
<div v-else class="space-x-4"> <div v-else class="space-x-4">
<button class="btn btn-sm" :class="[ disabledSave ? 'btn-disable' : 'btn-neutral']" :disabled="disabledSave" @click="showAlert">Save</button> <button class="btn btn-sm" :class="[ disabledSave ? 'btn-disable' : 'btn-neutral']" :disabled="disabledSave" @click="saveModal">Save</button>
<button class="btn btn-sm btn-neutral">Download</button> <button class="btn btn-sm btn-neutral">Download</button>
</div> </div>
</div> </div>
@@ -79,9 +79,9 @@ export default {
setup() { setup() {
const store = filesStore(); const store = filesStore();
const allMapDataStore = AllMapDataStore(); const allMapDataStore = AllMapDataStore();
const { tempFilterId, createfilterId, filterName, postRuleData, isUpdataFilter } = storeToRefs(allMapDataStore); const { logId, tempFilterId, createFilterId, filterName, postRuleData, isUpdataFilter } = storeToRefs(allMapDataStore);
return { store, allMapDataStore, tempFilterId, createfilterId, filterName, postRuleData, isUpdataFilter} return { store, allMapDataStore, logId, tempFilterId, createFilterId, filterName, postRuleData, isUpdataFilter}
}, },
components: { components: {
IconSearch, IconSearch,
@@ -90,33 +90,36 @@ export default {
savedSuccessfully savedSuccessfully
}, },
mounted() { mounted() {
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
this.getNavViewName();
let filterId = this.$route.params.filterId; let filterId = this.$route.params.filterId;
this.createfilterId = filterId; this.createfilterId = filterId;
this.showNavbarBreadcrumb = this.$route.matched[0].name !== ('AuthContainer')? true : false;
this.getNavViewName();
}, },
methods: { methods: {
/**
* switch navbar item
*/
switchNavItem(event) { switchNavItem(event) {
this.store.filesTag = event.target.innerText; this.store.filesTag = event.target.innerText;
}, },
getNavViewName() { getNavViewName() {
this.navViewName = this.$route.name.toUpperCase(); this.navViewName = this.$route.name.toUpperCase();
if(this.navViewName === 'DISCOVERLOG' || this.navViewName === 'DISCOVERFILTER'){ if(this.navViewName === 'DISCOVERLOG' || this.navViewName === 'DISCOVERFILTER') this.navViewName = 'DISCOVER';
this.navViewName = 'DISCOVER';
}
}, },
showAlert() { /**
* Save button' modal
*/
async saveModal() {
// 先判斷有沒有 filter Id有就儲存 return沒有就往下走 // 先判斷有沒有 filter Id有就儲存 return沒有就往下走
// 沒有 filter Id, 有暫存 tempFilterId Id 可以另存新檔 // 沒有 filter Id, 有暫存 tempFilterId Id 可以另存新檔
console.log(this.createfilterId); if(this.createFilterId) {
if(this.createfilterId) { await this.allMapDataStore.updataFilter();
this.allMapDataStore.updataFilter(); if(this.isUpdataFilter) await savedSuccessfully(this.filterName);
console.log(this.isUpdataFilter); this.tempFilterId = null;
if(this.isUpdataFilter) savedSuccessfully(this.filterName); }else if(this.logId){
this.tempFilterId = false
}else{
saveFilter(this.allMapDataStore.addFilterId); saveFilter(this.allMapDataStore.addFilterId);
} };
} }
}, },
} }

View File

@@ -294,7 +294,7 @@ export default defineStore('allMapDataStore', {
try { try {
const response = await this.$axios.put(api, data); const response = await this.$axios.put(api, data);
this.isUpdataFilter = response.data.is_modified; this.isUpdataFilter = response.status === 200;
}catch(error) { }catch(error) {
this.httpStatus = error.request.status; this.httpStatus = error.request.status;
await delay(); await delay();

View File

@@ -69,7 +69,7 @@ export default defineStore('filesStore', {
o.parentLog = "-"; o.parentLog = "-";
o.fileType = "Log"; o.fileType = "Log";
o.ownerName = o.owner.name; o.ownerName = o.owner.name;
o.updated_at = moment(o.updated_at).utcOffset('+08:00').format('YYYY-MM-DD HH:MM'); 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; o.accessed_at = o.accessed_at ? moment(o.accessed_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm') : null;
return this.allEventLog return this.allEventLog
}) })
@@ -102,7 +102,7 @@ export default defineStore('filesStore', {
o.parentLog = o.log.name; o.parentLog = o.log.name;
o.fileType = "Filter"; o.fileType = "Filter";
o.ownerName = o.owner.name; o.ownerName = o.owner.name;
o.updated_at = moment(o.updated_at).utcOffset('+08:00').format('YYYY-MM-DD HH:MM'); 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; o.accessed_at = o.accessed_at ? moment(o.accessed_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm') : null;
}); });
if(this.httpStatus < 300) loading.isLoading = false; if(this.httpStatus < 300) loading.isLoading = false;