metrics.createWindow(() => {
const View = new ViewWindow({
title: ` Web Metrik`,
width: "600px",
height: "600px",
})
loadMetrics()
function loadMetrics() {
View.setContent(`
WebMetrik : Calcul en cours
Rafraîchir
Ajouter un WebMetrik
`)
const metricsList = new Array()
const metricsComponent = new Array()
const metricsReq = get("MT_ALL")
const metricsDiv = document.getElementById(`${View.getViewTitle()}_metrics`)
const metricsNumber = document.getElementById(`${View.getViewTitle()}_number`)
const addButton = document.getElementById(`${View.getViewTitle()}_add`)
const refreshButton = document.getElementById(`${View.getViewTitle()}_refresh`)
const metricsView = document.getElementById(`${View.getViewTitle()}_metrics`)
refreshButton.addEventListener("click", () => {
loadMetrics()
})
metricsReq.then((ANS_metrics) => {
console.log(ANS_metrics)
if(ANS_metrics != "UNAVAILABLE") {
metricsList.length = 0
if(ANS_metrics.length == 0) {
metricsList.push(`
Aucune WebMetrik n'a été ajoutée
`)
}
ANS_metrics.forEach((metric) => {
const metricComponent = new Metric({
properties: metric,
Component: metrics,
View: View
})
metricsList.push(metricComponent.generateHTML())
metricsComponent.push(metricComponent)
})
metricsDiv.innerHTML = metricsList.join("")
metricsNumber.innerHTML = ANS_metrics.length
for(const metric of metricsComponent) {
metric.loadScript()
}
} else {
metricsDiv.innerHTML = `
Une erreur est survenue lors du chargement des WebMetrik
`
}
})
// Generate a pop to add metrics with 3 settings, the adress, the port, the name of the metrics and the key to authentificate
addButton.addEventListener("click", () => {
View.createPopup({
title: "Ajouter un WebMetrik",
content: `
`
})
const addBtn = document.getElementById("mt-add-btn")
const address = document.getElementById("mt-add-address")
const port = document.getElementById("mt-add-port")
const name = document.getElementById("mt-add-name")
const key = document.getElementById("mt-add-key")
const infoMTAdd = new TextResponse("mtaddinfo")
addBtn.addEventListener("click", () => {
// Check if all fields are filled
if(address.value == "" || port.value == "" || name.value == "" || key.value == "") {
infoMTAdd.err("Veuillez remplir tous les champs")
return
}
post("MT_ADD", {
address: address.value,
port: port.value,
name: name.value,
key: key.value
}).then((res) => {
if(res != "ERROR") {
View.destroyPopup()
loadMetrics()
} else {
View.createPopup({
title: "Erreur",
content: `
Une erreur est survenue lors de l'ajout de la WebMetrik
`
})
}
})
})
})
}
})
/*
*/