Skip to content

Commit

Permalink
Support Kubernetes instance list (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj authored Dec 11, 2021
1 parent 27ae76a commit b184920
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 图标来自
[品牌图标](https://brands.iconhelper.cn/)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Flutter Paas Dashboard
## 其他语言文档
- [English Doc](README_en.md)

# 安装
- [Install Doc](install.md)

# 开发环境准备
```bash
flutter config --enable-macos-desktop
Expand Down
5 changes: 5 additions & 0 deletions install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 安装步骤
### windows
下载最新的release压缩包,[下载地址](https://github.com/paashzj/paas_dashboard_flutter/releases) <br/>
解压压缩文件 <br/>
运行**pass_dashboard_flutter.exe** 即可
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"@@locale": "en",
"aboutAuthor": "About author",
"appName": "Paas Dashboard",
"basic": "Basic",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"@@locale": "zh",
"aboutAuthor": "关于作者",
"appName": "Paas 仪表盘",
"basic": "基础信息",
Expand Down
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import 'package:paas_dashboard_flutter/ui/bk/bk_page.dart';
import 'package:paas_dashboard_flutter/ui/general/author_screen.dart';
import 'package:paas_dashboard_flutter/ui/general/settings_screen.dart';
import 'package:paas_dashboard_flutter/ui/home/home_page.dart';
import 'package:paas_dashboard_flutter/ui/kubernetes/k8s_page.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_page.dart';
import 'package:paas_dashboard_flutter/vm/bk/bk_instance_list_view_model.dart';
import 'package:paas_dashboard_flutter/vm/general/settings_view_model.dart';
import 'package:paas_dashboard_flutter/vm/kubernetes/k8s_instance_list_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_list_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_instance_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_namespace_view_model.dart';
Expand Down Expand Up @@ -61,6 +63,10 @@ class MyApp extends StatelessWidget {
create: (context) => BkInstanceListViewModel(),
child: BkPage(),
),
PageRouteConst.Kubernetes: (context) => ChangeNotifierProvider(
create: (context) => K8sInstanceListViewModel(),
child: K8sPage(),
),
PageRouteConst.Pulsar: (context) => ChangeNotifierProvider(
create: (context) => PulsarInstanceListViewModel(),
child: PulsarPage(),
Expand Down
8 changes: 8 additions & 0 deletions lib/module/ssh/ssh_step.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SshStep {
final String username;
final String password;
String? suUser;
String? suPassword;

SshStep(this.username, this.password);
}
14 changes: 14 additions & 0 deletions lib/persistent/persistent.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:paas_dashboard_flutter/module/ssh/ssh_step.dart';
import 'package:paas_dashboard_flutter/persistent/persistent_api.dart';
import 'package:paas_dashboard_flutter/persistent/persistent_db.dart';
import 'package:paas_dashboard_flutter/persistent/persistent_memory.dart';
import 'package:paas_dashboard_flutter/persistent/po/bk_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';

class Persistent {
Expand Down Expand Up @@ -44,6 +46,18 @@ class Persistent {
return (await getApi()).bookkeeperInstances();
}

static Future<void> saveKubernetesSsh(String name, List<SshStep> sshSteps) async {
return (await getApi()).saveKubernetesSsh(name, sshSteps);
}

static Future<void> deleteKubernetes(int id) async {
return (await getApi()).deleteKubernetes(id);
}

static Future<List<K8sInstancePo>> kubernetesInstances() async {
return (await getApi()).kubernetesInstances();
}

static bool supportDb() {
return !kIsWeb;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/persistent/persistent_api.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:paas_dashboard_flutter/module/ssh/ssh_step.dart';
import 'package:paas_dashboard_flutter/persistent/po/bk_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';

abstract class PersistentApi {
Expand All @@ -13,4 +15,10 @@ abstract class PersistentApi {
Future<void> deleteBookkeeper(int id);

Future<List<BkInstancePo>> bookkeeperInstances();

Future<void> saveKubernetesSsh(String name, List<SshStep> sshSteps);

Future<void> deleteKubernetes(int id);

Future<List<K8sInstancePo>> kubernetesInstances();
}
33 changes: 33 additions & 0 deletions lib/persistent/persistent_db.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:developer';
import 'dart:io';

import 'package:paas_dashboard_flutter/module/ssh/ssh_step.dart';
import 'package:paas_dashboard_flutter/persistent/persistent_api.dart';
import 'package:paas_dashboard_flutter/persistent/po/bk_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
Expand Down Expand Up @@ -59,6 +61,19 @@ class PersistentDb implements PersistentApi {
await db.execute(
'INSERT INTO bookkeeper_instances(name, host, port) VALUES ("example", "localhost", 8080)',
);
await db.execute(
'CREATE TABLE zookeeper_instances(id INTEGER PRIMARY KEY, name TEXT, host TEXT, port INTEGER)',
);
await db.execute(
'INSERT INTO zookeeper_instances(name, host, port) VALUES ("example", "localhost", 8080)',
);
// type: api、host
await db.execute(
'CREATE TABLE kubernetes_instances(id INTEGER PRIMARY KEY, name TEXT, type TEXT, content TEXT)',
);
await db.execute(
'INSERT INTO kubernetes_instances(name, type, content) VALUES ("example", "host", "{}")',
);
}

@override
Expand Down Expand Up @@ -113,4 +128,22 @@ class PersistentDb implements PersistentApi {
});
}

@override
Future<void> saveKubernetesSsh(String name, List<SshStep> sshSteps) {
// TODO: implement saveKubernetesSsh
throw UnimplementedError();
}

@override
Future<void> deleteKubernetes(int id) {
// TODO: implement deleteKubernetes
throw UnimplementedError();
}

@override
Future<List<K8sInstancePo>> kubernetesInstances() {
// TODO: implement k8sInstances
throw UnimplementedError();
}

}
19 changes: 19 additions & 0 deletions lib/persistent/persistent_memory.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:paas_dashboard_flutter/module/ssh/ssh_step.dart';
import 'package:paas_dashboard_flutter/persistent/persistent_api.dart';
import 'package:paas_dashboard_flutter/persistent/po/bk_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';

class PersistentMemory implements PersistentApi {
Expand Down Expand Up @@ -36,4 +38,21 @@ class PersistentMemory implements PersistentApi {
Future<List<BkInstancePo>> bookkeeperInstances() async {
return [new BkInstancePo(0, "example", "localhost", 8080)];
}

@override
Future<void> saveKubernetesSsh(String name, List<SshStep> sshSteps) {
// TODO: implement saveKubernetesSsh
throw UnimplementedError();
}

@override
Future<void> deleteKubernetes(int id) {
// TODO: implement deleteKubernetes
throw UnimplementedError();
}

@override
Future<List<K8sInstancePo>> kubernetesInstances() async{
return [new K8sInstancePo(0, "example")];
}
}
2 changes: 1 addition & 1 deletion lib/persistent/po/bk_instance_po.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BkInstancePo extends HttpEndpoint {

@override
String toString() {
return 'BookKeeperInstance{id: $id, name: $name, host: $host, port: port}';
return 'BookKeeperInstance{id: $id, name: $name, host: $host, port: $port}';
}

}
2 changes: 1 addition & 1 deletion lib/persistent/po/http_endpoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class HttpEndpoint {

@override
String toString() {
return 'HttpEndpoint{name: $name, host: $host, port: port}';
return 'HttpEndpoint{name: $name, host: $host, port: $port}';
}
}
19 changes: 19 additions & 0 deletions lib/persistent/po/k8s_instance_po.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

class K8sInstancePo {
final int id;
final String name;

K8sInstancePo(this.id, this.name);

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
};
}

@override
String toString() {
return 'BookKeeperInstance{id: $id, name: $name}';
}
}
1 change: 1 addition & 0 deletions lib/route/page_route_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class PageRouteConst {
static const String Author = '/author';
static const String Settings = '/settings';
static const String Bookkeeper = '/bookkeeper';
static const String Kubernetes = '/kubernetes';
static const String Pulsar = '/pulsar';
static const String PulsarInstance = '/pulsar/instance';
static const String PulsarTenant = '/pulsar/instance/tenant';
Expand Down
68 changes: 68 additions & 0 deletions lib/ui/kubernetes/k8s_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/vm/kubernetes/k8s_instance_list_view_model.dart';
import 'package:provider/provider.dart';

class K8sPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _K8sPageState();
}
}

class _K8sPageState extends State<K8sPage> {
@override
void initState() {
super.initState();
Provider.of<K8sInstanceListViewModel>(context, listen: false)
.fetchBkInstances();
}

@override
Widget build(BuildContext context) {
final vm = Provider.of<K8sInstanceListViewModel>(context);
var refreshButton = TextButton(
onPressed: () {
setState(() {
vm.fetchBkInstances();
});
},
child: Text(S.of(context).refresh));
var body = ListView(
children: [
Container(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [refreshButton],
),
),
Center(
child: Text('Kubernetes Instance List'),
),
SingleChildScrollView(
child: DataTable(
showCheckboxColumn: false,
columns: [
DataColumn(label: Text('Id')),
DataColumn(label: Text('Name')),
],
rows: vm.instances
.map((itemRow) =>
DataRow(onSelectChanged: (bool? selected) {}, cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
]))
.toList(),
),
),
],
);
return Scaffold(
appBar: AppBar(
title: Text('Kubernetes Dashboard'),
),
body: body);
}
}
25 changes: 25 additions & 0 deletions lib/vm/kubernetes/k8s_instance_list_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/persistent/persistent.dart';

import 'k8s_instance_view_model.dart';

class K8sInstanceListViewModel extends ChangeNotifier {
List<K8sInstanceViewModel> instances = <K8sInstanceViewModel>[];

Future<void> fetchBkInstances() async {
final results = await Persistent.kubernetesInstances();
this.instances = results.map((e) => K8sInstanceViewModel(e)).toList();
notifyListeners();
}

Future<void> createBk(String name, String host, int port) async {
Persistent.saveBookkeeper(name, host, port);
fetchBkInstances();
}

Future<void> deleteBk(int id) async {
Persistent.deleteBookkeeper(id);
fetchBkInstances();
}

}
15 changes: 15 additions & 0 deletions lib/vm/kubernetes/k8s_instance_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';

class K8sInstanceViewModel {
final K8sInstancePo k8sInstancePo;

K8sInstanceViewModel(this.k8sInstancePo);

int get id {
return this.k8sInstancePo.id;
}

String get name {
return this.k8sInstancePo.name;
}
}

0 comments on commit b184920

Please sign in to comment.