- /**
- * Get an object representing the base state of parameters
- * and highlights.
- *
- * This is meant to make sure that the saved queries that are
- * in memory are always the same structure as what we would get
- * by calling the current model's "getSelectedState" and by checking
- * highlight items.
- *
- * In cases where a user saved a query when the system had a certain
- * set of filters, and then a filter was added to the system, we want
- * to make sure that the stored queries can still be comparable to
- * the current state, which means that we need the base state for
- * two operations:
- *
- * - Saved queries are stored in "minimal" view (only changed filters
- * are stored); When we initialize the system, we merge each minimal
- * query with the base state (using 'getNormalizedFilters') so all
- * saved queries have the exact same structure as what we would get
- * by checking the getSelectedState of the filter.
- * - When we save the queries, we minimize the object to only represent
- * whatever has actually changed, rather than store the entire
- * object. To check what actually is different so we can store it,
- * we need to obtain a base state to compare against, this is
- * what #_getMinimalFilterList does
- */
- mw.rcfilters.Controller.prototype._buildBaseFilterState = function () {
- var defaultParams = this.filtersModel.getDefaultParams(),
- highlightedItems = {};
-
- // Prepare highlights
- this.filtersModel.getItemsSupportingHighlights().forEach( function ( item ) {
- highlightedItems[ item.getName() ] = null;
- } );
- highlightedItems.highlight = false;
-
- this.baseFilterState = {
- filters: this.filtersModel.getFiltersFromParameters( defaultParams ),
- highlights: highlightedItems,
- invert: false
- };
- };
-
- /**
- * Get an object representing the base filter state of both
- * filters and highlights. The structure is similar to what we use
- * to store each query in the saved queries object:
- * {
- * filters: {
- * filterName: (bool)
- * },
- * highlights: {
- * filterName: (string|null)
- * }
- * }
- *
- * @return {Object} Object representing the base state of
- * parameters and highlights
- */
- mw.rcfilters.Controller.prototype._getBaseFilterState = function () {
- return this.baseFilterState;
- };
-
- /**
- * Get an object that holds only the parameters and highlights that have
- * values different than the base default value.
- *
- * This is the reverse of the normalization we do initially on loading and
- * initializing the saved queries model.
- *
- * @param {Object} valuesObject Object representing the state of both
- * filters and highlights in its normalized version, to be minimized.
- * @return {Object} Minimal filters and highlights list
- */
- mw.rcfilters.Controller.prototype._getMinimalFilterList = function ( valuesObject ) {
- var result = { filters: {}, highlights: {}, invert: valuesObject.invert },
- baseState = this._getBaseFilterState();
-
- // XOR results
- $.each( valuesObject.filters, function ( name, value ) {
- if ( baseState.filters !== undefined && baseState.filters[ name ] !== value ) {
- result.filters[ name ] = value;
- }
- } );
-
- $.each( valuesObject.highlights, function ( name, value ) {
- if ( baseState.highlights !== undefined && baseState.highlights[ name ] !== value ) {
- result.highlights[ name ] = value;
- }
- } );
-
- return result;
- };
-