mirror of
https://github.com/StefBuwalda/dashboard_test.git
synced 2025-12-19 03:27:54 +00:00
First big step in moving towards DB storage instead of memory storage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
@@ -7,12 +7,8 @@ from flask_migrate import Migrate
|
||||
class service:
|
||||
id: int
|
||||
url: str
|
||||
status: Optional[int]
|
||||
online: bool
|
||||
public: bool
|
||||
error: Optional[str]
|
||||
ping: Optional[int]
|
||||
icon_filetype: str
|
||||
ping_type: int
|
||||
|
||||
def __init__(
|
||||
@@ -21,7 +17,6 @@ class service:
|
||||
url: str = "",
|
||||
label: str = "",
|
||||
public: bool = True,
|
||||
icon_filetype: str = "svg",
|
||||
ping_type: int = 0,
|
||||
):
|
||||
self.id = id
|
||||
@@ -30,38 +25,15 @@ class service:
|
||||
self.label = label
|
||||
self.ping_type = ping_type
|
||||
|
||||
self.online = False
|
||||
self.status = None
|
||||
self.error = None
|
||||
self.ping = None
|
||||
self.icon_filetype = icon_filetype
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"url": self.url,
|
||||
"status": self.status,
|
||||
"public": self.public,
|
||||
"online": self.online,
|
||||
"error": self.error,
|
||||
"ping": self.ping,
|
||||
"label": self.label,
|
||||
"icon_filetype": self.icon_filetype,
|
||||
"id": self.id,
|
||||
"ping_type": self.ping_type,
|
||||
}
|
||||
|
||||
def set_status(self, status: Optional[int]):
|
||||
self.status = status
|
||||
|
||||
def set_online(self, b: bool):
|
||||
self.online = b
|
||||
|
||||
def set_error(self, s: Optional[str]):
|
||||
self.error = s
|
||||
|
||||
def set_ping(self, n: Optional[int]):
|
||||
self.ping = n
|
||||
|
||||
|
||||
services: list[service] = [
|
||||
service(0, "https://git.ihatemen.uk/", "Gitea"),
|
||||
|
||||
@@ -75,18 +75,18 @@
|
||||
|
||||
// Build all service divs as a single string
|
||||
main_body.innerHTML = services.map(s => `
|
||||
<a href="${s.url}" class="d-block text-body text-decoration-none m-2 border border-3 ${s.online ? 'border-success' : 'border-danger'}" style="width: 175px">
|
||||
<a href="${s.url}" class="d-block text-body text-decoration-none m-2 border border-3 ${s.ping ? 'border-success' : 'border-danger'}" style="width: 175px">
|
||||
<div class="bg-body-tertiary d-flex flex-column align-items-center">
|
||||
<div class="bg-dark w-100">
|
||||
<h4 class="text-center text-truncate m-0 p-1">${s.label}</h4>
|
||||
</div>
|
||||
<div class="position-relative ratio ratio-1x1">
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<img src="static/icons/${s.id}.${s.icon_filetype}" class="img-fluid w-75">
|
||||
<img src="static/icons/${s.service_id - 1}.svg" class="img-fluid w-75">
|
||||
</div>
|
||||
<div>
|
||||
${s.public ? `` : `<img src='static/lock.svg' class='img-fluid position-absolute bottom-0 end-0 w-25'>`}
|
||||
<div class="position-absolute bottom-0 text-body bg-dark bg-opacity-75 px-1 rounded">${s.online ? s.ping + "ms" : ""}</div>
|
||||
${s.public_access ? `` : `<img src='static/lock.svg' class='img-fluid position-absolute bottom-0 end-0 w-25'>`}
|
||||
<div class="position-absolute bottom-0 text-body bg-dark bg-opacity-75 px-1 rounded">${s.ping ? s.ping + "ms" : ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user