From e140caff553e187b0b4ce436d3b9f88c84b75644 Mon Sep 17 00:00:00 2001 From: McMatts Date: Thu, 20 Dec 2018 14:31:59 +0000 Subject: [PATCH] Break out document tag and category mng sections Separate out screens for tag and category management. --- ...{settings-meta.js => settings-category.js} | 1 - gui/app/components/document/settings-tag.js | 189 ++++++++++++++++++ gui/app/pods/document/revisions/template.hbs | 12 +- gui/app/pods/document/settings/template.hbs | 92 +++++---- gui/app/pods/folder/settings/template.hbs | 12 +- .../components/document/settings-category.hbs | 19 ++ .../components/document/settings-general.hbs | 40 ++-- .../components/document/settings-meta.hbs | 30 --- .../components/document/settings-tag.hbs | 25 +++ 9 files changed, 315 insertions(+), 105 deletions(-) rename gui/app/components/document/{settings-meta.js => settings-category.js} (99%) create mode 100644 gui/app/components/document/settings-tag.js create mode 100644 gui/app/templates/components/document/settings-category.hbs delete mode 100644 gui/app/templates/components/document/settings-meta.hbs create mode 100644 gui/app/templates/components/document/settings-tag.hbs diff --git a/gui/app/components/document/settings-meta.js b/gui/app/components/document/settings-category.js similarity index 99% rename from gui/app/components/document/settings-meta.js rename to gui/app/components/document/settings-category.js index 85ba173a..8780beb0 100644 --- a/gui/app/components/document/settings-meta.js +++ b/gui/app/components/document/settings-category.js @@ -156,7 +156,6 @@ export default Component.extend(Notifier, { this.get('categoryService').setCategoryMembership(toUnlink, 'unlink').then(() => { this.get('categoryService').setCategoryMembership(toLink, 'link').then(() => { - this.notifySuccess('Saved'); }); }); diff --git a/gui/app/components/document/settings-tag.js b/gui/app/components/document/settings-tag.js new file mode 100644 index 00000000..8780beb0 --- /dev/null +++ b/gui/app/components/document/settings-tag.js @@ -0,0 +1,189 @@ +// 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 $ from 'jquery'; +import { inject as service } from '@ember/service'; +import { A } from '@ember/array'; +import { computed } from '@ember/object'; +import { schedule } from '@ember/runloop'; +import Notifier from '../../mixins/notifier'; +import Component from '@ember/component'; + +export default Component.extend(Notifier, { + appMeta: service(), + documentSvc: service('document'), + categoryService: service('category'), + + tagz: A([]), + categories: A([]), + newCategory: '', + showCategoryModal: false, + hasCategories: computed('categories', function() { + return this.get('categories').length > 0; + }), + canSelectCategory: computed('categories', function() { + return (this.get('categories').length > 0 && this.get('permissions.documentEdit')); + }), + canAddCategory: computed('categories', function() { + return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage'); + }), + + didReceiveAttrs() { + this._super(...arguments); + this.load(); + }, + + didInsertElement() { + this._super(...arguments); + + schedule('afterRender', () => { + $("#add-tag-field-1").focus(); + + $(".tag-input").off("keydown").on("keydown", function(e) { + if (e.shiftKey && e.which === 9) { + return true; + } + + if (e.shiftKey) { + return false; + } + + if (e.which === 9 || + e.which === 13 || + e.which === 16 || + e.which === 37 || + e.which === 38 || + e.which === 39 || + e.which === 40 || + e.which === 45 || + e.which === 189 || + e.which === 8 || + e.which === 127 || + (e.which >= 65 && e.which <= 90) || + (e.which >= 97 && e.which <= 122) || + (e.which >= 48 && e.which <= 57)) { + return true; + } + + return false; + }); + }); + }, + + willDestroyElement() { + this._super(...arguments); + + $(".tag-input").off("keydown"); + }, + + load() { + this.get('categoryService').getUserVisible(this.get('space.id')).then((categories) => { + let cats = A(categories); + this.set('categories', cats); + this.get('categoryService').getDocumentCategories(this.get('document.id')).then((selected) => { + this.set('selectedCategories', selected); + selected.forEach((s) => { + let cat = cats.findBy('id', s.id); + if (is.not.undefined(cat)) { + cat.set('selected', true); + this.set('categories', cats); + } + }); + }); + }); + + let counter = 1; + let tagz = A([]); + let maxTags = this.get('appMeta.maxTags'); + + if (!_.isUndefined(this.get('document.tags')) && this.get('document.tags').length > 1) { + let tags = this.get('document.tags').split('#'); + + _.each(tags, (tag) => { + tag = tag.trim(); + if (tag.length > 0 && counter <= maxTags) { + tagz.pushObject({number: counter, value: tag}); + counter++; + } + }); + } + + for (let index = counter; index <= maxTags; index++) { + tagz.pushObject({number: index, value: ''}); + } + + this.set('tagz', tagz); + }, + + actions: { + onSave() { + let docId = this.get('document.id'); + let folderId = this.get('space.id'); + let link = this.get('categories').filterBy('selected', true); + let unlink = this.get('categories').filterBy('selected', false); + let toLink = []; + let toUnlink = []; + + // prepare links associated with document + link.forEach((l) => { + let t = { + spaceId: folderId, + documentId: docId, + categoryId: l.get('id') + }; + + toLink.push(t); + }); + + // prepare links no longer associated with document + unlink.forEach((l) => { + let t = { + spaceId: folderId, + documentId: docId, + categoryId: l.get('id') + }; + + toUnlink.pushObject(t); + }); + + this.get('categoryService').setCategoryMembership(toUnlink, 'unlink').then(() => { + this.get('categoryService').setCategoryMembership(toLink, 'link').then(() => { + }); + }); + + let tagz = this.get('tagz'); + let tagzToSave = []; + + _.each(tagz, (t) => { + let tag = t.value.toLowerCase().trim(); + if (tag.length> 0) { + if (!_.contains(tagzToSave, tag) && is.not.startWith(tag, '-')) { + tagzToSave.push(tag); + this.$('#add-tag-field-' + t.number).removeClass('is-invalid'); + } else { + this.$('#add-tag-field-' + t.number).addClass('is-invalid'); + } + } + }); + + let save = "#"; + _.each(tagzToSave, (t) => { + save += t; + save += '#'; + }); + + let doc = this.get('document'); + doc.set('tags', save); + + this.get('onSaveDocument')(doc); + } + } +}); diff --git a/gui/app/pods/document/revisions/template.hbs b/gui/app/pods/document/revisions/template.hbs index 6c3cd77c..449cf691 100644 --- a/gui/app/pods/document/revisions/template.hbs +++ b/gui/app/pods/document/revisions/template.hbs @@ -1,13 +1,13 @@ {{#layout/master-sidebar}} {{ui/ui-spacer size=300}} - {{#link-to "document.index"}} - {{ui/ui-button color=constants.Color.Yellow light=true icon=constants.Icon.ArrowLeft label="Document"}} - {{/link-to}} - - {{ui/ui-spacer size=400}} -
+ {{#link-to "document.index"}} + {{ui/ui-button color=constants.Color.Yellow light=true icon=constants.Icon.ArrowLeft label="Document"}} + {{/link-to}} + + {{ui/ui-spacer size=400}} +
REVISIONS
{{#each revisions as |revision|}} diff --git a/gui/app/pods/document/settings/template.hbs b/gui/app/pods/document/settings/template.hbs index 773e58d6..b418c622 100644 --- a/gui/app/pods/document/settings/template.hbs +++ b/gui/app/pods/document/settings/template.hbs @@ -1,49 +1,53 @@ -{{#layout/top-bar}} -
  • - {{#link-to "folder.index" model.folder.id model.folder.slug class="link"}} - {{model.folder.name}} - {{/link-to}} -
  • -
  • - {{#link-to "document.index" model.folder.id model.folder.slug model.document.id model.document.slug class="link"}} - {{model.document.name}} - {{/link-to}} -
  • -
  • - {{#link-to "document.settings" model.folder.id model.folder.slug class="link selected"}} - Settings - {{/link-to}} -
  • -{{/layout/top-bar}} +{{#layout/master-sidebar}} + {{ui/ui-spacer size=300}} -{{#layout/middle-zone}} - {{#layout/middle-zone-content}} - {{#if (eq tab "general")}} - {{document/settings-general - space=model.folder - document=model.document - permissions=model.permissions - onSaveDocument=(action "onSaveDocument")}} - {{/if}} +
    + {{#link-to "document.index"}} + {{ui/ui-button color=constants.Color.Yellow light=true icon=constants.Icon.ArrowLeft label="Document"}} + {{/link-to}} - {{#if (eq tab "meta")}} - {{document/settings-meta - space=model.folder - document=model.document - permissions=model.permissions - onSaveDocument=(action "onSaveDocument")}} - {{/if}} - {{/layout/middle-zone-content}} + {{ui/ui-spacer size=400}} - {{#layout/middle-zone-sidebar}} - +{{/layout/master-sidebar}} -{{#layout/bottom-bar}} -{{/layout/bottom-bar}} +{{#layout/master-content}} + {{#if (eq tab "general")}} + {{document/settings-general + space=model.folder + document=model.document + permissions=model.permissions + onSaveDocument=(action "onSaveDocument")}} + {{/if}} + + {{#if (eq tab "category")}} + {{document/settings-category + space=model.folder + document=model.document + permissions=model.permissions + onSaveDocument=(action "onSaveDocument")}} + {{/if}} + + {{#if (eq tab "tag")}} + {{document/settings-tag + space=model.folder + document=model.document + permissions=model.permissions + onSaveDocument=(action "onSaveDocument")}} + {{/if}} +{{/layout/master-content}} diff --git a/gui/app/pods/folder/settings/template.hbs b/gui/app/pods/folder/settings/template.hbs index 420d4d3e..939e5ffa 100644 --- a/gui/app/pods/folder/settings/template.hbs +++ b/gui/app/pods/folder/settings/template.hbs @@ -1,13 +1,13 @@ {{#layout/master-sidebar}} {{ui/ui-spacer size=300}} - {{#link-to "folder.index"}} - {{ui/ui-button color=constants.Color.Yellow light=true icon=constants.Icon.ArrowLeft label="Space"}} - {{/link-to}} - - {{ui/ui-spacer size=400}} -
    + {{#link-to "folder.index"}} + {{ui/ui-button color=constants.Color.Yellow light=true icon=constants.Icon.ArrowLeft label="Space"}} + {{/link-to}} + + {{ui/ui-spacer size=400}} +
    space management
    diff --git a/gui/app/templates/components/document/settings-category.hbs b/gui/app/templates/components/document/settings-category.hbs new file mode 100644 index 00000000..7d406e66 --- /dev/null +++ b/gui/app/templates/components/document/settings-category.hbs @@ -0,0 +1,19 @@ +{{layout/logo-heading + title="Categories" + desc="Assign one or more categories to help organize content within this space" + icon=constants.Icon.Category}} + +{{ui/ui-list-picker items=categories nameField="category" singleSelect=false}} + +{{#unless categories}} +

    This space has no categories yet

    +{{/unless}} + +{{ui/ui-spacer size=300}} + +{{ui/ui-button + color=constants.Color.Green + icon=constants.Icon.Category + label=constants.Label.Save + light=true + onClick=(action "onSave")}} diff --git a/gui/app/templates/components/document/settings-general.hbs b/gui/app/templates/components/document/settings-general.hbs index ed03ab0b..38220c67 100644 --- a/gui/app/templates/components/document/settings-general.hbs +++ b/gui/app/templates/components/document/settings-general.hbs @@ -1,21 +1,25 @@ -
    -
    General Options
    -

    Set name, excerpt and lifecycle stage

    +{{layout/logo-heading + title="Content Settings" + desc="Set name, description and lifecycle stage" + icon=constants.Icon.Settings}} -
    -
    - - {{focus-input id="document-name" type="text" value=docName - class=(if hasNameError "form-control mousetrap is-invalid" "form-control mousetrap") placeholder="Title" autocomplete="off"}} -
    + +
    + + {{focus-input id="document-name" type="text" value=docName + class=(if hasNameError "form-control mousetrap is-invalid" "form-control mousetrap") placeholder="Title" autocomplete="off"}} +
    -
    - - {{textarea id="document-excerpt" rows="4" value=docExcerpt class="form-control mousetrap" placeholder="Excerpt" autocomplete="off"}} - Optional description explaining content -
    - - -
    -
    +
    + + {{textarea id="document-excerpt" rows="4" value=docExcerpt class="form-control mousetrap" placeholder="Excerpt" autocomplete="off"}} + Optional description explaining content +
    + {{ui/ui-button + color=constants.Color.Green + icon=constants.Icon.Settings + label=constants.Label.Save + light=true + onClick=(action "onSave")}} + diff --git a/gui/app/templates/components/document/settings-meta.hbs b/gui/app/templates/components/document/settings-meta.hbs deleted file mode 100644 index 4de916ef..00000000 --- a/gui/app/templates/components/document/settings-meta.hbs +++ /dev/null @@ -1,30 +0,0 @@ -
    -
    Categories & Tags
    -

    Categorize your content, assign tags to suppliment

    - -

    Specify up to {{appMeta.maxTags}} tags

    -

    Lowercase, characters, numbers, hyphens only

    -
    - {{#each tagz as |tag|}} -
    -
    - # -
    - {{input type="text" id=(concat "add-tag-field-" tag.number) class="form-control mousetrap tag-input" placeholder="Tag name" value=tag.value}} -
    - {{/each}} -
    - -
    - -

    Assign categories

    -

    Categories allow you divide a space into logical chunks

    - - {{ui/ui-list-picker items=categories nameField="category" singleSelect=false}} - {{#unless selectedCategories}} -

    This space has no categories defined yet.

    - {{/unless}} - - -
    - diff --git a/gui/app/templates/components/document/settings-tag.hbs b/gui/app/templates/components/document/settings-tag.hbs new file mode 100644 index 00000000..d5c39b3a --- /dev/null +++ b/gui/app/templates/components/document/settings-tag.hbs @@ -0,0 +1,25 @@ +{{layout/logo-heading + title="Tags" + desc=(concat "Specify up to " appMeta.maxTags " tags — lowercase, characters, numbers, hyphens only") + icon=constants.Icon.Category}} + +{{#each tagz as |tag|}} +
    +
    + + + +
    + {{input type="text" id=(concat "add-tag-field-" tag.number) class="form-control mousetrap tag-input" placeholder="Tag name" value=tag.value}} +
    + {{ui/ui-spacer size=200}} +{{/each}} + +{{ui/ui-spacer size=300}} + +{{ui/ui-button + color=constants.Color.Green + icon=constants.Icon.Tag + label=constants.Label.Save + light=true + onClick=(action "onSave")}}