1
0
Fork 0
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:
McMatts 2019-03-13 11:40:36 +00:00
parent 0985dbf5b6
commit 1d00f8ac6e
19 changed files with 1182 additions and 807 deletions

View file

@ -9,11 +9,13 @@
//
// https://documize.com
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { A } from '@ember/array';
import Component from '@ember/component';
export default Component.extend({
localStorage: service(),
showDeleteDialog: false,
showMoveDialog: false,
selectedDocuments: A([]),
@ -36,9 +38,53 @@ export default Component.extend({
let targets = _.reject(this.get('spaces'), {id: space.get('id')});
this.set('moveOptions', A(targets));
this.set('selectedDocuments', A([]));
let sortBy = this.get('localStorage').getSessionItem('space.sortBy');
if (!_.isNull(sortBy) && !_.isUndefined(sortBy)) {
this.send('onSetSort', sortBy);
}
let sortOrder = this.get('localStorage').getSessionItem('space.sortOrder');
if (!_.isNull(sortOrder) && !_.isUndefined(sortOrder)) {
this.send('onSetSort', sortOrder);
}
},
actions: {
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) {
// attacher.hide();
this.get('onFiltered')(this.get('documents'));
},
onShowDeleteDocuments() {
this.set('showDeleteDialog', true);
},

View file

@ -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'));
},
}
});

View file

@ -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'));

View file

@ -21,6 +21,7 @@ export default Component.extend({
icon: '',
color: '',
light: false,
outline: false,
themed: false,
dismiss: false,
truncate: false,
@ -48,6 +49,10 @@ export default Component.extend({
bc += '-light';
}
if (this.outline) {
bc += '-outline';
}
if (!this.uppercase) {
bc += ' text-case-normal';
}