*~
data/i18n/lokalize-scripts/
rest_server/tools/rest_server
+/UpdRestSv
///
/// Override it if needed.
void onInitialized() {
- for (var page in this.pageList){
+ for (var page in this.pageList) {
page.onInitialized();
}
}
}
this.name = name;
}
- void onInitialized(){
+ void onInitialized() {
var newFields = <WidgetMetaData>[];
var toDelete = <WidgetMetaData>[];
- for (var field in fields){
- if (field is CopyDbFields){
+ for (var field in fields) {
+ if (field is CopyDbFields) {
String excluded = '';
final start = field.options.indexOf('excluded=');
- if (start >= 0){
+ if (start >= 0) {
var end = field.options.indexOf(':', start);
- if (end < 0){
+ if (end < 0) {
end = field.options.length;
}
excluded = ' ' + field.options.substring(start, end) + ' ';
}
- for (var property in module.propertyList){
- if (excluded.contains(" ${property.name} ")){
+ for (var property in module.propertyList) {
+ if (excluded.contains(" ${property.name} ")) {
continue;
}
- if (! property.hasOption(':hidden:')) {
+ if (!property.hasOption(':hidden:')) {
newFields.add(property);
}
}
toDelete.add(field);
}
}
- for (var field in toDelete){
+ for (var field in toDelete) {
fields.remove(field);
}
fields.addAll(newFields);
final int size;
String columnName;
var validators = <String>[];
+
/// The foreign key if dataType is DataType.reference, e.g. 'users.user_id'
String? foreignKey;
PropertyMetaData(String name, this.label, this.dataType, this.options,
this.columnName = '',
this.size = 0,
this.foreignKey,
- int weight = 6, List<String>? validators})
+ int weight = 6,
+ List<String>? validators})
: super(name, WidgetType.property) {
this.weight = weight > 12 ? 12 : weight;
this.validators = validators ?? [];
import 'roles_meta.dart';
import 'structures_meta.dart';
import 'users_meta.dart';
+
/// Returns the meta data of the module given by [name].
/// Returns null if not found.
ModuleMetaData? moduleByName(String name) {
}
return rc;
}
+
/// Returns the module names as string list.
-List<String> moduleNames(){
+List<String> moduleNames() {
return [
'Roles',
'Structures',
}
class _CreateRolePageState extends CreateRoleCustom {
- _CreateRolePageState(): super();
+ _CreateRolePageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
}
class _EditRolePageState extends EditRoleCustom {
- _EditRolePageState(int primaryKey): super(primaryKey);
+ _EditRolePageState(int primaryKey) : super(primaryKey);
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
}
class _ListRolePageState extends ListRoleCustom {
- _ListRolePageState(): super();
+ _ListRolePageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
@override
_CreateStructurePageState createState() {
final rc = _CreateStructurePageState();
- rc.attendedPage =
- AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates);
+ rc.attendedPage = AttendedPage(
+ this, rc, GlobalData(), StructureMeta.instance, pageStates);
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
class _CreateStructurePageState extends CreateStructureCustom {
- _CreateStructurePageState(): super();
+ _CreateStructurePageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
@override
_DeleteStructurePageState createState() {
final rc = _DeleteStructurePageState(this.primaryKey);
- rc.attendedPage =
- AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates);
+ rc.attendedPage = AttendedPage(
+ this, rc, GlobalData(), StructureMeta.instance, pageStates);
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
class _DeleteStructurePageState extends DeleteStructureCustom {
- _DeleteStructurePageState(int primaryKey): super(primaryKey);
+ _DeleteStructurePageState(int primaryKey) : super(primaryKey);
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
@override
_EditStructurePageState createState() {
final rc = _EditStructurePageState(this.primaryKey);
- rc.attendedPage =
- AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates);
+ rc.attendedPage = AttendedPage(
+ this, rc, GlobalData(), StructureMeta.instance, pageStates);
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
class _EditStructurePageState extends EditStructureCustom {
- _EditStructurePageState(int primaryKey): super(primaryKey);
+ _EditStructurePageState(int primaryKey) : super(primaryKey);
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
@override
_ListStructurePageState createState() {
final rc = _ListStructurePageState();
- rc.attendedPage =
- AttendedPage(this, rc, GlobalData(), StructureMeta.instance, pageStates);
+ rc.attendedPage = AttendedPage(
+ this, rc, GlobalData(), StructureMeta.instance, pageStates);
pageStates.attendedPage = rc.attendedPage;
return rc;
}
}
class _ListStructurePageState extends ListStructureCustom {
- _ListStructurePageState(): super();
+ _ListStructurePageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
formItems,
screenWidth: attendedPage!.pageStates.screenWidth,
padding: padding,
- ))))));
+ ))))));
return rc;
}
}
class _CreateUserPageState extends CreateUserCustom {
- _CreateUserPageState(): super();
+ _CreateUserPageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
weight: 6),
FormItem(
ElevatedButton(
- onPressed: () => verifyAndDelete(), child: Text(i18n.tr('Delete'))),
+ onPressed: () => verifyAndDelete(),
+ child: Text(i18n.tr('Delete'))),
weight: 8,
gapAbove: 2 * padding),
FormItem(
formItems,
screenWidth: attendedPage!.pageStates.screenWidth,
padding: padding,
- ))))));
+ ))))));
return rc;
}
'module': 'Users',
'sql': 'delete',
};
- _fieldData.toMap(parameters);
+ parameters[':id'] = primaryKey;
globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
}
class _DeleteUserPageState extends DeleteUserCustom {
- _DeleteUserPageState(int primaryKey): super(primaryKey);
+ _DeleteUserPageState(int primaryKey) : super(primaryKey);
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
formItems,
screenWidth: attendedPage!.pageStates.screenWidth,
padding: padding,
- ))))));
+ ))))));
return rc;
}
'module': 'Users',
'sql': 'update',
};
+ parameters[':id'] = primaryKey;
_fieldData.toMap(parameters);
globalData.restPersistence!
.store(what: 'store', map: parameters)
- .then((answer) {
-
- });
+ .then((answer) {});
}
void verifyAndStore() {
email = map['user_email'];
role = map['user_role'];
}
+
void toMap(Map<String, dynamic> map) {
- map[':id'] = primaryKey;
+ // please set outside: map[':id'] = primaryKey;
map[':name'] = name;
map[':displayName'] = displayName;
map[':email'] = email;
}
class _EditUserPageState extends EditUserCustom {
- _EditUserPageState(int primaryKey): super(primaryKey);
+ _EditUserPageState(int primaryKey) : super(primaryKey);
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
void initState() {
super.initState();
}
+
@override
- void dispose(){
+ void dispose() {
textController.dispose();
super.dispose();
}
}
class _ListUserPageState extends ListUserCustom {
- _ListUserPageState(): super();
+ _ListUserPageState() : super();
@override
void didChangeDependencies() {
final size = MediaQuery.of(context).size;
'module': 'Users',
'sql': '#SQL_TYPE',
};
- _fieldData.toMap(parameters);
- globalData.restPersistence!
+#SET_PRIMARY#CALL_TO_MAP globalData.restPersistence!
.store(what: 'store', map: parameters)
.then((answer) {
#STORAGE_DONE
continue;
}
final name = field.name;
- final field2 = field as PropertyMetaData;
+ final field2 = field;
String type;
String value;
switch (field2.dataType) {
if (page.pageType == PageType.edit || page.pageType == PageType.create) {
final buffer = StringBuffer(' void toMap(Map<String, dynamic> map) {\n');
if (page.pageType == PageType.edit) {
- buffer.writeln(" map[':id'] = primaryKey;");
+ buffer.writeln(" // please set outside: map[':id'] = primaryKey;");
}
for (var field in page.fields) {
if (!(field is PropertyMetaData) || field.hasOption(':primary:')) {
var action2 = 'verifyAndStore';
var storageDone = '';
var buttonText = 'Save';
- String sqlType = '';
+ var sqlType = '';
+ var setPrimary = '';
+ var callToMap = '';
page.pageType == PageType.edit
? 'update'
: (page.pageType == PageType.delete ? 'delete' : 'insert');
switch (page.pageType) {
case PageType.create:
+ callToMap = ' _fieldData.toMap(parameters);\n';
sqlType = 'insert';
storageDone = templateStorageDoneCreate.replaceFirst(
'#MODULE', page.module.moduleName);
break;
case PageType.edit:
+ callToMap = ' _fieldData.toMap(parameters);\n';
+ setPrimary = " parameters[':id'] = primaryKey;\n";
sqlType = 'update';
storageDone = templateStorageDoneEdit;
hasPrimary = true;
storageDone = '';
break;
case PageType.delete:
+ setPrimary = " parameters[':id'] = primaryKey;\n";
sqlType = 'delete';
buttonText = 'Delete';
action1 = 'delete';
.replaceFirst('#LOAD_RECORD', buildLoadRecord(page))
.replaceFirst('#PAGE_LABEL', page.label)
.replaceFirst('#SQL_TYPE', sqlType)
+ .replaceFirst('#SET_PRIMARY', setPrimary)
+ .replaceFirst('#CALL_TO_MAP', callToMap)
.replaceAll('#ACTION1', action1)
.replaceAll('#ACTION2', action2)
.replaceFirst('#BUTTON', buttonText)