Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableResultPrinter to support a datatable output #2420

Merged
merged 1 commit into from Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion i18n/en.json
Expand Up @@ -531,5 +531,21 @@
"smw-patternedit-protection": "This page is protected and can only be edited by users with the appropriate <code>smw-patternedit</code> [https://www.semantic-mediawiki.org/wiki/Help:Permissions permission].",
"smw-pa-property-predefined_edip": "\"$1\" is a predefined property provided by [https://www.semantic-mediawiki.org/wiki/Help:Special_properties Semantic MediaWiki] to indicate whether editing is protected or not.",
"smw-pa-property-predefined-long_edip": "While any user is qualified to add this property to a subject, only a user with a dedicated permission can edit or revoke the protection to an entity after it has been added.",
"smw-query-reference-link-label" : "Query reference"
"smw-query-reference-link-label" : "Query reference",
"smw-format-datatable-emptytable": "No data available in table",
"smw-format-datatable-info": "Showing _START_ to _END_ of _TOTAL_ entries",
"smw-format-datatable-infoempty": "Showing 0 to 0 of 0 entries",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwjames Shouldn't this be something like "No results are shown"?

"smw-format-datatable-infofiltered": "(filtered from _MAX_ total entries)",
"smw-format-datatable-infothousands": ",",
"smw-format-datatable-lengthmenu": "Show _MENU_ entries",
"smw-format-datatable-loadingrecords": "Loading...",
"smw-format-datatable-processing": "Processing...",
"smw-format-datatable-search": "Search:",
"smw-format-datatable-zerorecords": "No matching records found",
"smw-format-datatable-first": "First",
"smw-format-datatable-last": "Last",
"smw-format-datatable-next": "Next",
"smw-format-datatable-previous": "Previous",
"smw-format-datatable-sortascending": ": activate to sort column ascending",
"smw-format-datatable-sortdescending": ": activate to sort column descending"
}
18 changes: 17 additions & 1 deletion i18n/ja.json
Expand Up @@ -338,5 +338,21 @@
"smw-datavalue-external-formatter-invalid-uri": "「$1」は無効な URL です。",
"smw-datavalue-propertylist-invalid-property-key": "プロパティリスト「$1」は無効なプロパティキー「$2」を含んでいました。",
"smw-datavalue-reference-outputformat": "$1: $2",
"smw-parse": "$1"
"smw-parse": "$1",
"smw-format-datatable-emptytable": "テーブルにデータがありません",
"smw-format-datatable-info": "_TOTAL_ 件中 _START_ から _END_ まで表示",
"smw-format-datatable-infoempty": "0 件中 0 から 0 まで表示",
"smw-format-datatable-infofiltered": "(全 _MAX_ 件より抽出)",
"smw-format-datatable-infothousands": ",",
"smw-format-datatable-lengthmenu": "_MENU_ 件表示",
"smw-format-datatable-loadingrecords": "読み込み中...",
"smw-format-datatable-processing": "処理中...",
"smw-format-datatable-search": "検索:",
"smw-format-datatable-zerorecords": "一致するレコードがありません",
"smw-format-datatable-first": "先頭",
"smw-format-datatable-last": "最終",
"smw-format-datatable-next": "次",
"smw-format-datatable-previous": "前",
"smw-format-datatable-sortascending": ": 列を昇順に並べ替えるにはアクティブにする",
"smw-format-datatable-sortdescending": ": 列を降順に並べ替えるにはアクティブにする"
}
30 changes: 28 additions & 2 deletions includes/SMW_Outputs.php
Expand Up @@ -41,9 +41,20 @@ class SMWOutputs {
*/
protected static $scripts = array();

/// Protected member for temporarily storing resource modules.
/**
* Protected member for temporarily storing resource modules.
*
* @var array
*/
protected static $resourceModules = array();

/**
* Protected member for temporarily storing resource modules.
*
* @var array
*/
protected static $resourceStyles = array();

/**
* Adds a resource module to the parser output.
*
Expand All @@ -55,6 +66,15 @@ public static function requireResource( $moduleName ) {
self::$resourceModules[$moduleName] = $moduleName;
}

/**
* @since 3.0
*
* @param string $stylesName
*/
public static function requireStyle( $stylesName ) {
self::$resourceStyles[$stylesName] = $stylesName;
}

/**
* Require the presence of header scripts, provided as strings with
* enclosing script tags. Note that the same could be achieved with
Expand Down Expand Up @@ -91,7 +111,7 @@ public static function requireHeadItem( $id, $item = '' ) {
self::requireResource( 'ext.smw.tooltips' );
break;
case SMW_HEADER_STYLE:
self::requireResource( 'ext.smw.style' );
self::requireStyle( 'ext.smw.style' );
break;
}
} else {
Expand Down Expand Up @@ -159,15 +179,19 @@ static public function commitToParser( Parser $parser ) {
* @param ParserOutput $parserOutput
*/
static public function commitToParserOutput( ParserOutput $parserOutput ) {

foreach ( self::$scripts as $key => $script ) {
$parserOutput->addHeadItem( $script . "\n", $key );
}

foreach ( self::$headItems as $key => $item ) {
$parserOutput->addHeadItem( "\t\t" . $item . "\n", $key );
}

$parserOutput->addModuleStyles( array_values( self::$resourceStyles ) );
$parserOutput->addModules( array_values( self::$resourceModules ) );

self::$resourceStyles = array();
self::$resourceModules = array();
self::$headItems = array();
}
Expand All @@ -190,8 +214,10 @@ static public function commitToOutputPage( OutputPage $output ) {
$output->addHeadItem( $key, "\t\t" . $item . "\n" );
}

$output->addModuleStyles( array_values( self::$resourceStyles ) );
$output->addModules( array_values( self::$resourceModules ) );

self::$resourceStyles = array();
self::$resourceModules = array();
self::$headItems = array();
}
Expand Down
24 changes: 22 additions & 2 deletions includes/queryprinters/TableResultPrinter.php
Expand Up @@ -7,6 +7,8 @@
use SMWDataValue;
use SMWQueryResult;
use SMWResultArray;
use SMWOutputs as ResourceManager;
use Html;

/**
* Print query results in tables
Expand Down Expand Up @@ -45,6 +47,7 @@ public function getName() {
*/
protected function getResultText( SMWQueryResult $res, $outputMode ) {
$this->isHTML = ( $outputMode === SMW_OUTPUT_HTML );
$this->isDataTable = strpos( $this->params['class'], 'datatable' ) !== false;

$this->htmlTableRenderer = ApplicationFactory::getInstance()->newMwCollaboratorFactory()->newHtmlTableRenderer();
$this->htmlTableRenderer->setHtmlContext( $this->isHTML );
Expand Down Expand Up @@ -98,9 +101,22 @@ protected function getResultText( SMWQueryResult $res, $outputMode ) {
$tableAttrs['width'] = '100%';
}

$this->htmlTableRenderer->transpose( $this->mShowHeaders !== SMW_HEADERS_HIDE && $this->params['transpose'] );
if ( $this->isDataTable ) {
ResourceManager::requireStyle( 'onoi.dataTables.styles' );
ResourceManager::requireResource( 'ext.smw.tableprinter' );
$tableAttrs['width'] = '100%';
// Table is made invisible until the resources are actually loaded
// and until then show a `smw-loading-image-dots`
$tableAttrs['style'] = 'display:none;';
}

$this->htmlTableRenderer->transpose(
$this->mShowHeaders !== SMW_HEADERS_HIDE && $this->params['transpose']
);

return $this->htmlTableRenderer->getHtml( $tableAttrs );
$html = $this->htmlTableRenderer->getHtml( $tableAttrs );

return $this->isDataTable ? Html::rawElement( 'div', array( 'class' => 'smw-datatable smw-loading-image-dots' ), $html ) : $html;
}

/**
Expand Down Expand Up @@ -157,6 +173,10 @@ protected function getCellForPropVals( SMWResultArray $resultArray, $outputMode,
$attributes['data-sort-value'] = $sortKey;
}

if ( $this->isDataTable && $sortKey !== '' ) {
$attributes['data-order'] = $sortKey;
}

$alignment = trim( $resultArray->getPrintRequest()->getParameter( 'align' ) );

if ( in_array( $alignment, array( 'right', 'left', 'center' ) ) ) {
Expand Down
34 changes: 34 additions & 0 deletions res/Resources.php
Expand Up @@ -266,5 +266,39 @@
),
'position' => 'bottom',
'targets' => array( 'mobile', 'desktop' )
),

// TableResultPrinter resource
'ext.smw.tableprinter' => $moduleTemplate + array(
'scripts' => array(
'smw/printer/ext.smw.tableprinter.js'
),
'styles' => array(
'smw/printer/ext.smw.tableprinter.css'
),
'dependencies' => array(
'onoi.dataTables'
),
'position' => 'top',
'messages' => array(
"smw-format-datatable-emptytable",
"smw-format-datatable-info",
"smw-format-datatable-infoempty",
"smw-format-datatable-infofiltered",
"smw-format-datatable-infothousands",
"smw-format-datatable-lengthmenu",
"smw-format-datatable-loadingrecords",
"smw-format-datatable-processing",
"smw-format-datatable-search",
"smw-format-datatable-zerorecords",
"smw-format-datatable-first",
"smw-format-datatable-last",
"smw-format-datatable-next",
"smw-format-datatable-previous",
"smw-format-datatable-sortascending",
"smw-format-datatable-sortdescending"
),
'targets' => array( 'mobile', 'desktop' )
)

);
9 changes: 9 additions & 0 deletions res/smw/ext.smw.css
Expand Up @@ -780,6 +780,15 @@ a.smw-ask-action-btn-lblue:hover {

/* http://stackoverflow.com/questions/6091253/overlay-with-spinner */

.smw-loading-image-dots {
background:
url('data:image/gif;base64,R0lGODlhIgAUAMQRAOjp6dTW19ze3+Xm54iKjevs7IKEh/f396Olp5ianPz8/Judn9fY2YGDhp+ho4CChdHT1P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDoxRThFNDZFQ0RFQjJFMjExQUZCNUREQjU1MEFCRTI5OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozNkVFNURCOUIyREYxMUUyQTBEQUNFNUIzREVGNjg0MyIgeG1wTU06SW5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IfkEBTIAEQAsAAAAACIAFAAABWNgJI5kaZ5oqq5s675wLM90zRaCAJi4biIEAiIFgBghu1HxmBQ5HtCHAyU4QgKk6hE7MkQfBhTDyhWNt6TGt4FaGgckNwQ+WnwXqUEgMFCU9Hx+IwcJUAkHNomKi4yNjo+QKCEAOw==')
no-repeat
left center;
padding: 5px 0 5px 35px;
vertical-align: middle;
}

.smw-overlay-spinner.small{
height: 20px;
width: 20px;
Expand Down