mirror of
https://github.com/documize/community.git
synced 2025-08-02 03:55:24 +02:00
[WIP] PDF viewer section & per section attachments
This commit is contained in:
parent
c0ed3c3d04
commit
166aeba09b
428 changed files with 45874 additions and 802 deletions
|
@ -46,7 +46,6 @@ export default Component.extend(Modals, Notifier, {
|
|||
let url = this.get('appMeta.endpoint');
|
||||
let uploadUrl = `${url}/documents/${documentId}/attachments`;
|
||||
|
||||
|
||||
// Handle upload clicks on button and anything inside that button.
|
||||
let sel = ['#upload-document-files ', '#upload-document-files > div'];
|
||||
for (var i=0; i < 2; i++) {
|
||||
|
@ -58,7 +57,7 @@ export default Component.extend(Modals, Notifier, {
|
|||
method: "post",
|
||||
paramName: 'attachment',
|
||||
clickable: true,
|
||||
maxFilesize: 50,
|
||||
maxFilesize: 250,
|
||||
parallelUploads: 5,
|
||||
uploadMultiple: false,
|
||||
addRemoveLinks: false,
|
||||
|
|
|
@ -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'))) {
|
||||
|
|
57
gui/app/components/section/pdf/type-editor.js
Normal file
57
gui/app/components/section/pdf/type-editor.js
Normal 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);
|
||||
}
|
||||
}
|
||||
});
|
46
gui/app/components/section/pdf/type-renderer.js
Normal file
46
gui/app/components/section/pdf/type-renderer.js
Normal 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);
|
||||
}
|
||||
});
|
|
@ -15,6 +15,7 @@ import attr from 'ember-data/attr';
|
|||
|
||||
export default Model.extend({
|
||||
documentId: attr('string'),
|
||||
pageId: attr('string'),
|
||||
extension: attr('string'),
|
||||
fileId: attr('string'),
|
||||
filename: attr('string'),
|
||||
|
|
|
@ -50,7 +50,8 @@ export default Route.extend(AuthenticatedRouteMixin, {
|
|||
permissions: this.modelFor('document').permissions,
|
||||
roles: this.modelFor('document').roles,
|
||||
blocks: this.modelFor('document').blocks,
|
||||
versions: this.modelFor('document').versions
|
||||
versions: this.modelFor('document').versions,
|
||||
attachments: this.modelFor('document').attachments
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -67,6 +68,7 @@ export default Route.extend(AuthenticatedRouteMixin, {
|
|||
controller.set('roles', model.roles);
|
||||
controller.set('blocks', model.blocks);
|
||||
controller.set('versions', model.versions);
|
||||
controller.set('attachments', model.attachments);
|
||||
},
|
||||
|
||||
activate: function () {
|
||||
|
|
|
@ -33,6 +33,7 @@ export default Route.extend(AuthenticatedRouteMixin, {
|
|||
this.set('roles', data.roles);
|
||||
this.set('links', data.links);
|
||||
this.set('versions', data.versions);
|
||||
this.set('attachments', data.attachments);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
@ -47,6 +48,7 @@ export default Route.extend(AuthenticatedRouteMixin, {
|
|||
roles: this.get('roles'),
|
||||
links: this.get('links'),
|
||||
versions: this.get('versions'),
|
||||
attachments: this.get('attachments'),
|
||||
sections: this.get('sectionService').getAll(),
|
||||
blocks: this.get('sectionService').getSpaceBlocks(this.get('folder.id'))
|
||||
});
|
||||
|
|
|
@ -397,6 +397,7 @@ export default Service.extend({
|
|||
folder: {},
|
||||
links: [],
|
||||
versions: [],
|
||||
attachments: [],
|
||||
};
|
||||
|
||||
let doc = this.get('store').normalize('document', response.document);
|
||||
|
@ -414,6 +415,11 @@ export default Service.extend({
|
|||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
let attachments = response.attachments.map((obj) => {
|
||||
let data = this.get('store').normalize('attachment', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
data.document = doc;
|
||||
data.permissions = perms;
|
||||
data.roles = roles;
|
||||
|
@ -421,6 +427,7 @@ export default Service.extend({
|
|||
data.folder = folders.findBy('id', doc.get('spaceId'));
|
||||
data.links = response.links;
|
||||
data.versions = response.versions;
|
||||
data.attachments = attachments;
|
||||
|
||||
return data;
|
||||
}).catch((error) => {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
@import "github.scss";
|
||||
@import "jira.scss";
|
||||
@import "markdown.scss";
|
||||
@import "pdfjs.scss";
|
||||
@import "plantuml.scss";
|
||||
@import "papertrail.scss";
|
||||
@import "table.scss";
|
||||
|
|
2392
gui/app/styles/core/section/pdfjs.scss
Normal file
2392
gui/app/styles/core/section/pdfjs.scss
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,10 @@
|
|||
box-shadow: 0 0 0 0.75pt map-get($gray-shades, 200),0 0 3pt 0.75pt map-get($gray-shades, 200);
|
||||
border: 1px solid map-get($gray-shades, 200);
|
||||
}
|
||||
|
||||
> .attachments {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
.content-linker-modal-container {
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.dz-preview, .dz-processing {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.document-sidebar-attachment {
|
||||
> .files {
|
||||
margin: 0;
|
||||
|
|
|
@ -41,6 +41,12 @@
|
|||
<div class="canvas">
|
||||
{{yield}}
|
||||
</div>
|
||||
|
||||
<div class="attachments">
|
||||
{{ui/ui-spacer size=100}}
|
||||
{{ui/ui-button color=constants.Color.Gray label="Upload" id=uploadId}}
|
||||
{{ui/ui-spacer size=100}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
3
gui/app/templates/components/section/pdf/type-editor.hbs
Normal file
3
gui/app/templates/components/section/pdf/type-editor.hbs
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{#section/base-editor-inline document=document folder=folder page=page tip="Select PDF to render" isDirty=(action "isDirty") onCancel=(action "onCancel") onAction=(action "onAction")}}
|
||||
|
||||
{{/section/base-editor-inline}}
|
|
@ -0,0 +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}}">
|
||||
</iframe>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue