Skip to content

Commit

Permalink
Support look mongo table
Browse files Browse the repository at this point in the history
  • Loading branch information
goflutterjava committed Jan 10, 2022
1 parent 727cbf1 commit 70fce26
Show file tree
Hide file tree
Showing 25 changed files with 704 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/api/mongo/mongo_databases_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:mongo_dart/mongo_dart.dart';
import 'package:paas_dashboard_flutter/module/mongo/mongo_database.dart';

class MongoDatabaseApi {
static Future<List<DatabaseResp>> getDatabaseList(
String addr, String username, String password) async {
var db = await Db.create(addr);
await db.open();
var databases = await db.listDatabases();
return databases.map((name) => new DatabaseResp(name)).toList();
}
}
14 changes: 14 additions & 0 deletions lib/api/mongo/mongo_tables_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:mongo_dart/mongo_dart.dart';
import 'package:paas_dashboard_flutter/module/mongo/mongo_table.dart';

class MongoTablesApi {
static Future<List<TableResp>> getTableList(String addr, String username,
String password, String databaseName) async {
var db = await Db.create(addr + "/" + databaseName);
await db.open();
var collectionNames = await db.getCollectionNames();
return collectionNames.whereType<String>().map((name) {
return new TableResp(name);
}).toList();
}
}
1 change: 1 addition & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand Down
10 changes: 10 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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/mongo/mongo_database_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_instance_list_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_instance_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mysql/mysql_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';
Expand Down Expand Up @@ -85,6 +87,14 @@ class MyApp extends StatelessWidget {
),
},
onGenerateRoute: (settings) {
if (settings.name == PageRouteConst.MongoInstance) {
final args = settings.arguments as MongoInstanceViewModel;
return RouteGen.mongoInstance(args);
}
if (settings.name == PageRouteConst.MongoDatabase) {
final args = settings.arguments as MongoDatabaseViewModel;
return RouteGen.mongoDatabase(args);
}
if (settings.name == PageRouteConst.PulsarInstance) {
final args = settings.arguments as PulsarInstanceViewModel;
return RouteGen.pulsarInstance(args);
Expand Down
14 changes: 14 additions & 0 deletions lib/module/mongo/mongo_database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class DatabaseResp {
final String databaseName;

DatabaseResp(this.databaseName);

DatabaseResp deepCopy() {
return new DatabaseResp(this.databaseName);
}

@override
String toString() {
return 'DatabaseResp{databaseName: $databaseName}';
}
}
14 changes: 14 additions & 0 deletions lib/module/mongo/mongo_table.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class TableResp {
final String tableName;

TableResp(this.tableName);

TableResp deepCopy() {
return new TableResp(this.tableName);
}

@override
String toString() {
return 'TableResp{tableName: $tableName}';
}
}
7 changes: 7 additions & 0 deletions lib/persistent/po/mongo_instance_po.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ class MongoInstancePo {

MongoInstancePo(this.id, this.name, this.addr, this.username, this.password);

MongoInstancePo deepCopy() {
return new MongoInstancePo(id, name, addr, username, password);
}

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

Expand Down
4 changes: 4 additions & 0 deletions lib/persistent/po/mysql_instance_po.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class MysqlInstancePo {
return {
'id': id,
'name': name,
'host': host,
'port': port,
'username': username,
'password': password,
};
}

Expand Down
2 changes: 2 additions & 0 deletions lib/route/page_route_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class PageRouteConst {
static const String Bookkeeper = '/bookkeeper';
static const String Kubernetes = '/kubernetes';
static const String Mongo = '/mongo';
static const String MongoInstance = '/mongo/instance';
static const String MongoDatabase = '/mongo/instance/database';
static const String Mysql = '/mysql';
static const String Pulsar = '/pulsar';
static const String PulsarInstance = '/pulsar/instance';
Expand Down
22 changes: 22 additions & 0 deletions lib/route/route_gen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/ui/mongo/mongo_instance.dart';
import 'package:paas_dashboard_flutter/ui/mongo/screen/mongo_database.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_instance.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_namespace.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_partitioned_topic.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_sink.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_source.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_tenant.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/screen/pulsar_topic.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_database_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_instance_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';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_partitioned_topic_view_model.dart';
Expand All @@ -16,6 +20,24 @@ import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_topic_view_model.dart';
import 'package:provider/provider.dart';

class RouteGen {
static Route mongoInstance(MongoInstanceViewModel viewModel) {
// deep copy view model
return MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (context) => viewModel,
child: MongoInstanceScreen(),
));
}

static Route mongoDatabase(MongoDatabaseViewModel viewModel) {
// deep copy view model
return MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (context) => viewModel,
child: MongoDatabaseScreen(),
));
}

static Route pulsarInstance(PulsarInstanceViewModel viewModel) {
// deep copy view model
return MaterialPageRoute(
Expand Down
47 changes: 47 additions & 0 deletions lib/ui/mongo/mongo_instance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/ui/mongo/widget/mongo_database_list.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_database_list_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_instance_view_model.dart';
import 'package:provider/provider.dart';

class MongoInstanceScreen extends StatefulWidget {
MongoInstanceScreen();

@override
State<StatefulWidget> createState() {
return new _MongoInstanceState();
}
}

class _MongoInstanceState extends State<MongoInstanceScreen> {
_MongoInstanceState();

@override
Widget build(BuildContext context) {
final vm = Provider.of<MongoInstanceViewModel>(context);
return DefaultTabController(
length: 1,
child: Scaffold(
appBar: AppBar(
title: Text('Mongo ${vm.name} Dashboard'),
bottom: TabBar(
tabs: [
Tab(
text: "Databases",
),
],
),
),
body: TabBarView(
children: [
ChangeNotifierProvider(
create: (context) =>
MongoDatabaseListViewModel(vm.mongoInstancePo.deepCopy()),
child: MongoDatabaseListWidget(),
).build(context),
],
),
),
);
}
}
20 changes: 13 additions & 7 deletions lib/ui/mongo/mongo_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/generated/l10n.dart';
import 'package:paas_dashboard_flutter/route/page_route_const.dart';
import 'package:paas_dashboard_flutter/ui/util/form_util.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_instance_list_view_model.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -53,13 +54,18 @@ class _MongoPageState extends State<MongoPage> {
DataColumn(label: Text('Username')),
],
rows: vm.instances
.map((itemRow) =>
DataRow(onSelectChanged: (bool? selected) {}, cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
DataCell(Text(itemRow.addr)),
DataCell(Text(itemRow.username)),
]))
.map((itemRow) => DataRow(
onSelectChanged: (bool? selected) {
Navigator.pushNamed(
context, PageRouteConst.MongoInstance,
arguments: itemRow.deepCopy());
},
cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
DataCell(Text(itemRow.addr)),
DataCell(Text(itemRow.username)),
]))
.toList(),
),
),
Expand Down
53 changes: 53 additions & 0 deletions lib/ui/mongo/screen/mongo_database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:paas_dashboard_flutter/ui/mongo/widget/mongo_table_list.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_database_view_model.dart';
import 'package:paas_dashboard_flutter/vm/mongo/mongo_table_list_view_model.dart';
import 'package:provider/provider.dart';

class MongoDatabaseScreen extends StatefulWidget {
MongoDatabaseScreen();

@override
State<StatefulWidget> createState() {
return new MongoDatabaseScreenState();
}
}

class MongoDatabaseScreenState extends State<MongoDatabaseScreen> {
@override
void initState() {
super.initState();
}

@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
final vm = Provider.of<MongoDatabaseViewModel>(context);
return DefaultTabController(
length: 1,
child: Scaffold(
appBar: AppBar(
title: Text('Mongo ${vm.name} -> ${vm.databaseName}'),
bottom: TabBar(
tabs: [
Tab(text: "Tables"),
],
),
),
body: TabBarView(
children: [
ChangeNotifierProvider(
create: (context) =>
MongoTableListViewModel(vm.mongoInstancePo, vm.databaseResp),
child: MongoTableListWidget(),
).build(context),
],
),
),
);
}
}
Loading

0 comments on commit 70fce26

Please sign in to comment.