- FilterWidget can represents the retrieved data with tablesorter or pivotUI

- Added new constants to FiltersLib
- Added new parameter pivotui to FHC-Header to load JS and CSS for pivotUI
- Renamed constat WIDGET_URL_TABLE_DATASET to WIDGET_URL_DATASET_TABLESORTER in FilterWidget
- Added new constat WIDGET_URL_DATASET_PIVOTUI to FilterWidget
- Added new private properties _datasetRepresentation and _datasetRepresentationOptions to FilterWidget
- Renamed FilterWidget->loadViewTableDataset to loadViewDataset
- FilterWidget->loadViewDataset loads tablesorter or pivotUI view depending on the value of property _datasetRepresentation
- FilterWidget accepts two new parameter: datasetRepresentation and datasetRepOptions
- datasetRepresentation is required
- FilterWidget stores in session the _datasetRepresentation and _datasetRepresentationOptions properties
- Adapted view views/widgets/filter/filter to use loadViewDataset
- All views using FilterWidget have been adapted to use the required parameter datasetRepresentation
- Added new constats DATASET_REP_TABLESORTER and DATASET_REP_PIVOTUI to public/js/FilterWidget.js
- Added new private property _datasetRepresentation to FHC_FilterWidget in public/js/FilterWidget.js
- Based on property _datasetRepresentation FilterWidget.js will represent the FilterWidget data with tablesorter or pivotUI
- Added new private method _renderDataset to FHC_FilterWidget in public/js/FilterWidget.js
- Renamed method _renderTableDataset to _renderDatasetTablesorter in FHC_FilterWidget in public/js/FilterWidget.js
- Added new method _renderDatasetPivotUI to FHC_FilterWidget in public/js/FilterWidget.js
- Added bew method _setDatasetRepresentation to FHC_FilterWidget in public/js/FilterWidget.js
This commit is contained in:
Paolo
2019-01-11 15:14:53 +01:00
parent a090468126
commit fa9976ec66
11 changed files with 229 additions and 21 deletions
+10
View File
@@ -20,6 +20,8 @@ class FiltersLib
const SESSION_DATASET = 'dataset';
const SESSION_ROW_NUMBER = 'rowNumber';
const SESSION_RELOAD_DATASET = 'reloadDataset';
const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation';
const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions';
// Alias for the dynamic table used to retrive the dataset
const DATASET_TABLE_ALIAS = 'datasetFilterTable';
@@ -55,6 +57,14 @@ class FiltersLib
const CUSTOM_MENU = 'customMenu'; // ...to specify if the menu for this filter is custom (true) or not (false)
// ...to specify how to represent the dataset (ex: tablesorter, pivotUI, ...)
const DATASET_REPRESENTATION = 'datasetRepresentation';
const DATASET_REP_OPTIONS = 'datasetRepOptions';
// Different dataset representations
const DATASET_REP_TABLESORTER = 'tablesorter';
const DATASET_REP_PIVOTUI = 'pivotUI';
// Filter operations values
const OP_EQUAL = 'equal';
const OP_NOT_EQUAL = 'nequal';
@@ -111,6 +111,7 @@
) data
",
'requiredPermissions' => 'infocenter',
'datasetRepresentation' => 'tablesorter',
'additionalColumns' => array('Details'),
'columnsAliases' => array(
'ReihungstestID',
+1
View File
@@ -13,6 +13,7 @@
person_id=tbl_person.person_id AND tbl_benutzer.aktiv=true)
',
'requiredPermissions' => 'admin',
'datasetRepresentation' => 'tablesorter',
'additionalColumns' => array('Details'),
'columnsAliases' => array(
'PersonID',
@@ -232,6 +232,7 @@
'filterKurzbz' => 'InfoCenterSentApplicationAll',
'filter_id' => $this->input->get('filter_id'),
'requiredPermissions' => 'infocenter',
'datasetRepresentation' => 'tablesorter',
'customMenu' => true,
'checkboxes' => 'PersonId',
'additionalColumns' => array('Details'),
@@ -192,6 +192,7 @@
'datasetName' => 'freigegeben',
'filter_id' => $this->input->get('filter_id'),
'requiredPermissions' => 'infocenter',
'datasetRepresentation' => 'tablesorter',
'checkboxes' => 'PersonId',
'additionalColumns' => array('Details'),
'columnsAliases' => array(
@@ -186,6 +186,7 @@
'datasetName' => 'reihungstestAbsolviert',
'filter_id' => $this->input->get('filter_id'),
'requiredPermissions' => 'infocenter',
'datasetRepresentation' => 'tablesorter',
'checkboxes' => 'PersonId',
'additionalColumns' => array('Details'),
'columnsAliases' => array(
@@ -26,6 +26,7 @@
$navigationwidget = isset($navigationwidget) ? $navigationwidget : false;
$sbadmintemplate = isset($sbadmintemplate) ? $sbadmintemplate : false;
$tablesorter = isset($tablesorter) ? $tablesorter : false;
$pivotui = isset($pivotui) ? $pivotui : false;
$tinymce = isset($tinymce) ? $tinymce : false;
?>
@@ -60,6 +61,12 @@
generateCSSsInclude('vendor/mottie/tablesorter/dist/css/jquery.tablesorter.pager.min.css');
}
// PivotUI CSS
if ($pivotui === true)
{
generateCSSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.css');
}
// SB Admin 2 template CSS
if ($sbadmintemplate === true)
{
@@ -121,6 +128,12 @@
generateJSsInclude('vendor/mottie/tablesorter/dist/js/extras/jquery.tablesorter.pager.min.js');
}
// PivotUI CSS
if ($pivotui === true)
{
generateJSsInclude('vendor/nicolaskruchten/pivottable/dist/pivot.min.js');
}
// Tinymce JS
if ($tinymce === true) generateJSsInclude('vendor/tinymce/tinymce/tinymce.min.js');
+1 -1
View File
@@ -46,7 +46,7 @@
<!-- Filter table -->
<div>
<?php FilterWidget::loadViewTableDataset(); ?>
<?php FilterWidget::loadViewDataset(); ?>
</div>
<!-- Filter info bottom -->
@@ -0,0 +1 @@
<div id="filterPivotUI"></div>
+55 -11
View File
@@ -8,7 +8,8 @@ class FilterWidget extends Widget
// Paths of the views
const WIDGET_URL_FILTER = 'widgets/filter/filter';
const WIDGET_URL_SELECT_FIELDS = 'widgets/filter/selectFields';
const WIDGET_URL_TABLE_DATASET = 'widgets/filter/tableDataset';
const WIDGET_URL_DATASET_TABLESORTER = 'widgets/filter/tableDataset';
const WIDGET_URL_DATASET_PIVOTUI = 'widgets/filter/pivotUIDataset';
const WIDGET_URL_SELECT_FILTERS = 'widgets/filter/selectFilters';
const WIDGET_URL_SAVE_FILTER = 'widgets/filter/saveFilter';
@@ -45,6 +46,9 @@ class FilterWidget extends Widget
private $_customMenu; // if true then method _setFilterMenu is NOT called
private $_datasetRepresentation; // dataset representation (ex: tablesorter, pivotUI, ...)
private $_datasetRepresentationOptions; // dataset representation options for tablesorter, pivotUI, ...
private static $_FilterWidgetInstance; // static property that contains the instance of itself
/**
@@ -119,11 +123,19 @@ class FilterWidget extends Widget
}
/**
* Loads the view related to the table dataset
* Loads the view related to the dataset, here is decided how to represent the dataset (ex: tablesorter, pivotUI, ...)
*/
public static function loadViewTableDataset()
public static function loadViewDataset()
{
self::_loadView(self::WIDGET_URL_TABLE_DATASET);
if (self::$_FilterWidgetInstance->_datasetRepresentation == FiltersLib::DATASET_REP_TABLESORTER)
{
self::_loadView(self::WIDGET_URL_DATASET_TABLESORTER);
}
if (self::$_FilterWidgetInstance->_datasetRepresentation == FiltersLib::DATASET_REP_PIVOTUI)
{
self::_loadView(self::WIDGET_URL_DATASET_PIVOTUI);
}
}
//------------------------------------------------------------------------------------------------------------------
@@ -153,6 +165,8 @@ class FilterWidget extends Widget
$this->_hideHeader = null;
$this->_hideSave = null;
$this->_customMenu = null;
$this->_datasetRepresentation = null;
$this->_datasetRepresentationOptions = null;
// Retrived the required permissions parameter if present
if (isset($args[FiltersLib::REQUIRED_PERMISSIONS_PARAMETER]))
@@ -234,10 +248,25 @@ class FilterWidget extends Widget
$this->_hideSave = $args[FiltersLib::HIDE_SAVE];
}
// If a custom menu is set
if (isset($args[FiltersLib::CUSTOM_MENU]) && is_bool($args[FiltersLib::CUSTOM_MENU]))
{
$this->_customMenu = $args[FiltersLib::CUSTOM_MENU];
}
// To specify how to represent the dataset (ex: tablesorter, pivotUI, ...)
if (isset($args[FiltersLib::DATASET_REPRESENTATION])
&& ($args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_TABLESORTER
|| $args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_PIVOTUI))
{
$this->_datasetRepresentation = $args[FiltersLib::DATASET_REPRESENTATION];
}
// To specify options for the dataset representation (ex: tablesorter, pivotUI, ...)
if (isset($args[FiltersLib::DATASET_REP_OPTIONS]) && !isEmptyString($args[FiltersLib::DATASET_REP_OPTIONS]))
{
$this->_datasetRepresentationOptions = $args[FiltersLib::DATASET_REP_OPTIONS];
}
}
/**
@@ -247,7 +276,7 @@ class FilterWidget extends Widget
{
if (!is_array($args) || (is_array($args) && count($args) == 0))
{
show_error('Second parameter of the widget call must be a not empty associative array');
show_error('Second parameter of the widget call must be a NOT empty associative array');
}
else
{
@@ -259,12 +288,25 @@ class FilterWidget extends Widget
FiltersLib::FILTER_ID.'" must be specified'
);
}
else
if (!isset($args[FiltersLib::QUERY_PARAMETER]))
{
if (!isset($args[FiltersLib::QUERY_PARAMETER]))
{
show_error('The parameters "'.FiltersLib::QUERY_PARAMETER.'" must be specified');
}
show_error('The parameters "'.FiltersLib::QUERY_PARAMETER.'" must be specified');
}
if (!isset($args[FiltersLib::DATASET_REPRESENTATION]))
{
show_error('The parameter "'.FiltersLib::DATASET_REPRESENTATION.'" must be specified');
}
if (isset($args[FiltersLib::DATASET_REPRESENTATION])
&& $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_TABLESORTER
&& $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_PIVOTUI)
{
show_error(
'The parameter "'.FiltersLib::DATASET_REPRESENTATION.
'" must be IN ("'.FiltersLib::DATASET_REP_TABLESORTER.'", "'.FiltersLib::DATASET_REP_PIVOTUI.'")'
);
}
}
}
@@ -370,7 +412,9 @@ class FilterWidget extends Widget
FiltersLib::SESSION_METADATA => $this->FiltersModel->getExecutedQueryMetaData(), // the metadata of the dataset
FiltersLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this filter
FiltersLib::SESSION_DATASET => $dataset->retval, // the entire dataset
FiltersLib::SESSION_RELOAD_DATASET => false // if the dataset must be reloaded, not needed the first time
FiltersLib::SESSION_RELOAD_DATASET => false, // if the dataset must be reloaded, not needed the first time
FiltersLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation
FiltersLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions // the choosen dataset representation options
)
);
}
+144 -9
View File
@@ -63,10 +63,23 @@ function sideMenuHook()
});
}
//--------------------------------------------------------------------------------------------------------------------
// Constants
// Success
const DATASET_REP_TABLESORTER = "tablesorter";
const DATASET_REP_PIVOTUI = "pivotUI";
/**
* FHC_FilterWidget this object is used to render the GUI of a filter widget and to operate with it
*/
var FHC_FilterWidget = {
//------------------------------------------------------------------------------------------------------------------
// Properties
_datasetRepresentation: null, //
//------------------------------------------------------------------------------------------------------------------
// Public methods
@@ -138,8 +151,19 @@ var FHC_FilterWidget = {
$("#addField").html("<option value=''>" + FHC_PhrasesLib.t("ui", "bitteEintragWaehlen") + "</option>");
$("#appliedFilters").html("");
$("#addFilter").html("<option value=''>" + FHC_PhrasesLib.t("ui", "bitteEintragWaehlen") + "</option>");
$("#filterTableDataset > thead > tr").html("");
$("#filterTableDataset > tbody").html("");
// If the choosen dataset representation is tablesorter
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABLESORTER)
{
$("#filterTableDataset > thead > tr").html("");
$("#filterTableDataset > tbody").html("");
}
// If the choosen dataset representation is pivotUI
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_PIVOTUI)
{
$("#filterPivotUI").html("");
}
},
/**
@@ -155,6 +179,7 @@ var FHC_FilterWidget = {
},
{
successCallback: function(data, textStatus, jqXHR) {
if (FHC_AjaxClient.hasData(data))
{
if (typeof renderFunction == "function")
@@ -180,6 +205,9 @@ var FHC_FilterWidget = {
_renderFilterWidget: function(data) {
FHC_FilterWidget._initSessionStorage(); // initialize the session storage
FHC_FilterWidget._setDatasetRepresentation(data); // set what type of dataset representation was choosen
FHC_FilterWidget._turnOffEvents(); // turns all the events off
FHC_FilterWidget._resetGUI(); // Reset the entire GUI
@@ -189,7 +217,7 @@ var FHC_FilterWidget = {
FHC_FilterWidget._renderDropDownFields(data); // render the fields drop-down
FHC_FilterWidget._renderAppliedFilters(data); // render the GUI for the applied filters
FHC_FilterWidget._renderDropDownFilters(data); // render the filters drop-down
FHC_FilterWidget._renderTableDataset(data); // render the table GUI
FHC_FilterWidget._renderDataset(data);
FHC_FilterWidget._turnOnEvents(); // turns all the events off
},
@@ -230,7 +258,12 @@ var FHC_FilterWidget = {
$("#addFilter").off("change");
$("#applyFilter").off("click");
$("#saveCustomFilterButton").off("click");
FHC_FilterWidget._disableTableSorter();
// If the choosen dataset representation is tablesorter
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABLESORTER)
{
FHC_FilterWidget._disableTableSorter(); // disable the tablesorter
}
},
/**
@@ -249,7 +282,12 @@ var FHC_FilterWidget = {
$("#addFilter").change(FHC_FilterWidget._addFilterEvent); // Click event on the applied filters drop-down to add a new filter to the dataset
$("#applyFilter").click(FHC_FilterWidget._applyFilterEvent); // Click event on the applied filters drop-down to apply filters to the dataset
$("#saveCustomFilterButton").click(FHC_FilterWidget._saveCustomFilterButtonEvent); // Click evento to for the save custom filter button
FHC_FilterWidget._enableTableSorter(); // enable the tablesorter
// If the choosen dataset representation is tablesorter
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABLESORTER)
{
FHC_FilterWidget._enableTableSorter(); // enable the tablesorter
}
},
/**
@@ -761,11 +799,26 @@ var FHC_FilterWidget = {
return html;
},
_renderDataset: function(data) {
// If the choosen dataset representation is tablesorter then...
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABLESORTER)
{
FHC_FilterWidget._renderDatasetTablesorter(data); // ...render the tablesorter GUI
}
// If the choosen dataset representation is pivotUI then...
if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_PIVOTUI)
{
FHC_FilterWidget._renderDatasetPivotUI(data); // ...render the pivotUI GUI
}
},
/**
* Renders the table for the FilterWidget
* Renders the tablesorter for the FilterWidget
* The data to be displayed are retrived from the parameter data
*/
_renderTableDataset: function(data) {
_renderDatasetTablesorter: function(data) {
if (data.hasOwnProperty("checkboxes") && data.checkboxes!=null && data.checkboxes.trim() != "")
{
@@ -823,7 +876,6 @@ var FHC_FilterWidget = {
{
strHtml += "<td>" + record[additionalColumn] + "</td>";
}
});
}
@@ -853,7 +905,7 @@ var FHC_FilterWidget = {
}
});
// reset filter storage if there is a filter id in url TODO: find better solution
// Reset filter storage if there is a filter id in url TODO: find better solution
var filter_id = FHC_AjaxClient.getUrlParameter("filter_id");
if (typeof filter_id !== "undefined") FHC_FilterWidget._cleanTablesorterLocalStorage();
@@ -869,6 +921,78 @@ var FHC_FilterWidget = {
$("#filterTableDataset").trigger("disable");
},
/**
* Renders the pivotUI for the FilterWidget
* The data to be displayed are retrived from the parameter data
*/
_renderDatasetPivotUI: function(data) {
var options = {}; // eventually contains options fot the pivotUI
// Checks if options were given
if (data.hasOwnProperty("datasetRepresentationOptions") && data.datasetRepresentationOptions != "")
{
var tmpOptions = eval("(" + data.datasetRepresentationOptions + ")"); // and converts them from string to javascript code
// If it is an object then can be used
if (typeof tmpOptions == "object")
{
options = tmpOptions;
}
}
// Manipulation for the representation!
var arrayFieldsToDisplay = FHC_FilterWidget._getFieldsToDisplay(data);
// If there are fields to be displayed...
if (arrayFieldsToDisplay.length > 0)
{
// ...if there are data to be displayed...
if (data.hasOwnProperty("dataset") && $.isArray(data.dataset))
{
// Build the array of objects used by pivotUI and store it in pivotUIData
var pivotUIData = [];
// Loops through data
for (var i = 0; i < data.dataset.length; i++)
{
var record = data.dataset[i]; // Single record
var tmpObj = {}; // New object that represents a record
// Loops through columns of a record
$.each(arrayFieldsToDisplay, function(i, fieldToDisplay) {
if (record.hasOwnProperty(data.selectedFields[i]))
{
tmpObj[fieldToDisplay] = record[data.selectedFields[i]]; // Add data with the column alias
}
});
// If additional columns are present...
if (data.additionalColumns != null && $.isArray(data.additionalColumns))
{
// ...loops through them
$.each(data.additionalColumns, function(i, additionalColumn) {
if (record.hasOwnProperty(additionalColumn))
{
tmpObj[additionalColumn] = record[additionalColumn]; // Add the additional column
}
});
}
pivotUIData.push(tmpObj); // Add tmpObj to pivotUIData
}
// Renders the pivotUI
$("#filterPivotUI").pivotUI(
pivotUIData,
options
);
}
}
},
/**
* Retrives the fields to be displayed from the data parameter, if aliases are present then they are used
*/
@@ -906,6 +1030,17 @@ var FHC_FilterWidget = {
_cleanTablesorterLocalStorage: function() {
$("#filterTableDataset").trigger("filterResetSaved");
},
/**
* Set what type of dataset representation was choosen
*/
_setDatasetRepresentation: function(data) {
if (data.hasOwnProperty("datasetRepresentation"))
{
FHC_FilterWidget._datasetRepresentation = data.datasetRepresentation;
}
}
};