1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-05 05:25:27 +02:00

Migrate document attachments view to new UI framework

This commit is contained in:
sauls8t 2018-12-19 12:41:36 +00:00
parent 7cdf97aa86
commit 3d2060ca60
9 changed files with 148 additions and 9 deletions

View file

@ -62,7 +62,6 @@ export default Component.extend(Notifier, {
}
this.set('model.general.maxTags', this.get('maxTags'));
this.model.general.set('allowAnonymousAccess', $("#allowAnonymousAccess").prop('checked'));
this.get('save')().then(() => {
this.notifySuccess('Saved');

View file

@ -20,11 +20,13 @@ export default Component.extend(Modals, Notifier, {
documentService: service('document'),
browserSvc: service('browser'),
appMeta: service(),
session: service(),
hasAttachments: notEmpty('files'),
canEdit: computed('permissions.documentEdit', 'document.protection', function() {
return this.get('document.protection') !== this.get('constants').ProtectionType.Lock && this.get('permissions.documentEdit');
}),
showDialog: false,
downloadQuery: '',
init() {
this._super(...arguments);
@ -50,7 +52,7 @@ export default Component.extend(Modals, Notifier, {
let dzone = new Dropzone("#upload-document-files", {
headers: {
'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token')
'Authorization': 'Bearer ' + self.get('session.authToken')
},
url: uploadUrl,
method: "post",
@ -67,16 +69,16 @@ export default Component.extend(Modals, Notifier, {
});
this.on("queuecomplete", function () {
self.notifySuccess('Saved');
self.notifySuccess('Uploaded file');
self.getAttachments();
});
this.on("addedfile", function ( /*file*/ ) {
});
this.on("error", function (error, msg) { // // eslint-disable-line no-unused-vars
this.on("error", function (error, msg) {
self.notifyError(msg);
console.log(msg); // eslint-disable-line no-console
self.notifyError(error);
});
}
});
@ -86,6 +88,13 @@ export default Component.extend(Modals, Notifier, {
});
this.set('drop', dzone);
// For authenticated users we send server auth token.
let qry = '';
if (this.get('session.authenticated')) {
qry = '?token=' + this.get('session.authToken');
}
this.set('downloadQuery', qry);
},
getAttachments() {

View file

@ -356,7 +356,7 @@ export default Service.extend({
},
//**************************************************
// Export
// Export content to HTML
//**************************************************
export(spec) {
@ -367,6 +367,14 @@ export default Service.extend({
});
},
//**************************************************
// Secure document attachment download
//**************************************************
downloadAttachment(fileId) {
return this.get('ajax').get(`attachment/${fileId}`, {});
},
//**************************************************
// Fetch bulk data
//**************************************************

View file

@ -85,6 +85,16 @@ export default SimpleAuthSession.extend({
this.get('session.content.authenticated.user.viewUsers') === true;
}),
authToken: computed('session.content.authenticated.user', function () {
if (is.null(this.get('session.authenticator')) ||
this.get('appMeta.secureMode')) return '';
if (this.get('session.authenticator') === 'authenticator:anonymous' ||
this.get('session.content.authenticated.user.id') === '0') return '';
return this.get('session.content.authenticated.token');
}),
init() {
this._super(...arguments);

View file

@ -84,4 +84,15 @@
}
}
}
.empty-label {
margin: 10px 0;
font-size: 1rem;
font-weight: 500;
color: map-get($gray-shades, 700);
font-style: italic;
padding: 0 7px;
}
}

View file

@ -12,7 +12,7 @@
<ul class="files">
{{#each files key="id" as |file|}}
<li class="file">
<a href="{{appMeta.endpoint}}/public/attachments/{{appMeta.orgId}}/{{file.id}}">
<a href="{{appMeta.endpoint}}/public/attachment/{{appMeta.orgId}}/{{file.id}}{{downloadQuery}}">
{{file.filename}}
</a>
{{#if canEdit}}
@ -27,6 +27,8 @@
{{/each}}
</ul>
</div>
{{else}}
<p class="empty-label">No attachments</p>
{{/if}}
{{#ui/ui-dialog title="Delete Attachment" confirmCaption="Delete" buttonColor=constants.Color.Red show=showDialog onAction=(action "onDelete")}}