Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mysql instances page #25

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/api/mysql/mysql_databases_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:paas_dashboard_flutter/module/mysql/mysql_database.dart';

class MysqlDatabaseApi {
static Future<List<DatabaseResp>> getDatabaseList(
String host, int port, String username, String password) async {
throw UnimplementedError();
}
}
8 changes: 8 additions & 0 deletions lib/api/mysql/mysql_tables_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:paas_dashboard_flutter/module/mysql/mysql_table.dart';

class MysqlTablesApi {
static Future<List<TableResp>> getTableList(String host, int port,
String username, String password, String databaseName) async {
throw UnimplementedError();
}
}
7 changes: 7 additions & 0 deletions lib/module/mysql/const.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MysqlConst {
static const String infoDb = "information_schema";
static const String defaultHost = "localhost";
static const int defaultPort = 3306;
static const String defaultUsername = "hzj";
static const String defaultPassword = "Mysql@123";
}
14 changes: 14 additions & 0 deletions lib/module/mysql/mysql_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/mysql/mysql_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}';
}
}
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 @@ -9,6 +9,10 @@ class MysqlInstancePo {
MysqlInstancePo(
this.id, this.name, this.host, this.port, this.username, this.password);

MysqlInstancePo deepCopy() {
return new MysqlInstancePo(id, name, host, port, username, password);
}

Map<String, dynamic> toMap() {
return {
'id': id,
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 @@ -8,6 +8,8 @@ class PageRouteConst {
static const String MongoInstance = '/mongo/instance';
static const String MongoDatabase = '/mongo/instance/database';
static const String Mysql = '/mysql';
static const String MysqlInstance = '/mysql/instance';
static const String MysqlDatabase = '/mysql/instance/database';
static const String Pulsar = '/pulsar';
static const String PulsarInstance = '/pulsar/instance';
static const String PulsarTenant = '/pulsar/instance/tenant';
Expand Down
30 changes: 18 additions & 12 deletions lib/ui/mysql/mysql_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/mysql/mysql_instance_list_view_model.dart';
import 'package:provider/provider.dart';
Expand All @@ -16,7 +17,7 @@ class _MysqlPageState extends State<MysqlPage> {
void initState() {
super.initState();
Provider.of<MysqlInstanceListViewModel>(context, listen: false)
.fetchMongoInstances();
.fetchMysqlInstances();
}

@override
Expand All @@ -26,7 +27,7 @@ class _MysqlPageState extends State<MysqlPage> {
var refreshButton = TextButton(
onPressed: () {
setState(() {
vm.fetchMongoInstances();
vm.fetchMysqlInstances();
});
},
child: Text(S.of(context).refresh));
Expand All @@ -41,7 +42,7 @@ class _MysqlPageState extends State<MysqlPage> {
),
),
Center(
child: Text('Mongo Instance List'),
child: Text('Mysql Instance List'),
),
SingleChildScrollView(
child: DataTable(
Expand All @@ -54,22 +55,27 @@ class _MysqlPageState extends State<MysqlPage> {
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.host)),
DataCell(Text(itemRow.port.toString())),
DataCell(Text(itemRow.username)),
]))
.map((itemRow) => DataRow(
onSelectChanged: (bool? selected) {
Navigator.pushNamed(
context, PageRouteConst.MysqlInstance,
arguments: itemRow.deepCopy());
},
cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
DataCell(Text(itemRow.host)),
DataCell(Text(itemRow.port.toString())),
DataCell(Text(itemRow.username)),
]))
.toList(),
),
),
],
);
return Scaffold(
appBar: AppBar(
title: Text('Mongo Dashboard'),
title: Text('Mysql Dashboard'),
),
body: body);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/vm/mysql/mysql_instance_list_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:paas_dashboard_flutter/vm/mysql/mysql_instance_view_model.dart';
class MysqlInstanceListViewModel extends ChangeNotifier {
List<MysqlInstanceViewModel> instances = <MysqlInstanceViewModel>[];

Future<void> fetchMongoInstances() async {
Future<void> fetchMysqlInstances() async {
final results = await Persistent.mysqlInstances();
this.instances = results.map((e) => MysqlInstanceViewModel(e)).toList();
notifyListeners();
Expand All @@ -14,11 +14,11 @@ class MysqlInstanceListViewModel extends ChangeNotifier {
Future<void> createMysql(String name, String host, int port, String username,
String password) async {
Persistent.saveMysql(name, host, port, username, password);
fetchMongoInstances();
fetchMysqlInstances();
}

Future<void> deleteMysql(int id) async {
Persistent.deleteMysql(id);
fetchMongoInstances();
fetchMysqlInstances();
}
}
4 changes: 4 additions & 0 deletions lib/vm/mysql/mysql_instance_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class MysqlInstanceViewModel {

MysqlInstanceViewModel(this.mysqlInstancePo);

MysqlInstanceViewModel deepCopy() {
return new MysqlInstanceViewModel(mysqlInstancePo.deepCopy());
}

int get id {
return this.mysqlInstancePo.id;
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
mysql1:
dependency: "direct main"
description:
name: mysql1
url: "https://pub.dartlang.org"
source: hosted
version: "0.19.2"
nested:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
mongo_dart: ^0.7.4
mysql1: ^0.19.2
http: ^0.13.3
clipboard:
provider: ^6.0.1
Expand Down
14 changes: 14 additions & 0 deletions test/api/mysql/mysql_databases_api_query_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:paas_dashboard_flutter/api/mysql/mysql_databases_api.dart';
import 'package:paas_dashboard_flutter/module/mysql/const.dart';

void main() {
test("test_query_databases", () async {
var list = await MysqlDatabaseApi.getDatabaseList(
MysqlConst.defaultHost,
MysqlConst.defaultPort,
MysqlConst.defaultUsername,
MysqlConst.defaultPassword);
print(list);
});
}
15 changes: 15 additions & 0 deletions test/api/mysql/mysql_tables_api_query_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:paas_dashboard_flutter/api/mysql/mysql_tables_api.dart';
import 'package:paas_dashboard_flutter/module/mysql/const.dart';

void main() {
test("test_query_tables", () async {
var list = await MysqlTablesApi.getTableList(
MysqlConst.defaultHost,
MysqlConst.defaultPort,
MysqlConst.defaultUsername,
MysqlConst.defaultPassword,
MysqlConst.infoDb);
print(list);
});
}