1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import _ from 'underscore';
import Backbone from 'backbone';
import CustomMeasure from './custom-measure';
export default Backbone.Collection.extend({
model: CustomMeasure,
initialize: function (options) {
this.projectId = options.projectId;
},
url: function () {
return baseUrl + '/api/custom_measures/search';
},
parse: function (r) {
this.total = r.total;
this.p = r.p;
this.ps = r.ps;
return r.customMeasures;
},
fetch: function (options) {
var opts = _.defaults(options || {}, { data: {} });
this.q = opts.data.q;
opts.data.projectId = this.projectId;
return Backbone.Collection.prototype.fetch.call(this, opts);
},
fetchMore: function () {
var p = this.p + 1;
return this.fetch({ add: true, remove: false, data: { p: p, ps: this.ps, q: this.q } });
},
refresh: function () {
return this.fetch({ reset: true, data: { q: this.q } });
},
hasMore: function () {
return this.total > this.p * this.ps;
},
getTakenMetrics: function () {
var metrics = this.map(function (model) {
return model.get('metric').id;
});
return _.uniq(metrics);
}
});
|