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

Tweaks to IAs #461

Merged
merged 4 commits into from
May 19, 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
83 changes: 51 additions & 32 deletions src/components/DownloadLink.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<template>
<a
v-if="fileName && linkHref"
class="govuk-link govuk-body-m"
:class="{'download-visited' : visited }"
href="javascript:void(0)"
@click.prevent="download(fileName)"
:class="{'download-visited' : visited, 'govuk-button govuk-button--secondary': type === 'button' }"
:download="fileName"
:href="linkHref"
>
{{ linkText }}
</a>
<span
v-else
class="govuk-body"
>
File not available
</span>
</template>

<script>
import firebase from '@firebase/app';
import '@firebase/storage';

export default {
props: {
fileName: {
Expand All @@ -24,67 +32,78 @@ export default {
type: String,
default: '',
},
applicationId: {
required: false,
type: String,
default: '',
},
userId: {
required: false,
type: String,
default: null,
},
assessorId: {
required: false,
type: String,
default: '',
},
title: {
required: false,
type: String,
default: '',
},
type: {
required: false,
type: String,
default: 'link',
},
},
data () {
return {
visited: false,
linkHref: '',
};
},
computed: {
linkText() {
return this.title ? this.title : this.fileName;
},
savePath() {
let savePath = '';
if (this.exerciseId) {
savePath += `exercise/${this.exerciseId}/`;
let savePath = `exercise/${this.exerciseId}/`;
if (this.applicationId) {
savePath += `application/${this.applicationId}/`;
}
if (this.userId) {
savePath += `user/${this.userId}/`;
}
if (this.assessorId) {
savePath += `assessor/${this.assessorId}/`;
}

return savePath;
},
},
methods: {
download(fileName) {
this.visited = true;
const storageRef = firebase.storage().ref();
const fileNameRef = storageRef.child(this.savePath + fileName);
fileNameRef.getDownloadURL().then((url) => {
// open url in another window
window.open(url);
}).catch((error) => {

// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/object-not-found':
// File doesn't exist
break;
async mounted() {
const downloadUrl = await this.getDownloadURL();

case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
if (downloadUrl) {
this.linkHref = downloadUrl;
}
},
methods: {
async getDownloadURL() {
const fileRef = firebase.storage().ref(this.savePath + this.fileName);

case 'storage/canceled':
// User canceled the upload
break;
try {
const downloadUrl = await fileRef.getDownloadURL();

case 'storage/unknown':
// Unknown error occurred, inspect the server response
break;
if (typeof downloadUrl === 'string' && downloadUrl.length) {
return downloadUrl;
}
});
return false;
} catch (e) {
return false;
}
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const lookup = (value) => {
'citizenship': 'Citizenship',
'civil': 'Civil',
'closed': 'Closed',
'completed': 'Completed',
'court': 'Court',
'crime': 'Crime',
'critical-analysis-qualifying-test': 'Critical analysis qualifying test (QT)',
Expand Down Expand Up @@ -175,6 +176,7 @@ const lookup = (value) => {
'other-sexual-orientation': 'Other',
'paper-sift': 'Paper sift',
'pakistani': 'Pakistani',
'pending': 'Pending',
'pqe': 'Post-qualification experience',
'practice-or-employment-as-lawyer': 'Practice or employment as a lawyer',
'pre-launch': 'Pre launch',
Expand Down
Loading