Добавил фронтенд
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
class CreateLogsCluster extends ControllerBase {
|
||||
// Конструктор
|
||||
constructor() {
|
||||
super("logs_clusters");
|
||||
}
|
||||
|
||||
// Отправка запроса на сервер
|
||||
async SendRequest(name, description, recommendation) {
|
||||
let cluster = {
|
||||
"id": window.get_logs_clusters.clusters.length,
|
||||
"name": name,
|
||||
"description": description,
|
||||
"recommendation": recommendation
|
||||
};
|
||||
|
||||
await super.Any(cluster, 'post');
|
||||
|
||||
let row = window.logs_cluters_table.insertRow();
|
||||
this.FillClusterRow(row, cluster);
|
||||
|
||||
window.get_logs_clusters.clusters.push(cluster);
|
||||
window.get_logs_clusters.AddCluster(window.select_cluster, cluster);
|
||||
}
|
||||
|
||||
// Обработка ответа от сервера
|
||||
// respone -- ответ сервера
|
||||
ProcessResponse(response) {}
|
||||
|
||||
FillClusterRow(row, cluster) {
|
||||
let cell = row.insertCell(0);
|
||||
cell.innerHTML = String(cluster["id"]);
|
||||
|
||||
cell = row.insertCell(1);
|
||||
cell.innerHTML = cluster["name"];
|
||||
|
||||
cell = row.insertCell(2);
|
||||
cell.innerHTML = cluster["description"];
|
||||
|
||||
cell = row.insertCell(3);
|
||||
cell.innerHTML = cluster["recommendation"];
|
||||
}
|
||||
}
|
||||
|
||||
async function CreateCluster() {
|
||||
const name = document.getElementById("cluster-name").value;
|
||||
if (name.length == 0) {
|
||||
alert("Название кластера не может быть пустым");
|
||||
return;
|
||||
}
|
||||
|
||||
const description = document.getElementById("cluster-description").value;
|
||||
const recommendation = document.getElementById("cluster-recommendation").value;
|
||||
|
||||
await window.create_logs_cluster.SendRequest(name, description, recommendation);
|
||||
}
|
||||
|
||||
function UpdateClusterSelector(selector) {
|
||||
for (let index = selector.options.length; index < window.select_cluster.options.length; index++) {
|
||||
let option = window.select_cluster.options[index];
|
||||
selector.add(option.cloneNode(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
class GetLogsClusters extends ControllerBase {
|
||||
// Конструктор
|
||||
constructor() {
|
||||
super("logs_clusters");
|
||||
this.clusters = null
|
||||
}
|
||||
|
||||
// Отправка запроса на сервер
|
||||
async SendRequest() {
|
||||
await super.Get({});
|
||||
}
|
||||
|
||||
// Обработка ответа от сервера
|
||||
// respone -- ответ сервера
|
||||
ProcessResponse(response) {
|
||||
this.clusters = response["result"];
|
||||
|
||||
for (const cluster of this.clusters) {
|
||||
let row = window.logs_cluters_table.insertRow();
|
||||
|
||||
let cell = row.insertCell(0);
|
||||
cell.innerHTML = cluster["id"];
|
||||
|
||||
cell = row.insertCell(1);
|
||||
cell.innerHTML = cluster["name"];
|
||||
|
||||
cell = row.insertCell(2);
|
||||
cell.innerHTML = cluster["description"];
|
||||
|
||||
cell = row.insertCell(3);
|
||||
cell.innerHTML = cluster["recommendation"];
|
||||
}
|
||||
|
||||
// Формирование списка кластеров
|
||||
let select_cluster = document.createElement("select");
|
||||
|
||||
let option = document.createElement("option");
|
||||
option.text = "Неизвестный кластер. Выберите один из существующих";
|
||||
|
||||
select_cluster.add(option);
|
||||
|
||||
for (let index of Array.from({length: this.clusters.length - 1}, (_, i) => i + 1)) {
|
||||
const cluster = this.clusters[index];
|
||||
this.AddCluster(select_cluster, cluster)
|
||||
}
|
||||
|
||||
window.select_cluster = select_cluster;
|
||||
}
|
||||
|
||||
AddCluster(select_cluster, cluster) {
|
||||
let option = document.createElement("option");
|
||||
option.value = cluster["id"];
|
||||
option.text = cluster["name"];
|
||||
|
||||
select_cluster.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
async function UpdateClusters() {
|
||||
await window.get_logs_clusters.SendRequest()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function InitLogsClusters() {
|
||||
window.create_logs_cluster = new CreateLogsCluster();
|
||||
window.get_logs_clusters = new GetLogsClusters();
|
||||
window.logs_cluters_table = document.getElementById("logs-clusters-table");
|
||||
}
|
||||
Reference in New Issue
Block a user