From 6dd31ead4fe49e3c5f25a0ce977dadf2999e7bd3 Mon Sep 17 00:00:00 2001 From: Tim Bradgate Date: Sun, 18 Jun 2023 12:00:11 +0100 Subject: [PATCH] Add Go To Page functionality for Cue Editing --- .../show/config/cues/CueEditor.vue | 89 ++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/client/src/vue_components/show/config/cues/CueEditor.vue b/client/src/vue_components/show/config/cues/CueEditor.vue index 043642a1..d55560f1 100644 --- a/client/src/vue_components/show/config/cues/CueEditor.vue +++ b/client/src/vue_components/show/config/cues/CueEditor.vue @@ -4,7 +4,14 @@ fluid > - + + + Go to Page + + + + + + + + This is a required field, and must be greater than 0. + + + + @@ -95,6 +136,8 @@ import log from 'loglevel'; import { makeURL } from '@/js/utils'; import ScriptLineCueEditor from '@/vue_components/show/config/cues/ScriptLineCueEditor.vue'; +import { minValue, required } from 'vuelidate/lib/validators'; +import { notNull, notNullAndGreaterThanZero } from '@/js/customValidators'; export default { name: 'CueEditor', @@ -115,8 +158,22 @@ export default { savingInProgress: false, saveError: false, currentMaxPage: 1, + changingPage: false, + pageInputFormState: { + pageNo: 1, + }, }; }, + validations: { + pageInputFormState: { + pageNo: { + required, + notNull, + notNullAndGreaterThanZero, + minValue: minValue(1), + }, + }, + }, async beforeMount() { // Config status await this.GET_SCRIPT_CONFIG_STATUS(); @@ -133,8 +190,12 @@ export default { await this.getMaxScriptPage(); // Initialisation of page data - await this.LOAD_SCRIPT_PAGE(this.currentEditPage); - await this.LOAD_SCRIPT_PAGE(this.currentEditPage + 1); + // Initialisation of page data + const storedPage = localStorage.getItem('cueEditPage'); + if (storedPage != null) { + this.currentEditPage = parseInt(storedPage, 10); + } + await this.goToPageInner(this.currentEditPage); }, methods: { async getMaxScriptPage() { @@ -179,6 +240,23 @@ export default { } return []; }, + validatePageState(name) { + const { $dirty, $error } = this.$v.pageInputFormState[name]; + return $dirty ? !$error : null; + }, + async goToPage() { + this.changingPage = true; + await this.goToPageInner(this.pageInputFormState.pageNo); + this.changingPage = false; + }, + async goToPageInner(pageNo) { + if (pageNo > 1) { + await this.LOAD_SCRIPT_PAGE(parseInt(pageNo, 10) - 1); + } + await this.LOAD_SCRIPT_PAGE(pageNo); + this.currentEditPage = pageNo; + await this.LOAD_SCRIPT_PAGE(parseInt(pageNo, 10) + 1); + }, ...mapMutations(['REMOVE_PAGE', 'ADD_BLANK_LINE', 'SET_LINE']), ...mapActions(['GET_SCENE_LIST', 'GET_ACT_LIST', 'GET_CHARACTER_LIST', 'GET_CHARACTER_GROUP_LIST', 'LOAD_SCRIPT_PAGE', 'ADD_BLANK_PAGE', 'GET_SCRIPT_CONFIG_STATUS', @@ -199,5 +277,10 @@ export default { 'CHARACTER_GROUP_LIST', 'CAN_REQUEST_EDIT', 'CURRENT_EDITOR', 'INTERNAL_UUID', 'GET_SCRIPT_PAGE', 'DEBUG_MODE_ENABLED', 'CUE_TYPES', 'SCRIPT_CUES', 'SCRIPT_CUTS']), }, + watch: { + currentEditPage(val) { + localStorage.setItem('cueEditPage', val); + }, + }, };