From: Roman Bazalevsky Date: Mon, 16 Dec 2019 08:14:05 +0000 (+0300) Subject: Работа с датами. Вперед-назад, проверка ограничений. X-Git-Url: https://git.rvb.name/squid-reports.git/commitdiff_plain/823133accebdf5f40aff0d1807389438a053423c?ds=inline;hp=ec03340acbf414ccaee2f2ac9bed6fb68fe75674 Работа с датами. Вперед-назад, проверка ограничений. --- diff --git a/web/api.php b/web/api.php index 2b700e2..4da8707 100644 --- a/web/api.php +++ b/web/api.php @@ -78,6 +78,8 @@ $users = exec_query("select id,username as name,alias from users"); $hosts = exec_query("select id,hostname as name,alias from hosts"); $data["dictionaries"] = Array( "user_id" => $users, "host_id" => $hosts); + $data["online_refresh"] = $online_refresh; + $data["online_history"] = $online_history; break; diff --git a/web/index.html b/web/index.html index 39266c4..e3a8f40 100644 --- a/web/index.html +++ b/web/index.html @@ -26,6 +26,7 @@
Отчет с: по: + Фильтр: diff --git a/web/squid.js b/web/squid.js index 58a9542..0260b10 100644 --- a/web/squid.js +++ b/web/squid.js @@ -1,8 +1,5 @@ urlbase="./api.php" -refresh = 1000 -online_history = 60 - graph_colors = [ "salmon", "lightcoral", "crimson", "red", "darkred", "orangered", "gold", "orange", "yellow", "darkkhaki", "lime", "green", "greenyellow", @@ -42,11 +39,22 @@ assigned_colors = [] current_time = null time_labels = [] -var d = new Date(); -var curr_day = d.getDate(); -var curr_month = d.getMonth() + 1; -var curr_year = d.getFullYear(); -today = curr_year + "-" + curr_month + "-" + curr_day; +function toDate(d) { + var curr_day = d.getDate(); + if (curr_day<10) { curr_day = '0' + curr_day; } + var curr_month = d.getMonth() + 1; + if (curr_month<10) { curr_month = '0' + curr_month; } + var curr_year = d.getFullYear(); + return curr_year + "-" + curr_month + "-" + curr_day +} + +function Today() { + var dToday = new Date(); + dToday.setHours(0,0,0,0) + return dToday +} + +today = toDate(Today()); date_from = today date_to = today @@ -133,6 +141,9 @@ function UpdatePageProps(props) { var logo = document.getElementById("brand"); logo.innerText = props["site-header"]; + refresh = props["online_refresh"] + online_history = props["online_history"] + cats = props["cats"] for (var i in res["columns"]) { @@ -635,6 +646,37 @@ function UpdateDates() { } +function DateLeft() { + UpdateDates() + var dFrom = new Date(date_from) + var dTo = new Date(date_to) + var delta = Math.round(((dTo.getTime() - dFrom.getTime()))/(86400*1000)) + dTo.setDate(dTo.getDate() - (1 + delta)) + dFrom.setDate(dFrom.getDate() - (1 + delta)) + date_from = toDate(dFrom) + date_to = toDate(dTo) + SetDates() +} + +function DateRight() { + dToday = new Date(); + UpdateDates() + var dFrom = new Date(date_from) + var dTo = new Date(date_to) + var delta = Math.round(((dTo.getTime() - dFrom.getTime()))/(86400*1000)) + dFrom.setDate(dFrom.getDate() + 1 + delta) + dTo.setDate(dTo.getDate() + 1 + delta) + if (dTo>Today()) { + dTo = Today() + } + if (dFrom>Today()) { + dFrom = Today() + } + date_from = toDate(dFrom) + date_to = toDate(dTo) + SetDates() +} + function SetFilter(name,select) { current_filter[name] = select.value; }