mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
select space root or category docs
This commit is contained in:
parent
8d761da939
commit
ba5988dca3
8 changed files with 105 additions and 100 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -46,9 +46,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
});
|
||||
|
||||
model.rootDocCount = rootDocCount;
|
||||
},
|
||||
|
||||
activate() {
|
||||
this.set('model.showStartDocument', false);
|
||||
console.log('afterModel');
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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('');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
{{/unless}}
|
||||
<ul class="list">
|
||||
{{#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>
|
||||
{{/link-to}}
|
||||
{{/each}}
|
||||
|
@ -57,7 +57,7 @@
|
|||
{{/unless}}
|
||||
<ul class="list">
|
||||
{{#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>
|
||||
{{/link-to}}
|
||||
{{/each}}
|
||||
|
@ -71,7 +71,7 @@
|
|||
{{/unless}}
|
||||
<ul class="list">
|
||||
{{#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>
|
||||
{{/link-to}}
|
||||
{{/each}}
|
||||
|
|
|
@ -13,16 +13,18 @@
|
|||
onImport=(action 'onImport') onHideStartDocument=(action 'onHideStartDocument')}}
|
||||
{{else}}
|
||||
|
||||
{{#if (gt categories.length 0)}}
|
||||
{{#if hasCategories}}
|
||||
<div class="category-filter">
|
||||
{{#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}})
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#each categories as |cat index|}}
|
||||
<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}})
|
||||
</div>
|
||||
{{/each}}
|
||||
|
@ -30,7 +32,6 @@
|
|||
{{/if}}
|
||||
|
||||
{{folder/documents-list documents=filteredDocs folders=folders folder=folder
|
||||
templates=templates permissions=permissions selectedDocuments=(mut selectedDocuments)
|
||||
onImport=(action 'onImport')}}
|
||||
templates=templates permissions=permissions selectedDocuments=(mut selectedDocuments)}}
|
||||
|
||||
{{/if}}
|
Loading…
Add table
Add a link
Reference in a new issue