Skip to content

Commit

Permalink
fixup code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice Rottersman committed Sep 15, 2017
1 parent 86d9c8c commit e979ba5
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions src/mmw/js/src/data_catalog/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var FilterModel = Backbone.Model.extend({
},

validate: function() {
_.noop();
return true;
},

isActive: function() {
Expand All @@ -34,36 +34,30 @@ var FilterModel = Backbone.Model.extend({
});

var SearchOption = FilterModel.extend({
defaults: function() {
return _.extend(FilterModel.prototype.defaults, {
active: false
});
},
defaults: _.defaults({
active: false,
}, FilterModel.prototype.defaults),

isActive: function() {
return this.get('active');
}
});

var GriddedServicesFilter = SearchOption.extend({
defaults: function() {
return _.extend(SearchOption.prototype.defaults(), {
id: 'gridded',
type: 'checkbox',
label: 'Gridded Services',
});
},
defaults: _.defaults({
id: 'gridded',
type: 'checkbox',
label: 'Gridded Services',
}, SearchOption.prototype.defaults)
});

var DateFilter = FilterModel.extend({
defaults: function() {
return _.extend(FilterModel.prototype.defaults, {
id: 'date',
type: 'date',
fromDate: null,
toDate: null,
});
},
defaults: _.defaults({
id: 'date',
type: 'date',
fromDate: null,
toDate: null,
}, FilterModel.prototype.defaults),

isActive: function() {
return this.get('fromDate') || this.get('toDate');
Expand Down Expand Up @@ -99,11 +93,9 @@ var FilterCollection = Backbone.Collection.extend({
model: FilterModel,

countActive: function() {
var incrementIfActive = function(count, filter) {
return filter.isActive() ? ++count : count;
};
var isActive = function(filter) { return filter.isActive(); };

return this.reduce(incrementIfActive, 0);
return this.filter(isActive).length;
},
});

Expand Down Expand Up @@ -176,15 +168,10 @@ var Catalog = Backbone.Model.extend({

isSearchValid: function() {
var query = this.get('query'),
dateFilter = this.get('filters').findWhere({ id: 'date'}),
dateFilterValid = true;

if (dateFilter) {
dateFilter.validate();
dateFilterValid = dateFilter.get('isValid');
}
validate = function(filter) { return filter.validate(); },
valid = this.get('filters').map(validate);

return query && dateFilterValid;
return query && _.every(valid);
},

startSearch: function(page) {
Expand Down

0 comments on commit e979ba5

Please sign in to comment.