mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Enable PDF section editor
This commit is contained in:
parent
61d0086337
commit
7fde947a52
6 changed files with 118 additions and 20 deletions
|
@ -46,10 +46,10 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
|||
|
||||
// Render just sends back HMTL as-is.
|
||||
func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
||||
return data
|
||||
return config
|
||||
}
|
||||
|
||||
// Refresh just sends back data as-is.
|
||||
func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||
return data
|
||||
return config
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -1,3 +1,37 @@
|
|||
{{#section/base-editor-inline document=document folder=folder page=page tip="Select PDF to render" isDirty=(action "isDirty") onCancel=(action "onCancel") onAction=(action "onAction")}}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-space-name">PDF</label>
|
||||
{{input type="text" class="form-control mousetrap" placeholder="click upload button below" value=pdfName readonly=true}}
|
||||
<small class="form-text text-muted">First PDF uploaded will be used</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-space-name">Preview Height</label>
|
||||
{{input type="number" class="form-control mousetrap" placeholder="e.g. 700" value=pdfOption.height}}
|
||||
<small class="form-text text-muted">How tall is the PDF preview?</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-space-name">Start Page</label>
|
||||
{{input type="number" class="form-control mousetrap" placeholder="e.g. 1" value=pdfOption.startPage}}
|
||||
<small class="form-text text-muted">The first page to display</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="new-space-name">Sidebar</label>
|
||||
<select onchange={{action "onSetSidebar" value="target.value"}} class="form-control">
|
||||
<option value="none" selected={{is-equal pdfOption.sidebar 'none'}}>
|
||||
None
|
||||
</option>
|
||||
<option value="bookmarks" selected={{is-equal pdfOption.sidebar 'bookmarks'}}>
|
||||
Bookmarks
|
||||
</option>
|
||||
<option value="thumbs" selected={{is-equal pdfOption.sidebar 'thumbs'}}>
|
||||
Thumbnails
|
||||
</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Optionally, set sidebar content</small>
|
||||
</div>
|
||||
|
||||
{{/section/base-editor-inline}}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="non-printable">
|
||||
<iframe frameborder="0" onmousewheel=""
|
||||
width="100%"
|
||||
height={{viewHeight}}
|
||||
src="/pdfjs/web/viewer.html?file={{pdfUrl}}#zoom=page-width&page={{startPage}}&pagemode={{pageMode}}">
|
||||
height={{pdfOption.height}}
|
||||
src="/pdfjs/web/viewer.html?file={{pdfUrl}}#zoom=page-width&page={{pdfOption.startPage}}&pagemode={{pdfOption.sidebar}}">
|
||||
</iframe>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue