Skip to content

Commit

Permalink
new: pve (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Mar 18, 2024
1 parent 8bfb0eb commit 26264ec
Show file tree
Hide file tree
Showing 31 changed files with 1,114 additions and 56 deletions.
20 changes: 20 additions & 0 deletions lib/core/extension/duration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:toolbox/core/extension/context/locale.dart';

extension DurationX on Duration {
String get toStr {
final days = inDays;
if (days > 0) {
return '$days ${l10n.day}';
}
final hours = inHours % 24;
if (hours > 0) {
return '$hours ${l10n.hour}';
}
final minutes = inMinutes % 60;
if (minutes > 0) {
return '$minutes ${l10n.minute}';
}
final seconds = inSeconds % 60;
return '$seconds ${l10n.second}';
}
}
5 changes: 5 additions & 0 deletions lib/core/extension/numx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ extension BigIntX on BigInt {

String get kb2Str => (this * BigInt.from(1024)).bytes2Str;
}

extension IntX on int {
Duration secondsToDuration() => Duration(seconds: this);
DateTime get tsToDateTime => DateTime.fromMillisecondsSinceEpoch(this * 1000);
}
11 changes: 6 additions & 5 deletions lib/core/extension/order.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:toolbox/core/extension/listx.dart';
import 'package:toolbox/core/persistant_store.dart';

typedef Order<T> = List<T>;
Expand Down Expand Up @@ -52,7 +53,7 @@ extension OrderX<T> on Order<T> {
move(index, newIndex, property: property, onMove: onMove);
}

/// order: ['d', 'b', 'e']\
/// order: ['d', 'b', 'e']
/// this: ['a', 'b', 'c', 'd']\
/// result: ['d', 'b', 'a', 'c']\
/// return: ['e']
Expand All @@ -64,11 +65,11 @@ extension OrderX<T> on Order<T> {
final missed = <T>[];
final surplus = <String>[];
for (final id in order.toSet()) {
try {
final item = firstWhere((e) => finder(e, id));
newOrder.add(item);
} catch (e) {
final item = firstWhereOrNull((element) => finder(element, id));
if (item == null) {
surplus.add(id);
} else {
newOrder.add(item);
}
}
for (final item in this) {
Expand Down
7 changes: 7 additions & 0 deletions lib/core/extension/widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter/material.dart';

extension WidgetX on Widget {
Widget get card {
return Card(child: this);
}
}
5 changes: 5 additions & 0 deletions lib/core/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:toolbox/view/page/iperf.dart';
import 'package:toolbox/view/page/ping.dart';
import 'package:toolbox/view/page/private_key/edit.dart';
import 'package:toolbox/view/page/private_key/list.dart';
import 'package:toolbox/view/page/pve.dart';
import 'package:toolbox/view/page/server/detail.dart';
import 'package:toolbox/view/page/setting/platform/android.dart';
import 'package:toolbox/view/page/setting/platform/ios.dart';
Expand Down Expand Up @@ -227,4 +228,8 @@ class AppRoute {
static AppRoute serverFuncBtnsOrder({Key? key}) {
return AppRoute(ServerFuncBtnsOrderPage(key: key), 'server_func_btns_seq');
}

static AppRoute pve({Key? key, required ServerPrivateInfo spi}) {
return AppRoute(PvePage(key: key, spi: spi), 'pve');
}
}
4 changes: 4 additions & 0 deletions lib/data/model/app/menu/server_func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum ServerFuncBtn {
snippet,
@HiveField(6)
iperf,
@HiveField(7)
pve,
;

IconData get icon => switch (this) {
Expand All @@ -30,6 +32,7 @@ enum ServerFuncBtn {
process => Icons.list_alt_outlined,
terminal => Icons.terminal,
iperf => Icons.speed,
pve => Icons.computer,
};

String get toStr => switch (this) {
Expand All @@ -40,6 +43,7 @@ enum ServerFuncBtn {
process => l10n.process,
terminal => l10n.terminal,
iperf => 'iperf',
pve => 'PVE',
};

int toJson() => index;
Expand Down
5 changes: 5 additions & 0 deletions lib/data/model/app/menu/server_func.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions lib/data/model/server/custom.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:hive_flutter/adapters.dart';

part 'custom.g.dart';

@HiveType(typeId: 7)
final class ServerCustom {
@HiveField(0)
final String? temperature;
@HiveField(1)
final String? pveAddr;

const ServerCustom({
this.temperature,
this.pveAddr,
});

static ServerCustom fromJson(Map<String, dynamic> json) {
final temperature = json["temperature"] as String?;
final pveAddr = json["pveAddr"] as String?;
return ServerCustom(
temperature: temperature,
pveAddr: pveAddr,
);
}

Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (temperature != null) {
json["temperature"] = temperature;
}
if (pveAddr != null) {
json["pveAddr"] = pveAddr;
}
return json;
}
}
44 changes: 44 additions & 0 deletions lib/data/model/server/custom.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26264ec

Please sign in to comment.