-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/modules/metadata/option_group/entities/option_group.entity.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:d2_touch/core/annotations/index.dart'; | ||
import 'package:d2_touch/shared/entities/identifiable.entity.dart'; | ||
|
||
@AnnotationReflectable | ||
@Entity(tableName: 'optiongroup', apiResourceName: 'optionGroups') | ||
class OptionGroup extends IdentifiableEntity { | ||
@Column(type: ColumnType.TEXT) | ||
String options; | ||
|
||
OptionGroup({ | ||
required String id, | ||
required String name, | ||
required bool dirty, | ||
required this.options, | ||
}) : super(id: id, name: name, dirty: dirty); | ||
|
||
factory OptionGroup.fromJson(Map<String, dynamic> jsonData) { | ||
return OptionGroup( | ||
id: jsonData['id'], | ||
name: jsonData['name'], | ||
dirty: jsonData['dirty'], | ||
options: jsonEncode(jsonData['options']), | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['id'] = this.id; | ||
data['name'] = this.name; | ||
data['dirty'] = this.dirty; | ||
data['options'] = this.options; | ||
return data; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lib/modules/metadata/option_group/option_group.module.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:d2_touch/modules/metadata/option_group/queries/option_group.query.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
class OptionGroupModule { | ||
Database? database; | ||
OptionGroupModule({this.database, String? locale}); | ||
static createTables({required Database database}) async { | ||
await OptionGroupQuery(database: database).createTable(); | ||
} | ||
|
||
OptionGroupQuery get optionGroup => OptionGroupQuery(database: database); | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/modules/metadata/option_group/queries/option_group.query.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:d2_touch/modules/metadata/option_group/entities/option_group.entity.dart'; | ||
import 'package:d2_touch/shared/queries/base.query.dart'; | ||
import 'package:d2_touch/shared/utilities/query_filter.util.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
class OptionGroupQuery extends BaseQuery<OptionGroup> { | ||
OptionGroupQuery({Database? database}) : super(database: database); | ||
|
||
@override | ||
Future<String> dhisUrl() { | ||
final apiFilter = | ||
QueryFilter.getApiFilters(this.repository.columns, this.filters); | ||
|
||
if ((this.selected).isNotEmpty) { | ||
return Future.value( | ||
'optionGroups.json${apiFilter != null ? '?$apiFilter&' : '?'}fields=${this.selected.join(',')}&paging=false'); | ||
} | ||
|
||
return Future.value( | ||
'optionGroups.json${apiFilter != null ? '?$apiFilter&' : '?'}fields=id,name,shortName,options[code,name]&paging=false'); | ||
} | ||
} |