From 4cdca54223bc99d53b18979dfdf85f21f5f74a08 Mon Sep 17 00:00:00 2001 From: Matthieu Leproux Date: Wed, 29 Sep 2021 16:19:22 +0200 Subject: [PATCH] fixes #1491 better user filter for activity tab --- .../themes/default/template/user_activity.tpl | 53 +++++++++++++------ include/ws_functions/pwg.php | 31 ++++++++++- language/en_UK/admin.lang.php | 2 + language/fr_FR/admin.lang.php | 2 + 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/admin/themes/default/template/user_activity.tpl b/admin/themes/default/template/user_activity.tpl index 03eae0181..1f989851f 100644 --- a/admin/themes/default/template/user_activity.tpl +++ b/admin/themes/default/template/user_activity.tpl @@ -14,16 +14,12 @@ var usersCache = new UsersCache({ rootUrl: '{$ROOT_URL}' }); -usersCache.selectize(jQuery('[data-selectize=users]')); - -jQuery(".cancel-icon").click(function() { - jQuery(".user-selecter")[0].selectize.setValue(null); - return false; -}); - const color_icons = ["icon-red", "icon-blue", "icon-yellow", "icon-purple", "icon-green"]; const users_key = "{"Users"|@translate}" +const line_key = "{'%s line'|translate}"; +const lines_key = "{'%s lines'|translate}"; + {*<-- Translation keys -->*} var actionType_add = "{'add'|translate}"; @@ -112,22 +108,46 @@ function get_user_activity() { /* console log to help debug */ {* console.log(data); *} - setCreationDate(data.result[data.result.length-1].date, data.result[0].date); + setCreationDate(data.result['result_lines'][data.result['result_lines'].length-1].date, data.result['result_lines'][0].date); $(".loading").hide(); - data.result.forEach(line => { + data.result['result_lines'].forEach(line => { lineConstructor(line); }); - displayLine(data); + + fillUserFilter(data.result['filterable_users']); }, error: (e) => { console.log("ajax call failed"); console.log(e); } - }) } +function fillUserFilter(user_tab) { + + var index = 0; + for (const [key, value] of Object.entries(user_tab)) { + console.log(key, value); + if (value > 1) { + var newOption = ""; + } else { + var newOption = ""; + } + + index++; + $(".user-selecter").append(newOption); + } + + jQuery('.user-selecter').selectize(); + + jQuery(".user-selecter")[0].selectize.setValue(null); + + jQuery(".cancel-icon").click(function() { + jQuery(".user-selecter")[0].selectize.setValue(null); + }); +} + function lineConstructor(line) { let newLine = $("#-1").clone(); @@ -612,8 +632,9 @@ function setCreationDate(startDate, endDate) { $(document).ready(function () { $('select').on('change', function (user) { + console.log($(".selectize-input .item")[0].innerText.split(" ")[0]) try { - filterUsers($(".selectize-input .item")[0].innerHTML); + filterUsers($(".selectize-input .item")[0].innerText.split(" ")[0]); } catch (error) { showAllLines(); let lines = $(".line"); @@ -634,8 +655,8 @@ $(document).ready(function () {
{'Selected user'|translate} - + @@ -759,7 +780,7 @@ $(document).ready(function () { .tab-title .action-title, .line .action-section { - min-width: 310px; + min-width: 320px; max-width: 340px; } .tab-title .action-title { @@ -768,7 +789,7 @@ $(document).ready(function () { .tab-title .date-title, .line .date-section { - min-width: 240px; + min-width: 280px; max-width: 300px; } diff --git a/include/ws_functions/pwg.php b/include/ws_functions/pwg.php index 31e98d4ba..11b149d25 100644 --- a/include/ws_functions/pwg.php +++ b/include/ws_functions/pwg.php @@ -504,6 +504,7 @@ SELECT } $username_of = array(); + $user_id_list = array(); if (count($user_ids) > 0) { $query = ' @@ -514,6 +515,17 @@ SELECT WHERE `'.$conf['user_fields']['id'].'` IN ('.implode(',', array_keys($user_ids)).') ;'; $username_of = query2array($query, 'user_id', 'username'); + + $query = ' +SELECT + performed_by, + count(*) as nb_lines + FROM '.ACTIVITY_TABLE.' + GROUP BY + performed_by + ;'; + + $user_id_list = query2array($query, 'performed_by', 'nb_lines'); } foreach ($output_lines as $idx => $output_line) @@ -522,7 +534,7 @@ SELECT { foreach ($output_line['object_id'] as $user_id) { - @$output_lines[$idx]['details']['users'][] = isset($username_of[$user_id]) ? $username_of[$user_id] : 'user #'.$user_id; + @$output_lines[$idx]['details']['users'][] = isset($username_of[$user_id]) ? $username_of[$user_id] : 'user#'.$user_id; } if (isset($output_lines[$idx]['details']['users'])) @@ -532,7 +544,22 @@ SELECT } } - return $output_lines; + $filterable_users = array(); + foreach ($user_id_list as $key => $value) { + if (isset($username_of[$key])) { + $filterable_users[$username_of[$key]] = $value; + } else { + $filterable_users['user#'.$key] = $value; + } + } + + unset($filterable_users['guest']); + + // return $output_lines; + return array( + 'result_lines' => $output_lines, + 'filterable_users' => $filterable_users, + ); } /** diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php index 7107fd927..33d286fc1 100644 --- a/language/en_UK/admin.lang.php +++ b/language/en_UK/admin.lang.php @@ -1242,3 +1242,5 @@ $lang['Equivalent to deactivation. The user is still in the list, but can no lon $lang['%s MB'] = '%s MB'; $lang['Your selection'] = 'Your selection'; $lang['action succesfully performed.'] = 'action succesfully performed.'; +$lang['%s lines'] = "%s lines"; +$lang['%s line'] = "%s line"; diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php index 581215315..c437ffd28 100644 --- a/language/fr_FR/admin.lang.php +++ b/language/fr_FR/admin.lang.php @@ -1249,3 +1249,5 @@ $lang['Edit photo'] = 'Éditer la photo'; $lang['Delete tag "%s"?'] = 'Supprimer le tag "%s" ?'; $lang['Your selection'] = 'Votre selection'; $lang['action succesfully performed.'] = 'action effectuée avec succès.'; +$lang['%s lines'] = "%s lignes"; +$lang['%s line'] = "%s ligne";