Skip to content

Commit

Permalink
Prepopulate potential tree parents. Filter using parent id in COU ind…
Browse files Browse the repository at this point in the history
…ex view.
  • Loading branch information
Ioannis Igoumenos committed May 6, 2022
1 parent 9fd85b7 commit bfef1bc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ protected function populateAutoViewVars(object $obj=null) {

$this->set($vvar, $query->toArray());
break;
case 'parent':
$modelsName = $this->name;
// $table = the actual table object
$table = $this->$modelsName;
// XXX We assume that all models that load the Tree behavior will
// implement a potentialParnets method
$this->set($vvar, $table->potentialParents($this->getCOID()));
break;
default:
// XXX I18n? and in match?
throw new \LogicException('Unknonwn Auto View Var Type {0}', [$avv['type']]);
Expand Down
5 changes: 3 additions & 2 deletions app/src/Lib/Traits/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public function whereFilter(\Cake\ORM\Query $query, string $attribute, string $q
$sub = true;
}

// Boolean Values
if($this->searchFilters[$attribute]['type'] == 'boolean') {
// Primitive types
$search_types = ['integer', 'boolean'];
if(in_array($this->searchFilters[$attribute]['type'], $search_types, true)) {
return $query->where([$attribute => $search]);
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/Model/Table/CousTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public function initialize(array $config): void {
'index' => ['platformAdmin', 'coAdmin']
]
]);

$this->setAutoViewVars([
'parent_ids' => [
'type' => 'parent'
]
]);
}

/**
Expand Down Expand Up @@ -117,6 +123,7 @@ public function buildTableRules(RulesChecker $rules): RulesChecker {
* @param int $id COU ID to determine potential parents of, or null for any (or a new) COU
* @param bool $hierarchy Render the hierarchy in the name
* @return Array Array of COU IDs and COU Names
* @todo Make a TreeTrait and move the function there
*/

public function potentialParents(int $coId, int $id=null, bool $hierarchy=false) {
Expand Down
6 changes: 5 additions & 1 deletion app/templates/element/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@
e.preventDefault();
e.stopPropagation();
$(this).hide();
filterId = '#' + $(this).attr("aria-controls");
// CAKEPHP transforms snake case variables to kebab. As a result
// searching for the initial key will fail
original_value = $(this).attr("aria-controls");
value_to_snake = original_value.replace(/_/g, "-");;
filterId = '#' + value_to_snake;
$(filterId).val("");
$(this).closest('form').submit();
});
Expand Down

0 comments on commit bfef1bc

Please sign in to comment.