r114410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114409‎ | r114410 | r114411 >
Date:21:37, 21 March 2012
Author:foxtrott
Status:deferred
Tags:
Comment:
filtered format: printout parameter 'value filter values'
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.value-filter.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php
@@ -37,21 +37,25 @@
3838
3939 $ret = array();
4040
41 - if ( array_key_exists( 'value filter switches', $params ) ) {
 41+ if ( array_key_exists( 'value filter switches', $params ) ) {
4242 $switches = explode( ',', $params['value filter switches'] );
4343 $switches = array_map( 'trim', $switches );
4444
4545 $ret['switches'] = $switches;
4646 }
4747
48 - if ( array_key_exists( 'value filter collapsible', $params ) ) {
 48+ if ( array_key_exists( 'value filter collapsible', $params ) ) {
4949 $ret['collapsible'] = trim($params['value filter collapsible']);
5050 }
5151
52 - if ( array_key_exists( 'value filter height', $params ) ) {
 52+ if ( array_key_exists( 'value filter height', $params ) ) {
5353 $ret['height'] = trim($params['value filter height']);
5454 }
5555
 56+ if ( array_key_exists( 'value filter values', $params ) ) {
 57+ $ret['values'] = trim($params['value filter values']);
 58+ }
 59+
5660 return $ret;
5761 }
5862
Index: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.value-filter.js
@@ -21,20 +21,20 @@
2222
2323 // show all if no value is checked
2424 if ( selectedInputs.length == 0 ) {
25 - for ( i in values ) {
 25+ for ( valueId in values ) {
2626 filtered.filtered( 'voteItemVisibilityAndUpdate', {
2727 'filter': 'value',
2828 'printout' : target,
2929 'visible': true,
30 - 'item': i
 30+ 'item': valueId
3131 });
3232 }
3333
3434 } else {
3535
36 - for ( i in values ) {
 36+ for ( valueId in values ) {
3737
38 - var printoutValues = values[i]['printouts'][target]['values'];
 38+ var printoutValues = values[valueId]['printouts'][target]['values'];
3939 var useOr = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'use or'} );
4040
4141 if ( useOr ) {
@@ -70,7 +70,7 @@
7171 'filter': 'value',
7272 'printout' : target,
7373 'visible': selected,
74 - 'item': i
 74+ 'item': valueId
7575 });
7676
7777 }
@@ -85,32 +85,50 @@
8686 var switches = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'switches'} );
8787 var collapsible = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'collapsible'} );
8888 var height = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'height'} );
 89+ var fixedValues = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'values'} );
8990
90 - // find distinct values and set visibility for all items that have
91 - // some value for this printout
92 - var distinctValues = [];
93 -
94 - var i;
95 - for ( i in values ) {
96 - var printoutValues = values[i]['printouts'][target]['values'];
 91+ var valueId; // just some valid value ID
 92+ if ( fixedValues == null ) {
 93+ // build filter values from available values in result set
9794
98 - for (var j in printoutValues) {
99 - distinctValues[ printoutValues[j] ] = true;
 95+ // find distinct values and set visibility for all items that have
 96+ // some value for this printout
 97+ var distinctValues = [];
 98+
 99+ for ( valueId in values ) {
 100+ var printoutValues = values[valueId]['printouts'][target]['values'];
 101+
 102+ for (var j in printoutValues) {
 103+ distinctValues[ printoutValues[j] ] = true;
 104+ }
 105+
 106+ filtered.filtered( 'voteItemVisibility', {
 107+ 'filter': 'value',
 108+ 'printout' : target,
 109+ 'visible': true,
 110+ 'item': valueId
 111+ });
100112 }
101113
102 - filtered.filtered( 'voteItemVisibility', {
103 - 'filter': 'value',
104 - 'printout' : target,
105 - 'visible': true,
106 - 'item': i
107 - });
 114+ var sortedDistinctValues = [];
 115+
 116+ for ( var i in distinctValues ) {
 117+ sortedDistinctValues.push(i);
 118+ }
 119+
 120+ sortedDistinctValues.sort();
 121+ } else {
 122+ // use given values
 123+ sortedDistinctValues = fixedValues.split(/\s*,\s*/);
 124+
 125+ for ( valueId in values ) break; // get some valid value ID
108126 }
109127
110128 // build filter controls
111129 var filtercontrols = this.children('.filtered-filters').children('.' + target).filter('.filtered-value');
112130
113131 // insert the label of the printout this filter filters on
114 - filtercontrols.append('<div class="filtered-value-label"><span>' + values[i]['printouts'][target]['label'] + '</span></div>');
 132+ filtercontrols.append('<div class="filtered-value-label"><span>' + values[valueId]['printouts'][target]['label'] + '</span></div>');
115133
116134 if ( collapsible != null && ( collapsible == 'collapsed' || collapsible == 'uncollapsed') ) {
117135
@@ -192,14 +210,6 @@
193211 }
194212
195213
196 - var sortedDistinctValues = [];
197 -
198 - for ( var i in distinctValues ) {
199 - sortedDistinctValues.push(i);
200 - }
201 -
202 - sortedDistinctValues.sort();
203 -
204214 // insert options (checkboxes and labels) and attach event handlers
205215 // TODO: Do we need to wrap these in a form?
206216 for ( var j in sortedDistinctValues ) {

Status & tagging log