Persist event log user preferences

This commit is contained in:
D. Berge
2025-08-22 15:56:12 +02:00
parent 2734870871
commit bf054d3902

View File

@@ -548,6 +548,7 @@ export default {
watch: { watch: {
options: { options: {
async handler () { async handler () {
this.savePrefs(),
await this.fetchEvents(); await this.fetchEvents();
}, },
deep: true deep: true
@@ -566,16 +567,19 @@ export default {
}, },
filter (newVal, oldVal) { filter (newVal, oldVal) {
this.savePrefs();
if (newVal?.toLowerCase() != oldVal?.toLowerCase()) { if (newVal?.toLowerCase() != oldVal?.toLowerCase()) {
this.fetchEvents(); this.fetchEvents();
} }
}, },
labelSearch () { labelSearch () {
this.savePrefs();
this.fetchEvents(); this.fetchEvents();
}, },
filteredLabels () { filteredLabels () {
this.savePrefs()
this.fetchEvents(); this.fetchEvents();
}, },
@@ -584,7 +588,7 @@ export default {
}, },
user (newVal, oldVal) { user (newVal, oldVal) {
this.itemsPerPage = Number(localStorage.getItem(`dougal/prefs/${this.user?.name}/${this.$route.params.project}/${this.$options.name}/items-per-page`)) || 25; this.loadPrefs();
} }
}, },
@@ -876,10 +880,36 @@ export default {
*/ */
}, },
getPrefsKey () {
return `dougal/prefs/${this.user?.name}/${this.$route.params.project}/Log/v1`;
},
savePrefs () {
const prefs = {
shownLabels: this.shownLabels,
labelSearch: this.labelSearch,
filter: this.filter,
options: this.options
};
localStorage.setItem(this.getPrefsKey(), JSON.stringify(prefs));
},
loadPrefs () {
const stored = localStorage.getItem(this.getPrefsKey());
if (stored) {
const prefs = JSON.parse(stored);
if (prefs.shownLabels !== undefined) this.shownLabels = prefs.shownLabels;
if (prefs.labelSearch !== undefined) this.labelSearch = prefs.labelSearch;
if (prefs.filter !== undefined) this.filter = prefs.filter;
if (prefs.options !== undefined) this.options = prefs.options;
}
},
...mapActions(["api", "showSnack", "refreshEvents", "getEvents"]) ...mapActions(["api", "showSnack", "refreshEvents", "getEvents"])
}, },
async mounted () { async mounted () {
this.loadPrefs();
this.fetchEvents(); this.fetchEvents();
window.addEventListener('keyup', this.handleKeyboardEvent); window.addEventListener('keyup', this.handleKeyboardEvent);