Skip to content

Commit

Permalink
use filter component name as key, re #4771
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters committed May 3, 2019
1 parent 0011ae9 commit ff6cb7d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
4 changes: 2 additions & 2 deletions arches/app/media/js/views/components/search/base-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ define([
return;
},

getFilter: function(filterName) {
return
getFilter: function(filterName, callback) {
return this.filters[filterName]();
}
});
});
57 changes: 34 additions & 23 deletions arches/app/media/js/views/components/search/map-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ define([
'views/components/widgets/map',
],
function(ko, BaseFilter, arches) {
return ko.components.register('map-filter', {
var componentName = 'map-filter';
return ko.components.register(componentName, {
viewModel: BaseFilter.extend({
initialize: function(options) {
options.name = "Map Filter";
Expand All @@ -18,7 +19,9 @@ function(ko, BaseFilter, arches) {
results: this.searchResults.results.hits.hits,
geo_aggs: this.searchResults.results.aggregations.geo_aggs.inner.buckets[0]
});
this.searchBuffer(this.searchResults.search_buffer);
if(!!this.searchResults[componentName]) {
this.searchBuffer(this.searchResults[componentName].search_buffer);
}
}, this);

this.resizeOnChange = ko.computed(function() {
Expand Down Expand Up @@ -66,19 +69,40 @@ function(ko, BaseFilter, arches) {
}
}, this);

options.filters['map-filter'](this);
var filterUpdated = ko.computed(function() {
return ko.toJS(this.filter.feature_collection());
}, this);
filterUpdated.subscribe(function() {
this.updateQuery();
}, this);

options.filters[componentName](this);
},

updateQuery: function(filterParams) {
var queryObj = this.query();
if (this.filter.feature_collection().features.length > 0) {
if (this.getFilter('term-filter').hasTag(this.type) === false) {
this.getFilter('term-filter').addTag('Map Filter Enabled', this.name, this.filter.inverted);
}
this.filter.feature_collection().features[0].properties['inverted'] = this.filter.inverted();
queryObj[componentName] = ko.toJSON(this.filter.feature_collection());
} else {
this.clear();
}
this.query(queryObj);
},

restoreState: function() {
var inverted;
var query = this.query();
if ('mapFilter' in query) {
query.mapFilter = JSON.parse(query.mapFilter);
//this.query = query.mapFilter;
if (query.mapFilter.features.length > 0) {
this.filter.feature_collection(query.mapFilter);
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
//this.query = query[componentName];
if (query[componentName].features.length > 0) {
this.filter.feature_collection(query[componentName]);
this.filter.inverted(query.features[0].properties.inverted);
this.termFilter.addTag('Map Filter Enabled', this.name, this.filter.inverted);
this.getFilter('term-filter').addTag('Map Filter Enabled', this.name, this.filter.inverted);
}
}
},
Expand All @@ -92,20 +116,7 @@ function(ko, BaseFilter, arches) {
});
}
}
this.termFilter.removeTag('Map Filter Enabled');
},

appendFilters: function(filterParams) {
if (this.filter.feature_collection().features.length > 0) {
if (this.termFilter.hasTag(this.type) === false) {
this.termFilter.addTag('Map Filter Enabled', this.name, this.filter.inverted);
}
this.filter.feature_collection().features[0].properties['inverted'] = this.filter.inverted();
filterParams.mapFilter = ko.toJSON(this.filter.feature_collection());
} else {
this.clear();
}
return this.filter.feature_collection().features.length === 0;
this.getFilter('term-filter').removeTag('Map Filter Enabled');
}
}),
template: { require: 'text!templates/views/components/search/map-filter.htm' }
Expand Down
20 changes: 10 additions & 10 deletions arches/app/media/js/views/components/search/term-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ define([
'views/components/search/base-filter',
'bindings/term-search'
], function(ko, koMapping, _, BaseFilter, termSearchComponent) {
var component_name = 'term-filter';
return ko.components.register(component_name, {
var componentName = 'term-filter';
return ko.components.register(componentName, {
viewModel: BaseFilter.extend({
initialize: function(options) {
options.name = 'Term Filter';
Expand All @@ -22,7 +22,7 @@ define([
this.updateQuery();
}, this);

options.filters[component_name](this);
options.filters[componentName](this);

this.restoreState();
},
Expand All @@ -34,22 +34,22 @@ define([

var queryObj = this.query();
if (terms.length > 0){
queryObj[component_name] = ko.toJSON(terms);
queryObj[componentName] = ko.toJSON(terms);
} else {
delete queryObj[component_name];
delete queryObj[componentName];
}
this.query(queryObj);
},

restoreState: function() {
var query = this.query();
if (component_name in query) {
query[component_name] = JSON.parse(query[component_name]);
if (query[component_name].length > 0) {
query[component_name].forEach(function(term){
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
if (query[componentName].length > 0) {
query[componentName].forEach(function(term){
term.inverted = ko.observable(term.inverted);
});
this.filter.terms(query[component_name]);
this.filter.terms(query[componentName]);
}
}
},
Expand Down

0 comments on commit ff6cb7d

Please sign in to comment.