Добавил фронтенд
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
class GetAnomalyLogs extends ControllerBase {
|
||||
// Конструктор
|
||||
constructor(url) {
|
||||
super("anomaly_logs");
|
||||
|
||||
this.last_id = -1;
|
||||
}
|
||||
|
||||
// Отправка запроса на сервер
|
||||
SendRequest() {
|
||||
let parameters = {
|
||||
'last_id': this.last_id
|
||||
};
|
||||
|
||||
super.Get(parameters);
|
||||
}
|
||||
|
||||
// Обработка ответа от сервера
|
||||
// respone -- ответ сервера
|
||||
ProcessResponse(response) {
|
||||
this.UpdateData(response);
|
||||
}
|
||||
|
||||
// Обновление данных
|
||||
// respone -- ответ от сервера
|
||||
UpdateData(response) {
|
||||
let logs = response["result"];
|
||||
if (logs == null)
|
||||
return;
|
||||
|
||||
let last_id = this.last_id;
|
||||
for (const item of logs) {
|
||||
let row = window.anomaly_logs_table.insertRow();
|
||||
|
||||
const id = Number(item["id"]);
|
||||
|
||||
let cell = row.insertCell(0);
|
||||
cell.innerHTML = String(id);
|
||||
|
||||
cell = row.insertCell(1);
|
||||
cell.innerHTML = item["data"];
|
||||
|
||||
cell = row.insertCell(2);
|
||||
const cluster_id = Number(item["cluster_id"]);
|
||||
cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
|
||||
|
||||
DecorateClusterCell(id, cluster_id, cell);
|
||||
|
||||
if (id > last_id)
|
||||
last_id = id;
|
||||
}
|
||||
|
||||
this.last_id = last_id;
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateAnomalyLogs() {
|
||||
window.get_anomaly_logs.SendRequest()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function InitAnomalyLogs() {
|
||||
window.get_anomaly_logs = new GetAnomalyLogs();
|
||||
window.update_cluster_id = new UpdateClusterIdInAnomalyLog();
|
||||
window.anomaly_logs_table = document.getElementById("anomaly-logs-table");
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
class UpdateClusterIdInAnomalyLog extends ControllerBase {
|
||||
// Конструктор
|
||||
constructor(url) {
|
||||
super("anomaly_logs/update_cluster_id");
|
||||
}
|
||||
|
||||
// Отправка запроса на сервер
|
||||
async SendRequest(log_id, cluster_id, cell) {
|
||||
let parameters = {
|
||||
'id': Number(log_id),
|
||||
'cluster_id': Number(cluster_id)
|
||||
};
|
||||
|
||||
await super.Any(parameters, "post");
|
||||
|
||||
this.UpdateCell(cluster_id, cell);
|
||||
}
|
||||
|
||||
ProcessResponse(response) {}
|
||||
|
||||
UpdateCell(cluster_id, cell) {
|
||||
cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
function DecorateClusterCell(log_id, cluster_id, cell) {
|
||||
if (cluster_id == 0) {
|
||||
cell.innerHTML = "";
|
||||
let select_cluster = window.select_cluster.cloneNode(true);
|
||||
|
||||
select_cluster.addEventListener("change", async (event) => {
|
||||
let new_cluster_id = event.target.value;
|
||||
await window.update_cluster_id.SendRequest(log_id, new_cluster_id, cell);
|
||||
cell.innerHTML = window.get_logs_clusters.clusters[new_cluster_id]["name"];
|
||||
});
|
||||
|
||||
select_cluster.addEventListener("click", (event) => {
|
||||
console.log("updating selector");
|
||||
UpdateClusterSelector(select_cluster);
|
||||
});
|
||||
|
||||
cell.appendChild(select_cluster);
|
||||
} else {
|
||||
cell.innerHTML = window.get_logs_clusters.clusters[cluster_id]["name"];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user