Adapt Plan component to Vuex use for fetching data

This commit is contained in:
D. Berge
2023-10-25 16:14:45 +02:00
parent 503a0de12f
commit 171feb9dd2

View File

@@ -44,6 +44,7 @@
label="Filter" label="Filter"
single-line single-line
clearable clearable
hint="Filter by sequence, line, first or last shotpoints, remarks or start/end time"
></v-text-field> ></v-text-field>
</v-toolbar> </v-toolbar>
</v-card-title> </v-card-title>
@@ -109,11 +110,14 @@
:headers="headers" :headers="headers"
:items="items" :items="items"
:items-per-page.sync="itemsPerPage" :items-per-page.sync="itemsPerPage"
:server-items-length="sequenceCount"
item-key="sequence"
:search="filter" :search="filter"
:loading="loading" :loading="plannedSequencesLoading"
:fixed-header="true" fixed-header
no-data-text="No planned lines. Add lines via the context menu from either the Lines or Sequences view." no-data-text="No planned lines. Add lines via the context menu from either the Lines or Sequences view."
:item-class="(item) => (activeItem == item && !edit) ? 'blue accent-1 elevation-3' : ''" :item-class="(item) => (activeItem == item && !edit) ? 'blue accent-1 elevation-3' : ''"
:footer-props="{showFirstLastPage: true}"
@click:row="setActiveItem" @click:row="setActiveItem"
@contextmenu:row="contextMenu" @contextmenu:row="contextMenu"
> >
@@ -275,7 +279,7 @@
icon icon
small small
title="Edit" title="Edit"
:disabled="loading" :disabled="plannedSequencesLoading"
@click="editItem(item, 'remarks')" @click="editItem(item, 'remarks')"
> >
<v-icon small>mdi-square-edit-outline</v-icon> <v-icon small>mdi-square-edit-outline</v-icon>
@@ -417,7 +421,8 @@ export default {
remarks: null, remarks: null,
editRemarks: false, editRemarks: false,
filter: null, filter: null,
num_lines: null, options: {},
sequenceCount: null,
activeItem: null, activeItem: null,
edit: null, // {sequence, key, value} edit: null, // {sequence, key, value}
queuedReload: false, queuedReload: false,
@@ -552,11 +557,22 @@ export default {
}, },
computed: { computed: {
...mapGetters(['user', 'writeaccess', 'loading', 'serverEvent']) ...mapGetters(['user', 'writeaccess', 'plannedSequencesLoading', 'plannedSequences', 'planRemarks'])
}, },
watch: { watch: {
options: {
handler () {
this.fetchPlannedSequences();
},
deep: true
},
async plannedSequences () {
await this.fetchPlannedSequences();
},
async edit (newVal, oldVal) { async edit (newVal, oldVal) {
if (newVal === null && oldVal !== null) { if (newVal === null && oldVal !== null) {
const item = this.items.find(i => i.sequence == oldVal.sequence); const item = this.items.find(i => i.sequence == oldVal.sequence);
@@ -587,41 +603,9 @@ export default {
} }
}, },
async serverEvent (event) { filter (newVal, oldVal) {
if (event.channel == "planned_lines" && event.payload.pid == this.$route.params.project) { if (newVal?.toLowerCase() != oldVal?.toLowerCase()) {
this.fetchPlannedSequences();
// Ignore non-ops
/*
if (event.payload.old === null && event.payload.new === null) {
return;
}
*/
if (!this.loading && !this.queuedReload) {
// Do not force a non-cached response if refreshing as a result
// of an event notification. We will assume that the server has
// already had time to update the cache by the time our request
// gets back to it.
this.getPlannedLines();
} else {
this.queuedReload = true;
}
} else if (event.channel == "info" && event.payload.pid == this.$route.params.project) {
if (event.payload?.new?.key == "plan" && ("remarks" in (event.payload?.new?.value || {}))) {
this.remarks = event.payload?.new.value.remarks;
}
}
},
queuedReload (newVal, oldVal) {
if (newVal && !oldVal && !this.loading) {
this.getPlannedLines();
}
},
loading (newVal, oldVal) {
if (!newVal && oldVal && this.queuedReload) {
this.getPlannedLines();
} }
}, },
@@ -890,7 +874,6 @@ export default {
const url = `/project/${this.$route.params.project}/plan/${this.contextMenuItem.sequence}`; const url = `/project/${this.$route.params.project}/plan/${this.contextMenuItem.sequence}`;
const init = {method: "DELETE"}; const init = {method: "DELETE"};
await this.api([url, init]); await this.api([url, init]);
await this.getPlannedLines();
}, },
editItem (item, key, value) { editItem (item, key, value) {
@@ -942,21 +925,6 @@ export default {
} }
}, },
async getPlannedLines () {
const url = `/project/${this.$route.params.project}/plan`;
this.queuedReload = false;
this.items = await this.api([url]) || [];
for (const item of this.items) {
item.ts0 = new Date(item.ts0);
item.ts1 = new Date(item.ts1);
this.wxQuery(item).then( (wx) => {
item.meta = {...item.meta, wx};
});
}
},
async getPlannerConfig () { async getPlannerConfig () {
const url = `/project/${this.$route.params.project}/configuration/planner`; const url = `/project/${this.$route.params.project}/configuration/planner`;
this.plannerConfig = await this.api([url]) || { this.plannerConfig = await this.api([url]) || {
@@ -967,14 +935,15 @@ export default {
} }
}, },
async getPlannerRemarks () { async fetchPlannedSequences (opts = {}) {
const url = `/project/${this.$route.params.project}/info/plan/remarks`; const options = {
this.remarks = await this.api([url]) || ""; text: this.filter,
}, ...this.options
};
async getSequences () { const res = await this.getPlannedSequences([this.$route.params.project, options]);
const url = `/project/${this.$route.params.project}/sequence`; this.items = res.sequences;
this.sequences = await this.api([url]) || []; this.sequenceCount = res.count;
this.remarks = this.planRemarks;
}, },
setActiveItem (item) { setActiveItem (item) {
@@ -983,13 +952,12 @@ export default {
: item; : item;
}, },
...mapActions(["api", "showSnack"]) ...mapActions(["api", "showSnack", "getPlannedSequences"])
}, },
async mounted () { async mounted () {
await this.getPlannerConfig(); await this.getPlannerConfig();
this.getPlannedLines(); await this.fetchPlannedSequences();
this.getPlannerRemarks();
} }
} }