Merge "RCFilters: Add 'enhanced' view (Group by pages)"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.Controller.js
index d558e46..f07d3f1 100644 (file)
@@ -33,6 +33,7 @@
         */
        mw.rcfilters.Controller.prototype.initialize = function ( filterStructure, namespaceStructure, tagList ) {
                var parsedSavedQueries, limitDefault,
+                       displayConfig = mw.config.get( 'StructuredChangeFiltersDisplayConfig' ),
                        controller = this,
                        views = {},
                        items = [],
                                        hidden: true,
                                        allowArbitrary: true,
                                        validate: $.isNumeric,
+                                       range: {
+                                               min: 1,
+                                               max: 1000
+                                       },
                                        sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); },
                                        'default': String( limitDefault ),
-                                       isSticky: true,
-                                       filters: [ 50, 100, 250, 500 ].map( function ( num ) {
+                                       // Temporarily making this not sticky until we resolve the problem
+                                       // with the misleading preference. Note that if this is to be permanent
+                                       // we should remove all sticky behavior methods completely
+                                       // See T172156
+                                       // isSticky: true,
+                                       filters: displayConfig.arrayLimit.map( function ( num ) {
                                                return controller._createFilterDataFromNumber( num, num );
                                        } )
                                },
                                        hidden: true,
                                        allowArbitrary: true,
                                        validate: $.isNumeric,
+                                       range: {
+                                               min: 0,
+                                               max: displayConfig.maxLimit
+                                       },
                                        sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); },
                                        numToLabelFunc: function ( i ) {
                                                return Number( i ) < 1 ?
                                                        Number( i );
                                        },
                                        'default': mw.user.options.get( 'rcdays', '30' ),
-                                       isSticky: true,
+                                       // Temporarily making this not sticky while limit is not sticky, see above
+                                       // isSticky: true,
                                        filters: [
                                                // Hours (1, 2, 6, 12)
-                                               0.04166, 0.0833, 0.25, 0.5,
-                                               // Days
-                                               1, 3, 7, 14, 30
-                                       ].map( function ( num ) {
-                                               return controller._createFilterDataFromNumber(
-                                                       num,
-                                                       // Convert fractions of days to number of hours for the labels
-                                                       num < 1 ? Math.round( num * 24 ) : num
-                                               );
-                                       } )
+                                               0.04166, 0.0833, 0.25, 0.5
+                                       // Days
+                                       ].concat( displayConfig.arrayDays )
+                                               .map( function ( num ) {
+                                                       return controller._createFilterDataFromNumber(
+                                                               num,
+                                                               // Convert fractions of days to number of hours for the labels
+                                                               num < 1 ? Math.round( num * 24 ) : num
+                                                       );
+                                               } )
                                }
                        ]
                };
 
                arbitraryValues = Array.isArray( arbitraryValues ) ? arbitraryValues : [ arbitraryValues ];
 
+               // Normalize the arbitrary values
+               if ( groupData.range ) {
+                       arbitraryValues = arbitraryValues.map( function ( val ) {
+                               if ( val < 0 ) {
+                                       return groupData.range.min; // Min
+                               } else if ( val >= groupData.range.max ) {
+                                       return groupData.range.max; // Max
+                               }
+                               return val;
+                       } );
+               }
+
                // This is only true for single_option group
                // We assume these are the only groups that will allow for
                // arbitrary, since it doesn't make any sense for the other
                                // but if that value isn't already in the definition
                                groupData.filters
                                        .map( function ( filterData ) {
-                                               return filterData.name;
+                                               return String( filterData.name );
                                        } )
-                                       .indexOf( val ) === -1
+                                       .indexOf( String( val ) ) === -1
                        ) {
                                // Add the filter information
                                groupData.filters.push( controller._createFilterDataFromNumber(
         */
        mw.rcfilters.Controller.prototype.toggleInvertedNamespaces = function () {
                this.filtersModel.toggleInvertedNamespaces();
-               this.updateChangesList();
+
+               if (
+                       this.filtersModel.getFiltersByView( 'namespaces' )
+                               .filter( function ( filterItem ) {
+                                       return filterItem.isSelected();
+                               } )
+                               .length
+               ) {
+                       // Only re-fetch results if there are namespace items that are actually selected
+                       this.updateChangesList();
+               }
        };
 
        /**
         */
        mw.rcfilters.Controller.prototype.applySavedQuery = function ( queryID ) {
                var data, highlights,
-                       queryItem = this.savedQueriesModel.getItemByID( queryID );
+                       queryItem = this.savedQueriesModel.getItemByID( queryID ),
+                       currentMatchingQuery = this.findQueryMatchingCurrentState();
 
-               if ( queryItem ) {
+               if (
+                       queryItem &&
+                       (
+                               // If there's already a query, don't reload it
+                               // if it's the same as the one that already exists
+                               !currentMatchingQuery ||
+                               currentMatchingQuery.getID() !== queryItem.getID()
+                       )
+               ) {
                        data = queryItem.getData();
                        highlights = data.highlights;
 
        /**
         * Update the limit default value
         *
-        * @param {number} newValue New value
+        * param {number} newValue New value
         */
-       mw.rcfilters.Controller.prototype.updateLimitDefault = function ( newValue ) {
+       mw.rcfilters.Controller.prototype.updateLimitDefault = function ( /* newValue */ ) {
+               // HACK: Temporarily remove this from being sticky
+               // See T172156
+
+               /*
                if ( !$.isNumeric( newValue ) ) {
                        return;
                }
                        // Update the preference for this session
                        mw.user.options.set( 'rcfilters-rclimit', newValue );
                }
+               */
+               return;
        };
 
        /**
         * Update the days default value
         *
-        * @param {number} newValue New value
+        * param {number} newValue New value
         */
-       mw.rcfilters.Controller.prototype.updateDaysDefault = function ( newValue ) {
+       mw.rcfilters.Controller.prototype.updateDaysDefault = function ( /* newValue */ ) {
+               // HACK: Temporarily remove this from being sticky
+               // See T172156
+
+               /*
                if ( !$.isNumeric( newValue ) ) {
                        return;
                }
                        // Update the preference for this session
                        mw.user.options.set( 'rcdays', newValue );
                }
+               */
+               return;
        };
 
        /**