Skip to content

Commit

Permalink
Merge branch 'main' into 1894-draft-applications-under-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlovesgithub committed Jun 2, 2023
2 parents f58805a + f7cc62b commit 98cea63
Show file tree
Hide file tree
Showing 13 changed files with 8,576 additions and 3,163 deletions.
11,247 changes: 8,176 additions & 3,071 deletions package-lock.json

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions src/components/ModalViews/OverrideExercise.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<template>
<div>
<div class="modal__title text-left govuk-!-padding-2 background-blue">
<h2 class="govuk-heading-m govuk-!-margin-bottom-0">
Override an exercise
</h2>
</div>
<div class="modal__content govuk-!-margin-6">
<div style="text-align: left;">
<p
v-if="errorMessage"
class="govuk-error-message"
>
{{ errorMessage }}
</p>
<Select
id="draft-exercise-select"
v-model="referenceNumber"
label=""
required
>
<option
v-for="exercise in draftRecords"
:key="exercise.referenceNumber"
:value="exercise.referenceNumber"
>
{{ `${exercise.referenceNumber} ${exercise.name}` }}
</option>
</Select>
<button
class="govuk-button govuk-!-margin-right-3"
:disabled="!referenceNumber"
@click="save"
>
Override
</button>
<button
type="button"
class="govuk-button govuk-button--secondary govuk-!-margin-right-3"
@click="closeModal"
>
Cancel
</button>
</div>
</div>
</div>
</template>

<script>
import { mapState } from 'vuex';
import Select from '@jac-uk/jac-kit/draftComponents/Form/Select';
export default {
name: 'OverrideExercise',
components: {
Select,
},
data() {
return {
referenceNumber: '',
errorMessage: '',
};
},
computed: {
...mapState('exerciseCollection', [
'draftRecords',
]),
},
mounted() {
this.$store.dispatch('exerciseCollection/bindDraft');
},
destroyed() {
this.$store.dispatch('exerciseCollection/unbindDraft');
},
methods: {
closeModal() {
this.$emit('close');
},
async save() {
this.errorMessage = '';
if (!this.referenceNumber) {
this.errorMessage = 'Please select an exercise.';
return;
}
const exercise = this.draftRecords.find(record => record.referenceNumber === this.referenceNumber);
if (exercise) {
this.$emit('confirmed', { exerciseId: exercise.id, referenceNumber: this.referenceNumber });
this.errorMessage = '';
} else {
this.errorMessage = 'Exercise does not exist.';
}
},
},
};
</script>

<style scoped>
fieldset {
border: none;
padding: 0;
margin: 0;
}
</style>
1 change: 1 addition & 0 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const lookup = (value) => {
noAnswer: 'No answer',
genderNeutral: 'Gender neutral',
firstGenerationUniversity: 'First generation at University',
parentsAttendedUniversity: 'Parents attended University',
attendedUKStateSchool: 'Attended UK state school',
white: 'White',
bame: 'Ethnic minorities',
Expand Down
32 changes: 26 additions & 6 deletions src/reports.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { lookup } from '@/filters';
import _cloneDeep from 'lodash/cloneDeep';

const REPORTS = {
ApplicationStageDiversity: {
Expand Down Expand Up @@ -110,15 +111,11 @@ const REPORTS = {
title: `${lookup('noAnswer')}`,
},
],
socialMobility: [
socialMobility: [ // THIS VARIES SO WILL BE APPENDED TO BEFORE BEING RETURNED
{
key: 'attendedUKStateSchool',
title: `${lookup('attendedUKStateSchool')}`,
},
{
key: 'firstGenerationUniversity',
title: `${lookup('firstGenerationUniversity')}`,
},
],
professionalBackground: [
{
Expand Down Expand Up @@ -150,4 +147,27 @@ const REPORTS = {
},
};

export default REPORTS;
const pre04012023SocialMobility = {
key: 'firstGenerationUniversity',
title: `${lookup('firstGenerationUniversity')}`,
};

const post04012023SocialMobility = {
key: 'parentsAttendedUniversity',
title: `${lookup('parentsAttendedUniversity')}`,
};

const getReports = (applicationOpenDate) => {
const mergedReports = _cloneDeep(REPORTS);
if (applicationOpenDate > new Date('2023-04-01')) {
mergedReports.ApplicationStageDiversity.legend.socialMobility.push(post04012023SocialMobility);
}
else {
mergedReports.ApplicationStageDiversity.legend.socialMobility.push(pre04012023SocialMobility);
}
return mergedReports;
};

export {
getReports
};
10 changes: 10 additions & 0 deletions src/store/exercise/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export default {
unbind: firestoreAction(({ unbindFirestoreRef }) => {
return unbindFirestoreRef('records');
}),
bindDraft: firestoreAction(({ bindFirestoreRef }) => {
const firestoreRef = firestore
.collection('exercises')
.where('state', '==', 'draft');
return bindFirestoreRef('draftRecords', firestoreRef, { serialize: vuexfireSerialize });
}),
unbindDraft: firestoreAction(({ unbindFirestoreRef }) => {
return unbindFirestoreRef('draftRecords');
}),
showFavourites: ({ commit, dispatch }) => {
commit('updateFavourites', true);
commit('updateArchived', false);
Expand Down Expand Up @@ -112,6 +121,7 @@ export default {
},
state: {
records: [],
draftRecords: [],
isFavourites: false,
isArchived: false,
selectedItems: [],
Expand Down
19 changes: 19 additions & 0 deletions src/store/exercise/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export default {
const docRef = await collection.doc(id).get();
return docRef.data();
},
getDocumentDataByReferenceNumber: async (context, referenceNumber) => {
let exercise = null;
const snap = await collection.where('referenceNumber', '==', referenceNumber).limit(1).get();
if (snap.empty) return null;

snap.forEach(doc => {
const row = doc.data();
row.id = doc.id;
exercise = row;
});
return exercise;
},
create: async ({ rootState, dispatch }, data) => {
const metaRef = firestore.collection('meta').doc('stats');
return firestore.runTransaction((transaction) => {
Expand All @@ -52,6 +64,9 @@ export default {
return dispatch('bind', newId);
});
},
override: async (_, { exerciseId, data }) => {
await collection.doc(exerciseId).update(data);
},
save: async ({ state }, data) => {
const saveData = clone(data);
if (JSON.stringify(saveData).indexOf('_applicationContent') === -1) { // recalculate applicationContent (if necessary)
Expand Down Expand Up @@ -243,5 +258,9 @@ export default {
}
return null;
},
applicationOpenDatePost01042023: (state) => {
// Used to facilitate different fields after 01-04-2023
return state.record.applicationOpenDate > new Date('2023-04-01');
},
},
};
12 changes: 6 additions & 6 deletions src/views/Candidates/CandidatesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
<Applications :candidate-id="candidateId" />
</div>
<div
v-if="activeTab === 'actions'"
v-if="activeTab === 'loginEmail'"
>
<Actions :candidate-id="getUserId" />
<UpdateLoginEmail :candidate-id="getUserId" />
</div>
</div>
</template>
Expand All @@ -88,7 +88,7 @@ import Applications from './Applications';
import PersonalDetailsSummary from '@/views/InformationReview/PersonalDetailsSummary';
import CharacterInformationSummary from '@/views/InformationReview/CharacterInformationSummary';
import EqualityAndDiversity from '@jac-uk/jac-kit/draftComponents/Candidates/EqualityAndDiversity';
import Actions from '@/views/Candidates/Actions';
import UpdateLoginEmail from '@/views/Candidates/UpdateLoginEmail';
import permissionMixin from '@/permissionMixin';
export default {
Expand All @@ -97,7 +97,7 @@ export default {
TabsList,
Notes,
Applications,
Actions,
UpdateLoginEmail,
PersonalDetailsSummary,
CharacterInformationSummary,
EqualityAndDiversity,
Expand Down Expand Up @@ -130,8 +130,8 @@ export default {
});
if (this.hasPermissions([this.PERMISSIONS.candidates.permissions.canUpdateCandidates.value]))
tabs.push({
ref: 'actions',
title: 'Actions',
ref: 'loginEmail',
title: 'Log in Email',
});
return tabs;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import ActionButton from '@jac-uk/jac-kit/draftComponents/ActionButton';
import permissionMixin from '@/permissionMixin';
export default {
name: 'Actions',
name: 'UpdateLoginEmail',
components: {
TextField,
Banner,
Expand Down
41 changes: 41 additions & 0 deletions src/views/CreateExercise.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
>
Create exercise from clipboard
</ActionButton>
<button
class="govuk-button govuk-button--secondary govuk-!-margin-left-3"
@click.prevent="openOverrideExerciseModal"
>
Override an exercise
</button>
</div>
</div>

Expand Down Expand Up @@ -124,6 +130,13 @@
</button>
</div>
</form>

<Modal ref="modalOverrideExercise">
<OverrideExercise
@close="closeOverrideExerciseModal"
@confirmed="overrideExercise"
/>
</Modal>
</div>
</template>

Expand All @@ -137,6 +150,9 @@ import CheckboxGroup from '@jac-uk/jac-kit/draftComponents/Form/CheckboxGroup';
import CheckboxItem from '@jac-uk/jac-kit/draftComponents/Form/CheckboxItem';
import BackLink from '@jac-uk/jac-kit/draftComponents/BackLink';
import ActionButton from '@jac-uk/jac-kit/draftComponents/ActionButton';
import Modal from '@jac-uk/jac-kit/components/Modal/Modal';
import OverrideExercise from '@/components/ModalViews/OverrideExercise.vue';
import { cloneDeep } from 'lodash';
export default {
name: 'CreateExercise',
Expand All @@ -149,6 +165,8 @@ export default {
CheckboxItem,
BackLink,
ActionButton,
Modal,
OverrideExercise,
},
extends: Form,
data() {
Expand Down Expand Up @@ -178,6 +196,29 @@ export default {
this.$router.push(this.$store.getters['exerciseCreateJourney/nextPage']());
}
},
openOverrideExerciseModal() {
this.$refs.modalOverrideExercise.openModal();
},
closeOverrideExerciseModal() {
this.$refs.modalOverrideExercise.closeModal();
},
async overrideExercise({ exerciseId, referenceNumber }) {
const content = cloneDeep(this.$store.state.clipboard.data.content);
// keep reference number
content.referenceNumber = referenceNumber;
content.state = 'draft';
// ignore fields that do not need to override
const ignoredFields = ['_applicationContent', '_applicationRecords', '_applications', '_approval', '_lateApplicationRequests'];
for (const field of ignoredFields) {
delete content[field];
}
await this.$store.dispatch('exerciseDocument/override', { exerciseId, data: content });
await this.$store.dispatch('clipboard/empty');
this.$store.dispatch('exerciseCreateJourney/start', []);
this.$router.push(`/exercise/${exerciseId}/dashboard`);
this.closeOverrideExerciseModal();
},
async copyFromClipboard() {
const content = this.$store.state.clipboard.data.content;
content.name = `${content.name} COPY`;
Expand Down
19 changes: 12 additions & 7 deletions src/views/Exercise.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,18 @@ export default {
}
},
async copyToClipboard() {
const exercise = await this.$store.dispatch('exerciseDocument/getDocumentData', this.exerciseId);
await this.$store.dispatch('clipboard/write', {
environment: this.$store.getters.appEnvironment,
type: 'exercise',
title: `${exercise.referenceNumber} ${exercise.name}`,
content: exercise,
});
try {
const exercise = await this.$store.dispatch('exerciseDocument/getDocumentData', this.exerciseId);
await this.$store.dispatch('clipboard/write', {
environment: this.$store.getters.appEnvironment,
type: 'exercise',
title: `${exercise.referenceNumber} ${exercise.name}`,
content: exercise,
});
return true;
} catch (error) {
return;
}
},
openArchiveModal() {
this.$refs.archiveModal.openModal();
Expand Down
Loading

0 comments on commit 98cea63

Please sign in to comment.