diff --git a/application/libraries/FiltersLib.php b/application/libraries/FiltersLib.php index 6346150d8..2af6f15ac 100644 --- a/application/libraries/FiltersLib.php +++ b/application/libraries/FiltersLib.php @@ -65,6 +65,7 @@ class FiltersLib // Different dataset representations const DATASET_REP_TABLESORTER = 'tablesorter'; const DATASET_REP_PIVOTUI = 'pivotUI'; + const DATASET_REP_TABULATOR = 'tabulator'; // Filter operations values const OP_EQUAL = 'equal'; diff --git a/application/views/widgets/filter/tabulatorDataset.php b/application/views/widgets/filter/tabulatorDataset.php new file mode 100644 index 000000000..f5efc50b3 --- /dev/null +++ b/application/views/widgets/filter/tabulatorDataset.php @@ -0,0 +1 @@ +
diff --git a/application/widgets/FilterWidget.php b/application/widgets/FilterWidget.php index 84a4d138b..ff483738a 100644 --- a/application/widgets/FilterWidget.php +++ b/application/widgets/FilterWidget.php @@ -10,6 +10,7 @@ class FilterWidget extends Widget const WIDGET_URL_SELECT_FIELDS = 'widgets/filter/selectFields'; const WIDGET_URL_DATASET_TABLESORTER = 'widgets/filter/tableDataset'; const WIDGET_URL_DATASET_PIVOTUI = 'widgets/filter/pivotUIDataset'; + const WIDGET_URL_DATASET_TABULATOR = 'widgets/filter/tabulatorDataset'; const WIDGET_URL_SELECT_FILTERS = 'widgets/filter/selectFilters'; const WIDGET_URL_SAVE_FILTER = 'widgets/filter/saveFilter'; @@ -137,6 +138,11 @@ class FilterWidget extends Widget { self::_loadView(self::WIDGET_URL_DATASET_PIVOTUI); } + + if (self::$_FilterWidgetInstance->_datasetRepresentation == FiltersLib::DATASET_REP_TABULATOR) + { + self::_loadView(self::WIDGET_URL_DATASET_TABULATOR); + } } //------------------------------------------------------------------------------------------------------------------ @@ -264,7 +270,8 @@ class FilterWidget extends Widget // 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)) + || $args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_PIVOTUI + || $args[FiltersLib::DATASET_REPRESENTATION] == FiltersLib::DATASET_REP_TABULATOR)) { $this->_datasetRepresentation = $args[FiltersLib::DATASET_REPRESENTATION]; } @@ -308,11 +315,15 @@ class FilterWidget extends Widget if (isset($args[FiltersLib::DATASET_REPRESENTATION]) && $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_TABLESORTER - && $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_PIVOTUI) + && $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_PIVOTUI + && $args[FiltersLib::DATASET_REPRESENTATION] != FiltersLib::DATASET_REP_TABULATOR) { show_error( 'The parameter "'.FiltersLib::DATASET_REPRESENTATION. - '" must be IN ("'.FiltersLib::DATASET_REP_TABLESORTER.'", "'.FiltersLib::DATASET_REP_PIVOTUI.'")' + '" must be IN ("' + .FiltersLib::DATASET_REP_TABLESORTER.'", "' + .FiltersLib::DATASET_REP_PIVOTUI.'", "' + .FiltersLib::DATASET_REP_TABULATOR.'")' ); } } diff --git a/public/js/FilterWidget.js b/public/js/FilterWidget.js index 767cd228a..4a075bba1 100644 --- a/public/js/FilterWidget.js +++ b/public/js/FilterWidget.js @@ -69,6 +69,7 @@ function sideMenuHook() // Success const DATASET_REP_TABLESORTER = "tablesorter"; const DATASET_REP_PIVOTUI = "pivotUI"; +const DATASET_REP_TABULATOR = "tabulator"; /** * FHC_FilterWidget this object is used to render the GUI of a filter widget and to operate with it @@ -164,6 +165,12 @@ var FHC_FilterWidget = { { $("#filterPivotUI").html(""); } + + // If the choosen dataset representation is tabulator + if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABULATOR) + { + $("#filterTabulator").html(""); + } }, /** @@ -812,6 +819,12 @@ var FHC_FilterWidget = { { FHC_FilterWidget._renderDatasetPivotUI(data); // ...render the pivotUI GUI } + + // If the choosen dataset representation is tabulator then... + if (FHC_FilterWidget._datasetRepresentation == DATASET_REP_TABULATOR) + { + FHC_FilterWidget._renderDatasetTabulator(data); // ...render the tabulator GUI + } }, /** @@ -934,25 +947,22 @@ var FHC_FilterWidget = { $("#filterTableDataset").trigger("disable"); }, + /** + * Tablesorter filter local storage clean + */ + _cleanTablesorterLocalStorage: function() { + + $("#filterTableDataset").trigger("filterResetSaved"); + }, + /** * 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; - } - } + // Checks if options were given and returns them + var options = FHC_FilterWidget._getRepresentationOptions(data); // Manipulation for the representation! var arrayFieldsToDisplay = FHC_FilterWidget._getFieldsToDisplay(data); @@ -1038,11 +1048,137 @@ var FHC_FilterWidget = { }, /** - * Tablesorter filter local storage clean + * Renders the tabulator for the FilterWidget + * The data to be displayed are retrived from the parameter data */ - _cleanTablesorterLocalStorage: function() { + _renderDatasetTabulator: function(data) { - $("#filterTableDataset").trigger("filterResetSaved"); + // Checks if options were given and returns them + var options = FHC_FilterWidget._getRepresentationOptions(data); + + // Manipulation for the representation! + var arrayFieldsToDisplay = FHC_FilterWidget._getFieldsToDisplayTabulator(data); + + if (arrayFieldsToDisplay.length > 0) + { + // ...if there are data to be displayed... + if (data.hasOwnProperty("dataset") && $.isArray(data.dataset)) + { + if (options == null) options = {}; + + options.columns = arrayFieldsToDisplay; + options.data = data.dataset; + + // Renders the tabulator + var filterTabulator = new Tabulator("#filterTabulator", options); + } + } + }, + + /** + * Retrives the fields to be displayed from the data parameter, if aliases are present then they are used + */ + _getFieldsToDisplay: function(data) { + + var arrayFieldsToDisplay = []; + + if (data.hasOwnProperty("selectedFields") && $.isArray(data.selectedFields)) + { + if (data.hasOwnProperty("columnsAliases") && $.isArray(data.columnsAliases)) + { + for (var sfc = 0; sfc < data.selectedFields.length; sfc++) + { + for (var fc = 0; fc < data.fields.length; fc++) + { + if (data.selectedFields[sfc] == data.fields[fc]) + { + arrayFieldsToDisplay[sfc] = data.columnsAliases[fc]; + } + } + } + } + else + { + arrayFieldsToDisplay = data.selectedFields; + } + } + + return arrayFieldsToDisplay; + }, + + /** + * Retrives the fields to be displayed from the data parameter, if aliases are present then they are used + */ + _getFieldsToDisplayTabulator: function(data) { + + var fieldsToDisplayTabulator = []; + + if (data.hasOwnProperty("selectedFields") && $.isArray(data.selectedFields)) + { + for (var sfc = 0; sfc < data.selectedFields.length; sfc++) + { + for (var fc = 0; fc < data.fields.length; fc++) + { + if (data.selectedFields[sfc] == data.fields[fc]) + { + // Build the array of objects (columns) used by tabulator and store it in tabulatorColumns + var tmpColumnObj = {}; // New object that represents a column + + if (data.hasOwnProperty("columnsAliases") && $.isArray(data.columnsAliases)) + { + tmpColumnObj.title = data.columnsAliases[fc]; + } + else + { + tmpColumnObj.title = data.selectedFields[sfc]; + } + + tmpColumnObj.field = data.selectedFields[sfc]; + + fieldsToDisplayTabulator.push(tmpColumnObj); // Add tmpColumnObj to tabulatorColumns + } + } + } + } + + // If additional columns are present... + if (data.hasOwnProperty("additionalColumns") && data.additionalColumns != null && $.isArray(data.additionalColumns)) + { + // ...loops through them + $.each(data.additionalColumns, function(i, additionalColumn) { + + var tmpColumnObj = {}; // New object that represents a column + + tmpColumnObj.title = additionalColumn; + tmpColumnObj.field = additionalColumn; + + fieldsToDisplayTabulator.push(tmpColumnObj); // Add tmpColumnObj to tabulatorColumns + }); + } + + return fieldsToDisplayTabulator; + }, + + /** + * Gets options for the representation + */ + _getRepresentationOptions: function(data) { + + var options = {}; // eventually contains options fot the representation + + // 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; + } + } + + return options; }, /**