Skip to content

Commit

Permalink
Merge pull request #1213 from jac-uk/1100-exports-should-be-prepared-…
Browse files Browse the repository at this point in the history
…server-side

4 x reports/exports should be prepared server side
  • Loading branch information
HalcyonJAC authored Mar 12, 2021
2 parents 640f462 + e3c5bb1 commit d9c2c00
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 740 deletions.
264 changes: 239 additions & 25 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "vue-cli-service lint",
"lint-ci": "vue-cli-service lint --no-fix",
"test": "vue-cli-service test:unit",
"test-ci": "vue-cli-service test:unit --ci --runInBand"
"test-ci": "vue-cli-service test:unit --ci --runInBand --detectOpenHandles --forceExit"
},
"dependencies": {
"@ckeditor/ckeditor5-build-classic": "^16.0.0",
Expand All @@ -26,6 +26,7 @@
"@ministryofjustice/frontend": "0.0.17-alpha",
"@sentry/browser": "^5.30.0",
"@sentry/integrations": "^5.30.0",
"@vue/compiler-sfc": "^3.0.7",
"canvas": "^2.6.1",
"core-js": "^2.6.12",
"file-saver": "^2.0.5",
Expand Down
127 changes: 23 additions & 104 deletions src/views/Exercises/Show/Applications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<script>
import Table from '@jac-uk/jac-kit/components/Table/Table';
import TableCell from '@jac-uk/jac-kit/components/Table/TableCell';
import * as filters from '@jac-uk/jac-kit/filters/filters';
import { functions } from '@/firebase';
import { downloadXLSX } from '@jac-uk/jac-kit/helpers/export';
export default {
Expand Down Expand Up @@ -97,126 +97,45 @@ export default {
},
},
methods: {
flattenCurrentLegalRole(equalityAndDiversitySurvey) {
if (!(equalityAndDiversitySurvey && equalityAndDiversitySurvey.currentLegalRole)) {
return '';
}
const roles = [];
equalityAndDiversitySurvey.currentLegalRole.forEach((role) => {
if (role === 'other-fee-paid-judicial-office-holder') {
roles.push(`other: ${ equalityAndDiversitySurvey.otherCurrentFeePaidJudicialOfficeHolderDetails }`);
} else if (role === 'other-salaried-judicial-office-holder') {
roles.push(`other: ${ equalityAndDiversitySurvey.otherCurrentSalariedJudicialOfficeHolderDetails}`);
} else if (role === 'other-current-legal-role') {
roles.push(`Other: ${ equalityAndDiversitySurvey.otherCurrentLegalRoleDetails }`);
} else {
roles.push(filters.lookup(role));
}
});
return roles.join('\n');
},
flattenProfessionalBackground(equalityAndDiversitySurvey) {
if (!(equalityAndDiversitySurvey && equalityAndDiversitySurvey.professionalBackground)) {
return '';
}
const roles = [];
equalityAndDiversitySurvey.professionalBackground.forEach((role) => {
if (role === 'other-professional-background') {
roles.push(`Other: ${ equalityAndDiversitySurvey.otherProfessionalBackgroundDetails }`);
} else {
roles.push(filters.lookup(role));
getTableData(params) {
return this.$store.dispatch(
'applications/bind',
{
exerciseId: this.exercise.id,
status: this.status,
...params,
}
});
return roles.join('\n');
},
attendedUKStateSchool(equalityAndDiversitySurvey) {
if (!(equalityAndDiversitySurvey && equalityAndDiversitySurvey.stateOrFeeSchool)) {
return '';
}
return filters.toYesNo(['uk-state-selective', 'uk-state-non-selective'].indexOf(equalityAndDiversitySurvey.stateOrFeeSchool) >= 0);
);
},
gatherContacts() {
const headers = [
'Reference number',
'Status',
'Name',
'Email',
'Phone number',
'Date of Birth',
'National Insurance Number',
'Gender',
'Disability',
'Ethnic Group',
'Current Legal Role',
'Professional Background',
'Held Fee-paid Judicial Role',
'Attended UK State School',
'First Generation Student',
'First Assessor Name',
'First Assessor Email',
'First Assessor Phone',
'Second Assessor Name',
'Second Assessor Email',
'Second Assessor Phone',
];
async gatherReportData() {
// fetch data
const response = await functions.httpsCallable('exportApplicationContactsData')({ exerciseId: this.exercise.id, status: this.status });
const reportData = [];
const contacts = this.applications.map((application) => {
return [
application.referenceNumber,
filters.lookup(application.status),
application.personalDetails.fullName,
application.personalDetails.email,
application.personalDetails.phone,
filters.formatDate(application.personalDetails.dateOfBirth),
filters.formatNIN(application.personalDetails.nationalInsuranceNumber),
filters.lookup(application.equalityAndDiversitySurvey.gender),
filters.toYesNo(filters.lookup(application.equalityAndDiversitySurvey.disability)),
filters.lookup(application.equalityAndDiversitySurvey.ethnicGroup),
this.flattenCurrentLegalRole(application.equalityAndDiversitySurvey),
this.flattenProfessionalBackground(application.equalityAndDiversitySurvey),
filters.heldFeePaidJudicialRole(application.equalityAndDiversitySurvey.feePaidJudicialRole),
filters.toYesNo(this.attendedUKStateSchool(application.equalityAndDiversitySurvey)),
filters.toYesNo(filters.lookup(application.equalityAndDiversitySurvey.firstGenerationStudent)),
application.firstAssessorFullName,
application.firstAssessorEmail,
application.firstAssessorPhone,
application.secondAssessorFullName,
application.secondAssessorEmail,
application.secondAssessorPhone,
];
// get headers
reportData.push(response.data.headers.map(header => header));
// get rows
response.data.rows.forEach((row) => {
reportData.push(Object.values(row).map(cell => cell));
});
return [
headers,
...contacts,
];
return reportData;
},
async exportContacts() {
const title = 'Contacts';
await this.getTableData({});
const data = this.gatherContacts();
const xlsxData = await this.gatherReportData();
downloadXLSX(
data,
xlsxData,
{
title: `${this.exercise.referenceNumber} ${title}`,
sheetName: title,
fileName: `${this.exercise.referenceNumber} - ${title}.xlsx`,
}
);
},
getTableData(params) {
return this.$store.dispatch(
'applications/bind',
{
exerciseId: this.exercise.id,
status: this.status,
...params,
}
);
},
},
};
</script>
Expand Down
Loading

0 comments on commit d9c2c00

Please sign in to comment.