From: Hamatoma Date: Sun, 24 Oct 2021 17:36:48 +0000 (+0200) Subject: Refactoring X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=c67917caae7cbe946c5c5f776c21fdd9e8775408;p=exhibition.git Refactoring * Refactoring: ** usage of the dart feature "late": many "Type? x;" replaced by "late TYPE x;" * module_meta_data: ** new module attribute needsSqlAll: creates a "all" section of the module with no WHERE condition ** Fix in pageByName(): "nothing found" is handled now correctly ** Fix in primaryOf(): "nothing found" is handled now correctly * rest_server: ** logging of the using configuration file --- diff --git a/dart_tools/bin/i18n_text_parser.dart b/dart_tools/bin/i18n_text_parser.dart index 48928ca..bcfca05 100644 --- a/dart_tools/bin/i18n_text_parser.dart +++ b/dart_tools/bin/i18n_text_parser.dart @@ -59,7 +59,7 @@ void parse(List args) { excluded = RegExp.escape(excluded).replaceAll(';', '|'); } parser.regExpExcluded = RegExp('^($excluded)\$'); - logger.log('excluding: ' + parser.regExpExcluded!.pattern, LEVEL_FINE); + logger.log('excluding: ' + parser.regExpExcluded.pattern, LEVEL_FINE); } parser.scanDirectory(args[0], 0); parser.writePot(args[1]); @@ -103,7 +103,7 @@ class I18nTextParser { List lines = []; int currentLineNo = 0; int currentIxLines = 0; - RegExp? regExpExcluded; + late RegExp regExpExcluded; // ...........................1.............1.........2 final regExpModule = RegExp(r'''(\w+) = (I18N\(\)|i18n)\.module\(["'](.*?)['"]\);'''); @@ -474,8 +474,7 @@ msgstr "" } for (var node in subDirs) { if (depth == 0 && - regExpExcluded != null && - regExpExcluded!.firstMatch(node) != null) { + regExpExcluded.firstMatch(node) != null) { logger.log('ignoring $node'); } else { scanDirectory( diff --git a/lib/base/i18n.dart b/lib/base/i18n.dart index e0ccf44..528f67f 100644 --- a/lib/base/i18n.dart +++ b/lib/base/i18n.dart @@ -36,8 +36,8 @@ class I18N { rc = removeInvisibleTag(count == 1 ? keySingular : keyPlural); } else { if (map.containsKey(keySingular)) { - final info = map[keySingular]; - if (info!.list != null && count < info.list!.length) { + final info = map[keySingular]!; + if (info.list != null && count < info.list!.length) { rc = info.list![count]; } else { rc = count == 1 ? info.singular : info.plural; diff --git a/lib/common/benchmark_actions.dart b/lib/common/benchmark_actions.dart index 9703511..c3290a2 100644 --- a/lib/common/benchmark_actions.dart +++ b/lib/common/benchmark_actions.dart @@ -68,7 +68,7 @@ class BenchmarkActions { ':active': 'T', ':createdBy': 'benchmark' }; - final answer = await globalData.restPersistence! + final answer = await globalData.restPersistence .store(what: 'store', map: parameters); if (!answer.startsWith('id:')) { rc = '+++ storage failed: $answer'; diff --git a/lib/meta/module_meta_data.dart b/lib/meta/module_meta_data.dart index 2634f52..80f924b 100644 --- a/lib/meta/module_meta_data.dart +++ b/lib/meta/module_meta_data.dart @@ -157,6 +157,8 @@ class ModuleMetaData { /// The related database table. String tableName = ''; + final needsSqlAll; + /// If true the fields create, createdBy ... have the same ("short") column name /// instead of prefix and name. bool shortModifiedLabel = false; @@ -168,7 +170,8 @@ class ModuleMetaData { {String tableName = '', String moduleNameSingular = '', String columnPrefix = '', - bool shortModifiedLabel = false}) { + bool shortModifiedLabel = false, + bool this.needsSqlAll = false}) { this.tableName = tableName.isEmpty ? moduleName.toLowerCase() : tableName; this.shortModifiedLabel = shortModifiedLabel; if (moduleNameSingular.isEmpty) { @@ -307,16 +310,37 @@ class ModuleMetaData { /// Returns the meta data of a page given by its [name] or null if missing. PageMetaData? pageByName(String name) { - final rc = - pageList.firstWhere((element) => element.name == name, orElse: null); + PageMetaData? rc; + for (var item in pageList) { + if (item.name == name) { + rc = item; + break; + } + } + return rc; + } + + /// Returns the list of pages with a given [pageType]. May be empty. + List pagesByType(PageType pageType) { + final rc = []; + for (var item in pageList) { + if (item.pageType == pageType) { + rc.add(item); + break; + } + } return rc; } /// Returns the primary key of the relation. PropertyMetaData? primaryOf() { - final rc = propertyList.firstWhere( - (element) => element.options.contains('primary'), - orElse: null); + PropertyMetaData? rc; + for (var item in propertyList) { + if (item.options.contains('primary')) { + rc = item; + break; + } + } return rc; } diff --git a/lib/meta/roles_meta.dart b/lib/meta/roles_meta.dart index ed49469..e3f1eaf 100644 --- a/lib/meta/roles_meta.dart +++ b/lib/meta/roles_meta.dart @@ -11,39 +11,44 @@ class RolesMeta extends ModuleMetaData { return instance; } RolesMeta.internal() - : super('Roles', [ - PropertyMetaData('id', i18n.tr('Id'), DataType.reference, ':primary:', - displayType: DisplayType.combobox), - PropertyMetaData( - 'name', i18n.tr('Name'), DataType.string, ':notnull:', - size: 64), - PropertyMetaData('createdAt', i18n.tr('Created at'), - DataType.datetime, ':hidden:'), - PropertyMetaData( - 'createdBy', i18n.tr('Created by'), DataType.string, ':hidden:', - size: 32), - PropertyMetaData( - 'changedAt', i18n.tr('ChangedAt'), DataType.datetime, ':hidden:'), - PropertyMetaData( - 'changedBy', i18n.tr('Changed by'), DataType.string, ':hidden:', - size: 32), - ], [ - PageMetaData('New Role', PageType.create, - fields: [CopyDbFields('fields')]), - PageMetaData('Change Role', PageType.edit, - fields: [CopyDbFields('fields')]), - ListPageMetaData( - 'Roles Overview', - fields: [ - PropertyMetaData('text', i18n.tr('Text'), DataType.string, - ':where=!text IS NONE OR (role_name like !text):', + : super( + 'Roles', + [ + PropertyMetaData( + 'id', i18n.tr('Id'), DataType.reference, ':primary:', + displayType: DisplayType.combobox), + PropertyMetaData( + 'name', i18n.tr('Name'), DataType.string, ':notnull:', size: 64), + PropertyMetaData('createdAt', i18n.tr('Created at'), + DataType.datetime, ':hidden:'), + PropertyMetaData('createdBy', i18n.tr('Created by'), + DataType.string, ':hidden:', + size: 32), + PropertyMetaData('changedAt', i18n.tr('ChangedAt'), + DataType.datetime, ':hidden:'), + PropertyMetaData('changedBy', i18n.tr('Changed by'), + DataType.string, ':hidden:', + size: 32), ], - toolTipAddButton: i18n.tr('Add a new role'), - tableColumns: 'role_id;role_name', - tableHeaders: i18n.tr(';Id;Name'), - ), - ]); + [ + PageMetaData('New Role', PageType.create, + fields: [CopyDbFields('fields')]), + PageMetaData('Change Role', PageType.edit, + fields: [CopyDbFields('fields')]), + ListPageMetaData( + 'Roles Overview', + fields: [ + PropertyMetaData('text', i18n.tr('Text'), DataType.string, + ':where=!text IS NONE OR (role_name like !text):', + size: 64), + ], + toolTipAddButton: i18n.tr('Add a new role'), + tableColumns: 'role_id;role_name', + tableHeaders: i18n.tr(';Id;Name'), + ), + ], + needsSqlAll: true); @override void onInitialized() { super.onInitialized(); diff --git a/lib/meta/rolestarter_meta.dart b/lib/meta/rolestarter_meta.dart index 35c7144..2fac6a8 100644 --- a/lib/meta/rolestarter_meta.dart +++ b/lib/meta/rolestarter_meta.dart @@ -13,32 +13,45 @@ class RoleStarterMeta extends ModuleMetaData { return instance; } RoleStarterMeta.internal() - : super('RoleStarter', [ - PropertyMetaData('id', i18n.tr('Id'), DataType.reference, ':primary:', - displayType: DisplayType.combobox), - PropertyMetaData( - 'role', i18n.tr('Role'), DataType.reference, ':notnull:', - displayType: DisplayType.combobox, - foreignKey: 'roles.role_id;role_name;role'), - PropertyMetaData( - 'starter', i18n.tr('Starter'), DataType.reference, ':notnull:', - displayType: DisplayType.combobox, - foreignKey: 'starters.starter_id;starter_name;starter'), - PropertyMetaData('createdAt', i18n.tr('Created at'), - DataType.datetime, ':hidden:'), - PropertyMetaData( - 'createdBy', i18n.tr('Created by'), DataType.string, ':hidden:', - size: 32), - PropertyMetaData('changedAt', i18n.tr('Changed at'), - DataType.datetime, ':hidden:'), - PropertyMetaData( - 'changedBy', i18n.tr('Changed by'), DataType.string, ':hidden:', - size: 32), - ], [ - MappingPageMetaData( - i18n.tr('Role-Starter Assignment'), - ), - ]); + : super( + 'RoleStarter', + [ + PropertyMetaData( + 'id', i18n.tr('Id'), DataType.reference, ':primary:', + displayType: DisplayType.combobox), + PropertyMetaData( + 'role', i18n.tr('Role'), DataType.reference, ':notnull:', + displayType: DisplayType.combobox, + foreignKey: 'roles.role_id;role_name;role'), + PropertyMetaData('starter', i18n.tr('Starter'), + DataType.reference, ':notnull:', + displayType: DisplayType.combobox, + foreignKey: 'starters.starter_id;starter_name;starter'), + PropertyMetaData('order', i18n.tr('Order'), DataType.int, ''), + PropertyMetaData('createdAt', i18n.tr('Created at'), + DataType.datetime, ':hidden:'), + PropertyMetaData('createdBy', i18n.tr('Created by'), + DataType.string, ':hidden:', + size: 32), + PropertyMetaData('changedAt', i18n.tr('Changed at'), + DataType.datetime, ':hidden:'), + PropertyMetaData('changedBy', i18n.tr('Changed by'), + DataType.string, ':hidden:', + size: 32), + ], + [ + MappingPageMetaData( + i18n.tr('Role-Starter Assignment'), + ), + ListPageMetaData( + 'Role/Starter Assignment Overview', + fields: [], + tableColumns: + 'rolestarter_id;rolestarter_position;role;starter', + tableHeaders: i18n.tr(';Id;Position;Role;Starter'), + ), + ], + needsSqlAll: true); @override void onInitialized() { super.onInitialized(); diff --git a/lib/meta/starters_meta.dart b/lib/meta/starters_meta.dart index 150ab1f..8da2dc7 100644 --- a/lib/meta/starters_meta.dart +++ b/lib/meta/starters_meta.dart @@ -11,47 +11,53 @@ class StartersMeta extends ModuleMetaData { return instance; } StartersMeta.internal() - : super('Starters', [ - PropertyMetaData('id', i18n.tr('Id'), DataType.reference, ':primary:', - displayType: DisplayType.combobox), - PropertyMetaData( - 'name', i18n.tr('Name'), DataType.string, ':notnull:', - size: 64), - PropertyMetaData( - 'link', i18n.tr('Link'), DataType.string, ':notnull:', - size: 64), - PropertyMetaData( - 'icon', i18n.tr('Icon'), DataType.string, ':notnull:', - size: 64), - PropertyMetaData('createdAt', i18n.tr('Created at'), - DataType.datetime, ':hidden:'), - PropertyMetaData( - 'createdBy', i18n.tr('Created by'), DataType.string, ':hidden:', - size: 32), - PropertyMetaData('changedAt', i18n.tr('Changed at'), - DataType.datetime, ':hidden:'), - PropertyMetaData( - 'changedBy', i18n.tr('Changed by'), DataType.string, ':hidden:', - size: 32), - ], [ - PageMetaData('New Starter', PageType.create, - fields: [CopyDbFields('fields')]), - PageMetaData('Change Starter', PageType.edit, - fields: [CopyDbFields('fields')]), - PageMetaData('Delete Starter', PageType.delete, - fields: [CopyDbFields('fields')]), - ListPageMetaData( - 'Starters Overview', - fields: [ - PropertyMetaData('text', i18n.tr('Text'), DataType.string, - ':where=!text IS NONE OR starter_name like !text OR starter_link like !text:', + : super( + 'Starters', + [ + PropertyMetaData( + 'id', i18n.tr('Id'), DataType.reference, ':primary:', + displayType: DisplayType.combobox), + PropertyMetaData( + 'name', i18n.tr('Name'), DataType.string, ':notnull:', size: 64), + PropertyMetaData( + 'route', i18n.tr('Route'), DataType.string, ':notnull:', + size: 128), + PropertyMetaData( + 'icon', i18n.tr('Icon'), DataType.string, ':notnull:', + size: 64), + PropertyMetaData('createdAt', i18n.tr('Created at'), + DataType.datetime, ':hidden:'), + PropertyMetaData('createdBy', i18n.tr('Created by'), + DataType.string, ':hidden:', + size: 32), + PropertyMetaData('changedAt', i18n.tr('Changed at'), + DataType.datetime, ':hidden:'), + PropertyMetaData('changedBy', i18n.tr('Changed by'), + DataType.string, ':hidden:', + size: 32), + ], + [ + PageMetaData('New Starter', PageType.create, + fields: [CopyDbFields('fields')]), + PageMetaData('Change Starter', PageType.edit, + fields: [CopyDbFields('fields')]), + PageMetaData('Delete Starter', PageType.delete, + fields: [CopyDbFields('fields')]), + ListPageMetaData( + 'Starters Overview', + fields: [ + PropertyMetaData('text', i18n.tr('Text'), DataType.string, + ':where=!text IS NONE OR starter_name like !text OR starter_route like !text:', + size: 64), + ], + toolTipAddButton: i18n.tr('Add a new starter'), + tableColumns: + 'starter_id;starter_name;starter_route;starter_icon', + tableHeaders: i18n.tr(';Id;Name;Route;Icon'), + ), ], - toolTipAddButton: i18n.tr('Add a new starter'), - tableColumns: 'starter_id;starter_name;starter_link;starter_icon', - tableHeaders: i18n.tr(';Id;Name;Link;Icon'), - ), - ]); + needsSqlAll: true); @override void onInitialized() { super.onInitialized(); diff --git a/lib/page/benchmarks/create_benchmark_custom.dart b/lib/page/benchmarks/create_benchmark_custom.dart index 7c16160..bb56856 100644 --- a/lib/page/benchmarks/create_benchmark_custom.dart +++ b/lib/page/benchmarks/create_benchmark_custom.dart @@ -18,7 +18,7 @@ final i18n = I18N(); class CreateBenchmarkCustom extends State with MessageLine { final globalData = GlobalData(); - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateBenchmark'); @@ -113,7 +113,7 @@ class CreateBenchmarkCustom extends State FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Benchmarks/list'); }, child: Text(i18n.tr('Cancel')), @@ -130,7 +130,7 @@ class CreateBenchmarkCustom extends State vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -160,7 +160,7 @@ class CreateBenchmarkCustom extends State 'sql': 'insert', }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { if (answer.startsWith('id:')) { @@ -169,7 +169,7 @@ class CreateBenchmarkCustom extends State setError(i18n.tr('Saving data failed: $answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Benchmarks/edit;$id'); } } @@ -177,7 +177,7 @@ class CreateBenchmarkCustom extends State } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/benchmarks/create_benchmark_page.dart b/lib/page/benchmarks/create_benchmark_page.dart index bac42c0..3933f0e 100644 --- a/lib/page/benchmarks/create_benchmark_page.dart +++ b/lib/page/benchmarks/create_benchmark_page.dart @@ -31,8 +31,8 @@ class _CreateBenchmarkPageState extends CreateBenchmarkCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/benchmarks/delete_benchmark_custom.dart b/lib/page/benchmarks/delete_benchmark_custom.dart index 17bce39..beefab1 100644 --- a/lib/page/benchmarks/delete_benchmark_custom.dart +++ b/lib/page/benchmarks/delete_benchmark_custom.dart @@ -21,7 +21,7 @@ class DeleteBenchmarkCustom extends State final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'DeleteBenchmark'); @@ -41,7 +41,7 @@ class DeleteBenchmarkCustom extends State child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -125,7 +125,7 @@ class DeleteBenchmarkCustom extends State FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Benchmarks/list'); }, child: Text(i18n.tr('Cancel')), @@ -142,7 +142,7 @@ class DeleteBenchmarkCustom extends State vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -172,7 +172,7 @@ class DeleteBenchmarkCustom extends State super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -182,7 +182,7 @@ class DeleteBenchmarkCustom extends State 'sql': 'delete', ':id': primaryKey }; - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { globalData.navigate(context, '/Benchmarks/list'); @@ -190,7 +190,7 @@ class DeleteBenchmarkCustom extends State } void onVerifyAndDelete() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onDelete(); } diff --git a/lib/page/benchmarks/delete_benchmark_page.dart b/lib/page/benchmarks/delete_benchmark_page.dart index d521ed4..e11e701 100644 --- a/lib/page/benchmarks/delete_benchmark_page.dart +++ b/lib/page/benchmarks/delete_benchmark_page.dart @@ -32,8 +32,8 @@ class _DeleteBenchmarkPageState extends DeleteBenchmarkCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/benchmarks/edit_benchmark_custom.dart b/lib/page/benchmarks/edit_benchmark_custom.dart index 147b644..de6c688 100644 --- a/lib/page/benchmarks/edit_benchmark_custom.dart +++ b/lib/page/benchmarks/edit_benchmark_custom.dart @@ -20,7 +20,7 @@ class EditBenchmarkCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditBenchmark'); @@ -40,7 +40,7 @@ class EditBenchmarkCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -124,7 +124,7 @@ class EditBenchmarkCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Benchmarks/list'); }, child: Text(i18n.tr('Cancel')), @@ -141,7 +141,7 @@ class EditBenchmarkCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -171,7 +171,7 @@ class EditBenchmarkCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -182,17 +182,17 @@ class EditBenchmarkCustom extends State with MessageLine { ':id': primaryKey }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); }); } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/benchmarks/edit_benchmark_page.dart b/lib/page/benchmarks/edit_benchmark_page.dart index 43e540f..53f305c 100644 --- a/lib/page/benchmarks/edit_benchmark_page.dart +++ b/lib/page/benchmarks/edit_benchmark_page.dart @@ -32,8 +32,8 @@ class _EditBenchmarkPageState extends EditBenchmarkCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/benchmarks/list_benchmark_custom.dart b/lib/page/benchmarks/list_benchmark_custom.dart index b20bc85..3dfcc0e 100644 --- a/lib/page/benchmarks/list_benchmark_custom.dart +++ b/lib/page/benchmarks/list_benchmark_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class ListBenchmarkCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateBenchmark'); @@ -43,7 +43,7 @@ class ListBenchmarkCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows( + final rows = attendedPage.getRows( dbData: snapshot.data!, columnList: 'benchmark_id;benchmark_lastname;benchmark_firstname;benchmark_birthday;benchmark_active;benchmark_income', @@ -91,7 +91,7 @@ class ListBenchmarkCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ @@ -116,7 +116,7 @@ class ListBenchmarkCustom extends State { ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -154,7 +154,7 @@ class ListBenchmarkCustom extends State { } void requestRecords() => - _futureDbData = globalData.restPersistence!.query(what: 'query', data: { + _futureDbData = globalData.restPersistence.query(what: 'query', data: { 'module': 'Benchmarks', 'sql': 'list', 'offset': _fieldData.theOffset, @@ -163,7 +163,7 @@ class ListBenchmarkCustom extends State { }); void search() { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); diff --git a/lib/page/benchmarks/list_benchmark_page.dart b/lib/page/benchmarks/list_benchmark_page.dart index 6e1c6af..6a65fa0 100644 --- a/lib/page/benchmarks/list_benchmark_page.dart +++ b/lib/page/benchmarks/list_benchmark_page.dart @@ -31,8 +31,8 @@ class _ListBenchmarkPageState extends ListBenchmarkCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/info_page.dart b/lib/page/info_page.dart index 9ae2ed8..e721ba2 100644 --- a/lib/page/info_page.dart +++ b/lib/page/info_page.dart @@ -63,14 +63,16 @@ Zur Entwicklung wurden einige **Opensource-Pakete** verwendet: String? href, String? title, ) async { - if (href!.startsWith('file:')) { - if (++clickCounter > 3) { - // globalData.navigate(context, '/configurations/base'); + if (href != null) { + if (href.startsWith('file:')) { + if (++clickCounter > 3) { + // globalData.navigate(context, '/configurations/base'); + } + } else { + await canLaunch(href) + ? await launch(href) + : globalData.logger.error('Could not launch $href'); } - } else { - await canLaunch(href) - ? await launch(href) - : globalData.logger.error('Could not launch $href'); } } diff --git a/lib/page/log_page.dart b/lib/page/log_page.dart index 81782e3..7028e22 100644 --- a/lib/page/log_page.dart +++ b/lib/page/log_page.dart @@ -47,7 +47,7 @@ class LogPageState extends State { } void store(context) async { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); } } diff --git a/lib/page/page_manager.dart b/lib/page/page_manager.dart index 581a5e4..c4d5ff0 100644 --- a/lib/page/page_manager.dart +++ b/lib/page/page_manager.dart @@ -10,6 +10,7 @@ import 'roles/create_role_page.dart'; import 'roles/edit_role_page.dart'; import 'roles/list_role_page.dart'; import 'rolestarter/mapping_rolestarter_page.dart'; +import 'rolestarter/list_rolestarter_page.dart'; import 'starters/create_starter_page.dart'; import 'starters/edit_starter_page.dart'; import 'starters/delete_starter_page.dart'; @@ -63,6 +64,9 @@ class PageManager { case '/RoleStarter/mapping': rc = MappingRoleStarterPage(); break; + case '/RoleStarter/list': + rc = ListRoleStarterPage(); + break; case '/Starters/create': rc = CreateStarterPage(); break; diff --git a/lib/page/roles/create_role_custom.dart b/lib/page/roles/create_role_custom.dart index 3929279..0de70da 100644 --- a/lib/page/roles/create_role_custom.dart +++ b/lib/page/roles/create_role_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class CreateRoleCustom extends State with MessageLine { final globalData = GlobalData(); - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateRole'); @@ -52,7 +52,7 @@ class CreateRoleCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Roles/list'); }, child: Text(i18n.tr('Cancel')), @@ -69,7 +69,7 @@ class CreateRoleCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -94,7 +94,7 @@ class CreateRoleCustom extends State with MessageLine { 'sql': 'insert', }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { if (answer.startsWith('id:')) { @@ -103,7 +103,7 @@ class CreateRoleCustom extends State with MessageLine { setError(i18n.tr('Saving data failed: $answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Roles/edit;$id'); } } @@ -111,7 +111,7 @@ class CreateRoleCustom extends State with MessageLine { } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/roles/create_role_page.dart b/lib/page/roles/create_role_page.dart index 2601a43..57426c9 100644 --- a/lib/page/roles/create_role_page.dart +++ b/lib/page/roles/create_role_page.dart @@ -31,8 +31,8 @@ class _CreateRolePageState extends CreateRoleCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/roles/edit_role_custom.dart b/lib/page/roles/edit_role_custom.dart index c853b7a..5b6d134 100644 --- a/lib/page/roles/edit_role_custom.dart +++ b/lib/page/roles/edit_role_custom.dart @@ -20,7 +20,7 @@ class EditRoleCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditRole'); @@ -35,7 +35,7 @@ class EditRoleCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -64,7 +64,7 @@ class EditRoleCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Roles/list'); }, child: Text(i18n.tr('Cancel')), @@ -81,7 +81,7 @@ class EditRoleCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -106,7 +106,7 @@ class EditRoleCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -117,17 +117,17 @@ class EditRoleCustom extends State with MessageLine { ':id': primaryKey }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); }); } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/roles/edit_role_page.dart b/lib/page/roles/edit_role_page.dart index 9a7a3d3..c720ac8 100644 --- a/lib/page/roles/edit_role_page.dart +++ b/lib/page/roles/edit_role_page.dart @@ -32,8 +32,8 @@ class _EditRolePageState extends EditRoleCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/roles/list_role_custom.dart b/lib/page/roles/list_role_custom.dart index 9f190cd..97c0f4b 100644 --- a/lib/page/roles/list_role_custom.dart +++ b/lib/page/roles/list_role_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class ListRoleCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateRole'); @@ -43,7 +43,7 @@ class ListRoleCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows( + final rows = attendedPage.getRows( dbData: snapshot.data!, columnList: 'role_id;role_name', onDone: () => setState(() => 1), @@ -90,7 +90,7 @@ class ListRoleCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ @@ -103,7 +103,7 @@ class ListRoleCustom extends State { ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -141,7 +141,7 @@ class ListRoleCustom extends State { } void requestRecords() => - _futureDbData = globalData.restPersistence!.query(what: 'query', data: { + _futureDbData = globalData.restPersistence.query(what: 'query', data: { 'module': 'Roles', 'sql': 'list', 'offset': _fieldData.theOffset, @@ -150,8 +150,8 @@ class ListRoleCustom extends State { }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); diff --git a/lib/page/roles/list_role_page.dart b/lib/page/roles/list_role_page.dart index 41a4331..fee466d 100644 --- a/lib/page/roles/list_role_page.dart +++ b/lib/page/roles/list_role_page.dart @@ -31,8 +31,8 @@ class _ListRolePageState extends ListRoleCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/rolestarter/list_rolestarter_custom.dart b/lib/page/rolestarter/list_rolestarter_custom.dart new file mode 100644 index 0000000..cf515f5 --- /dev/null +++ b/lib/page/rolestarter/list_rolestarter_custom.dart @@ -0,0 +1,163 @@ +// This file is created by the meta_tool. But it can be customized. +// It will never overridden by the meta_tool. +import 'package:flutter/material.dart'; + +import '../../base/defines.dart'; +import '../../base/helper.dart'; +import '../../base/i18n.dart'; +import '../../services/global_widget.dart'; +import '../../setting/global_data.dart'; +import '../../widget/attended_page.dart'; +import '../../widget/widget_form.dart'; +import '../../persistence/persistence.dart'; +import 'list_rolestarter_page.dart'; + +final i18n = I18N(); + +class ListRoleStarterCustom extends State { + final globalData = GlobalData(); + late Future _futureDbData; + late AttendedPage attendedPage; + final _fieldData = _FieldData(); + final GlobalKey _formKey = + GlobalKey(debugLabel: 'CreateRoleStarter'); + ListRoleStarterCustom(); + @override + Widget build(BuildContext context) { + final rc = Scaffold( + appBar: globalData.appBarBuilder(i18n.tr('Overview rolestarter')), + drawer: globalData.drawerBuilder(context), + floatingActionButton: FloatingActionButton( + onPressed: () { + globalData.navigate(context, '/RoleStarter/create'); + }, + child: const Icon(Icons.add), + tooltip: null), + body: SafeArea( + child: FutureBuilder( + future: _futureDbData, + builder: (context, snapshot) { + Widget rc; + if (snapshot.connectionState != ConnectionState.done) { + rc = const CircularProgressIndicator(); + } else { + if (snapshot.hasData) { + final rows = attendedPage.getRows( + dbData: snapshot.data!, + columnList: + 'rolestarter_id;rolestarter_position;role;starter', + onDone: () => setState(() => 1), + routeEdit: '/RoleStarter/edit', + context: context); + rc = buildFrame( + totalCount: snapshot.data?.count ?? rows.length, rows: rows); + } else if (snapshot.hasError) { + rc = Text('Backend problem: ${snapshot.error}'); + } else { + rc = const CircularProgressIndicator(); + } + } + return rc; + }, + )), + ); + return rc; + } + + Widget buildFrame({required JsonList rows, required int totalCount}) { + final padding = GlobalThemeData.padding; + final formItems = [ + FormItem( + ElevatedButton( + onPressed: () => search(), child: Text(i18n.tr('Search'))), + weight: 12, + gapAbove: padding), + ]; + final form = Form( + key: _formKey, + child: Card( + color: GlobalThemeData.formBackgroundColor, + elevation: GlobalThemeData.formElevation, + margin: + EdgeInsets.symmetric(vertical: padding, horizontal: padding), + child: Padding( + padding: EdgeInsets.symmetric( + vertical: padding, horizontal: padding), + child: WidgetForm.flexibleGrid(formItems, + screenWidth: attendedPage.pageStates.screenWidth, + padding: padding)))); + final table = DataTable( + columns: [ + DataColumn( + label: Text(i18n.tr('Id')), + ), + DataColumn( + label: Text(i18n.tr('Position')), + ), + DataColumn( + label: Text(i18n.tr('Role')), + ), + DataColumn( + label: Text(i18n.tr('Starter')), + ), + ], + rows: rows as List, + ); + Widget? tabBar = attendedPage.buildChipBar( + totalCount: totalCount, + offset: _fieldData.theOffset, + pageSize: _fieldData.thePageSize, + onTap: (offset) { + _fieldData.theOffset = offset; + requestRecords(); + setState(() => 1); + }); + final frameWidget = ListView(children: [ + form, + if (tabBar != null) tabBar, + SizedBox(height: padding), + SizedBox(width: double.infinity, child: table), + ]); + return frameWidget; + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + requestRecords(); + } + + @override + void dispose() { + helperDummyUsage(DataType.string); + globalWidgetDummyUsage(); + super.dispose(); + } + + @override + void initState() { + super.initState(); + } + + void requestRecords() => + _futureDbData = globalData.restPersistence.query(what: 'query', data: { + 'module': 'RoleStarter', + 'sql': 'list', + 'offset': _fieldData.theOffset, + 'size': _fieldData.thePageSize, + }); + + void search() { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { + _formKey.currentState!.save(); + requestRecords(); + setState(() => 1); + } + } +} + +class _FieldData { + int thePageSize = 10; + int theOffset = 0; +} diff --git a/lib/page/rolestarter/list_rolestarter_page.dart b/lib/page/rolestarter/list_rolestarter_page.dart new file mode 100644 index 0000000..0d1b5b9 --- /dev/null +++ b/lib/page/rolestarter/list_rolestarter_page.dart @@ -0,0 +1,61 @@ +// DO NOT CHANGE. This file is created by the meta_tool! +import 'package:flutter/material.dart'; + +import '../../meta/rolestarter_meta.dart'; +import '../../setting/global_data.dart'; +import '../../widget/attended_page.dart'; +import 'list_rolestarter_custom.dart'; + +class ListRoleStarterPage extends StatefulWidget { + final PageStates pageStates = PageStates(); + ListRoleStarterPage() : super(); + @override + _ListRoleStarterPageState createState() { + final rc = _ListRoleStarterPageState(); + rc.attendedPage = AttendedPage( + this, + rc, + GlobalData(), + RoleStarterMeta.instance.pageByName('list')!, + RoleStarterMeta.instance, + pageStates, + (afterReload, rebuild) => + rc.reload(afterReload: afterReload, rebuild: rebuild)); + pageStates.attendedPage = rc.attendedPage; + return rc; + } +} + +class _ListRoleStarterPageState extends ListRoleStarterCustom { + _ListRoleStarterPageState() : super(); + @override + void didChangeDependencies() { + final size = MediaQuery.of(context).size; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; + super.didChangeDependencies(); + } + + /// Renders the widget tree again. + /// + /// [afterReload] is a function used as parameter of setState(). + /// + /// If [rebuild] is true the state has been changed and didChangeDependencies() + /// will be called. + void reload({Function? afterReload, bool rebuild = false}) { + if (afterReload == null) { + if (rebuild) { + setState(() => didChangeDependencies()); + } else { + setState(() => 1); + } + } else { + setState(() { + afterReload(); + if (rebuild) { + didChangeDependencies(); + } + }); + } + } +} diff --git a/lib/page/rolestarter/mapping_rolestarter_custom.dart b/lib/page/rolestarter/mapping_rolestarter_custom.dart new file mode 100644 index 0000000..c03e7da --- /dev/null +++ b/lib/page/rolestarter/mapping_rolestarter_custom.dart @@ -0,0 +1,304 @@ +// This file is created by the meta_tool. But it can be customized. +// It will never overridden by the meta_tool. +import 'package:flutter/material.dart'; + +import '../../base/defines.dart'; +import '../../base/helper.dart'; +import '../../base/i18n.dart'; +import '../../persistence/persistence.dart'; +import '../../services/global_widget.dart'; +import '../../setting/global_data.dart'; +import '../../widget/attended_page.dart'; +import '../../widget/widget_form.dart'; +import 'mapping_rolestarter_page.dart'; + +final i18n = I18N(); + +class CommonInfo { + final List columns; + final List members = []; + CommonInfo({required this.columns}); +} + +class MappingRoleStarterCustom extends State { + final globalData = GlobalData(); + late Future _futureDbDataCommon; + late Future _futureDbDataMember; + late Future _futureDbDataConnection; + var membersOfCommon = >{}; + late AttendedPage attendedPage; + final _fieldData = _FieldData(); + final GlobalKey _formKey = + GlobalKey(debugLabel: 'CreateRole'); + final textController = TextEditingController(); + final commonColumns = ['role_name']; + final memberColumns = ['starter_name', 'starter_route']; + final commonInfos = {}; + + /// Members of the current common module: + final memberInfos = []; + + final notMemberInfos = []; + JsonList membersRows = []; + JsonList commonRows = []; + JsonList connectionRows = []; + MappingRoleStarterCustom(); + + @override + Widget build(BuildContext context) { + final rc = Scaffold( + appBar: globalData.appBarBuilder(i18n.tr('Role/Starter Assignment')), + drawer: globalData.drawerBuilder(context), + body: SafeArea( + child: FutureBuilder>( + future: Future.wait([ + _futureDbDataMember, + _futureDbDataCommon, + _futureDbDataConnection + ]), + builder: (context, AsyncSnapshot> snapshot) { + Widget rc; + if (snapshot.connectionState != ConnectionState.done) { + rc = const CircularProgressIndicator(); + } else { + if (snapshot.hasData) { + commonRows = snapshot.data![0].recordList ?? []; + membersRows = snapshot.data![1].recordList ?? []; + connectionRows = snapshot.data![2].recordList ?? []; + handleConnectionRows(); + rc = buildFrame(); + } else if (snapshot.hasError) { + rc = Text('Backend problem: ${snapshot.error}'); + } else { + rc = const CircularProgressIndicator(); + } + } + return rc; + }, + )), + ); + return rc; + } + + /// Builds the items of the common module combobox from the database records. + List> buildCommonItems() { + final rc = >[]; + for (var record in commonRows) { + rc.add(DropdownMenuItem( + value: record['role_id'], child: Text(record['role_name']))); + } + return rc; + } + + Widget buildFrame() { + final padding = GlobalThemeData.padding; + final itemsRoles = >[]; + final formItems = [ + FormItem( + DropdownButtonFormField( + value: itemsRoles.length == 1 ? 0 : _fieldData.role, + items: buildCommonItems(), + isExpanded: true, + decoration: InputDecoration(labelText: i18n.tr('Role')), + onChanged: (value) => _fieldData.role = value ?? 0, + ), + weight: 6), + FormItem( + ElevatedButton(onPressed: () => save(), child: Text(i18n.tr('Save'))), + weight: 12, + gapAbove: padding), + ]; + final form = Form( + key: _formKey, + child: Card( + color: GlobalThemeData.formBackgroundColor, + elevation: GlobalThemeData.formElevation, + margin: + EdgeInsets.symmetric(vertical: padding, horizontal: padding), + child: Padding( + padding: EdgeInsets.symmetric( + vertical: padding, horizontal: padding), + child: WidgetForm.flexibleGrid(formItems, + screenWidth: attendedPage.pageStates.screenWidth, + padding: padding)))); + final tableMembers = buildMemberTable(); + final tableNotMembers = buildNotMemberTable(); + final frameWidget = ListView(children: [ + form, + Text(i18n.tr('The following items are assigned. Click it to remove.')), + SizedBox(height: padding), + tableMembers, + SizedBox(height: padding), + Text( + i18n.tr('The following items are not assigned. Click it to assign.')), + SizedBox(height: padding), + tableNotMembers, + ]); + return frameWidget; + } + + buildMemberTable() { + final rows = buildTableItems( + commonInfos[_fieldData.role]!.members, 'rolestarter_id'); + final headers = []; + for (var column in commonInfos[_fieldData.role]!.columns) { + final label = + attendedPage.moduleMetaData.propertyByColumnName(column)?.label ?? + i18n.tr('Info'); + headers.add(DataColumn(label: Text(label))); + } + final rc = DataTable( + columns: headers, + rows: rows, + ); + return rc; + } + + buildNotMemberTable() { + final rows = buildTableItems( + commonInfos[_fieldData.role]!.members, 'rolestarter_id'); + final headers = []; + for (var column in commonInfos[_fieldData.role]!.columns) { + final label = + attendedPage.moduleMetaData.propertyByColumnName(column)?.label ?? + i18n.tr('Info'); + headers.add(DataColumn(label: Text(label))); + } + final rc = DataTable( + columns: headers, + rows: rows, + ); + return rc; + } + + /// Build the [notMemberInfos] list of items not being members of the common + /// module with [commonId]. + void buildNotMembers(int commonId) { + notMemberInfos.clear(); + int order = 10; + for (var record in membersRows) { + final id = record['rolestarter_starter']; + if (record['rolestarter_role'] == commonId && !hasMember(id)) { + notMemberInfos.add(MemberInfo( + memberId: id, position: order++, columns: memberColumns)); + } + } + } + + buildTableItems(List members, String primary) { + members.map((MemberInfo element) { + final cells = []; + final record = findRecord(membersRows, primary, element.memberId); + if (record != null) { + for (var column in element.columns) { + cells.add(DataCell(Text(record[column]))); + } + } + return DataRow(cells: cells); + }); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + requestRecords(); + } + + @override + void dispose() { + helperDummyUsage(DataType.string); + globalWidgetDummyUsage(); + textController.dispose(); + super.dispose(); + } + + /// Finds a record in a list of records by a given [id] in a given [column]. + JsonMap? findRecord(JsonList rows, String column, int id) { + JsonMap? rc; + for (var record in rows) { + if (record[column] == id) { + rc = record; + break; + } + } + return rc; + } + + /// Inspects the [connectionRows] and build the internal structures. + void handleConnectionRows() { + commonInfos.clear(); + for (var record in commonRows) { + int common = record['role_id']; + commonInfos[common] = CommonInfo(columns: commonColumns); + } + for (var record in connectionRows) { + int common = record['rolestarter_role']; + if (!commonInfos.containsKey(common)) { + commonInfos[common] = CommonInfo(columns: commonColumns); + } + commonInfos[common]!.members.add(MemberInfo( + memberId: record['rolestarter_starter'], + columns: memberColumns, + position: record['rolestarter_position'])); + } + for (var key in commonInfos.keys) { + commonInfos[key]!.members.sort((a, b) => a.position - b.position); + } + } + + /// Returns whether the given [memberId] is part of [memberInfos]. + bool hasMember(int memberId) { + bool rc = false; + for (var item in memberInfos) { + if (item.memberId == memberId) { + rc = true; + break; + } + } + return rc; + } + + @override + void initState() { + super.initState(); + } + + void requestRecords() { + _futureDbDataMember = + globalData.restPersistence.query(what: 'query', data: { + 'module': 'Starters', + 'sql': 'all', + }); + _futureDbDataCommon = + globalData.restPersistence.query(what: 'query', data: { + 'module': 'Roles', + 'sql': 'all', + }); + _futureDbDataConnection = + globalData.restPersistence.query(what: 'query', data: { + 'module': 'RoleStarter', + 'sql': 'all', + }); + } + + void save() { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState!.validate()) { + _formKey.currentState!.save(); + requestRecords(); + setState(() => 1); + } + } +} + +class MemberInfo { + final int memberId; + final int position; + final List columns; + MemberInfo( + {required this.memberId, required this.position, required this.columns}); +} + +class _FieldData { + int role = 0; +} diff --git a/lib/page/rolestarter/mapping_rolestarter_page.dart b/lib/page/rolestarter/mapping_rolestarter_page.dart new file mode 100644 index 0000000..4c97680 --- /dev/null +++ b/lib/page/rolestarter/mapping_rolestarter_page.dart @@ -0,0 +1,61 @@ +// DO NOT CHANGE. This file is created by the meta_tool! +import 'package:flutter/material.dart'; + +import '../../meta/rolestarter_meta.dart'; +import '../../setting/global_data.dart'; +import '../../widget/attended_page.dart'; +import 'mapping_rolestarter_custom.dart'; + +class MappingRoleStarterPage extends StatefulWidget { + final PageStates pageStates = PageStates(); + MappingRoleStarterPage() : super(); + @override + _MappingRoleStarterPageState createState() { + final rc = _MappingRoleStarterPageState(); + rc.attendedPage = AttendedPage( + this, + rc, + GlobalData(), + RoleStarterMeta.instance.pageByName('mapping')!, + RoleStarterMeta.instance, + pageStates, + (afterReload, rebuild) => + rc.reload(afterReload: afterReload, rebuild: rebuild)); + pageStates.attendedPage = rc.attendedPage; + return rc; + } +} + +class _MappingRoleStarterPageState extends MappingRoleStarterCustom { + _MappingRoleStarterPageState() : super(); + @override + void didChangeDependencies() { + final size = MediaQuery.of(context).size; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; + super.didChangeDependencies(); + } + + /// Renders the widget tree again. + /// + /// [afterReload] is a function used as parameter of setState(). + /// + /// If [rebuild] is true the state has been changed and didChangeDependencies() + /// will be called. + void reload({Function? afterReload, bool rebuild = false}) { + if (afterReload == null) { + if (rebuild) { + setState(() => didChangeDependencies()); + } else { + setState(() => 1); + } + } else { + setState(() { + afterReload(); + if (rebuild) { + didChangeDependencies(); + } + }); + } + } +} diff --git a/lib/page/rolestarter/role_starter_data.dart b/lib/page/rolestarter/role_starter_data.dart new file mode 100644 index 0000000..2e761f3 --- /dev/null +++ b/lib/page/rolestarter/role_starter_data.dart @@ -0,0 +1,114 @@ +// DO NOT CHANGE. This file is created by the meta_tool +import '../../base/defines.dart'; +import '../../base/helper.dart'; +import '../../persistence/data_record.dart'; + +class RoleStarterData extends DataRecord { + int? id; + int? role; + int? starter; + int? order; + DateTime? createdAt; + String? createdBy; + DateTime? changedAt; + String? changedBy; + RoleStarterData( + {this.id, + this.role, + this.starter, + this.order, + this.createdAt, + this.createdBy, + this.changedAt, + this.changedBy}); + RoleStarterData.createFromMap(DataMap map) { + fromMap(map); + } + @override + void fromMap(DataMap map) { + id = map.containsKey('rolestarter_id') + ? fromString(map['rolestarter_id'], dataType: DataType.reference) + : null; + role = map.containsKey('rolestarter_role') + ? fromString(map['rolestarter_role'], dataType: DataType.reference) + : null; + starter = map.containsKey('rolestarter_starter') + ? fromString(map['rolestarter_starter'], dataType: DataType.reference) + : null; + order = map.containsKey('rolestarter_order') + ? fromString(map['rolestarter_order'], dataType: DataType.int) + : null; + createdAt = map.containsKey('rolestarter_createdat') + ? fromString(map['rolestarter_createdat'], dataType: DataType.datetime) + : null; + createdBy = map.containsKey('rolestarter_createdby') + ? fromString(map['rolestarter_createdby'], dataType: DataType.string) + : null; + changedAt = map.containsKey('rolestarter_changedat') + ? fromString(map['rolestarter_changedat'], dataType: DataType.datetime) + : null; + changedBy = map.containsKey('rolestarter_changedby') + ? fromString(map['rolestarter_changedby'], dataType: DataType.string) + : null; + } + + @override + int keyOf() { + return id ?? 0; + } + + @override + String nameOfKey() { + return 'rolestarter_id'; + } + + static DataType? dataTypeOf(String name) { + DataType? rc; + switch (name) { + case 'id': + rc = DataType.reference; + break; + case 'role': + rc = DataType.reference; + break; + case 'starter': + rc = DataType.reference; + break; + case 'order': + rc = DataType.int; + break; + case 'createdAt': + rc = DataType.datetime; + break; + case 'createdBy': + rc = DataType.string; + break; + case 'changedAt': + rc = DataType.datetime; + break; + case 'changedBy': + rc = DataType.string; + break; + default: + break; + } + return rc; + } + + @override + DataMap toMap({DataMap? map, bool clear = true}) { + map ??= DataMap(); + if (clear) { + map.clear(); + } + map['rolestarter_id'] = id; + map['rolestarter_role'] = role; + map['rolestarter_starter'] = starter; + map['rolestarter_order'] = order; + map['rolestarter_createdat'] = createdAt; + map['rolestarter_createdby'] = createdBy; + map['rolestarter_changedat'] = changedAt; + map['rolestarter_changedby'] = changedBy; + return map; + } +} diff --git a/lib/page/start_page.dart b/lib/page/start_page.dart index ab5b3b0..845dc5c 100644 --- a/lib/page/start_page.dart +++ b/lib/page/start_page.dart @@ -96,7 +96,7 @@ class StartPageState extends State { RestPersistence.fromConfig(configuration, logger), logger); globalData.initializeAsync().then((value) { - globalData.navigate(context, '/Starters/list'); + globalData.navigate(context, '/RoleStarter/mapping'); }); } }); diff --git a/lib/page/starters/create_starter_custom.dart b/lib/page/starters/create_starter_custom.dart index fffaf2f..bfe2ccb 100644 --- a/lib/page/starters/create_starter_custom.dart +++ b/lib/page/starters/create_starter_custom.dart @@ -17,12 +17,12 @@ final i18n = I18N(); class CreateStarterCustom extends State with MessageLine { final globalData = GlobalData(); - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateStarter'); final nameController = TextEditingController(); - final linkController = TextEditingController(); + final routeController = TextEditingController(); final iconController = TextEditingController(); CreateStarterCustom(); @override @@ -37,7 +37,7 @@ class CreateStarterCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; nameController.text = _fieldData.name; - linkController.text = _fieldData.link; + routeController.text = _fieldData.route; iconController.text = _fieldData.icon; final formItems = [ FormItem( @@ -49,10 +49,10 @@ class CreateStarterCustom extends State with MessageLine { weight: 6), FormItem( TextFormField( - controller: linkController, - decoration: InputDecoration(labelText: i18n.tr('Link')), + controller: routeController, + decoration: InputDecoration(labelText: i18n.tr('Route')), validator: (input) => notEmpty(input), - onSaved: (value) => _fieldData.link = value ?? ''), + onSaved: (value) => _fieldData.route = value ?? ''), weight: 6), FormItem( TextFormField( @@ -70,7 +70,7 @@ class CreateStarterCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Starters/list'); }, child: Text(i18n.tr('Cancel')), @@ -87,7 +87,7 @@ class CreateStarterCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -98,7 +98,7 @@ class CreateStarterCustom extends State with MessageLine { helperDummyUsage(DataType.int); globalWidgetDummyUsage(); nameController.dispose(); - linkController.dispose(); + routeController.dispose(); iconController.dispose(); super.dispose(); } @@ -114,7 +114,7 @@ class CreateStarterCustom extends State with MessageLine { 'sql': 'insert', }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { if (answer.startsWith('id:')) { @@ -123,7 +123,7 @@ class CreateStarterCustom extends State with MessageLine { setError(i18n.tr('Saving data failed: $answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Starters/edit;$id'); } } @@ -131,7 +131,7 @@ class CreateStarterCustom extends State with MessageLine { } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } @@ -140,12 +140,12 @@ class CreateStarterCustom extends State with MessageLine { class _FieldData { String name = ''; - String link = ''; + String route = ''; String icon = ''; void toMap(Map map) { map[':name'] = name; - map[':link'] = link; + map[':route'] = route; map[':icon'] = icon; map[':createdBy'] = GlobalData.loginUserName; } diff --git a/lib/page/starters/create_starter_page.dart b/lib/page/starters/create_starter_page.dart index 29fc58b..5834647 100644 --- a/lib/page/starters/create_starter_page.dart +++ b/lib/page/starters/create_starter_page.dart @@ -31,8 +31,8 @@ class _CreateStarterPageState extends CreateStarterCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/starters/delete_starter_custom.dart b/lib/page/starters/delete_starter_custom.dart index c99708d..77d91f9 100644 --- a/lib/page/starters/delete_starter_custom.dart +++ b/lib/page/starters/delete_starter_custom.dart @@ -20,12 +20,12 @@ class DeleteStarterCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'DeleteStarter'); final nameController = TextEditingController(); - final linkController = TextEditingController(); + final routeController = TextEditingController(); final iconController = TextEditingController(); DeleteStarterCustom(this.primaryKey); @override @@ -37,7 +37,7 @@ class DeleteStarterCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -49,7 +49,7 @@ class DeleteStarterCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; nameController.text = _fieldData.name; - linkController.text = _fieldData.link; + routeController.text = _fieldData.route; iconController.text = _fieldData.icon; final formItems = [ FormItem( @@ -61,10 +61,10 @@ class DeleteStarterCustom extends State with MessageLine { weight: 6), FormItem( TextFormField( - controller: linkController, - decoration: InputDecoration(labelText: i18n.tr('Link')), + controller: routeController, + decoration: InputDecoration(labelText: i18n.tr('Route')), validator: (input) => notEmpty(input), - onSaved: (value) => _fieldData.link = value ?? ''), + onSaved: (value) => _fieldData.route = value ?? ''), weight: 6), FormItem( TextFormField( @@ -82,7 +82,7 @@ class DeleteStarterCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Starters/list'); }, child: Text(i18n.tr('Cancel')), @@ -99,7 +99,7 @@ class DeleteStarterCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -116,7 +116,7 @@ class DeleteStarterCustom extends State with MessageLine { helperDummyUsage(DataType.int); globalWidgetDummyUsage(); nameController.dispose(); - linkController.dispose(); + routeController.dispose(); iconController.dispose(); super.dispose(); } @@ -126,7 +126,7 @@ class DeleteStarterCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -136,7 +136,7 @@ class DeleteStarterCustom extends State with MessageLine { 'sql': 'delete', ':id': primaryKey }; - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { globalData.navigate(context, '/Starters/list'); @@ -144,7 +144,7 @@ class DeleteStarterCustom extends State with MessageLine { } void onVerifyAndDelete() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onDelete(); } @@ -153,12 +153,12 @@ class DeleteStarterCustom extends State with MessageLine { class _FieldData { String name = ''; - String link = ''; + String route = ''; String icon = ''; void fromMap(Map map) { name = map['starter_name']; - link = map['starter_link']; + route = map['starter_route']; icon = map['starter_icon']; } } diff --git a/lib/page/starters/delete_starter_page.dart b/lib/page/starters/delete_starter_page.dart index 9d872e6..0d16fe3 100644 --- a/lib/page/starters/delete_starter_page.dart +++ b/lib/page/starters/delete_starter_page.dart @@ -32,8 +32,8 @@ class _DeleteStarterPageState extends DeleteStarterCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/starters/edit_starter_custom.dart b/lib/page/starters/edit_starter_custom.dart index 60c5384..2dd6b6a 100644 --- a/lib/page/starters/edit_starter_custom.dart +++ b/lib/page/starters/edit_starter_custom.dart @@ -20,12 +20,12 @@ class EditStarterCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditStarter'); final nameController = TextEditingController(); - final linkController = TextEditingController(); + final routeController = TextEditingController(); final iconController = TextEditingController(); EditStarterCustom(this.primaryKey); @override @@ -37,7 +37,7 @@ class EditStarterCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -49,7 +49,7 @@ class EditStarterCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; nameController.text = _fieldData.name; - linkController.text = _fieldData.link; + routeController.text = _fieldData.route; iconController.text = _fieldData.icon; final formItems = [ FormItem( @@ -61,10 +61,10 @@ class EditStarterCustom extends State with MessageLine { weight: 6), FormItem( TextFormField( - controller: linkController, - decoration: InputDecoration(labelText: i18n.tr('Link')), + controller: routeController, + decoration: InputDecoration(labelText: i18n.tr('Route')), validator: (input) => notEmpty(input), - onSaved: (value) => _fieldData.link = value ?? ''), + onSaved: (value) => _fieldData.route = value ?? ''), weight: 6), FormItem( TextFormField( @@ -82,7 +82,7 @@ class EditStarterCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Starters/list'); }, child: Text(i18n.tr('Cancel')), @@ -99,7 +99,7 @@ class EditStarterCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -116,7 +116,7 @@ class EditStarterCustom extends State with MessageLine { helperDummyUsage(DataType.int); globalWidgetDummyUsage(); nameController.dispose(); - linkController.dispose(); + routeController.dispose(); iconController.dispose(); super.dispose(); } @@ -126,7 +126,7 @@ class EditStarterCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -137,17 +137,17 @@ class EditStarterCustom extends State with MessageLine { ':id': primaryKey }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); }); } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } @@ -156,19 +156,19 @@ class EditStarterCustom extends State with MessageLine { class _FieldData { String name = ''; - String link = ''; + String route = ''; String icon = ''; void fromMap(Map map) { name = map['starter_name']; - link = map['starter_link']; + route = map['starter_route']; icon = map['starter_icon']; } void toMap(Map map) { // please set outside: map[':id'] = primaryKey; map[':name'] = name; - map[':link'] = link; + map[':route'] = route; map[':icon'] = icon; map[':changedBy'] = GlobalData.loginUserName; } diff --git a/lib/page/starters/edit_starter_page.dart b/lib/page/starters/edit_starter_page.dart index a1022ae..2768e25 100644 --- a/lib/page/starters/edit_starter_page.dart +++ b/lib/page/starters/edit_starter_page.dart @@ -32,8 +32,8 @@ class _EditStarterPageState extends EditStarterCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/starters/list_starter_custom.dart b/lib/page/starters/list_starter_custom.dart index e2cce7e..e9de7ab 100644 --- a/lib/page/starters/list_starter_custom.dart +++ b/lib/page/starters/list_starter_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class ListStarterCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateStarter'); @@ -43,10 +43,10 @@ class ListStarterCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows( + final rows = attendedPage.getRows( dbData: snapshot.data!, columnList: - 'starter_id;starter_name;starter_link;starter_icon', + 'starter_id;starter_name;starter_route;starter_icon', onDone: () => setState(() => 1), routeEdit: '/Starters/edit', context: context); @@ -91,7 +91,7 @@ class ListStarterCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ @@ -102,7 +102,7 @@ class ListStarterCustom extends State { label: Text(i18n.tr('Name')), ), DataColumn( - label: Text(i18n.tr('Link')), + label: Text(i18n.tr('Route')), ), DataColumn( label: Text(i18n.tr('Icon')), @@ -110,7 +110,7 @@ class ListStarterCustom extends State { ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -148,7 +148,7 @@ class ListStarterCustom extends State { } void requestRecords() => - _futureDbData = globalData.restPersistence!.query(what: 'query', data: { + _futureDbData = globalData.restPersistence.query(what: 'query', data: { 'module': 'Starters', 'sql': 'list', 'offset': _fieldData.theOffset, @@ -157,8 +157,8 @@ class ListStarterCustom extends State { }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); diff --git a/lib/page/starters/list_starter_page.dart b/lib/page/starters/list_starter_page.dart index a0849ef..795a7d2 100644 --- a/lib/page/starters/list_starter_page.dart +++ b/lib/page/starters/list_starter_page.dart @@ -31,8 +31,8 @@ class _ListStarterPageState extends ListStarterCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/starters/starter_data.dart b/lib/page/starters/starter_data.dart index cf9a884..46c8085 100644 --- a/lib/page/starters/starter_data.dart +++ b/lib/page/starters/starter_data.dart @@ -6,7 +6,7 @@ import '../../persistence/data_record.dart'; class StarterData extends DataRecord { int? id; String? name; - String? link; + String? route; String? icon; DateTime? createdAt; String? createdBy; @@ -15,7 +15,7 @@ class StarterData extends DataRecord { StarterData( {this.id, this.name, - this.link, + this.route, this.icon, this.createdAt, this.createdBy, @@ -32,8 +32,8 @@ class StarterData extends DataRecord { name = map.containsKey('starter_name') ? fromString(map['starter_name'], dataType: DataType.string) : null; - link = map.containsKey('starter_link') - ? fromString(map['starter_link'], dataType: DataType.string) + route = map.containsKey('starter_route') + ? fromString(map['starter_route'], dataType: DataType.string) : null; icon = map.containsKey('starter_icon') ? fromString(map['starter_icon'], dataType: DataType.string) @@ -71,7 +71,7 @@ class StarterData extends DataRecord { case 'name': rc = DataType.string; break; - case 'link': + case 'route': rc = DataType.string; break; case 'icon': @@ -103,7 +103,7 @@ class StarterData extends DataRecord { } map['starter_id'] = id; map['starter_name'] = name; - map['starter_link'] = link; + map['starter_route'] = route; map['starter_icon'] = icon; map['starter_createdat'] = createdAt; map['starter_createdby'] = createdBy; diff --git a/lib/page/structures/create_structure_custom.dart b/lib/page/structures/create_structure_custom.dart index df1e153..13de279 100644 --- a/lib/page/structures/create_structure_custom.dart +++ b/lib/page/structures/create_structure_custom.dart @@ -18,7 +18,7 @@ final i18n = I18N(); class CreateStructureCustom extends State with MessageLine { final globalData = GlobalData(); - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateStructure'); @@ -80,7 +80,7 @@ class CreateStructureCustom extends State FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Structures/list'); }, child: Text(i18n.tr('Cancel')), @@ -97,7 +97,7 @@ class CreateStructureCustom extends State vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -125,7 +125,7 @@ class CreateStructureCustom extends State 'sql': 'insert', }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { if (answer.startsWith('id:')) { @@ -134,7 +134,7 @@ class CreateStructureCustom extends State setError(i18n.tr('Saving data failed: $answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Structures/edit;$id'); } } @@ -142,7 +142,7 @@ class CreateStructureCustom extends State } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/structures/create_structure_page.dart b/lib/page/structures/create_structure_page.dart index a46570b..ab007e1 100644 --- a/lib/page/structures/create_structure_page.dart +++ b/lib/page/structures/create_structure_page.dart @@ -31,8 +31,8 @@ class _CreateStructurePageState extends CreateStructureCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/structures/delete_structure_custom.dart b/lib/page/structures/delete_structure_custom.dart index f20a98b..043bc26 100644 --- a/lib/page/structures/delete_structure_custom.dart +++ b/lib/page/structures/delete_structure_custom.dart @@ -21,7 +21,7 @@ class DeleteStructureCustom extends State final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'DeleteStructure'); @@ -39,7 +39,7 @@ class DeleteStructureCustom extends State child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -92,7 +92,7 @@ class DeleteStructureCustom extends State FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Structures/list'); }, child: Text(i18n.tr('Cancel')), @@ -109,7 +109,7 @@ class DeleteStructureCustom extends State vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -137,7 +137,7 @@ class DeleteStructureCustom extends State super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -147,7 +147,7 @@ class DeleteStructureCustom extends State 'sql': 'delete', ':id': primaryKey }; - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { globalData.navigate(context, '/Structures/list'); @@ -155,7 +155,7 @@ class DeleteStructureCustom extends State } void onVerifyAndDelete() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onDelete(); } diff --git a/lib/page/structures/delete_structure_page.dart b/lib/page/structures/delete_structure_page.dart index b974f29..dda5535 100644 --- a/lib/page/structures/delete_structure_page.dart +++ b/lib/page/structures/delete_structure_page.dart @@ -32,8 +32,8 @@ class _DeleteStructurePageState extends DeleteStructureCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/structures/edit_structure_custom.dart b/lib/page/structures/edit_structure_custom.dart index c96e9ba..309734d 100644 --- a/lib/page/structures/edit_structure_custom.dart +++ b/lib/page/structures/edit_structure_custom.dart @@ -20,7 +20,7 @@ class EditStructureCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditStructure'); @@ -38,7 +38,7 @@ class EditStructureCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -91,7 +91,7 @@ class EditStructureCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Structures/list'); }, child: Text(i18n.tr('Cancel')), @@ -108,7 +108,7 @@ class EditStructureCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -136,7 +136,7 @@ class EditStructureCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -147,17 +147,17 @@ class EditStructureCustom extends State with MessageLine { ':id': primaryKey }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); }); } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/structures/edit_structure_page.dart b/lib/page/structures/edit_structure_page.dart index b8c92b9..5c4ef5f 100644 --- a/lib/page/structures/edit_structure_page.dart +++ b/lib/page/structures/edit_structure_page.dart @@ -32,8 +32,8 @@ class _EditStructurePageState extends EditStructureCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/structures/list_structure_custom.dart b/lib/page/structures/list_structure_custom.dart index 952c08c..4cec578 100644 --- a/lib/page/structures/list_structure_custom.dart +++ b/lib/page/structures/list_structure_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class ListStructureCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateStructure'); @@ -43,7 +43,7 @@ class ListStructureCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows( + final rows = attendedPage.getRows( dbData: snapshot.data!, columnList: 'structure_id;structure_scope;structure_name;structure_value;structure_position', @@ -91,7 +91,7 @@ class ListStructureCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ @@ -113,7 +113,7 @@ class ListStructureCustom extends State { ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -151,7 +151,7 @@ class ListStructureCustom extends State { } void requestRecords() => - _futureDbData = globalData.restPersistence!.query(what: 'query', data: { + _futureDbData = globalData.restPersistence.query(what: 'query', data: { 'module': 'Structures', 'sql': 'list', 'offset': _fieldData.theOffset, @@ -160,8 +160,8 @@ class ListStructureCustom extends State { }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); diff --git a/lib/page/structures/list_structure_page.dart b/lib/page/structures/list_structure_page.dart index cc03dc1..4b6d716 100644 --- a/lib/page/structures/list_structure_page.dart +++ b/lib/page/structures/list_structure_page.dart @@ -31,8 +31,8 @@ class _ListStructurePageState extends ListStructureCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/users/create_user_custom.dart b/lib/page/users/create_user_custom.dart index 5efce7c..8265748 100644 --- a/lib/page/users/create_user_custom.dart +++ b/lib/page/users/create_user_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class CreateUserCustom extends State with MessageLine { final globalData = GlobalData(); - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateUser'); @@ -37,9 +37,9 @@ class CreateUserCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; comboRolesFromBackend( - attendedPage: attendedPage!, onDone: () => setState(() => 1)); - final itemsRoles = comboRoles( - i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage!); + attendedPage: attendedPage, onDone: () => setState(() => 1)); + final itemsRoles = + comboRoles(i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage); nameController.text = _fieldData.name; displayNameController.text = _fieldData.displayName; emailController.text = _fieldData.email; @@ -85,7 +85,7 @@ class CreateUserCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Users/list'); }, child: Text(i18n.tr('Cancel')), @@ -102,7 +102,7 @@ class CreateUserCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -129,7 +129,7 @@ class CreateUserCustom extends State with MessageLine { 'sql': 'insert', }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { if (answer.startsWith('id:')) { @@ -138,7 +138,7 @@ class CreateUserCustom extends State with MessageLine { setError(i18n.tr('Saving data failed: $answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Users/edit;$id'); } } @@ -146,7 +146,7 @@ class CreateUserCustom extends State with MessageLine { } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/users/create_user_page.dart b/lib/page/users/create_user_page.dart index a476371..9428ee7 100644 --- a/lib/page/users/create_user_page.dart +++ b/lib/page/users/create_user_page.dart @@ -31,8 +31,8 @@ class _CreateUserPageState extends CreateUserCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/users/delete_user_custom.dart b/lib/page/users/delete_user_custom.dart index 9b01b61..75c7808 100644 --- a/lib/page/users/delete_user_custom.dart +++ b/lib/page/users/delete_user_custom.dart @@ -20,7 +20,7 @@ class DeleteUserCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'DeleteUser'); @@ -37,7 +37,7 @@ class DeleteUserCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -49,9 +49,9 @@ class DeleteUserCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; comboRolesFromBackend( - attendedPage: attendedPage!, onDone: () => setState(() => 1)); - final itemsRoles = comboRoles( - i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage!); + attendedPage: attendedPage, onDone: () => setState(() => 1)); + final itemsRoles = + comboRoles(i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage); nameController.text = _fieldData.name; displayNameController.text = _fieldData.displayName; emailController.text = _fieldData.email; @@ -97,7 +97,7 @@ class DeleteUserCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Users/list'); }, child: Text(i18n.tr('Cancel')), @@ -114,7 +114,7 @@ class DeleteUserCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -141,7 +141,7 @@ class DeleteUserCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -151,7 +151,7 @@ class DeleteUserCustom extends State with MessageLine { 'sql': 'delete', ':id': primaryKey }; - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { globalData.navigate(context, '/Users/list'); @@ -159,7 +159,7 @@ class DeleteUserCustom extends State with MessageLine { } void onVerifyAndDelete() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onDelete(); } diff --git a/lib/page/users/delete_user_page.dart b/lib/page/users/delete_user_page.dart index d87137a..5b62757 100644 --- a/lib/page/users/delete_user_page.dart +++ b/lib/page/users/delete_user_page.dart @@ -32,8 +32,8 @@ class _DeleteUserPageState extends DeleteUserCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/users/edit_user_custom.dart b/lib/page/users/edit_user_custom.dart index c38e348..e79c56c 100644 --- a/lib/page/users/edit_user_custom.dart +++ b/lib/page/users/edit_user_custom.dart @@ -20,7 +20,7 @@ class EditUserCustom extends State with MessageLine { final int primaryKey; final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditUser'); @@ -37,7 +37,7 @@ class EditUserCustom extends State with MessageLine { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -49,9 +49,9 @@ class EditUserCustom extends State with MessageLine { Widget buildFrame() { final padding = GlobalThemeData.padding; comboRolesFromBackend( - attendedPage: attendedPage!, onDone: () => setState(() => 1)); - final itemsRoles = comboRoles( - i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage!); + attendedPage: attendedPage, onDone: () => setState(() => 1)); + final itemsRoles = + comboRoles(i18n.trDyn(GlobalTranslations.comboboxSelect), attendedPage); nameController.text = _fieldData.name; displayNameController.text = _fieldData.displayName; emailController.text = _fieldData.email; @@ -97,7 +97,7 @@ class EditUserCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Users/list'); }, child: Text(i18n.tr('Cancel')), @@ -114,7 +114,7 @@ class EditUserCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -141,7 +141,7 @@ class EditUserCustom extends State with MessageLine { super.initState(); } - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -152,17 +152,17 @@ class EditUserCustom extends State with MessageLine { ':id': primaryKey }; _fieldData.toMap(parameters); - globalData.restPersistence! + globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) { requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); }); } void onVerifyAndStore() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); onStore(); } diff --git a/lib/page/users/edit_user_page.dart b/lib/page/users/edit_user_page.dart index 9b0c24f..18ae325 100644 --- a/lib/page/users/edit_user_page.dart +++ b/lib/page/users/edit_user_page.dart @@ -32,8 +32,8 @@ class _EditUserPageState extends EditUserCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/page/users/list_user_custom.dart b/lib/page/users/list_user_custom.dart index 4d5be2f..4c41337 100644 --- a/lib/page/users/list_user_custom.dart +++ b/lib/page/users/list_user_custom.dart @@ -17,7 +17,7 @@ final i18n = I18N(); class ListUserCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateUser'); @@ -43,7 +43,7 @@ class ListUserCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows( + final rows = attendedPage.getRows( dbData: snapshot.data!, columnList: 'user_id;user_name;user_displayname;user_email;role', @@ -68,9 +68,9 @@ class ListUserCustom extends State { Widget buildFrame({required JsonList rows, required int totalCount}) { final padding = GlobalThemeData.padding; comboRolesFromBackend( - attendedPage: attendedPage!, onDone: () => setState(() => 1)); + attendedPage: attendedPage, onDone: () => setState(() => 1)); final itemsRoles = comboRoles( - i18n.trDyn(GlobalTranslations.comboboxItemAll), attendedPage!); + i18n.trDyn(GlobalTranslations.comboboxItemAll), attendedPage); final formItems = [ FormItem( TextFormField( @@ -106,7 +106,7 @@ class ListUserCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ @@ -128,7 +128,7 @@ class ListUserCustom extends State { ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -166,7 +166,7 @@ class ListUserCustom extends State { } void requestRecords() => - _futureDbData = globalData.restPersistence!.query(what: 'query', data: { + _futureDbData = globalData.restPersistence.query(what: 'query', data: { 'module': 'Users', 'sql': 'list', 'offset': _fieldData.theOffset, @@ -176,8 +176,8 @@ class ListUserCustom extends State { }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); diff --git a/lib/page/users/list_user_page.dart b/lib/page/users/list_user_page.dart index 41a1c6c..b4f014c 100644 --- a/lib/page/users/list_user_page.dart +++ b/lib/page/users/list_user_page.dart @@ -31,8 +31,8 @@ class _ListUserPageState extends ListUserCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } diff --git a/lib/services/global_widget.dart b/lib/services/global_widget.dart index b3261a3..8449761 100644 --- a/lib/services/global_widget.dart +++ b/lib/services/global_widget.dart @@ -60,7 +60,7 @@ void _requestData(String name, AttendedPage attendedPage, if (!attendedPage.pageStates.dbDataState.hasEntry(name)) { attendedPage.pageStates.dbDataState.addRequest(name).then((_) => GlobalData() - .restPersistence! + .restPersistence .query(what: 'query', data: parameters) .then((value) { attendedPage.pageStates.dbDataState diff --git a/lib/setting/global_data.dart b/lib/setting/global_data.dart index 9c1215c..00f4031 100644 --- a/lib/setting/global_data.dart +++ b/lib/setting/global_data.dart @@ -24,7 +24,7 @@ abstract class FooterInterface { /// Storage for global resources. This is a singleton. class GlobalData { static const version = '2021.08.24.00'; - static GlobalData? _instance; + static late GlobalData _instance; static String baseDirectory = ''; static var serverEnvironment = ServerEnvironment.productive; static final String applicationName = theApplicationName; @@ -36,11 +36,11 @@ class GlobalData { final DrawerBuilder drawerBuilder; final FooterBuilder footerBuilder; final BaseConfiguration configuration; - final RestPersistence? restPersistence; + late final RestPersistence restPersistence; late HomeDirectories homeDirectories; final navigatorStack = NavigatorStack(); - factory GlobalData() => _instance ?? GlobalData(); + factory GlobalData() => _instance; /// [configuration]: general settings. /// [appBarBuilder]: a factory to create the Hamburger menu. @@ -108,7 +108,7 @@ class HomeDirectories { /// This allows to access the calling page from the current page, /// e.g. to inform about changes. class NavigatorStack { - GlobalData? globalData; + late GlobalData globalData; final stack = []; /// Switches the page given by a [route]. @@ -156,7 +156,7 @@ class NavigatorStack { } } if (parent == null) { - globalData!.logger + globalData.logger .error('informAboutChanges(): parent ${route!} not found'); } else { // parent.noticeChange(); @@ -170,7 +170,7 @@ class NavigatorStack { /// [context]: the context of the calling page. void pop(BuildContext context) { if (stack.isEmpty) { - globalData!.logger.error('NavigatorStack.pop(): empty stack'); + globalData.logger.error('NavigatorStack.pop(): empty stack'); } else { stack.removeLast(); Navigator.pop(context); @@ -195,7 +195,7 @@ class NavigatorStack { ?.addListener(() => attendedPage.reload(rebuild: true)); } } else { - globalData!.logger.error( + globalData.logger.error( 'supplyTopOfStack(): route $route not found. TOS: ' + (last == null ? '' : last.route)); } diff --git a/lib/setting/structure.dart b/lib/setting/structure.dart index 79f25f2..514fb0e 100644 --- a/lib/setting/structure.dart +++ b/lib/setting/structure.dart @@ -22,13 +22,13 @@ class Structure { /// Manages a list of [Structure] items. class Structures { - static Structures? _instance; - GlobalData? globalData; + static late Structures _instance; + late GlobalData globalData; final structures = []; final scopes = >{}; /// Returns the singleton instance. - factory Structures() => _instance!; + factory Structures() => _instance; /// Builds the singleton instance with items from a JSon file. /// @@ -38,7 +38,7 @@ class Structures { this.globalData = GlobalData(); final file = File(filename); if (!file.existsSync()) { - globalData!.logger.error('cannot read structures from $filename'); + globalData.logger.error('cannot read structures from $filename'); } else { final content = file.readAsStringSync(); final data = convert.jsonDecode(content); diff --git a/lib/widget/attended_page.dart b/lib/widget/attended_page.dart index 104ab17..7ddf1d1 100644 --- a/lib/widget/attended_page.dart +++ b/lib/widget/attended_page.dart @@ -175,7 +175,7 @@ class AttendedPage extends ChangeNotifier { String name = 'record'; if (!pageStates.dbDataState.hasEntry(name)) { pageStates.dbDataState.addRequest(name).then((_) => globalData - .restPersistence! + .restPersistence .query(what: what, data: parameters) .then((value) { pageStates.dbDataState diff --git a/metatool/bin/page_generator.dart b/metatool/bin/page_generator.dart index 37af3dc..982d8c9 100644 --- a/metatool/bin/page_generator.dart +++ b/metatool/bin/page_generator.dart @@ -15,7 +15,7 @@ class PageGenerator extends SqlGenerator { child: FutureBuilder( future: _futureDbData, builder: (context, snapshot) { - final rc = attendedPage!.loadRecord(snapshot, (record) { + final rc = attendedPage.loadRecord(snapshot, (record) { _fieldData.fromMap(record); return buildFrame(); }); @@ -65,8 +65,8 @@ class _EditUserPageState extends EditUserCustom { @override void didChangeDependencies() { final size = MediaQuery.of(context).size; - attendedPage!.pageStates.screenWidth = size.width; - attendedPage!.pageStates.screenHeight = size.height; + attendedPage.pageStates.screenWidth = size.width; + attendedPage.pageStates.screenHeight = size.height; super.didChangeDependencies(); } @@ -95,9 +95,9 @@ class _EditUserPageState extends EditUserCustom { }'''; static final templateGlobalComboBox = ''' comboRolesFromBackend( - attendedPage: attendedPage!, onDone: () => setState(() => 1)); + attendedPage: attendedPage, onDone: () => setState(() => 1)); final itemsRoles = comboRoles( - i18n.trDyn(GlobalTranslations.combobox#UNDEF), attendedPage!);'''; + i18n.trDyn(GlobalTranslations.combobox#UNDEF), attendedPage);'''; static final templateListCustom = '''// This file is created by the meta_tool. But it can be customized. @@ -119,7 +119,7 @@ final i18n = I18N(); class ListUserCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateUser'); @@ -145,7 +145,7 @@ class ListUserCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows(dbData: snapshot.data!, + final rows = attendedPage.getRows(dbData: snapshot.data!, columnList: '#ROW_COLUMNS', onDone: () => setState(() => 1), route#EDIT1: '/Users/#EDIT2', @@ -186,14 +186,14 @@ class ListUserCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ #TABLE_HEADER ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -229,7 +229,7 @@ class ListUserCustom extends State { super.initState(); } - void requestRecords() => _futureDbData = globalData.restPersistence!.query( + void requestRecords() => _futureDbData = globalData.restPersistence.query( what: 'query', data: { 'module': 'Users', 'sql': 'list', @@ -238,8 +238,8 @@ class ListUserCustom extends State { #PARAM_DEF }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); @@ -273,7 +273,7 @@ final i18n = I18N(); class MappingUserCustom extends State { final globalData = GlobalData(); late Future _futureDbData; - AttendedPage? attendedPage; + late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'CreateUser'); @@ -299,7 +299,7 @@ class MappingUserCustom extends State { rc = const CircularProgressIndicator(); } else { if (snapshot.hasData) { - final rows = attendedPage!.getRows(dbData: snapshot.data!, + final rows = attendedPage.getRows(dbData: snapshot.data!, columnList: '#ROW_COLUMNS', onDone: () => setState(() => 1), route#EDIT1: '/Users/#EDIT2', @@ -340,14 +340,14 @@ class MappingUserCustom extends State { padding: EdgeInsets.symmetric( vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid(formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding)))); final table = DataTable( columns: [ #TABLE_HEADER ], rows: rows as List, ); - Widget? tabBar = attendedPage!.buildChipBar( + Widget? tabBar = attendedPage.buildChipBar( totalCount: totalCount, offset: _fieldData.theOffset, pageSize: _fieldData.thePageSize, @@ -383,7 +383,7 @@ class MappingUserCustom extends State { super.initState(); } - void requestRecords() => _futureDbData = globalData.restPersistence!.query( + void requestRecords() => _futureDbData = globalData.restPersistence.query( what: 'query', data: { 'module': 'Users', 'sql': 'list', @@ -392,8 +392,8 @@ class MappingUserCustom extends State { #PARAM_DEF }); void search() { - attendedPage!.pageStates.dbDataState.clear(); - if (_formKey.currentState!.validate()) { + attendedPage.pageStates.dbDataState.clear(); + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); requestRecords(); setState(() => 1); @@ -427,7 +427,7 @@ final i18n = I18N(); class EditUserCustom extends State with MessageLine { #DEF_PRIMARY final globalData = GlobalData(); -#DEF_FUTURE AttendedPage? attendedPage; +#DEF_FUTURE late AttendedPage attendedPage; final _fieldData = _FieldData(); final GlobalKey _formKey = GlobalKey(debugLabel: 'EditUser'); @@ -453,7 +453,7 @@ class EditUserCustom extends State with MessageLine { FormItem( ElevatedButton( onPressed: () { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/Users/list'); }, child: Text(i18n.tr('Cancel')), @@ -470,7 +470,7 @@ class EditUserCustom extends State with MessageLine { vertical: padding, horizontal: padding), child: WidgetForm.flexibleGrid( formItems, - screenWidth: attendedPage!.pageStates.screenWidth, + screenWidth: attendedPage.pageStates.screenWidth, padding: padding, )))); return rc; @@ -493,13 +493,13 @@ class EditUserCustom extends State with MessageLine { 'module': 'Users', 'sql': '#SQL_TYPE', #SET_PRIMARY }; -#CALL_TO_MAP globalData.restPersistence! +#CALL_TO_MAP globalData.restPersistence .store(what: 'store', map: parameters) .then((answer) {#STORAGE_DONE}); } void #ACTION2() { - if (_formKey.currentState!.validate()) { + if (_formKey.currentState != null && _formKey.currentState!.validate()) { _formKey.currentState!.save(); #ACTION1(); } @@ -511,7 +511,7 @@ class _FieldData { #FROM_MAP#TO_MAP} '''; static final templateRequestRecord = ''' - void requestRecord() => _futureDbData = globalData.restPersistence!.query( + void requestRecord() => _futureDbData = globalData.restPersistence.query( what: 'query', data: {'module': 'Users', 'sql': 'byId', ':id': primaryKey}); @@ -525,7 +525,7 @@ class _FieldData { setError(i18n.tr('Saving data failed: \$answer')); setState(() => 1); } else { - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); globalData.navigate(context, '/#MODULE/edit;\$id'); } } @@ -533,7 +533,7 @@ class _FieldData { static final templateStorageDoneEdit = ''' requestRecord(); - attendedPage!.pageStates.dbDataState.clear(); + attendedPage.pageStates.dbDataState.clear(); setState(() => 1); '''; static final templateStorageDoneDelete = @@ -1031,7 +1031,7 @@ StatefulWidget? customPageByRoute(String route) { var didChangeDependencies = templateDidChangeDependencies; var definitionFuture = ' late Future _futureDbData;'; var importPersistence = "import '../../persistence/persistence.dart';\n"; - var informAboutChanges = ' attendedPage!.informAboutChanges();'; + var informAboutChanges = ' attendedPage.informAboutChanges();'; var requestRecord = templateRequestRecord; page.pageType == PageType.edit ? 'update' diff --git a/metatool/bin/sql_generator.dart b/metatool/bin/sql_generator.dart index 106d2eb..9826a6d 100644 --- a/metatool/bin/sql_generator.dart +++ b/metatool/bin/sql_generator.dart @@ -37,59 +37,60 @@ class SqlGenerator extends GeneratorBase { /// Creates the sections for pages with PageType.list of the [module]. String createListSections(ModuleMetaData module) { final buffer = StringBuffer(); - List? listPages; - try { - listPages = module.pageList - .where((element) => element.pageType == PageType.list) - .toList(growable: false); - } on Exception catch (exc) { - logger.error('no page with list type: $exc'); - listPages = null; + final listPages = module.pagesByType(PageType.list); + final tableName = module.tableName; + for (var page in listPages) { + if (page is ListPageMetaData) { + var whereCondition = page.whereCondition; + if (whereCondition.endsWith('\n')) { + whereCondition = + whereCondition.substring(0, whereCondition.length - 1); + } + addListSql(page.name, page, whereCondition, tableName, buffer); + } } - if (listPages != null) { - final tableName = module.tableName; - for (var page in listPages) { - if (page is ListPageMetaData) { - var whereCondition = page.whereCondition; - if (whereCondition.endsWith('\n')) { - whereCondition = - whereCondition.substring(0, whereCondition.length - 1); - } - String selectItems2 = ''; - var selectItems = - page.selectItems.isEmpty ? '' : indent(page.selectItems, ' '); - var joins = findReferences(module, (x) => selectItems2 = x); - if (page.joinItems.isNotEmpty) { - joins += indent(page.joinItems, ' '); - if (!joins.endsWith('\n')) { - joins += '\n'; - } - } - var parameters = ''; - if (whereCondition.isNotEmpty) { - parameters = findParameters(whereCondition, page.fields); - whereCondition = ' WHERE\n' + indent(whereCondition, ' '); - } - final order = page.orderBy.isNotEmpty - ? page.orderBy - : module.primaryOf()!.columnName; - buffer.writeln(page.name + ':'); - buffer.writeln(''' type: list + if (module.needsSqlAll) { + PageMetaData? page = module.pageByName('list'); + if (page != null) { + addListSql('all', page as ListPageMetaData, '1', tableName, buffer); + } + } + return buffer.toString(); + } + + void addListSql(String sqlName, ListPageMetaData page, String whereCondition, + String tableName, StringBuffer buffer) { + String selectItems2 = ''; + var selectItems = + page.selectItems.isEmpty ? '' : indent(page.selectItems, ' '); + var joins = findReferences(page.module, (x) => selectItems2 = x); + if (page.joinItems.isNotEmpty) { + joins += indent(page.joinItems, ' '); + if (!joins.endsWith('\n')) { + joins += '\n'; + } + } + var parameters = ''; + if (whereCondition.isNotEmpty) { + parameters = findParameters(whereCondition, page.fields); + whereCondition = ' WHERE\n' + indent(whereCondition, ' '); + } + final order = page.orderBy.isNotEmpty + ? page.orderBy + : page.module.primaryOf()!.columnName; + buffer.writeln(sqlName + ':'); + buffer.writeln(''' type: list parameters: [$parameters] order: "$order" sql: | SELECT'''); - if (selectItems.isNotEmpty) { - addToBuffer(selectItems, maxLength: 80, buffer: buffer, indent: 6); - } - addToBuffer(' t0.*$selectItems2', - maxLength: 80, buffer: buffer, indent: 6); - buffer.writeln(' FROM $tableName t0'); - buffer.write('$joins$whereCondition'); - } - } + if (selectItems.isNotEmpty) { + addToBuffer(selectItems, maxLength: 80, buffer: buffer, indent: 6); } - return buffer.toString(); + addToBuffer(' t0.*$selectItems2', + maxLength: 80, buffer: buffer, indent: 6); + buffer.writeln('\n FROM $tableName t0'); + buffer.write('$joins$whereCondition'); } /// Returns the SQL statements for insert, update, delete... @@ -135,7 +136,7 @@ update: } } parameters.write(']'); - if (! module.properties.containsKey('changedAt')){ + if (!module.properties.containsKey('changedAt')) { logger.error('Module $moduleName misses changedAt'); } var item = module.properties['changedAt']!; @@ -191,6 +192,10 @@ update: buffer.writeln(parameters); buffer.writeln(sql1); buffer.writeln(sql2); + for (var page in module.pagesByType(PageType.mapping)) { + final sql = sqlOfMapping(page as MappingPageMetaData); + buffer.write(sql); + } return buffer.toString(); } @@ -202,7 +207,7 @@ update: .map((element) => element.group(1)) .toSet() .toList(); - return '"' + names.join('","') + '"'; + return names.isEmpty ? '' : ('"' + names.join('","') + '"'); } /// Creates the joins and select items the foreign keys of the given [module]. @@ -261,4 +266,10 @@ update: } } } + + /// Returns the sql statement definitions of a page with type PageType.mapping. + String sqlOfMapping(MappingPageMetaData page) { + String rc = ''; + return rc; + } } diff --git a/rest_server/data/sql/benchmarks.sql.yaml b/rest_server/data/sql/benchmarks.sql.yaml index 67a1e38..c62099a 100644 --- a/rest_server/data/sql/benchmarks.sql.yaml +++ b/rest_server/data/sql/benchmarks.sql.yaml @@ -9,7 +9,8 @@ list: order: "benchmark_id" sql: | SELECT - t0.* FROM benchmarks t0 + t0.* + FROM benchmarks t0 WHERE (:text='' OR benchmark_lastname like :text OR benchmark_firstname like :text) diff --git a/rest_server/data/sql/roles.sql.yaml b/rest_server/data/sql/roles.sql.yaml index 34251b2..cc868b4 100644 --- a/rest_server/data/sql/roles.sql.yaml +++ b/rest_server/data/sql/roles.sql.yaml @@ -9,7 +9,18 @@ list: order: "role_id" sql: | SELECT - t0.* FROM roles t0 + t0.* + FROM roles t0 +all: + type: list + parameters: [] + order: "role_id" + sql: | + SELECT + t0.* + FROM roles t0 + WHERE + 1 byId: type: record parameters: [ ":id" ] diff --git a/rest_server/data/sql/rolestarter.sql.yaml b/rest_server/data/sql/rolestarter.sql.yaml new file mode 100644 index 0000000..638d435 --- /dev/null +++ b/rest_server/data/sql/rolestarter.sql.yaml @@ -0,0 +1,52 @@ +--- +# DO NOT CHANGE. This file is created by the meta_tool +# SQL statements of the module "RoleStarter": + +module: RoleStarter +list: + type: list + parameters: [] + order: "rolestarter_id" + sql: | + SELECT + t0.*,t1.role_name AS role,t2.starter_name AS starter + FROM rolestarter t0 + JOIN roles t1 ON t1.role_id=t0.rolestarter_role + JOIN starters t2 ON t2.starter_id=t0.rolestarter_starter +all: + type: list + parameters: [] + order: "rolestarter_id" + sql: | + SELECT + t0.*,t1.role_name AS role,t2.starter_name AS starter + FROM rolestarter t0 + JOIN roles t1 ON t1.role_id=t0.rolestarter_role + JOIN starters t2 ON t2.starter_id=t0.rolestarter_starter + WHERE + 1 +byId: + type: record + parameters: [ ":id" ] + sql: "SELECT * FROM rolestarter WHERE rolestarter_id=:id;" +delete: + type: delete + parameters: [ ":id" ] + sql: "DELETE * FROM rolestarter WHERE rolestarter_id=:id;" +update: + type: update + parameters: [":id",":role",":starter",":order"] + sql: | + UPDATE rolestarter SET + rolestarter_role=:role, + rolestarter_starter=:starter, + rolestarter_order=:order, + rolestarter_changedat=NOW() + WHERE rolestarter_id=:id; +insert: + type: insert + parameters: [":role",":starter",":order",":createdBy"] + sql: | + INSERT INTO rolestarter(rolestarter_role,rolestarter_starter, + rolestarter_order,rolestarter_createdby,rolestarter_createdat) + VALUES(:role,:starter,:order,:createdBy,NOW()); diff --git a/rest_server/data/sql/starters.sql.yaml b/rest_server/data/sql/starters.sql.yaml index 56262e3..75e0681 100644 --- a/rest_server/data/sql/starters.sql.yaml +++ b/rest_server/data/sql/starters.sql.yaml @@ -9,7 +9,18 @@ list: order: "starter_id" sql: | SELECT - t0.* FROM starters t0 + t0.* + FROM starters t0 +all: + type: list + parameters: [] + order: "starter_id" + sql: | + SELECT + t0.* + FROM starters t0 + WHERE + 1 byId: type: record parameters: [ ":id" ] @@ -20,18 +31,18 @@ delete: sql: "DELETE * FROM starters WHERE starter_id=:id;" update: type: update - parameters: [":id",":name",":link",":icon"] + parameters: [":id",":name",":route",":icon"] sql: | UPDATE starters SET starter_name=:name, - starter_link=:link, + starter_route=:route, starter_icon=:icon, starter_changedat=NOW() WHERE starter_id=:id; insert: type: insert - parameters: [":name",":link",":icon",":createdBy"] + parameters: [":name",":route",":icon",":createdBy"] sql: | - INSERT INTO starters(starter_name,starter_link,starter_icon, + INSERT INTO starters(starter_name,starter_route,starter_icon, starter_createdby,starter_createdat) - VALUES(:name,:link,:icon,:createdBy,NOW()); + VALUES(:name,:route,:icon,:createdBy,NOW()); diff --git a/rest_server/data/sql/structures.sql.yaml b/rest_server/data/sql/structures.sql.yaml index 957a3cb..e488a7f 100644 --- a/rest_server/data/sql/structures.sql.yaml +++ b/rest_server/data/sql/structures.sql.yaml @@ -9,7 +9,8 @@ list: order: "structure_id" sql: | SELECT - t0.* FROM structures t0 + t0.* + FROM structures t0 byId: type: record parameters: [ ":id" ] diff --git a/rest_server/data/sql/users.sql.yaml b/rest_server/data/sql/users.sql.yaml index 18133b3..c399079 100644 --- a/rest_server/data/sql/users.sql.yaml +++ b/rest_server/data/sql/users.sql.yaml @@ -9,7 +9,8 @@ list: order: "user_id" sql: | SELECT - t0.*,t1.role_name AS role FROM users t0 + t0.*,t1.role_name AS role + FROM users t0 JOIN roles t1 ON t1.role_id=t0.user_role WHERE (:text='' OR user_name like :text diff --git a/rest_server/lib/rest_server.dart b/rest_server/lib/rest_server.dart index 4c8ce98..da0afd5 100644 --- a/rest_server/lib/rest_server.dart +++ b/rest_server/lib/rest_server.dart @@ -50,7 +50,7 @@ class RestServer { static const _version = 'V2021.08.19.00'; static BaseLogger? unittestLogger; BaseLogger logger = MemoryLogger(LEVEL_FINE); - BaseConfiguration configuration = BaseConfiguration({}, globalLogger); + late BaseConfiguration configuration; var clientSessionTimeout = 15 * 60; String serviceName = 'exhibition'; RestServer( @@ -114,6 +114,7 @@ class RestServer { configuration.asInt('logLevel', section: 'service') ?? LEVEL_SUMMERY; logger = unittestLogger ?? Logger(logFile, level); globalLogger = logger; + logger.log('configuration read from $filename'); ProcessSync(logger); FileSync.initialize(logger); logger.log( @@ -274,14 +275,14 @@ class ServiceWorker { final int threadId; final String serviceName; int clientSessionTimeout = 30; - BaseLogger logger = globalLogger; + late BaseLogger logger; bool requestedCodecIsLatin1 = false; HttpRequest? currentRequest; String what = ''; MySqlDb? db; String restVersion = ''; FileSync? _fileSync = FileSync(); - SqlStorage sqlStorage = SqlStorage(globalLogger); + late SqlStorage sqlStorage; String sqlTestPrimaryTable = ''; ServiceWorker(this.threadId, this.configuration, this.serviceName) { diff --git a/rest_server/lib/sql_storage.dart b/rest_server/lib/sql_storage.dart index 9f17920..1c2dd52 100644 --- a/rest_server/lib/sql_storage.dart +++ b/rest_server/lib/sql_storage.dart @@ -135,7 +135,8 @@ class SqlStorage { modules[moduleName] = SqlModule(moduleName, this); } final module = modules[moduleName]; - for (var name in map.keys) { + final keys = map.keys.toList(); + for (var name in keys) { switch (name) { case 'module': // already done.