mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
new: pve dashboard (#307)
This commit is contained in:
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
}) {
|
||||
@@ -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:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user