From 007e516cd352b140e58110c8c7852e54cc3d479b Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Wed, 13 Oct 2021 22:39:16 +0200 Subject: [PATCH] Generator: generated program works --- .gitignore | 1 + lib/meta/module_meta_data.dart | 24 ++++++++++--------- lib/meta/modules.dart | 4 +++- lib/page/roles/create_role_page.dart | 2 +- lib/page/roles/edit_role_page.dart | 2 +- lib/page/roles/list_role_page.dart | 2 +- .../structures/create_structure_page.dart | 6 ++--- .../structures/delete_structure_page.dart | 6 ++--- lib/page/structures/edit_structure_page.dart | 6 ++--- lib/page/structures/list_structure_page.dart | 6 ++--- lib/page/users/create_user_custom.dart | 2 +- lib/page/users/create_user_page.dart | 2 +- lib/page/users/delete_user_custom.dart | 7 +++--- lib/page/users/delete_user_page.dart | 2 +- lib/page/users/edit_user_custom.dart | 10 ++++---- lib/page/users/edit_user_page.dart | 2 +- lib/page/users/list_user_custom.dart | 3 ++- lib/page/users/list_user_page.dart | 2 +- metatool/bin/page_generator.dart | 17 +++++++++---- 19 files changed, 60 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index 5bc5626..aa9f965 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ data/i18n/main.lqa *~ data/i18n/lokalize-scripts/ rest_server/tools/rest_server +/UpdRestSv diff --git a/lib/meta/module_meta_data.dart b/lib/meta/module_meta_data.dart index c6a237f..68d9895 100644 --- a/lib/meta/module_meta_data.dart +++ b/lib/meta/module_meta_data.dart @@ -225,7 +225,7 @@ class ModuleMetaData { /// /// Override it if needed. void onInitialized() { - for (var page in this.pageList){ + for (var page in this.pageList) { page.onInitialized(); } } @@ -276,32 +276,32 @@ class PageMetaData { } this.name = name; } - void onInitialized(){ + void onInitialized() { var newFields = []; var toDelete = []; - for (var field in fields){ - if (field is CopyDbFields){ + for (var field in fields) { + if (field is CopyDbFields) { String excluded = ''; final start = field.options.indexOf('excluded='); - if (start >= 0){ + if (start >= 0) { var end = field.options.indexOf(':', start); - if (end < 0){ + if (end < 0) { end = field.options.length; } excluded = ' ' + field.options.substring(start, end) + ' '; } - for (var property in module.propertyList){ - if (excluded.contains(" ${property.name} ")){ + for (var property in module.propertyList) { + if (excluded.contains(" ${property.name} ")) { continue; } - if (! property.hasOption(':hidden:')) { + if (!property.hasOption(':hidden:')) { newFields.add(property); } } toDelete.add(field); } } - for (var field in toDelete){ + for (var field in toDelete) { fields.remove(field); } fields.addAll(newFields); @@ -328,6 +328,7 @@ class PropertyMetaData extends WidgetMetaData { final int size; String columnName; var validators = []; + /// The foreign key if dataType is DataType.reference, e.g. 'users.user_id' String? foreignKey; PropertyMetaData(String name, this.label, this.dataType, this.options, @@ -335,7 +336,8 @@ class PropertyMetaData extends WidgetMetaData { this.columnName = '', this.size = 0, this.foreignKey, - int weight = 6, List? validators}) + int weight = 6, + List? validators}) : super(name, WidgetType.property) { this.weight = weight > 12 ? 12 : weight; this.validators = validators ?? []; diff --git a/lib/meta/modules.dart b/lib/meta/modules.dart index 5d0d3ed..2ff718c 100644 --- a/lib/meta/modules.dart +++ b/lib/meta/modules.dart @@ -3,6 +3,7 @@ import 'module_meta_data.dart'; import 'roles_meta.dart'; import 'structures_meta.dart'; import 'users_meta.dart'; + /// Returns the meta data of the module given by [name]. /// Returns null if not found. ModuleMetaData? moduleByName(String name) { @@ -22,8 +23,9 @@ ModuleMetaData? moduleByName(String name) { } return rc; } + /// Returns the module names as string list. -List moduleNames(){ +List moduleNames() { return [ 'Roles', 'Structures', diff --git a/lib/page/roles/create_role_page.dart b/lib/page/roles/create_role_page.dart index 4ec6c88..2cd8530 100644 --- a/lib/page/roles/create_role_page.dart +++ b/lib/page/roles/create_role_page.dart @@ -20,7 +20,7 @@ class CreateRolePage extends StatefulWidget { } class _CreateRolePageState extends CreateRoleCustom { - _CreateRolePageState(): super(); + _CreateRolePageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/edit_role_page.dart b/lib/page/roles/edit_role_page.dart index ef15ac4..6c32f01 100644 --- a/lib/page/roles/edit_role_page.dart +++ b/lib/page/roles/edit_role_page.dart @@ -21,7 +21,7 @@ class EditRolePage extends StatefulWidget { } class _EditRolePageState extends EditRoleCustom { - _EditRolePageState(int primaryKey): super(primaryKey); + _EditRolePageState(int primaryKey) : super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/roles/list_role_page.dart b/lib/page/roles/list_role_page.dart index b42f052..0915e10 100644 --- a/lib/page/roles/list_role_page.dart +++ b/lib/page/roles/list_role_page.dart @@ -20,7 +20,7 @@ class ListRolePage extends StatefulWidget { } class _ListRolePageState extends ListRoleCustom { - _ListRolePageState(): super(); + _ListRolePageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/structures/create_structure_page.dart b/lib/page/structures/create_structure_page.dart index 88aa0fb..e27c01e 100644 --- a/lib/page/structures/create_structure_page.dart +++ b/lib/page/structures/create_structure_page.dart @@ -12,15 +12,15 @@ class CreateStructurePage extends StatefulWidget { @override _CreateStructurePageState createState() { final rc = _CreateStructurePageState(); - rc.attendedPage = - AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates); + rc.attendedPage = AttendedPage( + this, rc, GlobalData(), StructureMeta.instance, pageStates); pageStates.attendedPage = rc.attendedPage; return rc; } } class _CreateStructurePageState extends CreateStructureCustom { - _CreateStructurePageState(): super(); + _CreateStructurePageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/structures/delete_structure_page.dart b/lib/page/structures/delete_structure_page.dart index 2bdedf3..cc888a8 100644 --- a/lib/page/structures/delete_structure_page.dart +++ b/lib/page/structures/delete_structure_page.dart @@ -13,15 +13,15 @@ class DeleteStructurePage extends StatefulWidget { @override _DeleteStructurePageState createState() { final rc = _DeleteStructurePageState(this.primaryKey); - rc.attendedPage = - AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates); + rc.attendedPage = AttendedPage( + this, rc, GlobalData(), StructureMeta.instance, pageStates); pageStates.attendedPage = rc.attendedPage; return rc; } } class _DeleteStructurePageState extends DeleteStructureCustom { - _DeleteStructurePageState(int primaryKey): super(primaryKey); + _DeleteStructurePageState(int primaryKey) : super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/structures/edit_structure_page.dart b/lib/page/structures/edit_structure_page.dart index c151f66..a689d34 100644 --- a/lib/page/structures/edit_structure_page.dart +++ b/lib/page/structures/edit_structure_page.dart @@ -13,15 +13,15 @@ class EditStructurePage extends StatefulWidget { @override _EditStructurePageState createState() { final rc = _EditStructurePageState(this.primaryKey); - rc.attendedPage = - AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates); + rc.attendedPage = AttendedPage( + this, rc, GlobalData(), StructureMeta.instance, pageStates); pageStates.attendedPage = rc.attendedPage; return rc; } } class _EditStructurePageState extends EditStructureCustom { - _EditStructurePageState(int primaryKey): super(primaryKey); + _EditStructurePageState(int primaryKey) : super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/structures/list_structure_page.dart b/lib/page/structures/list_structure_page.dart index e286fbc..55c901c 100644 --- a/lib/page/structures/list_structure_page.dart +++ b/lib/page/structures/list_structure_page.dart @@ -12,15 +12,15 @@ class ListStructurePage extends StatefulWidget { @override _ListStructurePageState createState() { final rc = _ListStructurePageState(); - rc.attendedPage = - AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates); + rc.attendedPage = AttendedPage( + this, rc, GlobalData(), StructureMeta.instance, pageStates); pageStates.attendedPage = rc.attendedPage; return rc; } } class _ListStructurePageState extends ListStructureCustom { - _ListStructurePageState(): super(); + _ListStructurePageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/create_user_custom.dart b/lib/page/users/create_user_custom.dart index ec8d94e..c0da66b 100644 --- a/lib/page/users/create_user_custom.dart +++ b/lib/page/users/create_user_custom.dart @@ -98,7 +98,7 @@ class CreateUserCustom extends State with MessageLine { formItems, screenWidth: attendedPage!.pageStates.screenWidth, padding: padding, - )))))); + )))))); return rc; } diff --git a/lib/page/users/create_user_page.dart b/lib/page/users/create_user_page.dart index 14e69e2..71a2c05 100644 --- a/lib/page/users/create_user_page.dart +++ b/lib/page/users/create_user_page.dart @@ -20,7 +20,7 @@ class CreateUserPage extends StatefulWidget { } class _CreateUserPageState extends CreateUserCustom { - _CreateUserPageState(): super(); + _CreateUserPageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/delete_user_custom.dart b/lib/page/users/delete_user_custom.dart index 8415fb2..65cfc7a 100644 --- a/lib/page/users/delete_user_custom.dart +++ b/lib/page/users/delete_user_custom.dart @@ -75,7 +75,8 @@ class DeleteUserCustom extends State with MessageLine { weight: 6), FormItem( ElevatedButton( - onPressed: () => verifyAndDelete(), child: Text(i18n.tr('Delete'))), + onPressed: () => verifyAndDelete(), + child: Text(i18n.tr('Delete'))), weight: 8, gapAbove: 2 * padding), FormItem( @@ -104,7 +105,7 @@ class DeleteUserCustom extends State with MessageLine { formItems, screenWidth: attendedPage!.pageStates.screenWidth, padding: padding, - )))))); + )))))); return rc; } @@ -118,7 +119,7 @@ class DeleteUserCustom extends State with MessageLine { 'module': 'Users', 'sql': 'delete', }; - _fieldData.toMap(parameters); + parameters[':id'] = primaryKey; globalData.restPersistence! .store(what: 'store', map: parameters) .then((answer) { diff --git a/lib/page/users/delete_user_page.dart b/lib/page/users/delete_user_page.dart index 85cbfc9..8bbef4c 100644 --- a/lib/page/users/delete_user_page.dart +++ b/lib/page/users/delete_user_page.dart @@ -21,7 +21,7 @@ class DeleteUserPage extends StatefulWidget { } class _DeleteUserPageState extends DeleteUserCustom { - _DeleteUserPageState(int primaryKey): super(primaryKey); + _DeleteUserPageState(int primaryKey) : super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/edit_user_custom.dart b/lib/page/users/edit_user_custom.dart index 4727f34..81685c3 100644 --- a/lib/page/users/edit_user_custom.dart +++ b/lib/page/users/edit_user_custom.dart @@ -104,7 +104,7 @@ class EditUserCustom extends State with MessageLine { formItems, screenWidth: attendedPage!.pageStates.screenWidth, padding: padding, - )))))); + )))))); return rc; } @@ -118,12 +118,11 @@ class EditUserCustom extends State with MessageLine { 'module': 'Users', 'sql': 'update', }; + parameters[':id'] = primaryKey; _fieldData.toMap(parameters); globalData.restPersistence! .store(what: 'store', map: parameters) - .then((answer) { - - }); + .then((answer) {}); } void verifyAndStore() { @@ -154,8 +153,9 @@ class _FieldData { email = map['user_email']; role = map['user_role']; } + void toMap(Map map) { - map[':id'] = primaryKey; + // please set outside: map[':id'] = primaryKey; map[':name'] = name; map[':displayName'] = displayName; map[':email'] = email; diff --git a/lib/page/users/edit_user_page.dart b/lib/page/users/edit_user_page.dart index 1179663..4b2e75f 100644 --- a/lib/page/users/edit_user_page.dart +++ b/lib/page/users/edit_user_page.dart @@ -21,7 +21,7 @@ class EditUserPage extends StatefulWidget { } class _EditUserPageState extends EditUserCustom { - _EditUserPageState(int primaryKey): super(primaryKey); + _EditUserPageState(int primaryKey) : super(primaryKey); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/lib/page/users/list_user_custom.dart b/lib/page/users/list_user_custom.dart index f481a2c..195eb9a 100644 --- a/lib/page/users/list_user_custom.dart +++ b/lib/page/users/list_user_custom.dart @@ -119,8 +119,9 @@ class ListUserCustom extends State { void initState() { super.initState(); } + @override - void dispose(){ + void dispose() { textController.dispose(); super.dispose(); } diff --git a/lib/page/users/list_user_page.dart b/lib/page/users/list_user_page.dart index 1938d3d..2723f48 100644 --- a/lib/page/users/list_user_page.dart +++ b/lib/page/users/list_user_page.dart @@ -20,7 +20,7 @@ class ListUserPage extends StatefulWidget { } class _ListUserPageState extends ListUserCustom { - _ListUserPageState(): super(); + _ListUserPageState() : super(); @override void didChangeDependencies() { final size = MediaQuery.of(context).size; diff --git a/metatool/bin/page_generator.dart b/metatool/bin/page_generator.dart index ac6333a..0d73fdb 100644 --- a/metatool/bin/page_generator.dart +++ b/metatool/bin/page_generator.dart @@ -218,8 +218,7 @@ class EditUserCustom extends State with MessageLine { 'module': 'Users', 'sql': '#SQL_TYPE', }; - _fieldData.toMap(parameters); - globalData.restPersistence! +#SET_PRIMARY#CALL_TO_MAP globalData.restPersistence! .store(what: 'store', map: parameters) .then((answer) { #STORAGE_DONE @@ -377,7 +376,7 @@ StatefulWidget? customPageByRoute(String route) { continue; } final name = field.name; - final field2 = field as PropertyMetaData; + final field2 = field; String type; String value; switch (field2.dataType) { @@ -578,7 +577,7 @@ StatefulWidget? customPageByRoute(String route) { if (page.pageType == PageType.edit || page.pageType == PageType.create) { final buffer = StringBuffer(' void toMap(Map map) {\n'); if (page.pageType == PageType.edit) { - buffer.writeln(" map[':id'] = primaryKey;"); + buffer.writeln(" // please set outside: map[':id'] = primaryKey;"); } for (var field in page.fields) { if (!(field is PropertyMetaData) || field.hasOption(':primary:')) { @@ -659,24 +658,30 @@ StatefulWidget? customPageByRoute(String route) { var action2 = 'verifyAndStore'; var storageDone = ''; var buttonText = 'Save'; - String sqlType = ''; + var sqlType = ''; + var setPrimary = ''; + var callToMap = ''; page.pageType == PageType.edit ? 'update' : (page.pageType == PageType.delete ? 'delete' : 'insert'); switch (page.pageType) { case PageType.create: + callToMap = ' _fieldData.toMap(parameters);\n'; sqlType = 'insert'; storageDone = templateStorageDoneCreate.replaceFirst( '#MODULE', page.module.moduleName); break; case PageType.edit: + callToMap = ' _fieldData.toMap(parameters);\n'; + setPrimary = " parameters[':id'] = primaryKey;\n"; sqlType = 'update'; storageDone = templateStorageDoneEdit; hasPrimary = true; storageDone = ''; break; case PageType.delete: + setPrimary = " parameters[':id'] = primaryKey;\n"; sqlType = 'delete'; buttonText = 'Delete'; action1 = 'delete'; @@ -697,6 +702,8 @@ StatefulWidget? customPageByRoute(String route) { .replaceFirst('#LOAD_RECORD', buildLoadRecord(page)) .replaceFirst('#PAGE_LABEL', page.label) .replaceFirst('#SQL_TYPE', sqlType) + .replaceFirst('#SET_PRIMARY', setPrimary) + .replaceFirst('#CALL_TO_MAP', callToMap) .replaceAll('#ACTION1', action1) .replaceAll('#ACTION2', action2) .replaceFirst('#BUTTON', buttonText) -- 2.39.5