diff --git a/app/app/components/document/document-page.js b/app/app/components/document/document-page.js index 88729821..ca895655 100644 --- a/app/app/components/document/document-page.js +++ b/app/app/components/document/document-page.js @@ -21,7 +21,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { didReceiveAttrs() { let toEdit = this.get('toEdit'); - if (toEdit === this.get('page.id')) { + if (toEdit === this.get('page.id') && this.get('isEditor')) { this.send('onEdit'); } }, diff --git a/app/app/components/document/document-view.js b/app/app/components/document/document-view.js index 46584c5b..9d6a3563 100644 --- a/app/app/components/document/document-view.js +++ b/app/app/components/document/document-view.js @@ -22,7 +22,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { sectionService: Ember.inject.service('section'), appMeta: Ember.inject.service(), link: Ember.inject.service(), - + hasPages: computed.notEmpty('pages'), newSectionName: '', newSectionNameMissing: computed.empty('newSectionName'), newSectionLocation: '', @@ -38,6 +38,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { this.set('blocks', blocks); this.set('hasBlocks', blocks.get('length') > 0); + // to test blocks.forEach((b) => { b.set('deleteId', `delete-block-button-${b.id}`); }); @@ -54,12 +55,12 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { }, didInsertElement() { - $(".start-section").hoverIntent({interval: 100, over: function() { + $(".start-section:not(.start-section-empty-state)").hoverIntent({interval: 100, over: function() { // in - $(this).find('.start-button').css("display", "block").removeClass('fadeOut').addClass('fadeIn'); + $(this).find('.start-button').velocity("transition.slideDownIn", {duration: 300}); }, out: function() { - //out - $(this).find('.start-button').css("display", "none").removeClass('fadeIn').addClass('fadeOut'); + // out + $(this).find('.start-button').velocity("transition.slideUpOut", {duration: 300}); } }); }, @@ -109,12 +110,15 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { if (is.not.null(beforePage)) { // get any page before the beforePage so we can insert this new section between them let index = _.findIndex(this.get('pages'), function(p) { return p.get('id') === beforePage.get('id'); }); - let beforeBeforePage = this.get('pages')[index-1]; - if (is.not.undefined(beforeBeforePage)) { - sequence = (beforePage.get('sequence') + beforeBeforePage.get('sequence')) / 2; - } else { - sequence = beforePage.get('sequence') / 2; + if (index !== -1) { + let beforeBeforePage = this.get('pages')[index-1]; + + if (is.not.undefined(beforeBeforePage)) { + sequence = (beforePage.get('sequence') + beforeBeforePage.get('sequence')) / 2; + } else { + sequence = beforePage.get('sequence') / 2; + } } } @@ -124,7 +128,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { const promise = this.get('onInsertSection')(model); promise.then((id) => { - if (model.page.contentType === 'section') { + if (model.page.pageType === 'section') { this.set('toEdit', id); } else { this.get('onEditSection')(id); @@ -154,17 +158,26 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { }, // Section wizard related - onShowSectionWizard(page) { - let beforePage = this.get('beforePage'); + if (is.undefined(page)) { + page = { id: '0' }; + } + let beforePage = this.get('beforePage'); if (is.not.null(beforePage) && $("#new-section-wizard").is(':visible') && beforePage.get('id') === page.id) { this.send('onHideSectionWizard'); return; } this.set('newSectionLocation', page.id); - this.set('beforePage', page); + + if (page.id === '0') { + // this handles add section at the end of the document + // because we are not before another page + this.set('beforePage', null); + } else { + this.set('beforePage', page); + } $("#new-section-wizard").insertAfter(`#add-section-button-${page.id}`); $("#new-section-wizard").velocity("transition.slideDownIn", {duration: 300, complete: @@ -250,7 +263,6 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, { // to test onDeleteBlock(id) { this.attrs.onDeleteBlock(id); - }, - + } } }); diff --git a/app/app/components/document/page-wizard.js b/app/app/components/document/page-wizard.js deleted file mode 100644 index 7c8848da..00000000 --- a/app/app/components/document/page-wizard.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2016 Documize Inc. . 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 . -// -// https://documize.com - -import Ember from 'ember'; -import NotifierMixin from '../../mixins/notifier'; - -export default Ember.Component.extend(NotifierMixin, { - display: 'section', // which CSS to use - hasTemplates: false, - hasBlocks: false, - blockMode: false, - - didReceiveAttrs() { - let blocks = this.get('blocks'); - let blockMode = is.not.undefined(blocks); - - this.set('blockMode', blockMode); - if (!blockMode) { - return; - } - - this.set('hasBlocks', blocks.get('length') > 0); - - blocks.forEach((b) => { - b.set('deleteId', `delete-block-button-${b.id}`); - }); - }, - - didRender() { - let self = this; - - Mousetrap.bind('esc', function () { - if (self.get('isDestroyed') || self.get('isDestroying')) { - return; - } - - self.send('onCancel'); - return false; - }); - }, - - actions: { - onCancel() { - this.attrs.onCancel(); - }, - - addSection(section) { - this.attrs.onAddSection(section); - }, - - onDeleteBlock(id) { - this.attrs.onDeleteBlock(id); - }, - - onInsertBlock(block) { - this.attrs.onInsertBlock(block); - } - } -}); diff --git a/app/app/pods/document/index/template.hbs b/app/app/pods/document/index/template.hbs index 13ba291b..d81065c8 100644 --- a/app/app/pods/document/index/template.hbs +++ b/app/app/pods/document/index/template.hbs @@ -40,7 +40,7 @@
-
+
{{#if toggled}} diff --git a/app/app/pods/document/zwizard/controller.js b/app/app/pods/document/zwizard/controller.js deleted file mode 100644 index db12c927..00000000 --- a/app/app/pods/document/zwizard/controller.js +++ /dev/null @@ -1,54 +0,0 @@ -import Ember from 'ember'; -import NotifierMixin from '../../../mixins/notifier'; - -export default Ember.Controller.extend(NotifierMixin, { - documentService: Ember.inject.service('document'), - - actions: { - onCancel() { - this.transitionToRoute('document'); - }, - - onAddSection(section) { - this.audit.record("added-section-" + section.get('contentType')); - - let page = { - documentId: this.get('model.document.id'), - title: `${section.get('title')}`, - level: 1, - sequence: 0, - body: "", - contentType: section.get('contentType'), - pageType: section.get('pageType') - }; - - let meta = { - documentId: this.get('model.document.id'), - rawBody: "", - config: "", - externaleSource: true - }; - - let model = { - page: page, - meta: meta - }; - - this.get('documentService').addPage(this.get('model.document.id'), model).then((newPage) => { - let data = this.get('store').normalize('page', newPage); - this.get('store').push(data); - - this.get('documentService').getPages(this.get('model.document.id')).then((pages) => { - this.set('model.pages', pages.filterBy('pageType', 'section')); - this.set('model.tabs', pages.filterBy('pageType', 'tab')); - - this.get('documentService').getPageMeta(this.get('model.document.id'), newPage.id).then(() => { - let options = {}; - options['mode'] = 'edit'; - this.transitionToRoute('document.section', newPage.id, { queryParams: options }); - }); - }); - }); - } - } -}); diff --git a/app/app/pods/document/zwizard/route.js b/app/app/pods/document/zwizard/route.js deleted file mode 100644 index 465717f6..00000000 --- a/app/app/pods/document/zwizard/route.js +++ /dev/null @@ -1,21 +0,0 @@ -import Ember from 'ember'; -import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; - -export default Ember.Route.extend(AuthenticatedRouteMixin, { - documentService: Ember.inject.service('document'), - folderService: Ember.inject.service('folder'), - sectionService: Ember.inject.service('section'), - - model() { - return Ember.RSVP.hash({ - folders: this.modelFor('document').folders, - folder: this.modelFor('document').folder, - document: this.modelFor('document').document, - pages: this.modelFor('document').pages, - tabs: this.modelFor('document').tabs, - sections: this.get('sectionService').getAll().then(function (sections) { - return sections.filterBy('pageType', 'tab'); - }) - }); - } -}); diff --git a/app/app/pods/document/zwizard/template.hbs b/app/app/pods/document/zwizard/template.hbs deleted file mode 100644 index 37c5e05b..00000000 --- a/app/app/pods/document/zwizard/template.hbs +++ /dev/null @@ -1 +0,0 @@ -{{document/page-wizard display='tab' document=model.document folder=model.folder sections=model.sections onCancel=(action 'onCancel') onAddSection=(action 'onAddSection')}} diff --git a/app/app/styles/view/document/view.scss b/app/app/styles/view/document/view.scss index fc0da62f..de2dfc35 100644 --- a/app/app/styles/view/document/view.scss +++ b/app/app/styles/view/document/view.scss @@ -151,7 +151,6 @@ } .start-section { - @include ease-in(); @extend .no-select; height: 60px; background-color: transparent; @@ -194,6 +193,12 @@ } } + .start-section-empty-state { + > .start-button { + display: block; + } + } + .new-section-wizard { @include border-radius(2px); margin: 0 0 30px 0; diff --git a/app/app/templates/components/document/document-view.hbs b/app/app/templates/components/document/document-view.hbs index 9a9e6da9..dbbd92be 100644 --- a/app/app/templates/components/document/document-view.hbs +++ b/app/app/templates/components/document/document-view.hbs @@ -1,35 +1,51 @@
- {{#each pages key="id" as |page index|}} + {{#if hasPages}} + {{#each pages key="id" as |page index|}} + {{#if isEditor}} +
+
+
+ add +
+
section
+
+
+ {{else}} +
+ {{/if}} + {{#if (is-equal page.pageType 'section')}} + {{#document/document-page document=document folder=folder page=page isEditor=isEditor toEdit=toEdit + onSavePage=(action 'onSavePage') onSavePageAsBlock=(action 'onSavePageAsBlock') + onCopyPage=(action 'onCopyPage') onMovePage=(action 'onMovePage') onDeletePage=(action 'onDeletePage')}} + {{/document/document-page}} + {{/if}} + {{#if (is-equal page.pageType 'tab')}} + {{#document/document-tab document=document folder=folder page=page isEditor=isEditor + onSavePage=(action 'onSavePage') onSavePageAsBlock=(action 'onSavePageAsBlock') + onCopyPage=(action 'onCopyPage') onMovePage=(action 'onMovePage') onDeletePage=(action 'onDeletePage')}} + {{/document/document-tab}} + {{/if}} + {{/each}} +
+
+
+ add +
+
section
+
+
+ {{else}} {{#if isEditor}} -
-
+
+
add
section
- {{else}} -
{{/if}} - {{#if (is-equal page.pageType 'section')}} - {{#document/document-page document=document folder=folder page=page isEditor=isEditor toEdit=toEdit - onSavePage=(action 'onSavePage') onSavePageAsBlock=(action 'onSavePageAsBlock') - onCopyPage=(action 'onCopyPage') onMovePage=(action 'onMovePage') onDeletePage=(action 'onDeletePage')}} - {{/document/document-page}} - {{/if}} - {{#if (is-equal page.pageType 'tab')}} - {{#document/document-tab document=document folder=folder page=page isEditor=isEditor - onSavePage=(action 'onSavePage') onSavePageAsBlock=(action 'onSavePageAsBlock') - onCopyPage=(action 'onCopyPage') onMovePage=(action 'onMovePage') onDeletePage=(action 'onDeletePage')}} - {{/document/document-tab}} - {{/if}} - {{else}} - no sections! -
- -
- {{/each}} + {{/if}}
diff --git a/app/app/templates/components/document/page-wizard.hbs b/app/app/templates/components/document/page-wizard.hbs deleted file mode 100644 index caf91168..00000000 --- a/app/app/templates/components/document/page-wizard.hbs +++ /dev/null @@ -1,63 +0,0 @@ -
-
-
    - {{#each sections as |section|}} -
  • -
    - -
    -
    -
    - {{section.title}} - {{#if section.preview}} -
    coming soon
    - {{/if}} -
    -
    {{section.description}}
    -
    -
    -
  • - {{/each}} -
- {{#if blockMode}} - {{#if hasBlocks}} -
-
Reusable content
-
    - {{#each blocks as |block|}} -
  • -
    -
    - view_agenda -
    -
    - {{#link-to 'document.block' folder.id folder.slug document.id document.slug block.id}} - mode_edit - {{/link-to}} - delete -
    -
    -
    -
    - {{block.title}} -
    -
    {{block.excerpt}}
    -
    By {{block.firstname}} {{block.lastname}}, {{time-ago block.created}} (used: {{ block.used }})
    -
    -
    - {{#dropdown-dialog target=block.deleteId position="bottom left" button="Delete" color="flat-red" onAction=(action 'onDeleteBlock' block.id)}} -

    - Are you sure you want to delete block
    - {{block.title}}? -

    - {{/dropdown-dialog}} -
  • - {{/each}} -
- {{else}} -
-
Reusable content appears below
- {{/if}} - {{/if}} -
-
diff --git a/app/public/assets/img/empty-state-document.gif b/app/public/assets/img/empty-state-document.gif deleted file mode 100644 index 523b76a0..00000000 Binary files a/app/public/assets/img/empty-state-document.gif and /dev/null differ diff --git a/core/api/endpoint/sections_endpoint.go b/core/api/endpoint/sections_endpoint.go index eaaf8045..8e6e5fbd 100644 --- a/core/api/endpoint/sections_endpoint.go +++ b/core/api/endpoint/sections_endpoint.go @@ -12,6 +12,7 @@ package endpoint import ( + "database/sql" "encoding/json" "io/ioutil" "net/http" @@ -121,6 +122,10 @@ func RefreshSections(w http.ResponseWriter, r *http.Request) { // Grab the page because we need content type and page, err2 := p.GetPage(pm.PageID) + if err2 == sql.ErrNoRows { + continue + } + if err2 != nil { writeGeneralSQLError(w, method, err2) log.IfErr(tx.Rollback())