Skip to content

Commit

Permalink
Merge pull request #165 from vaibhavsTekdi/byDefaultHideCustomFieldCo…
Browse files Browse the repository at this point in the history
…lumns

Issue #164 fix: After unchecking the column from 'Hide or Show Columns' drop down option, unchecked column gets removed from dropdown
  • Loading branch information
vaivk369 authored Nov 11, 2019
2 parents 474b6e7 + 7a27b3b commit d936deb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
24 changes: 21 additions & 3 deletions tjreports/site/models/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TjreportsModelReports extends JModelList
public $showhideCols = array();

// Columns which will be displayed by default
private $defaultColToShow = array();
public $defaultColToShow = array();

// Columns which will be hide by default
private $defaultColToHide = array();
Expand Down Expand Up @@ -85,7 +85,10 @@ class TjreportsModelReports extends JModelList

private $filterPiiColumns = array();

private $filterParamColToshow = array();
public $filterParamColToshow = array();

// Used to get the columns which are hide by default in load params
public $filterDefaultColToHide = array();

/**
* Constructor.
Expand Down Expand Up @@ -1140,7 +1143,7 @@ private function filterReportColumns($queryId, &$selColToshow)
}

$query = $this->_db->getQuery(true);
$this->filterShowhideCols = $this->filterPiiColumns = $this->filterParamColToshow = array();
$this->filterDefaultColToHide = $this->filterShowhideCols = $this->filterPiiColumns = $this->filterParamColToshow = array();

// $this->filterSelColToshow = $selColToshow;

Expand Down Expand Up @@ -1168,6 +1171,12 @@ private function filterReportColumns($queryId, &$selColToshow)
}
}

// Used to get the columns which are hide by default in load params
if (!empty($this->filterDefaultColToHide))
{
$this->defaultColToHide = $this->filterDefaultColToHide;
}

if (!empty($this->filterShowhideCols))
{
$this->showhideCols = $this->filterShowhideCols;
Expand Down Expand Up @@ -1240,6 +1249,11 @@ private function processSavedReportColumns($queryId, &$selColToshow)
{
$this->filterParamColToshow[$cols] = $cols;
}
else
{
// Used to get the columns which are hide (false) by default in load params
$this->filterDefaultColToHide[$cols] = $cols;
}

if (!empty($param['showHideColumns']) && !in_array($cols, $param['showHideColumns']) && !empty($selColToshow))
{
Expand All @@ -1253,6 +1267,10 @@ private function processSavedReportColumns($queryId, &$selColToshow)
// Check PII permission
if (!empty($param['piiColumns']) && !$this->piiPermission)
{
/* Checked the columns which are hide(false) in load params & if set them as piiColumns
* then it only returns the columns which are not available in piiColumns. */
$this->filterDefaultColToHide = array_diff($this->filterDefaultColToHide, $param['piiColumns']);

$this->filterParamColToshow = array_diff($this->filterParamColToshow, $param['piiColumns']);
$this->filterShowhideCols = array_diff($this->filterShowhideCols, $param['piiColumns']);
}
Expand Down
15 changes: 12 additions & 3 deletions tjreports/site/views/reports/view.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,26 @@ public function processData($type = 'html')
*/
$this->showHideColumns = $this->model->showhideCols;

/* To get the columns from loadparams*/
$this->defaultColToshow = $this->model->filterParamColToshow;

/* Check the columns in loadparams are available or not & show plugin level columns & custom field columns
* in case if load params are not available*/
if (empty($this->defaultColToshow))
{
$this->defaultColToshow = $this->model->defaultColToShow;
}

if (!empty($this->defaultColToHide))
{
$this->showHideColumns = array_intersect($this->model->showhideCols, array_merge($this->model->getState('colToshow'), $this->defaultColToHide));
$this->showHideColumns = array_intersect($this->model->showhideCols, array_merge($this->defaultColToshow, $this->defaultColToHide));
}

$this->sortable = $this->model->sortableColumns;
$this->emailColumn = $this->model->getState('emailColumn');
$this->srButton = $this->model->showSearchResetButton;

// Array_intersect - if column present in colToshow as true/false but not in showHideColumns then remove it
$this->colToshow = array_intersect($this->model->getState('colToshow'), $this->model->showhideCols);
$this->colToshow = $this->model->getState('colToshow');

$this->filterValues = $this->model->getState('filters');

Expand Down

0 comments on commit d936deb

Please sign in to comment.