new: [tag index] simple/advanced view

- simple view excludes eventtags / attributetags / sightings
- helps with heavier instances

- refactor of the index to the new generators
- new elements for the generators added
pull/6538/head
iglocska 2020-11-02 13:54:20 +01:00
parent 4664238d1f
commit b2bed4f8ed
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
8 changed files with 125 additions and 63 deletions

View File

@ -41,6 +41,14 @@ class TagsController extends AppController
if ($this->_isSiteAdmin()) {
$this->paginate['contain']['User'] = array('fields' => array('id', 'email'));
}
$filterData = array(
'request' => $this->request,
'named_params' => $this->params['named'],
'paramArray' => ['favouritesOnly', 'filter', 'searchall', 'name', 'search', 'exclude_statistics'],
'ordered_url_params' => @compact($paramArray)
);
$exception = false;
$passedArgsArray = $this->_harvestParameters($filterData, $exception);
$taxonomies = $this->Taxonomy->listTaxonomies(array('full' => false, 'enabled' => true));
$taxonomyNamespaces = array();
if (!empty($taxonomies)) {
@ -49,9 +57,8 @@ class TagsController extends AppController
}
}
$taxonomyTags = array();
$passedArgsArray = array();
$this->Event->recursive = -1;
if ($favouritesOnly) {
if (!empty($passedArgsArray['favouritesOnly'])) {
$tag_id_list = $this->Tag->FavouriteTag->find('list', array(
'conditions' => array('FavouriteTag.user_id' => $this->Auth->user('id')),
'fields' => array('FavouriteTag.tag_id')
@ -61,19 +68,13 @@ class TagsController extends AppController
}
$this->paginate['conditions']['AND']['Tag.id'] = $tag_id_list;
}
if (isset($this->params['named']['searchall'])) {
$passedArgsArray['all'] = $this->params['named']['searchall'];
} elseif ($this->request->is('post')) {
$validNames = array('filter', 'searchall', 'name', 'search');
foreach ($validNames as $vn) {
if (!empty($this->request->data[$vn])) {
$passedArgsArray['all'] = $this->request->data[$vn];
continue;
}
}
if (!empty($passedArgsArray['searchall'])) {
$this->paginate['conditions']['AND'][] = ['LOWER(Tag.name) LIKE' => '%' . strtolower($passedArgsArray['searchall']) . '%'];
}
if (!empty($passedArgsArray['all'])) {
$this->paginate['conditions']['AND']['LOWER(Tag.name) LIKE'] = '%' . strtolower($passedArgsArray['all']) . '%';
foreach (['name', 'filter', 'search'] as $f) {
if (!empty($passedArgsArray['name'])) {
$this->paginate['conditions']['AND'][] = ['LOWER(Tag.name)' => strtolower($passedArgsArray[$f])];
}
}
if ($this->_isRest()) {
unset($this->paginate['limit']);
@ -81,6 +82,11 @@ class TagsController extends AppController
unset($this->paginate['contain']['AttributeTag']);
$paginated = $this->Tag->find('all', $this->paginate);
} else {
if (!empty($passedArgsArray['exclude_statistics'])) {
unset($this->paginate['contain']['EventTag']);
unset($this->paginate['contain']['AttributeTag']);
$this->set('exclude_statistics', true);
}
$paginated = $this->paginate();
}
$tagList = array();
@ -88,20 +94,22 @@ class TagsController extends AppController
$sgs = $this->Tag->EventTag->Event->SharingGroup->fetchAllAuthorised($this->Auth->user());
foreach ($paginated as $k => $tag) {
$tagList[] = $tag['Tag']['id'];
$paginated[$k]['Tag']['count'] = $this->Tag->EventTag->countForTag($tag['Tag']['id'], $this->Auth->user(), $sgs);
if (!$this->_isRest()) {
$paginated[$k]['event_ids'] = array();
$paginated[$k]['attribute_ids'] = array();
foreach ($paginated[$k]['EventTag'] as $et) {
$paginated[$k]['event_ids'][] = $et['event_id'];
if (empty($passedArgsArray['exclude_statistics'])) {
$paginated[$k]['Tag']['count'] = $this->Tag->EventTag->countForTag($tag['Tag']['id'], $this->Auth->user(), $sgs);
if (!$this->_isRest()) {
$paginated[$k]['event_ids'] = array();
$paginated[$k]['attribute_ids'] = array();
foreach ($paginated[$k]['EventTag'] as $et) {
$paginated[$k]['event_ids'][] = $et['event_id'];
}
unset($paginated[$k]['EventTag']);
foreach ($paginated[$k]['AttributeTag'] as $at) {
$paginated[$k]['attribute_ids'][] = $at['attribute_id'];
}
unset($paginated[$k]['AttributeTag']);
}
unset($paginated[$k]['EventTag']);
foreach ($paginated[$k]['AttributeTag'] as $at) {
$paginated[$k]['attribute_ids'][] = $at['attribute_id'];
}
unset($paginated[$k]['AttributeTag']);
$paginated[$k]['Tag']['attribute_count'] = $this->Tag->AttributeTag->countForTag($tag['Tag']['id'], $this->Auth->user(), $sgs);
}
$paginated[$k]['Tag']['attribute_count'] = $this->Tag->AttributeTag->countForTag($tag['Tag']['id'], $this->Auth->user(), $sgs);
if (!empty($tag['FavouriteTag'])) {
foreach ($tag['FavouriteTag'] as $ft) {
if ($ft['user_id'] == $this->Auth->user('id')) {
@ -128,7 +136,7 @@ class TagsController extends AppController
}
}
}
if (!$this->_isRest()) {
if (!$this->_isRest() && empty($passedArgsArray['exclude_statistics'])) {
$this->loadModel('Sighting');
$sightings['event'] = $this->Sighting->getSightingsForObjectIds($this->Auth->user(), $tagList);
$sightings['attribute'] = $this->Sighting->getSightingsForObjectIds($this->Auth->user(), $tagList, 'attribute');
@ -152,13 +160,13 @@ class TagsController extends AppController
$startDate = date('Y-m-d', strtotime("-3 days", strtotime($startDate)));
$to = date('Y-m-d', time());
for ($date = $startDate; strtotime($date) <= strtotime($to); $date = date('Y-m-d', strtotime("+1 day", strtotime($date)))) {
if (!isset($csv[$k])) {
$csv[$k] = 'Date,Close\n';
if (!isset($paginated[$k]['Tag']['csv'])) {
$paginated[$k]['Tag']['csv'] = 'Date,Close\n';
}
if (isset($tag['sightings'][$date])) {
$csv[$k] .= $date . ',' . $tag['sightings'][$date] . '\n';
$paginated[$k]['Tag']['csv'] .= $date . ',' . $tag['sightings'][$date] . '\n';
} else {
$csv[$k] .= $date . ',0\n';
$paginated[$k]['Tag']['csv'] .= $date . ',0\n';
}
}
}

View File

@ -67,7 +67,7 @@
}
}
$aText = h($aText);
$span_scope = sprintf(
$span_scope = !empty($hide_global_scope) ? '' : sprintf(
'<span class="%s" title="%s" aria-label="%s"><i class="fas fa-%s"></i></span>',
'black-white tag',
!empty($tag['local']) ? __('Local tag') : __('Global tag'),

View File

@ -0,0 +1,21 @@
<?php
if (!empty($field['onclick'])) {
if (!empty($field['onclick_params_data_path'])) {
$data_path_params = [];
foreach ($field['onclick_params_data_path'] as $data_path) {
$data_path_params[] = Hash::extract($row, $data_path)[0];
}
$field['onclick'] = vsprintf($field['onclick'], $data_path_params);
}
}
$title = empty($field['title']) ? __('%s toggle', $field['name']) : $field['title'];
$default = (bool)Hash::extract($row, $field['data_path'])[0];
echo sprintf(
'<div id="%s"><input id="%s%s" type="checkbox" aria-label="%s" onClick="%s" %s /></div>',
empty($field['checkbox_container']) ? 'GenericCheckboxContainer' : h($field['checkbox_container']),
empty($field['checkbox_name']) ? 'GenericCheckbox' : h($field['checkbox_name']),
h($k),
h($title),
$field['onclick'],
$default ? 'checked' : ''
);

View File

@ -0,0 +1,17 @@
<?php
$fieldValue = Hash::extract($row, $field['data_path'])[0];
if (!empty($field['url'])) {
if (!empty($field['url_params_data_path'])) {
$data_path_params = [];
foreach ($field['url_params_data_path'] as $data_path) {
$data_path_params[] = Hash::extract($row, $data_path)[0];
}
$field['url'] = vsprintf($field['url'], $data_path_params);
}
$fieldValue = sprintf(
'<a href="%s">%s</a>',
h($field['url']),
$fieldValue
);
}
echo $fieldValue;

View File

@ -10,7 +10,10 @@
if (is_array($field['url_params_data_paths'])) {
$temp = array();
foreach ($field['url_params_data_paths'] as $path) {
$temp[] = h(Hash::extract($row, $path)[0]);
$extracted_value = Hash::extract($row, $path);
if (!empty($extracted_value)) {
$temp[] = h($extracted_value[0]);
}
}
$url_param_data_paths = implode('/', $temp);
} else {

View File

@ -1,4 +1,15 @@
<?php
$elementId = Hash::extract($row, $field['data_path'])[0];
echo $this->element('sparkline', array('scope' => $field['csv']['scope'], 'id' => $elementId, 'csv' => $field['csv']['data'][$k]));
if (!empty($field['csv_data_path'])) {
$csv = Hash::extract($row, $field['csv_data_path']);
if (!empty($csv)) {
$csv = $csv[0];
}
} else {
$csv = $field['csv']['data'];
}
if (!empty($csv)) {
$scope = empty($field['csv']['scope']) ? '' : $field['csv']['scope'];
echo $this->element('sparkline', array('scope' => $scope, 'id' => $elementId, 'csv' => $csv));
}
?>

View File

@ -6,12 +6,14 @@
}
echo $this->element(
'ajaxTags',
array(
[
'attributeId' => 0,
'tags' => $tags,
'tagAccess' => false,
'static_tags_only' => 1
)
'static_tags_only' => 1,
'scope' => isset($field['scope']) ? $field['scope'] : 'event',
'hide_global_scope' => isset($field['hide_global_scope']) ? $field['hide_global_scope'] : false
]
);
}
?>

View File

@ -224,30 +224,30 @@ function toggleSetting(e, setting, id) {
e.preventDefault();
e.stopPropagation();
switch (setting) {
case 'warninglist_enable':
formID = '#WarninglistIndexForm';
dataDiv = '#WarninglistData';
replacementForm = baseurl + '/warninglists/getToggleField/';
searchString = 'enabled';
break;
case 'favourite_tag':
formID = '#FavouriteTagIndexForm';
dataDiv = '#FavouriteTagData';
replacementForm = baseurl + '/favourite_tags/getToggleField/';
searchString = 'Adding';
break;
case 'activate_object_template':
formID = '#ObjectTemplateIndexForm';
dataDiv = '#ObjectTemplateData';
replacementForm = baseurl + '/ObjectTemplates/getToggleField/';
searchString = 'activated';
break;
case 'noticelist_enable':
formID = '#NoticelistIndexForm';
dataDiv = '#NoticelistData';
replacementForm = baseurl + '/noticelists/getToggleField/';
searchString = 'enabled';
break;
case 'warninglist_enable':
formID = '#WarninglistIndexForm';
dataDiv = '#WarninglistData';
replacementForm = baseurl + '/warninglists/getToggleField/';
searchString = 'enabled';
break;
case 'favourite_tag':
formID = '#FavouriteTagIndexForm';
dataDiv = '#FavouriteTagData';
replacementForm = baseurl + '/favourite_tags/getToggleField/';
searchString = 'Adding';
break;
case 'activate_object_template':
formID = '#ObjectTemplateIndexForm';
dataDiv = '#ObjectTemplateData';
replacementForm = baseurl + '/ObjectTemplates/getToggleField/';
searchString = 'activated';
break;
case 'noticelist_enable':
formID = '#NoticelistIndexForm';
dataDiv = '#NoticelistData';
replacementForm = baseurl + '/noticelists/getToggleField/';
searchString = 'enabled';
break;
}
$(dataDiv).val(id);
var formData = $(formID).serialize();
@ -261,12 +261,12 @@ function toggleSetting(e, setting, id) {
if (result.success) {
var setting = false;
if (result.success.indexOf(searchString) > -1) setting = true;
$('#checkBox_' + id).prop('checked', setting);
$('#' + e.target.id).prop('checked', setting);
}
handleGenericAjaxResponse(data);
},
complete:function() {
$.get(baseurl + replacementForm, function(data) {
$.get(replacementForm, function(data) {
$('#hiddenFormDiv').html(data);
});
$(".loading").hide();