Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(ui): pagination feedbacks from validation process
Browse files Browse the repository at this point in the history
  • Loading branch information
sc979 committed Apr 3, 2019
1 parent 0cf1b0b commit 8788f72
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 161 deletions.
24 changes: 15 additions & 9 deletions www/include/common/autoNumLimit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
Expand Down Expand Up @@ -41,6 +41,7 @@
$historyLimitNotDefault = isset($centreon->historyLimit[$url]) && $centreon->historyLimit[$url] !== 30;
$sessionLimitKey = "results_limit_{$url}";

// Setting the limit filter
if (isset($_POST['limit']) && $_POST['limit']) {
$limit = $_POST['limit'];
} elseif (isset($_GET['limit'])) {
Expand All @@ -63,17 +64,22 @@

$_SESSION[$sessionLimitKey] = $limit;

if (isset($_POST['num']) && $_POST['num']) {
$num = $_POST['num'];
} elseif (isset($_GET['num']) && $_GET['num']) {
$num = $_GET['num'];
} elseif (!isset($_POST['num']) && !isset($_GET['num']) && isset($centreon->historyPage[$url])) {
$num = $centreon->historyPage[$url];
} else {
// Setting the pagination filter
if (isset($centreon->historyLastPage) && $centreon->historyLastPage !== $url) {
// Checking if the current page and the last displayed page are the same
$num = 0;
} elseif (isset($_REQUEST['num'])) {
// Checking if a pagination filter has been sent in the http request
$num = filter_var(
$_GET['num'] ?? $_POST['num'] ?? 0,
FILTER_VALIDATE_INT
);
} else {
// Resetting the pagination filter
$num = $centreon->historyPage[$url] ?? 0;
}

/* cast limit and num to avoid sql error on prepared statement (PDO::PARAM_INT) */
// Cast limit and num to avoid sql error on prepared statement (PDO::PARAM_INT)
$limit = (int)$limit;
$num = (int)$num;

Expand Down
54 changes: 19 additions & 35 deletions www/include/common/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@
$type = $_REQUEST["type"] ?? null;
$o = $_GET["o"] ?? $o = null;

// checking if the current page and the last displayed page are the same
if (isset($centreon->historyLastPage) && $centreon->historyLastPage !== $url) {
$num = 0;
} elseif (isset($_REQUEST['num'])) {
$num = filter_var(
$_GET['num'] ?? $_POST['num'] ?? 0,
FILTER_VALIDATE_INT
);
} else {
$num = $centreon->historyPage[$url] ?? 0;
}

//saving current pagination filter value and current displayed page
$centreon->historyPage[$url] = $num;
$centreon->historyLastPage = $url;
Expand Down Expand Up @@ -177,18 +165,18 @@
}

$pageArr = array();
$istart = 0;
for ($i = 5, $istart = $num; $istart && $i > 0; $i--) {
$istart--;
$iStart = 0;
for ($i = 5, $iStart = $num; $iStart && $i > 0; $i--) {
$iStart--;
}
for ($i2 = 0, $iend = $num; ($iend < ($rows / $limit - 1)) && ($i2 < (5 + $i)); $i2++) {
$iend++;
for ($i2 = 0, $iEnd = $num; ($iEnd < ($rows / $limit - 1)) && ($i2 < (5 + $i)); $i2++) {
$iEnd++;
}

if ($rows != 0) {
for ($i = $istart; $i <= $iend; $i++) {
for ($i = $iStart; $i <= $iEnd; $i++) {

$urlPage = "main.php?p=" . $p . "&num=$i&limit=" . $limit . "&poller=" . $poller .
$urlPage = "main.php?p=" . $p . "&num=" . $i . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var;
$pageArr[$i] = array(
"url_page" => $urlPage,
Expand All @@ -210,15 +198,15 @@
if (($prev = $num - 1) >= 0) {
$tpl->assign(
'pagePrev',
("main.php?p=" . $p . "&num=$prev&limit=" . $limit . "&poller=" . $poller .
("main.php?p=" . $p . "&num=" . $prev . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
);
}

if (($next = $num + 1) < ($rows / $limit)) {
$tpl->assign(
'pageNext',
("main.php?p=" . $p . "&num=$next&limit=" . $limit . "&poller=" . $poller .
("main.php?p=" . $p . "&num=" . $next . "&limit=" . $limit . "&poller=" . $poller .
"&template=" . $template . "&search=" . $search . "&type=" . $type . "&o=" . $o . $url_var)
);
}
Expand Down Expand Up @@ -264,14 +252,14 @@
}

?>
<script type="text/javascript">
function setL(_this) {
var _l = document.getElementsByName('l');
document.forms['form'].elements['limit'].value = _this;
_l[0].value = _this;
_l[1].value = _this;
}
</script>
<script type="text/javascript">
function setL(_this) {
var _l = document.getElementsByName('l');
document.forms['form'].elements['limit'].value = _this;
_l[0].value = _this;
_l[1].value = _this;
}
</script>
<?php
$form = new HTML_QuickFormCustom(
'select_form',
Expand All @@ -287,9 +275,7 @@ function setL(_this) {
);
$selLim->setSelected($limit);

/*
* Element we need when we reload the page
*/
// Element we need when we reload the page
$form->addElement('hidden', 'p');
$form->addElement('hidden', 'search');
$form->addElement('hidden', 'num');
Expand All @@ -298,9 +284,7 @@ function setL(_this) {
$form->addElement('hidden', 'sort_types');
$form->setDefaults(array("p" => $p, "search" => $search, "num" => $num));

/*
* Init QuickForm
*/
// Init QuickForm
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);

Expand Down
4 changes: 2 additions & 2 deletions www/include/configuration/configNagios/listNagios.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@

if (isset($_POST['searchN'])) {
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['searchN'] = $search;
$centreon->historySearch[$url]['search'] = $search;
} else {
$search = $centreon->historySearch[$url]['searchN'] ?? null;
$search = $centreon->historySearch[$url]['search'] ?? null;
}

$SearchTool = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
}

if (isset($_POST['searchC'])) {
//restoring user's search field value
//saving user's search field value
$centreon->historySearch[$url] = array();
// the four pages have the same $url, so we need to distinguish each page using its $type,
// and to save the four search filters.
$centreon->historySearch[$url]['search' . $type] = $search;
} else {
//saving user's search field value
//restoring user's search field value
$search = $centreon->historySearch[$url]['search' . $type] ?? null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@

include_once "./include/common/autoNumLimit.php";


// restoring the pagination if we stay on this menu
$num = 0;
if ($centreon->historyLastPage === $url && isset($_GET['num'])) {
$num = $_GET['num'];
}

try {
$connectorsList = $connectorObj->getList(false, (int)$num, (int)$limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@

$search = null;
if (isset($_POST['searchC']) || isset($_GET['search'])) {
$centreon->historySearch[$url] = $search;
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['search'] = $search;
} else {
$search = $centreon->historySearch[$url];
$search = $centreon->historySearch[$url]['search'] ?? null;
}

$clauses = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
);

if (isset($_POST['searchCT']) || isset($_GET['searchCT'])) {
$centreon->historySearch[$url] = $search;
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['search'] = $search;
} else {
$search = $centreon->historySearch[$url];
$search = $centreon->historySearch[$url]['search'] ?? null;
}

$clauses = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
);

if (isset($_POST['searchCG']) || isset($_GET['search'])) {
$centreon->historySearch[$url] = $search;
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['search'] = $search;
} else {
$search = $centreon->historySearch[$url];
$search = $centreon->historySearch[$url]['search'] ?? null;
}

$clauses = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@

if (isset($_POST['searchE'])) {
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['searchE'] = $search;
$centreon->historySearch[$url]['search'] = $search;
} else {
$search = $centreon->historySearch[$url]['searchE'] ?? null;
$search = $centreon->historySearch[$url]['search'] ?? null;
}

$aclFrom = "";
Expand Down
Loading

0 comments on commit 8788f72

Please sign in to comment.