Skip to content

Commit

Permalink
new: pve dashboard (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 19, 2024
1 parent 26264ec commit 2597f99
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 114 deletions.
32 changes: 25 additions & 7 deletions lib/data/model/server/pve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ enum PveResType {
}

String get toStr => switch (this) {
PveResType.node => l10n.node,
PveResType.qemu => 'QEMU',
PveResType.lxc => 'LXC',
PveResType.storage => l10n.storage,
PveResType.sdn => 'SDN',
};
PveResType.node => l10n.node,
PveResType.qemu => 'QEMU',
PveResType.lxc => 'LXC',
PveResType.storage => l10n.storage,
PveResType.sdn => 'SDN',
};
}

sealed class PveResIface {
Expand Down Expand Up @@ -121,6 +121,15 @@ final class PveLxc extends PveResIface {
netout: json['netout'],
);
}

bool get isRunning => status == 'running';

String get topRight {
if (isRunning) {
return uptime.secondsToDuration().toStr;
}
return l10n.stopped;
}
}

final class PveQemu extends PveResIface {
Expand Down Expand Up @@ -190,7 +199,7 @@ final class PveQemu extends PveResIface {
bool get isRunning => status == 'running';

String get topRight {
if (!isRunning) {
if (isRunning) {
return uptime.secondsToDuration().toStr;
}
return l10n.stopped;
Expand Down Expand Up @@ -236,6 +245,15 @@ final class PveNode extends PveResIface {
maxcpu: json['maxcpu'],
);
}

bool get isRunning => status == 'online';

String get topRight {
if (isRunning) {
return uptime.secondsToDuration().toStr;
}
return l10n.stopped;
}
}

final class PveStorage extends PveResIface {
Expand Down
38 changes: 32 additions & 6 deletions lib/data/provider/pve.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/order.dart';
import 'package:toolbox/data/model/server/pve.dart';
import 'package:toolbox/data/model/server/server_private_info.dart';

Expand All @@ -10,6 +11,8 @@ final class PveProvider extends ChangeNotifier {
late final String addr;
//late final SSHClient _client;

final data = ValueNotifier<PveRes?>(null);

PveProvider({
required this.spi,
}) {
Expand Down Expand Up @@ -77,11 +80,12 @@ final class PveProvider extends ChangeNotifier {
final resp = await session.get('$addr/api2/json/cluster/resources');
final list = resp.data['data'] as List;
final items = list.map((e) => PveResIface.fromJson(e)).toList();
final qemus = <PveQemu>[];
final lxcs = <PveLxc>[];
final nodes = <PveNode>[];
final storages = <PveStorage>[];
final sdns = <PveSdn>[];

final Order<PveQemu> qemus = [];
final Order<PveLxc> lxcs = [];
final Order<PveNode> nodes = [];
final Order<PveStorage> storages = [];
final Order<PveSdn> sdns = [];
for (final item in items) {
switch (item.type) {
case PveResType.lxc:
Expand All @@ -101,12 +105,34 @@ final class PveProvider extends ChangeNotifier {
break;
}
}
return PveRes(

final old = data.value;
if (old != null) {
qemus.reorder(
order: old.qemus.map((e) => e.id).toList(),
finder: (e, s) => e.id == s);
lxcs.reorder(
order: old.lxcs.map((e) => e.id).toList(),
finder: (e, s) => e.id == s);
nodes.reorder(
order: old.nodes.map((e) => e.id).toList(),
finder: (e, s) => e.id == s);
storages.reorder(
order: old.storages.map((e) => e.id).toList(),
finder: (e, s) => e.id == s);
sdns.reorder(
order: old.sdns.map((e) => e.id).toList(),
finder: (e, s) => e.id == s);
}

final res = PveRes(
qemus: qemus,
lxcs: lxcs,
nodes: nodes,
storages: storages,
sdns: sdns,
);
data.value = res;
return res;
}
}
5 changes: 5 additions & 0 deletions lib/data/res/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ abstract final class UIs {
);
static const text13Grey = TextStyle(color: Colors.grey, fontSize: 13);
static const text15 = TextStyle(fontSize: 15);
static const text15Bold = TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
);
static const text18 = TextStyle(fontSize: 18);
static const text27 = TextStyle(fontSize: 27);
static const textGrey = TextStyle(color: Colors.grey);
Expand All @@ -39,6 +43,7 @@ abstract final class UIs {
/// SizedBox
static const placeholder = SizedBox();
static const height7 = SizedBox(height: 7);
static const height13 = SizedBox(height: 13);
static const height77 = SizedBox(height: 77);
static const width13 = SizedBox(width: 13);
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Container Name",
"containerStatus": "Container Status",
"containerTrySudoTip": "Zum Beispiel: In der App ist der Benutzer auf aaa eingestellt, aber Docker ist unter dem Root-Benutzer installiert. In diesem Fall müssen Sie diese Option aktivieren",
"content": "Inhalt",
"convert": "Konvertieren",
"copy": "Kopieren",
"copyPath": "Pfad kopieren",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Kein Server zum Anpingen.\nBitte füge einen Server hinzu.",
"pkg": "Pkg",
"platformNotSupportUpdate": "Die aktuelle Plattform unterstützt keine In-App-Updates.\nBitte kompiliere vom Quellcode und installiere sie.",
"plugInType": "Einfügetyp",
"plzEnterHost": "Bitte Host eingeben.",
"plzSelectKey": "Wähle einen Key.",
"port": "Port",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Container name",
"containerStatus": "Container status",
"containerTrySudoTip": "For example: In the app, the user is set to aaa, but Docker is installed under the root user. In this case, you need to enable this option.",
"content": "Content",
"convert": "Convert",
"copy": "Copy",
"copyPath": "Copy path",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "No server to ping.\nPlease add a server in server tab.",
"pkg": "Pkg",
"platformNotSupportUpdate": "Current platform does not support in app update.\nPlease build from source and install it.",
"plugInType": "Insertion Type",
"plzEnterHost": "Please enter host.",
"plzSelectKey": "Please select a key.",
"port": "Port",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Nombre del contenedor",
"containerStatus": "Estado del contenedor",
"containerTrySudoTip": "Por ejemplo: si configuras el usuario dentro de la app como aaa, pero Docker está instalado bajo el usuario root, entonces necesitarás habilitar esta opción",
"content": "Contenido",
"convert": "Convertir",
"copy": "Copiar",
"copyPath": "Copiar ruta",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "No hay servidores disponibles para hacer Ping\nPor favor, añade un servidor en la pestaña de servidores y vuelve a intentarlo",
"pkg": "Gestión de paquetes",
"platformNotSupportUpdate": "La plataforma actual no soporta actualizaciones, por favor instala manualmente la última versión del código fuente",
"plugInType": "Tipo de inserción",
"plzEnterHost": "Por favor, introduce el host",
"plzSelectKey": "Por favor, selecciona una llave privada",
"port": "Puerto",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Nom du conteneur",
"containerStatus": "Statut du conteneur",
"containerTrySudoTip": "Par exemple : dans l'application, l'utilisateur est défini comme aaa, mais Docker est installé en tant qu'utilisateur root. Dans ce cas, vous devez activer cette option.",
"content": "Contenu",
"convert": "Convertir",
"copy": "Copier",
"copyPath": "Copier le chemin",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Aucun serveur pour ping.\nVeuillez ajouter un serveur dans l'onglet serveur.",
"pkg": "Pkg",
"platformNotSupportUpdate": "La plateforme actuelle ne prend pas en charge la mise à jour dans l'application. \nVeuillez le compiler à partir de la source et l'installer.",
"plugInType": "Type d'insertion",
"plzEnterHost": "Veuillez saisir l'hôte.",
"plzSelectKey": "Veuillez sélectionner une clé.",
"port": "Port",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Nama kontainer",
"containerStatus": "Status wadah",
"containerTrySudoTip": "Contohnya: Di dalam aplikasi, pengguna diatur sebagai aaa, tetapi Docker diinstal di bawah pengguna root. Dalam kasus ini, Anda perlu mengaktifkan opsi ini.",
"content": "Konten",
"convert": "Mengubah",
"copy": "Menyalin",
"copyPath": "Path Copy",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Tidak ada server untuk melakukan ping.\nHarap tambahkan server di tab Server.",
"pkg": "Pkg",
"platformNotSupportUpdate": "Platform saat ini tidak mendukung pembaruan aplikasi.\nSilakan bangun dari sumber dan instal.",
"plugInType": "Jenis Penyisipan",
"plzEnterHost": "Harap masukkan host.",
"plzSelectKey": "Pilih kunci.",
"port": "Port",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "コンテナ名",
"containerStatus": "コンテナの状態",
"containerTrySudoTip": "例:アプリ内でユーザーをaaaに設定しているが、Dockerがrootユーザーでインストールされている場合、このオプションを有効にする必要があります",
"content": "コンテンツ",
"convert": "変換",
"copy": "コピー",
"copyPath": "パスをコピー",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Pingに使用するサーバーがありません\nサーバータブでサーバーを追加してから再試行してください",
"pkg": "パッケージ管理",
"platformNotSupportUpdate": "現在のプラットフォームは更新をサポートしていません。最新のソースコードをコンパイルして手動でインストールしてください",
"plugInType": "挿入タイプ",
"plzEnterHost": "ホストを入力してください",
"plzSelectKey": "プライベートキーを選択してください",
"port": "ポート",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "Nome do contêiner",
"containerStatus": "Estado do contêiner",
"containerTrySudoTip": "Por exemplo: se o usuário for definido como aaa dentro do app, mas o Docker estiver instalado sob o usuário root, esta opção precisará ser ativada",
"content": "Conteúdo",
"convert": "Converter",
"copy": "Copiar",
"copyPath": "Copiar caminho",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Nenhum servidor disponível para Ping\nPor favor, adicione um servidor na aba de servidores e tente novamente",
"pkg": "Gerenciamento de pacotes",
"platformNotSupportUpdate": "Atualização não suportada na plataforma atual, por favor, instale manualmente a versão mais recente do código-fonte",
"plugInType": "Tipo de Inserção",
"plzEnterHost": "Por favor, insira o host",
"plzSelectKey": "Por favor, selecione uma chave privada",
"port": "Porta",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "имя контейнера",
"containerStatus": "статус контейнера",
"containerTrySudoTip": "Например: если пользователь в приложении установлен как aaa, но Docker установлен под пользователем root, тогда нужно включить эту опцию",
"content": "Содержимое",
"convert": "конвертировать",
"copy": "копировать",
"copyPath": "копировать путь",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "Нет доступных серверов для Ping\nПожалуйста, добавьте серверы на вкладке серверов и попробуйте снова",
"pkg": "менеджер пакетов",
"platformNotSupportUpdate": "Текущая платформа не поддерживает обновления, пожалуйста, вручную установите последнюю версию из исходного кода",
"plugInType": "Тип вставки",
"plzEnterHost": "Пожалуйста, введите хост",
"plzSelectKey": "Пожалуйста, выберите ключ",
"port": "порт",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "容器名",
"containerStatus": "容器状态",
"containerTrySudoTip": "例如:在应用内将用户设置为aaa,但是Docker安装在root用户下,这时就需要启用此选项",
"content": "内容",
"convert": "转换",
"copy": "复制",
"copyPath": "复制路径",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "没有服务器可用于Ping\n请在服务器tab添加服务器后再试",
"pkg": "包管理",
"platformNotSupportUpdate": "当前平台不支持更新,请编译最新源码后手动安装",
"plugInType": "插入类型",
"plzEnterHost": "请输入主机",
"plzSelectKey": "请选择私钥",
"port": "端口",
Expand Down
2 changes: 2 additions & 0 deletions lib/l10n/app_zh_tw.arb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"containerName": "容器名稱",
"containerStatus": "容器狀態",
"containerTrySudoTip": "例如:App内设置用户为aaa,但是Docker安装在root用户,这时就需要开启此选项",
"content": "內容",
"convert": "轉換",
"copy": "複製",
"copyPath": "複製路徑",
Expand Down Expand Up @@ -185,6 +186,7 @@
"pingNoServer": "沒有服務器可用於Ping\n請在服務器tab新增服務器後再試",
"pkg": "包管理",
"platformNotSupportUpdate": "當前平台不支持更新,請編譯最新源碼後手動安裝",
"plugInType": "插入類型",
"plzEnterHost": "請輸入主機",
"plzSelectKey": "請選擇私鑰",
"port": "端口",
Expand Down
Loading

0 comments on commit 2597f99

Please sign in to comment.