1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 07:39:43 +02:00

[WIP] PDF viewer section & per section attachments

This commit is contained in:
Harvey Kandola 2019-04-17 17:13:18 +01:00
parent c0ed3c3d04
commit 166aeba09b
428 changed files with 45874 additions and 802 deletions

View file

@ -10,21 +10,33 @@
// https://documize.com
import $ from 'jquery';
import { empty } from '@ember/object/computed';
import { empty, notEmpty } from '@ember/object/computed';
import { computed } from '@ember/object';
import ModalMixin from '../../mixins/modal';
import { inject as service } from '@ember/service';
import Modals from '../../mixins/modal';
import Notifier from '../../mixins/notifier';
import Component from '@ember/component';
export default Component.extend(ModalMixin, {
export default Component.extend(Modals, Notifier, {
appMeta: service(),
session: service(),
documentSvc: service('document'),
busy: false,
mousetrap: null,
showLinkModal: false,
files: null,
downloadQuery: '',
hasAttachments: notEmpty('files'),
hasNameError: empty('page.title'),
hasDescError: empty('page.excerpt'),
pageId: computed('page', function () {
let page = this.get('page');
return `page-editor-${page.id}`;
}),
uploadId: computed('page', function () {
let page = this.get('page');
return `page-uploader-${page.id}`;
}),
previewText: 'Preview',
pageTitle: '',
@ -58,6 +70,67 @@ export default Component.extend(ModalMixin, {
});
},
didInsertElement() {
this._super(...arguments);
let self = this;
let documentId = this.get('document.id');
let pageId = this.get('page.id');
let url = this.get('appMeta.endpoint');
let uploadUrl = `${url}/documents/${documentId}/attachments?page=${pageId}`;
let uploadId = this.get('uploadId');
// Handle upload clicks on button and anything inside that button.
let sel = ['#' + uploadId, '#' + uploadId + ' > div'];
for (var i=0; i < 2; i++) {
let dzone = new Dropzone(sel[i], {
headers: {
'Authorization': 'Bearer ' + self.get('session.authToken')
},
url: uploadUrl,
method: "post",
paramName: 'attachment',
clickable: true,
maxFilesize: 250,
parallelUploads: 5,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
init: function () {
this.on("success", function (/*file, response*/ ) {
});
this.on("queuecomplete", function () {
self.notifySuccess('Uploaded file');
self.getAttachments();
});
this.on("addedfile", function ( /*file*/ ) {
});
this.on("error", function (error, msg) {
self.notifyError(msg);
self.notifyError(error);
});
}
});
dzone.on("complete", function (file) {
dzone.removeFile(file);
});
}
// For authenticated users we send server auth token.
let qry = '';
if (this.get('session.hasSecureToken')) {
qry = '?secure=' + this.get('session.secureToken');
} else if (this.get('session.authenticated')) {
qry = '?token=' + this.get('session.authToken');
}
this.set('downloadQuery', qry);
},
willDestroyElement() {
this._super(...arguments);
this.set('showLinkModal', false);
@ -69,6 +142,12 @@ export default Component.extend(ModalMixin, {
}
},
getAttachments() {
this.get('documentSvc').getAttachments(this.get('document.id')).then((files) => {
this.set('files', files);
});
},
actions: {
onAction() {
if (this.get('busy') || _.isEmpty(this.get('pageTitle'))) {

View file

@ -0,0 +1,57 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import { computed } from '@ember/object';
import Component from '@ember/component';
export default Component.extend({
isDirty: false,
pageBody: '',
editorId: computed('page', function () {
let page = this.get('page');
return `pdf-editor-${page.id}`;
}),
init() {
this._super(...arguments);
this.set('pageBody', this.get('meta.rawBody'));
},
didInsertElement() {
this._super(...arguments);
},
willDestroyElement() {
this._super(...arguments);
},
actions: {
isDirty() {
return this.get('isDirty');
},
onCancel() {
let cb = this.get('onCancel');
cb();
},
onAction(title) {
let page = this.get('page');
let meta = this.get('meta');
meta.set('rawBody', '');
page.set('title', title);
page.set('body', meta.get('rawBody'));
let cb = this.get('onAction');
cb(page, meta);
}
}
});

View file

@ -0,0 +1,46 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Component from '@ember/component';
export default Component.extend({
pdfUrl: '',
// https://github.com/mozilla/pdf.js/wiki/Viewer-options
viewHeight: 700,
startPage: 1,
pageMode: 'none', // none, bookmarks, thumbs
didReceiveAttrs() {
this._super(...arguments);
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
let page = this.get('page');
let rawBody = page.get('body');
this.set('pdfUrl', encodeURIComponent('https://demo.test:5001/api/public/attachment/4Tec34w8/bhird7crtr314et90n7g?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJkZW1vIiwiZXhwIjoxNTg2MzQ1ODA2LCJpc3MiOiJEb2N1bWl6ZSIsIm9yZyI6IjRUZWMzNHc4Iiwic3ViIjoid2ViYXBwIiwidXNlciI6ImlKZGY2cVVXIn0.YPrf_xlNJZVK1Ikt3S0HJagIqqnVjxwepUVQ44VYXR4'));
},
didInsertElement() {
this._super(...arguments);
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
},
willDestroyElement() {
this._super(...arguments);
}
});