diff --git a/app/src/Controller/AppController.php b/app/src/Controller/AppController.php index 0106378..5cf22f3 100644 --- a/app/src/Controller/AppController.php +++ b/app/src/Controller/AppController.php @@ -105,6 +105,7 @@ class AppController extends Controller $this->ACL->checkAccess(); $this->set('menu', $this->{$this->modelClass}->getMenu()); $this->set('ajax', $this->request->is('ajax')); + $this->request->getParam('prefix'); } private function authApiUser(): void diff --git a/app/src/Controller/Component/ACLComponent.php b/app/src/Controller/Component/ACLComponent.php index b8f83ab..6353613 100644 --- a/app/src/Controller/Component/ACLComponent.php +++ b/app/src/Controller/Component/ACLComponent.php @@ -8,6 +8,8 @@ use Cake\Http\Exception\NotFoundException; use Cake\Http\Exception\MethodNotAllowedException; use Cake\Http\Exception\ForbiddenException; use Cake\ORM\TableRegistry; +use Cake\Core\Configure; +use Cake\Core\Configure\Engine\PhpConfig; class ACLComponent extends Component { diff --git a/app/src/Controller/Open/OrganisationsController.php b/app/src/Controller/Open/OrganisationsController.php new file mode 100644 index 0000000..fdcf16a --- /dev/null +++ b/app/src/Controller/Open/OrganisationsController.php @@ -0,0 +1,35 @@ +Authentication->allowUnauthenticated(['index']); + } + + public function index() + { + $this->CRUD->index([ + 'filters' => ['name', 'uuid', 'nationality', 'sector', 'type', 'url', 'Alignments.id'], + 'quickFilters' => ['name', 'uuid', 'nationality', 'sector', 'type', 'url'], + 'contain' => ['Alignments' => 'Individuals'] + ]); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('alignmentScope', 'individuals'); + $this->set('metaGroup', 'Public'); + } +} diff --git a/app/src/Model/Table/AppTable.php b/app/src/Model/Table/AppTable.php index 177dc4a..9c9f8d3 100644 --- a/app/src/Model/Table/AppTable.php +++ b/app/src/Model/Table/AppTable.php @@ -4,6 +4,8 @@ namespace App\Model\Table; use Cake\ORM\Table; use Cake\Validation\Validator; +use Cake\Core\Configure; +use Cake\Core\Configure\Engine\PhpConfig; class AppTable extends Table { @@ -13,6 +15,7 @@ class AppTable extends Table public function getMenu() { + $open = Configure::read('Cerebrate.open'); return [ 'ContactDB' => [ 'Individuals' => [ @@ -193,6 +196,30 @@ class AppTable extends Table ] ] ] + ], + 'Open' => [ + 'Organisations' => [ + 'label' => __('Organisations'), + 'url' => '/open/organisations/index', + 'children' => [ + 'index' => [ + 'url' => '/open/organisations/index', + 'label' => __('List organisations') + ], + ], + 'open' => in_array('organisations', Configure::read('Cerebrate.open')) + ], + 'Individuals' => [ + 'label' => __('Individuals'), + 'url' => '/open/individuals/index', + 'children' => [ + 'index' => [ + 'url' => '/open/individuals/index', + 'label' => __('List individuals') + ], + ], + 'open' => in_array('individuals', Configure::read('Cerebrate.open')) + ] ] ]; } diff --git a/app/templates/Open/Organisations/index.php b/app/templates/Open/Organisations/index.php new file mode 100644 index 0000000..3870899 --- /dev/null +++ b/app/templates/Open/Organisations/index.php @@ -0,0 +1,95 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'simple', + 'children' => [ + 'data' => [ + 'type' => 'simple', + 'text' => __('Add organisation'), + 'class' => 'btn btn-primary', + 'popover_url' => '/organisations/add' + ] + ] + ], + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'class' => 'short', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'class' => 'short', + 'data_path' => 'name', + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'class' => 'short', + 'data_path' => 'uuid', + ], + [ + 'name' => __('Members'), + 'data_path' => 'alignments', + 'element' => 'count_summary', + 'url' => '/individuals/index/?Organisations.id={{url_data}}', + 'url_data_path' => 'id' + ], + [ + 'name' => __('URL'), + 'sort' => 'url', + 'class' => 'short', + 'data_path' => 'url', + ], + [ + 'name' => __('Nationality'), + 'data_path' => 'nationality', + ], + [ + 'name' => __('Sector'), + 'data_path' => 'sector', + ], + [ + 'name' => __('Type'), + 'data_path' => 'type', + ] + ], + 'title' => __('ContactDB Organisation Index'), + 'description' => __('A list of organisations known by your Cerebrate instance. This list can get populated either directly, by adding new organisations or by fetching them from trusted remote sources.'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/organisations/view', + 'url_params_data_paths' => ['id'], + 'icon' => 'eye' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/organisations/edit/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'edit' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/organisations/delete/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'trash' + ] + ] + ] +]); +echo ''; +?> diff --git a/app/templates/element/genericElements/IndexTable/index_table.php b/app/templates/element/genericElements/IndexTable/index_table.php index a138bb7..25057bc 100644 --- a/app/templates/element/genericElements/IndexTable/index_table.php +++ b/app/templates/element/genericElements/IndexTable/index_table.php @@ -1,13 +1,13 @@ element('/genericElements/IndexTable/index_table', array( + * echo $this->element('/genericElements/IndexTable/index_table', [ * 'top_bar' => ( * // search/filter bar information compliant with ListTopBar * ), - * 'data' => array( + * 'data' => [ // the actual data to be used * ), - * 'fields' => array( + * 'fields' => [ * // field list with information for the paginator, the elements used for the individual cells, etc * ), * 'title' => optional title, @@ -32,13 +32,13 @@ } $skipPagination = isset($data['skip_pagination']) ? $data['skip_pagination'] : 0; if (!$skipPagination) { - $paginationData = !empty($data['paginatorOptions']) ? $data['paginatorOptions'] : array(); + $paginationData = !empty($data['paginatorOptions']) ? $data['paginatorOptions'] : []; echo $this->element( '/genericElements/IndexTable/pagination', - array( + [ 'paginationOptions' => $paginationData, 'tableRandomValue' => $tableRandomValue - ) + ] ); if (!$ajax) { echo $this->element( @@ -49,17 +49,20 @@ if (!empty($data['top_bar'])) { echo $this->element( '/genericElements/ListTopBar/scaffold', - array( + [ 'data' => $data['top_bar'], 'tableRandomValue' => $tableRandomValue - ) + ] ); } $rows = ''; $row_element = isset($data['row_element']) ? $data['row_element'] : 'row'; - $options = isset($data['options']) ? $data['options'] : array(); - $actions = isset($data['actions']) ? $data['actions'] : array(); - $dblclickActionArray = isset($data['actions']) ? $this->Hash->extract($data['actions'], '{n}[dbclickAction]') : array(); + $options = isset($data['options']) ? $data['options'] : []; + $actions = isset($data['actions']) ? $data['actions'] : []; + if ($this->request->getParam('prefix') === 'Open') { + $actions = []; + } + $dblclickActionArray = !empty($actions) ? $this->Hash->extract($actions, '{n}[dbclickAction]') : []; $dbclickAction = ''; foreach ($data['data'] as $k => $data_row) { $primary = null; @@ -78,7 +81,7 @@ empty($data['class']) ? '' : h($data['row_class']), $this->element( '/genericElements/IndexTable/' . $row_element, - array( + [ 'k' => $k, 'row' => $data_row, 'fields' => $data['fields'], @@ -86,7 +89,7 @@ 'actions' => $actions, 'primary' => $primary, 'tableRandomValue' => $tableRandomValue - ) + ] ) ); } @@ -96,12 +99,12 @@ $tableRandomValue, $this->element( '/genericElements/IndexTable/headers', - array( + [ 'fields' => $data['fields'], 'paginator' => $this->Paginator, - 'actions' => (empty($data['actions']) ? false : true), + 'actions' => (empty($actions) ? false : true), 'tableRandomValue' => $tableRandomValue - ) + ] ), $tbody );