new: [delegations] Added delegation index, fixes #5023

/event_delegations/index

accepts context as a parameter with the following possible values:
- pending: all delegations awaiting my organisation's review (default)
- issued: all delegations issued by my organisation

parameters can be passed via key:value parameters or via json objects
pull/5048/head
iglocska 2019-08-23 11:38:47 +02:00
parent f6f5a8f0f5
commit 8769bed9ec
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
6 changed files with 195 additions and 5 deletions

View File

@ -179,4 +179,60 @@ class EventDelegationsController extends AppController
$this->render('ajax/delete_delegation');
}
}
public function index()
{
$context = 'pending';
if ($this->request->is('post') && !empty($this->request->data['context'])) {
$context = $this->request->data['context'];
} else if (!empty($this->params['named']['context'])) {
$context = $this->params['named']['context'];
}
if ($context === 'pending') {
$conditions = array('EventDelegation.org_id' => $this->Auth->user('org_id'));
} else if ($context === 'issued') {
$conditions = array('EventDelegation.requester_org_id' => $this->Auth->user('org_id'));
} else {
throw new InvalidArgumentException('Invalid context. Expected values: pending or issued.');
}
if (!empty($this->params['named']['value'])) {
$temp = array();
$temp['lower(EventDelegation.message) like'] = '%' . strtolower(trim($this->params['named']['value'])) . '%';
$temp['lower(Event.info) like'] = '%' . strtolower(trim($this->params['named']['value'])) . '%';
$temp['lower(Org.name) like'] = '%' . strtolower(trim($this->params['named']['value'])) . '%';
$temp['lower(RequesterOrg.name) like'] = '%' . strtolower(trim($this->params['named']['value'])) . '%';
$conditions['AND'][] = array('OR' => $temp);
}
$org_fields = array('id', 'name', 'uuid');
$event_fields = array('id', 'info', 'uuid', 'analysis', 'distribution', 'threat_level_id', 'date', 'attribute_count');
$params = array(
'conditions' => $conditions,
'recursive' => -1,
'contain' => array(
'Event' => array('fields' => $event_fields),
'Org' => array('fields' => $org_fields),
'RequesterOrg' => array('fields' => $org_fields)
)
);
$this->paginate = array_merge($this->paginate, $params);
$delegation_requests = $this->paginate();
foreach ($delegation_requests as $k => $v) {
if ($v['EventDelegation']['distribution'] == -1) {
unset($delegation_requests[$k]['EventDelegation']['distribution']);
}
if ($v['EventDelegation']['sharing_group_id'] == 0) {
unset($delegation_requests[$k]['EventDelegation']['sharing_group_id']);
}
unset($v['EventDelegation']);
$delegation_requests[$k]['EventDelegation'] = array_merge($delegation_requests[$k]['EventDelegation'], $v);
$delegation_requests[$k] = array('EventDelegation' => $delegation_requests[$k]['EventDelegation']);
}
if ($this->_isRest()) {
return $this->RestResponse->viewData($delegation_requests, $this->response->type());
} else {
$this->set('context', $context);
$this->set('delegation_requests', $delegation_requests);
$this->set('passedArgs', json_encode($this->passedArgs, true));
}
}
}

View File

@ -1,12 +1,20 @@
<?php
$url_data = Hash::extract($row, $field['data_path']);
$data_elements = Hash::extract($row, $field['data_path']);
$links = array();
foreach ($url_data as $url) {
foreach ($data_elements as $data) {
if (strpos($field['url'], '%s') !== false) {
$url = sprintf(
$field['url'],
$data
);
} else {
$url = $data;
}
$links[] = sprintf(
'<a href="%s" title="%s">%s</a>',
h($url['url']),
h($url['name']),
h($url['name'])
h($url),
empty($field['title']) ? h($data) : h($field['title']),
h($data)
);
}
echo implode('<br />', $links);

View File

@ -0,0 +1,9 @@
<?php
$org = Hash::extract($row, $field['data_path']);
echo sprintf(
'<a href="%s/organisations/view/%s">%s</a>',
$baseurl,
h($org['id']),
h($org['name'])
);
?>

View File

@ -302,6 +302,11 @@
'url' => '/events/proposalEventIndex',
'text' => __('Events with proposals')
));
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'viewDelegations',
'url' => '/event_delegations/index/context:pending',
'text' => __('View delegation requests')
));
echo $this->element('/genericElements/SideMenu/side_menu_divider');
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'url' => '/events/export',

View File

@ -42,6 +42,10 @@
'text' => __('Events with proposals'),
'url' => '/events/proposalEventIndex'
),
array(
'url' => '/event_delegations/index/context:pending',
'text' => __('View delegation requests')
),
array(
'type' => 'separator'
),

View File

@ -0,0 +1,108 @@
<?php
/*
* echo $this->element('/genericElements/IndexTable/index_table', array(
* 'top_bar' => (
* // search/filter bar information compliant with ListTopBar
* ),
* 'data' => array(
// the actual data to be used
* ),
* 'fields' => array(
* // field list with information for the paginator
* ),
* 'title' => optional title,
* 'description' => optional description
* ));
*
*/
echo '<div class="index">';
echo $this->element('/genericElements/IndexTable/index_table', array(
'data' => array(
'data' => $delegation_requests,
'top_bar' => array(
'children' => array(
array(
'type' => 'simple',
'children' => array(
array(
'active' => $context === 'pending',
'url' => $baseurl . '/event_delegations/index/context:pending',
'text' => __('Pending'),
),
array(
'active' => $context === 'issued',
'url' => $baseurl . '/event_delegations/index/context:issued',
'text' => __('Issued'),
)
),
),
array(
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value'
)
)
),
'fields' => array(
array(
'name' => __('Id'),
'sort' => 'EventDelegation.id',
'class' => 'short',
'data_path' => 'EventDelegation.id',
),
array(
'name' => __('Requester'),
'class' => 'short',
'element' => 'org',
'sort' => 'EventDelegation.requester_org_id',
'data_path' => 'EventDelegation.RequesterOrg'
),
array(
'name' => __('Recipient'),
'class' => 'short',
'element' => 'org',
'sort' => 'EventDelegation.org_id',
'data_path' => 'EventDelegation.Org'
),
array(
'name' => __('Event id'),
'sort' => 'EventDelegation.event_id',
'element' => 'links',
'class' => 'short',
'data_path' => 'EventDelegation.event_id',
'url' => $baseurl . '/events/view/%s'
),
array(
'name' => __('Event info'),
'data_path' => 'EventDelegation.Event.info'
),
array(
'name' => __('Message'),
'data_path' => 'EventDelegation.message'
)
),
'title' => __('Delegation index'),
'description' => __('')
)
));
echo '</div>';
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'event-collection', 'menuItem' => 'viewDelegations'));
?>
<script type="text/javascript">
var passedArgsArray = <?php echo $passedArgs; ?>;
if (passedArgsArray['context'] === undefined) {
passedArgsArray['context'] = 'pending';
}
$(document).ready(function() {
$('#quickFilterButton').click(function() {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
});
$('#quickFilterField').on('keypress', function (e) {
if(e.which === 13) {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
}
});
});
</script>