Allow user to download files on TO upload page
This commit is contained in:
parent
acc821a475
commit
e8234dcf34
@ -84,6 +84,18 @@ def upload_token(portfolio_id):
|
||||
return jsonify(render_args)
|
||||
|
||||
|
||||
@task_orders_bp.route("/task_orders/<portfolio_id>/download_link")
|
||||
@user_can(Permissions.CREATE_TASK_ORDER, message="edit task order form")
|
||||
def download_link(portfolio_id):
|
||||
filename = http_request.args.get("filename")
|
||||
object_name = http_request.args.get("objectName")
|
||||
render_args = {
|
||||
"downloadLink": app.csp.files.generate_download_link(object_name, filename)
|
||||
}
|
||||
|
||||
return jsonify(render_args)
|
||||
|
||||
|
||||
@task_orders_bp.route("/task_orders/<task_order_id>/edit")
|
||||
@user_can(Permissions.CREATE_TASK_ORDER, message="edit task order form")
|
||||
def edit(task_order_id):
|
||||
@ -117,14 +129,10 @@ def edit(task_order_id):
|
||||
@task_orders_bp.route("/task_orders/<task_order_id>/form/step_1")
|
||||
@user_can(Permissions.CREATE_TASK_ORDER, message="view task order form")
|
||||
def form_step_one_add_pdf(portfolio_id=None, task_order_id=None):
|
||||
(token, object_name) = current_app.uploader.get_token()
|
||||
extra_args = {"token": token, "object_name": object_name}
|
||||
|
||||
return render_task_orders_edit(
|
||||
"task_orders/step_1.html",
|
||||
portfolio_id=portfolio_id,
|
||||
task_order_id=task_order_id,
|
||||
extra_args=extra_args,
|
||||
)
|
||||
|
||||
|
||||
@ -228,11 +236,9 @@ def form_step_four_review(task_order_id):
|
||||
|
||||
(token, object_name) = current_app.uploader.get_token()
|
||||
extra_args = {
|
||||
"token": token,
|
||||
"object_name": object_name,
|
||||
"pdf_download_url": current_app.uploader.generate_download_link(
|
||||
task_order.pdf.object_name, task_order.pdf.filename
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
if task_order.is_completed == False:
|
||||
|
@ -18,7 +18,7 @@ export default {
|
||||
props: {
|
||||
name: String,
|
||||
initialData: {
|
||||
type: String,
|
||||
type: Object,
|
||||
},
|
||||
initialErrors: {
|
||||
type: Boolean,
|
||||
@ -39,10 +39,11 @@ export default {
|
||||
data: function() {
|
||||
return {
|
||||
hasInitialData: !!this.initialData,
|
||||
attachment: this.initialData || null,
|
||||
attachment: this.initialData.filename || null,
|
||||
changed: false,
|
||||
uploadError: false,
|
||||
sizeError: false,
|
||||
downloadLink: '',
|
||||
}
|
||||
},
|
||||
|
||||
@ -52,6 +53,11 @@ export default {
|
||||
name: this.name,
|
||||
valid: this.hasAttachment,
|
||||
})
|
||||
|
||||
if (this.hasInitialData) {
|
||||
const { filename, objectName } = this.initialData
|
||||
this.downloadLink = await this.getDownloadLink(filename, objectName)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
@ -70,6 +76,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
|
||||
}
|
||||
@ -110,6 +120,15 @@ export default {
|
||||
.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: {
|
||||
|
@ -4,7 +4,7 @@
|
||||
<uploadinput
|
||||
inline-template
|
||||
{% if not field.errors %}
|
||||
v-bind:initial-data='{{ field.filename.data | tojson }}'
|
||||
v-bind:initial-data='{{ {"filename": field.filename.data, "objectName": field.object_name.data} | tojson }}'
|
||||
{% else %}
|
||||
v-bind:initial-errors='true'
|
||||
{% endif %}
|
||||
@ -16,7 +16,7 @@
|
||||
<div>
|
||||
<div v-show="hasAttachment" class="uploaded-file">
|
||||
{{ Icon("check-circle-solid") }}
|
||||
<span class="uploaded-file__name" v-html="baseName"></span>
|
||||
<a class="uploaded-file__name" v-html="baseName" v-bind:href="downloadLink"></span>
|
||||
<a href="#" class="uploaded-file__remove" v-on:click="removeAttachment">Remove</a>
|
||||
</div>
|
||||
<div v-show="hasAttachment === false" v-bind:class='{ "usa-input": true, "usa-input--error": showErrors }'>
|
||||
|
Loading…
x
Reference in New Issue
Block a user