Revolution #1
16 changed files with 1346 additions and 641 deletions
15
.metadata
15
.metadata
|
|
@ -15,21 +15,6 @@ migration:
|
|||
- platform: root
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: android
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: ios
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: linux
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: macos
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: web
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
- platform: windows
|
||||
create_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
base_revision: 9ba0d08ebc074bf0da6dfd1fadea39f5c5566198
|
||||
|
|
|
|||
106
lib/models/db_column_definition.dart
Normal file
106
lib/models/db_column_definition.dart
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
import 'package:tuuli_api/tuuli_api.dart';
|
||||
|
||||
extension ColumnsParser on TableDefinition {
|
||||
List<DBColumnDefinition> get parsedColumns {
|
||||
return columns
|
||||
.split(",")
|
||||
.map((e) {
|
||||
final parts = e.split(":");
|
||||
final name = parts[0];
|
||||
switch (parts[1]) {
|
||||
case "serial":
|
||||
return PrimarySerialColumnDefinition(name);
|
||||
case "str":
|
||||
return TextColumnDefinition(
|
||||
name,
|
||||
parts.contains("unique"),
|
||||
parts.contains("default"),
|
||||
);
|
||||
case "bool":
|
||||
return BooleanColumnDefinition(
|
||||
name,
|
||||
parts.contains("unique"),
|
||||
parts.contains("default"),
|
||||
);
|
||||
case "datetime":
|
||||
return TimestampColumnDefinition(
|
||||
name,
|
||||
parts.contains("unique"),
|
||||
parts.contains("default"),
|
||||
);
|
||||
case "float":
|
||||
return DoubleColumnDefinition(
|
||||
name,
|
||||
parts.contains("unique"),
|
||||
parts.contains("default"),
|
||||
);
|
||||
case "int":
|
||||
return IntegerColumnDefinition(
|
||||
name,
|
||||
parts.contains("unique"),
|
||||
parts.contains("default"),
|
||||
);
|
||||
case "int-user":
|
||||
return UserRefColumnDefinition(name);
|
||||
case "int-asset":
|
||||
return AssetRefColumnDefinition(name);
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.whereType<DBColumnDefinition>()
|
||||
.toList(growable: false);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DBColumnDefinition {
|
||||
final String name;
|
||||
final bool unique;
|
||||
final bool hasDefault;
|
||||
|
||||
DBColumnDefinition({
|
||||
required this.name,
|
||||
required this.unique,
|
||||
required this.hasDefault,
|
||||
});
|
||||
}
|
||||
|
||||
class PrimarySerialColumnDefinition extends DBColumnDefinition {
|
||||
PrimarySerialColumnDefinition(String name)
|
||||
: super(name: name, unique: false, hasDefault: false);
|
||||
}
|
||||
|
||||
class TextColumnDefinition extends DBColumnDefinition {
|
||||
TextColumnDefinition(String name, bool unique, bool hasDefault)
|
||||
: super(name: name, unique: unique, hasDefault: hasDefault);
|
||||
}
|
||||
|
||||
class BooleanColumnDefinition extends DBColumnDefinition {
|
||||
BooleanColumnDefinition(String name, bool unique, bool hasDefault)
|
||||
: super(name: name, unique: unique, hasDefault: hasDefault);
|
||||
}
|
||||
|
||||
class TimestampColumnDefinition extends DBColumnDefinition {
|
||||
TimestampColumnDefinition(String name, bool unique, bool hasDefault)
|
||||
: super(name: name, unique: unique, hasDefault: hasDefault);
|
||||
}
|
||||
|
||||
class DoubleColumnDefinition extends DBColumnDefinition {
|
||||
DoubleColumnDefinition(String name, bool unique, bool hasDefault)
|
||||
: super(name: name, unique: unique, hasDefault: hasDefault);
|
||||
}
|
||||
|
||||
class IntegerColumnDefinition extends DBColumnDefinition {
|
||||
IntegerColumnDefinition(String name, bool unique, bool hasDefault)
|
||||
: super(name: name, unique: unique, hasDefault: hasDefault);
|
||||
}
|
||||
|
||||
class UserRefColumnDefinition extends DBColumnDefinition {
|
||||
UserRefColumnDefinition(String name)
|
||||
: super(name: name, unique: false, hasDefault: false);
|
||||
}
|
||||
|
||||
class AssetRefColumnDefinition extends DBColumnDefinition {
|
||||
AssetRefColumnDefinition(String name)
|
||||
: super(name: name, unique: false, hasDefault: false);
|
||||
}
|
||||
11
lib/models/group_definition.dart
Normal file
11
lib/models/group_definition.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class GroupDefinition {
|
||||
final int id;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
const GroupDefinition({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
});
|
||||
}
|
||||
13
lib/models/user_definition.dart
Normal file
13
lib/models/user_definition.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class UserDefinition {
|
||||
final int id;
|
||||
final String username;
|
||||
final String password;
|
||||
final String accessToken;
|
||||
|
||||
const UserDefinition({
|
||||
required this.id,
|
||||
required this.username,
|
||||
required this.password,
|
||||
required this.accessToken,
|
||||
});
|
||||
}
|
||||
11
lib/models/user_in_group_definition.dart
Normal file
11
lib/models/user_in_group_definition.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class UserInGroupDefinition {
|
||||
final int id;
|
||||
final int userId;
|
||||
final int groupId;
|
||||
|
||||
const UserInGroupDefinition({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.groupId,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
/*import 'package:flutter/material.dart';
|
||||
import 'package:flutter_fast_forms/flutter_fast_forms.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuuli_app/api/api_client.dart';
|
||||
|
|
@ -196,3 +196,4 @@ class _CreateTableItemBottomSheetState
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
/*import 'package:flutter/material.dart';
|
||||
import 'package:flutter_fast_forms/flutter_fast_forms.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuuli_app/api/api_client.dart';
|
||||
|
|
@ -215,3 +215,4 @@ class _CreateUserBottomSheetState extends State<CreateUserBottomSheet> {
|
|||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
/*import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
import 'package:tuuli_app/api/model/table_field_model.dart';
|
||||
|
|
@ -240,3 +240,4 @@ class _EditTableBottomSheetState extends State<EditTableBottomSheet> {
|
|||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||
/*import 'package:bottom_sheet/bottom_sheet.dart';
|
||||
import 'package:data_table_2/data_table_2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
|
@ -255,3 +255,4 @@ class _OpenTableBottomSheetState extends State<OpenTableBottomSheet> {
|
|||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -1,23 +1,17 @@
|
|||
import 'package:animated_background/animated_background.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuuli_app/api_controller.dart';
|
||||
|
||||
class CheckupPageController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<void> checkCredentials() async {
|
||||
if (ApiController.to.token.isEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ApiController.to.token = "";
|
||||
Get.offAllNamed("/login");
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
final resp =
|
||||
await ApiController.to.apiClient.listTablesApiListTablesGet();
|
||||
final resp = await ApiController.to.apiClient.listTables();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (resp.statusCode == 200) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:tuuli_app/api/api_client.dart';
|
||||
import 'package:tuuli_app/api/model/tables_list_model.dart';
|
||||
import 'package:tuuli_app/api_controller.dart';
|
||||
import 'package:tuuli_app/c.dart';
|
||||
import 'package:tuuli_app/pages/home_panels/none_panel.dart';
|
||||
import 'package:tuuli_app/pages/home_panels/settings_panel.dart';
|
||||
|
|
@ -16,35 +15,13 @@ enum PageType {
|
|||
settings,
|
||||
}
|
||||
|
||||
mixin HomePageStateRef {
|
||||
void refreshData();
|
||||
}
|
||||
class HomePageController extends GetxController {
|
||||
final _currentPage = PageType.none.obs;
|
||||
PageType get currentPage => _currentPage.value;
|
||||
set currentPage(PageType value) => _currentPage.value = value;
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
String get currentPageName => pageNames[currentPage]!;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> with HomePageStateRef {
|
||||
final apiClient = Get.find<ApiClient>();
|
||||
TablesListModel tables = TablesListModel([]);
|
||||
|
||||
TableModel get usersTable =>
|
||||
tables.tables.firstWhere((element) => element.tableName == "users");
|
||||
|
||||
bool get isNarrow =>
|
||||
(MediaQuery.of(context).size.width - C.materialDrawerWidth) <= 600;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
refreshData();
|
||||
}
|
||||
|
||||
var currentPage = PageType.none;
|
||||
final pageNames = {
|
||||
PageType.none: "Home",
|
||||
PageType.tables: "Tables",
|
||||
|
|
@ -52,8 +29,41 @@ class _HomePageState extends State<HomePage> with HomePageStateRef {
|
|||
PageType.settings: "Settings",
|
||||
};
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
Get.lazyPut<TablesListPanelController>(
|
||||
() => TablesListPanelController(),
|
||||
fenix: true,
|
||||
);
|
||||
Get.lazyPut<UserListPanelController>(
|
||||
() => UserListPanelController(),
|
||||
fenix: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
ApiController.to.token = "";
|
||||
|
||||
await Future.wait([
|
||||
Get.delete<TablesListPanelController>(),
|
||||
Get.delete<UserListPanelController>(),
|
||||
Get.delete<HomePageController>(),
|
||||
]);
|
||||
|
||||
Get.offAllNamed("/");
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends GetView<HomePageController> {
|
||||
const HomePage({super.key});
|
||||
|
||||
bool get isNarrow =>
|
||||
(Get.mediaQuery.size.width - C.materialDrawerWidth) <= 600;
|
||||
|
||||
AppBar get appBar => AppBar(
|
||||
title: Text(pageNames[currentPage]!),
|
||||
title: Obx(() => Text(controller.currentPageName)),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.home),
|
||||
|
|
@ -62,51 +72,49 @@ class _HomePageState extends State<HomePage> with HomePageStateRef {
|
|||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: refreshData,
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: () => controller.logout(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
ListView get drawerOptions => ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.table_chart),
|
||||
title: const Text("Tables"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
currentPage = PageType.tables;
|
||||
});
|
||||
},
|
||||
Obx(
|
||||
() => ListTile(
|
||||
leading: const Icon(Icons.table_chart),
|
||||
title: const Text("Tables"),
|
||||
onTap: () {
|
||||
controller.currentPage = PageType.tables;
|
||||
},
|
||||
selected: controller.currentPage == PageType.tables,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: const Text("Users"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
currentPage = PageType.users;
|
||||
});
|
||||
},
|
||||
Obx(
|
||||
() => ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: const Text("Users"),
|
||||
onTap: () {
|
||||
controller.currentPage = PageType.users;
|
||||
},
|
||||
selected: controller.currentPage == PageType.users,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.settings),
|
||||
title: const Text("Settings"),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
currentPage = PageType.settings;
|
||||
});
|
||||
},
|
||||
Obx(
|
||||
() => ListTile(
|
||||
leading: const Icon(Icons.settings),
|
||||
title: const Text("Settings"),
|
||||
onTap: () {
|
||||
controller.currentPage = PageType.settings;
|
||||
},
|
||||
selected: controller.currentPage == PageType.settings,
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.logout),
|
||||
title: const Text("Logout"),
|
||||
onTap: () {
|
||||
GetStorage().erase().then((value) {
|
||||
GetStorage().save();
|
||||
Get.offAllNamed("/");
|
||||
});
|
||||
},
|
||||
onTap: () => controller.logout(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -140,12 +148,12 @@ class _HomePageState extends State<HomePage> with HomePageStateRef {
|
|||
),
|
||||
LimitedBox(
|
||||
maxWidth: MediaQuery.of(context).size.width - C.materialDrawerWidth,
|
||||
child: Builder(builder: (context) {
|
||||
switch (currentPage) {
|
||||
child: Obx(() {
|
||||
switch (controller.currentPage) {
|
||||
case PageType.tables:
|
||||
return TablesListPanel(parent: this, tables: tables);
|
||||
return const TablesListPanel();
|
||||
case PageType.users:
|
||||
return UsersListPanel(usersTable: usersTable);
|
||||
return const UsersListPanel();
|
||||
case PageType.settings:
|
||||
return const SettingsPanel();
|
||||
case PageType.none:
|
||||
|
|
@ -158,25 +166,4 @@ class _HomePageState extends State<HomePage> with HomePageStateRef {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void refreshData() {
|
||||
apiClient.tablesList().then(
|
||||
(value) => value.unfold(
|
||||
(tables) {
|
||||
setState(() {
|
||||
this.tables = tables;
|
||||
});
|
||||
},
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.toString()),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,110 +1,106 @@
|
|||
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tuuli_api/tuuli_api.dart';
|
||||
import 'package:tuuli_app/api_controller.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
import 'package:tuuli_app/api/api_client.dart';
|
||||
import 'package:tuuli_app/api/model/tables_list_model.dart';
|
||||
import 'package:tuuli_app/c.dart';
|
||||
import 'package:tuuli_app/pages/bottomsheets/edit_table_bottomsheet.dart';
|
||||
import 'package:tuuli_app/pages/bottomsheets/open_table_bottomsheet.dart';
|
||||
import 'package:tuuli_app/pages/home_page.dart';
|
||||
|
||||
class TablesListPanel extends StatefulWidget {
|
||||
final TablesListModel tables;
|
||||
final HomePageStateRef parent;
|
||||
|
||||
const TablesListPanel({
|
||||
super.key,
|
||||
required this.tables,
|
||||
required this.parent,
|
||||
});
|
||||
import 'package:tuuli_app/models/db_column_definition.dart';
|
||||
|
||||
class TablesListPanelController extends GetxController {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _TablesListPanelState();
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
refreshData();
|
||||
}
|
||||
|
||||
final _isLoading = false.obs;
|
||||
bool get isLoading => _isLoading.value;
|
||||
|
||||
final _tables = <TableDefinition>[].obs;
|
||||
List<TableDefinition> get tables => _tables;
|
||||
|
||||
Future<void> refreshData() async {
|
||||
_isLoading.value = true;
|
||||
try {
|
||||
final resp = await ApiController.to.apiClient.listTables();
|
||||
|
||||
final respData = resp.data;
|
||||
if (respData == null) {
|
||||
throw Exception("No data in response");
|
||||
}
|
||||
|
||||
_tables.clear();
|
||||
_tables.addAll(respData);
|
||||
} on DioError catch (e) {
|
||||
final respData = e.response?.data;
|
||||
if (respData != null) {
|
||||
Get.snackbar(
|
||||
"Error trying to get tables",
|
||||
"${respData['error']}",
|
||||
);
|
||||
} else {
|
||||
Get.snackbar(
|
||||
"Error trying to get tables",
|
||||
"$e",
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar(
|
||||
"Error trying to get tables",
|
||||
"$e",
|
||||
);
|
||||
}
|
||||
_isLoading.value = false;
|
||||
}
|
||||
|
||||
Future<void> createNewTable() async {}
|
||||
|
||||
Future<void> openTable(TableDefinition table) async {}
|
||||
}
|
||||
|
||||
class _TablesListPanelState extends State<TablesListPanel> {
|
||||
final apiClient = Get.find<ApiClient>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
class TablesListPanel extends GetView<TablesListPanelController> {
|
||||
const TablesListPanel({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _buildTableList();
|
||||
}
|
||||
|
||||
Widget _buildTableCard(BuildContext ctx, TableModel table) {
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () => _openTable(table),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
table.tableName.pascalCase,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
table.system ? "System" : "Userland",
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"${table.columns.length} column(s)",
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
AppBar(
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () => controller.createNewTable(),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () => controller.refreshData(),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => controller.tables.isEmpty ? whenNoTables : cardGrid),
|
||||
),
|
||||
],
|
||||
),
|
||||
Obx(
|
||||
() => Positioned(
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
child: controller.isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: const SizedBox(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget get newTableCard => Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: _createNewTable,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildTableList() {
|
||||
var tableItems = widget.tables.tables
|
||||
.where((table) => !table.hidden && !table.system)
|
||||
.toList(growable: false);
|
||||
|
||||
if (tableItems.isEmpty) {
|
||||
return Center(
|
||||
Widget get whenNoTables => Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
|
@ -113,7 +109,7 @@ class _TablesListPanelState extends State<TablesListPanel> {
|
|||
Text(
|
||||
"No tables found",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).disabledColor,
|
||||
color: Get.theme.disabledColor,
|
||||
fontSize: 24,
|
||||
),
|
||||
),
|
||||
|
|
@ -121,81 +117,66 @@ class _TablesListPanelState extends State<TablesListPanel> {
|
|||
Text(
|
||||
"Maybe create one?",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).disabledColor,
|
||||
color: Get.theme.disabledColor,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _createNewTable,
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Create table"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: tableItems.length + 1,
|
||||
itemBuilder: (ctx, i) =>
|
||||
i == 0 ? newTableCard : _buildTableCard(ctx, tableItems[i - 1]),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 5,
|
||||
Widget get cardGrid => GridView.count(
|
||||
shrinkWrap: true,
|
||||
crossAxisCount: 3,
|
||||
childAspectRatio: 5 / 2,
|
||||
children: [...controller.tables.map((e) => _buildTableCard(e))],
|
||||
);
|
||||
|
||||
Widget _buildTableCard(TableDefinition table) {
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: () => controller.openTable(table),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
table.tableName.pascalCase,
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
table.system ? "System" : "Userland",
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"${table.parsedColumns.length} column(s)",
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _createNewTable() async {
|
||||
final result = await showFlexibleBottomSheet<EditTableBottomSheetResult>(
|
||||
minHeight: 0,
|
||||
initHeight: 0.75,
|
||||
maxHeight: 1,
|
||||
context: context,
|
||||
builder: (_, __, ___) => const EditTableBottomSheet(),
|
||||
anchors: [0, 0.5, 1],
|
||||
isSafeArea: true,
|
||||
isDismissible: false,
|
||||
);
|
||||
|
||||
if (result == null) return;
|
||||
|
||||
await apiClient
|
||||
.createTable(result.tableName, result.fields)
|
||||
.then((e) => WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
e.unfold((_) {
|
||||
Get.snackbar(
|
||||
"Success",
|
||||
"Table created",
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}, (error) {
|
||||
Get.defaultDialog(
|
||||
title: "Error",
|
||||
middleText: error.toString(),
|
||||
textConfirm: "OK",
|
||||
onConfirm: () => Get.back(),
|
||||
);
|
||||
});
|
||||
}));
|
||||
|
||||
widget.parent.refreshData();
|
||||
}
|
||||
|
||||
void _openTable(TableModel table) async {
|
||||
await showFlexibleBottomSheet<void>(
|
||||
minHeight: 1,
|
||||
initHeight: 1,
|
||||
maxHeight: 1,
|
||||
context: context,
|
||||
builder: (_, __, ___) => OpenTableBottomSheet(table: table),
|
||||
anchors: [0, 0.5, 1],
|
||||
isSafeArea: true,
|
||||
isDismissible: false,
|
||||
);
|
||||
|
||||
widget.parent.refreshData();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:animated_background/animated_background.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
|
@ -8,9 +7,9 @@ import 'package:tuuli_api/tuuli_api.dart';
|
|||
import 'package:tuuli_app/api_controller.dart';
|
||||
|
||||
class LoginPageController extends GetxController {
|
||||
final _login = "".obs;
|
||||
String get login => _login.value;
|
||||
set login(String value) => _login.value = value;
|
||||
final _username = "".obs;
|
||||
String get username => _username.value;
|
||||
set username(String value) => _username.value = value;
|
||||
|
||||
final _password = "".obs;
|
||||
String get password => _password.value;
|
||||
|
|
@ -20,18 +19,18 @@ class LoginPageController extends GetxController {
|
|||
bool get submitted => _submitted.value;
|
||||
set submitted(bool value) => _submitted.value = value;
|
||||
|
||||
bool get isFormValid => login.isNotEmpty && password.isNotEmpty;
|
||||
bool get isFormValid => username.isNotEmpty && password.isNotEmpty;
|
||||
|
||||
Future<void> submitForm() async {
|
||||
submitted = true;
|
||||
if (isFormValid) {
|
||||
final amb = AuthModelBuilder()
|
||||
..username = login
|
||||
..password = password;
|
||||
|
||||
try {
|
||||
final resp = await ApiController.to.apiClient
|
||||
.getAccessTokenApiGetAccessTokenPost(authModel: amb.build());
|
||||
final resp = await ApiController.to.apiClient.getAccessToken(
|
||||
authModel: AuthModel(
|
||||
username: username,
|
||||
password: password,
|
||||
),
|
||||
);
|
||||
|
||||
final respData = resp.data;
|
||||
if (resp.statusCode == 200 && respData != null) {
|
||||
|
|
@ -105,9 +104,9 @@ class LoginPage extends GetView<LoginPageController> {
|
|||
enabled: !controller.submitted,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
hintText: 'Enter your login',
|
||||
hintText: 'Enter your username',
|
||||
),
|
||||
onChanged: (value) => controller.login = value,
|
||||
onChanged: (value) => controller.username = value,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your Login';
|
||||
|
|
@ -149,147 +148,3 @@ class LoginPage extends GetView<LoginPageController> {
|
|||
);
|
||||
}
|
||||
}
|
||||
/*
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> with TickerProviderStateMixin {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final apiClient = Get.find<ApiClient>();
|
||||
var submitted = false;
|
||||
|
||||
final loginPageController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenSize = MediaQuery.of(context).size;
|
||||
final formWidth = screenSize.width <= 600 ? screenSize.width : 300.0;
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
AnimatedBackground(
|
||||
behaviour: RandomParticleBehaviour(),
|
||||
vsync: this,
|
||||
child: const SizedBox.square(
|
||||
dimension: 0,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
LimitedBox(
|
||||
maxWidth: formWidth,
|
||||
child: Container(
|
||||
color: Colors.black.withAlpha(100),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: loginPageController,
|
||||
enabled: !submitted,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
hintText: 'Enter your login',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your Login';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: passwordController,
|
||||
obscureText: true,
|
||||
enabled: !submitted,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
hintText: 'Enter your password',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: submitted ? null : _submit,
|
||||
child: const Text('Login'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
submitted = true;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Trying to login...'),
|
||||
),
|
||||
);
|
||||
|
||||
final response = await apiClient.login(
|
||||
loginPageController.text.trim(),
|
||||
passwordController.text.trim(),
|
||||
);
|
||||
response.unfold((data) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Login successful'),
|
||||
),
|
||||
);
|
||||
apiClient.setAccessToken(data.accessToken);
|
||||
GetStorage()
|
||||
.write("accessToken", data.accessToken)
|
||||
.then((value) => GetStorage().save())
|
||||
.then((value) {
|
||||
Timer(1.seconds, () {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Get.offAllNamed("/home");
|
||||
});
|
||||
});
|
||||
});
|
||||
}, (error) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.toString()),
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
submitted = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
118
pubspec.lock
118
pubspec.lock
|
|
@ -5,18 +5,18 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
sha256: a36ec4843dc30ea6bf652bf25e3448db6c5e8bcf4aa55f063a5d1dad216d8214
|
||||
sha256: "8880b4cfe7b5b17d57c052a5a3a8cc1d4f546261c7cc8fbd717bd53f48db0568"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "58.0.0"
|
||||
version: "59.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
sha256: cc4242565347e98424ce9945c819c192ec0838cb9d1f6aa4a97cc96becbc5b27
|
||||
sha256: a89627f49b0e70e068130a36571409726b04dab12da7e5625941d2c8ec278b96
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.10.0"
|
||||
version: "5.11.1"
|
||||
animated_background:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -275,6 +275,11 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
frontend_server_client:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -343,10 +348,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: intl
|
||||
sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6
|
||||
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.18.0"
|
||||
version: "0.18.1"
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -371,6 +376,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.8.0"
|
||||
lint:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lint
|
||||
sha256: "4a539aa34ec5721a2c7574ae2ca0336738ea4adc2a34887d54b7596310b33c85"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.0"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -463,18 +476,18 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_android
|
||||
sha256: "019f18c9c10ae370b08dce1f3e3b73bc9f58e7f087bb5e921f06529438ac0ae7"
|
||||
sha256: da97262be945a72270513700a92b39dd2f4a54dad55d061687e2e37a6390366a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.24"
|
||||
version: "2.0.25"
|
||||
path_provider_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_foundation
|
||||
sha256: "818b2dc38b0f178e0ea3f7cf3b28146faab11375985d815942a68eee11c2d0f7"
|
||||
sha256: ad4c4d011830462633f03eb34445a45345673dfd4faf1ab0b4735fbd93b19183
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "2.2.2"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -563,6 +576,62 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "858aaa72d8f61637d64e776aca82e1c67e6d9ee07979123c5d17115031c1b13b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "7fa90471a6875d26ad78c7e4a675874b2043874586891128dc5899662c97db46"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "0c1c16c56c9708aa9c361541a6f0e5cc6fc12a3232d866a687a7b7db30032b07"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: "9d387433ca65717bbf1be88f4d5bb18f10508917a8fa2fb02e0fd0d7479a9afa"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: "74083203a8eae241e0de4a0d597dbedab3b8fef5563f33cf3c12d7e93c655ca5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: "5e588e2efef56916a3b229c3bfe81e6a525665a454519ca51dbcc4236a274173"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -632,6 +701,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
styled_widget:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: styled_widget
|
||||
sha256: "4d439802919b6ccf10d1488798656da8804633b03012682dd1c8ca70a084aa84"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.1"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -656,6 +733,15 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
tuuli_api:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: master
|
||||
resolved-ref: "46d8acd4a54fd716a16f119e4296ee5583b8bc98"
|
||||
url: "https://glab.nuark.xyz/nuark/tuuli_api.git"
|
||||
source: git
|
||||
version: "1.0.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -664,14 +750,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
uuid:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: uuid
|
||||
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -700,10 +778,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
sha256: c9ebe7ee4ab0c2194e65d3a07d8c54c5d00bb001b76081c4a04cdb8448b59e46
|
||||
sha256: a6f0236dbda0f63aa9a25ad1ff9a9d8a4eaaa5012da0dc59d21afdb1dc361ca4
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
version: "3.1.4"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -22,7 +22,13 @@ dependencies:
|
|||
http: ^0.13.5
|
||||
one_of_serializer: ^1.5.0
|
||||
recase: ^4.1.0
|
||||
uuid: ^3.0.7
|
||||
shared_preferences: ^2.1.0
|
||||
styled_widget: ^0.4.1
|
||||
|
||||
tuuli_api:
|
||||
git:
|
||||
url: https://glab.nuark.xyz/nuark/tuuli_api.git
|
||||
ref: master
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue