2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// 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
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2018-04-05 14:24:27 +01:00
|
|
|
import { computed } from '@ember/object';
|
2017-11-16 13:28:05 +00:00
|
|
|
import Component from '@ember/component';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
export default Component.extend({
|
2018-03-19 15:04:02 +00:00
|
|
|
resultPhrase: '',
|
2018-04-05 14:24:27 +01:00
|
|
|
searchQuery: computed('keywords', function() {
|
|
|
|
return encodeURIComponent(this.get('keywords'));
|
|
|
|
}),
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2018-03-19 15:04:02 +00:00
|
|
|
didReceiveAttrs() {
|
2018-01-22 10:31:03 +00:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-08-15 14:15:31 +01:00
|
|
|
let docs = this.get('results');
|
2017-08-15 19:41:44 +01:00
|
|
|
let duped = [];
|
2016-11-05 16:02:35 -07:00
|
|
|
let phrase = 'Nothing found';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2017-08-15 14:15:31 +01:00
|
|
|
if (docs.length > 0) {
|
2017-08-15 19:41:44 +01:00
|
|
|
duped = _.uniq(docs, function (item) {
|
2018-03-19 15:04:02 +00:00
|
|
|
return item.get('documentId');
|
2017-08-15 19:41:44 +01:00
|
|
|
});
|
|
|
|
|
2017-08-15 14:15:31 +01:00
|
|
|
let references = docs.length === 1 ? "reference" : "references";
|
2017-08-15 19:41:44 +01:00
|
|
|
let docLabel = duped.length === 1 ? "document" : "documents";
|
2017-08-15 14:15:31 +01:00
|
|
|
let i = docs.length;
|
2017-08-15 19:41:44 +01:00
|
|
|
let j = duped.length;
|
|
|
|
phrase = `${i} ${references} across ${j} ${docLabel}`;
|
2016-11-05 16:02:35 -07:00
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-11-05 16:02:35 -07:00
|
|
|
this.set('resultPhrase', phrase);
|
2017-08-15 19:41:44 +01:00
|
|
|
this.set('documents', duped);
|
2016-11-05 16:02:35 -07:00
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|