issue #2106 added details to search history

API method modification `ws_history_search`: Added a new property in API return `SEARCH_DETAILS` only for searches.
These details are displayed on the `History` page in the `Search` section.
This commit is contained in:
Linty
2024-02-02 11:50:56 +01:00
parent fe47d3e60a
commit 1629cd9386
3 changed files with 182 additions and 3 deletions

View File

@@ -368,13 +368,112 @@ function lineConstructor(line, id, imageDisplay) {
newLine.find(".type-id").hide();
break;
case "search":
// for debug
// console.log('search n° : ', line.SEARCH_ID, ' ', line.SEARCH_DETAILS);
const search_details = line.SEARCH_DETAILS;
const search_icons = {
'allwords': 'gallery-icon-search',
'tags': 'gallery-icon-tag',
'date_posted': 'gallery-icon-calendar-plus',
'cat': 'gallery-icon-album',
'author': 'gallery-icon-user-edit',
'added_by': 'gallery-icon-user',
'filetypes': 'gallery-icon-file-image',
}
newLine.find(".type-name").html(line.SECTION);
newLine.find(".type-id").html("#" + line.SEARCH_ID);
if (!line.SEARCH_ID)
{
newLine.find(".type-id").hide();
}
newLine.find(".detail-item-1").hide();
if (!search_details)
{
newLine.find(".detail-item-1").hide();
break;
}
let active_search_details = {};
Object.keys(search_details).forEach(key => {
if (search_details[key] !== null) {
active_search_details[key] = search_details[key];
}
});
let count_item = 1;
const active_items = Object.keys(active_search_details);
if (active_items.length > 0)
{
if (active_search_details.allwords)
{
newLine.find(".detail-item-" + count_item).html(active_search_details.allwords.join(' ')).addClass(search_icons.allwords + ' tiptip');
newLine.find(".detail-item-" + count_item).attr('title', '<b>' + str_search_details['allwords'] + ' :</b> ' + active_search_details.allwords.join(' '));
count_item++;
}
if (active_search_details.cat)
{
const array_cat = Object.values(active_search_details.cat);
newLine.find(".detail-item-" + count_item).html(array_cat.join(' + ')).addClass(search_icons.cat + ' tiptip');
newLine.find(".detail-item-"+ count_item).attr('title','<b>' + str_search_details['cat'] + ' :</b> ' + array_cat.join(' + ')).removeClass("hide");
count_item++;
}
if (count_item <= 2 && active_search_details.tags)
{
const array_tags = Object.values(active_search_details.tags);
newLine.find(".detail-item-" + count_item).html(array_tags.join(' + ')).addClass(search_icons.tags + ' tiptip');
newLine.find(".detail-item-"+ count_item).attr('title', '<b>' + str_search_details['tags'] + ' :</b> ' + array_tags.join(' + ')).removeClass("hide");
count_item++;
}
if (count_item <= 2)
{
let badge_to_add = active_items.length == 1 ? 1 : count_item == 1 ? 2 : 1;
let badge_added = 0;
active_items.some(key => {
if (key !== 'allwords' && key !== 'cat' && key !== 'tags') {
let array_key;
if (Array.isArray(active_search_details[key]))
{
array_key = active_search_details[key];
}
else if (typeof active_search_details[key] === 'object')
{
array_key = Object.values(active_search_details[key]);
}
else
{
array_key = [active_search_details[key]];
}
newLine.find(".detail-item-" + count_item).html(array_key.join(' + ')).addClass(search_icons[key] + ' tiptip');
newLine.find(".detail-item-" + count_item).attr('title', '<b>' + str_search_details[key] + ' :</b> ' + array_key.join(' + ')).removeClass("hide");
count_item++;
badge_added++;
if (badge_added === badge_to_add) {
return true;
}
}
return false;
});
}
}
else
{
newLine.find(".detail-item-1").hide();
}
if (active_items.length >= 3)
{
let search_details_str = Object.entries(active_search_details)
.map(([key, value]) => {
let value_str;
if(Array.isArray(value)) {
value_str = value.join(' + ');
} else if (typeof value === 'object') {
value_str = Object.entries(value).map(([k, v]) => v).join(' + ');
} else {
value_str = value;
}
return `<b>${str_search_details[key]}</b>: ${value_str}`;
}).join(' <br />');
newLine.find(".detail-item-3").html('See details').addClass('icon-info-circled-1 tiptip');
newLine.find(".detail-item-3").attr('title', search_details_str).removeClass('hide');
}
break;
case "favorites":
newLine.find(".type-name").html(str_favorites);

View File

@@ -50,6 +50,16 @@ const str_guest = '{'guest'|@translate}';
const str_contact_form = '{'Contact Form'|@translate}';
const str_edit_img = '{'Edit photo'|@translate}';
const str_search_details = {
"allwords": "{'Search for words'|@translate}",
"date_posted": "{'Post date'|@translate}",
"tags": str_tags,
"cat": "{'Album'|@translate}",
"author": "{'Author'|@translate}",
"added_by": "{'Added by'|@translate}",
"filetypes": "{'File type'|@translate}",
};
const guest_id = {$guest_id};
{/footer_script}
@@ -58,6 +68,7 @@ const guest_id = {$guest_id};
{combine_script id='jquery.confirm' load='footer' require='jquery' path='themes/default/js/plugins/jquery-confirm.min.js'}
{combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *}
{combine_css path="themes/default/vendor/fontello/css/gallery-icon.css" order=-10}
<form class="filter" method="post" name="filter" action="">
<fieldset class="history-filter">
@@ -470,7 +481,7 @@ jQuery(document).ready( function() {
.detail-title,
.detail-section {
max-width: 500px;
width: 500px;
text-align: left;
padding-left: 10px;
}
@@ -480,7 +491,7 @@ jQuery(document).ready( function() {
padding: 4px 8px;
border-radius: 5px;
max-width: 250px;
max-width: 130px;
height: 20px;
text-align: center;
@@ -718,4 +729,13 @@ jQuery(document).ready( function() {
.loading {
font-size: 25px;
}
@media (min-width: 1600px) {
.detail-title,
.detail-section {
max-width: 500px;
}
.detail-item {
max-width: 170px;
}
}
</style>

View File

@@ -798,6 +798,7 @@ SELECT rules
$category_ids = array();
$image_ids = array();
$has_tags = false;
$search_ids = array();
foreach ($data as $row)
{
@@ -818,10 +819,51 @@ SELECT rules
$has_tags = true;
}
if (isset($row['search_id']))
{
array_push($search_ids, $row['search_id']);
}
$history_lines[] = $row;
}
// prepare reference data (users, tags, categories...)
if (count($search_ids) > 0)
{
$query = '
SELECT
id,
rules
FROM '.SEARCH_TABLE.'
WHERE id IN ('.implode(',', $search_ids).')
;';
$search_details = query2array($query, 'id', 'rules');
foreach ($search_details as $id_search => $rules_search)
{
$rules_search = safe_unserialize($rules_search)['fields'];
if (!empty($rules_search['tags']['words']))
{
$has_tags = true;
}
if (!empty($rules_search['cat']['words']))
{
$category_ids = array_merge($category_ids, $rules_search['cat']['words']);
}
if(!empty($rules_search['added_by']))
{
foreach ($rules_search['added_by'] as $key)
{
$user_ids[$key] = 1;
}
}
$search_details[$id_search] = $rules_search;
}
}
if (count($user_ids) > 0)
{
$query = '
@@ -1011,6 +1053,23 @@ SELECT
.'" alt="'.$image_title.'" title="'.$image_title.'">';
}
if (isset($line['search_id']))
{
$search_detail = array(
'allwords' => !empty($search_details[$line['search_id']]['allwords']['words']) ? $search_details[$line['search_id']]['allwords']['words'] : null,
'tags' => !empty($search_details[$line['search_id']]['tags']['words']) ? array_intersect_key($name_of_tag, array_flip($search_details[$line['search_id']]['tags']['words'])) : null,
'date_posted' => !empty($search_details[$line['search_id']]['date_posted']) ? $search_details[$line['search_id']]['date_posted'] : null,
'cat' => !empty($search_details[$line['search_id']]['cat']['words']) ? array_intersect_key($name_of_category, array_flip($search_details[$line['search_id']]['cat']['words'])) : null,
'author' => !empty($search_details[$line['search_id']]['author']['words']) ? $search_details[$line['search_id']]['author']['words'] : null,
'added_by' => !empty($search_details[$line['search_id']]['added_by']) ? array_intersect_key($username_of, array_flip($search_details[$line['search_id']]['added_by'])) : null,
'filetypes' => !empty($search_details[$line['search_id']]['filetypes']) ? $search_details[$line['search_id']]['filetypes'] : null,
);
}
else
{
$search_detail = null;
}
@$sorted_members[$user_name] += 1;
array_push(
@@ -1033,6 +1092,7 @@ SELECT
'SEARCH_ID' => $line['search_id'] ?? null,
'TAGS' => explode(",",$tag_names),
'TAGIDS' => explode(",",$tag_ids),
'SEARCH_DETAILS' => $search_detail,
)
);
}