2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
2017-08-15 14:15:31 +01:00
|
|
|
// This software (Documize Community Edition) is licensed under
|
2016-07-07 18:54:16 -07:00
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
2017-08-15 14:15:31 +01:00
|
|
|
// by contacting <sales@documize.com>.
|
2016-07-07 18:54:16 -07:00
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import { debounce } from '@ember/runloop';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Controller from '@ember/controller';
|
|
|
|
|
|
|
|
export default Controller.extend({
|
|
|
|
searchService: service('search'),
|
2017-12-05 11:34:18 +00:00
|
|
|
queryParams: ['filter', 'matchDoc', 'matchContent', 'matchTag', 'matchFile'],
|
|
|
|
filter: '',
|
2016-07-07 18:54:16 -07:00
|
|
|
onKeywordChange: function () {
|
2017-11-16 13:28:05 +00:00
|
|
|
debounce(this, this.fetch, 750);
|
2016-07-07 18:54:16 -07:00
|
|
|
}.observes('filter'),
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
matchDoc: true,
|
2017-08-15 14:15:31 +01:00
|
|
|
onMatchDoc: function () {
|
2017-11-16 13:28:05 +00:00
|
|
|
debounce(this, this.fetch, 750);
|
2017-08-15 14:15:31 +01:00
|
|
|
}.observes('matchDoc'),
|
2017-12-05 11:34:18 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
matchContent: true,
|
2017-08-15 14:15:31 +01:00
|
|
|
onMatchContent: function () {
|
2017-11-16 13:28:05 +00:00
|
|
|
debounce(this, this.fetch, 750);
|
2017-08-15 14:15:31 +01:00
|
|
|
}.observes('matchContent'),
|
2017-12-05 11:34:18 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
matchTag: false,
|
2017-08-15 14:15:31 +01:00
|
|
|
onMatchTag: function () {
|
2017-11-16 13:28:05 +00:00
|
|
|
debounce(this, this.fetch, 750);
|
2017-08-15 14:15:31 +01:00
|
|
|
}.observes('matchTag'),
|
2017-12-05 11:34:18 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
matchFile: false,
|
2017-08-15 14:15:31 +01:00
|
|
|
onMatchFile: function () {
|
2017-11-16 13:28:05 +00:00
|
|
|
debounce(this, this.fetch, 750);
|
2017-08-15 14:15:31 +01:00
|
|
|
}.observes('matchFile'),
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.results = [];
|
|
|
|
},
|
|
|
|
|
2016-07-07 18:54:16 -07:00
|
|
|
fetch() {
|
|
|
|
let self = this;
|
2017-08-15 14:15:31 +01:00
|
|
|
let payload = {
|
|
|
|
keywords: this.get('filter'),
|
|
|
|
doc: this.get('matchDoc'),
|
|
|
|
attachment: this.get('matchFile'),
|
|
|
|
tag: this.get('matchTag'),
|
|
|
|
content: this.get('matchContent')
|
|
|
|
};
|
|
|
|
|
|
|
|
payload.keywords = payload.keywords.trim();
|
|
|
|
|
|
|
|
if (payload.keywords.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!payload.doc && !payload.tag && !payload.content && !payload.attachment) {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2017-08-15 14:15:31 +01:00
|
|
|
this.get('searchService').find(payload).then(function(response) {
|
2016-07-07 18:54:16 -07:00
|
|
|
self.set('results', response);
|
|
|
|
});
|
2017-08-15 14:15:31 +01:00
|
|
|
},
|
|
|
|
});
|