Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item12870: implement %DATATABLE grid widget
  • Loading branch information
MichaelDaum committed Apr 22, 2016
1 parent f1b88fd commit 1d3c8f2
Show file tree
Hide file tree
Showing 194 changed files with 113,854 additions and 12,214 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -1 +1,10 @@
*.gz
*.swp
attic
JQDataTablesPlugin_installer
JQDataTablesPlugin_installer.pl
JQDataTablesPlugin.md5
JQDataTablesPlugin.sha1
JQDataTablesPlugin.tgz
JQDataTablesPlugin.txt
JQDataTablesPlugin.zip
7 changes: 0 additions & 7 deletions data/Sandbox/PluginTestJQDataTablesPlugin.txt

This file was deleted.

110 changes: 85 additions & 25 deletions data/System/JQDataTablesPlugin.txt
@@ -1,13 +1,73 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1384025482" format="1.1" reprev="3" version="3"}%
%META:TOPICPARENT{name="Plugins"}%
---+!! JQuery Data Tables
%SHORTDESCRIPTION%

%META:TOPICINFO{author="micha" comment="reprev" date="1459412123" format="1.1" reprev="4" version="4"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%

%TOC%

---++ Overview

This plugin implements a widget to enhance normal HTML tables with extra navigation features such as sorting, filtering and paginating through
datasets. The %DATATABLE macro is specifically tailored towards datasets created on the base of [[%SYSTEMWEB%.DataForms][DataForms]]. It lets you
easily compile an overview of data of that kind stored in a web as well as select specific records for further use in wiki apps.

%TOPIC% can be used in two distinct ways:

* by means of the %DATATABLE macro
* by means of HTML5 and JSON to enhance HTML tables directly

%DATATABLE takes a pointer to a !DataForm definition and then creates a table based on the known formfields in that definition to create columns
of a kind matching the formfield types. It then uses a connector fetch the data from the backend. There are several kinds of connectors available
at the moment based on the additional functionality installed on your Foswiki:

* =search=: this one uses the normal native search feature of Foswiki also used by the %SEARCH macro
* =dbcache=: this one uses [[Foswiki:Extensions/DBCachePlugin][DBCachePlugin]] which is implementing a faster still native search, also available via its %DBQUERY macro
* =solr=: this connector uses the [[Foswiki:Extensions/SolrPlugin][SolrPlugin]] which uses a Solr fulltext search engine integrated into Foswiki.

A default connector can be defined as required. Note however, that even though %DATATGABLE tries to hide the differences of available connectors
behind the scene, connectors will behave differently, i.e. when it comes to filtering. Also, performance is vastly different with the =search= connector being the slowest
one. It is strongly recommended that you at least install [[Foswiki:Extensions/DBCachePlugin][DBCachePlugin]] for acceptable performance in every-day usage.

---++ DATATABLE

Syntax: =%<nop>DATATABLE{"&lt;query>" parameter="..." parameter="..." ...}%=

| *Parameter* | *Description* | *Default* |
| =&lt;query>=, =query= | | |
| =class= | | |
| =width= | | |
| =web= | | |
| =form= | | |
| =paging=, =pager= | | |
| =scrolling=, =scroller= | | |
| =searching= | | |
| =searchmode= | | |
| =reverse= | | |
| =info= | | |
| =ordering= | | |
| =scrollx= | | |
| =scrolly= | | |
| =scrollcollapse= | | |
| =searchdelay= | | |
| =sort= | | |
| =lengthmenu= | | |
| =rows= | | |
| =columns= | | |
| =selecting= | | |
| =selectmode= | | |
| =selectproperty= | | |
| =selection= | | |
| =responsive= | | |
| =fixedheader= | | |
| =&lt;field-name>_title= | | |
| =&lt;field-name>_width= | | |
| =connector= | | |

---++ HTML5
Adds paging, searching and formatting to your tables automatically - just add =%<!-- -->JQREQUIRE{"datatables"}%= to your topic or template,
and wrap your tables into a =.jqDataTablesContainer=.

<verbatim class="tml">
<div class="jqDataTablesContainer>
<div class="jqDataTablesContainer">
| *Header* | *Header* | *Header* | *Header* |
| Data | Data | Data | Data |
| Data | Data | Data | Data |
Expand All @@ -16,7 +76,7 @@ and wrap your tables into a =.jqDataTablesContainer=.
</div>
</verbatim>

Use jquery.metadata ={options}= to configure the !DataTable. See http://www.datatables.net/usage/options for a full list of all options.
Use jquery.metadata ={options}= to configure the !DataTable. See http://datatables.net/reference/index for a full list of all options.

Some useful parameters are:

Expand Down Expand Up @@ -78,11 +138,11 @@ Click on the table headers to sort the columns according to their data type.
%STARTSECTION{"example2"}%
<div class="jqDataTablesContainer">
| *#* | *String* | *Date* | *Number* | *Currency* | *Size* |
| 3 | ActionTrackerPlugin | 27 Jan 2010 - 17:07 | 1 | 1,00 | 10KB |
| 1 | AntiWikiSpamPlugin | 03 Jan 2013 - 09:07 | 10 | 10,00 | 3GB |
| 3 | ActionTrackerPlugin | 27 Jan 2010 - 17:07 | 1 | 1,00 | 10KB |
| 1 | AntiWikiSpamPlugin | 03 Jan 2013 - 09:07 | 10 | 10,00 | 3GB |
| 2 | BibtexPlugin | 13 May 2012 - 02:59 | 0.01 | 1,01 | 100MB |
| 5 | CommentPlugin | 10 Apr 2011 - 23:39 | 100 | 0,10 | 2024kB |
| 4 | FindElsewherePlugin | 23 Dec 2012 - 17:06 | 20 | 100,- | 0.1kB |
| 4 | FindElsewherePlugin | 23 Dec 2012 - 17:06 | 20 | 100,- | 0.1kB |
| 6 | FindElsewherePlugin | | 0 | -100,- | 1024TB |
</div>
%ENDSECTION{"example2"}%
Expand All @@ -95,18 +155,10 @@ Click on the table headers to sort the columns according to their data type.
---++ Installation
%$INSTALL_INSTRUCTIONS%

---++ Info
This foswiki plugin encapsulates version 1.9.4 of the http://www.datatables.net/ jQuery plugin.

<!--
* Set SHORTDESCRIPTION = JQuery progressive enhancement of tables
-->
| Author: | Foswiki:Main.SvenDowideit, Foswiki:Main.michaelDaum |
| Copyright: | &copy; 2012, SvenDowideit@fosiki.com, &copy; 2013-2014 Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
---++ Dependencies
%$DEPENDENCIES%

---++ Change History
| 18 Mar 2014: | remove =console.log()= leftover; improve sorting date columns |
| 09 Nov 2013: | implemented sorting for currency, and metrics |
| 08 Nov 2013: | make it work under ={NoConflict}=; \
Expand All @@ -119,6 +171,14 @@ This foswiki plugin encapsulates version 1.9.4 of the http://www.datatables.net/
clean up controls and css classes added by !TablePlugin's; \
added type detector for foswiki date columns |
| 18 Jan 2013: | Initial version |
| Dependencies: | %$DEPENDENCIES% |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| Support: | http://foswiki.org/Support/%TOPIC% |

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Foswiki:Main.SvenDowideit, Foswiki:Main.MichaelDaum"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="2012 SvenDowideit@fosiki.com, 2013-2016 Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
%META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="https://foswiki.org/Support/%25TOPIC%25"}%
116 changes: 113 additions & 3 deletions lib/Foswiki/Plugins/JQDataTablesPlugin.pm
Expand Up @@ -3,21 +3,131 @@ package Foswiki::Plugins::JQDataTablesPlugin;

use strict;
use warnings;

use Assert;
use Error qw(:try);

use Foswiki::Plugins ();
use Foswiki::Plugins::JQueryPlugin ();
use Foswiki::Func ();
use Foswiki::AccessControlException ();

our $VERSION = '2.01';
our $RELEASE = '2.01';
our $VERSION = '2.99';
our $RELEASE = '2.99';
our $SHORTDESCRIPTION = 'JQuery based progressive enhancement of tables';

sub initPlugin {

Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesAutoButtons',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::Buttons' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesAutoFill',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::AutoFill' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesColReorder',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::ColReorder' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesFixedColumns',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::FixedColumns' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTables',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesResponsive',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::Responsive' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesSelect',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::Select' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesFixedHeader',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::FixedHeader' );
Foswiki::Plugins::JQueryPlugin::registerPlugin( 'DataTablesScroller',
'Foswiki::Plugins::JQDataTablesPlugin::DataTables::Scroller' );

# Foswiki::Plugins::JQueryPlugin::registerPlugin('DataTablesJSZip', 'Foswiki::Plugins::JQDataTablesPlugin::DataTables::JSZip');
# Foswiki::Plugins::JQueryPlugin::registerPlugin('DataTablesKeyTable', 'Foswiki::Plugins::JQDataTablesPlugin::DataTables::KeyTable');
# Foswiki::Plugins::JQueryPlugin::registerPlugin('DataTablesPDFMaker', 'Foswiki::Plugins::JQDataTablesPlugin::DataTables::PDFMaker');
# Foswiki::Plugins::JQueryPlugin::registerPlugin('DataTablesRowReorder', 'Foswiki::Plugins::JQDataTablesPlugin::DataTables::RowReorder');

Foswiki::Func::registerTagHandler( 'DATATABLE', \&handleDataTable );
Foswiki::Func::registerRESTHandler(
'connector', \&restConnector,
authenticate => 0,
validate => 0,
http_allow => 'GET,POST',
);

return 1;
}

sub handleDataTable {
my $session = shift;

my $plugin = Foswiki::Plugins::JQueryPlugin::createPlugin('datatables');

return $plugin->handleDataTable(@_) if $plugin;
return '';
}

sub restConnector {
my ( $session, $subject, $verb, $response ) = @_;

my $request = Foswiki::Func::getCgiQuery();

my $connectorID =
$request->param('connector')
|| $Foswiki::cfg{JQDataTablesPlugin}{DefaultConnector}
|| 'search';
my $connectorClass =
$Foswiki::cfg{JQDataTablesPlugin}{Connector}{$connectorID}
|| $Foswiki::cfg{JQDataTablesPlugin}{ExternalConnectors}{$connectorID};

unless ($connectorClass) {
printRESTResult( $response, 500,
"ERROR: unknown connector $connectorID" );
return '';
}

eval "require $connectorClass";
if ($@) {
printRESTResult( $response, 500,
"ERROR: loading connector $connectorID - $@" );
return '';
}

my $connector = $connectorClass->new($session);

my $action = $request->param('oper') || 'search';
try {
if ( $action eq 'edit' ) {
$connector->restHandleSave( $request, $response );
}
else {
$connector->restHandleSearch( $request, $response );
}
}
catch Foswiki::AccessControlException with {
my $error = shift;
printRESTResult( $response, 401,
"ERROR: Unauthorized access to $error->{web}.$error->{topic}" );
}
catch Error::Simple with {
my $error = shift;
printRESTResult( $response, 500, "ERROR: " . $error );
};

return '';
}

sub printRESTResult {
my ( $response, $status, $text ) = @_;

$response->header(
-status => $status,
-type => 'text/plain',
);

$response->print("$text\n");
}

1;
__END__
Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
JQTablePlugin is copyright (C)SvenDowideit@fosiki.com
JQTablePlugin is copyright (C) 2012 SvenDowideit@fosiki.com, 2013-2016 Michael Daum http://michaeldaumconsulting.com
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand Down
34 changes: 27 additions & 7 deletions lib/Foswiki/Plugins/JQDataTablesPlugin/Config.spec
@@ -1,11 +1,31 @@
# ---+ Extensions
# ---++ JQDataTablesPlugin
# ---+++ DataTable Connectors
# **STRING 50**
# Default connector used when no other <code>connector</code> parameter is specified to the <code>%DATATABLE</code> macro.
$Foswiki::cfg{JQDataTablesPlugin}{DefaultConnector} = 'search';

# **STRING 50**
# Implementation handling the default <code>search</code> connector based on Foswiki's standard <code>%SEARCH</code>
# implementation. Note that for adequat performance using jqGrid you are recommended to use a better search algorithm than the default
# grep-based, or use the DBCachePlugin or SolrPlugin backends. See Foswiki::Store::SearchAlgorithms.
$Foswiki::cfg{JQDataTablesPlugin}{Connector}{search} =
'Foswiki::Plugins::JQDataTablesPlugin::SearchConnector';

# **STRING 50**
# Implementation handling the <code>dbcache</code> connector. This will require DBCachePlugin to be installed.
$Foswiki::cfg{JQDataTablesPlugin}{Connector}{dbcache} =
'Foswiki::Plugins::JQDataTablesPlugin::DBCacheConnector';

# **STRING 50**
# Implementation handling the <code>solr</code> connector. This will require SolrPlugin to be installed.
$Foswiki::cfg{JQDataTablesPlugin}{Connector}{solr} =
'Foswiki::Plugins::JQDataTablesPlugin::SolrConnector';

# **PERL**
# Perl hashmap to integrate with custom grid connectors.
$Foswiki::cfg{JQDataTablesPlugin}{ExternalConnectors} = { my_grid_connector =>
'Foswiki::Plugins::MyGridConnectorPlugin::MyConnector' };

1;

# ---+ Extensions
# ---++ JQueryPlugin
# ---+++ Extra plugins
# **STRING**
$Foswiki::cfg{JQueryPlugin}{Plugins}{DataTables}{Module} = 'Foswiki::Plugins::JQDataTablesPlugin::DataTables';
# **BOOLEAN**
$Foswiki::cfg{JQueryPlugin}{Plugins}{DataTables}{Enabled} = 1;

0 comments on commit 1d3c8f2

Please sign in to comment.