mirror of
https://github.com/documize/community.git
synced 2025-07-25 08:09:43 +02:00
Enable PDF section editor
This commit is contained in:
parent
61d0086337
commit
7fde947a52
6 changed files with 118 additions and 20 deletions
|
@ -12,20 +12,14 @@
|
|||
import $ from 'jquery';
|
||||
import { empty } from '@ember/object/computed';
|
||||
import { computed } from '@ember/object';
|
||||
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(Modals, Notifier, {
|
||||
appMeta: service(),
|
||||
session: service(),
|
||||
documentSvc: service('document'),
|
||||
busy: false,
|
||||
mousetrap: null,
|
||||
showLinkModal: false,
|
||||
files: null,
|
||||
downloadQuery: '',
|
||||
hasNameError: empty('page.title'),
|
||||
hasDescError: empty('page.excerpt'),
|
||||
pageId: computed('page', function () {
|
||||
|
|
|
@ -18,22 +18,59 @@ export default Component.extend({
|
|||
editorId: computed('page', function () {
|
||||
let page = this.get('page');
|
||||
return `pdf-editor-${page.id}`;
|
||||
}),
|
||||
}),
|
||||
pdfOption: null,
|
||||
pdfName: '',
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.set('pageBody', this.get('meta.rawBody'));
|
||||
this.pdfOption = {};
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
didReceiveAttrs() {
|
||||
let pdfOption = {};
|
||||
|
||||
try {
|
||||
pdfOption = JSON.parse(this.get('meta.config'));
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
if (_.isEmpty(pdfOption)) {
|
||||
pdfOption = {
|
||||
height: 600,
|
||||
sidebar: 'none', // none, bookmarks, thumbs
|
||||
startPage: 1,
|
||||
fileId: ''
|
||||
};
|
||||
}
|
||||
|
||||
this.set('pdfOption', pdfOption);
|
||||
this.setPDF();
|
||||
},
|
||||
|
||||
didUpdateAttrs() {
|
||||
this._super(...arguments);
|
||||
this.setPDF();
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
this._super(...arguments);
|
||||
setPDF() {
|
||||
let files = this.get('attachments');
|
||||
if (!_.isArray(files)) return;
|
||||
|
||||
for (let i=0; i < files.length; i++) {
|
||||
if (_.endsWith(files[i].get('extension'), 'pdf') &&
|
||||
files[i].get('pageId') === this.get('page.id')) {
|
||||
this.set('pdfName', files[i].get('filename'));
|
||||
this.set('pdfOption.fileId', files[i].get('id'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
onSetSidebar(e) {
|
||||
this.set('pdfOption.sidebar', e);
|
||||
},
|
||||
|
||||
isDirty() {
|
||||
return this.get('isDirty');
|
||||
},
|
||||
|
@ -44,11 +81,14 @@ export default Component.extend({
|
|||
},
|
||||
|
||||
onAction(title) {
|
||||
let config = this.get('pdfOption');
|
||||
let page = this.get('page');
|
||||
let meta = this.get('meta');
|
||||
meta.set('rawBody', '');
|
||||
|
||||
page.set('title', title);
|
||||
page.set('body', meta.get('rawBody'));
|
||||
page.set('body', JSON.stringify(config));
|
||||
meta.set('config', JSON.stringify(config));
|
||||
meta.set('rawBody', JSON.stringify(config));
|
||||
|
||||
let cb = this.get('onAction');
|
||||
cb(page, meta);
|
||||
|
|
|
@ -9,9 +9,14 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
import { inject as service } from '@ember/service';
|
||||
import Component from '@ember/component';
|
||||
|
||||
export default Component.extend({
|
||||
appMeta: service(),
|
||||
session: service(),
|
||||
|
||||
// PDF URL is calculated
|
||||
pdfUrl: '',
|
||||
|
||||
// https://github.com/mozilla/pdf.js/wiki/Viewer-options
|
||||
|
@ -26,10 +31,35 @@ export default Component.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
let page = this.get('page');
|
||||
let rawBody = page.get('body');
|
||||
let pdfOption = {};
|
||||
|
||||
this.set('pdfUrl', encodeURIComponent('https://demo.test:5001/api/public/attachment/4Tec34w8/bhird7crtr314et90n7g?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJkZW1vIiwiZXhwIjoxNTg2MzQ1ODA2LCJpc3MiOiJEb2N1bWl6ZSIsIm9yZyI6IjRUZWMzNHc4Iiwic3ViIjoid2ViYXBwIiwidXNlciI6ImlKZGY2cVVXIn0.YPrf_xlNJZVK1Ikt3S0HJagIqqnVjxwepUVQ44VYXR4'));
|
||||
try {
|
||||
pdfOption = JSON.parse(this.get('page.body'));
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
if (_.isEmpty(pdfOption)) {
|
||||
pdfOption = {
|
||||
height: 600,
|
||||
sidebar: 'none', // none, bookmarks, thumbs
|
||||
startPage: 1,
|
||||
};
|
||||
}
|
||||
|
||||
this.set('pdfOption', pdfOption);
|
||||
|
||||
let endpoint = this.get('appMeta.endpoint');
|
||||
let orgId = this.get('appMeta.orgId');
|
||||
let fileId = this.get('pdfOption.fileId');
|
||||
|
||||
// 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('pdfUrl', encodeURIComponent(`${endpoint}/public/attachment/${orgId}/${fileId}${qry}`));
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue