Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#877 Create a mop up QT #908

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/store/qualifyingTest/qualifyingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export default {
actions: {
bind: firestoreAction(({ bindFirestoreRef }, id) => {
const firestoreRef = collection.doc(id);

return bindFirestoreRef('record', firestoreRef, { serialize: vuexfireSerialize });
}),
unbind: firestoreAction(({ unbindFirestoreRef }) => {
return unbindFirestoreRef('record');
}),
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 }) => {
Expand All @@ -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,
Expand All @@ -62,7 +75,6 @@ export default {
getters: {
id: (state) => {
if (state.record === null) return null;

return state.record.id;
},
data: (state) => () => {
Expand Down
4 changes: 3 additions & 1 deletion src/views/Exercises/Tasks/QualifyingTests/Cover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
</RouterLink>
<span
v-if="row.mode"
class="govuk-tag govuk-tag--grey govuk-!-margin-left-2"
class="govuk-tag govuk-tag--grey govuk-!-margin-left-1"
>{{ row.mode | lookup }}</span>
<br>
<span class="govuk-body-s">{{ row.startDate | formatDate('longdatetime') }}</span>
</TableCell>
<TableCell>
{{ row.type | lookup }}
Expand Down
40 changes: 26 additions & 14 deletions src/views/Exercises/Tasks/QualifyingTests/QualifyingTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
31 changes: 28 additions & 3 deletions src/views/Exercises/Tasks/QualifyingTests/QualifyingTest/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
class="govuk-grid-column-one-half"
>
<div
v-if="true"
class="background-light-grey govuk-!-padding-4 govuk-!-margin-bottom-3"
>
<h2 class="govuk-heading-l">
Expand Down Expand Up @@ -225,10 +224,18 @@
Reasonable Adjustments
</button>

<button
v-if="canCreateCopy"
class="govuk-button govuk-button--secondary govuk-!-margin-right-3"
@click="btnCreateCopy"
>
Create Mop Up Test
</button>

<ActionButton
v-if="isInitialised"
type="secondary"
:disabled="false"
:disabled="true"
class="govuk-!-margin-right-3"
@click="btnSendInvites"
>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
},
});

},
},
};
</script>