fixes #2211 integrate new redesign for date posted filter

filter on date_posted custom values (specific years, months or days) along side last 7, 30 days, 3 and 6 months
following redesign by alice
This commit is contained in:
HWFord 2024-09-04 11:30:44 +02:00 committed by GitHub
parent b6789d4de9
commit b3151e0129
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 589 additions and 92 deletions

View file

@ -397,8 +397,9 @@ SELECT
// //
// date_posted // date_posted
// //
if (!empty($search['fields']['date_posted'])) if (!empty($search['fields']['date_posted']['preset']))
{ {
$has_filters_filled = true; $has_filters_filled = true;
$options = array( $options = array(
@ -407,17 +408,60 @@ SELECT
'30d' => '30 DAY', '30d' => '30 DAY',
'3m' => '3 MONTH', '3m' => '3 MONTH',
'6m' => '6 MONTH', '6m' => '6 MONTH',
'1y' => '1 YEAR',
); );
if (isset($options[ $search['fields']['date_posted'] ])) if (isset($options[ $search['fields']['date_posted']['preset'] ]) and 'custom' != $search['fields']['date_posted']['preset'])
{ {
$date_posted_clause = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted'] ].')'; $date_posted_clause = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted']['preset'] ].')';
} }
elseif (preg_match('/^y(\d+)$/', $search['fields']['date_posted'], $matches)) elseif ('custom' == $search['fields']['date_posted']['preset'] and isset($search['fields']['date_posted']['custom']))
{ {
// that is for y2023 = all photos posted in 2023 $date_posted_subclauses = array();
$date_posted_clause = 'YEAR(date_available) = '.$matches[1]; $custom_dates = array_flip($search['fields']['date_posted']['custom']);
foreach (array_keys($custom_dates) as $custom_date)
{
// in real-life tests, we have determined "where year(date_available) = 2024" was
// far less (4 times less) than "where date_available between '2024-01-01 00:00:00' and '2024-12-31 23:59:59'"
// so let's find the begin/end for each custom date
// ... and also, no need to search for images of 2023-10-16 if 2023-10 is already requested
$begin = $end = null;
$ymd = substr($custom_date, 0, 1);
if ('y' == $ymd)
{
$year = substr($custom_date, 1);
$begin = $year.'-01-01 00:00:00';
$end = $year.'-12-31 23:59:59';
}
elseif ('m' == $ymd)
{
list($year, $month) = explode('-', substr($custom_date, 1));
if (!isset($custom_dates['y'.$year]))
{
$begin = $year.'-'.$month.'-01 00:00:00';
$end = $year.'-'.$month.'-'.cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year).' 23:59:59';
}
}
elseif ('d' == $ymd)
{
list($year, $month, $day) = explode('-', substr($custom_date, 1));
if (!isset($custom_dates['y'.$year]) and !isset($custom_dates['m'.$year.'-'.$month]))
{
$begin = $year.'-'.$month.'-'.$day.' 00:00:00';
$end = $year.'-'.$month.'-'.$day.' 23:59:59';
}
}
if (!empty($begin))
{
$date_posted_subclauses[] = 'date_available BETWEEN "'.$begin.'" AND "'.$end.'"';
}
}
$date_posted_clause = '('.implode(' OR ', prepend_append_array_items($date_posted_subclauses, '(', ')')).')';
} }
$query = ' $query = '
@ -428,6 +472,7 @@ SELECT
WHERE '.$date_posted_clause.' WHERE '.$date_posted_clause.'
'.$forbidden.' '.$forbidden.'
;'; ;';
$image_ids_for_filter['date_posted'] = query2array($query, null, 'id'); $image_ids_for_filter['date_posted'] = query2array($query, null, 'id');
} }

View file

@ -859,14 +859,70 @@ function ws_images_filteredSearch_create($params, $service)
$search['fields']['added_by'] = $params['added_by']; $search['fields']['added_by'] = $params['added_by'];
} }
if (isset($params['date_posted'])) if (isset($params['date_posted_preset']))
{ {
if (!preg_match('/^(24h|7d|30d|3m|6m|y\d+|)$/', $params['date_posted'])) if (!preg_match('/^(24h|7d|30d|3m|6m|custom|)$/', $params['date_posted_preset']))
{ {
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted'); return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted_preset');
} }
$search['fields']['date_posted'] = $params['date_posted']; @$search['fields']['date_posted']['preset'] = $params['date_posted_preset'];
if ('custom' == $search['fields']['date_posted']['preset'] and empty($params['date_posted_custom']))
{
return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom is missing');
}
}
if (isset($params['date_posted_custom']))
{
if (!isset($search['fields']['date_posted']['preset']) or $search['fields']['date_posted']['preset'] != 'custom')
{
return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom provided date_posted_preset is not custom');
}
foreach ($params['date_posted_custom'] as $date)
{
$correct_format = false;
$ymd = substr($date, 0, 1);
if ('y' == $ymd)
{
if (preg_match('/^y(\d{4})$/', $date, $matches))
{
$correct_format = true;
}
}
elseif ('m' == $ymd)
{
if (preg_match('/^m(\d{4}-\d{2})$/', $date, $matches))
{
list($year, $month) = explode('-', $matches[1]);
if ($month >= 1 and $month <= 12)
{
$correct_format = true;
}
}
}
elseif ('d' == $ymd)
{
if (preg_match('/^d(\d{4}-\d{2}-\d{2})$/', $date, $matches))
{
list($year, $month, $day) = explode('-', $matches[1]);
if ($month >= 1 and $month <= 12 and $day >= 1 and $day <= cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year))
{
$correct_format = true;
}
}
}
if (!$correct_format)
{
return new PwgError(WS_ERR_INVALID_PARAM, 'date_posted_custom, invalid option '.$date);
}
@$search['fields']['date_posted']['custom'][] = $date;
}
} }
if (isset($params['ratios'])) if (isset($params['ratios']))

View file

@ -341,20 +341,6 @@ SELECT
); );
} }
$pre_counters_keys = array_keys($pre_counters);
rsort($pre_counters_keys); // we want y2023 to come before y2022 in the list
foreach ($pre_counters_keys as $key)
{
if (preg_match('/^y(\d+)$/', $key, $matches))
{
$counters[$key] = array(
'label' => l10n('year %d', $matches[1]),
'counter' => count(array_keys($pre_counters[$key]))
);
}
}
foreach ($counters as $key => $counter) foreach ($counters as $key => $counter)
{ {
if (0 == $counter['counter']) if (0 == $counter['counter'])
@ -364,6 +350,49 @@ SELECT
} }
$template->assign('DATE_POSTED', $counters); $template->assign('DATE_POSTED', $counters);
// Custom date
$query = '
SELECT
DISTINCT id,
date_available as date
FROM '.IMAGES_TABLE.' AS i
JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
WHERE '.$filter_clause.'
;';
$list_of_dates = array();
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
list($date_without_time) = explode(' ', $row['date']);
list($y, $m) = explode('-', $date_without_time);
@$list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['count']++;
@$list_of_dates[$y]['months'][$y.'-'.$m]['count']++;
@$list_of_dates[$y]['count']++;
// Benchmark if better to put the label in another array rather than keep in this array
if (!isset($list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['label']))
{
$list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['label'] = format_date($row['date']);
}
if (!isset($list_of_dates[$y]['months'][$m]['label']))
{
$list_of_dates[$y]['months'][$y.'-'.$m]['label'] = $lang['month'][(int)$m].' '.$y;
}
if (!isset($list_of_dates[$y]['label']))
{
$list_of_dates[$y]['label'] = l10n('year %d', $y);
}
}
$template->assign('LIST_DATE_POSTED', $list_of_dates);
} }
if (isset($my_search['fields']['added_by'])) if (isset($my_search['fields']['added_by']))

View file

@ -109,15 +109,34 @@
color: #444; color: #444;
} }
.date_posted-option label{
background-color:white;
border-bottom:1px solid #f3f3f3;
}
.date_posted-option i{
background-color:white;
}
.filetypes-option:nth-child(odd), .filetypes-option:nth-child(odd),
.added_by-option:nth-child(odd), .added_by-option:nth-child(odd),
.date_posted-option:nth-child(odd) label, .preset_posted_date .date_posted-option:nth-child(odd) label,
.preset_posted_date .date_posted-option:nth-child(odd) i,
.custom_posted_date .date_posted-option:nth-child(odd) .year_input label,
.custom_posted_date .date_posted-option:nth-child(odd) .year_input i,
.custom_posted_date .date_posted-option:nth-child(even) .month_input label,
.custom_posted_date .date_posted-option:nth-child(even) .month_input i,
.custom_posted_date .days_container .date_posted-option:nth-child(odd) label,
.custom_posted_date .days_container .date_posted-option:nth-child(odd) i,
.ratios-option:nth-child(odd), .ratios-option:nth-child(odd),
.ratings-option:nth-child(odd){ .ratings-option:nth-child(odd){
background: #f3f3f3; background: #f3f3f3;
} }
.date_posted-option label .checked-icon.grey-icon{
color:#777;
}
.filetypes-option label .checked-icon, .filetypes-option label .checked-icon,
.added_by-option label .checked-icon, .added_by-option label .checked-icon,
.date_posted-option label .checked-icon, .date_posted-option label .checked-icon,
@ -128,7 +147,7 @@
.filetypes-option label .ext-badge, .filetypes-option label .ext-badge,
.added_by-option label .added_by-badge, .added_by-option label .added_by-badge,
.date_posted-option label .date_posted-badge, .date_posted-badge,
.ratios-option label .ratio-badge, .ratios-option label .ratio-badge,
.ratings-option label .ratings-badge { .ratings-option label .ratings-badge {
background: #ff7700; background: #ff7700;
@ -149,14 +168,12 @@
.filetypes-option input:checked + label, .filetypes-option input:checked + label,
.ratios-option input:checked + label, .ratios-option input:checked + label,
.ratings-option input:checked + label { .ratings-option input:checked + label,
.preset_posted_date .date_posted-option input:checked + label,
.custom_posted_date .selected input:checked {
background: #fff5e8; background: #fff5e8;
} }
.date_posted-option input:checked + label {
background: rgba(244, 171, 79, 0.17);
}
.head-button-2 { .head-button-2 {
color: #777; color: #777;
} }

View file

@ -128,7 +128,7 @@
.filetypes-option label .ext-badge, .filetypes-option label .ext-badge,
.added_by-option label .added_by-badge, .added_by-option label .added_by-badge,
.date_posted-option label .date_posted-badge, .date_posted-badge,
.ratios-option label .ratio-badge, .ratios-option label .ratio-badge,
.ratings-option label .ratings-badge { .ratings-option label .ratings-badge {
background: #ff7700bb; background: #ff7700bb;
@ -149,7 +149,8 @@
.added_by-option input:checked + label, .added_by-option input:checked + label,
.filetypes-option input:checked + label, .filetypes-option input:checked + label,
.date_posted-option input:checked + label, .date_posted-option .selected label,
.date_posted-option .selected .accordion-toggle,
.ratios-option input:checked + label, .ratios-option input:checked + label,
.ratings-option input:checked + label{ .ratings-option input:checked + label{
background: rgba(244, 171, 79, 0.17); background: rgba(244, 171, 79, 0.17);

View file

@ -302,7 +302,6 @@
width: 200px; width: 200px;
} }
.filter-date_posted-form,
.filter-ratings-form{ .filter-ratings-form{
width: 250px; width: 250px;
} }
@ -339,7 +338,7 @@
.filetypes-option label, .filetypes-option label,
.added_by-option label, .added_by-option label,
.date_posted-option label, .preset_posted_date .date_posted-option label,
.ratios-option label, .ratios-option label,
.ratings-option label{ .ratings-option label{
display: flex; display: flex;
@ -351,14 +350,20 @@
.filetypes-option label .checked-icon, .filetypes-option label .checked-icon,
.added_by-option label .checked-icon, .added_by-option label .checked-icon,
.date_posted-option label .checked-icon,
.ratios-option label .checked-icon, .ratios-option label .checked-icon,
.ratings-option label .checked-icon{ .ratings-option label .checked-icon,
.preset_posted_date .date_posted-option label .checked-icon{
display: none; display: none;
position: absolute; position: absolute;
left: 0; left: 3px;
top: 4px;
}
.custom_posted_date .date_posted-option label .checked-icon{
display: none;
position: absolute;
right: 3px;
top: 4px; top: 4px;
margin: 5px;
} }
.filetypes-option label .ext-name { .filetypes-option label .ext-name {
@ -367,8 +372,8 @@
.filetypes-option label .ext-name, .filetypes-option label .ext-name,
.added_by-option label .added_by-name, .added_by-option label .added_by-name,
.date_posted-option label .date-period,
.ratios-option label .ratio-name, .ratios-option label .ratio-name,
.preset_posted_date .date_posted-option .date-period,
.ratings-option label .ratings-name { .ratings-option label .ratings-name {
margin-left: 30px; margin-left: 30px;
} }
@ -378,29 +383,36 @@
margin-right: 10px; margin-right: 10px;
} }
.date_posted-option label .date-period{ .custom_posted_date .date_posted-option label .date-period{
margin-left: 30px; margin-right: 30px;
} }
.filetypes-option label .ext-badge, .filetypes-option label .ext-badge,
.added_by-option label .added_by-badge, .added_by-option label .added_by-badge,
.date_posted-option label .date_posted-badge,
.ratios-option label .ratio-badge, .ratios-option label .ratio-badge,
.ratings-option label .ratings-badge { .ratings-option label .ratings-badge,
.preset_posted_date .date_posted-option label .date_posted-badge {
margin-left: auto; margin-left: auto;
border-radius: 10px; border-radius: 10px;
padding: 0 5px; padding: 0 5px;
font-weight: 600; font-weight: 600;
} }
.custom_posted_date .date_posted-option label .date_posted-badge{
border-radius: 10px;
padding: 0 5px;
font-weight: 600;
}
.filetypes-option input:checked + label .checked-icon, .filetypes-option input:checked + label .checked-icon,
.added_by-option input:checked + label .checked-icon, .added_by-option input:checked + label .checked-icon,
.date_posted-option input:checked + label .checked-icon,
.ratios-option input:checked + label .checked-icon, .ratios-option input:checked + label .checked-icon,
.ratings-option input:checked + label .checked-icon{ .ratings-option input:checked + label .checked-icon,
display: flex; .preset_posted_date .date_posted-option input:checked + label .checked-icon{
display: block;
} }
.filter-date_posted-form,
.filter-album-form { .filter-album-form {
width: 400px; width: 400px;
} }
@ -422,6 +434,75 @@
.width-option-container{ .width-option-container{
margin-bottom:25px; margin-bottom:25px;
} }
.year_input,
.month_input{
display:flex
}
.date_posted-option label{
display: flex;
flex-direction: row;
align-items: baseline;
position: relative;
padding: 5px;
margin-left:-1px;
}
.custom_posted_date .date_posted-option label{
width:100%;
}
.date_posted-option .accordion-toggle{
padding:5px;
rotate:90deg;
}
.date_posted-option .accordion-toggle:hover{
color:#ff7700;
cursor:pointer;
}
.date_posted-option.month{
margin-left:15px;
display:none;
}
.date_posted-option.day{
margin-left:30px;
margin-right:10px;
display:none;
}
.date_posted-option .show-child .accordion-toggle::before {
transform: rotate(90deg);
}
.custom_posted_date{
display:none;
}
.grey-icon{
display:block!important;
}
.custom_posted_date_toggle{
cursor:pointer;
}
.date_posted-option .custom_posted_date_toggle{
padding: 5px 0;
border-top: .3px solid #aaa;
border-bottom: .3px solid #aaa;
}
.custom_posted_date_toggle .gallery-icon-up-open:before{
rotate: -90deg;
}
.custom_posted_date.custom_posted_date_toggle{
position:absolute;
}
/*_____________________________*/ /*_____________________________*/
.head-button-2 { .head-button-2 {
@ -778,8 +859,7 @@
.ui-slider-horizontal .ui-slider-horizontal
{ {
width: 280px; margin: 10px;
margin: 10px 0 10px 9px;
height: 2px; height: 2px;
} }
@ -846,4 +926,28 @@
.ui-slider-horizontal .ui-slider-handle:hover{ .ui-slider-horizontal .ui-slider-handle:hover{
cursor:pointer; cursor:pointer;
}
.mcs-container div .slider_input{
display:flex;
justify-content: space-between;
margin-bottom:15px;
}
.mcs-container div .slider_input .max_input{
text-align:right;
}
.mcs-container input[type="number"],
.mcs-container input[type="number"]:focus{
border: none;
background: #eee;
color: #444;
border-radius:6px;
}
.mcs-container div .slider_input p{
margin:0;
color:#656565;
font-size:12px;
} }

View file

@ -86,6 +86,7 @@ $(document).ready(function () {
items: global_params.fields.tags ? global_params.fields.tags.words : null, items: global_params.fields.tags ? global_params.fields.tags.words : null,
}); });
}); });
if (global_params.fields.tags) { if (global_params.fields.tags) {
$(".filter-tag").css("display", "flex"); $(".filter-tag").css("display", "flex");
$(".filter-manager-controller.tags").prop("checked", true); $(".filter-manager-controller.tags").prop("checked", true);
@ -114,25 +115,165 @@ $(document).ready(function () {
} }
// Setup Date post filter // Setup Date post filter
if (global_params.fields.hasOwnProperty('date_posted')) { if (global_params.fields.date_posted) {
$(".filter-date_posted").css("display", "flex"); $(".filter-date_posted").css("display", "flex");
$(".filter-manager-controller.date_posted").prop("checked", true); $(".filter-manager-controller.date_posted").prop("checked", true);
if (global_params.fields.date_posted != null && global_params.fields.date_posted != "") { if (global_params.fields.date_posted.preset != null && global_params.fields.date_posted.preset != "") {
$("#date_posted-" + global_params.fields.date_posted).prop("checked", true); // If filter is used and not empty check preset date option
$("#date_posted-" + global_params.fields.date_posted.preset).prop("checked", true);
date_posted_str = $('.date_posted-option label#'+ global_params.fields.date_posted.preset +' .date-period').text();
date_posted_str = $('.date_posted-option label#'+global_params.fields.date_posted+' .date-period').text(); // if option is custom check custom dates
if ('custom' == global_params.fields.date_posted.preset && global_params.fields.date_posted.custom != null)
{
date_posted_str = '';
var customArray = global_params.fields.date_posted.custom
$(customArray).each(function( index ) {
var customValue = this.substring(1, $(this).length);
$("#date_posted_"+customValue).prop("checked", true).addClass('selected');
$("#date_posted_"+customValue).siblings('label').find('.checked-icon').show();
date_posted_str += $('.date_posted-option label#'+ customValue +' .date-period').text()
if($(global_params.fields.date_posted.custom).length > 1 && index != $(customArray).length-1)
{
date_posted_str += ', ';
}
});
}
// change badge label if filter not empty
$(".filter-date_posted").addClass("filter-filled"); $(".filter-date_posted").addClass("filter-filled");
$(".filter.filter-date_posted .search-words").text(date_posted_str); $(".filter.filter-date_posted .search-words").text(date_posted_str);
} }
$(".filter-date_posted .filter-actions .clear").on('click', function () { $(".filter-date_posted .filter-actions .clear").on('click', function () {
updateFilters('date_posted', 'add');
$(".date_posted-option input").prop('checked', false); $(".date_posted-option input").prop('checked', false);
$(".date_posted-option input").trigger('change');
// $('.date_posted-option input').removeAttr('disabled');
// $('.date_posted-option input').removeClass('grey-icon');
}); });
PS_params.date_posted = global_params.fields.date_posted.length > 0 ? global_params.fields.date_posted : ''; // Disable possiblity for user to select custom option, its gets selected programtically later on
$("#date_posted_custom").attr('disabled', 'disabled');
empty_filters_list.push(PS_params.date_posted); // Handle toggle between preset and custom options
$(".custom_posted_date_toggle").on("click", function (e) {
$('.custom_posted_date').toggle()
$('.preset_posted_date').toggle()
});
// Handle accoridan features in custom options
$(".custom_posted_date .accordion-toggle").on("click", function (e) {
var clickedOption = $(this).parent();
$(clickedOption).toggleClass('show-child');
if('year' == $(this).data('type'))
{
$(clickedOption).parent().find('.date_posted-option.month').toggle();
}
else if('month' == $(this).data('type'))
{
$(clickedOption).parent().find('.date_posted-option.day').toggle();
}
});
// On custom date input select
$(".custom_posted_date .date_posted-option input").change(function() {
var parentOption = $(this).parent()
if(true == $(this).prop("checked")){
// Toggle tick icon on selected date in custom list
$(this).siblings('label').find('.checked-icon').show();
// Add class selected to selected option,
// We want to find which are selected to handle the others
$(this).addClass('selected')
$(parentOption).addClass('selected')
$(parentOption).find('.mcs-icon').addClass('selected')
}
else
{
// Toggle tick icon on selected date in custom list
$(this).siblings('label').find('.checked-icon').hide();
// Add class selected to selected option,
// We want to find which are selected to handle the others
$(this).removeClass('selected')
$(parentOption).removeClass('selected')
$(parentOption).find('.mcs-icon').removeClass('selected')
}
// TODO finish handling grey tick on child options, and having specifi icon to show children are selected
// if this is selected then disable selecting children, and display grey tick
// var selectedContainerID = $(this).parent().parent().attr('id');
// if ($(this).is(":checked"))
// {
// $('#'+selectedContainerID+' .date_posted-option input').not('.selected').attr('disabled', 'disabled');
// $('#'+selectedContainerID+' .date_posted-option .mcs-icon').not('.selected').addClass('grey-icon');
// if($(parentOption).hasClass('year'))
// {
// if($(parentOption).find('label .mcs-icon').hasClass('gallery-icon-menu'))
// {
// $(parentOption).find('label .mcs-icon').toggleClass('gallery-icon-menu gallery-icon-checkmark').show();
// }
// }
// else if($(parentOption).hasClass('month'))
// {
// $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon');
// }
// else if ($(parentOption).hasClass('day'))
// {
// $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark').show();
// $(this).parents('.month').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark').show();
// }
// }
// else
// {
// $('#'+selectedContainerID+' .date_posted-option input').not('.selected').removeAttr('disabled');
// $('#'+selectedContainerID+' .date_posted-option .mcs-icon').not('.selected').removeClass('grey-icon');
// $(this).parents('.year').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon');
// $(this).parents('.month').find('label .mcs-icon').first().toggleClass('gallery-icon-menu gallery-icon-checkmark grey-icon');
// }
// Used to select custom in preset list if dates are selected
if($('.custom_posted_date input:checked').length > 0)
{
$("#date_posted-custom").prop('checked', true);
$('.preset_posted_date input').attr('disabled', 'disabled');
}
else{
$("#date_posted-custom").prop('checked', false);
$('.preset_posted_date input').removeAttr('disabled');
}
});
// Used to select custom in preset list if dates are selected
if($('.custom_posted_date input:checked').length > 0)
{
$("#date_posted-custom").prop('checked', true);
$('.preset_posted_date input').attr('disabled', 'disabled');
}
else{
$("#date_posted-custom").prop('checked', false);
$('.preset_posted_date input').removeAttr('disabled');
}
PS_params.date_posted_preset = global_params.fields.date_posted.preset != '' ? global_params.fields.date_posted.preset : '';
PS_params.date_posted_custom = global_params.fields.date_posted.custom != '' ? global_params.fields.date_posted.custom : '';
empty_filters_list.push(PS_params.date_posted_preset);
empty_filters_list.push(PS_params.date_posted_custom);
} }
// Setup album filter // Setup album filter
@ -351,6 +492,15 @@ $(document).ready(function () {
$('[data-slider=filesizes]').pwgDoubleSlider(sliders.filesizes); $('[data-slider=filesizes]').pwgDoubleSlider(sliders.filesizes);
$('[data-slider=filesizes]').on("slidestop", function(event, ui) {
var min = $('[data-slider=filesizes]').find('[data-input=min]').val();
var max = $('[data-slider=filesizes]').find('[data-input=max]').val();
$('input[name=filter_filesize_min_text]').val(min).trigger('change');
$('input[name=filter_filesize_max_text]').val(max).trigger('change');
});
if( global_params.fields.filesize_min != null && global_params.fields.filesize_max > 0) { if( global_params.fields.filesize_min != null && global_params.fields.filesize_max > 0) {
$(".filter-filesize").addClass("filter-filled"); $(".filter-filesize").addClass("filter-filled");
$(".filter.filter-filesize .search-words").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max,)); $(".filter.filter-filesize .search-words").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max,));
@ -516,7 +666,6 @@ $(document).ready(function () {
} }
} else { } else {
if ($(".filter.filter-" + $(this).data("wid")).is(':visible')) { if ($(".filter.filter-" + $(this).data("wid")).is(':visible')) {
console.log($(this).data("wid"));
updateFilters($(this).data("wid"), 'del'); updateFilters($(this).data("wid"), 'del');
} }
} }
@ -658,14 +807,31 @@ $(document).ready(function () {
return; return;
} }
$(".filter-date_posted-form").toggle(0, function () { $(".filter-date_posted-form").toggle(0, function () {
if ($(this).is(':visible')) { if ($(this).is(':visible'))
{
$(".filter-date_posted").addClass("show-filter-dropdown"); $(".filter-date_posted").addClass("show-filter-dropdown");
} else { }
else
{
$(".filter-date_posted").removeClass("show-filter-dropdown"); $(".filter-date_posted").removeClass("show-filter-dropdown");
global_params.fields.date_posted = $(".date_posted-option input:checked").val(); var presetValue = $(".preset_posted_date .date_posted-option input:checked").val();
PS_params.date_posted = $(".date_posted-option input:checked").length > 0 ? $(".date_posted-option input:checked").val() : ""; global_params.fields.date_posted.preset = presetValue;
PS_params.date_posted_preset = presetValue != null ? presetValue : "";
if ('custom' == presetValue)
{
var customDates = [];
$(".custom_posted_date .date_posted-option input:checked").each(function(){
customDates.push($(this).val());
});
global_params.fields.date_posted.custom = customDates;
PS_params.date_posted_custom = customDates.length > 0 ? customDates : "";
}
} }
}); });
}); });
@ -674,6 +840,7 @@ $(document).ready(function () {
$(".filter-date_posted").trigger("click"); $(".filter-date_posted").trigger("click");
performSearch(PS_params, true); performSearch(PS_params, true);
}); });
$(".filter-date_posted .filter-actions .delete").on("click", function () { $(".filter-date_posted .filter-actions .delete").on("click", function () {
updateFilters('date_posted', 'del'); updateFilters('date_posted', 'del');
performSearch(PS_params, true); performSearch(PS_params, true);
@ -826,6 +993,7 @@ $(document).ready(function () {
} }
}); });
}); });
$(".filter-filetypes .filter-validate").on("click", function () { $(".filter-filetypes .filter-validate").on("click", function () {
$(".filter-filetypes").trigger("click"); $(".filter-filetypes").trigger("click");
performSearch(PS_params, true); performSearch(PS_params, true);
@ -1041,26 +1209,6 @@ $(document).ready(function () {
$(".filter-manager-controller.width").prop("checked", false); $(".filter-manager-controller.width").prop("checked", false);
} }
}); });
/* Close dropdowns if you click on the screen */
// $(document).mouseup(function (e) {
// e.stopPropagation();
// let option_is_clicked = false
// $(".mcs-container .filter").each(function () {
// console.log(($(this).hasClass("show-filter-dropdown")));
// if (!($(this).has(e.target).length === 0)) {
// option_is_clicked = true;
// }
// })
// if (!option_is_clicked) {
// $(".filter-form").hide();
// if ($(".show-filter-dropdown").length != 0) {
// $(".show-filter-dropdown").removeClass("show-filter-dropdown");
// performSearch();
// }
// }
// });
}) })
function performSearch(params, reload = false) { function performSearch(params, reload = false) {
@ -1076,11 +1224,11 @@ function performSearch(params, reload = false) {
}, },
error:function(e) { error:function(e) {
console.log(e); console.log(e);
$(".filter-form ").append('<p class="error">Error</p>')
$(".filter-validate").find(".validate-text").css("display", "block");
$(".filter-validate").find(".loading").hide();
$(".remove-filter").removeClass(prefix_icon + 'spin6 animate-spin').addClass(prefix_icon + 'cancel');
}, },
}).done(function () {
$(".filter-validate").find(".validate-text").css("display", "block");
$(".filter-validate").find(".loading").hide();
$(".remove-filter").removeClass(prefix_icon + 'spin6 animate-spin').addClass(prefix_icon + 'cancel');
}); });
} }
@ -1159,6 +1307,24 @@ function updateFilters(filterName, mode) {
} }
break; break;
case 'date_posted':
if (mode == 'add') {
global_params.fields['date_posted'] = {};
global_params.fields.date_posted.preset = '';
global_params.fields.date_posted.custom = [];
PS_params.date_posted_preset = '';
PS_params.date_posted_custom = [];
} else if (mode == 'del') {
delete global_params.fields.date_posted.preset;
delete global_params.fields.date_posted.custom;
delete PS_params.date_posted_preset;
delete PS_params.date_posted_custom;
}
break;
case 'filesize': case 'filesize':
if (mode == 'add') { if (mode == 'add') {
global_params.fields.filesize_min = ''; global_params.fields.filesize_min = '';

View file

@ -255,6 +255,7 @@ const prefix_icon = 'gallery-icon-';
</div> </div>
{/if} {/if}
{* For pst date *}
{if isset($DATE_POSTED)} {if isset($DATE_POSTED)}
<div class="filter filter-date_posted"> <div class="filter filter-date_posted">
<span class="mcs-icon gallery-icon-calendar-plus filter-icon"></span> <span class="mcs-icon gallery-icon-calendar-plus filter-icon"></span>
@ -269,7 +270,8 @@ const prefix_icon = 'gallery-icon-';
</div> </div>
<div class="date_posted-option-container"> <div class="date_posted-option-container">
{foreach from=$DATE_POSTED item=date_posted key=k} <div class="preset_posted_date">
{foreach from=$DATE_POSTED item=date_posted key=k}
<div class="date_posted-option"> <div class="date_posted-option">
<input type="radio" id="date_posted-{$k}" value={$k} name="date_posted-period"> <input type="radio" id="date_posted-{$k}" value={$k} name="date_posted-period">
<label for="date_posted-{$k}" id="{$k}"> <label for="date_posted-{$k}" id="{$k}">
@ -278,11 +280,73 @@ const prefix_icon = 'gallery-icon-';
<span class="date_posted-badge">{$date_posted.counter}</span> <span class="date_posted-badge">{$date_posted.counter}</span>
</label> </label>
</div> </div>
{/foreach} {/foreach}
<div class="date_posted-option">
<input type="radio" id="date_posted-custom" value="custom" name="date_posted-period">
<label for="date_posted_custom" class="custom_posted_date_toggle">
<span class="mcs-icon gallery-icon-checkmark checked-icon"></span>
<span class="date-period">{'Custom'|translate}</span>
</label>
</div>
</div>
<div class="custom_posted_date">
{foreach from=$LIST_DATE_POSTED key=y item=year}
<div class="date_posted-option year" id="container_{$y}">
<div class="year_input">
<input type="checkbox" id="date_posted_{$y}" value='y{$y}'>
<i class="gallery-icon-up-open accordion-toggle" data-type='year'></i>
<label for="date_posted_{$y}" id="{$y}">
<span class="date-period">{$year.label}</span>
<span class="date_posted-badge">{$year.count}</span>
<span class="mcs-icon gallery-icon-checkmark checked-icon"></span>
</label>
</div>
<div class="months_container">
{foreach from=$year.months key=m item=month}
<div class="date_posted-option month" id="container_{$m}">
<div class="month_input">
<input type="checkbox" id="date_posted_{$m}" value='m{$m}'>
<i class="gallery-icon-up-open accordion-toggle" data-type='month'></i>
<label for="date_posted_{$m}" id="{$m}">
<span class="date-period">{$month.label}</span>
<span class="date_posted-badge">{$month.count}</span>
<span class="mcs-icon gallery-icon-checkmark checked-icon"></span>
</label>
</div>
<div class="days_container">
{foreach from=$month.days key=d item=day}
<div class="date_posted-option day" id="container_{$d}">
<input type="checkbox" id="date_posted_{$d}" value='d{$d}'>
<label for="date_posted_{$d}" id="{$d}">
<span class="date-period">{$day.label}</span>
<span class="date_posted-badge">{$day.count}</span>
<span class="mcs-icon gallery-icon-checkmark checked-icon"></span>
</label>
</div>
{/foreach}
</div>
</div>
{/foreach}
</div>
</div>
{/foreach}
</div>
</div> </div>
<div class="filter-validate"> <div>
<i class="loading gallery-icon-spin6 animate-spin"></i> <div class="custom_posted_date custom_posted_date_toggle">
<span class="validate-text">{'Validate'|@translate}</span> <i class="gallery-icon-up-open"></i>
<span>{'Previous'|translate}</span>
</div>
<div class="filter-validate">
<i class="loading gallery-icon-spin6 animate-spin"></i>
<span class="validate-text">{'Validate'|@translate}</span>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -516,6 +580,17 @@ const prefix_icon = 'gallery-icon-';
<div class="form-container"> <div class="form-container">
<div class="filesize-option-container"> <div class="filesize-option-container">
<div class="slider_input">
<div class="min_input">
<p>Min</p>
<input type="number" step=".1" min="0" name="filter_filesize_min_text" value="{$FILESIZE.selected.min}">
</div>
<div class="max_input">
<p>Max</p>
<input type="number" step=".1" min="0" name="filter_filesize_max_text" value="{$FILESIZE.selected.max}">
</div>
</div>
<div data-slider="filesizes"> <div data-slider="filesizes">
<span class="slider-info"></span> <span class="slider-info"></span>
<div class="slider-slider"></div> <div class="slider-slider"></div>

8
ws.php
View file

@ -1454,9 +1454,13 @@ enabled_high, registration_date, registration_date_string, registration_date_sin
'filetypes' => array( 'filetypes' => array(
'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
), ),
'date_posted' => array( 'date_posted_preset' => array(
'flags' => WS_PARAM_OPTIONAL, 'flags' => WS_PARAM_OPTIONAL,
'info' => 'files posted within 24 hours, 7 days or 30 days or 3 months or 6 months or year NNNN. Value among 24h|7d|30d|3m|6m|yNNNN', 'info' => 'files posted within 24 hours, 7 days, 30 days, 3 months, 6 months or custom. Value among 24h|7d|30d|3m|6m|custom.',
),
'date_posted_custom' => array(
'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,
'info' => 'Must be provided if date_posted_preset is custom. List of yYYYY or mYYYY-MM or dYYYY-MM-DD.',
), ),
'ratios' => array( 'ratios' => array(
'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY,