diff --git a/src/store/qualifyingTest/qualifyingTest.js b/src/store/qualifyingTest/qualifyingTest.js index ba2b865be..c9fe34e87 100644 --- a/src/store/qualifyingTest/qualifyingTest.js +++ b/src/store/qualifyingTest/qualifyingTest.js @@ -12,7 +12,6 @@ export default { actions: { bind: firestoreAction(({ bindFirestoreRef }, id) => { const firestoreRef = collection.doc(id); - return bindFirestoreRef('record', firestoreRef, { serialize: vuexfireSerialize }); }), unbind: firestoreAction(({ unbindFirestoreRef }) => { @@ -20,8 +19,9 @@ export default { }), bindQTs: firestoreAction(({ bindFirestoreRef }, id) => { const firestoreRef = collection - .where('vacancy.id', '==', id); - + .where('vacancy.id', '==', id) + .orderBy('title') + .orderBy('startDate'); return bindFirestoreRef('records', firestoreRef, { serialize: vuexfireSerialize }); }), unbindQTs: firestoreAction(({ unbindFirestoreRef }) => { @@ -30,30 +30,43 @@ export default { create: async (state, data) => { data.created = firebase.firestore.FieldValue.serverTimestamp(); data.status = QUALIFYING_TEST.STATUS.CREATED; - + data.lastUpdated = null; + data.counts = {}; const doc = await collection.add(data); - return doc.id; }, save: async ({ state }, data) => { data.lastUpdated = firebase.firestore.FieldValue.serverTimestamp(); - return await collection.doc(state.record.id).update(data); }, submitForApproval: async ({ state }) => { const data = { status: QUALIFYING_TEST.STATUS.SUBMITTED, }; - await collection.doc(state.record.id).update(data); }, approve: async ({ state }) => { const data = { status: QUALIFYING_TEST.STATUS.APPROVED, }; - await collection.doc(state.record.id).update(data); }, + copy: async (context) => { + const qualifyingTest = context.state.record; + const data = context.getters.data(); + data.title += ' copy'; + data.mode = 'mop-up'; + data.relationship = { + copiedFrom: qualifyingTest.id, + }; + data.startDate = null; + data.endDate = null; + const newId = await context.dispatch('create', data); + return newId; + }, + delete: async ({ state }) => { + await collection.doc(state.record.id).delete(); + }, }, state: { record: null, @@ -62,7 +75,6 @@ export default { getters: { id: (state) => { if (state.record === null) return null; - return state.record.id; }, data: (state) => () => { diff --git a/src/views/Exercises/Tasks/QualifyingTests/Cover.vue b/src/views/Exercises/Tasks/QualifyingTests/Cover.vue index dea89ead3..6007e2e1a 100644 --- a/src/views/Exercises/Tasks/QualifyingTests/Cover.vue +++ b/src/views/Exercises/Tasks/QualifyingTests/Cover.vue @@ -23,8 +23,10 @@ {{ row.mode | lookup }} +
+ {{ row.startDate | formatDate('longdatetime') }} {{ row.type | lookup }} diff --git a/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest.vue b/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest.vue index 9d6bfb398..406621f8f 100644 --- a/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest.vue +++ b/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest.vue @@ -20,26 +20,38 @@ export default { loadFailed: false, }; }, + computed: { + qualifyingTestId() { + return this.$route.params.qualifyingTestId; + }, + }, + watch: { + '$route.params.qualifyingTestId'() { + this.loadPage(); + }, + }, mounted() { - const id = this.$route.params.qualifyingTestId; - - this.$store.dispatch('qualifyingTest/bind', id) - .then((data) => { - if (data === null) { - this.redirectToPage(); - } - else { - this.loaded = true; - } - }).catch((e) => { - this.loadFailed = true; - throw e; - }); + this.loadPage(); }, destroyed() { this.$store.dispatch('qualifyingTest/unbind'); }, methods: { + loadPage() { + this.loaded = false; + this.$store.dispatch('qualifyingTest/bind', this.qualifyingTestId) + .then((data) => { + if (data === null) { + this.redirectToPage(); + } + else { + this.loaded = true; + } + }).catch((e) => { + this.loadFailed = true; + throw e; + }); + }, redirectToPage() { // this.$router.replace({ name: 'page-not-found' }); this.$router.replace({ name: 'exercise-tasks-qualifying-tests' }); diff --git a/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest/View.vue b/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest/View.vue index 9fd589811..233300701 100644 --- a/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest/View.vue +++ b/src/views/Exercises/Tasks/QualifyingTests/QualifyingTest/View.vue @@ -90,7 +90,6 @@ class="govuk-grid-column-one-half" >

@@ -225,10 +224,18 @@ Reasonable Adjustments + + @@ -275,7 +282,7 @@ export default { return record; }, hasCounts() { - return this.qualifyingTest.counts; + return this.qualifyingTest.counts && this.qualifyingTest.counts.initialised; }, isCreated() { return this.qualifyingTest.status === QUALIFYING_TEST.STATUS.CREATED; @@ -309,6 +316,14 @@ export default { const endDate = new Date(this.qualifyingTest.endDate); return isDateGreaterThan(endDate, today); }, + canCreateCopy() { + return !this.isMopUp && ( + this.isInitialised || + this.isActivated || + this.isPaused || + this.isCompleted + ); + }, }, methods: { btnEdit() { @@ -351,6 +366,16 @@ export default { qtStatus(status) { return QUALIFYING_TEST.STATUS[status]; }, + async btnCreateCopy() { + const newTestId = await this.$store.dispatch('qualifyingTest/copy'); + this.$router.push({ + name: 'qualifying-test-edit', + params: { + qualifyingTestId: newTestId, + }, + }); + + }, }, };