Skip to content

Commit

Permalink
Owner References
Browse files Browse the repository at this point in the history
1. add len params to custom copyTileValue.
2. add modal window to show ownerReferences detail.
3. add ownerReferences info to metadata section of detail page.

Signed-off-by: 疯魔慕薇 <[email protected]>
  • Loading branch information
kofj committed May 25, 2024
1 parent 01e78f6 commit 060c1b4
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MessageLookup extends MessageLookupByLibrary {
"age": MessageLookupByLibrary.simpleMessage("Age"),
"all": MessageLookupByLibrary.simpleMessage("All"),
"annotations": MessageLookupByLibrary.simpleMessage("Annotations"),
"apiVersion": MessageLookupByLibrary.simpleMessage("apiVersion"),
"api_request_duration": m0,
"api_timeout": MessageLookupByLibrary.simpleMessage("API Timeout"),
"appName": MessageLookupByLibrary.simpleMessage("k8z"),
Expand All @@ -136,6 +137,8 @@ class MessageLookup extends MessageLookupByLibrary {
"apply": MessageLookupByLibrary.simpleMessage("Apply"),
"args": MessageLookupByLibrary.simpleMessage("Arguments"),
"arsure": MessageLookupByLibrary.simpleMessage("are your sure?"),
"blockOwnerDeletion":
MessageLookupByLibrary.simpleMessage("blockOwnerDeletion"),
"cancel": MessageLookupByLibrary.simpleMessage("Cancel"),
"clusters": MessageLookupByLibrary.simpleMessage("Clusters"),
"command": MessageLookupByLibrary.simpleMessage("Command"),
Expand All @@ -146,6 +149,7 @@ class MessageLookup extends MessageLookupByLibrary {
"container_id": MessageLookupByLibrary.simpleMessage("Container ID"),
"container_runtime": m2,
"containers": MessageLookupByLibrary.simpleMessage("Containers"),
"controller": MessageLookupByLibrary.simpleMessage("controller"),
"cpu": MessageLookupByLibrary.simpleMessage("CPU"),
"crds":
MessageLookupByLibrary.simpleMessage("CustomResourceDefinition"),
Expand Down Expand Up @@ -215,6 +219,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Init Containers"),
"internel_ip": m13,
"items_number": m14,
"kind": MessageLookupByLibrary.simpleMessage("kind"),
"labels": MessageLookupByLibrary.simpleMessage("Labels"),
"last_warning_events": m15,
"livenessProbe": MessageLookupByLibrary.simpleMessage("Liveness Probe"),
Expand Down Expand Up @@ -245,6 +250,7 @@ class MessageLookup extends MessageLookupByLibrary {
"A node may be a virtual or physical machine."),
"ok": MessageLookupByLibrary.simpleMessage("ok"),
"overview": MessageLookupByLibrary.simpleMessage("Overview"),
"owner": MessageLookupByLibrary.simpleMessage("Owner"),
"pod_text": m23,
"pods": MessageLookupByLibrary.simpleMessage("Pods"),
"ports": MessageLookupByLibrary.simpleMessage("Ports"),
Expand Down
5 changes: 5 additions & 0 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class MessageLookup extends MessageLookupByLibrary {
"age": MessageLookupByLibrary.simpleMessage("年龄"),
"all": MessageLookupByLibrary.simpleMessage("全部"),
"annotations": MessageLookupByLibrary.simpleMessage("注解"),
"apiVersion": MessageLookupByLibrary.simpleMessage("API版本"),
"api_request_duration": m0,
"api_timeout": MessageLookupByLibrary.simpleMessage("API 超时"),
"appName": MessageLookupByLibrary.simpleMessage("k8z"),
Expand All @@ -135,6 +136,7 @@ class MessageLookup extends MessageLookupByLibrary {
"apply": MessageLookupByLibrary.simpleMessage("应用"),
"args": MessageLookupByLibrary.simpleMessage("参数"),
"arsure": MessageLookupByLibrary.simpleMessage("你确认吗?"),
"blockOwnerDeletion": MessageLookupByLibrary.simpleMessage("阻塞属主删除"),
"cancel": MessageLookupByLibrary.simpleMessage("取消"),
"clusters": MessageLookupByLibrary.simpleMessage("集群"),
"command": MessageLookupByLibrary.simpleMessage("命令"),
Expand All @@ -145,6 +147,7 @@ class MessageLookup extends MessageLookupByLibrary {
"container_id": MessageLookupByLibrary.simpleMessage("容器 ID"),
"container_runtime": m2,
"containers": MessageLookupByLibrary.simpleMessage("容器"),
"controller": MessageLookupByLibrary.simpleMessage("控制器"),
"cpu": MessageLookupByLibrary.simpleMessage("CPU"),
"crds": MessageLookupByLibrary.simpleMessage("自定资源定义"),
"crds_text": m3,
Expand Down Expand Up @@ -204,6 +207,7 @@ class MessageLookup extends MessageLookupByLibrary {
"initContainers": MessageLookupByLibrary.simpleMessage("初始容器"),
"internel_ip": m13,
"items_number": m14,
"kind": MessageLookupByLibrary.simpleMessage("种类"),
"labels": MessageLookupByLibrary.simpleMessage("标签"),
"last_warning_events": m15,
"livenessProbe": MessageLookupByLibrary.simpleMessage("存活探针"),
Expand Down Expand Up @@ -231,6 +235,7 @@ class MessageLookup extends MessageLookupByLibrary {
"nodes_desc": MessageLookupByLibrary.simpleMessage("节点可以是虚拟机或物理机。"),
"ok": MessageLookupByLibrary.simpleMessage("好的"),
"overview": MessageLookupByLibrary.simpleMessage("概览"),
"owner": MessageLookupByLibrary.simpleMessage("属主"),
"pod_text": m23,
"pods": MessageLookupByLibrary.simpleMessage("Pods"),
"ports": MessageLookupByLibrary.simpleMessage("端口"),
Expand Down
50 changes: 50 additions & 0 deletions lib/generated/l10n.dart

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

12 changes: 11 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,15 @@
"ready": {},
"available": {}
}
}
},
"owner": "Owner",
"@owner": {},
"apiVersion": "apiVersion",
"@apiVersion": {},
"blockOwnerDeletion": "blockOwnerDeletion",
"@blockOwnerDeletion": {},
"controller": "controller",
"@controller": {},
"kind": "kind",
"@kind": {}
}
12 changes: 11 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -597,5 +597,15 @@
"ready": {},
"available": {}
}
}
},
"owner": "属主",
"@owner": {},
"apiVersion": "API版本",
"@apiVersion": {},
"blockOwnerDeletion": "阻塞属主删除",
"@blockOwnerDeletion": {},
"controller": "控制器",
"@controller": {},
"kind": "种类",
"@kind": {}
}
81 changes: 81 additions & 0 deletions lib/pages/k8s_detail/details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:k8zdev/common/const.dart';
import 'package:k8zdev/common/ops.dart';
import 'package:k8zdev/common/styles.dart';
import 'package:k8zdev/dao/kube.dart';
import 'package:k8zdev/generated/l10n.dart';
import 'package:k8zdev/models/models.dart';
Expand All @@ -18,6 +19,7 @@ import 'package:k8zdev/widgets/detail_widgets/secret.dart';
import 'package:k8zdev/widgets/get_logstream.dart';
import 'package:k8zdev/widgets/get_terminal.dart';
import 'package:k8zdev/widgets/modal.dart';
import 'package:k8zdev/widgets/tiles.dart';
import 'package:k8zdev/widgets/widgets.dart';
import 'package:kubeconfig/kubeconfig.dart';
import 'package:numberpicker/numberpicker.dart';
Expand Down Expand Up @@ -400,6 +402,8 @@ class _ResourceDetailsPageState extends State<ResourceDetailsPage> {
}).toList();
annotations.sort((a, b) => a.length.compareTo(b.length));

final ownerReferences = metadata.ownerReferences;

return SettingsSection(
title: Text(lang.metadata),
tiles: [
Expand All @@ -421,6 +425,83 @@ class _ResourceDetailsPageState extends State<ResourceDetailsPage> {
leading: leadingText(lang.namespace, langCode),
title: Text(metadata.namespace ?? ""),
),
if (ownerReferences.isNotEmpty)
SettingsTile.navigation(
title: Text(
"${ownerReferences.first.kind}/${ownerReferences.first.name}"),
leading: leadingText(lang.owner, langCode),
value: Text(
"${ownerReferences.length}",
style: tileValueStyle,
),
onPressed: (context) {
List<AbstractSettingsSection> ownerSections = [];
ownerReferences.forEach((owner) {
List<AbstractSettingsTile> ownerTiles = [];
ownerTiles.add(
copyTileValue(
lang.apiVersion,
owner.apiVersion,
langCode,
enLen: 82.0,
),
);
ownerTiles.add(
copyTileValue(
lang.blockOwnerDeletion,
"${owner.blockOwnerDeletion}",
langCode,
zhLen: 52.0,
enLen: 82.0,
),
);
ownerTiles.add(
copyTileValue(
lang.controller,
"${owner.controller}",
langCode,
zhLen: 52.0,
enLen: 82.0,
),
);
ownerTiles.add(
copyTileValue(
lang.kind,
owner.kind,
langCode,
),
);
ownerTiles.add(
copyTileValue(
lang.name,
owner.name,
langCode,
),
);
ownerTiles.add(
copyTileValue(
lang.uid,
owner.uid,
langCode,
),
);
ownerSections.add(
SettingsSection(
margin: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 10),
title: Text(owner.name),
tiles: ownerTiles,
),
);
});
showModal(
context,
SettingsList(
sections: ownerSections,
contentPadding: EdgeInsets.zero,
),
);
},
),
if (metadata.generation != null)
SettingsTile(
leading: leadingText(lang.generation, langCode),
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ SettingsTile copyTile(String name, {String? value}) {
);
}

SettingsTile copyTileValue(String name, String value, String langCode) {
SettingsTile copyTileValue(String name, String value, String langCode,
{zhLen, enLen}) {
return SettingsTile(
leading: leadingText(name, langCode),
leading: leadingText(name, langCode, zhLen: zhLen, enLen: enLen),
title: Text(
value,
style: tileValueStyle,
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const smallProgressIndicator = SizedBox(
child: CircularProgressIndicator(),
);

Widget leadingText(String label, String langCode) {
Widget leadingText(String label, String langCode, {zhLen, enLen}) {
late double len;
switch (langCode) {
case "zh":
len = 32;
len = zhLen ?? 32.0;
default:
len = 52;
len = enLen ?? 52.0;
}
return SizedBox(
width: len,
Expand Down

0 comments on commit 060c1b4

Please sign in to comment.