1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 21:59:42 +02:00

select space root or category docs

This commit is contained in:
Harvey Kandola 2017-10-02 13:48:37 -04:00
parent 8d761da939
commit ba5988dca3
8 changed files with 105 additions and 100 deletions

View file

@ -31,22 +31,21 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
pinState : { pinState : {
isPinned: false, isPinned: false,
pinId: '', pinId: '',
newName: '', newName: ''
tip: null
}, },
deleteSpaceName: '', deleteSpaceName: '',
didReceiveAttrs() { didReceiveAttrs() {
this._super(...arguments); this._super(...arguments);
let targets = _.reject(this.get('folders'), {
id: this.get('folder').get('id')
});
let folder = this.get('folder'); let folder = this.get('folder');
this.set('pinState.pinId', this.get('pinned').isSpacePinned(folder.get('id'))); let targets = _.reject(this.get('folders'), {id: folder.get('id')});
this.set('pinState.isPinned', this.get('pinState.pinId') !== '');
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('pinState.newName', folder.get('name'));
});
this.set('movedFolderOptions', targets); this.set('movedFolderOptions', targets);
}, },
@ -91,9 +90,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
willDestroyElement() { willDestroyElement() {
this._super(...arguments); this._super(...arguments);
if (this.get('isDestroyed') || this.get('isDestroying')) { if (this.get('isDestroyed') || this.get('isDestroying')) return;
return;
}
if (is.not.null(this.get('drop'))) { if (is.not.null(this.get('drop'))) {
this.get('drop').destroy(); this.get('drop').destroy();

View file

@ -25,13 +25,27 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
localStorage: service('localStorage'), localStorage: service('localStorage'),
selectedDocuments: [], selectedDocuments: [],
hasSelectedDocuments: Ember.computed.gt('selectedDocuments.length', 0), hasSelectedDocuments: Ember.computed.gt('selectedDocuments.length', 0),
hasCategories: Ember.computed.gt('categories.length', 0),
showStartDocument: false, showStartDocument: false,
filteredDocs: [], filteredDocs: [],
selectedCategory: '',
didReceiveAttrs() { didReceiveAttrs() {
this._super(...arguments); 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 categories = this.get('categories');
let categorySummary = this.get('categorySummary'); let categorySummary = this.get('categorySummary');
let selectedCategory = ''; 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 summary = _.findWhere(categorySummary, {type: "documents", categoryId: cat.get('id')});
let docCount = is.not.undefined(summary) ? summary.count : 0; let docCount = is.not.undefined(summary) ? summary.count : 0;
cat.set('docCount', docCount); 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('categories', categories);
this.set('selectedCategory', selectedCategory);
// Default document view logic: Ember.run.schedule('afterRender', () => {
//
// 1. show space root documents if we have any
// 2. show category documents for first category that has documents
if (this.get('rootDocCount') > 0) { if (this.get('rootDocCount') > 0) {
this.send('onDocumentFilter', 'space', this.get('folder.id')); this.send('onDocumentFilter', 'space', this.get('folder.id'));
} else { } else if (selectedCategory !== '') {
if (selectedCategory !== '') {
this.send('onDocumentFilter', 'category', 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: { actions: {
@ -138,32 +133,39 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
onDocumentFilter(filter, id) { onDocumentFilter(filter, id) {
let docs = this.get('documents'); let docs = this.get('documents');
let categories = this.get('categories');
let categoryMembers = this.get('categoryMembers'); let categoryMembers = this.get('categoryMembers');
let filtered = []; let filtered = [];
let allowed = [];
// filter doc list by category switch (filter) {
if (filter === 'category') { case 'category':
let allowed = _.pluck(_.where(categoryMembers, {'categoryId': id}), 'documentId'); allowed = _.pluck(_.where(categoryMembers, {'categoryId': id}), 'documentId');
docs.forEach((d) => { docs.forEach((d) => {
if (_.contains(allowed, d.get('id'))) { if (_.contains(allowed, d.get('id'))) {
filtered.pushObject(d); filtered.pushObject(d);
} }
}); });
} this.set('spaceSelected', false);
break;
// filter doc list by space (i.e. have no category) case 'space':
if (filter === 'space') { this.set('spaceSelected', true);
this.set('selectedCategory', id); allowed = _.pluck(categoryMembers, 'documentId');
let allowed = _.pluck(categoryMembers, 'documentId');
docs.forEach((d) => { docs.forEach((d) => {
if (!_.contains(allowed, d.get('id'))) { if (!_.contains(allowed, d.get('id'))) {
filtered.pushObject(d); filtered.pushObject(d);
} }
}); });
break;
} }
categories.forEach((cat)=> {
cat.set('selected', cat.get('id') === id);
});
this.set('categories', categories);
this.set('filteredDocs', filtered); this.set('filteredDocs', filtered);
this.set('selectedCategory', id);
} }
} }
}); });

View file

@ -46,9 +46,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
}); });
model.rootDocCount = rootDocCount; model.rootDocCount = rootDocCount;
},
activate() { console.log('afterModel');
this.set('model.showStartDocument', false);
} }
}); });

View file

@ -104,45 +104,51 @@ export default Ember.Service.extend({
isDocumentPinned(documentId) { isDocumentPinned(documentId) {
let userId = this.get('session.user.id'); let userId = this.get('session.user.id');
if (this.get('initialized') === false) {
this.getUserPins().then(() => {
let pins = this.get('pins'); 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) => { pins.forEach((pin) => {
if (pin.get('userId') === userId && pin.get('documentId') === documentId) { if (pin.get('userId') === userId && pin.get('documentId') === documentId) {
pinId = pin.get('id'); resolve(pin.get('id'));
} }
}); });
return pinId;
}); });
} else { } else {
let pins = this.get('pins');
let pinId = '';
pins.forEach((pin) => { pins.forEach((pin) => {
if (pin.get('userId') === userId && pin.get('documentId') === documentId) { if (pin.get('userId') === userId && pin.get('documentId') === documentId) {
pinId = pin.get('id'); resolve(pin.get('id'));
} }
}); });
return pinId;
} }
resolve('');
});
}, },
isSpacePinned(spaceId) { isSpacePinned(spaceId) {
let userId = this.get('session.user.id'); let userId = this.get('session.user.id');
let pins = this.get('pins'); let pins = this.get('pins');
let pinId = '';
return new Ember.RSVP.Promise((resolve) => {
if (!this.get('initialized')) {
this.getUserPins().then((pins) => {
pins.forEach((pin) => { pins.forEach((pin) => {
if (pin.get('userId') === userId && pin.get('documentId') === '' && pin.get('folderId') === spaceId) { if (pin.get('userId') === userId && pin.get('documentId') === '' && pin.get('folderId') === spaceId) {
pinId = pin.get('id'); 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('');
});
} }
}); });

View file

@ -29,14 +29,14 @@
} }
.documents-list { .documents-list {
@include content-container();
margin-bottom: 50px; margin-bottom: 50px;
.document-item { .document-item {
margin: 0; margin: 0 0 25px 0;
padding: 25px 15px; padding: 25px 15px;
position: relative; position: relative;
transition: 0.3s; transition: 0.3s;
@include content-container();
&:hover { &:hover {
> .link { > .link {
@ -58,7 +58,7 @@
position: absolute; position: absolute;
display: none; display: none;
top: 10px; top: 10px;
right: 10px; right: 20px;
cursor: pointer; cursor: pointer;
> .material-icons { > .material-icons {

View file

@ -245,7 +245,7 @@
.button-nav { .button-nav {
background-color: $color-nav-button; background-color: $color-nav-button;
color: $color-nav-button-text; color: $color-nav-button-text;
border: 1px solid $color-nav-button; border: 1px solid $color-sidebar-border;
} }
.flat-button { .flat-button {

View file

@ -42,7 +42,7 @@
{{/unless}} {{/unless}}
<ul class="list"> <ul class="list">
{{#each publicFolders as |folder|}} {{#each publicFolders as |folder|}}
{{#link-to 'folder' folder.id folder.slug class="link" activeClass='selected' }} {{#link-to 'folder.index' folder.id folder.slug class="link" activeClass='selected' }}
<li class="item">{{ folder.name }}</li> <li class="item">{{ folder.name }}</li>
{{/link-to}} {{/link-to}}
{{/each}} {{/each}}
@ -57,7 +57,7 @@
{{/unless}} {{/unless}}
<ul class="list"> <ul class="list">
{{#each protectedFolders as |folder|}} {{#each protectedFolders as |folder|}}
{{#link-to 'folder' folder.id folder.slug class="link" activeClass='selected' }} {{#link-to 'folder.index' folder.id folder.slug class="link" activeClass='selected' }}
<li class="item">{{ folder.name }}</li> <li class="item">{{ folder.name }}</li>
{{/link-to}} {{/link-to}}
{{/each}} {{/each}}
@ -71,7 +71,7 @@
{{/unless}} {{/unless}}
<ul class="list"> <ul class="list">
{{#each privateFolders as |folder|}} {{#each privateFolders as |folder|}}
{{#link-to 'folder' folder.id folder.slug class="link" activeClass='selected' }} {{#link-to 'folder.index' folder.id folder.slug class="link" activeClass='selected' }}
<li class="item">{{ folder.name }}</li> <li class="item">{{ folder.name }}</li>
{{/link-to}} {{/link-to}}
{{/each}} {{/each}}

View file

@ -13,16 +13,18 @@
onImport=(action 'onImport') onHideStartDocument=(action 'onHideStartDocument')}} onImport=(action 'onImport') onHideStartDocument=(action 'onHideStartDocument')}}
{{else}} {{else}}
{{#if (gt categories.length 0)}} {{#if hasCategories}}
<div class="category-filter"> <div class="category-filter">
{{#if (gt rootDocCount 0)}} {{#if (gt rootDocCount 0)}}
<div class="regular-button button-white {{if (eq folder.id selectedCategory) 'selected'}}" id="uncategorized-button" data-tooltip="Documents without category" data-tooltip-position="top center" {{action 'onDocumentFilter' 'space' folder.id}}> <div class="regular-button button-white {{if spaceSelected 'selected'}}"
id="uncategorized-button" data-tooltip="Documents without category" data-tooltip-position="top center"
{{action 'onDocumentFilter' 'space' folder.id}}>
{{folder.name}} ({{rootDocCount}}) {{folder.name}} ({{rootDocCount}})
</div> </div>
{{/if}} {{/if}}
{{#each categories as |cat index|}} {{#each categories as |cat index|}}
<div class="button-gap"/> <div class="button-gap"/>
<div class="regular-button button-white {{if (eq cat.id selectedCategory) 'selected'}}" {{action 'onDocumentFilter' 'category' cat.id}}> <div class="regular-button button-white {{if cat.selected 'selected'}}" {{action 'onDocumentFilter' 'category' cat.id}}>
{{cat.category}} ({{cat.docCount}}) {{cat.category}} ({{cat.docCount}})
</div> </div>
{{/each}} {{/each}}
@ -30,7 +32,6 @@
{{/if}} {{/if}}
{{folder/documents-list documents=filteredDocs folders=folders folder=folder {{folder/documents-list documents=filteredDocs folders=folders folder=folder
templates=templates permissions=permissions selectedDocuments=(mut selectedDocuments) templates=templates permissions=permissions selectedDocuments=(mut selectedDocuments)}}
onImport=(action 'onImport')}}
{{/if}} {{/if}}