diff --git a/application/components/filters/LogsViewer.php b/application/components/filters/LogsViewer.php index 79e97f366..3a5390273 100644 --- a/application/components/filters/LogsViewer.php +++ b/application/components/filters/LogsViewer.php @@ -1,5 +1,8 @@ 'core', + 'datasetName' => 'logs', + //'filterKurzbz' => 'jobs48hours', // REMOVE ME 'query' => ' SELECT wsl.webservicelog_id AS "LogId", wsl.request_id AS "RequestId", @@ -11,51 +14,6 @@ FROM system.tbl_webservicelog wsl ORDER BY wsl.execute_time DESC ', - 'requiredPermissions' => 'admin', - 'datasetRepresentation' => 'tablesorter', - 'columnsAliases' => array( - 'Log id', - 'Request id', - 'Execution time', - 'Executed by', - 'Producer', - 'Data', - 'Webservice type' - ), - 'formatRow' => function($datasetRaw) { - - $datasetRaw->ExecutionTime = date_format(date_create($datasetRaw->ExecutionTime), 'd.m.Y H:i:s:u'); - - return $datasetRaw; - }, - 'markRow' => function($datasetRaw) { - - $mark = ''; - - if (strpos($datasetRaw->RequestId, 'error') != false) - { - $mark = 'text-red'; - } - - if (strpos($datasetRaw->RequestId, 'info') != false) - { - $mark = 'text-green'; - } - - if (strpos($datasetRaw->RequestId, 'warning') != false) - { - $mark = 'text-orange'; - } - - if (strpos($datasetRaw->RequestId, 'debug') != false) - { - $mark = 'text-info'; - } - - return $mark; - } + 'requiredPermissions' => 'admin' ); - $filterCmptArray['app'] = 'core'; - $filterCmptArray['datasetName'] = 'logs'; - diff --git a/application/controllers/components/Filter.php b/application/controllers/components/Filter.php index 94a3967ed..6d5df98b7 100644 --- a/application/controllers/components/Filter.php +++ b/application/controllers/components/Filter.php @@ -26,10 +26,7 @@ class Filter extends FHC_Controller $this->load->library('AuthLib'); // Loads the FilterCmptLib with HTTP GET/POST parameters - $this->_loadFilterCmptLib(); - - // Checks if the caller is allow to read this data - $this->_isAllowed(); + $this->_startFilterCmptLib(); } //------------------------------------------------------------------------------------------------------------------ @@ -43,22 +40,6 @@ class Filter extends FHC_Controller $this->outputJsonSuccess($this->filtercmptlib->getSession()); } - /** - * Retrieves the number of records present in the current dataset and will be written on the output in JSON format - */ - public function rowNumber() - { - $rowNumber = 0; - $dataset = $this->filtercmptlib->getSessionElement(FilterCmptLib::SESSION_DATASET); - - if (isset($dataset) && is_array($dataset)) - { - $rowNumber = count($dataset); - } - - $this->outputJsonSuccess($rowNumber); - } - /** * Change the sort of the selected fields of the current filter and * its data will be written on the output in JSON format @@ -87,11 +68,11 @@ class Filter extends FHC_Controller if ($this->filtercmptlib->removeSelectedField($selectedField) == true) { - $this->getFilter(); + $this->outputJsonSuccess('Field removed'); } else { - $this->outputJsonError('Wrong parameter'); + $this->outputJsonError('Error occurred'); } } @@ -104,70 +85,62 @@ class Filter extends FHC_Controller if ($this->filtercmptlib->addSelectedField($selectedField) == true) { - $this->getFilter(); + $this->outputJsonSuccess('Field added'); } else { - $this->outputJsonError('Wrong parameter'); + $this->outputJsonError('Error occurred'); } } /** * Remove an applied filter (SQL where condition) from the current filter */ - public function removeAppliedFilter() + public function removeFilterField() { - $appliedFilter = $this->input->post('appliedFilter'); + $appliedFilter = $this->input->post('filterField'); - if ($this->filtercmptlib->removeAppliedFilter($appliedFilter) == true) + if ($this->filtercmptlib->removeFilterField($appliedFilter) == true) { - $this->outputJsonSuccess('Removed'); + $this->outputJsonSuccess('Field removed'); } else { - $this->outputJsonError('Wrong parameter'); - } - } - - /** - * Apply all the applied filters (SQL where conditions) to the current filter - */ - public function applyFilters() - { - $appliedFilters = $this->input->post('appliedFilters'); - $appliedFiltersOperations = $this->input->post('appliedFiltersOperations'); - $appliedFiltersConditions = $this->input->post('appliedFiltersConditions'); - $appliedFiltersOptions = $this->input->post('appliedFiltersOptions'); - - if ($this->filtercmptlib->applyFilters( - $appliedFilters, - $appliedFiltersOperations, - $appliedFiltersConditions, - $appliedFiltersOptions - ) == true) - { - $this->outputJsonSuccess('Applied'); - } - else - { - $this->outputJsonError('Wrong parameter'); + $this->outputJsonError('Error occurred'); } } /** * Add a filter (SQL where clause) to be applied to the current filter */ - public function addFilter() + public function addFilterField() { - $filter = $this->input->post('filter'); + $filterField = $this->input->post('filterField'); - if ($this->filtercmptlib->addFilter($filter) == true) + if ($this->filtercmptlib->addFilterField($filterField) == true) { - $this->getFilter(); + $this->outputJsonSuccess('Field added'); } else { - $this->outputJsonError('Wrong parameter'); + $this->outputJsonError('Error occurred'); + } + } + + /** + * Apply the filter changes + */ + public function applyFilterFields() + { + $filterFields = $this->input->post('filterFields'); + + if ($this->filtercmptlib->applyFilterFields($filterFields) == true) + { + $this->outputJsonSuccess('Applied'); + } + else + { + $this->outputJsonError('Error occurred'); } } @@ -176,9 +149,9 @@ class Filter extends FHC_Controller */ public function saveCustomFilter() { - $customFilterDescription = $this->input->post('customFilterDescription'); + $customFilterName = $this->input->post('customFilterName'); - if ($this->filtercmptlib->saveCustomFilter($customFilterDescription) == true) + if ($this->filtercmptlib->saveCustomFilter($customFilterName) == true) { $this->outputJsonSuccess('Saved'); } @@ -215,41 +188,22 @@ class Filter extends FHC_Controller $this->outputJsonSuccess('Success'); } - /** - * Define the navigation menu for the current filter widget - */ - public function generateFilterMenu() - { - // Generates the filters menu - $this->outputJsonSuccess($this->filtercmptlib->generateFilterMenu($this->input->get(FilterCmptLib::NAVIGATION_PAGE))); - } - //------------------------------------------------------------------------------------------------------------------ // Private methods - /** - * Checks if the user is allowed to use this filter - */ - private function _isAllowed() - { - if (!$this->filtercmptlib->isAllowed()) - { - $this->terminateWithJsonError('You are not allowed to access to this content'); - } - } - /** * Loads the FilterCmptLib with the FILTER_UNIQUE_ID parameter * If the parameter FILTER_UNIQUE_ID is not given then the execution of the controller is terminated and * an error message is printed */ - private function _loadFilterCmptLib() + private function _startFilterCmptLib() { + $filterUniqueId = null; + $filterType = null; + // If the parameter FILTER_UNIQUE_ID is present in the HTTP GET or POST if (isset($_GET[self::FILTER_UNIQUE_ID]) || isset($_POST[self::FILTER_UNIQUE_ID])) { - $filterUniqueId = null; - // If it is present in the HTTP GET if (isset($_GET[self::FILTER_UNIQUE_ID])) { @@ -259,22 +213,15 @@ class Filter extends FHC_Controller { $filterUniqueId = $this->input->post(self::FILTER_UNIQUE_ID); // is retrieved from the HTTP POST } - - // Loads the FilterCmptLib that contains all the used logic - $this->load->library('FilterCmptLib'); - - $this->filtercmptlib->setFilterUniqueId($filterUniqueId); } else // Otherwise an error will be written in the output { $this->terminateWithJsonError('Parameter "'.self::FILTER_UNIQUE_ID.'" not provided!'); } - // If provided + // If the parameter FILTER_TYPE is present in the HTTP GET or POST if (isset($_GET[self::FILTER_TYPE]) || isset($_POST[self::FILTER_TYPE])) { - $filterType = null; - // If it is present in the HTTP GET if (isset($_GET[self::FILTER_TYPE])) { @@ -284,11 +231,24 @@ class Filter extends FHC_Controller { $filterType = $this->input->post(self::FILTER_TYPE); // is retrieved from the HTTP POST } - - $this->filtercmptlib->setFilterType($filterType); + } + else // Otherwise an error will be written in the output + { + $this->terminateWithJsonError('Parameter "'.self::FILTER_TYPE.'" not provided!'); } - $this->filtercmptlib->setFilterId($this->input->get('filterId')); + // Loads the FilterCmptLib that contains all the used logic + $this->load->library( + 'FilterCmptLib', + array( + 'filterUniqueId' => $filterUniqueId, + 'filterType' => $filterType, + 'filterId' => $this->input->get('filter_id') + ) + ); + + // + $this->filtercmptlib->start(); } } diff --git a/application/libraries/FilterCmptLib.php b/application/libraries/FilterCmptLib.php index 53020d358..5e413aee8 100644 --- a/application/libraries/FilterCmptLib.php +++ b/application/libraries/FilterCmptLib.php @@ -14,9 +14,6 @@ class FilterCmptLib const SESSION_FILTER_NAME = 'filterName'; const SESSION_FIELDS = 'fields'; const SESSION_SELECTED_FIELDS = 'selectedFields'; - const SESSION_COLUMNS_ALIASES = 'columnsAliases'; - const SESSION_ADDITIONAL_COLUMNS = 'additionalColumns'; - const SESSION_CHECKBOXES = 'checkboxes'; const SESSION_FILTERS = 'filters'; const SESSION_METADATA = 'datasetMetadata'; const SESSION_ROW_NUMBER = 'rowNumber'; @@ -25,9 +22,8 @@ class FilterCmptLib // Session dataset elements const SESSION_DATASET = 'dataset'; const SESSION_DATASET_RELOAD = 'reloadDataset'; - const SESSION_DATASET_REPRESENTATION = 'datasetRepresentation'; - const SESSION_DATASET_REP_OPTIONS = 'datasetRepresentationOptions'; - const SESSION_DATASET_REP_FIELDS_DEFS = 'datasetRepresentationFieldsDefinitions'; + + const SESSION_SIDE_MENU = 'sideMenu'; // Default session timeout const SESSION_DEFAULT_TIMEOUT = 30; @@ -52,34 +48,6 @@ class FilterCmptLib // ...stament to retrieve the dataset const QUERY = 'query'; - // ...to specify more columns or aliases for them - const ADDITIONAL_COLUMNS = 'additionalColumns'; - const CHECKBOXES = 'checkboxes'; - const COLUMNS_ALIASES = 'columnsAliases'; - - // ...to format/mark records of a dataset - const FORMAT_ROW = 'formatRow'; - const MARK_ROW = 'markRow'; - - // ...to hide the options for a filter - const HIDE_OPTIONS = 'hideOptions'; - const HIDE_SELECT_FIELDS = 'hideSelectFields'; - const HIDE_SELECT_FILTERS = 'hideSelectFilters'; - const HIDE_SAVE = 'hideSave'; - - const CUSTOM_MENU = 'customMenu'; // ...to specify if the menu for this filter is custom (true) or not (false) - const HIDE_MENU = 'hideMenu'; // ...to specify if the menu should be shown or not - - // ...to specify how to represent the dataset (ex: tablesorter, pivotUI, ...) - const DATASET_REPRESENTATION = 'datasetRepresentation'; - const DATASET_REP_OPTIONS = 'datasetRepOptions'; - const DATASET_REP_FIELDS_DEFS = 'datasetRepFieldsDefs'; - - // 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'; const OP_NOT_EQUAL = 'nequal'; @@ -105,20 +73,39 @@ class FilterCmptLib const PERMISSION_FILTER_METHOD = 'FilterCmpt'; // Name for fake method to be checked by the PermissionLib const PERMISSION_TYPE = 'r'; - // Navigation page parameter name - const NAVIGATION_PAGE = 'navigation_page'; - private $_ci; // Code igniter instance - private $_filterUniqueId; // unique id for this filter component + + private $_filterUniqueId; // Unique id for this filter component private $_filterType; // private $_filterId; // + private $_app; + private $_datasetName; + private $_filterKurzbz; + private $_query; + private $_requiredPermissions; + private $_reloadDataset; + private $_sessionTimeout; + /** * Gets the CI instance and loads message helper */ - public function __construct($params = null) + public function __construct($params) { $this->_ci =& get_instance(); // get code igniter instance + + // Set parameters + $this->_setParameters($params); + } + + /** + * + */ + private function _setParameters($params) + { + if (isset($params['filterUniqueId'])) $this->_filterUniqueId = $params['filterUniqueId']; + if (isset($params['filterType'])) $this->_filterType = $params['filterType']; + if (isset($params['filterId'])) $this->_filterId = $params['filterId']; } //------------------------------------------------------------------------------------------------------------------ @@ -131,25 +118,17 @@ class FilterCmptLib * then NO one is allow to use this FilterCmpt * Wrapper method to permissionlib->hasAtLeastOne */ - public function isAllowed() + private function _isAllowed() { $this->_ci->load->library('PermissionLib'); // Load permission library - // Gets the required permissions from the session if they are not provided as parameter - $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS); - - // - if ($rq == null) + if (!$this->_ci->permissionlib->hasAtLeastOne($this->_requiredPermissions, self::PERMISSION_FILTER_METHOD, self::PERMISSION_TYPE)) { - // - $this->_initFilterCmpt(); - // - $this->_startFilterCmpt(); - // Gets the required permissions from the session if they are not provided as parameter - $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS); + $this->setSession(error('The required permission is not help by the logged user')); + return false; } - return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_FILTER_METHOD, self::PERMISSION_TYPE); + return true; } /** @@ -433,6 +412,35 @@ class FilterCmptLib return $sortSelectedFields; } + /** + * Add a field to the current filter + */ + public function addSelectedField($selectedField) + { + $removeSelectedField = false; + + // Checks the parameter selectedField + if (!isEmptyString($selectedField)) + { + // Retrieves all the used fields by the current filter + $fields = $this->getSessionElement(self::SESSION_FIELDS); + // Retrieves the selected fields by the current filter + $selectedFields = $this->getSessionElement(self::SESSION_SELECTED_FIELDS); + + // Checks that the given selected field is present in the list of all the used fields by the current filter + if (in_array($selectedField, $fields)) + { + array_push($selectedFields, $selectedField); // place the new filed at the end of the selected fields list + + $this->setSessionElement(self::SESSION_SELECTED_FIELDS, $selectedFields); // write changes into the session + + $removeSelectedField = true; + } + } + + return $removeSelectedField; + } + /** * Remove a selected field from the current filter */ @@ -468,43 +476,14 @@ class FilterCmptLib } /** - * Add a field to the current filter + * Add a filter (SQL where clause) to be applied to the current filter */ - public function addSelectedField($selectedField) + public function addFilterField($filterField) { - $removeSelectedField = false; + $addFilterField = false; - // Checks the parameter selectedField - if (!isEmptyString($selectedField)) - { - // Retrieves all the used fields by the current filter - $fields = $this->getSessionElement(self::SESSION_FIELDS); - // Retrieves the selected fields by the current filter - $selectedFields = $this->getSessionElement(self::SESSION_SELECTED_FIELDS); - - // Checks that the given selected field is present in the list of all the used fields by the current filter - if (in_array($selectedField, $fields)) - { - array_push($selectedFields, $selectedField); // place the new filed at the end of the selected fields list - - $this->setSessionElement(self::SESSION_SELECTED_FIELDS, $selectedFields); // write changes into the session - - $removeSelectedField = true; - } - } - - return $removeSelectedField; - } - - /** - * Remove an applied filter (SQL where condition) from the current filter - */ - public function removeAppliedFilter($appliedFilter) - { - $removeAppliedFilter = false; - - // Checks the parameter appliedFilter - if (!isEmptyString($appliedFilter)) + // Checks the parameter filter + if (!isEmptyString($filterField)) { // Retrieves all the used fields by the current filter $fields = $this->getSessionElement(self::SESSION_FIELDS); @@ -512,10 +491,53 @@ class FilterCmptLib $filters = $this->getSessionElement(self::SESSION_FILTERS); // Checks that the given applied filter is present in the list of all the used fields by the current filter - if (in_array($appliedFilter, $fields)) + if (in_array($filterField, $fields)) { // Search in what position the given applied filter is - $pos = $this->_searchFilterByName($filters, $appliedFilter); + $pos = $this->_searchFilterByName($filters, $filterField); + if ($pos === false) // If NOT found then add it + { + // New filter definition + $filterDefinition = new stdClass(); + // Sets filter definition required properties + $filterDefinition->name = $filterField; + // Sets filter definition optional properties + $filterDefinition->operation = null; + $filterDefinition->condition = null; + $filterDefinition->option = null; + // Place the new applied filter at the end of the applied filters list + array_push($filters, $filterDefinition); + } + + $this->setSessionElement(self::SESSION_FILTERS, $filters); // write changes into the session + + $addFilterField = true; + } + } + + return $addFilterField; + } + + /** + * Remove an applied filter (SQL where condition) from the current filter + */ + public function removeFilterField($filterField) + { + $removeFilterField = false; + + // Checks the parameter filterField + if (!isEmptyString($filterField)) + { + // Retrieves all the used fields by the current filter + $fields = $this->getSessionElement(self::SESSION_FIELDS); + // Retrieves the applied filters by the current filter + $filters = $this->getSessionElement(self::SESSION_FILTERS); + + // Checks that the given applied filter is present in the list of all the used fields by the current filter + if (in_array($filterField, $fields)) + { + // Search in what position the given applied filter is + $pos = $this->_searchFilterByName($filters, $filterField); if ($pos !== false) // If found { array_splice($filters, $pos, 1); // Then remove it and shift the rest of elements by one if needed @@ -525,54 +547,68 @@ class FilterCmptLib $this->setSessionElement(self::SESSION_FILTERS, $filters); $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded - $removeAppliedFilter = true; + $removeFilterField = true; } } - return $removeAppliedFilter; + return $removeFilterField; } /** * Apply all the applied filters (SQL where conditions) to the current filter */ - public function applyFilters($appliedFilters, $appliedFiltersOperations, $appliedFiltersConditions, $appliedFiltersOptions) + public function applyFilterFields($filterFields) { $applyFilters = false; - // Checks the required parameters: appliedFilters and appliedFiltersOperations - if (isset($appliedFilters) && is_array($appliedFilters) - && isset($appliedFiltersOperations) && is_array($appliedFiltersOperations)) + // Check if the parameter is an array and it is not empty + if (!isEmptyArray($filterFields)) { - $fields = $this->getSessionElement(self::SESSION_FIELDS); // Retrieves all the used fields by the current filter + $filters = array(); - // Checks that the given applied filters are present in all the used fields by the current filter - if (!array_diff($appliedFilters, $fields)) + // Check if the parameter is fine + $fine = true; + foreach ($filterFields as $filterField) { - $filters = array(); // starts building the new applied filters list - for ($i = 0; $i < count($appliedFilters); $i++) // loops through the given applied filters + // If not an empty array + if (!isEmptyArray($filterField)) { - $filterDefinition = new stdClass(); // new applied filter definition - - // Sets the filter definition required properties - $filterDefinition->name = $appliedFilters[$i]; - $filterDefinition->operation = $appliedFiltersOperations[$i]; - - // Sets the filter definition optional properties - $filterDefinition->condition = null; - if (isset($appliedFiltersConditions) && isset($appliedFiltersConditions[$i])) + // + if (isset($filterField['name']) && isset($filterField["operation"]) && isset($filterField["condition"]) + && !isEmptyString($filterField["name"]) && !isEmptyString($filterField["operation"]) + && !isEmptyString($filterField["condition"])) { - $filterDefinition->condition = $appliedFiltersConditions[$i]; + // Fine + $filter = new stdClass(); + $filter->name = $filterField['name']; + $filter->operation = $filterField['operation']; + $filter->condition = $filterField['condition']; + if (isset($filterField['option']) && !isEmptyString($filterField['option'])) + { + $filter->option = $filterField['option']; + } + else + { + $filter->option = null; + } + $filters[] = $filter; } - - $filterDefinition->option = null; - if (isset($appliedFiltersOptions) && isset($appliedFiltersOptions[$i])) + else // otherwise is not fine and stop checking { - $filterDefinition->option = $appliedFiltersOptions[$i]; + $fine = false; + break; } - - $filters[$i] = $filterDefinition; // adds the new definition to the list } + else // + { + $fine = false; + break; + } + } + // + if ($fine) + { // Write changes into the session $this->setSessionElement(self::SESSION_FILTERS, $filters); $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); // the dataset must be reloaded @@ -592,49 +628,6 @@ class FilterCmptLib $this->setSessionElement(self::SESSION_DATASET_RELOAD, true); } - /** - * Add a filter (SQL where clause) to be applied to the current filter - */ - public function addFilter($filter) - { - $addFilter = false; - - // Checks the parameter filter - if (!isEmptyString($filter)) - { - // Retrieves all the used fields by the current filter - $fields = $this->getSessionElement(self::SESSION_FIELDS); - // Retrieves the applied filters by the current filter - $filters = $this->getSessionElement(self::SESSION_FILTERS); - - // Checks that the given applied filter is present in the list of all the used fields by the current filter - if (in_array($filter, $fields)) - { - // Search in what position the given applied filter is - $pos = $this->_searchFilterByName($filters, $filter); - if ($pos === false) // If NOT found then add it - { - // New filter definition - $filterDefinition = new stdClass(); - // Sets filter definition required properties - $filterDefinition->name = $filter; - // Sets filter definition optional properties - $filterDefinition->operation = null; - $filterDefinition->condition = null; - $filterDefinition->option = null; - // Place the new applied filter at the end of the applied filters list - array_push($filters, $filterDefinition); - } - - $this->setSessionElement(self::SESSION_FILTERS, $filters); // write changes into the session - - $addFilter = true; - } - } - - return $addFilter; - } - /** * Save the current filter as a custom filter for this user with the given description */ @@ -742,116 +735,50 @@ class FilterCmptLib return $removeCustomFilter; } - /** - * Return an unique string that identify this filter component - * NOTE: The default value is the URI where the FilterCmpt is called - * If the fhc_controller_id is present then is also used - */ - public function setFilterUniqueIdByParams($params) - { - if ($params != null - && is_array($params) - && isset($params[self::FILTER_UNIQUE_ID]) - && !isEmptyString($params[self::FILTER_UNIQUE_ID])) - { - $filterUniqueId = $params[self::FILTER_UNIQUE_ID]; - } - else - { - // Gets the current page URI - $filterUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.$this->_ci->router->method; - } - - $this->setFilterUniqueId($filterUniqueId); - } - - /** - * - */ - public function setFilterUniqueId($filterUniqueId) - { - // If the FHC_CONTROLLER_ID parameter is present in the HTTP GET - if (isset($_GET[self::FHC_CONTROLLER_ID])) - { - $filterUniqueId .= '/'.$this->_ci->input->get(self::FHC_CONTROLLER_ID); // then use it - } - elseif (isset($_POST[self::FHC_CONTROLLER_ID])) // else if the FHC_CONTROLLER_ID parameter is present in the HTTP POST - { - $filterUniqueId .= '/'.$this->_ci->input->post(self::FHC_CONTROLLER_ID); // then use it - } - - $this->_filterUniqueId = $filterUniqueId; - } - - /** - * - */ - public function setFilterType($filterType) - { - $this->_filterType = $filterType; - } - - /** - * - */ - public function setFilterId($filterId) - { - $this->_filterId = $filterId; - } - /** * Generates the filters menu structure array and stores it into the session */ - public function generateFilterMenu($navigationPage) + private function _generateFilterMenu($app, $datasetName) { $filterMenu = new stdClass(); $filterMenu->filters = array(); $filterMenu->personalFilters = array(); - $session = $this->getSession(); // The filter currently stored in session (the one that is currently used) - if ($session != null) + // Loads the Filters model + $this->_ci->load->model('system/Filters_model', 'FiltersModel'); + + // Loads all the filters related to this page (same dataset_name and same app name) + $filters = $this->_ci->FiltersModel->getFiltersByAppDatasetNamePersonId( + $app, + $datasetName, + getAuthPersonId() + ); + + // If filters were loaded + if (hasData($filters)) { - // Loads the Filters model - $this->_ci->load->model('system/Filters_model', 'FiltersModel'); + $childrenArray = array(); // contains all the children elements in a menu entry + $childrenPersonalArray = array(); // contains all the children elements in menu enty for personal filters - // Loads all the filters related to this page (same dataset_name and same app name) - $filters = $this->_ci->FiltersModel->getFiltersByAppDatasetNamePersonId( - $session[self::APP], - $session[self::DATASET_NAME], - getAuthPersonId() - ); - - // If filters were loaded - if (hasData($filters)) + // Loops through loaded filters + foreach (getData($filters) as $filter) { - $childrenArray = array(); // contains all the children elements in a menu entry - $childrenPersonalArray = array(); // contains all the children elements in menu enty for personal filters + $menuEntry = new stdClass(); + $menuEntry->desc = $filter->description[0]; + $menuEntry->filter_id = $filter->filter_id; - // Loops through loaded filters - foreach (getData($filters) as $filter) + // If it is NOT a personal filter + if ($filter->person_id == null) { - $menuEntry = new stdClass(); - $menuEntry->desc = $filter->description[0]; - $menuEntry->link = sprintf( - '%s?%s=%s', - site_url($navigationPage), - self::FILTER_ID, - $filter->{self::FILTER_ID} - ); + $filterMenu->filters[] = $menuEntry; + } + else // otherwise + { + $menuEntry->subscriptDescription = 'Remove'; + $menuEntry->subscriptLinkClass = 'remove-custom-filter'; + $menuEntry->subscriptLinkValue = $filter->{self::FILTER_ID}; - // If it is NOT a personal filter - if ($filter->person_id == null) - { - $filterMenu->filters[] = $menuEntry; - } - else // otherwise - { - $menuEntry->subscriptDescription = 'Remove'; - $menuEntry->subscriptLinkClass = 'remove-custom-filter'; - $menuEntry->subscriptLinkValue = $filter->{self::FILTER_ID}; - - $filterMenu->personalFilters[] = $menuEntry; // adds to personal filters menu array - } + $filterMenu->personalFilters[] = $menuEntry; // adds to personal filters menu array } } } @@ -862,11 +789,51 @@ class FilterCmptLib //------------------------------------------------------------------------------------------------------------------ // Private methods + /** + * Checks the required parameters used to call this FilterCmpt + */ + private function _checkJSParameters() + { + // + if (isEmptyString($this->_filterUniqueId)) + { + $this->setSession(error('Parameter "filterUniqueId" not provided')); + return false; + } + + // + if (isEmptyString($this->_filterType)) + { + $this->setSession(error('Parameter "filterType" not provided')); + return false; + } + + return true; + } + /** * Contains all the logic used to load all the data needed to the FilterCmpt */ - private function _startFilterCmpt() + public function start() { + // + if (!$this->_checkJSParameters()) return; + + // Gets the filter configuration from the file system + require_once(APPPATH.'components/filters/'.$this->_filterType.'.php'); + + // Gets the filter configuration from the extensions + // require_once(APPPATH.'components/extensions/'.$this->_filterType.'.php'); + + // + if (!$this->_checkPHPParameters($filterCmptArray)) return; + + // + $this->_initFilterCmpt($filterCmptArray); + + // + if (!$this->_isAllowed()) return; + // Looks for expired filter components in session and drops them $this->dropExpiredFilterCmpts(); @@ -908,8 +875,6 @@ class FilterCmptLib // Save changes into session if data are valid if (!isError($dataset)) { - $this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow - // Set the new dataset and its attributes in the session $this->setSessionElement(FilterCmptLib::SESSION_METADATA, $this->_ci->FiltersModel->getExecutedQueryMetaData()); $this->setSessionElement(FilterCmptLib::SESSION_ROW_NUMBER, count($dataset->retval)); @@ -946,8 +911,6 @@ class FilterCmptLib // Save changes into session if data are valid if (!isError($dataset)) { - $this->_formatDataset($dataset); // marks rows using markRow and format rowns using formatRow - // Stores an array that contains all the data useful for $this->setSession( array( @@ -957,17 +920,12 @@ class FilterCmptLib FilterCmptLib::SESSION_FILTER_NAME => $filterName, // the current filter name FilterCmptLib::SESSION_FIELDS => $this->_ci->FiltersModel->getExecutedQueryListFields(), // all the fields of the dataset FilterCmptLib::SESSION_SELECTED_FIELDS => $this->_getColumnsNames($parsedFilterJson->columns), // all the selected fields - FilterCmptLib::SESSION_COLUMNS_ALIASES => $this->_columnsAliases, // all the fields aliases - FilterCmptLib::SESSION_ADDITIONAL_COLUMNS => $this->_additionalColumns, // additional columns - FilterCmptLib::SESSION_CHECKBOXES => $this->_checkboxes, // the name of the field used to build the checkboxes column FilterCmptLib::SESSION_FILTERS => $parsedFilterJson->filters, // all the filters used to filter the dataset FilterCmptLib::SESSION_METADATA => $this->_ci->FiltersModel->getExecutedQueryMetaData(), // the metadata of the dataset FilterCmptLib::SESSION_ROW_NUMBER => count($dataset->retval), // the number of loaded rows by this filter FilterCmptLib::SESSION_DATASET => $dataset->retval, // the entire dataset FilterCmptLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time - FilterCmptLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation - FilterCmptLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options - FilterCmptLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition + FilterCmptLib::SESSION_SIDE_MENU => $this->_generateFilterMenu($this->_app, $this->_datasetName) ) ); } @@ -984,97 +942,67 @@ class FilterCmptLib /** * Checks the required parameters used to call this FilterCmpt */ - private function _checkParameters($filterCmptArray) + private function _checkPHPParameters($filterCmptArray) { // If no options are given to this component... if (!is_array($filterCmptArray) || (is_array($filterCmptArray) && count($filterCmptArray) == 0)) { - show_error('Second parameter of the component call must be a NOT empty associative array'); + $this->setSession(error('No parameters provided')); + return false; } else // ...otherwise { - // Parameters (app AND dataset name) OR filter id are mandatory - if ((!isset($filterCmptArray[FilterCmptLib::APP]) && !isset($filterCmptArray[FilterCmptLib::DATASET_NAME])) - && !isset($filterCmptArray[FilterCmptLib::FILTER_ID])) + // Parameters app AND dataset name + if (!isset($filterCmptArray[FilterCmptLib::APP]) && !isset($filterCmptArray[FilterCmptLib::DATASET_NAME])) { - show_error( - 'The parameters ("'.FilterCmptLib::APP.'" AND "'.FilterCmptLib::DATASET_NAME.') OR "'. - FilterCmptLib::FILTER_ID.'" must be specified' + $this->setSession( + error( + 'The parameters "'.FilterCmptLib::APP.'" AND "'.FilterCmptLib::DATASET_NAME.' must be specified' + ) ); + return false; } // The query parameter is mandatory if (!isset($filterCmptArray[FilterCmptLib::QUERY])) { - show_error('The parameter "'.FilterCmptLib::QUERY.'" must be specified'); + $this->setSession(error('The parameter "'.FilterCmptLib::QUERY.'" must be specified')); + return false; } - // The dataset representation parameter is mandatory - if (!isset($filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION])) + // + if (!isset($filterCmptArray[FilterCmptLib::DATASET_NAME])) { - show_error('The parameter "'.FilterCmptLib::DATASET_REPRESENTATION.'" must be specified'); + $this->setSession(error('The parameter "'.FilterCmptLib::DATESET_NAME.'" must be specified')); + return false; } - // Checks if the dataset representation parameter is valid - if (isset($filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION]) - && $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] != FilterCmptLib::DATASET_REP_TABLESORTER - && $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] != FilterCmptLib::DATASET_REP_PIVOTUI - && $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] != FilterCmptLib::DATASET_REP_TABULATOR) + // + if (!isset($filterCmptArray[FilterCmptLib::REQUIRED_PERMISSIONS])) { - show_error( - 'The parameter "'.FilterCmptLib::DATASET_REPRESENTATION. - '" must be IN ("' - .FilterCmptLib::DATASET_REP_TABLESORTER.'", "' - .FilterCmptLib::DATASET_REP_PIVOTUI.'", "' - .FilterCmptLib::DATASET_REP_TABULATOR.'")' - ); - } - - // If given the session timeout parameter must be a number - if (isset($filterCmptArray[FilterCmptLib::SESSION_TIMEOUT]) && !is_numeric($filterCmptArray[FilterCmptLib::SESSION_TIMEOUT])) - { - show_error('The parameter "'.FilterCmptLib::SESSION_TIMEOUT.'" must be a number'); + $this->setSession(error('The parameter "'.FilterCmptLib::REQUIRED_PERMISSIONS.'" must be specified')); + return false; } } + + return true; } /** * Checks parameters and initialize all the properties of this FilterCmpt */ - private function _initFilterCmpt() + private function _initFilterCmpt($filterCmptArray) { - // Gets the filter configuration from the file system - require_once(APPPATH.'components/filters/'.$this->_filterType.'.php'); - - // Gets the filter configuration from the extensions - // require_once(APPPATH.'components/extensions/'.$this->_filterType.'.php'); - - $this->_checkParameters($filterCmptArray); - // If here then everything is ok // Initialize class properties - $this->_requiredPermissions = null; $this->_app = null; $this->_datasetName = null; $this->_filterKurzbz = null; - //$this->_filterId = null; - $this->_reloadDataset = true; // by default the dataset is NOT cached in session $this->_query = null; - $this->_additionalColumns = null; - $this->_columnsAliases = null; - $this->_formatRow = null; - $this->_markRow = null; - $this->_checkboxes = null; - $this->_hideOptions = null; - $this->_hideSelectFields = null; - $this->_hideSelectFilters = null; - $this->_hideSave = null; - $this->_hideMenu = null; - $this->_customMenu = null; - $this->_datasetRepresentation = null; - $this->_datasetRepresentationOptions = null; - $this->_datasetRepFieldsDefs = null; + $this->_requiredPermissions = null; + + $this->_reloadDataset = true; // by default the dataset is NOT cached in session $this->_sessionTimeout = FilterCmptLib::SESSION_DEFAULT_TIMEOUT; // Retrieved the required permissions parameter if present @@ -1099,119 +1027,11 @@ class FilterCmptLib $this->_filterKurzbz = $filterCmptArray[FilterCmptLib::FILTER_KURZBZ]; } - if (isset($filterCmptArray[FilterCmptLib::FILTER_ID])) - { - $this->_filterId = $filterCmptArray[FilterCmptLib::FILTER_ID]; - } - // How to retrieve data for the filter: SQL statement or a result from DB if (isset($filterCmptArray[FilterCmptLib::QUERY])) { $this->_query = $filterCmptArray[FilterCmptLib::QUERY]; } - - if (isset($filterCmptArray[FilterCmptLib::DATASET_RELOAD])) - { - $this->_reloadDataset = $filterCmptArray[FilterCmptLib::DATASET_RELOAD]; - } - - // Parameter is used to add extra columns to the dataset - if (isset($filterCmptArray[FilterCmptLib::ADDITIONAL_COLUMNS]) - && is_array($filterCmptArray[FilterCmptLib::ADDITIONAL_COLUMNS]) - && count($filterCmptArray[FilterCmptLib::ADDITIONAL_COLUMNS]) > 0) - { - $this->_additionalColumns = $filterCmptArray[FilterCmptLib::ADDITIONAL_COLUMNS]; - } - - // Parameter is used to add use aliases for the columns fo the dataset - if (isset($filterCmptArray[FilterCmptLib::COLUMNS_ALIASES]) - && is_array($filterCmptArray[FilterCmptLib::COLUMNS_ALIASES]) - && count($filterCmptArray[FilterCmptLib::COLUMNS_ALIASES]) > 0) - { - $this->_columnsAliases = $filterCmptArray[FilterCmptLib::COLUMNS_ALIASES]; - } - - // Parameter that contains a function to format the rows of the dataset - if (isset($filterCmptArray[FilterCmptLib::FORMAT_ROW]) && is_callable($filterCmptArray[FilterCmptLib::FORMAT_ROW])) - { - $this->_formatRow = $filterCmptArray[FilterCmptLib::FORMAT_ROW]; - } - - // Parameter that contains a function to mark in the GUI the rows of the dataset - if (isset($filterCmptArray[FilterCmptLib::MARK_ROW]) && is_callable($filterCmptArray[FilterCmptLib::MARK_ROW])) - { - $this->_markRow = $filterCmptArray[FilterCmptLib::MARK_ROW]; - } - - // Parameter used to specify the column of the dataset that will be used - // as id of the checkboxes column in the GUI - if (isset($filterCmptArray[FilterCmptLib::CHECKBOXES])) - { - $this->_checkboxes = $filterCmptArray[FilterCmptLib::CHECKBOXES]; - } - - // To specify if the filter options are shown ot not - if (isset($filterCmptArray[FilterCmptLib::HIDE_OPTIONS]) && is_bool($filterCmptArray[FilterCmptLib::HIDE_OPTIONS])) - { - $this->_hideOptions = $filterCmptArray[FilterCmptLib::HIDE_OPTIONS]; - } - - // To specify if the form to select fields is shown or not - if (isset($filterCmptArray[FilterCmptLib::HIDE_SELECT_FIELDS]) && is_bool($filterCmptArray[FilterCmptLib::HIDE_SELECT_FIELDS])) - { - $this->_hideSelectFields = $filterCmptArray[FilterCmptLib::HIDE_SELECT_FIELDS]; - } - - // To specify if the form to select filters is shown or not - if (isset($filterCmptArray[FilterCmptLib::HIDE_SELECT_FILTERS]) && is_bool($filterCmptArray[FilterCmptLib::HIDE_SELECT_FILTERS])) - { - $this->_hideSelectFilters = $filterCmptArray[FilterCmptLib::HIDE_SELECT_FILTERS]; - } - - // To specify if the form to save a custom FilterCmpt is shown or not - if (isset($filterCmptArray[FilterCmptLib::HIDE_SAVE]) && is_bool($filterCmptArray[FilterCmptLib::HIDE_SAVE])) - { - $this->_hideSave = $filterCmptArray[FilterCmptLib::HIDE_SAVE]; - } - - // If the menu should be shown or not - if (isset($filterCmptArray[FilterCmptLib::HIDE_MENU]) && is_bool($filterCmptArray[FilterCmptLib::HIDE_MENU])) - { - $this->_hideMenu = $filterCmptArray[FilterCmptLib::HIDE_MENU]; - } - - // If a custom menu is set - if (isset($filterCmptArray[FilterCmptLib::CUSTOM_MENU]) && is_bool($filterCmptArray[FilterCmptLib::CUSTOM_MENU])) - { - $this->_customMenu = $filterCmptArray[FilterCmptLib::CUSTOM_MENU]; - } - - // To specify how to represent the dataset (ex: tablesorter, pivotUI, ...) - if (isset($filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION]) - && ($filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] == FilterCmptLib::DATASET_REP_TABLESORTER - || $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] == FilterCmptLib::DATASET_REP_PIVOTUI - || $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION] == FilterCmptLib::DATASET_REP_TABULATOR)) - { - $this->_datasetRepresentation = $filterCmptArray[FilterCmptLib::DATASET_REPRESENTATION]; - } - - // To specify options for the dataset representation (ex: tablesorter, pivotUI, ...) - if (isset($filterCmptArray[FilterCmptLib::DATASET_REP_OPTIONS]) && !isEmptyString($filterCmptArray[FilterCmptLib::DATASET_REP_OPTIONS])) - { - $this->_datasetRepresentationOptions = $filterCmptArray[FilterCmptLib::DATASET_REP_OPTIONS]; - } - - // To specify how to represent each record field - if (isset($filterCmptArray[FilterCmptLib::DATASET_REP_FIELDS_DEFS]) && !isEmptyString($filterCmptArray[FilterCmptLib::DATASET_REP_FIELDS_DEFS])) - { - $this->_datasetRepFieldsDefs = $filterCmptArray[FilterCmptLib::DATASET_REP_FIELDS_DEFS]; - } - - // To specify the expiring session time - if (isset($filterCmptArray[FilterCmptLib::SESSION_TIMEOUT]) && is_numeric($filterCmptArray[FilterCmptLib::SESSION_TIMEOUT])) - { - $this->_sessionTimeout = $filterCmptArray[FilterCmptLib::SESSION_TIMEOUT]; - } } /** @@ -1353,73 +1173,6 @@ class FilterCmptLib } } - /** - * Calls the method _markRow and _formatRow to marks rows using markRow and format rowns using formatRow - * NOTE: this method operates directly on the retrieved dataset: parameter passed by reference - */ - private function _formatDataset(&$rawDataset) - { - if (hasData($rawDataset) && is_array($rawDataset->retval)) - { - // For each row of the data set - for ($rowCounter = 0; $rowCounter < count($rawDataset->retval); $rowCounter++) - { - // Calls the methods to mark and to format a row - // NOTE: keep this order! the markRow function given as parameter is supposing to work - // on a raw dataset, NOT on a formatted one - $rawDataset->retval[$rowCounter]->MARK_ROW_CLASS = $this->_markRow($rawDataset->retval[$rowCounter]); - $this->_formatRow($rawDataset->retval[$rowCounter]); - } - } - } - - /** - * Formats the columns of all the rows of the entire dataset - * - converts booleans into strings "true" and "false" - * - format dates using the format string defined in DEFAULT_DATE_FORMAT - * Calls the parameter formatRow if it was given and if it is a valid funtion - * NOTE: this method operates directly on the retrieved dataset: parameter passed by reference - */ - private function _formatRow(&$rawDatasetRow) - { - // For each column of the row - foreach ($rawDatasetRow as $columnName => $columnValue) - { - // Basic conversions - if (is_bool($columnValue)) - { - $rawDatasetRow->{$columnName} = ($columnValue === true ? 'true' : 'false'); - } - elseif (DateTime::createFromFormat('Y-m-d H:i:s', $columnValue) !== false) - { - $rawDatasetRow->{$columnName} = date(self::DEFAULT_DATE_FORMAT, strtotime($columnValue)); - } - } - - // If a valid function call the given formatRow - if ($this->_formatRow != null && is_callable($this->_formatRow)) - { - $formatRowFunction = $this->_formatRow; - $rawDatasetRow = $formatRowFunction($rawDatasetRow); - } - } - - /** - * Returns a string that contains a class name used to mark rows in the dataset table - * Calls the parameter markRow if it was given and if it is a valid funtion - */ - private function _markRow($rawDatasetRow) - { - // If a valid function call the given markRow - if ($this->_markRow != null && is_callable($this->_markRow)) - { - $markRowFunction = $this->_markRow; - $class = $markRowFunction($rawDatasetRow); - } - - return !isset($class) ? '' : $class; - } - /** * Utility method that retrieves the name of the columns present in a filter JSON definition */ diff --git a/public/css/FilterComponent.css b/public/css/FilterComponent.css new file mode 100644 index 000000000..eaa3de83f --- /dev/null +++ b/public/css/FilterComponent.css @@ -0,0 +1,47 @@ +.filter-header-title { + font-weight: bold; + font-size: 16px; + text-decoration: none; + color: #333; + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + padding-top: 0.75rem !important; + cursor: pointer; +} + +.filter-filter-options { + margin-bottom: 30px; +} + +.filter-options-div { + margin-bottom: 12px; + padding-bottom: 12px; + border-bottom-style: solid; + border-bottom-color: rgba(0, 0, 0, 0.125); + border-bottom-width: 1px; +} + +.filter-dnd-area { + height: 50px; + padding: 3px; + margin-bottom: 10px; +} + +.filter-dnd-object { + height: 100%; + margin-left: 7px; + padding: 11px; + display: inline-block; + background-color: white; + border-style: solid; + border-color: black; + border-width: 1px; + border-radius: 7px; + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + cursor: move; +} + +.filter-filter-fields { + margin-top: 12px; + margin-bottom: 12px; +} + diff --git a/public/css/NavigationComponent.css b/public/css/NavigationComponent.css index 64d908b02..3e2273b67 100644 --- a/public/css/NavigationComponent.css +++ b/public/css/NavigationComponent.css @@ -1,23 +1,82 @@ -.header-menu-link-entry { - font-size: 18px; - color: #5e5e5e !important; -} - +/* + * Hederer + */ .navbar-header { background-color: #f8f8f8; + padding-top: 0px; + padding-bottom: 0px; + padding-left: 10px; + border-style: solid; border-color: #e7e7e7; + border-width: 0 0 1px; } -.sidebar { +.header-menu-link-entry { + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + font-size: 18px; + line-height: 1.42857143; + color: #5e5e5e !important; + padding-top: 15px !important; + padding-right: 7px !important; + padding-left: 7px !important; +} + +.header-menu-icon { + top: 0px; + margin-right: 3px; + font-size: 16px; +} + +/* + * Left side + */ +.navbar-left-side { z-index: 1; position: absolute; width: 250px; + border-right: 1px solid #e7e7e7; + background-color: #f8f8f8; } +.navbar-left-side ul { + width: 250px; +} + +.navbar-left-side ul li { + border-bottom: 1px solid #e7e7e7; +} + +.left-side-menu-second-level { + padding-top: 0px !important; + padding-bottom: 0px !important; +} + +.left-side-menu-second-level li { + border-bottom: none !important; +} + +.left-side-menu-link-entry { + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + font-size: 14px; + line-height: 1.42857143; + color: #23527c; + padding-top: 10px !important; + padding-bottom: 10px !important; + padding-left: 7px !important; + padding-right: 7px !important; + text-decoration: none; +} + +.left-side-menu-link-entry:hover { + background-color: #eee; +} + +/* + * To be moved outside + */ #content { - position: inherit; - margin: 0 0 0 250px; - padding: 30px 30px; - border-left: 1px solid #e7e7e7; + position: inherit; + margin: 0 0 0 250px; + padding: 30px 30px; }