Merge pull request #1005 from dod-ccpo/cloud-pdf-downloads
Cloud pdf downloads
This commit is contained in:
@@ -8,7 +8,8 @@ const UploadWrapper = makeTestWrapper({
|
||||
components: { uploadinput },
|
||||
templatePath: 'upload_input_template.html',
|
||||
data: function() {
|
||||
return { initialvalue: this.initialData.initialvalue, token: this.token }
|
||||
const { filename, objectName } = this.initialData
|
||||
return { filename, objectName }
|
||||
},
|
||||
})
|
||||
|
||||
@@ -16,7 +17,7 @@ const UploadErrorWrapper = makeTestWrapper({
|
||||
components: { uploadinput },
|
||||
templatePath: 'upload_input_error_template.html',
|
||||
data: function() {
|
||||
return { initialvalue: null, token: null }
|
||||
return { filename: null, objectName: null }
|
||||
},
|
||||
})
|
||||
|
||||
@@ -24,7 +25,7 @@ describe('UploadInput Test', () => {
|
||||
it('should show input and button when no attachment present', () => {
|
||||
const wrapper = mount(UploadWrapper, {
|
||||
propsData: {
|
||||
initialData: { initialvalue: null, token: 'token' },
|
||||
initialData: {},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -35,21 +36,24 @@ describe('UploadInput Test', () => {
|
||||
it('should show file name and hide input', () => {
|
||||
const wrapper = mount(UploadWrapper, {
|
||||
propsData: {
|
||||
initialData: { initialvalue: 'somepdf.pdf', token: 'token' },
|
||||
initialData: {
|
||||
filename: 'somepdf.pdf',
|
||||
objectName: 'abcd',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const fileInput = wrapper.find('input[type=file]').element
|
||||
const fileNameSpan = wrapper.find('.uploaded-file__name')
|
||||
const fileNameLink = wrapper.find('.uploaded-file__name')
|
||||
|
||||
expect(fileInput).toBe(undefined)
|
||||
expect(fileNameSpan.html()).toContain('somepdf.pdf')
|
||||
expect(fileNameLink.html()).toContain('somepdf.pdf')
|
||||
})
|
||||
|
||||
it('should correctly display error treatment', () => {
|
||||
const wrapper = mount(UploadErrorWrapper, {
|
||||
propsData: {
|
||||
initialData: { initialvalue: 'somepdf.pdf', token: 'token' },
|
||||
initialData: { initialvalue: 'somepdf.pdf', objectName: 'abcd' },
|
||||
},
|
||||
})
|
||||
|
||||
|
@@ -17,7 +17,10 @@ export default {
|
||||
|
||||
props: {
|
||||
name: String,
|
||||
initialData: {
|
||||
filename: {
|
||||
type: String,
|
||||
},
|
||||
objectName: {
|
||||
type: String,
|
||||
},
|
||||
initialErrors: {
|
||||
@@ -38,11 +41,12 @@ export default {
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
hasInitialData: !!this.initialData,
|
||||
attachment: this.initialData || null,
|
||||
hasInitialData: !!this.filename,
|
||||
attachment: this.filename || null,
|
||||
changed: false,
|
||||
uploadError: false,
|
||||
sizeError: false,
|
||||
downloadLink: '',
|
||||
}
|
||||
},
|
||||
|
||||
@@ -52,6 +56,13 @@ export default {
|
||||
name: this.name,
|
||||
valid: this.hasAttachment,
|
||||
})
|
||||
|
||||
if (this.hasInitialData) {
|
||||
this.downloadLink = await this.getDownloadLink(
|
||||
this.filename,
|
||||
this.objectName
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
@@ -70,6 +81,10 @@ export default {
|
||||
this.attachment = e.target.value
|
||||
this.$refs.attachmentFilename.value = file.name
|
||||
this.$refs.attachmentObjectName.value = response.objectName
|
||||
this.downloadLink = await this.getDownloadLink(
|
||||
file.name,
|
||||
response.objectName
|
||||
)
|
||||
} else {
|
||||
this.uploadError = true
|
||||
}
|
||||
@@ -104,12 +119,21 @@ export default {
|
||||
this.sizeError = false
|
||||
},
|
||||
getUploader: async function() {
|
||||
return fetch(`/task_orders/${this.portfolioId}/upload-token`, {
|
||||
return fetch(`/task_orders/${this.portfolioId}/upload_token`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(({ token, objectName }) => buildUploader(token, objectName))
|
||||
},
|
||||
getDownloadLink: async function(filename, objectName) {
|
||||
const { downloadLink } = await fetch(
|
||||
`/task_orders/${
|
||||
this.portfolioId
|
||||
}/download_link?filename=${filename}&objectName=${objectName}`,
|
||||
{ credentials: 'include' }
|
||||
).then(r => r.json())
|
||||
return downloadLink
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
|
Reference in New Issue
Block a user