case 4503

This commit is contained in:
2023-04-06 00:37:29 +00:00
parent c94dea1dd3
commit 585635939f
2 changed files with 238 additions and 21 deletions

View File

@@ -180,7 +180,7 @@ export default {
"Cancel", "Cancel",
"Close", "Close",
"Save", "Save",
"SaveACopy", "SaveAs",
"Delete", "Delete",
"SoftDelete", "SoftDelete",
"SoftDeleteAll", "SoftDeleteAll",

View File

@@ -11,21 +11,157 @@
>{{ activeFilterNameAtOpen }} {{ activeFilterCreator }}</v-card-subtitle >{{ activeFilterNameAtOpen }} {{ activeFilterCreator }}</v-card-subtitle
> >
<v-card-text> <v-card-text>
<v-text-field <!-- ORIGINAL UI<template v-if="selectedSavedFilterToOverWrite == null">
v-model="activeFilter.name" <v-text-field
:readonly="formState.readOnly" v-model="activeFilter.name"
:label="$ay.t('GridFilterName')" :readonly="formState.readOnly"
required :label="$ay.t('SaveAs')"
></v-text-field> required
<v-checkbox ></v-text-field>
ref="public" <v-checkbox
v-model="activeFilter.public" ref="public"
:readonly="formState.readOnly" v-model="activeFilter.public"
:label="$ay.t('AnyUser')" :readonly="formState.readOnly"
data-cy="public" :label="$ay.t('AnyUser')"
></v-checkbox> data-cy="public"
></v-checkbox>
</template>
<v-select
v-if="offerReplace"
v-model="selectedSavedFilterToOverWrite"
:items="selectLists.savedFilters"
item-text="name"
item-value="id"
:label="$ay.t('Replace')"
>
</v-select> -->
<!--
TASKS:
save a default filter to a named filter
change and save a named filter
overwrite a named filter with new filter selections from default filter
Modes ON OPEN OF THIS DIALOG
- named saved filter was selected
edit: name, all users
Options: cancel, delete, {NOTE META NOT DOING THIS SEE NO PRACTICAL REASON "Duplicate" (was 'save a copy')}, Save if name or all users changed
- Default filter was selected
edit: name, all users, replace select
Options: cancel, delete (resets it), ["Save As" (was 'save a copy', only if replacement selection is NOT made) | "Replace" (if replace selection made)]
{{ activeFilter }}
-->
<template v-if="isDefaultFilter">
<!-- <pre>
- Default filter was selected
edit: name, all users, replace select
Options: cancel, delete (resets it), ["Save As" (was 'save a copy', only if replacement selection is NOT made) | "Replace" (if replace selection made)]
</pre
> -->
<div v-if="selectedSavedFilterToOverWrite == null" class="mb-5">
<!-- DEFAULT UN-NAMED FILTER BEING EDITED BLOCK -->
<h2>
{{ $ay.t("SaveAs") }}
</h2>
<v-text-field
v-model="activeFilter.name"
:readonly="formState.readOnly"
:label="$ay.t('GridFilterName')"
required
></v-text-field>
<v-checkbox
ref="public"
v-model="activeFilter.public"
:readonly="formState.readOnly"
:label="$ay.t('AnyUser')"
data-cy="public"
></v-checkbox>
</div>
<div v-if="offerReplace && !defaultFilterNameEdited" class="mb-5">
<h2>{{ $ay.t("Replace") }}</h2>
<v-select
v-model="selectedSavedFilterToOverWrite"
:items="selectLists.savedFilters"
item-text="name"
item-value="id"
:label="$ay.t('DataListSavedFilter')"
>
</v-select>
</div>
<v-card-actions>
<v-btn text color="primary" @click="close()">{{
$ay.t("Cancel")
}}</v-btn>
<v-spacer />
<template
v-if="isSelfOwned && selectedSavedFilterToOverWrite == null"
>
<v-btn text color="primary" @click="deleteFilter()">{{
$ay.t("Delete")
}}</v-btn>
<v-spacer />
</template>
<v-btn
v-if="selectedSavedFilterToOverWrite == null"
text
:disabled="!defaultFilterIsSavAsAble"
color="primary"
@click="saveAndExit('save-as-new')"
>{{ $ay.t("Save") }}</v-btn
>
<v-btn
v-if="selectedSavedFilterToOverWrite != null"
text
color="primary"
@click="saveAndExit('save-over-existing-named')"
>{{ $ay.t("Replace") }}</v-btn
>
</v-card-actions>
</template>
<template v-else>
<!-- EXISTING NAMED FILTER BEING EDITED BLOCK -->
<v-text-field
v-model="activeFilter.name"
:readonly="formState.readOnly"
:label="$ay.t('GridFilterName')"
required
></v-text-field>
<v-checkbox
ref="public"
v-model="activeFilter.public"
:readonly="formState.readOnly"
:label="$ay.t('AnyUser')"
data-cy="public"
></v-checkbox>
<v-card-actions>
<v-btn text color="primary" @click="close()">{{
$ay.t("Cancel")
}}</v-btn>
<v-spacer />
<template v-if="isSelfOwned">
<v-btn text color="primary" @click="deleteFilter()">{{
$ay.t("Delete")
}}</v-btn>
<v-spacer />
</template>
<v-btn
text
:disabled="!namedFilterIsSavable"
color="primary"
@click="saveAndExit('save-over-existing-named')"
>{{ $ay.t("Save") }}</v-btn
>
</v-card-actions>
</template>
</v-card-text> </v-card-text>
<v-card-actions>
<!-- <v-card-actions>
<v-btn text color="primary" @click="close()">{{ <v-btn text color="primary" @click="close()">{{
$ay.t("Cancel") $ay.t("Cancel")
}}</v-btn> }}</v-btn>
@@ -38,16 +174,17 @@
</template> </template>
<v-btn text color="primary" @click="saveAndExit(true)">{{ <v-btn text color="primary" @click="saveAndExit(true)">{{
$ay.t("SaveACopy") $ay.t("SaveAs")
}}</v-btn> }}</v-btn>
<template v-if="activeFilter.defaultFilter == false && isSelfOwned"> v-if="activeFilter.defaultFilter == false && isSelfOwned"
<template v-if="replaceMode">
<v-spacer /> <v-spacer />
<v-btn text color="primary" @click="saveAndExit()">{{ <v-btn text color="primary" @click="saveAndExit()">{{
$ay.t("Save") $ay.t("Replace")
}}</v-btn> }}</v-btn>
</template> </template>
</v-card-actions> </v-card-actions> -->
</v-card> </v-card>
</v-dialog> </v-dialog>
</template> </template>
@@ -72,8 +209,14 @@ export default {
filter: "[]" filter: "[]"
}, },
activeFilterNameAtOpen: null, activeFilterNameAtOpen: null,
activeFilterPublicAtOpen: null,
activeFilterCreator: "", activeFilterCreator: "",
isSelfOwned: true, isSelfOwned: true,
selectedSavedFilterToOverWrite: null,
selectLists: {
savedFilters: []
},
formState: { formState: {
ready: false, ready: false,
dirty: false, dirty: false,
@@ -85,9 +228,58 @@ export default {
serverError: {} serverError: {}
} }
}), }),
computed: {
offerReplace() {
return (
this.activeFilter.defaultFilter &&
this.selectLists.savedFilters.length > 0
);
},
isDefaultFilter() {
if (this.activeFilter && this.activeFilter.defaultFilter) {
return true;
}
return false;
},
namedFilterIsSavable() {
if (
this.activeFilter.name != this.activeFilterNameAtOpen ||
this.activeFilter.public != this.activeFilterPublicAtOpen
) {
return true;
} else {
return false;
}
},
defaultFilterNameEdited() {
if (this.activeFilter.name != this.activeFilterNameAtOpen) {
return true;
} else {
return false;
}
},
defaultFilterIsSavAsAble() {
if (
this.defaultFilterNameEdited &&
this.selectedSavedFilterToOverWrite == null
) {
return true;
} else {
return false;
}
},
defaultFilterIsOverWriteSavAble() {
if (this.selectedSavedFilterToOverWrite != null) {
return true;
} else {
return false;
}
}
},
async created() { async created() {
await initForm(this); await initForm(this);
}, },
methods: { methods: {
async deleteFilter() { async deleteFilter() {
//prompt if a true delete and not a default filter "reset" //prompt if a true delete and not a default filter "reset"
@@ -108,6 +300,9 @@ export default {
} }
}, },
async saveAndExit(saveAs) { async saveAndExit(saveAs) {
//TODO: if it's going to do a replace then it needs to get a fresh copy of the replacement filter and it's concurrency token etc
//otherwise saveAs is fine as is I think
if (saveAs) { if (saveAs) {
//SAVE AS //SAVE AS
//strip ID //strip ID
@@ -148,12 +343,13 @@ export default {
}, },
async open(tableColumnData) { async open(tableColumnData) {
this.tableColumnData = tableColumnData; this.tableColumnData = tableColumnData;
this.selectedSavedFilterToOverWrite = null;
await fetchActiveFilter(this); await fetchActiveFilter(this);
this.activeFilterNameAtOpen = this.activeFilter.name; this.activeFilterNameAtOpen = this.activeFilter.name;
this.activeFilterPublicAtOpen = this.activeFilter.public;
this.isSelfOwned = this.isSelfOwned =
this.activeFilter.userId == window.$gz.store.state.userId; this.activeFilter.userId == window.$gz.store.state.userId;
//Get owner name //Get owner name
if (!this.isSelfOwned) { if (!this.isSelfOwned) {
const res = await window.$gz.api.post("pick-list/list", { const res = await window.$gz.api.post("pick-list/list", {
@@ -170,6 +366,8 @@ export default {
} }
} }
await fetchSavedFilterList(this);
this.isVisible = true; this.isVisible = true;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.resolve = resolve; this.resolve = resolve;
@@ -202,11 +400,30 @@ async function fetchActiveFilter(vm) {
} }
} }
////////////////////
//
async function fetchSavedFilterList(vm) {
const res = await window.$gz.api.get(
"data-list-filter/list?ListKey=" + vm.dataListKey
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//use previous selects but weed out default filter
vm.selectLists.savedFilters = res.data.filter(z => z.default != true);
}
}
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
// //
// Ensures UI translated text is available // Ensures UI translated text is available
// //
async function fetchTranslatedText() { async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations(["GridFilterName", "AnyUser"]); await window.$gz.translation.cacheTranslations([
"GridFilterName",
"AnyUser",
"DataListSavedFilter"
]);
} }
</script> </script>