Skip to content

Commit

Permalink
fix issue with restoring search component state, and restoring state …
Browse files Browse the repository at this point in the history
…before adding listeners, re #4771
  • Loading branch information
apeters committed Jun 10, 2019
1 parent 2ef9611 commit 8cd53a1
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 59 deletions.
23 changes: 11 additions & 12 deletions arches/app/media/js/views/components/search/advanced-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ define([
this.searchableGraphs = ko.observableArray();
this.datatypelookup = {};
this.facetFilterText = ko.observable('');
this.filter = {
facets: ko.observableArray()
};

$.ajax({
type: "GET",
Expand Down Expand Up @@ -61,21 +64,17 @@ define([
}
}
}, this);
});
this.restoreState();

this.filter = {
facets: ko.observableArray()
};

var filterUpdated = ko.computed(function() {
return JSON.stringify(ko.toJS(this.filter.facets()));
}, this);
filterUpdated.subscribe(function() {
this.updateQuery();
}, this);
var filterUpdated = ko.computed(function() {
return JSON.stringify(ko.toJS(this.filter.facets()));
}, this);
filterUpdated.subscribe(function() {
this.updateQuery();
}, this);
});

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

updateQuery: function() {
Expand Down
14 changes: 7 additions & 7 deletions arches/app/media/js/views/components/search/map-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ function(_, ko, BaseFilter, arches) {
}
}, this);

this.filters[componentName](this);
this.restoreState();

var filterUpdated = ko.computed(function() {
return JSON.stringify(ko.toJS(this.filter.feature_collection())) + this.filter.inverted();
}, this);
filterUpdated.subscribe(function() {
this.updateQuery();
}, this);

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

updateQuery: function(filterParams) {
Expand All @@ -94,11 +94,11 @@ function(_, ko, BaseFilter, arches) {
restoreState: function() {
var query = this.query();
if (componentName in query) {
query = JSON.parse(query[componentName]);
if (query.features.length > 0) {
this.filter.inverted(query.features[0].properties.inverted);
var mapQuery = JSON.parse(query[componentName]);
if (mapQuery.features.length > 0) {
this.filter.inverted(mapQuery.features[0].properties.inverted);
this.getFilter('term-filter').addTag('Map Filter Enabled', this.name, this.filter.inverted);
this.filter.feature_collection(query);
this.filter.feature_collection(mapQuery);
}
}
this.updateResults();
Expand Down
19 changes: 8 additions & 11 deletions arches/app/media/js/views/components/search/provisional-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ define([
this.filter = ko.observableArray();
this.provisionalOptions = [{'name': 'Authoritative'},{'name': 'Provisional'}];

var filterChanged = ko.computed(function() {
return JSON.stringify(ko.toJS(this.filter));
}, this);
this.restoreState();

filterChanged.subscribe(function() {
this.filter.subscribe(function() {
this.updateQuery();
}, this);

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

updateQuery: function() {
Expand All @@ -34,15 +31,15 @@ define([
},

restoreState: function() {
var query = this.query;
var query = this.query();
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
if (query[componentName].length > 0) {
query[componentName].forEach(function(type){
var provisionalQuery = JSON.parse(query[componentName]);
if (provisionalQuery.length > 0) {
provisionalQuery.forEach(function(type){
type.inverted = ko.observable(!!type.inverted);
this.getFilter('term-filter').addTag(type.provisionaltype, this.provisionaltype, type.inverted);
this.getFilter('term-filter').addTag(type.provisionaltype, this.name, type.inverted);
}, this);
this.filter(query[componentName]);
this.filter(provisionalQuery);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ define([
},

restoreState: function() {
var doQuery = false;
var query = this.query();
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
if (query[componentName].length > 0) {
query[componentName].forEach(function(type){
var resourceTypeQuery = JSON.parse(query[componentName]);
if (resourceTypeQuery.length > 0) {
resourceTypeQuery.forEach(function(type){
type.inverted = ko.observable(!!type.inverted);
this.getFilter('term-filter').addTag(type.name, this.name, type.inverted);
}, this);
this.filter(query[componentName]);
this.filter(resourceTypeQuery);
}
}
return doQuery;
},

clear: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function($, _, BaseFilter, bootstrap, arches, select2, ko, koMapping, viewdata)
this.mouseoverInstanceId = ko.observable();
this.relationshipCandidates = ko.observableArray();
this.selectedResourceId = ko.observable(null);
this.userIsReviewer = ko.observable(false);

this.showRelationships.subscribe(function(res) {
this.selectedResourceId(res.resourceinstanceid);
Expand Down Expand Up @@ -79,7 +80,7 @@ function($, _, BaseFilter, bootstrap, arches, select2, ko, koMapping, viewdata)
this.total(this.searchResults.results.hits.total);
this.results.removeAll();
this.selectedResourceId(null);
this.userIsReviewer = this.searchResults.reviewer;
this.userIsReviewer(this.searchResults.reviewer);
this.searchResults.results.hits.hits.forEach(function(result){
var graphdata = _.find(viewdata.graphs, function(graphdata){
return result._source.graph_id === graphdata.graphid;
Expand Down
8 changes: 4 additions & 4 deletions arches/app/media/js/views/components/search/term-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ define([
restoreState: function() {
var query = this.query();
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
if (query[componentName].length > 0) {
query[componentName].forEach(function(term){
var termQuery = JSON.parse(query[componentName]);
if (termQuery.length > 0) {
termQuery.forEach(function(term){
term.inverted = ko.observable(term.inverted);
});
this.filter.terms(query[componentName]);
this.filter.terms(termQuery);
}
}
},
Expand Down
36 changes: 19 additions & 17 deletions arches/app/media/js/views/components/search/time-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function($, _, ko, moment, BaseFilter, arches) {
viewModel: BaseFilter.extend({
initialize: function(options) {
options.name = 'Time Filter';
this.dateDropdownEleId = 'dateDropdownEleId' + _.random(2000, 3000000);
BaseFilter.prototype.initialize.call(this, options);
this.filter = {
fromDate: ko.observable(null),
Expand Down Expand Up @@ -91,29 +92,30 @@ function($, _, ko, moment, BaseFilter, arches) {
this.filter.fromDate(from);
}, this);


$.ajax({
type: "GET",
url: arches.urls.api_search_component_data + componentName,
context: this
}).done(function(response) {
this.date_nodes(response.date_nodes);
this.graph_models(response.graph_models);
$("select[data-bind^=chosen]").trigger("chosen:updated");
});

this.filterChanged = ko.computed(function(){
if(!!this.filter.fromDate() || !!this.filter.toDate()){
this.getFilter('term-filter').addTag(this.name, this.name, this.filter.inverted);
}
return ko.toJSON(this.filter);
}, this).extend({ deferred: true });
this.restoreState();
$("#" + this.dateDropdownEleId).trigger("chosen:updated");
this.filterChanged = ko.computed(function(){
if(!!this.filter.fromDate() || !!this.filter.toDate()){
this.getFilter('term-filter').addTag(this.name, this.name, this.filter.inverted);
}
return ko.toJSON(this.filter);
}, this).extend({ deferred: true });

this.filterChanged.subscribe(function() {
this.updateQuery();
}, this);
this.filterChanged.subscribe(function() {
this.updateQuery();
}, this);
});

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

updateQuery: function() {
Expand Down Expand Up @@ -144,12 +146,12 @@ function($, _, ko, moment, BaseFilter, arches) {
restoreState: function() {
var query = this.query();
if (componentName in query) {
query[componentName] = JSON.parse(query[componentName]);
this.filter.inverted(!!query[componentName].inverted);
var timeQuery = JSON.parse(query[componentName]);
this.filter.inverted(!!timeQuery.inverted);
this.getFilter('term-filter').addTag(this.name, this.name, this.filter.inverted);
['fromDate', 'toDate', 'dateNodeId'].forEach(function(key) {
if (key in query[componentName]) {
this.filter[key](query[componentName][key]);
if (key in timeQuery) {
this.filter[key](timeQuery[key]);
}
}, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h3 class="search-title" data-bind="visible: showWheel()">{% trans "Time Wheel"
<!-- Date Type -->
<div class="calendar">
<h3 class="search-label">{% trans "Type" %}</h3>
<select class="resources" data-placeholder="Date type" tabindex="-1" data-bind="value: filter.dateNodeId, chosen:{ width: '100%' }">
<select id="" class="resources" data-placeholder="Date type" tabindex="-1" data-bind="value: filter.dateNodeId, chosen:{ width: '100%' }, attr: {id:dateDropdownEleId} ">
<option value="">{% trans "Search all dates" %}</option>
<!-- ko foreach: { data: graph_models, as: 'graph' } -->
<optgroup data-bind="if: (graph.isresource && graph.isactive), attr: { label: graph.name }">
Expand Down

0 comments on commit 8cd53a1

Please sign in to comment.