Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php |
— | — | @@ -98,6 +98,7 @@ |
99 | 99 | $wgAutoloadClasses['SRFD3Bar'] = $formatDir . 'D3/SRF_D3Bar.php'; |
100 | 100 | $wgAutoloadClasses['SRFD3Treemap'] = $formatDir . 'D3/SRF_D3Treemap.php'; |
101 | 101 | $wgAutoloadClasses['SRFTree'] = $formatDir . 'Tree/SRF_Tree.php'; |
| 102 | +$wgAutoloadClasses['SRFFiltered'] = $formatDir . 'Filtered/SRF_Filtered.php'; |
102 | 103 | |
103 | 104 | unset( $formatDir ); |
104 | 105 | |
— | — | @@ -149,6 +150,7 @@ |
150 | 151 | 'tree' => 'SRFTree', |
151 | 152 | 'ultree' => 'SRFTree', |
152 | 153 | 'oltree' => 'SRFTree', |
| 154 | + 'filtered' => 'SRFFiltered', |
153 | 155 | ); |
154 | 156 | |
155 | 157 | $formatAliases = array( |
Index: trunk/extensions/SemanticResultFormats/Filtered/skins/ext.srf.filtered.value-filter.css |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +/* |
| 3 | + Stylesheet for the value filter |
| 4 | +*/ |
| 5 | + |
| 6 | +.filtered-filters .filtered-value { |
| 7 | + overflow: visible; |
| 8 | + border: 1px solid #aaa; |
| 9 | + padding: 1em; |
| 10 | + margin: 1em; |
| 11 | +} |
| 12 | + |
| 13 | +.filtered-filters .filtered-value .filtered-value-label { |
| 14 | + height: 0; |
| 15 | +} |
| 16 | + |
| 17 | +.filtered-filters .filtered-value .filtered-value-label span { |
| 18 | + background-color: white; |
| 19 | + font-weight: bold; |
| 20 | + |
| 21 | + position: relative; |
| 22 | + top: -1.8em; |
| 23 | + left: 0; |
| 24 | + |
| 25 | + padding: 0 1em; |
| 26 | +} |
| 27 | + |
| 28 | +.filtered-filters .filtered-value .filtered-value-switches { |
| 29 | + border-bottom: 1px solid #aaa; |
| 30 | + font-weight: bold; |
| 31 | + padding: 0.5em 1em; |
| 32 | + |
| 33 | + margin-bottom: 1em; |
| 34 | +} |
| 35 | + |
| 36 | +.filtered-filters .filtered-value .filtered-value-option { |
| 37 | + display: inline-block; |
| 38 | + padding: 0 1em; |
| 39 | + width: 20%; |
| 40 | +} |
| 41 | + |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/skins/ext.srf.filtered.value-filter.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/skins/ext.srf.filtered.css |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +/* |
| 3 | + Main stylesheet for the filtered query printer |
| 4 | +*/ |
| 5 | + |
| 6 | + |
| 7 | +.filtered { |
| 8 | + height: 100%; |
| 9 | +} |
| 10 | + |
| 11 | +.filtered-filters { |
| 12 | + height: 40%; |
| 13 | + overflow: auto; |
| 14 | + border: 1px solid #aaa; |
| 15 | + margin: 1em; |
| 16 | + position: relative; |
| 17 | + top: 0; |
| 18 | + left: 0; |
| 19 | +} |
| 20 | + |
| 21 | +.filtered-views { |
| 22 | + height: 60%; |
| 23 | + overflow: auto; |
| 24 | + border: 1px solid #aaa; |
| 25 | + padding: 1em; |
| 26 | + margin: 1em; |
| 27 | +} |
| 28 | + |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/skins/ext.srf.filtered.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRF_Filtered_Filter class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * The SRF_Filtered_Filter class. |
| 14 | + * |
| 15 | + * @ingroup SemanticResultFormats |
| 16 | + */ |
| 17 | +abstract class SRF_Filtered_Filter { |
| 18 | + |
| 19 | + private $mResults = null; |
| 20 | + private $mPrintRequest = null; |
| 21 | + private $mQueryPrinter = null; |
| 22 | + |
| 23 | + public function __construct( &$results, SMWPrintRequest $printRequest, SRFFiltered &$queryPrinter ) { |
| 24 | + $this->mResults = $results; |
| 25 | + $this->mPrintRequest = $printRequest; |
| 26 | + $this->mQueryPrinter = $queryPrinter; |
| 27 | + } |
| 28 | + |
| 29 | + public function &getQueryResults() {return $this->mResults;} |
| 30 | + public function &getPrintRequest() {return $this->mPrintRequest;} |
| 31 | + public function &getQueryPrinter() {return $this->mQueryPrinter;} |
| 32 | + |
| 33 | + |
| 34 | + public function getActualParameters() { |
| 35 | + |
| 36 | + return $this->mPrintRequest->getParameters(); |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns the name (string) or names (array of strings) of the resource |
| 42 | + * modules to load. |
| 43 | + * |
| 44 | + * @return string|array |
| 45 | + */ |
| 46 | + public function getResourceModules() { |
| 47 | + return null; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the HTML text that is to be included for this filter. |
| 52 | + * |
| 53 | + * This text will appear on the page in a div that has the filter's id set |
| 54 | + * as class. |
| 55 | + * |
| 56 | + * @return string |
| 57 | + */ |
| 58 | + public function getResultText() { |
| 59 | + return ''; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns an array of config data for this filter to be stored in the JS |
| 64 | + * @return null |
| 65 | + */ |
| 66 | + public function getJsData() { |
| 67 | + return null; |
| 68 | + } |
| 69 | + |
| 70 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 71 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php |
— | — | @@ -0,0 +1,60 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRF_FF_Value class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * The SRF_FF_Value class. |
| 14 | + * |
| 15 | + * Available parameters for this filter: |
| 16 | + * value filter switches: switches to be shown for this filter; currently only 'and or' supported |
| 17 | + * |
| 18 | + * @ingroup SemanticResultFormats |
| 19 | + */ |
| 20 | +class SRF_FF_Value extends SRF_Filtered_Filter { |
| 21 | + |
| 22 | + /** |
| 23 | + * Returns the HTML text that is to be included for this view. |
| 24 | + * |
| 25 | + * This text will appear on the page in a div that has the view's id set as |
| 26 | + * class. |
| 27 | + * |
| 28 | + * @return string |
| 29 | + */ |
| 30 | + public function getResultText() { |
| 31 | + return ''; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Returns the name (string) or names (array of strings) of the resource |
| 36 | + * modules to load. |
| 37 | + * |
| 38 | + * @return string|array |
| 39 | + */ |
| 40 | + public function getResourceModules() { |
| 41 | + return 'ext.srf.filtered.value-filter'; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns an array of config data for this filter to be stored in the JS |
| 46 | + * @return null |
| 47 | + */ |
| 48 | + public function getJsData() { |
| 49 | + $params = $this->getActualParameters(); |
| 50 | + |
| 51 | + if ( array_key_exists( 'value filter switches', $params ) ) { |
| 52 | + $switches = explode(',', $params['value filter switches'] ); |
| 53 | + $switches = array_map('trim', $switches ); |
| 54 | + |
| 55 | + return array( 'switches' => $switches ); |
| 56 | + } |
| 57 | + |
| 58 | + return null; |
| 59 | + } |
| 60 | + |
| 61 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 62 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.value-filter.js |
— | — | @@ -0,0 +1,182 @@ |
| 2 | +/** |
| 3 | + * File holding the value-filter plugin |
| 4 | + * |
| 5 | + * For this plugin to work, the filtered plugin needs to be available first. |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +(function ($) { |
| 13 | + |
| 14 | + var methods = { |
| 15 | + |
| 16 | + init: function( args ){ |
| 17 | + |
| 18 | + function update( filtered, filtercontrols, target ) { |
| 19 | + |
| 20 | + var values = filtered.data('ext.srf.filtered')['values']; |
| 21 | + var selectedInputs = filtercontrols.children('div.filtered-value-option').children('input:checked'); |
| 22 | + |
| 23 | + for ( i in values ) { |
| 24 | + |
| 25 | + var printoutValues = values[i]['printouts'][target]['values']; |
| 26 | + var useOr = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'use or'} ); |
| 27 | + |
| 28 | + if ( useOr ) { |
| 29 | + var selected = false; |
| 30 | + |
| 31 | + for ( var j in printoutValues ) { |
| 32 | + |
| 33 | + selectedInputs.each(function(){ |
| 34 | + selected = selected || ( printoutValues[j] == $(this).attr('value') ); |
| 35 | + }); |
| 36 | + } |
| 37 | + } else { |
| 38 | + var selected = true; |
| 39 | + |
| 40 | + for ( var j in printoutValues ) { |
| 41 | + |
| 42 | + selectedInputs.each(function(){ |
| 43 | + selected = selected && ( printoutValues[j] == $(this).attr('value') ); |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + filtered.filtered( 'voteItemVisibilityAndUpdate', { |
| 49 | + 'filter': 'value', |
| 50 | + 'printout' : target, |
| 51 | + 'visible': selected, |
| 52 | + 'item': i |
| 53 | + }); |
| 54 | + |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + var filtered = this; |
| 59 | + |
| 60 | + var values = this.data('ext.srf.filtered')['values']; |
| 61 | + var target = args.printout; |
| 62 | + var switches = filtered.filtered( 'getFilterData', {filter: 'value', printout: target, configvar: 'switches'} ); |
| 63 | + |
| 64 | + // find distinct values and set visibility for all items that have |
| 65 | + // some value for this printout |
| 66 | + var distinctValues = []; |
| 67 | + |
| 68 | + var i; |
| 69 | + for ( i in values ) { |
| 70 | + var printoutValues = values[i]['printouts'][target]['values']; |
| 71 | + |
| 72 | + for (var j in printoutValues) { |
| 73 | + distinctValues[ printoutValues[j] ] = true; |
| 74 | + } |
| 75 | + |
| 76 | + filtered.filtered( 'voteItemVisibility', { |
| 77 | + 'filter': 'value', |
| 78 | + 'printout' : target, |
| 79 | + 'visible': printoutValues.length > 0, |
| 80 | + 'item': i |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + // build filter controls |
| 85 | + var filtercontrols = this.children('.filtered-filters').children('.' + target).filter('.filtered-value'); |
| 86 | + |
| 87 | + // insert the label of the printout this filter filters on |
| 88 | + filtercontrols.append('<div class="filtered-value-label"><span>' + values[i]['printouts'][target]['label'] + '</span></div>'); |
| 89 | + |
| 90 | + // set default config values |
| 91 | + filtered.filtered( 'setFilterData', {filter: 'value', printout: target, configvar: 'use or', configvalue: true } ); |
| 92 | + |
| 93 | + |
| 94 | + // insert switches |
| 95 | + if ( switches != null && switches.length > 0 ) { |
| 96 | + |
| 97 | + var switchControls = $('<div class="filtered-value-switches">'); |
| 98 | + |
| 99 | + if ( $.inArray('and or', switches) ) { |
| 100 | + |
| 101 | + var andorControl = $('<div class="filtered-value-andor">'); |
| 102 | + var andControl = $('<input type="radio" name="filtered-value-andor ' + |
| 103 | + target + '" class="filtered-value-andor ' + target + '" value="and">'); |
| 104 | + |
| 105 | + var orControl = $('<input type="radio" name="filtered-value-andor ' + |
| 106 | + target + '" class="filtered-value-andor ' + target + '" value="or" checked>'); |
| 107 | + |
| 108 | + andControl |
| 109 | + .add( orControl ) |
| 110 | + .change(function() { |
| 111 | + filtered.filtered( 'setFilterData', {filter: 'value', printout: target, configvar: 'use or', configvalue: orControl.is(':checked') } ); |
| 112 | + update( filtered, filtercontrols, target ); |
| 113 | + }); |
| 114 | + |
| 115 | + andorControl |
| 116 | + .append( orControl ) |
| 117 | + .append(' OR ') |
| 118 | + .append( andControl ) |
| 119 | + .append(' AND ') |
| 120 | + .appendTo( switchControls ); |
| 121 | + |
| 122 | + } |
| 123 | + |
| 124 | + filtercontrols.append( switchControls ); |
| 125 | + } |
| 126 | + var sortedDistinctValues = []; |
| 127 | + |
| 128 | + for ( var i in distinctValues ) { |
| 129 | + sortedDistinctValues.push(i); |
| 130 | + } |
| 131 | + |
| 132 | + sortedDistinctValues.sort(); |
| 133 | + |
| 134 | + // insert options (checkboxes and labels) and attach event handlers |
| 135 | + // TODO: Do we need to wrap these in a form? |
| 136 | + for ( var j in sortedDistinctValues ) { |
| 137 | + var option = $('<div class="filtered-value-option">'); |
| 138 | + var checkbox = $('<input type="checkbox" class="filtered-value-value" value="' + sortedDistinctValues[j] + '" checked >'); |
| 139 | + |
| 140 | + // attach event handler |
| 141 | + checkbox.change(function( evt ){ |
| 142 | + update(filtered, filtercontrols, target); |
| 143 | + }); |
| 144 | + |
| 145 | + option |
| 146 | + .append(checkbox) |
| 147 | + .append(sortedDistinctValues[j]); |
| 148 | + |
| 149 | + filtercontrols |
| 150 | + .append(option); |
| 151 | + |
| 152 | + } |
| 153 | + |
| 154 | + return this; |
| 155 | + }, |
| 156 | + |
| 157 | + alert: function(){ |
| 158 | + alert('ValueFilter!'); |
| 159 | + return this; |
| 160 | + } |
| 161 | + |
| 162 | + }; |
| 163 | + |
| 164 | + valueFilter = function( method ) { |
| 165 | + |
| 166 | + // Method calling logic |
| 167 | + if ( methods[method] ) { |
| 168 | + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); |
| 169 | + } else if ( typeof method === 'object' || ! method ) { |
| 170 | + return methods.init.apply( this, arguments ); |
| 171 | + } else { |
| 172 | + $.error( 'Method ' + method + ' does not exist on jQuery.filtered.listView' ); |
| 173 | + } |
| 174 | + |
| 175 | + |
| 176 | + }; |
| 177 | + |
| 178 | + // attach ListView to all Filtered query printers |
| 179 | + // let them sort out, if ListView is actually applicable to them |
| 180 | + jQuery('.filtered').filtered('attachFilter', 'value', valueFilter ); |
| 181 | + |
| 182 | +})(jQuery); |
| 183 | + |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.value-filter.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 184 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.js |
— | — | @@ -0,0 +1,213 @@ |
| 2 | +/** |
| 3 | + * File holding the filtered plugin |
| 4 | + * |
| 5 | + * @author Stephan Gambke |
| 6 | + * @file |
| 7 | + * @ingroup SemanticResultFormats |
| 8 | + */ |
| 9 | + |
| 10 | +(function ($) { |
| 11 | + |
| 12 | + var methods = { |
| 13 | + |
| 14 | + init: function( args ){ |
| 15 | + |
| 16 | + return this.each( function() { |
| 17 | + var data = args['data']; |
| 18 | + $(this).data( 'ext.srf.filtered', data ); |
| 19 | + |
| 20 | + data['data']['pending-filters'] = []; |
| 21 | + data['data']['pending-views'] = []; |
| 22 | + |
| 23 | + for (var i in data['data']['filterhandlers']) { |
| 24 | + data['data']['pending-filters'].push(i); |
| 25 | + } |
| 26 | + |
| 27 | + for (var i in data['data']['viewhandlers']) { |
| 28 | + data['data']['pending-views'].push(i); |
| 29 | + } |
| 30 | + |
| 31 | + // init housekeeping on values |
| 32 | + for (i in data['values']) { |
| 33 | + |
| 34 | + data['values'][i]['data'] = { |
| 35 | + |
| 36 | + 'visibility': { |
| 37 | + 'overall' : true, |
| 38 | + 'votes' : {} |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + return this; |
| 44 | + }); |
| 45 | + }, |
| 46 | + |
| 47 | + attachView : function( viewName, view ) { |
| 48 | + return this.each( function() { |
| 49 | + |
| 50 | + var $this = $(this); |
| 51 | + |
| 52 | + var viewhandlers = $this.data('ext.srf.filtered')['data']['viewhandlers']; |
| 53 | + |
| 54 | + if ( viewName in viewhandlers ) { |
| 55 | + viewhandlers[viewName] = view; |
| 56 | + } |
| 57 | + |
| 58 | + var pendingViews = $this.data('ext.srf.filtered')['data']['pending-views']; |
| 59 | + |
| 60 | + var i = $.inArray(viewName, pendingViews); |
| 61 | + pendingViews.splice(i, 1); |
| 62 | + |
| 63 | + if ( pendingViews.length == 0 && $this.data('ext.srf.filtered')['data']['pending-filters'].length == 0) { |
| 64 | + |
| 65 | + for (var i in viewhandlers){ |
| 66 | + viewhandlers[i].apply( $this, ['updateAllItems'] ); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return this; |
| 71 | + }); |
| 72 | + }, |
| 73 | + |
| 74 | + attachFilter : function( filterName, filter ) { |
| 75 | + return this.each( function() { |
| 76 | + |
| 77 | + var $this = $(this); |
| 78 | + |
| 79 | + var handlers = $this.data('ext.srf.filtered')['data']['filterhandlers']; |
| 80 | + |
| 81 | + if ( filterName in handlers ) { |
| 82 | + handlers[filterName] = filter; |
| 83 | + var printouts = $this.data('ext.srf.filtered')['data']['filterdata'][filterName]; |
| 84 | + |
| 85 | + for ( var i in printouts ) { |
| 86 | + (handlers[filterName]).apply($this, [ 'init', { |
| 87 | + printout: i |
| 88 | + } ] ); |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + var pendingFilters = $this.data('ext.srf.filtered')['data']['pending-filters']; |
| 94 | + |
| 95 | + // take attached filter from list of pending filters |
| 96 | + var i = $.inArray(filterName, pendingFilters); |
| 97 | + pendingFilters.splice(i, 1); |
| 98 | + |
| 99 | + if ( pendingFilters.length == 0 && $this.data('ext.srf.filtered')['data']['pending-views'].length == 0) { |
| 100 | + var viewhandlers = $this.data('ext.srf.filtered')['data']['viewhandlers']; |
| 101 | + |
| 102 | + for (var i in viewhandlers){ |
| 103 | + viewhandlers[i].apply( $this, ['updateAllItems'] ); |
| 104 | + } |
| 105 | + } |
| 106 | + return this; |
| 107 | + }); |
| 108 | + }, |
| 109 | + |
| 110 | + voteItemVisibility : function( params ) { |
| 111 | + var item = this.data('ext.srf.filtered')['values'][params['item']]; |
| 112 | + var votes = item.data['visibility']['votes']; |
| 113 | + |
| 114 | + // Figure out if the vote changed from the filter in the params |
| 115 | + var voteChanged = |
| 116 | + votes[params['filter'] + ' ' + params['printout']] == undefined || |
| 117 | + votes[params['filter'] + ' ' + params['printout']] != params['visible']; |
| 118 | + |
| 119 | + // Store the new vote |
| 120 | + votes[params['filter'] + ' ' + params['printout']] = params['visible']; |
| 121 | + |
| 122 | + // If vote from filter changed, figure out if it has an impact on the end result |
| 123 | + if ( voteChanged ) { |
| 124 | + |
| 125 | + var visible=true; |
| 126 | + for ( var i in votes ) { |
| 127 | + visible = visible && votes[i]; |
| 128 | + } |
| 129 | + |
| 130 | + voteChanged = item.data['visibility']['overall'] != visible; |
| 131 | + |
| 132 | + // Store new end result |
| 133 | + item.data['visibility']['overall'] = visible; |
| 134 | + } |
| 135 | + |
| 136 | + |
| 137 | + return voteChanged; |
| 138 | + }, |
| 139 | + |
| 140 | + voteItemVisibilityAndUpdate : function( params ) { |
| 141 | + |
| 142 | + |
| 143 | + if ( methods.voteItemVisibility.apply(this, [params]) ) { |
| 144 | + |
| 145 | + var handlers = this.data('ext.srf.filtered')['data']['viewhandlers']; |
| 146 | + |
| 147 | + for (var i in handlers){ |
| 148 | + handlers[i].apply( this, ['updateItem', params] ); |
| 149 | + } |
| 150 | + } |
| 151 | + return this; |
| 152 | + }, |
| 153 | + |
| 154 | + getFilterData : function ( params ) { |
| 155 | + if ( params['filter'] == undefined ) { |
| 156 | + return this.data('ext.srf.filtered')['data']['filterdata'] |
| 157 | + } else if ( params['printout'] == undefined ) { |
| 158 | + return this.data('ext.srf.filtered')['data']['filterdata'][params['filter']]; |
| 159 | + } else if ( params['configvar'] == undefined ) { |
| 160 | + return this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']]; |
| 161 | + } else { |
| 162 | + if (this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']] != null) { |
| 163 | + return this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']][params['configvar']]; |
| 164 | + } else { |
| 165 | + return null; |
| 166 | + } |
| 167 | + } |
| 168 | + }, |
| 169 | + |
| 170 | + setFilterData : function ( params ) { |
| 171 | + if ( params['filter'] == undefined || |
| 172 | + params['printout'] == undefined || |
| 173 | + params['configvar'] == undefined || |
| 174 | + params['configvalue'] == undefined ) { |
| 175 | + return null; |
| 176 | + } else { |
| 177 | + if (this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']] == null) { |
| 178 | + this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']] = {} |
| 179 | + } |
| 180 | + this.data('ext.srf.filtered')['data']['filterdata'][params['filter']][params['printout']][params['configvar']] = params['configvalue']; |
| 181 | + } |
| 182 | + }, |
| 183 | + |
| 184 | + getValues : function ( params ) { |
| 185 | + return this.data('ext.srf.filtered')['data']; |
| 186 | + }, |
| 187 | + |
| 188 | + isVisible : function ( item ) { |
| 189 | + return this.data('ext.srf.filtered')['values'][item]['data']['visibility']['overall']; |
| 190 | + } |
| 191 | + }; |
| 192 | + |
| 193 | + $.fn.filtered = function( method ) { |
| 194 | + |
| 195 | + // Method calling logic |
| 196 | + if ( methods[method] ) { |
| 197 | + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); |
| 198 | + } else if ( typeof method === 'object' || ! method ) { |
| 199 | + return methods.init.apply( this, arguments ); |
| 200 | + } else { |
| 201 | + $.error( 'Method ' + method + ' does not exist on jQuery.tooltip' ); |
| 202 | + } |
| 203 | + |
| 204 | + |
| 205 | + }; |
| 206 | + |
| 207 | +})(jQuery); |
| 208 | + |
| 209 | +// initialize all Filtered |
| 210 | +for ( id in srf_filtered_values ) { |
| 211 | + jQuery('.' + id).filtered( { |
| 212 | + 'data' : srf_filtered_values[ id ] |
| 213 | + }); |
| 214 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 215 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.list-view.js |
— | — | @@ -0,0 +1,77 @@ |
| 2 | +/** |
| 3 | + * File holding the list-view plugin |
| 4 | + * |
| 5 | + * For this plugin to work, the filtered plugin needs to be available first. |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +(function ($) { |
| 13 | + |
| 14 | + var methods = { |
| 15 | + |
| 16 | + init: function( args ){ |
| 17 | + return this; |
| 18 | + }, |
| 19 | + |
| 20 | + alert: function(){ |
| 21 | + alert('List View!'); |
| 22 | + return this; |
| 23 | + }, |
| 24 | + |
| 25 | + updateItem: function(params){ |
| 26 | + |
| 27 | + var view = this.children('.filtered-views').children('.filtered-list'); |
| 28 | + |
| 29 | + if ( params.visible ) { |
| 30 | + view.children('.' + params.item ).slideDown( 200 ); |
| 31 | + } else { |
| 32 | + view.children('.' + params.item ).slideUp( 200 ); |
| 33 | + } |
| 34 | + return this; |
| 35 | + }, |
| 36 | + |
| 37 | + updateAllItems: function(){ |
| 38 | + |
| 39 | + var filtered = this; |
| 40 | + var items = this.children('.filtered-views').children('.filtered-list').children(); |
| 41 | + |
| 42 | + items.each(function(){ |
| 43 | + |
| 44 | + var $this = $(this) |
| 45 | + var id = $this.attr('id'); |
| 46 | + |
| 47 | + if (filtered.filtered('isVisible', id)) { |
| 48 | + $this.slideDown(0); |
| 49 | + } else { |
| 50 | + $this.slideUp(0); |
| 51 | + } |
| 52 | + |
| 53 | + }); |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + }; |
| 58 | + |
| 59 | + listView = function( method ) { |
| 60 | + |
| 61 | + // Method calling logic |
| 62 | + if ( methods[method] ) { |
| 63 | + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); |
| 64 | + } else if ( typeof method === 'object' || ! method ) { |
| 65 | + return methods.init.apply( this, arguments ); |
| 66 | + } else { |
| 67 | + $.error( 'Method ' + method + ' does not exist on jQuery.filtered.listView' ); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + }; |
| 72 | + |
| 73 | + // attach ListView to all Filtered query printers |
| 74 | + // let them sort out, if ListView is actually applicable to them |
| 75 | + jQuery('.filtered').filtered('attachView', 'list', listView ); |
| 76 | + |
| 77 | +})(jQuery); |
| 78 | + |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/libs/ext.srf.filtered.list-view.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 79 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php |
— | — | @@ -0,0 +1,76 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRF_Filtered_Item class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * The SRF_Filtered_Item class. |
| 14 | + * |
| 15 | + * @ingroup SemanticResultFormats |
| 16 | + */ |
| 17 | +class SRF_Filtered_Item { |
| 18 | + |
| 19 | + private $mResultArray; |
| 20 | + private $mItemData = array(); |
| 21 | + private $mQueryPrinter; |
| 22 | + |
| 23 | + public function __construct($resultArray, SRFFiltered &$queryPrinter) { |
| 24 | + $this->mResultArray = $resultArray; |
| 25 | + $this->mQueryPrinter = $queryPrinter; |
| 26 | + } |
| 27 | + |
| 28 | + public function setDataForView ( $viewId, &$data ){ |
| 29 | + $this->mItemData[$viewId] = $data; |
| 30 | + } |
| 31 | + |
| 32 | + public function unsetDataForView ( $viewId ){ |
| 33 | + unset($this->mItemData[$viewId]); |
| 34 | + } |
| 35 | + |
| 36 | + public function getDataForView ( $viewId ){ |
| 37 | + return $this->mItemData[$viewId]; |
| 38 | + } |
| 39 | + |
| 40 | + public function getValue() { |
| 41 | + return $this->mResultArray; |
| 42 | + } |
| 43 | + |
| 44 | + public function getArrayRepresentation() { |
| 45 | + |
| 46 | + $printouts = array(); |
| 47 | + |
| 48 | + foreach ( $this->mResultArray as $i => $field ) { |
| 49 | + |
| 50 | + $printRequest = $field->getPrintRequest(); |
| 51 | + |
| 52 | + $label = $printRequest->getLabel(); |
| 53 | + $type = $printRequest->getTypeID(); |
| 54 | + $params = $printRequest->getParameters(); |
| 55 | + |
| 56 | + $values = array(); |
| 57 | + |
| 58 | + $field->reset(); |
| 59 | + while ( ( $value = $field->getNextText( SMW_OUTPUT_WIKI, null ) ) !== false ) { |
| 60 | + $values[] = $value; |
| 61 | + } |
| 62 | + |
| 63 | + $printouts[ md5($printRequest->getHash()) ] = array( |
| 64 | + 'label' => $label, |
| 65 | + 'type' => $type, |
| 66 | + 'params' => $params, |
| 67 | + 'values' => $values, |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + return array( |
| 73 | + 'printouts' => $printouts, |
| 74 | + 'data' => $this->mItemData, |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 78 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php |
— | — | @@ -0,0 +1,209 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRF_FV_List class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * The SRF_FV_List class defines the List view. |
| 14 | + * |
| 15 | + * Available parameters for this view: |
| 16 | + * list view type: list|ul|ol; default: list |
| 17 | + * list view template: a template rendering a list item |
| 18 | + * list view introtemplate: a template prepended to the list |
| 19 | + * list view outrotemplate: a template appended to the list |
| 20 | + * list view named args: use named args for templates |
| 21 | + * |
| 22 | + * @ingroup SemanticResultFormats |
| 23 | + */ |
| 24 | +class SRF_FV_List extends SRF_Filtered_View { |
| 25 | + |
| 26 | + private $mFormat, $mTemplate, $mIntroTemplate, $mOutroTemplate, $mNamedArgs, $mShowHeaders; |
| 27 | + |
| 28 | + /** |
| 29 | + * Transfers the parameters applicable to this view into internal variables. |
| 30 | + */ |
| 31 | + protected function handleParameters() { |
| 32 | + |
| 33 | + $params = $this->getActualParameters(); |
| 34 | + |
| 35 | + $this->mFormat = $params['list view type']; |
| 36 | + $this->mTemplate = $params['list view template']; |
| 37 | + $this->mIntroTemplate = $params['list view introtemplate']; |
| 38 | + $this->mOutroTemplate = $params['list view outrotemplate']; |
| 39 | + $this->mNamedArgs = $params['list view named args']; |
| 40 | + |
| 41 | + if ( $params['headers'] == 'hide' ) { |
| 42 | + $this->mShowHeaders = SMW_HEADERS_HIDE; |
| 43 | + } elseif ( $params['headers'] == 'plain' ) { |
| 44 | + $this->mShowHeaders = SMW_HEADERS_PLAIN; |
| 45 | + } else { |
| 46 | + $this->mShowHeaders = SMW_HEADERS_SHOW; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns the wiki text that is to be included for this view. |
| 52 | + * |
| 53 | + * @return string |
| 54 | + */ |
| 55 | + public function getResultText() { |
| 56 | + |
| 57 | + $this->handleParameters(); |
| 58 | + |
| 59 | + // Determine mark-up strings used around list items: |
| 60 | + if ( ( $this->mFormat == 'ul' ) || ( $this->mFormat == 'ol' ) ) { |
| 61 | + $header = "<" . $this->mFormat . ">\n"; |
| 62 | + $footer = "</" . $this->mFormat . ">\n"; |
| 63 | + $rowstart = "\t<li class='filtered-list-item "; |
| 64 | + $rowend = "</li>\n"; |
| 65 | + $listsep = ', '; |
| 66 | + } else { // "list" format |
| 67 | + $header = ''; |
| 68 | + $footer = ''; |
| 69 | + $rowstart = "\t<div class='filtered-list-item "; |
| 70 | + $rowend = "</div>\n"; |
| 71 | + $listsep = ', '; |
| 72 | + } |
| 73 | + |
| 74 | + // Initialise more values |
| 75 | + $result = ''; |
| 76 | + |
| 77 | + if ( $header !== '' ) { |
| 78 | + $result .= $header; |
| 79 | + } |
| 80 | + |
| 81 | + if ( $this->mIntroTemplate !== '' ) { |
| 82 | + $result .= "{{" . $this->mIntroTemplate . "}}"; |
| 83 | + } |
| 84 | + |
| 85 | + // Now print each row |
| 86 | + $rownum = -1; |
| 87 | + |
| 88 | + foreach ($this->getQueryResults() as $id => $value) { |
| 89 | + $row = $value->getValue(); |
| 90 | + |
| 91 | + $this->printRow( $row, $rownum, $rowstart . $id . "' id='$id' >", $rowend, $result, $listsep ); |
| 92 | + } |
| 93 | + |
| 94 | + if ( $this->mOutroTemplate !== '' ) { |
| 95 | + $result .= "{{" . $this->mOutroTemplate . "}}"; |
| 96 | + } |
| 97 | + |
| 98 | + // Print footer |
| 99 | + if ( $footer !== '' ) { |
| 100 | + $result .= $footer; |
| 101 | + } |
| 102 | + |
| 103 | + return $result; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Prints one row of a list view. |
| 108 | + */ |
| 109 | + protected function printRow( $row, &$rownum, $rowstart, $rowend, &$result, $listsep ) { |
| 110 | + |
| 111 | + $rownum++; |
| 112 | + |
| 113 | + $result .= $rowstart; |
| 114 | + |
| 115 | + if ( $this->mTemplate !== '' ) { // build template code |
| 116 | + $this->getQueryPrinter()->hasTemplates( true ); |
| 117 | + |
| 118 | + // $wikitext = ( $this->mUserParam ) ? "|userparam=$this->mUserParam" : ''; |
| 119 | + $wikitext = ''; |
| 120 | + |
| 121 | + foreach ( $row as $i => $field ) { |
| 122 | + $wikitext .= '|' . ( $this->mNamedArgs ? '?' . $field->getPrintRequest()->getLabel() : $i + 1 ) . '='; |
| 123 | + $first_value = true; |
| 124 | + |
| 125 | + $field->reset(); |
| 126 | + while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) { |
| 127 | + if ( $first_value ) $first_value = false; else $wikitext .= ', '; |
| 128 | + $wikitext .= $text; |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + $wikitext .= "|#=$rownum"; |
| 133 | + $result .= '{{' . $this->mTemplate . $wikitext . '}}'; |
| 134 | + |
| 135 | + } else { // build simple list |
| 136 | + $first_col = true; |
| 137 | + $found_values = false; // has anything but the first column been printed? |
| 138 | + |
| 139 | + foreach ( $row as $field ) { |
| 140 | + $first_value = true; |
| 141 | + |
| 142 | + while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== false ) { |
| 143 | + if ( !$first_col && !$found_values ) { // first values after first column |
| 144 | + $result .= ' ('; |
| 145 | + $found_values = true; |
| 146 | + } elseif ( $found_values || !$first_value ) { |
| 147 | + // any value after '(' or non-first values on first column |
| 148 | + $result .= "$listsep "; |
| 149 | + } |
| 150 | + |
| 151 | + if ( $first_value ) { // first value in any column, print header |
| 152 | + $first_value = false; |
| 153 | + |
| 154 | + if ( ( $this->mShowHeaders != SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) { |
| 155 | + $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker(true, true) ) ) . ' '; |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + $result .= $text; // actual output value |
| 160 | + } |
| 161 | + |
| 162 | + $first_col = false; |
| 163 | + } |
| 164 | + |
| 165 | + if ( $found_values ) $result .= ')'; |
| 166 | + } |
| 167 | + |
| 168 | + $result .= $rowend; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * A function to describe the allowed parameters of a query for this view. |
| 173 | + * |
| 174 | + * @return array of Parameter |
| 175 | + */ |
| 176 | + public static function getParameters() { |
| 177 | + $params = parent::getParameters(); |
| 178 | + |
| 179 | + $params['list view type'] = new Parameter( 'list type' ); |
| 180 | + $params['list view type']->setMessage( 'srf-paramdesc-filtered-list-type' ); |
| 181 | + $params['list view type']->setDefault( 'list' ); |
| 182 | + |
| 183 | + $params['list view template'] = new Parameter( 'list template' ); |
| 184 | + $params['list view template']->setMessage( 'srf-paramdesc-filtered-list-template' ); |
| 185 | + $params['list view template']->setDefault( '' ); |
| 186 | + |
| 187 | + $params['list view named args'] = new Parameter( 'list named args', Parameter::TYPE_BOOLEAN, false ); |
| 188 | + $params['list view named args']->setMessage( 'srf-paramdesc-filtered-list-named-args' ); |
| 189 | + |
| 190 | + $params['list view introtemplate'] = new Parameter( 'list introtemplate' ); |
| 191 | + $params['list view introtemplate']->setMessage( 'srf-paramdesc-filtered-list-introtemplate' ); |
| 192 | + $params['list view introtemplate']->setDefault( '' ); |
| 193 | + |
| 194 | + $params['list view outrotemplate'] = new Parameter( 'list outrotemplate' ); |
| 195 | + $params['list view outrotemplate']->setMessage( 'srf-paramdesc-filtered-list-outrotemplate' ); |
| 196 | + $params['list view outrotemplate']->setDefault( '' ); |
| 197 | + |
| 198 | + return $params; |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Returns the name of the resource module to load for this view. |
| 203 | + * |
| 204 | + * @return string|array |
| 205 | + */ |
| 206 | + public function getResourceModules() { |
| 207 | + return 'ext.srf.filtered.list-view'; |
| 208 | + } |
| 209 | + |
| 210 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 211 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRF_Filtered_View class |
| 6 | + * |
| 7 | + * @author Stephan Gambke |
| 8 | + * @file |
| 9 | + * @ingroup SemanticResultFormats |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * The SRF_Filtered_View class. |
| 14 | + * |
| 15 | + * @ingroup SemanticResultFormats |
| 16 | + */ |
| 17 | +abstract class SRF_Filtered_View { |
| 18 | + |
| 19 | + private $mId; |
| 20 | + private $mResults; |
| 21 | + private $mParameters; |
| 22 | + private $mQueryPrinter; |
| 23 | + |
| 24 | + /** |
| 25 | + * Constructor for the view. |
| 26 | + * |
| 27 | + * @param $id the view id |
| 28 | + * @param $results array of SRF_Filtered_Item containing the query results |
| 29 | + * @param type $params array of parameter values given as key-value-pairs |
| 30 | + */ |
| 31 | + public function __construct( $id, &$results, &$params, SRFFiltered &$queryPrinter ) { |
| 32 | + $this->mId = $id; |
| 33 | + $this->mResults = $results; |
| 34 | + $this->mParameters = $params; |
| 35 | + $this->mQueryPrinter = $queryPrinter; |
| 36 | + } |
| 37 | + |
| 38 | + public function getId() {return $this->mId;} |
| 39 | + public function &getQueryResults() {return $this->mResults;} |
| 40 | + public function &getActualParameters() {return $this->mParameters;} |
| 41 | + public function &getQueryPrinter() {return $this->mQueryPrinter;} |
| 42 | + |
| 43 | + /** |
| 44 | + * Returns the name (string) or names (array of strings) of the resource |
| 45 | + * modules to load. |
| 46 | + * |
| 47 | + * @return string|array |
| 48 | + */ |
| 49 | + public function getResourceModules() { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * A function to describe the allowed parameters of a query for this view. |
| 55 | + * |
| 56 | + * @return array of Parameter |
| 57 | + */ |
| 58 | + public static function getParameters() { |
| 59 | + return array(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Returns the HTML text that is to be included for this view. |
| 64 | + * |
| 65 | + * This text will appear on the page in a div that has the view's id set as |
| 66 | + * class. |
| 67 | + * |
| 68 | + * @return string |
| 69 | + */ |
| 70 | + public function getResultText() { |
| 71 | + return ''; |
| 72 | + } |
| 73 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 74 | + native |
Index: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php |
— | — | @@ -0,0 +1,238 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * File holding the SRFFiltered class. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup SemanticResultFormats |
| 9 | + * @author Stephan Gambke |
| 10 | + * |
| 11 | + */ |
| 12 | + |
| 13 | +$formatDir = dirname( __FILE__ ) . '/'; |
| 14 | + |
| 15 | +$wgAutoloadClasses['SRF_Filtered_Item'] = $formatDir . 'SRF_Filtered_Item.php'; |
| 16 | + |
| 17 | +$wgAutoloadClasses['SRF_Filtered_View'] = $formatDir . 'views/SRF_Filtered_View.php'; |
| 18 | +$wgAutoloadClasses['SRF_FV_List'] = $formatDir . 'views/SRF_FV_List.php'; |
| 19 | + |
| 20 | +$wgAutoloadClasses['SRF_Filtered_Filter'] = $formatDir . 'filters/SRF_Filtered_Filter.php'; |
| 21 | +$wgAutoloadClasses['SRF_FF_Value'] = $formatDir . 'filters/SRF_FF_Value.php'; |
| 22 | + |
| 23 | + |
| 24 | +/** |
| 25 | + * Result printer that displays results in switchable views and offers |
| 26 | + * client-side (JavaScript based) filtering. |
| 27 | + * |
| 28 | + * This result printer is ultimately planned to replace exhibit. Currently only |
| 29 | + * a list view is available. It is not yet possible to switch between views. |
| 30 | + * There is also only the 'value' filter available yet. |
| 31 | + * |
| 32 | + * Syntax of the #ask call: |
| 33 | + * (This is only a syntax example. For currently available features see the |
| 34 | + * documentation of the various classes.) |
| 35 | + * |
| 36 | + * {{#ask:[[SomeCondition]] |
| 37 | + * |? SomePrintout |+filter=value, someFutureFilter |+value filter switches=and or, disable, all, none |+someFutureFilter filter option=someOptionValue |
| 38 | + * |? SomeOtherPrintout |+filter=value, someOtherFutureFilter |+someOtherFutureFilter filter option=someOptionValue |
| 39 | + * |
| 40 | + * |format=filtered |
| 41 | + * |views=list, someFutureView, someOtherFutureView |
| 42 | + * |
| 43 | + * |list view type=list |
| 44 | + * |list view template=ListItem |
| 45 | + * |
| 46 | + * |someFutureView view option=someOptionValue |
| 47 | + * |
| 48 | + * |someOtherFutureView view option=someOptionValue |
| 49 | + * |
| 50 | + * }} |
| 51 | + * |
| 52 | + * All format specific parameters are optional, although leaving the 'views' |
| 53 | + * parameter empty probably does not make much sense. |
| 54 | + * |
| 55 | + */ |
| 56 | +class SRFFiltered extends SMWResultPrinter { |
| 57 | + |
| 58 | + /** |
| 59 | + * The available view types |
| 60 | + * @var array of Strings |
| 61 | + */ |
| 62 | + private $mViewTypes = array( |
| 63 | + 'list' => 'SRF_FV_List', |
| 64 | + ); |
| 65 | + |
| 66 | + /** |
| 67 | + * The available filter types |
| 68 | + * @var array of Strings |
| 69 | + */ |
| 70 | + private $mFilterTypes = array( |
| 71 | + 'value' => 'SRF_FF_Value', |
| 72 | + ); |
| 73 | + |
| 74 | + private $mViews; |
| 75 | + private $mParams; |
| 76 | + |
| 77 | + public function hasTemplates ( $hasTemplates = null ) { |
| 78 | + $ret = $this->hasTemplates; |
| 79 | + if ( is_bool( $hasTemplates ) ) { |
| 80 | + $this->hasTemplates = $hasTemplates; |
| 81 | + } |
| 82 | + return $ret; |
| 83 | + } |
| 84 | + |
| 85 | + protected function handleParameters( array $params, $outputmode ) { |
| 86 | + parent::handleParameters( $params, $outputmode ); |
| 87 | + |
| 88 | + //// Set in SMWResultPrinter: |
| 89 | + // $this->mIntro = $params['intro']; |
| 90 | + // $this->mOutro = $params['outro']; |
| 91 | + // $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel']; |
| 92 | + // $this->mLinkFirst = true | false; |
| 93 | + // $this->mLinkOthers = true | false; |
| 94 | + // $this->mDefault = str_replace( '_', ' ', $params['default'] ); |
| 95 | + // $this->mShowHeaders = SMW_HEADERS_HIDE | SMW_HEADERS_PLAIN | SMW_HEADERS_SHOW; |
| 96 | + |
| 97 | + $this->mSearchlabel = null; |
| 98 | + |
| 99 | + $this->mParams = $params; |
| 100 | + $this->mViews = array_map( 'trim', explode( ',', $params['views'] ) ); |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Return serialised results in specified format. |
| 106 | + */ |
| 107 | + protected function getResultText( SMWQueryResult $res, $outputmode ) { |
| 108 | + |
| 109 | + // collect the query results in an array |
| 110 | + $result = array(); |
| 111 | + while ( $row = $res->getNext() ) { |
| 112 | + $result[uniqid()] = new SRF_Filtered_Item( $row, $this ); |
| 113 | + } |
| 114 | + |
| 115 | + $resourceModules = array(); |
| 116 | + |
| 117 | + // prepare filter data for inclusion in HTML and JS |
| 118 | + $filterHtml = ''; |
| 119 | + $filterHandlers = array(); |
| 120 | + $filterData = array(); |
| 121 | + |
| 122 | + foreach ( $res->getPrintRequests() as $printRequest ) { |
| 123 | + $filter = $printRequest->getParameter( 'filter' ); |
| 124 | + if ( $filter ) { |
| 125 | + |
| 126 | + $filtersForPrintout = explode( ',', $filter ); |
| 127 | + $filtersForPrintout = array_map('trim', $filtersForPrintout); |
| 128 | + |
| 129 | + foreach ( $filtersForPrintout as $filterName ) { |
| 130 | + if ( array_key_exists( $filterName, $this->mFilterTypes ) ) { |
| 131 | + |
| 132 | + $filter = new $this->mFilterTypes[$filterName]( $result, $printRequest, $this); |
| 133 | + |
| 134 | + $resourceModules = $filter->getResourceModules(); |
| 135 | + |
| 136 | + if ( is_array( $resourceModules ) ) { |
| 137 | + array_walk( $resourceModules, 'SMWOutputs::requireResource' ); |
| 138 | + } elseif ( is_string( $resourceModules ) ) { |
| 139 | + SMWOutputs::requireResource( $resourceModules ); |
| 140 | + } |
| 141 | + |
| 142 | + $printRequestHash = md5( $printRequest->getHash() ); |
| 143 | + $filterHtml .= Html::rawElement( 'div', array('class' => "filtered-$filterName $printRequestHash"), $filter->getResultText() ); |
| 144 | + |
| 145 | + $filterHandlers[$filterName] = null; |
| 146 | + $filterData[$filterName][$printRequestHash] = $filter->getJsData(); |
| 147 | + |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + // wrap filters in a div |
| 154 | + $filterHtml = Html::rawElement( 'div', array( 'class' => 'filtered-filters' ), $filterHtml ); |
| 155 | + |
| 156 | + // prepare view data for inclusion in HTML and JS |
| 157 | + $viewHtml = ''; |
| 158 | + $viewHandlers = array(); |
| 159 | + $viewElements = array(); |
| 160 | + |
| 161 | + foreach ( $this->mViews as $viewName ) { |
| 162 | + if ( array_key_exists( $viewName, $this->mViewTypes ) ) { |
| 163 | + |
| 164 | + // generate unique id |
| 165 | + $viewid = uniqid(); |
| 166 | + |
| 167 | + $view = new $this->mViewTypes[$viewName]( $viewid, $result, $this->mParams, $this ); |
| 168 | + |
| 169 | + $resourceModules = $view->getResourceModules(); |
| 170 | + |
| 171 | + if ( is_array( $resourceModules ) ) { |
| 172 | + array_walk( $resourceModules, 'SMWOutputs::requireResource' ); |
| 173 | + } elseif ( is_string( $resourceModules ) ) { |
| 174 | + SMWOutputs::requireResource( $resourceModules ); |
| 175 | + } |
| 176 | + |
| 177 | + $viewHtml .= Html::rawElement( 'div', array('class' => "filtered-$viewName $viewid"), $view->getResultText() ); |
| 178 | + |
| 179 | + $viewHandlers[$viewName] = null; |
| 180 | + $viewElements[$viewName][] = $viewid; |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + // wrap views in a div |
| 185 | + $viewHtml = Html::rawElement( 'div', array( 'class' => 'filtered-views' ), $viewHtml ); |
| 186 | + |
| 187 | + // Define the srf_filtered_values array |
| 188 | + SMWOutputs::requireScript( 'srf_filtered_values', Html::inlineScript( |
| 189 | + 'srf_filtered_values = {};' |
| 190 | + ) |
| 191 | + ); |
| 192 | + |
| 193 | + $resultAsArray = array(); |
| 194 | + foreach ( $result as $id => $value ) { |
| 195 | + $resultAsArray[$id] = $value->getArrayRepresentation(); |
| 196 | + } |
| 197 | + |
| 198 | + $id = uniqid(); |
| 199 | + SMWOutputs::requireScript( 'srf_filtered_values' . $id, |
| 200 | + Html::inlineScript( |
| 201 | + 'srf_filtered_values["' . $id . '"] = { "values":' . json_encode( $resultAsArray ) . |
| 202 | + ', "data": {' . |
| 203 | + ' "viewhandlers" : ' . json_encode( $viewHandlers ) . |
| 204 | + ', "viewelements" : ' . json_encode( $viewElements ) . |
| 205 | + ', "filterhandlers" : ' . json_encode( $filterHandlers ) . |
| 206 | + ', "filterdata" : ' . json_encode( $filterData ) . |
| 207 | + '}};' |
| 208 | + ) |
| 209 | + ); |
| 210 | + |
| 211 | + SMWOutputs::requireResource('ext.srf.filtered'); |
| 212 | + |
| 213 | + // wrap all in a div |
| 214 | + $html = Html::rawElement( 'div', array( 'class' => 'filtered ' . $id ), $filterHtml . $viewHtml ); |
| 215 | + |
| 216 | + return $html; |
| 217 | + } |
| 218 | + |
| 219 | + |
| 220 | + public function getParameters() { |
| 221 | + $params = array_merge( parent::getParameters(), |
| 222 | + parent::textDisplayParameters() ); |
| 223 | + |
| 224 | + $params['views'] = new Parameter( 'views' ); |
| 225 | + $params['views']->setMessage( 'srf-paramdesc-views' ); |
| 226 | + $params['views']->setDefault( '' ); |
| 227 | + |
| 228 | + foreach ( $this->mViewTypes as $viewType ) { |
| 229 | + $params = array_merge($params, call_user_func( array( $viewType, 'getParameters') ) ); |
| 230 | + } |
| 231 | + |
| 232 | + return $params; |
| 233 | + } |
| 234 | + |
| 235 | + public function getLinker( $firstcol = false, $force = false ) { |
| 236 | + return ( $force ) ? $this->mLinker : parent::getLinker( $firstcol ); |
| 237 | + } |
| 238 | + |
| 239 | +} |
Property changes on: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 240 | + native |
Index: trunk/extensions/SemanticResultFormats/SRF_Settings.php |
— | — | @@ -53,6 +53,7 @@ |
54 | 54 | $srfgFormats[] = 'D3Line'; |
55 | 55 | $srfgFormats[] = 'D3Bar'; |
56 | 56 | $srfgFormats[] = 'D3Treemap'; |
| 57 | + $srfgFormats[] = 'filtered'; |
57 | 58 | } |
58 | 59 | |
59 | 60 | # load hash format only if HashTables extension is initialised, otherwise 'Array' format is enough |
Index: trunk/extensions/SemanticResultFormats/SRF_Resources.php |
— | — | @@ -124,4 +124,38 @@ |
125 | 125 | 'position' => 'top', |
126 | 126 | ); |
127 | 127 | |
| 128 | +$wgResourceModules['ext.srf.filtered'] = $moduleTemplate + array( |
| 129 | + 'scripts' => array( |
| 130 | + 'Filtered/libs/ext.srf.filtered.js', |
| 131 | + ), |
| 132 | + 'styles' => array( |
| 133 | + 'Filtered/skins/ext.srf.filtered.css', |
| 134 | + ), |
| 135 | +); |
| 136 | + |
| 137 | +$wgResourceModules['ext.srf.filtered.list-view'] = $moduleTemplate + array( |
| 138 | + 'scripts' => array( |
| 139 | + 'Filtered/libs/ext.srf.filtered.list-view.js', |
| 140 | + ), |
| 141 | +// TODO: Do we need a style file? |
| 142 | +// 'styles' => array( |
| 143 | +// 'Filtered/skins/ext.srf.filtered.css', |
| 144 | +// ), |
| 145 | + 'dependencies' => array( |
| 146 | + 'ext.srf.filtered' |
| 147 | + ), |
| 148 | +); |
| 149 | + |
| 150 | +$wgResourceModules['ext.srf.filtered.value-filter'] = $moduleTemplate + array( |
| 151 | + 'scripts' => array( |
| 152 | + 'Filtered/libs/ext.srf.filtered.value-filter.js', |
| 153 | + ), |
| 154 | + 'styles' => array( |
| 155 | + 'Filtered/skins/ext.srf.filtered.value-filter.css', |
| 156 | + ), |
| 157 | + 'dependencies' => array( |
| 158 | + 'ext.srf.filtered' |
| 159 | + ), |
| 160 | +); |
| 161 | + |
128 | 162 | unset( $moduleTemplate ); |