From 6896d8bc8729002f72515124edd3124b45897210 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Thu, 15 Oct 2020 19:07:27 +0200 Subject: [PATCH] Change sequence renumbering behaviour. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, change just the number of the sequence being edited. It is checked for conflict with other planned sequences but not with anything already acquired. If the user ticks the ‘shift all’ checkbox, then all planned sequences are shifted by the same amount. --- lib/www/client/source/src/views/Plan.vue | 46 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/www/client/source/src/views/Plan.vue b/lib/www/client/source/src/views/Plan.vue index f07eca0..7b348f5 100644 --- a/lib/www/client/source/src/views/Plan.vue +++ b/lib/www/client/source/src/views/Plan.vue @@ -58,6 +58,11 @@ single-line > + @@ -320,6 +325,7 @@ export default { queuedReload: false, plannerConfig: null, + shiftAll: false, // Shift all sequences checkbox // Context menu stuff contextMenuShow: false, @@ -355,7 +361,11 @@ export default { await this.shiftTimesAfter(item, delta); await this.saveItem({sequence: item.sequence, key: 'ts1', value: ts1}); } else if (oldVal.key == "sequence") { - await this.shiftSequences(oldVal.value-item.sequence); + if (this.shiftAll) { + await this.shiftSequences(oldVal.value-item.sequence); + } else { + await this.shiftSequence(item, oldVal.value); + } } else if (item[oldVal.key] != oldVal.value) { if (await this.saveItem(oldVal)) { item[oldVal.key] = oldVal.value; @@ -449,6 +459,38 @@ export default { } }, + async shiftSequence (item, newSequence) { + + if (item.sequence == newSequence) { + // Nothing to do + return; + } + + const conflict = this.items.find(i => i.sequence == newSequence) + if (conflict) { + this.showSnack([`Sequence ${newSequence} already exists`, "error"]); + } else { + // Cannot do this check at the moment as we would have to load the list of sequences. + // TODO We will do this after refactoring. + /* + if (this.sequences.find(i => i.sequence == newSequence)) { + this.showSnack([`Sequence ${newSequence} conflicts with a line that's already been acquired`, "warning"]); + } + */ + + const url = `/project/${this.$route.params.project}/plan/${item.sequence}`; + const init = { + method: "PATCH", + headers: {"Content-Type": "application/json"}, + body: { + sequence: newSequence, + name: null + } // Setting name to null causes it to be regenerated + } + await this.api([url, init]); + } + }, + async shiftTimesAfter(item, delta) { const pos = this.items.indexOf(item)+1; if (pos != 0) { @@ -546,7 +588,7 @@ export default { : item; }, - ...mapActions(["api"]) + ...mapActions(["api", "showSnack"]) }, async mounted () {