From: Hamatoma Date: Tue, 20 Oct 2020 21:42:10 +0000 (+0200) Subject: daily work: sub project model_tool, persistence works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=487caca10a196f56efab9711d3403cca038409aa;p=flutter_bones.git daily work: sub project model_tool, persistence works --- diff --git a/data/ddl/role.sql b/data/ddl/role.sql index a061d41..cba827e 100644 --- a/data/ddl/role.sql +++ b/data/ddl/role.sql @@ -1,4 +1,3 @@ -<<<<<<< HEAD DROP TABLE IF EXISTS role; CREATE TABLE role ( role_id INT(10) UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT, @@ -10,17 +9,4 @@ CREATE TABLE role ( role_changedat TIMESTAMP NULL, role_changedby VARCHAR(16), PRIMARY KEY(role_id) -======= -drop table if exists role; -create table role ( - role_id int(10) notnull unique, - role_name varchar(32) unique notnull, - role_priority int(10), - role_active char(1), - role_createdat timestamp null, - role_createdby varchar(16), - role_changedat timestamp null, - role_changedby varchar(16), - primary role_id ->>>>>>> origin/master ); diff --git a/data/ddl/user.sql b/data/ddl/user.sql index 2d23956..84441b6 100644 --- a/data/ddl/user.sql +++ b/data/ddl/user.sql @@ -1,4 +1,3 @@ -<<<<<<< HEAD DROP TABLE IF EXISTS user; CREATE TABLE user ( user_id INT(10) UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT, @@ -12,19 +11,4 @@ CREATE TABLE user ( user_changedat TIMESTAMP NULL, user_changedby VARCHAR(16), PRIMARY KEY(user_id) -======= -drop table if exists user; -create table user ( - user_id int(10) notnull unique, - user_name varchar(64) unique notnull, - user_displayname varchar(32) unique, - user_email varchar(128) unique, - user_password varchar(128), - user_role int(10), - user_createdat timestamp null, - user_createdby varchar(16), - user_changedat timestamp null, - user_changedby varchar(16), - primary user_id ->>>>>>> origin/master ); diff --git a/data/rest/configuration.yaml b/data/rest/configuration.yaml new file mode 100644 index 0000000..2b6816a --- /dev/null +++ b/data/rest/configuration.yaml @@ -0,0 +1,30 @@ +--- +# configuration of the bones backend for configuration: +created: 2020.10.20 23:16:54 +author: flutter_bones.module_model.exportSqlBackend() +version: 1.0.0 +modules: + - module: configuration + list: + - name: insert + type: insert + sql: "INSERT INTO configuration(configuration_scope,configuration_property,configuration_order,configuration_type,configuration_value,configuration_description,configuration_createdat,configuration_createdby) + VALUES(:configuration_scope,:configuration_property,:configuration_order,:configuration_type,:configuration_value,:configuration_description,NOW(),:configuration_createdby);" + - name: update + type: update + sql: "UPDATE configuration SET + configuration_scope=:configuration_scope,configuration_property=:configuration_property,configuration_order=:configuration_order,configuration_type=:configuration_type,configuration_value=:configuration_value,configuration_description=:configuration_description,configuration_changedat=NOW(),configuration_changedby=:configuration_changedby + WHERE configuration_id=:configuration_id;" + - name: delete + type: delete + sql: "DELETE from configuration WHERE configuration_id=:configuration_id;" + - name: record + type: record + sql: "SELECT * from configuration WHERE configuration_id=:configuration_id;" + - name: by_configuration_scope + type: record + sql: "SELECT * from configuration WHERE configuration_scope=:configuration_scope&&configuration_id!=:excluded;" + - name: list + type: list + sql: "SELECT * from configuration + WHERE configuration_name like :configuration_name AND configuration_scope like :configuration_scope AND configuration_scope like :configuration_scope;" diff --git a/data/rest/role.yaml b/data/rest/role.yaml index 9d7cb3c..25b3215 100644 --- a/data/rest/role.yaml +++ b/data/rest/role.yaml @@ -1,6 +1,6 @@ --- # configuration of the bones backend for role: -created: 2020.10.20 15:25:01 +created: 2020.10.20 23:16:54 author: flutter_bones.module_model.exportSqlBackend() version: 1.0.0 modules: diff --git a/data/rest/user.yaml b/data/rest/user.yaml index 3a995c6..3ac76cd 100644 --- a/data/rest/user.yaml +++ b/data/rest/user.yaml @@ -1,6 +1,6 @@ --- # configuration of the bones backend for user: -created: 2020.10.20 15:25:01 +created: 2020.10.20 23:16:54 author: flutter_bones.module_model.exportSqlBackend() version: 1.0.0 modules: diff --git a/lib/db_tool.dart b/lib/db_tool.dart deleted file mode 100644 index 48299f4..0000000 --- a/lib/db_tool.dart +++ /dev/null @@ -1,92 +0,0 @@ -import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; - -import 'src/model/standard/role_model.dart'; -import 'src/model/standard/user_model.dart'; - -void main(List argv) async { - final logger = MemoryLogger(LEVEL_FINE); - final dbHelper = DbHelper(logger); - if (argv.isEmpty) { - argv = ['export-sql']; - } - final mode = argv[0]; - argv.removeAt(0); - final options = []; - argv = StringHelper.splitArgv(argv, options); - switch (mode) { - case 'export-sql': - dbHelper.exportSql(argv, options); - break; - default: - logger.error('unknown mode: $mode'); - break; - } -} - -class DbHelper { - final BaseLogger logger; - - DbHelper(this.logger); - - void exportSql(List args, List options) { - String directory; - String value; - for (var opt in options) { - value = StringUtils.stringOption('directory', 'd', opt); - if (value != null) { - directory = value; - } - } - directory ??= 'data'; - final dirDDL = FileSync.joinPaths(directory, 'ddl'); - final dirREST = FileSync.joinPaths(directory, 'rest'); - FileSync.ensureDirectory(dirDDL); - FileSync.ensureDirectory(dirREST); - if (args.isEmpty) { - args = ['user', 'role', 'configuration']; - } - while (args.isNotEmpty) { - final name = args[0]; - args.removeAt(0); - ModuleModel module; - switch (name) { - case 'user': - module = UserModel(logger); - break; - case 'role': - module = RoleModel(logger); - break; - case 'configuration': - module = ConfigurationModel(logger); - break; - default: - logger.error('unknown table'); - break; - } - if (module != null) { - module.parse(); - var filename = FileSync.joinPaths(dirDDL, '$name.sql'); - FileSync.toFile(filename, module.exportSqlCreateTable()); - print('exported: $filename'); - filename = FileSync.joinPaths(dirREST, '$name.yaml'); - FileSync.toFile(filename, module.exportSqlBackend()); - print('exported: $filename'); - } - } - } - - void usage(String error) { - print('''usage: dbhelper [] -: - create-sql [] [] - : 'role', 'user' ... - : - -d or --directory=: - the base directory used for the exported files. -Examples: -dbhelper create-sql role role.sql -d/tmp -dbhelper create-sql --directory=/opt/sql-data -'''); - } -} diff --git a/lib/src/helper/settings.dart b/lib/src/helper/settings.dart index a3dfb5a..7e814f6 100644 --- a/lib/src/helper/settings.dart +++ b/lib/src/helper/settings.dart @@ -1,10 +1,17 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/intl.dart'; +import 'package:meta/meta.dart'; +/// A replacement for dart_ui:Locale. This avoids a flutter dependency. +/// Note: package:intl uses only a string for locale, e.g. 'en_US'. +class SettingLocale { + String languageCode; + String countryCode; + SettingLocale({this.languageCode, this.countryCode}); +} class BaseSettings { - static Locale locale = Locale('US', 'en'); + static var locale = SettingLocale(countryCode: 'US', languageCode: 'en'); static get language => locale.languageCode; @@ -29,7 +36,7 @@ class BaseSettings { country = country.toUpperCase(); country = country == 'EN' ? 'US' : country; language = language.toLowerCase(); - setLocale(Locale(language, country)); + setLocale(SettingLocale(languageCode: language, countryCode: country)); } /// Translates a [text] with a given translation [map]. diff --git a/lib/src/helper/string_helper.dart b/lib/src/helper/string_helper.dart index 8559759..e94e597 100644 --- a/lib/src/helper/string_helper.dart +++ b/lib/src/helper/string_helper.dart @@ -1,6 +1,6 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; import 'package:intl/intl.dart'; +import '../model/model_types.dart'; class StringHelper { static final regExpTrue = RegExp(r'^(true|yes)$', caseSensitive: false); diff --git a/lib/src/helper/validators.dart b/lib/src/helper/validators.dart index 351bf22..8a044f4 100644 --- a/lib/src/helper/validators.dart +++ b/lib/src/helper/validators.dart @@ -1,6 +1,6 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; import 'package:meta/meta.dart'; +import 'settings.dart'; /// Tests whether [input] is an valid email address. /// Returns null if it is a valid email address, otherwise an error message. diff --git a/lib/src/model/button_model.dart b/lib/src/model/button_model.dart index 3fba73b..9a2e1fa 100644 --- a/lib/src/model/button_model.dart +++ b/lib/src/model/button_model.dart @@ -1,8 +1,7 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bones/flutter_bones.dart'; - -typedef ButtonOnPressed = void Function(String name); +import 'widget_model.dart'; +import 'section_model.dart'; +import 'page_model.dart'; /// Describes a button widget. class ButtonModel extends WidgetModel { @@ -13,11 +12,6 @@ class ButtonModel extends WidgetModel { List options; ButtonModelType buttonModelType; - VoidCallback onPressed; - - VoidCallback onLongPressed; - ValueChanged onHighlightChanged; - ButtonModel(SectionModel section, PageModel page, this.map, BaseLogger logger) : super(section, page, WidgetModelType.button, logger); @@ -42,7 +36,6 @@ class ButtonModel extends WidgetModel { parseEnum('buttonType', map, ButtonModelType.values); buttonModelType ??= ButtonModelType.custom; options = parseOptions('options', map); - onPressed = () => logger.error('${fullName()}: missing onPressed'); checkOptionsByRegExpr(options, regExprOptions); } diff --git a/lib/src/model/column_model.dart b/lib/src/model/column_model.dart index 63ee2f8..cf25439 100644 --- a/lib/src/model/column_model.dart +++ b/lib/src/model/column_model.dart @@ -1,6 +1,5 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/cupertino.dart'; - +import 'package:meta/meta.dart'; import 'model_base.dart'; import 'model_types.dart'; import 'table_model.dart'; diff --git a/lib/src/model/combobox_model.dart b/lib/src/model/combobox_model.dart index 695a47d..159bd3c 100644 --- a/lib/src/model/combobox_model.dart +++ b/lib/src/model/combobox_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import 'field_model.dart'; import 'page_model.dart'; @@ -11,8 +10,6 @@ class ComboboxModel extends FieldModel { static final regExprOptions = RegExp(r'^(readonly|disabled|required|undef)$'); List texts; List values; - FormFieldValidator validator; - FormFieldSetter onSaved; final Map map; diff --git a/lib/src/model/db_reference_model.dart b/lib/src/model/db_reference_model.dart index 5e9d9d1..83f8081 100644 --- a/lib/src/model/db_reference_model.dart +++ b/lib/src/model/db_reference_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import 'column_model.dart'; import 'field_model.dart'; @@ -15,10 +14,6 @@ class DbReferenceModel extends FieldModel { int rows; var value; ColumnModel column; - FormFieldValidator validator; - - FormFieldSetter onSaved; - final Map map; DbReferenceModel( diff --git a/lib/src/model/field_model.dart b/lib/src/model/field_model.dart index 5d5b0c8..a833b02 100644 --- a/lib/src/model/field_model.dart +++ b/lib/src/model/field_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import '../helper/string_helper.dart'; import 'model_types.dart'; @@ -13,7 +12,6 @@ abstract class FieldModel extends WidgetModel { String label; String toolTip; DataType dataType; - FormFieldSetter onSaved; List options; FilterType filterType; diff --git a/lib/src/model/model_base.dart b/lib/src/model/model_base.dart index 189ccfe..f0e775a 100644 --- a/lib/src/model/model_base.dart +++ b/lib/src/model/model_base.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; import 'model_types.dart'; diff --git a/lib/src/model/module_model.dart b/lib/src/model/module_model.dart index 039affe..e93e6e5 100644 --- a/lib/src/model/module_model.dart +++ b/lib/src/model/module_model.dart @@ -1,12 +1,13 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter_bones/flutter_bones.dart'; -import 'package:flutter_bones/src/model/column_model.dart'; -import 'package:flutter_bones/src/model/table_model.dart'; +import 'column_model.dart'; +import 'table_model.dart'; import 'package:meta/meta.dart'; - import 'model_base.dart'; import 'page_model.dart'; +import 'field_model.dart'; +import 'model_types.dart'; +import 'widget_model.dart'; +import '../helper/string_helper.dart'; /// Describes a module. /// A module realizes a model of an entitiy which is normally related to one diff --git a/lib/src/model/section_model.dart b/lib/src/model/section_model.dart index c1955be..05f49f6 100644 --- a/lib/src/model/section_model.dart +++ b/lib/src/model/section_model.dart @@ -1,7 +1,6 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/src/model/all_db_fields_model.dart'; -import 'package:flutter_bones/src/model/db_reference_model.dart'; - +import 'all_db_fields_model.dart'; +import 'db_reference_model.dart'; import 'button_model.dart'; import 'checkbox_model.dart'; import 'combobox_model.dart'; diff --git a/lib/src/model/standard/configuration_model.dart b/lib/src/model/standard/configuration_model.dart index fcc66a6..a9534db 100644 --- a/lib/src/model/standard/configuration_model.dart +++ b/lib/src/model/standard/configuration_model.dart @@ -1,5 +1,5 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; +import '../module_model.dart'; /// class ConfigurationModel extends ModuleModel { diff --git a/lib/src/model/standard/role_model.dart b/lib/src/model/standard/role_model.dart index a1c6b1c..553a838 100644 --- a/lib/src/model/standard/role_model.dart +++ b/lib/src/model/standard/role_model.dart @@ -1,5 +1,5 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; +import '../module_model.dart'; class RoleModel extends ModuleModel { static final yamlMap = { diff --git a/lib/src/model/standard/standard_modules.dart b/lib/src/model/standard/standard_modules.dart index 7eda53f..5aa6f0a 100644 --- a/lib/src/model/standard/standard_modules.dart +++ b/lib/src/model/standard/standard_modules.dart @@ -1,5 +1,8 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; +import '../module_model.dart'; +import 'role_model.dart'; +import 'user_model.dart'; +import 'configuration_model.dart'; /// Returns an instance of a standard module given by [name]. ModuleModel standardModule(String name, BaseLogger logger) { diff --git a/lib/src/model/standard/user_model.dart b/lib/src/model/standard/user_model.dart index 84d18a9..a8b0c54 100644 --- a/lib/src/model/standard/user_model.dart +++ b/lib/src/model/standard/user_model.dart @@ -1,5 +1,5 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter_bones/flutter_bones.dart'; +import '../module_model.dart'; class UserModel extends ModuleModel { static final model = { diff --git a/lib/src/model/table_model.dart b/lib/src/model/table_model.dart index 3be6eff..37a4f19 100644 --- a/lib/src/model/table_model.dart +++ b/lib/src/model/table_model.dart @@ -1,6 +1,5 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/foundation.dart'; - +import 'package:meta/meta.dart'; import 'column_model.dart'; import 'model_base.dart'; import 'model_types.dart'; diff --git a/lib/src/model/text_field_model.dart b/lib/src/model/text_field_model.dart index f3df8ea..01a157a 100644 --- a/lib/src/model/text_field_model.dart +++ b/lib/src/model/text_field_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; -import 'package:flutter/material.dart'; import 'field_model.dart'; import 'model_types.dart'; @@ -15,10 +14,6 @@ class TextFieldModel extends FieldModel { int rows; var value; - FormFieldValidator validator; - - FormFieldSetter onSaved; - final Map map; TextFieldModel( diff --git a/lib/src/model/text_model.dart b/lib/src/model/text_model.dart index f16195d..55ec29c 100644 --- a/lib/src/model/text_model.dart +++ b/lib/src/model/text_model.dart @@ -1,5 +1,4 @@ import 'package:dart_bones/dart_bones.dart'; - import 'page_model.dart'; import 'section_model.dart'; import 'widget_model.dart'; diff --git a/lib/src/widget/view.dart b/lib/src/widget/view.dart index 989279c..24c2b2a 100644 --- a/lib/src/widget/view.dart +++ b/lib/src/widget/view.dart @@ -130,7 +130,7 @@ class View { Widget textField(TextFieldModel model) { var rc = toolTip( TextFormField( - validator: model.validator, + //validator: model.validator, decoration: InputDecoration(labelText: model.label), onSaved: (input) => model.value(input), ), diff --git a/model_tool/data b/model_tool/data new file mode 120000 index 0000000..4909e06 --- /dev/null +++ b/model_tool/data @@ -0,0 +1 @@ +../data \ No newline at end of file diff --git a/model_tool/lib/main.dart b/model_tool/lib/main.dart new file mode 100644 index 0000000..17a4946 --- /dev/null +++ b/model_tool/lib/main.dart @@ -0,0 +1,78 @@ +import 'package:dart_bones/dart_bones.dart'; + +import 'src/model/module_model.dart'; +import 'src/model/standard/standard_modules.dart'; +import 'src/helper/string_helper.dart'; + +void main(List argv) async { + final logger = MemoryLogger(LEVEL_FINE); + final dbHelper = DbHelper(logger); + if (argv.isEmpty) { + argv = ['export-sql']; + } + final mode = argv[0]; + argv.removeAt(0); + final options = []; + argv = StringHelper.splitArgv(argv, options); + switch (mode) { + case 'export-sql': + dbHelper.exportSql(argv, options); + break; + default: + logger.error('unknown mode: $mode'); + break; + } +} + +class DbHelper { + final BaseLogger logger; + + DbHelper(this.logger); + + void exportSql(List args, List options) { + String directory; + String value; + for (var opt in options) { + value = StringUtils.stringOption('directory', 'd', opt); + if (value != null) { + directory = value; + } + } + directory ??= 'data'; + final dirDDL = FileSync.joinPaths(directory, 'ddl'); + final dirREST = FileSync.joinPaths(directory, 'rest'); + FileSync.ensureDirectory(dirDDL); + FileSync.ensureDirectory(dirREST); + if (args.isEmpty) { + args = standardModules(); + } + while (args.isNotEmpty) { + final name = args[0]; + args.removeAt(0); + ModuleModel module = standardModule(name, logger); + if (module != null) { + module.parse(); + var filename = FileSync.joinPaths(dirDDL, '$name.sql'); + FileSync.toFile(filename, module.exportSqlCreateTable()); + print('exported: $filename'); + filename = FileSync.joinPaths(dirREST, '$name.yaml'); + FileSync.toFile(filename, module.exportSqlBackend()); + print('exported: $filename'); + } + } + } + + void usage(String error) { + print('''usage: dbhelper [] +: + create-sql [] [] + : 'role', 'user' ... + : + -d or --directory=: + the base directory used for the exported files. +Examples: +dbhelper create-sql role role.sql -d/tmp +dbhelper create-sql --directory=/opt/sql-data +'''); + } +} diff --git a/model_tool/lib/src/helper b/model_tool/lib/src/helper new file mode 120000 index 0000000..165a190 --- /dev/null +++ b/model_tool/lib/src/helper @@ -0,0 +1 @@ +../../../lib/src/helper/ \ No newline at end of file diff --git a/model_tool/lib/src/model b/model_tool/lib/src/model new file mode 120000 index 0000000..91de7ef --- /dev/null +++ b/model_tool/lib/src/model @@ -0,0 +1 @@ +../../../lib/src/model/ \ No newline at end of file diff --git a/model_tool/pubspec.yaml b/model_tool/pubspec.yaml new file mode 100644 index 0000000..09ffb06 --- /dev/null +++ b/model_tool/pubspec.yaml @@ -0,0 +1,38 @@ +name: flutter_bones_tool +description: A tool round about the model defined in flutter_bones, e.g. export as yaml. + +# The following line prevents the package from being accidentally published to +# pub.dev using `pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +version: 1.0.0+1 + +environment: + sdk: ">=2.11.0-234.0.dev <3.0.0" + +dependencies: + dart_bones: "^0.4.6" + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + # cupertino_icons: ^1.0.0 + +dev_dependencies: + +# flutter_test: +# sdk: flutter + +#flutter: + +# uses-material-design: true diff --git a/pubspec.yaml b/pubspec.yaml index 0cd45ac..b7e6ee7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.0 + # cupertino_icons: ^1.0.0 dev_dependencies: flutter_test: