fix: use from/until input in UI filters

pull/8019/head
Luciano Righetti 2021-12-06 16:01:12 +01:00
parent ba37a8240b
commit 869ef3e874
3 changed files with 72 additions and 34 deletions

View File

@ -364,10 +364,21 @@ class EventsController extends AppController
if ($v == "") {
continue 2;
}
if (preg_match('/^[0-9]+[mhdw]$/i', $v)) {
$v = $this->Event->resolveTimeDelta($v);
if (is_array($v) && isset($v[0]) && isset($v[1])) {
if (!is_int($v)) {
$v[0] = $this->Event->resolveTimeDelta($v[0]);
}
if (!is_int($v)) {
$v[1] = $this->Event->resolveTimeDelta($v[1]);
}
$this->paginate['conditions']['AND'][] = array('Event.timestamp >=' => $v[0]);
$this->paginate['conditions']['AND'][] = array('Event.timestamp <=' => $v[1]);
} else {
if (!is_int($v)) {
$v = $this->Event->resolveTimeDelta($v);
}
$this->paginate['conditions']['AND'][] = array('Event.timestamp >=' => $v);
}
$this->paginate['conditions']['AND'][] = array('Event.timestamp >=' => $v);
break;
case 'publish_timestamp':
case 'publishtimestamp':
@ -375,16 +386,16 @@ class EventsController extends AppController
continue 2;
}
if (is_array($v) && isset($v[0]) && isset($v[1])) {
if (preg_match('/^[0-9]+[mhdw]$/i', $v[0])) {
if (!is_int($v)) {
$v[0] = $this->Event->resolveTimeDelta($v[0]);
}
if (preg_match('/^[0-9]+[mhdw]$/i', $v[1])) {
if (!is_int($v)) {
$v[1] = $this->Event->resolveTimeDelta($v[1]);
}
$this->paginate['conditions']['AND'][] = array('Event.publish_timestamp >=' => $v[0]);
$this->paginate['conditions']['AND'][] = array('Event.publish_timestamp <=' => $v[1]);
} else {
if (preg_match('/^[0-9]+[mhdw]$/i', $v)) {
if (!is_int($v)) {
$v = $this->Event->resolveTimeDelta($v);
}
$this->paginate['conditions']['AND'][] = array('Event.publish_timestamp >=' => $v);
@ -1052,8 +1063,8 @@ class EventsController extends AppController
'analysis' => array('OR' => array(), 'NOT' => array()),
'attribute' => array('OR' => array(), 'NOT' => array()),
'hasproposal' => 2,
'timestamp' => "",
'publishtimestamp' => ""
'timestamp' => array('from' => "", 'until' => ""),
'publishtimestamp' => array('from' => "", 'until' => ""),
);
if ($this->_isSiteAdmin()) {

View File

@ -10,7 +10,7 @@
'class' => 'input',
//'label' => 'Add Filtering Rule',
'onchange' => "indexRuleChange();",
'style' => 'margin-right:3px;width:120px;',
'style' => 'margin-right:3px;width:130px;',
'div' => false
));
echo $this->Form->input('searchbool', array(
@ -88,20 +88,36 @@
'div' => false
));
echo $this->Form->input('searchtimestamp', array(
echo $this->Form->input('searchtimestampfrom', array(
'class' => 'input',
'label' => false,
'style' => 'display:none;width:424px;',
'style' => 'display:none;width:236px;margin-right:3px;',
'div' => false,
'placeholder' => __("Time related filter: 7d, timestamps, [14d, 7d] for ranges")
'placeholder' => __("YYYY:MM:DD HH:MM:SS")
));
echo $this->Form->input('searchpublishtimestamp', array(
echo $this->Form->input('searchtimestampuntil', array(
'class' => 'input',
'label' => false,
'style' => 'display:none;width:424px;',
'style' => 'display:none;width:236px;margin-right:3px;',
'div' => false,
'placeholder' => __("Time related filter: 7d, timestamps, [14d, 7d] for ranges")
'placeholder' => __("YYYY:MM:DD HH:MM:SS")
));
echo $this->Form->input('searchpublishtimestampfrom', array(
'class' => 'input',
'label' => false,
'style' => 'display:none;width:236px;margin-right:3px;',
'div' => false,
'placeholder' => __("YYYY:MM:DD HH:MM:SS")
));
echo $this->Form->input('searchpublishtimestampuntil', array(
'class' => 'input',
'label' => false,
'style' => 'display:none;width:236px;margin-right:3px;',
'div' => false,
'placeholder' => __("YYYY:MM:DD HH:MM:SS")
));
echo $this->Form->input('searcheventinfo', array(

View File

@ -2095,15 +2095,23 @@ function indexEvaluateFiltering() {
}
$('#value_date').html(text);
if (filtering.timestamp != null) {
if (filtering.timestamp.from != null) {
var text = "";
if (filtering.timestamp != "") text = "Last change at: " + $('<span>').text(filtering.timestamp).html();
if (filtering.timestamp.from != "") text = "From: " + $('<span>').text(filtering.timestamp.from).html();
if (filtering.timestamp.until != "") {
if (text != "") text += " ";
text += "Until: " + $('<span>').text(filtering.timestamp.until).html();
}
}
$('#value_timestamp').html(text);
if (filtering.publishtimestamp != null) {
if (filtering.publishtimestamp.from != null) {
var text = "";
if (filtering.publishtimestamp != "") text = "Published at: " + $('<span>').text(filtering.publishtimestamp).html();
if (filtering.publishtimestamp.from != "") text = "From: " + $('<span>').text(filtering.publishtimestamp.from).html();
if (filtering.publishtimestamp.until != "") {
if (text != "") text += " ";
text += "Until: " + $('<span>').text(filtering.publishtimestamp.until).html();
}
}
$('#value_publishtimestamp').html(text);
@ -2331,13 +2339,21 @@ function indexCreateFilters() {
if (text != "") text += "/";
text += "searchDateuntil:" + filtering.date.until;
}
if (filtering.timestamp) {
if (filtering.timestamp.from) {
if (text != "") text += "/";
text += "searchTimestamp:" + filtering.timestamp;
text += "searchTimestamp:" + filtering.timestamp.from;
}
if (filtering.publishtimestamp) {
if (filtering.timestamp.until) {
if (text != "") text += "/";
text += "searchPublishTimestamp:" + filtering.publishtimestamp;
text += "searchTimestamp:" + filtering.timestamp.until;
}
if (filtering.publishtimestamp.from) {
if (text != "") text += "/";
text += "searchPublishTimestamp:" + filtering.publishtimestamp.from;
}
if (filtering.publishtimestamp.until) {
if (text != "") text += "/";
text += "searchPublishTimestamp:" + filtering.publishtimestamp.until;
}
return baseurl + '/events/index/' + text;
} else {
@ -2414,23 +2430,17 @@ function indexEvaluateSimpleFiltering(field) {
function indexAddRule(param) {
var found = false;
if (filterContext == 'event') {
if (param.data.param1 == "date") {
if (param.data.param1 == "date" || param.data.param1 == "timestamp" || param.data.param1 == "publishtimestamp") {
var val1 = encodeURIComponent($('#EventSearch' + param.data.param1 + 'from').val());
var val2 = encodeURIComponent($('#EventSearch' + param.data.param1 + 'until').val());
if (val1 != "") filtering.date.from = val1;
if (val2 != "") filtering.date.until = val2;
if (val1 != "") filtering[param.data.param1].from = val1;
if (val2 != "") filtering[param.data.param1].until = val2;
} else if (param.data.param1 == "published") {
var value = encodeURIComponent($('#EventSearchpublished').val());
if (value != "") filtering.published = value;
} else if (param.data.param1 == "hasproposal") {
var value = encodeURIComponent($('#EventSearchhasproposal').val());
if (value != "") filtering.hasproposal = value;
} else if (param.data.param1 == "timestamp") {
var value = encodeURIComponent($('#EventSearchtimestamp').val());
if (value != "") filtering.timestamp = value;
} else if (param.data.param1 == "publishtimestamp") {
var value = encodeURIComponent($('#EventSearchpublishtimestamp').val());
if (value != "") filtering.publishtimestamp = value;
} else {
var value = encodeURIComponent($('#EventSearch' + param.data.param1).val());
var operator = operators[encodeURIComponent($('#EventSearchbool').val())];
@ -2463,7 +2473,7 @@ function indexRuleChange() {
$('[id^=' + context + 'Search]').hide();
var rule = $('#' + context + 'Rule').val();
var fieldName = '#' + context + 'Search' + rule;
if (fieldName === '#' + context + 'Searchdate') {
if (fieldName === '#' + context + 'Searchdate' || fieldName === '#' + context + 'Searchtimestamp' || fieldName === '#' + context + 'Searchpublishtimestamp') {
$(fieldName + 'from').show();
$(fieldName + 'until').show();
} else {
@ -2487,7 +2497,8 @@ function indexFilterClearRow(field) {
filtering.date.from = "";
filtering.date.until = "";
} else if (field == "timestamp") {
filtering.timestamp = "";
filtering.timestamp.from = "";
filtering.timestamp.until = "";
} else if (field == "publishtimestamp") {
filtering.timestamp = "";
} else if (field == "published") {