From 91bb79c893c139bc5adebf18ff3b29ce77f03af2 Mon Sep 17 00:00:00 2001 From: Linty Date: Mon, 23 Sep 2024 12:44:00 +0200 Subject: [PATCH] fixes #2226 implement album selector in batch manager filter and action --- admin/batch_manager_global.php | 9 +- admin/include/batch_manager_filters.inc.php | 262 +++++++++--------- admin/themes/clear/theme.css | 4 +- admin/themes/default/js/batchManagerFilter.js | 15 + admin/themes/default/js/batchManagerGlobal.js | 39 +++ .../default/template/batch_manager_global.tpl | 24 +- .../include/batch_manager_filter.inc.tpl | 14 +- admin/themes/default/theme.css | 54 +++- admin/themes/roma/theme.css | 20 +- 9 files changed, 289 insertions(+), 152 deletions(-) diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 7a8680244..d36d5c44e 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -33,7 +33,8 @@ if (!empty($_POST)) trigger_notify('loc_begin_element_set_global'); check_input_parameter('del_tags', $_POST, true, PATTERN_ID); -check_input_parameter('associate', $_POST, false, PATTERN_ID); +check_input_parameter('associate', $_POST, true, PATTERN_ID); +check_input_parameter('move', $_POST, false, PATTERN_ID); check_input_parameter('dissociate', $_POST, false, PATTERN_ID); // +-----------------------------------------------------------------------+ @@ -165,7 +166,7 @@ DELETE { associate_images_to_categories( $collection, - array($_POST['associate']) + $_POST['associate'] ); $_SESSION['page_infos'] = array( @@ -190,7 +191,7 @@ DELETE else if ('move' == $action) { - move_images_to_categories($collection, array($_POST['associate'])); + move_images_to_categories($collection, array($_POST['move'])); $_SESSION['page_infos'] = array( l10n('Information data registered in database') @@ -204,7 +205,7 @@ DELETE else if ('no_virtual_album' == $page['prefilter']) { - $category_info = get_cat_info($_POST['associate']); + $category_info = get_cat_info($_POST['move']); if (empty($category_info['dir'])) { $redirect = true; diff --git a/admin/include/batch_manager_filters.inc.php b/admin/include/batch_manager_filters.inc.php index f6980d003..7071aa902 100644 --- a/admin/include/batch_manager_filters.inc.php +++ b/admin/include/batch_manager_filters.inc.php @@ -1,142 +1,146 @@ 'caddie', 'NAME' => l10n('Caddie')), - array('ID' => 'favorites', 'NAME' => l10n('Your favorites')), - array('ID' => 'last_import', 'NAME' => l10n('Last import')), - array('ID' => 'no_album', 'NAME' => l10n('With no album').' ('.l10n('Orphans').')'), - array('ID' => 'no_tag', 'NAME' => l10n('With no tag')), - array('ID' => 'duplicates', 'NAME' => l10n('Duplicates')), - array('ID' => 'all_photos', 'NAME' => l10n('All')) - ); - - if ($conf['enable_synchronization']) - { - $prefilters[] = array('ID' => 'no_virtual_album', 'NAME' => l10n('With no virtual album')); - $prefilters[] = array('ID' => 'no_sync_md5sum', 'NAME' => l10n('With no checksum')); - } - - function UC_name_compare($a, $b) - { - return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); - } - - $prefilters = trigger_change('get_batch_manager_prefilters', $prefilters); - - // Sort prefilters by localized name. - usort($prefilters, function ($a, $b) { - return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); - }); - - $template->assign( - array( - 'conf_checksum_compute_blocksize' => $conf['checksum_compute_blocksize'], - 'prefilters' => $prefilters, - 'filter' => $_SESSION['bulk_manager_filter'], - 'selection' => $collection, - 'all_elements' => $page['cat_elements_id'], - 'START' => $page['start'], - 'PWG_TOKEN' => get_pwg_token(), - 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), - 'F_ACTION'=>$base_url.get_query_string_diff(array('cat','start','tag','filter')), - 'ADMIN_PAGE_TITLE' => l10n('Batch Manager'), - ) - ); - - if (isset($page['no_md5sum_number'])) - { - $template->assign( - array( - 'NB_NO_MD5SUM' => $page['no_md5sum_number'], - ) - ); - } else { - $template->assign('NB_NO_MD5SUM', ''); - } - - // privacy level - foreach ($conf['available_permission_levels'] as $level) - { - $level_options[$level] = l10n(sprintf('Level %d', $level)); - - if (0 == $level) - { - $level_options[$level] = l10n('Everybody'); - } - } - $template->assign( - array( - 'filter_level_options'=> $level_options, - 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) - ? $_SESSION['bulk_manager_filter']['level'] - : 0, - ) - ); - - // tags - $filter_tags = array(); - - if (!empty($_SESSION['bulk_manager_filter']['tags'])) - { - $query = ' - SELECT - id, - name - FROM '.TAGS_TABLE.' - WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).') - ;'; - - $filter_tags = get_taglist($query); - } - - $template->assign('filter_tags', $filter_tags); - - // in the filter box, which category to select by default - $selected_category = array(); - if (isset($_SESSION['bulk_manager_filter']['category'])) - { - $selected_category = array($_SESSION['bulk_manager_filter']['category']); - } - else - { - // we need to know the category in which the last photo was added - $query = ' - SELECT category_id - FROM '.IMAGE_CATEGORY_TABLE.' - ORDER BY image_id DESC - LIMIT 1 - ;'; - $result = pwg_query($query); - if (pwg_db_num_rows($result) > 0) - { - $row = pwg_db_fetch_assoc($result); - $selected_category[] = $row['category_id']; - } - } - - $template->assign('filter_category_selected', $selected_category); +// +-----------------------------------------------------------------------+ +// | This file is part of Piwigo. | +// | | +// | For copyright and license information, please view the COPYING.txt | +// | file that was distributed with this source code. | +// +-----------------------------------------------------------------------+ - // Dissociate from a category : categories listed for dissociation can only - // represent virtual links. We can't create orphans. Links to physical - // categories can't be broken. - $associated_categories = array(); +if (!defined('PHPWG_ROOT_PATH')) +{ + die ("Hacking attempt!"); +} - if (count($page['cat_elements_id']) > 0) - { +$prefilters = array( + array('ID' => 'caddie', 'NAME' => l10n('Caddie')), + array('ID' => 'favorites', 'NAME' => l10n('Your favorites')), + array('ID' => 'last_import', 'NAME' => l10n('Last import')), + array('ID' => 'no_album', 'NAME' => l10n('With no album') . ' (' . l10n('Orphans') . ')'), + array('ID' => 'no_tag', 'NAME' => l10n('With no tag')), + array('ID' => 'duplicates', 'NAME' => l10n('Duplicates')), + array('ID' => 'all_photos', 'NAME' => l10n('All')) +); + +if ($conf['enable_synchronization']) { + $prefilters[] = array('ID' => 'no_virtual_album', 'NAME' => l10n('With no virtual album')); + $prefilters[] = array('ID' => 'no_sync_md5sum', 'NAME' => l10n('With no checksum')); +} + +function UC_name_compare($a, $b) +{ + return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); +} + +$prefilters = trigger_change('get_batch_manager_prefilters', $prefilters); + +// Sort prefilters by localized name. +usort($prefilters, function ($a, $b) { + return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); +}); + +$template->assign( + array( + 'conf_checksum_compute_blocksize' => $conf['checksum_compute_blocksize'], + 'prefilters' => $prefilters, + 'filter' => $_SESSION['bulk_manager_filter'], + 'selection' => $collection, + 'all_elements' => $page['cat_elements_id'], + 'START' => $page['start'], + 'PWG_TOKEN' => get_pwg_token(), + 'U_DISPLAY' => $base_url . get_query_string_diff(array('display')), + 'F_ACTION' => $base_url . get_query_string_diff(array('cat', 'start', 'tag', 'filter')), + 'ADMIN_PAGE_TITLE' => l10n('Batch Manager'), + ) +); + +if (isset($page['no_md5sum_number'])) { + $template->assign( + array( + 'NB_NO_MD5SUM' => $page['no_md5sum_number'], + ) + ); +} else { + $template->assign('NB_NO_MD5SUM', ''); +} + +// privacy level +foreach ($conf['available_permission_levels'] as $level) { + $level_options[$level] = l10n(sprintf('Level %d', $level)); + + if (0 == $level) { + $level_options[$level] = l10n('Everybody'); + } +} +$template->assign( + array( + 'filter_level_options' => $level_options, + 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) + ? $_SESSION['bulk_manager_filter']['level'] + : 0, + ) +); + +// tags +$filter_tags = array(); + +if (!empty($_SESSION['bulk_manager_filter']['tags'])) { + $query = ' +SELECT + id, + name + FROM ' . TAGS_TABLE . ' + WHERE id IN (' . implode(',', $_SESSION['bulk_manager_filter']['tags']) . ') +;'; + + $filter_tags = get_taglist($query); +} + +$template->assign('filter_tags', $filter_tags); + +// in the filter box, which category to select by default +$selected_category = array(); +if (isset($_SESSION['bulk_manager_filter']['category'])) { + $selected_category = $_SESSION['bulk_manager_filter']['category']; +} else { + // we need to know the category in which the last photo was added + $query = ' +SELECT category_id + FROM ' . IMAGE_CATEGORY_TABLE . ' + ORDER BY image_id DESC + LIMIT 1 +;'; + $result = pwg_query($query); + if (pwg_db_num_rows($result) > 0) { + $row = pwg_db_fetch_assoc($result); + $selected_category = $row['category_id']; + } +} + +$selected_category_name = get_cat_display_name_from_id( + $selected_category, +); +$template->assign('filter_category_selected_name', strip_tags($selected_category_name)); +$template->assign('filter_category_selected', intval($selected_category)); + +// Dissociate from a category : categories listed for dissociation can only +// represent virtual links. We can't create orphans. Links to physical +// categories can't be broken. +$associated_categories = array(); + +if (count($page['cat_elements_id']) > 0) { $query = ' SELECT DISTINCT(category_id) AS id - FROM '.IMAGE_CATEGORY_TABLE.' AS ic - JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id - WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') + FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic + JOIN ' . IMAGES_TABLE . ' AS i ON i.id = ic.image_id + WHERE ic.image_id IN (' . implode(',', $page['cat_elements_id']) . ') AND ( ic.category_id != i.storage_category_id OR i.storage_category_id IS NULL ) ;'; - $associated_categories = query2array($query, 'id', 'id'); - } + $associated_categories = query2array($query, 'id', 'id'); +} - $template->assign('associated_categories', $associated_categories); -?> \ No newline at end of file +$template->assign('associated_categories', $associated_categories); diff --git a/admin/themes/clear/theme.css b/admin/themes/clear/theme.css index b20052039..46aa6ba55 100644 --- a/admin/themes/clear/theme.css +++ b/admin/themes/clear/theme.css @@ -688,13 +688,13 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; #checkActions a, .deleteDerivButtons a {background-color: #E8E8E8;} #filterList select, .pictureLevels select, #permitAction select, .sort-by select {background-color: #FFF; color: #4E4E4E; border: 2px solid #7070704f !important; outline: none !important;} #filter_category .selectize-input.items.full.has-options.has-items, #filter_tags .selectize-input.items.not-full.has-options, -#filter_tags .selectize-input.items.not-full, #filter_search input, #action_associate .selectize-input.items.full.has-options.has-items, +#filter_tags .selectize-input.items.not-full, #filter_search input, #action_move .selectize-input.items.full.has-options.has-items, #action_dissociate .selectize-input.items.full.has-options.has-items { border: 2px solid #7070704f !important; background: #FFF; color: #3C3C3CBD; } -#action_associate a:last-child {background: #FFF; border: 1px solid #787777a6; box-shadow: none;} +#action_move a:last-child {background: #FFF; border: 1px solid #787777a6; box-shadow: none;} #forbidAction, .selectionEmptyBlock, .noFilter {background-color: #f3f3f3;} #action_title .large, #action_author .large {background-color: #FFF; color: #4E4E4E;} #filter_dimension .slider-choice, #filter_filesize .slider-choice {background-color: #EEE; color: #777;} diff --git a/admin/themes/default/js/batchManagerFilter.js b/admin/themes/default/js/batchManagerFilter.js index 33c8e0587..7e3a95d6a 100644 --- a/admin/themes/default/js/batchManagerFilter.js +++ b/admin/themes/default/js/batchManagerFilter.js @@ -31,7 +31,22 @@ function filter_disable(filter) { } } +// Album Selector +function select_album_filter({ album, newSelectedAlbum, getSelectedAlbum }) { + $('#selectedAlbumNameFilter').html(album.full_name_with_admin_links); + newSelectedAlbum(); + $('#filterCategoryValue').val(+getSelectedAlbum()[0]); +} $(document).ready(function () { + const ab_filter = new AlbumSelector({ + selectedCategoriesIds: selected_filter_cat_ids, + selectAlbum: select_album_filter, + adminMode: true, + }); + + $('#selectedAlbumEditFilter').on('click', function() { + ab_filter.open(); + }); $(".removeFilter").addClass("icon-cancel-circled"); diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index eab1ded53..9413d65c8 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -42,8 +42,46 @@ jQuery(document).ready(function() { }); } $('ul.thumbnails').enableShiftClick(); + + const ab_action = new AlbumSelector({ + adminMode: true, + selectAlbum: select_album_action, + removeSelectedAlbum: remove_album_action, + }); + + $('#associate_as').on('click', function () { + ab_action.open(); + }); + + $('.selected-associate-action').on('click', (e) => { + if (e.target.classList.contains("remove-associate")) { + ab_action.remove_selected_album($(e.target).attr('id')); + } + }); + }); +/* ********** Album Selector */ +function select_album_action({ album, addSelectedAlbum, getSelectedAlbum }) { + $('#associate_as p').html(str_add_alb_associate); + $(".selected-associate-action").append( + `
+ ${album.name} + +
` + ); + addSelectedAlbum(); +} + +function remove_album_action({ id_album, getSelectedAlbum }) { + $('.selected-associate-item').find(`#${id_album}`).parent().remove(); + const selected = getSelectedAlbum(); + if (!selected.length) { + $('#associate_as p').html(str_select_alb_associate); + } +} + + jQuery("a.preview-box").colorbox( {photo: true} ); jQuery('.thumbnails img').tipTip({ @@ -472,3 +510,4 @@ function delete_orphans_block(blockSize) { } }); } + diff --git a/admin/themes/default/template/batch_manager_global.tpl b/admin/themes/default/template/batch_manager_global.tpl index fd8cef127..40d6a18bc 100644 --- a/admin/themes/default/template/batch_manager_global.tpl +++ b/admin/themes/default/template/batch_manager_global.tpl @@ -69,6 +69,8 @@ var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}] var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}"; var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}"; var selectedMessage_all = "{'All %d photos are selected'|@translate}"; +const str_add_alb_associate = "{"Add Album"|@translate}"; +const str_select_alb_associate = "{"Select an album"|@translate}"; $(document).ready(function() { jQuery('.help-popin-search').colorbox({ width:"600px" }); @@ -134,9 +136,9 @@ $(document).ready(function() { $("[id^=action_]").hide(); var action = $(this).prop("value"); - if (action == 'move') { + {* if (action == 'move') { action = 'associate'; - } + } *} $("#action_"+action).show(); @@ -447,10 +449,19 @@ UL.thumbnails SPAN.wrap2 {ldelim}
- {* also used for "move" action *} +
- - +
+

{"Select an album"|translate}

+
+
+
+
+ + +
+ +
@@ -566,9 +577,10 @@ UL.thumbnails SPAN.wrap2 {ldelim} +{include file='include/album_selector.inc.tpl'}