Skip to content

Commit

Permalink
Add sql list page
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehzj committed Jan 11, 2022
1 parent 72e2705 commit 3e4a6f4
Show file tree
Hide file tree
Showing 20 changed files with 283 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// 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 Expand Up @@ -57,6 +56,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchByTopic": MessageLookupByLibrary.simpleMessage("Search by Topic Name"),
"second": MessageLookupByLibrary.simpleMessage("second"),
"settings": MessageLookupByLibrary.simpleMessage("Settings"),
"sqlQuery": MessageLookupByLibrary.simpleMessage("sql query"),
"submit": MessageLookupByLibrary.simpleMessage("Submit"),
"subscription": MessageLookupByLibrary.simpleMessage("subscription"),
"subscriptionList": MessageLookupByLibrary.simpleMessage("Subscription list"),
Expand Down
2 changes: 1 addition & 1 deletion lib/generated/intl/messages_zh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// 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 Expand Up @@ -57,6 +56,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchByTopic": MessageLookupByLibrary.simpleMessage("按 Topic 名称搜索"),
"second": MessageLookupByLibrary.simpleMessage("秒"),
"settings": MessageLookupByLibrary.simpleMessage("设置"),
"sqlQuery": MessageLookupByLibrary.simpleMessage("sql 查询"),
"submit": MessageLookupByLibrary.simpleMessage("提交"),
"subscription": MessageLookupByLibrary.simpleMessage("订阅"),
"subscriptionList": MessageLookupByLibrary.simpleMessage("订阅列表"),
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

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

1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"subscription": "subscription",
"subscriptionList": "Subscription list",
"subscriptionName": "Subscription Name",
"sqlQuery": "sql query",
"tenant": "tenant",
"tenantName": "Tenant Name",
"tenants": "Tenants",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"subscription": "订阅",
"subscriptionList": "订阅列表",
"subscriptionName": "订阅名称",
"sqlQuery": "sql 查询",
"tenant": "租户",
"tenantName": "租户名称",
"tenants": "租户列表",
Expand Down
14 changes: 10 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:paas_dashboard_flutter/ui/kubernetes/k8s_page.dart';
import 'package:paas_dashboard_flutter/ui/mongo/mongo_page.dart';
import 'package:paas_dashboard_flutter/ui/mysql/mysql_page.dart';
import 'package:paas_dashboard_flutter/ui/pulsar/pulsar_page.dart';
import 'package:paas_dashboard_flutter/ui/sql/sql_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';
Expand All @@ -26,6 +27,7 @@ import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_sink_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_source_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_tenant_view_model.dart';
import 'package:paas_dashboard_flutter/vm/pulsar/pulsar_topic_view_model.dart';
import 'package:paas_dashboard_flutter/vm/sql/sql_list_view_model.dart';
import 'package:provider/provider.dart';

void main() {
Expand Down Expand Up @@ -61,10 +63,6 @@ class MyApp extends StatelessWidget {
routes: {
PageRouteConst.Root: (context) => HomePage(),
PageRouteConst.Author: (context) => AuthorScreen(),
PageRouteConst.Settings: (context) => ChangeNotifierProvider(
create: (context) => SettingsViewModel(),
child: SettingsScreen(),
),
PageRouteConst.Bookkeeper: (context) => ChangeNotifierProvider(
create: (context) => BkInstanceListViewModel(),
child: BkPage(),
Expand All @@ -85,6 +83,14 @@ class MyApp extends StatelessWidget {
create: (context) => PulsarInstanceListViewModel(),
child: PulsarPage(),
),
PageRouteConst.Settings: (context) => ChangeNotifierProvider(
create: (context) => SettingsViewModel(),
child: SettingsScreen(),
),
PageRouteConst.Sql: (context) => ChangeNotifierProvider(
create: (context) => SqlListViewModel(),
child: SqlPage(),
),
},
onGenerateRoute: (settings) {
if (settings.name == PageRouteConst.MongoInstance) {
Expand Down
13 changes: 13 additions & 0 deletions lib/persistent/persistent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mongo_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mysql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart';

class Persistent {
static PersistentApi? api;
Expand Down Expand Up @@ -83,6 +84,18 @@ class Persistent {
return (await getApi()).mysqlInstances();
}

static Future<void> saveSql(String name, String sql) async {
return (await getApi()).saveSql(name, sql);
}

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

static Future<List<SqlPo>> sqlList() async {
return (await getApi()).sqlList();
}

static bool supportDb() {
return !kIsWeb;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/persistent/persistent_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mongo_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mysql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart';

abstract class PersistentApi {
Expand Down Expand Up @@ -42,4 +43,10 @@ abstract class PersistentApi {
Future<void> deleteMysql(int id);

Future<List<MysqlInstancePo>> mysqlInstances();

Future<void> saveSql(String name, String sql);

Future<void> deleteSql(int id);

Future<List<SqlPo>> sqlList();
}
39 changes: 33 additions & 6 deletions lib/persistent/persistent_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mongo_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mysql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
Expand Down Expand Up @@ -94,6 +95,9 @@ class PersistentDb implements PersistentApi {
await db.execute(
'INSERT INTO mysql_instances(name, host, port, username, password) VALUES ("example", "${MysqlConst.defaultHost}", ${MysqlConst.defaultPort}, "${MysqlConst.defaultUsername}", "${MysqlConst.defaultPassword}")',
);
await db.execute(
'CREATE TABLE sql_list(id INTEGER PRIMARY KEY, name TEXT, sql TEXT)',
);
}

@override
Expand Down Expand Up @@ -186,9 +190,9 @@ class PersistentDb implements PersistentApi {
}

@override
Future<void> deleteMongo(int id) {
// TODO: implement deleteMongo
throw UnimplementedError();
Future<void> deleteMongo(int id) async {
var aux = await getInstance();
aux.database.delete('mongo_instances', where: 'id = ?', whereArgs: [id]);
}

@override
Expand All @@ -209,9 +213,9 @@ class PersistentDb implements PersistentApi {
}

@override
Future<void> deleteMysql(int id) {
// TODO: implement deleteMysql
throw UnimplementedError();
Future<void> deleteMysql(int id) async {
var aux = await getInstance();
aux.database.delete('mysql_instances', where: 'id = ?', whereArgs: [id]);
}

@override
Expand All @@ -231,4 +235,27 @@ class PersistentDb implements PersistentApi {
aux.database
.execute('INSERT INTO mysql_instances(name, host, port, username, password) VALUES (?, ?, ?, ?, ?)', list);
}

@override
Future<void> deleteSql(int id) async {
var aux = await getInstance();
aux.database.delete('sql_list', where: 'id = ?', whereArgs: [id]);
}

@override
Future<void> saveSql(String name, String sql) async {
var aux = await getInstance();
var list = [name, sql];
aux.database.execute('INSERT INTO sql_list(name, sql) VALUES (?, ?)', list);
}

@override
Future<List<SqlPo>> sqlList() async {
var aux = await getInstance();
final List<Map<String, dynamic>> maps = await aux.database.query('sql_list');
return List.generate(maps.length, (i) {
var aux = maps[i];
return SqlPo(aux['id'], aux['name'], aux['sql']);
});
}
}
19 changes: 19 additions & 0 deletions lib/persistent/persistent_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:paas_dashboard_flutter/persistent/po/k8s_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mongo_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/mysql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/pulsar_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/sql_instance_po.dart';
import 'package:paas_dashboard_flutter/persistent/po/zk_instance_po.dart';

class PersistentMemory implements PersistentApi {
Expand Down Expand Up @@ -118,4 +119,22 @@ class PersistentMemory implements PersistentApi {
// TODO: implement saveMysql
throw UnimplementedError();
}

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

@override
Future<void> saveSql(String name, String sql) {
// TODO: implement saveSql
throw UnimplementedError();
}

@override
Future<List<SqlPo>> sqlList() {
// TODO: implement sqlList
throw UnimplementedError();
}
}
19 changes: 19 additions & 0 deletions lib/persistent/po/sql_instance_po.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SqlPo {
final int id;
final String name;
final String sql;

SqlPo(this.id, this.name, this.sql);

SqlPo deepCopy() {
return new SqlPo(id, name, sql);
}

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'sql': sql,
};
}
}
4 changes: 3 additions & 1 deletion lib/route/page_route_const.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class PageRouteConst {
static const String Root = '/';
static const String Author = '/author';
static const String Settings = '/settings';
static const String Bookkeeper = '/bookkeeper';
static const String Kubernetes = '/kubernetes';
static const String Mongo = '/mongo';
Expand All @@ -18,4 +17,7 @@ class PageRouteConst {
static const String PulsarTopic = '/pulsar/instance/tenant/namespace/topic';
static const String PulsarSource = '/pulsar/instance/tenant/namespace/source';
static const String PulsarSink = '/pulsar/instance/tenant/namespace/sink';
static const String Settings = '/settings';
static const String Sql = '/sql';
static const String SqlInstance = '/sql/instance';
}
4 changes: 4 additions & 0 deletions lib/ui/home/home_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class NavDrawer extends StatelessWidget {
image: DecorationImage(
fit: BoxFit.fill, image: AssetImage('assets/images/background/joy_valley_slide.png'))),
),
ListTile(
title: Text(S.of(context).sqlQuery),
onTap: () => {Navigator.of(context).pushNamed(PageRouteConst.Sql)},
),
ListTile(
title: Text(S.of(context).aboutAuthor),
onTap: () => {Navigator.of(context).pushNamed(PageRouteConst.Author)},
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/kubernetes/k8s_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/ui/util/data_cell_util.dart';
import 'package:paas_dashboard_flutter/vm/kubernetes/k8s_instance_list_view_model.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -46,11 +47,15 @@ class _K8sPageState extends State<K8sPage> {
columns: [
DataColumn(label: Text('Id')),
DataColumn(label: Text('Name')),
DataColumn(label: Text('Delete instance')),
],
rows: vm.instances
.map((itemRow) => DataRow(onSelectChanged: (bool? selected) {}, cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
DataCellUtil.newDellDataCell(() {
vm.deleteKubernetes(itemRow.id);
}),
]))
.toList(),
),
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/mongo/mongo_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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/data_cell_util.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 @@ -51,6 +52,7 @@ class _MongoPageState extends State<MongoPage> {
DataColumn(label: Text('Name')),
DataColumn(label: Text('Addr')),
DataColumn(label: Text('Username')),
DataColumn(label: Text('Delete instance')),
],
rows: vm.instances
.map((itemRow) => DataRow(
Expand All @@ -62,6 +64,9 @@ class _MongoPageState extends State<MongoPage> {
DataCell(Text(itemRow.name)),
DataCell(Text(itemRow.addr)),
DataCell(Text(itemRow.username)),
DataCellUtil.newDellDataCell(() {
vm.deleteMongo(itemRow.id);
}),
]))
.toList(),
),
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/mysql/mysql_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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/data_cell_util.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 Down Expand Up @@ -52,6 +53,7 @@ class _MysqlPageState extends State<MysqlPage> {
DataColumn(label: Text('Host')),
DataColumn(label: Text('Port')),
DataColumn(label: Text('Username')),
DataColumn(label: Text('Delete instance')),
],
rows: vm.instances
.map((itemRow) => DataRow(
Expand All @@ -64,6 +66,9 @@ class _MysqlPageState extends State<MysqlPage> {
DataCell(Text(itemRow.host)),
DataCell(Text(itemRow.port.toString())),
DataCell(Text(itemRow.username)),
DataCellUtil.newDellDataCell(() {
vm.deleteMysql(itemRow.id);
}),
]))
.toList(),
),
Expand Down
Loading

0 comments on commit 3e4a6f4

Please sign in to comment.