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

[WIP] moved start-document functionality, reworked folder view

WIP -- import files still BROKEN
This commit is contained in:
Harvey Kandola 2017-09-25 19:14:33 +01:00
parent 8f80673cde
commit a0a1dd396a
20 changed files with 2820 additions and 2039 deletions

View file

@ -14,43 +14,13 @@ import Ember from 'ember';
export default Ember.Component.extend({
folderService: Ember.inject.service('folder'),
moveTarget: null,
emptyState: Ember.computed('documents', function() {
return this.get('documents.length') === 0;
}),
didReceiveAttrs() {
this._super(...arguments);
this.set('canCreate', this.get('permissions.documentAdd'));
this.set('deleteTargets', this.get('folders').rejectBy('id', this.get('folder.id')));
},
didUpdateAttrs() {
this._super(...arguments);
this.setupAddWizard();
},
didInsertElement() {
this._super(...arguments);
this.setupAddWizard();
},
setupAddWizard() {
Ember.run.schedule('afterRender', () => {
$('.start-document:not(.start-document-empty-state)').off('.hoverIntent');
$('.start-document:not(.start-document-empty-state)').hoverIntent({interval: 100, over: function() {
// in
$(this).find('.start-button').velocity("transition.slideDownIn", {duration: 300});
}, out: function() {
// out
$(this).find('.start-button').velocity("transition.slideUpOut", {duration: 300});
} });
});
},
actions: {
selectDocument(documentId) {
let doc = this.get('documents').findBy('id', documentId);
@ -65,39 +35,6 @@ export default Ember.Component.extend({
}
this.set('selectedDocuments', list);
},
onDelete() {
this.get("onDeleteSpace")();
},
onImport() {
this.get('onImport')();
},
onShowDocumentWizard(docId) {
if ($("#new-document-wizard").is(':visible') && this.get('docId') === docId) {
this.send('onHideDocumentWizard');
return;
}
this.set('docId', docId);
if (docId === '') {
$("#new-document-wizard").insertAfter('#wizard-placeholder');
} else {
$("#new-document-wizard").insertAfter(`#document-${docId}`);
}
$("#new-document-wizard").velocity("transition.slideDownIn", { duration: 300, complete:
function() {
$("#new-document-name").focus();
}});
},
onHideDocumentWizard() {
$("#new-document-wizard").insertAfter('#wizard-placeholder');
$("#new-document-wizard").velocity("transition.slideUpOut", { duration: 300 });
}
}
}
});

View file

@ -81,6 +81,10 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
} else {
this.addTooltip(document.getElementById("space-pin-button"));
}
if (this.get('permissions.documentAdd')) {
this.addTooltip(document.getElementById("document-add-button"));
}
}
},
@ -170,6 +174,10 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
this.attrs.onMoveDocument(this.get('moveFolderId'));
return true;
},
onStartDocument() {
this.attrs.onStartDocument();
}
}
});

View file

@ -0,0 +1,91 @@
// 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 Ember from 'ember';
import NotifierMixin from '../../mixins/notifier';
import TooltipMixin from '../../mixins/tooltip';
import AuthMixin from '../../mixins/auth';
const {
inject: { service }
} = Ember;
export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
router: service(),
documentService: service('document'),
folderService: service('folder'),
localStorage: service('localStorage'),
selectedDocuments: [],
hasSelectedDocuments: Ember.computed.gt('selectedDocuments.length', 0),
showStartDocument: false,
actions: {
onMoveDocument(folder) {
let self = this;
let documents = this.get('selectedDocuments');
documents.forEach(function (documentId) {
self.get('documentService').getDocument(documentId).then(function (doc) {
doc.set('folderId', folder);
doc.set('selected', !doc.get('selected'));
self.get('documentService').save(doc).then(function () {
self.attrs.onRefresh();
});
});
});
this.set('selectedDocuments', []);
this.send("showNotification", "Moved");
},
onDeleteDocument() {
let documents = this.get('selectedDocuments');
let self = this;
let promises = [];
documents.forEach(function (document, index) {
promises[index] = self.get('documentService').deleteDocument(document);
});
Ember.RSVP.all(promises).then(() => {
let documents = this.get('documents');
documents.forEach(function (document) {
document.set('selected', false);
});
this.set('documents', documents);
this.set('selectedDocuments', []);
this.send("showNotification", "Deleted");
this.attrs.onRefresh();
});
},
onDeleteSpace() {
this.get('folderService').delete(this.get('folder.id')).then(() => { /* jshint ignore:line */
this.showNotification("Deleted");
this.get('localStorage').clearSessionItem('folder');
this.get('router').transitionTo('application');
});
},
onImport() {
// this.attrs.onRefresh();
},
onStartDocument() {
this.set('showStartDocument', !this.get('showStartDocument'));
},
onHideStartDocument() {
this.set('showStartDocument', false);
}
}
});

View file

@ -14,54 +14,66 @@ import NotifierMixin from '../../mixins/notifier';
const {
computed,
inject: { service }
} = Ember;
export default Ember.Component.extend(NotifierMixin, {
localStorage: Ember.inject.service(),
appMeta: Ember.inject.service(),
templateService: Ember.inject.service('template'),
canEditTemplate: "",
localStorage: service(),
appMeta: service(),
templateService: service('template'),
importedDocuments: [],
savedTemplates: [],
drop: null,
newDocumentName: 'New Document',
dropzone: null,
newDocumentName: '',
newDocumentNameMissing: computed.empty('newDocumentName'),
didInsertElement() {
this.setupImport();
},
didReceiveAttrs() {
this._super(...arguments);
this.setupTemplates();
Ember.run.schedule('afterRender', ()=> {
this.setupImport();
});
},
willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
this._super(...arguments);
if (is.not.null(this.get('dropzone'))) {
this.get('dropzone').destroy();
this.set('dropzone', null);
}
},
setupTemplates() {
let templates = this.get('templates');
let emptyTemplate = {
id: "0",
title: "Empty",
description: "An empty canvas for your words",
layout: "doc",
locked: true
};
if (is.undefined(templates.findBy('id', '0'))) {
let emptyTemplate = {
id: "0",
title: "Blank",
description: "An empty canvas for your words",
layout: "doc",
locked: true
};
templates.unshiftObject(emptyTemplate);
}
templates.unshiftObject(emptyTemplate);
this.set('savedTemplates', templates);
Ember.run.schedule('afterRender', () => {
$('#new-document-name').select();
});
},
setupImport() {
console.log("setting up import");
// already done init?
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
if (is.not.null(this.get('dropzone'))) {
this.get('dropzone').destroy();
this.set('dropzone', null);
}
let self = this;
@ -70,9 +82,7 @@ export default Ember.Component.extend(NotifierMixin, {
let importUrl = `${url}/import/folder/${folderId}`;
let dzone = new Dropzone("#import-document-button", {
headers: {
'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token')
},
headers: { 'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token') },
url: importUrl,
method: "post",
paramName: 'attachment',
@ -90,7 +100,7 @@ export default Ember.Component.extend(NotifierMixin, {
});
this.on("error", function (x) {
console.log("Conversion failed for ", x.name, " obj ", x); // eslint-disable-line no-console
console.log("Conversion failed for", x.name, x); // eslint-disable-line no-console
});
this.on("queuecomplete", function () {});
@ -105,12 +115,12 @@ export default Ember.Component.extend(NotifierMixin, {
dzone.removeFile(file);
});
this.set('drop', dzone);
this.set('dropzone', dzone);
},
actions: {
onHideDocumentWizard() {
this.get('onHideDocumentWizard')();
onHideStartDocument() {
this.get('onHideStartDocument')();
},
editTemplate(template) {
@ -120,7 +130,13 @@ export default Ember.Component.extend(NotifierMixin, {
},
startDocument(template) {
this.send("showNotification", "Creating");
if (this.get('newDocumentNameMissing')) {
this.$("#new-document-name").addClass('error').focus();
return;
}
this.$("#new-document-name").removeClass('error');
this.send("showNotification", "Creating");
this.get('templateService').importSavedTemplate(this.folder.get('id'), template.id, this.get('newDocumentName')).then((document) => {
this.get('router').transitionTo('document', this.get('folder.id'), this.get('folder.slug'), document.get('id'), document.get('slug'));
@ -130,26 +146,30 @@ export default Ember.Component.extend(NotifierMixin, {
},
onDocumentImporting(filename) {
if (this.isDestroyed) { return; }
this.send("showNotification", `Importing ${filename}`);
this.get('onHideDocumentWizard')();
this.get('onHideStartDocument')();
let documents = this.get('importedDocuments');
documents.push(filename);
if (this.isDestroyed) { return; }
this.set('importedDocuments', documents);
},
onDocumentImported(filename /*, document*/ ) {
if (this.isDestroyed) { return; }
this.send("showNotification", `${filename} ready`);
let documents = this.get('importedDocuments');
documents.pop(filename);
if (this.isDestroyed) { return; }
this.set('importedDocuments', documents);
this.get('onImport')();
if (documents.length === 0) {
// this.get('showDocument')(this.get('folder'), document);
}
},
}
});