Skip to content

Commit

Permalink
Add init options to CatalogSearchView
Browse files Browse the repository at this point in the history
Relates to #2069
  • Loading branch information
robyngit committed Mar 30, 2023
1 parent 2898796 commit d7e2557
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/js/models/connectors/Map-Search-Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ define([

/**
* Initialize the model.
* @param {Object} attrs - The attributes for this model.
* @param {Object} options - The options for this model.
* @param {Map | Object} [options.map] - The Map model to use for this
* connector or a JSON object with options to create a new Map model. If
Expand All @@ -64,11 +65,11 @@ define([
* FilterGroup models. If a single FilterGroup is passed, it will be
* wrapped in an array. If not provided, the default from the appModel
* will be used. See {@link AppModel#defaultFilterGroups}.
* @param {boolean} [addGeohashLayer=true] - If set to true, a Geohash
* @param {boolean} [options.addGeohashLayer=true] - If set to true, a Geohash
* layer will be added to the Map model if one is not already present. If
* set to false, no Geohash layer will be added. A geohash layer is
* required for the Search-Map connector to work.
* @param {boolean} [addSpatialFilter=true] - If set to true, a spatial
* @param {boolean} [options.addSpatialFilter=true] - If set to true, a spatial
* filter will be added to the Filters model if one is not already
* present. If set to false, no spatial filter will be added. A spatial
* filter is required for the Filters-Map connector to work.
Expand All @@ -80,7 +81,6 @@ define([
* results to un-obsoleted metadata.
*/
initialize: function (attrs, options = {}) {
// TODO: allow setting these with args here
if (!options) options = {};
const app = MetacatUI.appModel;
const map = options.map || app.get("catalogSearchMapOptions");
Expand Down Expand Up @@ -133,7 +133,6 @@ define([
setFilters: function (filtersArray, catalogSearch = true) {
const filterGroups = [];
const filters = new Filters(null, { catalogSearch: catalogSearch });
// TODO: catalogSearch should be an option set in initialize

filtersArray = Array.isArray(filtersArray)
? filtersArray
Expand Down
47 changes: 31 additions & 16 deletions src/js/views/search/CatalogSearchView.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,41 @@ define([
},

/**
* Initializes the view
* @param {Object} options
* @param {string} options.initialQuery - The initial text query to run
* Initialize the view. In addition to the options described below, any
* option that is available in the
* {@link MapSearchFiltersConnector#initialize} method can be passed to
* this view, such as Map, SolrResult, and FilterGroup models, and whether
* to create a geohash layer or spatial filter if they are not present.
* @param {Object} options - The options for this view.
* @param {string} [options.initialQuery] - The initial text query to run
* when the view is rendered.
* @param {MapSearchFiltersConnector} [options.model] - A
* MapSearchFiltersConnector model to use for this view. If not provided,
* a new one will be created. If one is provided, then other options that
* would be passed to the MapSearchFiltersConnector model will be ignored
* (such as map, searchResults, filterGroups, catalogSearch, etc.)
* @since x.x.x
*/
initialize: function (options) {
this.initialQuery = options?.initialQuery;
// TODO: allow for initial models/filters to be passed in, as well as
// options like, whether or not to create a SpatialFilter or Geohash
// layer if not present, etc.

// const mapOptions = Object.assign(
// {},
// MetacatUI.appModel.get("catalogSearchMapOptions") || {}
// );
// Create the Map model and view

this.model = new MapSearchFiltersConnector();
this.model.connect();
if (!options) options = {};

this.initialQuery = options.initialQuery || null;

let model = options.model;
if (!model) {
const app = MetacatUI.appModel;
model = new MapSearchFiltersConnector({
map: options.map || app.get("catalogSearchMapOptions"),
searchResults: options.searchResults || null,
filterGroups:
options.filterGroups || app.get("defaultFilterGroups"),
catalogSearch: options.catalogSearch !== false,
addGeohashLayer: options.addGeohashLayer !== false,
addSpatialFilter: options.addSpatialFilter !== false,
});
}
model.connect();
this.model = model;
},

/**
Expand Down

0 comments on commit d7e2557

Please sign in to comment.