mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
Allow sorting of search results and space contents
Closes #187 Sort search results and space contents by Name, Created or Revised.
This commit is contained in:
parent
0985dbf5b6
commit
1d00f8ac6e
19 changed files with 1182 additions and 807 deletions
|
@ -10,13 +10,23 @@
|
|||
// https://documize.com
|
||||
|
||||
import { computed } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Component from '@ember/component';
|
||||
|
||||
export default Component.extend({
|
||||
localStorage: service('localStorage'),
|
||||
resultPhrase: '',
|
||||
searchQuery: computed('keywords', function() {
|
||||
return encodeURIComponent(this.get('keywords'));
|
||||
}),
|
||||
// eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects
|
||||
sortBy: {
|
||||
name: true,
|
||||
created: false,
|
||||
updated: false,
|
||||
asc: true,
|
||||
desc: false,
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
|
@ -34,10 +44,84 @@ export default Component.extend({
|
|||
let docLabel = duped.length === 1 ? "document" : "documents";
|
||||
let i = docs.length;
|
||||
let j = duped.length;
|
||||
phrase = `${i} ${references} across ${j} ${docLabel}`;
|
||||
phrase = `${i} ${references} in ${j} ${docLabel}`;
|
||||
}
|
||||
|
||||
this.set('resultPhrase', phrase);
|
||||
this.set('documents', duped);
|
||||
|
||||
let sortBy = this.get('localStorage').getSessionItem('search.sortBy');
|
||||
if (!_.isNull(sortBy) && !_.isUndefined(sortBy)) {
|
||||
this.send('onSetSort', sortBy);
|
||||
}
|
||||
|
||||
let sortOrder = this.get('localStorage').getSessionItem('search.sortOrder');
|
||||
if (!_.isNull(sortOrder) && !_.isUndefined(sortOrder)) {
|
||||
this.send('onSetSort', sortOrder);
|
||||
}
|
||||
|
||||
this.sortResults(duped);
|
||||
},
|
||||
|
||||
sortResults(docs) {
|
||||
let ls = this.get('localStorage');
|
||||
let sortBy = this.get('sortBy');
|
||||
|
||||
if (_.isNull(docs)) return;
|
||||
|
||||
if (sortBy.name) {
|
||||
docs = docs.sortBy('document');
|
||||
ls.storeSessionItem('search.sortBy', 'name');
|
||||
}
|
||||
if (sortBy.created) {
|
||||
docs = docs.sortBy('created');
|
||||
ls.storeSessionItem('search.sortBy', 'created');
|
||||
}
|
||||
if (sortBy.updated) {
|
||||
docs = docs.sortBy('revised');
|
||||
ls.storeSessionItem('search.sortBy', 'updated');
|
||||
}
|
||||
if (sortBy.desc) {
|
||||
docs = docs.reverseObjects();
|
||||
ls.storeSessionItem('search.sortOrder', 'desc');
|
||||
} else {
|
||||
ls.storeSessionItem('search.sortOrder', 'asc');
|
||||
}
|
||||
|
||||
this.set('documents', docs);
|
||||
},
|
||||
|
||||
actions: {
|
||||
onSetSort(val) {
|
||||
switch (val) {
|
||||
case 'name':
|
||||
this.set('sortBy.name', true);
|
||||
this.set('sortBy.created', false);
|
||||
this.set('sortBy.updated', false);
|
||||
break;
|
||||
case 'created':
|
||||
this.set('sortBy.name', false);
|
||||
this.set('sortBy.created', true);
|
||||
this.set('sortBy.updated', false);
|
||||
break;
|
||||
case 'updated':
|
||||
this.set('sortBy.name', false);
|
||||
this.set('sortBy.created', false);
|
||||
this.set('sortBy.updated', true);
|
||||
break;
|
||||
case 'asc':
|
||||
this.set('sortBy.asc', true);
|
||||
this.set('sortBy.desc', false);
|
||||
break;
|
||||
case 'desc':
|
||||
this.set('sortBy.asc', false);
|
||||
this.set('sortBy.desc', true);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
onSortBy(attacher) {
|
||||
this.sortResults(this.get('documents'));
|
||||
},
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,10 +20,6 @@ export default Component.extend({
|
|||
keywords: '' ,
|
||||
matchFilter: null,
|
||||
|
||||
// init() {
|
||||
// this._super(...arguments);
|
||||
// },
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
this.set('keywords', this.get('filter'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue