Version 0.4.0 - Ajout des metrics
All checks were successful
Neutral/pipeline/head This commit looks good

This commit is contained in:
Raphix
2023-11-28 21:05:44 +01:00
parent 04fcece8d4
commit b19243a8af
17 changed files with 1121 additions and 384 deletions

View File

@ -1,164 +1,7 @@
async function generateServiceView() {
class Service {
name = null
description = null
icon = null
url = null
canAccess = false
isOnline = false
constructor(properties) {
this.name = properties.name
this.description = properties.description
this.icon = properties.icon
this.url = properties.url
this.canAccess = properties.canAccess
}
generateHTML() {
return `
<div class="sv">
<div class='sv-info'>
<img class="sv-icon" src="${this.icon}" alt="${this.name}">
<div>
<h1>${this.name}</h1>
<p>${this.description}</p>
<p>Etat : <span id='${this.name}_status' class="sv-status">Vérification en cours ...</span></p>
</div>
</div>
<div class="sv-actions">
${this.canAccess ? `<a href="${this.url}" target="_blank"><button class="btn green"><span>Accéder au service</span></button></a>` : ""}
<button id='${this.name}_svpower' class='btn yellow'n><span>Options d'alimentation<span></button>
</div>
</div>
`
}
loadScript() {
return new Promise((resolve, reject) => {
const statusSpan = getID(`${this.name}_status`)
const request = post(`SV_GET_SERVICE_STATUS`, this.url)
request.then((answer) => {
if(answer.name == this.url) {
if(answer.answer == "ONLINE") {
statusSpan.innerHTML = '<span style="font-size: 12px;"><i class="fa-solid fa-circle green"></i> En ligne</span>'
this.isOnline = true
} else {
statusSpan.innerHTML = '<span style="font-size: 12px;"><i class="fa-solid fa-circle red"></i> Hors ligne</span>'
}
resolve("LOADED")
}
})
const powerButton = getID(`${this.name}_svpower`)
// Make a popup of View to select if you want to start, stop or restart the service by doing a request
powerButton.addEventListener("click", () => {
View.createPopup({
title: `<i class='fa-solid fa-power-off'></i> Gestion de l'alimentation du service`,
content: `
<p class='sv-power-select'>${this.name}</p>
<p id='sv-power-info'></p>
<div class="sv-power">
<button id="${this.name}_start" class="btn green"><span>Démarrer</span></button>
<button id="${this.name}_restart" class="btn yellow"><span>Redémarrer</span></button>
<button id="${this.name}_stop" class="btn red"><span> Arrêter</span></button>
</div>
`
})
const startButton = getID(`${this.name}_start`)
const stopButton = getID(`${this.name}_stop`)
const restartButton = getID(`${this.name}_restart`)
const info = new InfoPop("sv-power-info")
if(this.isOnline) {
startButton.style.display = "none"
info.info("Verifiez que le service n'est pas utilisé par quelqu'un d'autre avant de le redémarrer ou de l'arrêter")
} else {
stopButton.style.display = "none"
restartButton.style.display = "none"
info.info("Si le service ne démarre pas, vérifiez l'intégrité du service")
}
startButton.addEventListener("click", () => {
const request = post(`SV_START_SERVICE`, this.url)
request.then((answer) => {
if(answer.answer == "OK") {
statusSpan.innerHTML = '<span style="font-size: 12px;"><i class="fa-solid fa-circle green"></i> En ligne</span>'
View.destroyPopup("`<i class='fa-solid fa-power-off'></i> Gestion de l'alimentation du service`")
this.isOnline = true
} else {
info.err("Impossible de démarrer le service")
}
})
})
stopButton.addEventListener("click", () => {
const request = post(`SV_STOP_SERVICE`, this.url)
request.then((answer) => {
if(answer.answer == "OK") {
statusSpan.innerHTML = '<span style="font-size: 12px;"><i class="fa-solid fa-circle red"></i> Hors ligne</span>'
this.isOnline = false
View.destroyPopup("`<i class='fa-solid fa-power-off'></i> Gestion de l'alimentation du service`")
} else {
info.err("Impossible d'arrêter le service")
}
})
})
restartButton.addEventListener("click", () => {
console.log("RESTART")
const request = post(`SV_RESTART_SERVICE`, this.url)
request.then((answer) => {
if(answer.answer == "OK") {
statusSpan.innerHTML = '<span style="font-size: 12px;"><i class="fa-solid fa-circle green"></i> En ligne</span>'
View.destroyPopup("`<i class='fa-solid fa-power-off'></i> Gestion de l'alimentation du service`")
this.isOnline = true
} else {
info.err("Impossible de redémarrer le service")
}
})
})
})
})
}
}
services.createWindow(async () => {
/**
* CODE OF SERVICE.JS
*/
const allServices = new Array()
const View = new ViewWindow({
@ -236,5 +79,5 @@ async function generateServiceView() {
await cvraphix.loadScript()
await lavalink.loadScript()
}
})