diff --git a/application/libraries/FiltersLib.php b/application/libraries/FiltersLib.php index 48f6c413a..3b719b5f3 100644 --- a/application/libraries/FiltersLib.php +++ b/application/libraries/FiltersLib.php @@ -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'; diff --git a/application/views/organisation/reihungstest/ReihungstestUebersichtData.php b/application/views/organisation/reihungstest/ReihungstestUebersichtData.php index 158a46e3b..719370ab3 100644 --- a/application/views/organisation/reihungstest/ReihungstestUebersichtData.php +++ b/application/views/organisation/reihungstest/ReihungstestUebersichtData.php @@ -111,6 +111,7 @@ ) data ", 'requiredPermissions' => 'infocenter', + 'datasetRepresentation' => 'tablesorter', 'additionalColumns' => array('Details'), 'columnsAliases' => array( 'ReihungstestID', diff --git a/application/views/person/bpk/bpkData.php b/application/views/person/bpk/bpkData.php index f7bf75b50..7e375030f 100644 --- a/application/views/person/bpk/bpkData.php +++ b/application/views/person/bpk/bpkData.php @@ -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', diff --git a/application/views/system/infocenter/infocenterData.php b/application/views/system/infocenter/infocenterData.php index 8922de4c0..9baac9ea6 100644 --- a/application/views/system/infocenter/infocenterData.php +++ b/application/views/system/infocenter/infocenterData.php @@ -232,6 +232,7 @@ 'filterKurzbz' => 'InfoCenterSentApplicationAll', 'filter_id' => $this->input->get('filter_id'), 'requiredPermissions' => 'infocenter', + 'datasetRepresentation' => 'tablesorter', 'customMenu' => true, 'checkboxes' => 'PersonId', 'additionalColumns' => array('Details'), diff --git a/application/views/system/infocenter/infocenterFreigegebenData.php b/application/views/system/infocenter/infocenterFreigegebenData.php index 02981a6c6..b3ee8c9e5 100644 --- a/application/views/system/infocenter/infocenterFreigegebenData.php +++ b/application/views/system/infocenter/infocenterFreigegebenData.php @@ -192,6 +192,7 @@ 'datasetName' => 'freigegeben', 'filter_id' => $this->input->get('filter_id'), 'requiredPermissions' => 'infocenter', + 'datasetRepresentation' => 'tablesorter', 'checkboxes' => 'PersonId', 'additionalColumns' => array('Details'), 'columnsAliases' => array( diff --git a/application/views/system/infocenter/infocenterReihungstestAbsolviertData.php b/application/views/system/infocenter/infocenterReihungstestAbsolviertData.php index 63a2d906c..2a976771b 100644 --- a/application/views/system/infocenter/infocenterReihungstestAbsolviertData.php +++ b/application/views/system/infocenter/infocenterReihungstestAbsolviertData.php @@ -186,6 +186,7 @@ 'datasetName' => 'reihungstestAbsolviert', 'filter_id' => $this->input->get('filter_id'), 'requiredPermissions' => 'infocenter', + 'datasetRepresentation' => 'tablesorter', 'checkboxes' => 'PersonId', 'additionalColumns' => array('Details'), 'columnsAliases' => array( diff --git a/application/views/templates/FHC-Header.php b/application/views/templates/FHC-Header.php index 0e1021da3..785ac0184 100644 --- a/application/views/templates/FHC-Header.php +++ b/application/views/templates/FHC-Header.php @@ -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'); diff --git a/application/views/widgets/filter/filter.php b/application/views/widgets/filter/filter.php index bae5110e9..dc20e58b6 100644 --- a/application/views/widgets/filter/filter.php +++ b/application/views/widgets/filter/filter.php @@ -46,7 +46,7 @@
- +
diff --git a/application/views/widgets/filter/pivotUIDataset.php b/application/views/widgets/filter/pivotUIDataset.php new file mode 100644 index 000000000..570f41ae0 --- /dev/null +++ b/application/views/widgets/filter/pivotUIDataset.php @@ -0,0 +1 @@ +
diff --git a/application/widgets/FilterWidget.php b/application/widgets/FilterWidget.php index 1ae29cb42..86e954e93 100644 --- a/application/widgets/FilterWidget.php +++ b/application/widgets/FilterWidget.php @@ -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 ) ); } diff --git a/public/js/FilterWidget.js b/public/js/FilterWidget.js index 18082b96d..0f1889486 100644 --- a/public/js/FilterWidget.js +++ b/public/js/FilterWidget.js @@ -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(""); $("#appliedFilters").html(""); $("#addFilter").html(""); - $("#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 += "" + record[additionalColumn] + ""; } - }); } @@ -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; + } } };