diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 07ec3aa..4370704 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -78,7 +78,7 @@ class AppController extends Controller Configure::write('DebugKit.panels', ['DebugKit.Packages' => true]); Configure::write('DebugKit.forceEnable', true); } - + $this->loadComponent('CustomPagination'); /* * Enable the following component for recommended CakePHP form protection settings. * see https://book.cakephp.org/4/en/controllers/components/form-protection.html @@ -112,6 +112,7 @@ class AppController extends Controller $this->set('ajax', $this->request->is('ajax')); $this->request->getParam('prefix'); $this->set('darkMode', !empty(Configure::read('Cerebrate.dark'))); + $this->set('baseurl', empty(Configure::read('baseurl')) ? '' : Configure::read('baseurl')); } private function authApiUser(): void diff --git a/src/Controller/BroodsController.php b/src/Controller/BroodsController.php new file mode 100644 index 0000000..d9d2cd8 --- /dev/null +++ b/src/Controller/BroodsController.php @@ -0,0 +1,119 @@ +CRUD->index([ + 'filters' => ['name', 'uuid', 'url', 'description', 'Organisations.id', 'trusted', 'pull', 'authkey'], + 'quickFilters' => ['name', 'uuid', 'description'], + 'contain' => ['Organisations'] + ]); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Sync'); + } + + public function add() + { + $this->CRUD->add(); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Sync'); + $this->loadModel('Organisations'); + $dropdownData = [ + 'organisation' => $this->Organisations->find('list', [ + 'sort' => ['name' => 'asc'] + ]) + ]; + $this->set(compact('dropdownData')); + } + + public function view($id) + { + $this->CRUD->view($id, ['contain' => ['Organisations']]); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Sync'); + } + + public function edit($id) + { + $this->CRUD->edit($id); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Sync'); + $this->render('add'); + } + + public function delete($id) + { + $this->CRUD->delete($id); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Sync'); + } + + public function testConnection($id) + { + $status = $this->Broods->queryStatus($id); + return $this->RestResponse->viewData($status, 'json'); + } + + public function previewIndex($id, $scope) + { + if (!in_array($scope, ['organisations', 'individuals', 'sharingGroups'])) { + throw new MethodNotAllowedException(__('Invalid scope. Valid options are: organisations, individuals, sharing_groups')); + } + $filter = $this->request->getQuery('quickFilter'); + $data = $this->Broods->queryIndex($id, $scope, $filter); + if (!is_array($data)) { + $data = []; + } + if ($this->ParamHandler->isRest()) { + return $this->RestResponse->viewData($data, 'json'); + } else { + $data = $this->CustomPagination->paginate($data); + $this->set('data', $data); + $this->set('brood_id', $id); + if ($this->request->is('ajax')) { + $this->viewBuilder()->disableAutoLayout(); + } + $this->set('metaGroup', 'Sync'); + $this->render('preview_' . $scope); + } + } + + public function downloadOrg($brood_id, $org_id) + { + $result = $this->Broods->downloadOrg($brood_id, $org_id); + $success = __('Organisation fetched from remote.'); + $fail = __('Could not save the remote organisation'); + if ($this->ParamHandler->isRest()) { + if ($result) { + return $this->RestResponse->saveSuccessResponse('Brood', 'downloadOrg', $brood_id, 'json', $success); + } else { + return $this->RestResponse->saveFailResponse('Brood', 'downloadOrg', $brood_id, $fail, 'json'); + } + } else { + if ($result) { + $this->Flash->success($success); + } else { + $this->Flash->error($fail); + } + $this->redirect($this->referer()); + } + } +} diff --git a/src/Controller/Component/ACLComponent.php b/src/Controller/Component/ACLComponent.php index 1cc9897..9917fe6 100644 --- a/src/Controller/Component/ACLComponent.php +++ b/src/Controller/Component/ACLComponent.php @@ -534,6 +534,43 @@ class ACLComponent extends Component ] ] ], + 'Sync' => [ + 'Broods' => [ + 'label' => __('Broods'), + 'url' => '/broods/index', + 'children' => [ + 'index' => [ + 'url' => '/broods/index', + 'label' => __('List broods') + ], + 'add' => [ + 'url' => '/broods/add', + 'label' => __('Add brood'), + 'popup' => 1 + ], + 'view' => [ + 'url' => '/broods/view/{{id}}', + 'label' => __('View brood'), + 'actions' => ['delete', 'edit', 'view'], + 'skipTopMenu' => 1 + ], + 'edit' => [ + 'url' => '/broods/edit/{{id}}', + 'label' => __('Edit brood'), + 'actions' => ['edit', 'delete', 'view'], + 'skipTopMenu' => 1, + 'popup' => 1 + ], + 'delete' => [ + 'url' => '/broods/delete/{{id}}', + 'label' => __('Delete brood'), + 'actions' => ['delete', 'edit', 'view'], + 'skipTopMenu' => 1, + 'popup' => 1 + ] + ] + ] + ], 'Administration' => [ 'Roles' => [ 'label' => __('Roles'), diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 988c7d7..faafe66 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -90,7 +90,12 @@ class CRUDComponent extends Component $this->Controller->set('fields', $params['fields']); } if ($this->request->is('post')) { - $patchEntityParams = []; + $patchEntityParams = [ + 'associated' => [] + ]; + if (!empty($params['id'])) { + unset($params['id']); + } $input = $this->__massageInput($params); if (!empty($params['fields'])) { $patchEntityParams['fields'] = $params['fields']; @@ -156,33 +161,7 @@ class CRUDComponent extends Component private function saveMetaFields($id, $input) { - foreach ($input['metaFields'] as $templateID => $metaFields) { - $metaTemplates = $this->MetaTemplates->find()->where([ - 'id' => $templateID, - 'enabled' => 1 - ])->contain(['MetaTemplateFields'])->first(); - $fieldNameToId = []; - foreach ($metaTemplates->meta_template_fields as $i => $metaTemplateField) { - $fieldNameToId[$metaTemplateField->field] = $metaTemplateField->id; - } - foreach ($metaFields as $metaField => $values) { - if (!is_array($values)) { - $values = [$values]; - } - foreach ($values as $value) { - if ($value !== '') { - $temp = $this->MetaFields->newEmptyEntity(); - $temp->field = $metaField; - $temp->value = $value; - $temp->scope = $this->Table->metaFields; - $temp->parent_id = $id; - $temp->meta_template_id = $templateID; - $temp->meta_template_field_id = $fieldNameToId[$metaField]; - $this->MetaFields->save($temp); - } - } - } - } + $this->Table->saveMetaFields($id, $input); } private function __massageInput($params) @@ -215,7 +194,9 @@ class CRUDComponent extends Component $this->Controller->set('fields', $params['fields']); } if ($this->request->is(['post', 'put'])) { - $patchEntityParams = []; + $patchEntityParams = [ + 'associated' => [] + ]; $input = $this->__massageInput($params); if (!empty($params['fields'])) { $patchEntityParams['fields'] = $params['fields']; diff --git a/src/Controller/Component/CustomPaginationComponent.php b/src/Controller/Component/CustomPaginationComponent.php new file mode 100644 index 0000000..0f8871a --- /dev/null +++ b/src/Controller/Component/CustomPaginationComponent.php @@ -0,0 +1,103 @@ + 10, + 'direction' => 'asc' + ]; + + protected $settings = [ + + ]; + + protected $validFields = [ + 'limit', + 'page', + 'sort', + 'direction' + ]; + + public function paginate(array $data): array + { + + $request = $this->_registry->getController()->getRequest(); + $params = $request->getQueryParams(); + $settings = $this->defaults; + foreach ($this->validFields as $validField) { + if (isset($params[$validField])) { + $settings[$validField] = $params[$validField]; + } + } + $count = count($data); + if (!empty($settings['sort'])) { + $data = $this->_sortData($data, $settings); + } + if (!empty($settings['limit'])) { + $data = $this->_truncateData($data, $settings); + } + $this->_setPagingParams($settings, $count, count($data)); + return $data; + } + + protected function _sortData(array $data, array &$settings): array + { + return Hash::sort($data, '{n}.' . $settings['sort'], strtolower($settings['direction'])); + } + + protected function _truncateData(array $data, array $settings): array + { + $page = $settings['page'] ?? 1; + $limit = $settings['limit'] ?? 50; + $offset = ($page - 1) * $limit; + return array_slice($data, $offset, $limit); + } + + protected function _setPagingParams(array $settings, int $count, int $currentCount): void + { + $controller = $this->getController(); + $request = $controller->getRequest(); + $limit = $settings['limit'] ?? 0; + $pageCount = empty($settings['limit']) ? 1 : ceil($count/$limit); + $page = $settings['page'] ?? 1; + $start = $end = 0; + $prevPage = $page > 1; + $nextPage = true; + if ($count) { + $nextPage = $count > ($page * $limit); + } + if ($currentCount > 0) { + $start = (($page - 1) * $limit) + 1; + $end = $start + $currentCount - 1; + } + $paging = [ + 'count' => $count, + 'current' => $currentCount, + 'perPage' => $limit, + 'page' => $page, + 'requestedPage' => $settings['page'] ?? 1, + 'pageCount' => $pageCount, + 'start' => $start, + 'end' => $end, + 'prevPage' => $page > 1, + 'nextPage' => $nextPage + ]; + $paging = ['organisations' => $paging + $settings]; + $controller->setRequest($request->withAttribute('paging', $paging)); + } +} diff --git a/src/Model/Table/AlignmentsTable.php b/src/Model/Table/AlignmentsTable.php index 16064ca..ad7e10f 100644 --- a/src/Model/Table/AlignmentsTable.php +++ b/src/Model/Table/AlignmentsTable.php @@ -22,5 +22,24 @@ class AlignmentsTable extends AppTable ->notEmptyString('organisation_id') ->requirePresence(['individual_id', 'organisation_id'], 'create'); return $validator; + } + + public function setAlignment($organisation_id, $individual_id, $type): void + { + $query = $this->find(); + $query->where([ + 'organisation_id' => $organisation_id, + 'individual_id' => $individual_id + ]); + $existingAlignment = $query->first(); + if (empty($existingAlignment)) { + $alignment = $this->newEmptyEntity(); + $data = [ + 'organisation_id' => $organisation_id, + 'individual_id' => $individual_id, + 'type' => $type + ]; + $this->patchEntity($alignment, $data); + } } } diff --git a/src/Model/Table/AppTable.php b/src/Model/Table/AppTable.php index 3d3ae9d..32d2e67 100644 --- a/src/Model/Table/AppTable.php +++ b/src/Model/Table/AppTable.php @@ -6,10 +6,44 @@ use Cake\ORM\Table; use Cake\Validation\Validator; use Cake\Core\Configure; use Cake\Core\Configure\Engine\PhpConfig; +use Cake\ORM\TableRegistry; class AppTable extends Table { public function initialize(array $config): void { } + + public function saveMetaFields($id, $input) + { + $this->MetaFields = TableRegistry::getTableLocator()->get('MetaFields'); + $this->MetaTemplates = TableRegistry::getTableLocator()->get('MetaTemplates'); + foreach ($input['metaFields'] as $templateID => $metaFields) { + $metaTemplates = $this->MetaTemplates->find()->where([ + 'id' => $templateID, + 'enabled' => 1 + ])->contain(['MetaTemplateFields'])->first(); + $fieldNameToId = []; + foreach ($metaTemplates->meta_template_fields as $i => $metaTemplateField) { + $fieldNameToId[$metaTemplateField->field] = $metaTemplateField->id; + } + foreach ($metaFields as $metaField => $values) { + if (!is_array($values)) { + $values = [$values]; + } + foreach ($values as $value) { + if ($value !== '') { + $temp = $this->MetaFields->newEmptyEntity(); + $temp->field = $metaField; + $temp->value = $value; + $temp->scope = $this->Table->metaFields; + $temp->parent_id = $id; + $temp->meta_template_id = $templateID; + $temp->meta_template_field_id = $fieldNameToId[$metaField]; + $this->MetaFields->save($temp); + } + } + } + } + } } diff --git a/src/Model/Table/BroodsTable.php b/src/Model/Table/BroodsTable.php new file mode 100644 index 0000000..51424f1 --- /dev/null +++ b/src/Model/Table/BroodsTable.php @@ -0,0 +1,120 @@ +addBehavior('UUID'); + $this->BelongsTo( + 'Organisations' + ); + $this->setDisplayField('name'); + } + + public function validationDefault(Validator $validator): Validator + { + return $validator; + } + + public function queryStatus($id) + { + $brood = $this->find()->where(['id' => $id])->first(); + $http = new Client(); + $start = microtime(true); + $response = $http->get($brood['url'] . '/instance/status.json', [], [ + 'headers' => [ + 'Authorization' => $brood['authkey'], + 'Accept' => 'Application/json', + 'Content-type' => 'Application/json' + ] + ]); + $ping = ((int)(100 * (microtime(true) - $start))); + $errors = [ + 403 => [ + 'error' => __('Authentication failure'), + 'reason' => __('Invalid user credentials.') + ], + 405 => [ + 'error' => __('Insufficient privileges'), + 'reason' => __('The remote user account doesn\'t have the required privileges to synchronise.') + ], + 500 => [ + 'error' => __('Internal error'), + 'reason' => __('Something is probably broken on the remote side. Get in touch with the instance owner.') + ] + ]; + $result = [ + 'code' => $response->getStatusCode() + ]; + if ($response->isOk()) { + $raw = $response->getJson(); + $result['response']['role'] = $raw['user']['role']; + $result['response']['user'] = $raw['user']['username']; + $result['response']['application'] = $raw['application']; + $result['response']['version'] = $raw['version']; + $result['ping'] = $ping; + } else { + $result['error'] = $errors[$result['code']]['error']; + $result['reason'] = $errors[$result['code']]['reason']; + $result['ping'] = $ping; + } + return $result; + } + + public function queryIndex($id, $scope, $filter) + { + $brood = $this->find()->where(['id' => $id])->first(); + if (empty($brood)) { + throw new NotFoundException(__('Brood not found')); + } + $http = new Client(); + $filterQuery = empty($filter) ? '' : '?quickFilter=' . urlencode($filter); + $response = $http->get($brood['url'] . '/' . $scope . '/index.json' . $filterQuery , [], [ + 'headers' => [ + 'Authorization' => $brood['authkey'], + 'Accept' => 'Application/json', + 'Content-type' => 'Application/json' + ] + ]); + if ($response->isOk()) { + return $response->getJson(); + } else { + return false; + } + } + + public function downloadOrg($brood_id, $org_id) + { + $query = $this->find(); + $brood = $query->where(['id' => $brood_id])->first(); + if (empty($brood)) { + throw new NotFoundException(__('Brood not found')); + } + $http = new Client(); + $response = $http->get($brood['url'] . '/organisations/view/' . $org_id . '/index.json' , [], [ + 'headers' => [ + 'Authorization' => $brood['authkey'], + 'Accept' => 'Application/json', + 'Content-type' => 'Application/json' + ] + ]); + if ($response->isOk()) { + $org = $response->getJson(); + $this->Organisation = TableRegistry::getTableLocator()->get('Organisations'); + $result = $this->Organisation->captureOrg($org); + return $result; + } else { + return false; + } + } +} diff --git a/src/Model/Table/IndividualsTable.php b/src/Model/Table/IndividualsTable.php index 466b731..1611a5f 100644 --- a/src/Model/Table/IndividualsTable.php +++ b/src/Model/Table/IndividualsTable.php @@ -44,4 +44,51 @@ class IndividualsTable extends AppTable ->requirePresence(['email'], 'create'); return $validator; } + + public function captureIndividual($individual): ?int + { + if (!empty($individual['uuid'])) { + $existingIndividual = $this->find()->where([ + 'uuid' => $individual['uuid'] + ])->first(); + } else { + return null; + } + if (empty($existingIndividual)) { + $entity = $this->newEntity($individual, ['associated' => []]); + if (!$this->save($entity)) { + return null; + } + $individual = $entity; + } else { + $reserved = ['id', 'uuid', 'metaFields']; + foreach ($individual as $field => $value) { + if (in_array($field, $reserved)) { + continue; + } + $existingIndividual->$field = $value; + } + if (!$this->save($existingIndividual, ['associated' => false])) { + return null; + } + $individual = $existingIndividua; + } + $this->postCaptureActions($individual); + return $individual->id; + } + + public function postCaptureActions($individual): void + { + if (!empty($individual['metaFields'])) { + $this->saveMetaFields($id, $individual); + } + if (!empty($individual['alignments'])) { + foreach ($individual['alignments'] as $alignment) { + $org_id = $this->Organisation->captureOrg($alignment['organisation']); + if ($org_id) { + $this->Alignments->setAlignment($org_id, $individual->id, $alignment['type']); + } + } + } + } } diff --git a/src/Model/Table/OrganisationsTable.php b/src/Model/Table/OrganisationsTable.php index 52f08ac..5eeb756 100644 --- a/src/Model/Table/OrganisationsTable.php +++ b/src/Model/Table/OrganisationsTable.php @@ -5,11 +5,16 @@ namespace App\Model\Table; use App\Model\Table\AppTable; use Cake\ORM\Table; use Cake\Validation\Validator; +use Cake\Error\Debugger; class OrganisationsTable extends AppTable { public $metaFields = 'organisation'; + protected $_accessible = [ + 'id' => false + ]; + public function initialize(array $config): void { parent::initialize($config); @@ -47,4 +52,47 @@ class OrganisationsTable extends AppTable ->requirePresence(['name', 'uuid'], 'create'); return $validator; } + + public function captureOrg($org): ?int + { + if (!empty($org['id'])) { + unset($org['id']); + } + if (!empty($org['uuid'])) { + $existingOrg = $this->find()->where([ + 'uuid' => $org['uuid'] + ])->first(); + } else { + return null; + } + if (empty($existingOrg)) { + $data = $this->newEmptyEntity(); + $data = $this->patchEntity($data, $org, ['associated' => []]); + if (!$this->save($data)) { + return null; + } + $savedOrg = $data; + } else { + $reserved = ['id', 'uuid', 'metaFields']; + foreach ($org as $field => $value) { + if (in_array($field, $reserved)) { + continue; + } + $existingOrg->$field = $value; + } + if (!$this->save($existingOrg)) { + return null; + } + $savedOrg = $existingOrg; + } + $this->postCaptureActions($savedOrg->id, $org); + return $savedOrg->id; + } + + public function postCaptureActions($id, $org) + { + if (!empty($org['metaFields'])) { + $this->saveMetaFields($id, $org); + } + } } diff --git a/templates/Broods/add.php b/templates/Broods/add.php new file mode 100644 index 0000000..ffd525f --- /dev/null +++ b/templates/Broods/add.php @@ -0,0 +1,53 @@ +element('genericElements/Form/genericForm', array( + 'data' => array( + 'description' => __('Individuals are natural persons. They are meant to describe the basic information about an individual that may or may not be a user of this community. Users in genral require an individual object to identify the person behind them - however, no user account is required to store information about an individual. Individuals can have affiliations to organisations and broods as well as cryptographic keys, using which their messages can be verified and which can be used to securely contact them.'), + 'model' => 'Organisations', + 'fields' => array( + array( + 'field' => 'name' + ), + array( + 'field' => 'url', + 'label' => __('URL') + ), + array( + 'field' => 'authkey', + 'label' => 'Authkey', + 'type' => 'authkey', + 'default' => '' + ), + array( + 'field' => 'description', + 'type' => 'textarea' + ), + array( + 'field' => 'organisation_id', + 'label' => __('Owner organisation'), + 'options' => $dropdownData['organisation'], + 'type' => 'dropdown' + ), + array( + 'field' => 'trusted', + 'label' => __('Trusted upstream source'), + 'type' => 'checkbox' + ), + array( + 'field' => 'pull', + 'label' => __('Enable pulling of trust information'), + 'type' => 'checkbox' + ), + array( + 'field' => 'skip_proxy', + 'label' => 'Skip proxy', + 'type' => 'checkbox' + ) + ), + 'submit' => array( + 'action' => $this->request->getParam('action') + ) + ) + )); +?> + diff --git a/templates/Broods/index.php b/templates/Broods/index.php new file mode 100644 index 0000000..9a3e103 --- /dev/null +++ b/templates/Broods/index.php @@ -0,0 +1,83 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'simple', + 'children' => [ + 'data' => [ + 'type' => 'simple', + 'text' => __('Add brood'), + 'class' => 'btn btn-primary', + 'popover_url' => '/broods/add' + ] + ] + ], + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'sort' => 'name', + 'data_path' => 'name', + ], + [ + 'name' => 'Connection test', + 'data_path' => 'id', + 'element' => 'connection_test' + ], + [ + 'name' => __('Url'), + 'sort' => 'url', + 'data_path' => 'url', + ], + [ + 'name' => __('Description'), + 'data_path' => 'description', + ], + [ + 'name' => __('Owner Organisation'), + 'sort' => 'organisation.name', + 'data_path' => 'organisation', + 'element' => 'org' + ] + ], + 'title' => __('Broods Index'), + 'description' => __('Cerebrate can connect to other Cerebrate instances to exchange trust information and to instrument interconnectivity between connected local tools. Each such Cerebrate instance with its connected tools is considered to be a brood.'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/broods/view', + 'url_params_data_paths' => ['id'], + 'icon' => 'eye' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/broods/edit/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'edit' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/broods/delete/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'trash' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/Broods/preview_individuals.php b/templates/Broods/preview_individuals.php new file mode 100644 index 0000000..85a565d --- /dev/null +++ b/templates/Broods/preview_individuals.php @@ -0,0 +1,65 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value', + 'additionalUrlParams' => $brood_id . '/individuals' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'data_path' => 'id', + ], + [ + 'name' => __('Email'), + 'sort' => 'email', + 'data_path' => 'email', + ], + [ + 'name' => __('First Name'), + 'sort' => 'first_name', + 'data_path' => 'first_name', + ], + [ + 'name' => __('Last Name'), + 'sort' => 'last_name', + 'data_path' => 'last_name', + ], + [ + 'name' => __('Alignments'), + 'data_path' => 'alignments', + 'element' => 'alignments', + 'scope' => 'organisation' + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'data_path' => 'uuid', + 'placeholder' => __('Leave empty to auto generate') + ], + ], + 'title' => __('Individuals Index'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/broods/downloadIndividual/' . $brood_id, + 'url_params_data_paths' => ['id'], + 'title' => __('Download'), + 'icon' => 'download' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/Broods/preview_organisations.php b/templates/Broods/preview_organisations.php new file mode 100644 index 0000000..5bded24 --- /dev/null +++ b/templates/Broods/preview_organisations.php @@ -0,0 +1,70 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value', + 'additionalUrlParams' => $brood_id . '/organisations' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'class' => 'short', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'class' => 'short', + 'data_path' => 'name', + 'sort' => 'name' + ], + [ + 'name' => __('UUID'), + 'class' => 'short', + 'data_path' => 'uuid', + ], + [ + 'name' => __('URL'), + 'class' => 'short', + 'data_path' => 'url', + ], + [ + 'name' => __('Nationality'), + 'data_path' => 'nationality', + 'sort' => 'nationality' + ], + [ + 'name' => __('Sector'), + 'data_path' => 'sector', + 'sort' => 'sector' + ], + [ + 'name' => __('Type'), + 'data_path' => 'type', + 'sort' => 'type' + ] + ], + 'title' => __('Organisation Index'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/broods/downloadOrg/' . $brood_id, + 'url_params_data_paths' => ['id'], + 'title' => __('Download'), + 'icon' => 'download' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/Broods/preview_sharing_groups.php b/templates/Broods/preview_sharing_groups.php new file mode 100644 index 0000000..1348182 --- /dev/null +++ b/templates/Broods/preview_sharing_groups.php @@ -0,0 +1,50 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value', + 'additionalUrlParams' => $brood_id . '/sharingGroups' + ] + ] + ], + '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', + ] + ], + 'title' => __('Sharing Groups Index'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/broods/downloadSharingGroup/' . $brood_id, + 'url_params_data_paths' => ['id'], + 'title' => __('Download'), + 'icon' => 'download' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/Broods/view.php b/templates/Broods/view.php new file mode 100644 index 0000000..5a0c03e --- /dev/null +++ b/templates/Broods/view.php @@ -0,0 +1,49 @@ +element( + '/genericElements/SingleViews/single_view', + [ + 'title' => __('Cererate Brood View'), + 'data' => $entity, + 'fields' => [ + [ + 'key' => __('ID'), + 'path' => 'id' + ], + [ + 'key' => __('Name'), + 'path' => 'name' + ], + [ + 'key' => __('Url'), + 'path' => 'url' + ], + [ + 'key' => __('Description'), + 'path' => 'description' + ], + [ + 'key' => __('Owner'), + 'path' => 'organisation.name' + ] + ], + 'metaFields' => empty($metaFields) ? [] : $metaFields, + 'children' => [ + [ + 'url' => '/Broods/previewIndex/{{0}}/organisations', + 'url_params' => ['id'], + 'title' => __('Organisations') + ], + [ + 'url' => '/Broods/previewIndex/{{0}}/individuals', + 'url_params' => ['id'], + 'title' => __('Individuals') + ], + [ + 'url' => '/Broods/previewIndex/{{0}}/sharingGroups', + 'url_params' => ['id'], + 'title' => __('Sharing groups') + ] + ] + ] +); diff --git a/templates/element/genericElements/IndexTable/Fields/connection_test.php b/templates/element/genericElements/IndexTable/Fields/connection_test.php new file mode 100644 index 0000000..c79370b --- /dev/null +++ b/templates/element/genericElements/IndexTable/Fields/connection_test.php @@ -0,0 +1,14 @@ +Hash->extract($row, $field['data_path'])[0]; + echo sprintf( + '