Skip to content

Commit

Permalink
issue #2132 album selector hierarchy added to search page
Browse files Browse the repository at this point in the history
  • Loading branch information
LintyDev committed Mar 8, 2024
1 parent 5da20bf commit 4d26c62
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 18 deletions.
70 changes: 68 additions & 2 deletions admin/themes/default/js/album_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ function linked_albums_search(searchText) {
}
}

console.log('lalalal');
console.log(api_method);
// console.log(api_method);

$(".linkedAlbumPopInContainer .searching").show();
$.ajax({
Expand Down Expand Up @@ -66,3 +65,70 @@ function linked_albums_search(searchText) {
}
})
}

function prefill_search() {
$(".linkedAlbumPopInContainer .searching").show();
if (api_method == "pwg.categories.getList") {
api_params = {
cat_id: 0,
recursive: false,
fullname: true,
limit: limit_params,
};
} else {
api_params = {
additional_output: "full_name_with_admin_links",
};
}

$.ajax({
url: "ws.php?format=json&method=" + api_method,
type: "POST",
dataType: "json",
data: api_params,
success: function (data) {
// for debug
// console.log(data);
$(".linkedAlbumPopInContainer .searching").hide();
const cats = data.result.categories;
const limit = data.result.limit;
prefill_results("root", cats, limit);
},
error: function (e) {
$(".linkedAlbumPopInContainer .searching").hide();
console.log("error : ", e.message);
},
});
}

async function prefill_search_subcats(cat_id) {
let method = {};
if (api_method == "pwg.categories.getList") {
method = {
cat_id: cat_id,
recursive: false,
limit: limit_params,
};
} else {
method = {
additional_output: "full_name_with_admin_links",
};
}

try {
const data = await $.ajax({
url: "ws.php?format=json&method=" + api_method,
type: "POST",
dataType: "json",
data: method,
});

// for debug
// console.log(data);
const cats = data.result.categories.filter((c) => c.id !== +cat_id);
const limit = data.result.limit;
prefill_results(cat_id, cats, limit);
} catch (e) {
console.log("error", e.message);
}
}
6 changes: 5 additions & 1 deletion admin/themes/default/template/include/album_selector.inc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{if !isset($show_root_btn)}{$show_root_btn=false}{/if}

{include file='include/colorbox.inc.tpl' load_mode=$load_mode}
{combine_script id='albumSelector' load_mode=$load_mode path='admin/themes/default/js/album_selector.js'}
{combine_script id='albumSelector' load=$load_mode path='admin/themes/default/js/album_selector.js'}
{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'}
{footer_script}
str_no_search_in_progress = '{'No search in progress'|@translate|escape:javascript}';
str_albums_found = '{"<b>%d</b> albums found"|translate}';
Expand All @@ -14,6 +15,9 @@
api_method = 'pwg.categories.getAdminList';
{/if}

const limit_params = 50;
const str_plus_albums_found = "{'Only the first %d albums are displayed, out of %d.'|@translate|escape:javascript}"
const str_album_selected = "{'Album already selected'|@translate|escape:javascript}"
{/footer_script}

<div id="addLinkedAlbum" class="linkedAlbumPopIn">
Expand Down
52 changes: 41 additions & 11 deletions include/ws_functions/pwg.categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ function ws_categories_getList($params, &$service)
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid thumbnail_size");
}

if (!empty($params['limit']) and $params['recursive'])
{
return new PwgError(WS_ERR_INVALID_PARAM, 'Cannot use both recursive and limit parameters at the same time');
}

$output = [];
$where = array('1=1');
$join_type = 'INNER';
$join_user = $user['id'];
Expand Down Expand Up @@ -290,7 +296,7 @@ function ws_categories_getList($params, &$service)
}

$query = '
SELECT
SELECT SQL_CALC_FOUND_ROWS
id, name, comment, permalink, status,
uppercats, global_rank, id_uppercat,
nb_images, count_images AS total_nb_images,
Expand All @@ -302,17 +308,41 @@ function ws_categories_getList($params, &$service)
ON id=cat_id AND user_id='.$join_user.'
WHERE '. implode("\n AND ", $where);

if (isset($params["search"]) and $params['search'] != "")
if (isset($params['search']) and '' != $params['search'])
{
$query .= '
AND name LIKE \'%'.pwg_db_real_escape_string($params["search"]).'%\'
LIMIT '.$conf["linked_album_search_limit"];
AND name LIKE \'%'.pwg_db_real_escape_string($params['search']).'%\'';
if (!isset($params['limit']))
{
$query .= ' LIMIT '.$conf["linked_album_search_limit"];
}
}

if (isset($params['limit']))
{
$query .= '
ORDER BY rank ASC
LIMIT '.($params['limit'] + ($params['cat_id'] > 0 ? 1 : 0));
}

$query.= '
;';
$result = pwg_query($query);

if (isset($params['limit']))
{
list($result_count) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()'));
if ($params['cat_id'] > 0)
{
$result_count = $result_count - 1;
}
$output['limit'] = array(
'limited_to' => $params['limit'],
'total_cats' => intval($result_count),
'remaining_cats' => $result_count > $params['limit'] ? $result_count - $params['limit'] : 0,
);
}

// management of the album thumbnail -- starts here
$image_ids = array();
$categories = array();
Expand Down Expand Up @@ -542,13 +572,13 @@ function ws_categories_getList($params, &$service)
return categories_flatlist_to_tree($cats);
}

return array(
'categories' => new PwgNamedArray(
$cats,
'category',
ws_std_get_category_xml_attributes()
)
);
$output['categories'] = new PwgNamedArray(
$cats,
'category',
ws_std_get_category_xml_attributes()
);

return $output;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions language/en_UK/common.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,6 @@
$lang['year %d'] = 'year %d';
$lang['last 3 months'] = 'Last 3 months';
$lang['last 24 hours'] = 'last 24 hours';
$lang['Album already selected'] = 'Album already selected';
$lang['Only the first %d albums are displayed, out of %d.'] = 'Only the first %d albums are displayed, out of %d.';
?>
3 changes: 2 additions & 1 deletion language/fr_FR/common.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,5 @@
$lang['year %d'] = 'année %d';
$lang['last 3 months'] = '3 derniers mois';
$lang['last 24 hours'] = '24 dernières heures';

$lang['Only the first %d albums are displayed, out of %d.'] = 'Seuls les %d premiers sont affichés, sur %d.';
$lang['Album already selected'] = 'Album déjà sélectionné';
4 changes: 4 additions & 0 deletions themes/default/css/clear-search.css
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
color:#000;
}

.and-more{
color: #777
}

@media (max-width: 600px) {
.filter-form {
width: 101vw;
Expand Down
4 changes: 4 additions & 0 deletions themes/default/css/dark-search.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
color:black;
}

.and-more{
color: #777
}

@media (max-width: 600px) {
.filter-form {
width: 100vw;
Expand Down
34 changes: 34 additions & 0 deletions themes/default/css/search.css
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,40 @@
margin-bottom:10px;
}

.display-subcat {
margin-right: 2px;
}

.display-subcat:hover {
cursor: pointer;
}

.display-subcat::before {
transition: 0.5s;
transform: rotate(90deg);
}

.display-subcat.open::before {
transform: rotate(180deg);
}

.prefill-results-item {
width: 100%;
height: 100%;
display: flex;
align-items: center;
}

.search-result-subcat-item {
display: none;
}

.search-result-item.already-in {
cursor: default;
}
.and-more{
text-align: center;
}

@media (max-width: 600px) {
html, body {
Expand Down
Loading

0 comments on commit 4d26c62

Please sign in to comment.