From: Moriel Schottlender Date: Sat, 13 May 2017 18:21:14 +0000 (-0700) Subject: RCFilters: Always put highlight values in the URL X-Git-Tag: 1.31.0-rc.0~3252^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=e37ebca63103edc85b3105bc14bc031e19261cf1;p=lhc%2Fweb%2Fwiklou.git RCFilters: Always put highlight values in the URL Up until now, we only populated highlights in the URL if the item had a highlight, otherwise it was not in the url at all. However, now that the system can load defaults from saved queries that can have highlights themselves, then every time we reload the page (and the system checks to get defaults merged with the URL query) nothing actively overrides the default highlight value if it exists. This meant that if you have a saved query default with any highlights in it, every time you load the page from the URL it will **also add** the default highlights that you have saved. To prevent this, the URL now needs to always populate items with highlight value, even if that value is null. When we literally ask for defaults or when we actively load a saved query, that value will be overridden, but if we have a URL with highlights enabled at all, the defaults will not override and add a redundany unneeded highlight just because it existed in your saved query. Bug: T165231 Change-Id: Ia43b5c777c0b4e238e99818696a3a60dda0daca9 --- diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index 81b9dc36c9..4a9e780660 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -179,7 +179,8 @@ highlightedItems[ item.getName() ] = highlightEnabled ? item.getHighlightColor() : null; } ); - highlightedItems.highlight = this.filtersModel.isHighlightEnabled(); + // Stored as a string '0' or '1' + highlightedItems.highlight = String( Number( this.filtersModel.isHighlightEnabled() ) ); // Add item this.savedQueriesModel.addNewQuery( @@ -576,11 +577,15 @@ // highlight params uri.query.highlight = Number( this.filtersModel.isHighlightEnabled() ); Object.keys( highlightParams ).forEach( function ( paramName ) { - if ( highlightParams[ paramName ] ) { - uri.query[ paramName ] = highlightParams[ paramName ]; - } else { - delete uri.query[ paramName ]; - } + // Always have some value (either the color or null) so that + // if we have something in the URL that doesn't have the highlight + // intentionally, it can override default with highlight. + // Otherwise, the $.extend will always add the highlight that + // exists in the default even if the URL query that is being + // refreshed has different highlights, or has highlights enabled + // but no active highlights anywhere + uri.query[ paramName ] = highlightParams[ paramName ] ? + highlightParams[ paramName ] : null; } ); return uri;