diff --git a/gui/app/components/folder/space-toolbar.js b/gui/app/components/folder/space-toolbar.js index 93e85f3b..997cc2a0 100644 --- a/gui/app/components/folder/space-toolbar.js +++ b/gui/app/components/folder/space-toolbar.js @@ -31,22 +31,21 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, { pinState : { isPinned: false, pinId: '', - newName: '', - tip: null + newName: '' }, deleteSpaceName: '', didReceiveAttrs() { this._super(...arguments); - let targets = _.reject(this.get('folders'), { - id: this.get('folder').get('id') - }); - let folder = this.get('folder'); - this.set('pinState.pinId', this.get('pinned').isSpacePinned(folder.get('id'))); - this.set('pinState.isPinned', this.get('pinState.pinId') !== ''); - this.set('pinState.newName', folder.get('name')); + let targets = _.reject(this.get('folders'), {id: folder.get('id')}); + + this.get('pinned').isSpacePinned(folder.get('id')).then((pinId) => { + this.set('pinState.pinId', pinId); + this.set('pinState.isPinned', pinId !== ''); + this.set('pinState.newName', folder.get('name')); + }); this.set('movedFolderOptions', targets); }, @@ -91,9 +90,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, { willDestroyElement() { this._super(...arguments); - if (this.get('isDestroyed') || this.get('isDestroying')) { - return; - } + if (this.get('isDestroyed') || this.get('isDestroying')) return; if (is.not.null(this.get('drop'))) { this.get('drop').destroy(); diff --git a/gui/app/components/folder/space-view.js b/gui/app/components/folder/space-view.js index cf3b1c34..9ac2684c 100644 --- a/gui/app/components/folder/space-view.js +++ b/gui/app/components/folder/space-view.js @@ -25,13 +25,27 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, { localStorage: service('localStorage'), selectedDocuments: [], hasSelectedDocuments: Ember.computed.gt('selectedDocuments.length', 0), + hasCategories: Ember.computed.gt('categories.length', 0), showStartDocument: false, filteredDocs: [], - selectedCategory: '', didReceiveAttrs() { this._super(...arguments); + this.setup(); + }, + didUpdateAttrs() { + this._super(...arguments); + this.set('selectedDocuments', []); + }, + + willDestroyElement() { + this._super(...arguments); + + this.destroyTooltips(); + }, + + setup() { let categories = this.get('categories'); let categorySummary = this.get('categorySummary'); let selectedCategory = ''; @@ -40,39 +54,20 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, { let summary = _.findWhere(categorySummary, {type: "documents", categoryId: cat.get('id')}); let docCount = is.not.undefined(summary) ? summary.count : 0; cat.set('docCount', docCount); - if (docCount > 0 && selectedCategory === '') selectedCategory = cat.get('id'); + if (docCount > 0 && selectedCategory === '') { + selectedCategory = cat.get('id'); + } }); this.set('categories', categories); - this.set('selectedCategory', selectedCategory); - // Default document view logic: - // - // 1. show space root documents if we have any - // 2. show category documents for first category that has documents - if (this.get('rootDocCount') > 0) { - this.send('onDocumentFilter', 'space', this.get('folder.id')); - } else { - if (selectedCategory !== '') { + Ember.run.schedule('afterRender', () => { + if (this.get('rootDocCount') > 0) { + this.send('onDocumentFilter', 'space', this.get('folder.id')); + } else if (selectedCategory !== '') { this.send('onDocumentFilter', 'category', selectedCategory); } - } - }, - - didRender() { - this._super(...arguments); - - if (this.get('categories.length') > 0) { - this.addTooltip(document.getElementById("uncategorized-button")); - } - }, - - willDestroyElement() { - this._super(...arguments); - - if (this.get('isDestroyed') || this.get('isDestroying')) return; - - this.destroyTooltips(); + }); }, actions: { @@ -138,32 +133,39 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, { onDocumentFilter(filter, id) { let docs = this.get('documents'); + let categories = this.get('categories'); let categoryMembers = this.get('categoryMembers'); let filtered = []; + let allowed = []; - // filter doc list by category - if (filter === 'category') { - let allowed = _.pluck(_.where(categoryMembers, {'categoryId': id}), 'documentId'); - docs.forEach((d) => { - if (_.contains(allowed, d.get('id'))) { - filtered.pushObject(d); - } - }); + switch (filter) { + case 'category': + allowed = _.pluck(_.where(categoryMembers, {'categoryId': id}), 'documentId'); + docs.forEach((d) => { + if (_.contains(allowed, d.get('id'))) { + filtered.pushObject(d); + } + }); + this.set('spaceSelected', false); + break; + + case 'space': + this.set('spaceSelected', true); + allowed = _.pluck(categoryMembers, 'documentId'); + docs.forEach((d) => { + if (!_.contains(allowed, d.get('id'))) { + filtered.pushObject(d); + } + }); + break; } - // filter doc list by space (i.e. have no category) - if (filter === 'space') { - this.set('selectedCategory', id); - let allowed = _.pluck(categoryMembers, 'documentId'); - docs.forEach((d) => { - if (!_.contains(allowed, d.get('id'))) { - filtered.pushObject(d); - } - }); - } + categories.forEach((cat)=> { + cat.set('selected', cat.get('id') === id); + }); + this.set('categories', categories); this.set('filteredDocs', filtered); - this.set('selectedCategory', id); } } }); diff --git a/gui/app/pods/folder/index/route.js b/gui/app/pods/folder/index/route.js index ec983db3..91759c4e 100644 --- a/gui/app/pods/folder/index/route.js +++ b/gui/app/pods/folder/index/route.js @@ -46,9 +46,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }); model.rootDocCount = rootDocCount; - }, - activate() { - this.set('model.showStartDocument', false); + console.log('afterModel'); + } }); diff --git a/gui/app/services/pinned.js b/gui/app/services/pinned.js index 975eb1ae..613d38be 100644 --- a/gui/app/services/pinned.js +++ b/gui/app/services/pinned.js @@ -104,45 +104,51 @@ export default Ember.Service.extend({ isDocumentPinned(documentId) { let userId = this.get('session.user.id'); + let pins = this.get('pins'); - if (this.get('initialized') === false) { - this.getUserPins().then(() => { - let pins = this.get('pins'); - let pinId = ''; - + return new Ember.RSVP.Promise((resolve) => { + if (this.get('initialized') === false) { + this.getUserPins().then((pins) => { + pins.forEach((pin) => { + if (pin.get('userId') === userId && pin.get('documentId') === documentId) { + resolve(pin.get('id')); + } + }); + }); + } else { pins.forEach((pin) => { if (pin.get('userId') === userId && pin.get('documentId') === documentId) { - pinId = pin.get('id'); + resolve(pin.get('id')); } }); + } - return pinId; - }); - } else { - let pins = this.get('pins'); - let pinId = ''; - - pins.forEach((pin) => { - if (pin.get('userId') === userId && pin.get('documentId') === documentId) { - pinId = pin.get('id'); - } - }); - - return pinId; - } + resolve(''); + }); }, isSpacePinned(spaceId) { let userId = this.get('session.user.id'); let pins = this.get('pins'); - let pinId = ''; - pins.forEach((pin) => { - if (pin.get('userId') === userId && pin.get('documentId') === '' && pin.get('folderId') === spaceId) { - pinId = pin.get('id'); + return new Ember.RSVP.Promise((resolve) => { + if (!this.get('initialized')) { + this.getUserPins().then((pins) => { + pins.forEach((pin) => { + if (pin.get('userId') === userId && pin.get('documentId') === '' && pin.get('folderId') === spaceId) { + resolve(pin.get('id')); + } + }); + }); + } else { + pins.forEach((pin) => { + if (pin.get('userId') === userId && pin.get('documentId') === '' && pin.get('folderId') === spaceId) { + resolve(pin.get('id')); + } + }); } - }); - return pinId; + resolve(''); + }); } }); diff --git a/gui/app/styles/view/folder/document.scss b/gui/app/styles/view/folder/document.scss index 17d91189..0c380726 100644 --- a/gui/app/styles/view/folder/document.scss +++ b/gui/app/styles/view/folder/document.scss @@ -29,14 +29,14 @@ } .documents-list { - @include content-container(); margin-bottom: 50px; .document-item { - margin: 0; + margin: 0 0 25px 0; padding: 25px 15px; position: relative; transition: 0.3s; + @include content-container(); &:hover { > .link { @@ -58,7 +58,7 @@ position: absolute; display: none; top: 10px; - right: 10px; + right: 20px; cursor: pointer; > .material-icons { diff --git a/gui/app/styles/widget/widget-button.scss b/gui/app/styles/widget/widget-button.scss index 3bd3a5c5..84c976ad 100644 --- a/gui/app/styles/widget/widget-button.scss +++ b/gui/app/styles/widget/widget-button.scss @@ -245,7 +245,7 @@ .button-nav { background-color: $color-nav-button; color: $color-nav-button-text; - border: 1px solid $color-nav-button; + border: 1px solid $color-sidebar-border; } .flat-button { diff --git a/gui/app/templates/components/folder/sidebar-folders-list.hbs b/gui/app/templates/components/folder/sidebar-folders-list.hbs index 3f9055ff..1ca4f955 100644 --- a/gui/app/templates/components/folder/sidebar-folders-list.hbs +++ b/gui/app/templates/components/folder/sidebar-folders-list.hbs @@ -42,7 +42,7 @@ {{/unless}}