Skip to content

Commit

Permalink
Merge pull request #12 from udsm-dhis2-lab/develop
Browse files Browse the repository at this point in the history
Add releases for version 1.0.0-beta.13
  • Loading branch information
BaharaJr authored Sep 9, 2022
2 parents d755388 + 204e5e5 commit 9c5ed3b
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 29 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## [1.0.0-beta.1] - 01/04/2022
## [1.0.0-beta.13] - 09/09/2022

- Add attribute column on attribute option table
- Add attribute column on attribute option table
- Improve datavalue set sync
- Add option to include additional search params

## [1.0.0-beta.11] - 01/04/2022

- Support validation rule execution
- Bug fixes and improvement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:d2_touch/shared/entities/base_entity.dart';
@AnnotationReflectable
@Entity(tableName: 'attributeoption', apiResourceName: 'attributeOptions')
class AttributeOption extends BaseEntity {
@Column()
String attribute;
@ManyToOne(
table: ProgramTrackedEntityAttribute,
joinColumnName: 'programTrackedEntityAttribute')
Expand All @@ -15,6 +17,7 @@ class AttributeOption extends BaseEntity {
required String name,
required String code,
required this.programTrackedEntityAttribute,
required this.attribute,
required bool dirty})
: super(id: id, name: name, code: code, dirty: dirty);

Expand All @@ -25,6 +28,7 @@ class AttributeOption extends BaseEntity {
code: jsonData['code'],
programTrackedEntityAttribute:
jsonData['programTrackedEntityAttribute'],
attribute: jsonData['attribute'],
dirty: jsonData['dirty']);
}

Expand All @@ -34,6 +38,7 @@ class AttributeOption extends BaseEntity {
data['name'] = this.name;
data['code'] = this.code;
data['programTrackedEntityAttribute'] = this.programTrackedEntityAttribute;
data['attribute'] = this.attribute;
data['dirty'] = this.dirty;
return data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ class ProgramTrackedEntityAttribute extends BaseEntity {
Map<String, dynamic> jsonData) {
final optionSetValueCount =
jsonData['trackedEntityAttribute']?['optionSet']?['options']?.length;
final attribute =
jsonData['attribute'] ?? jsonData['trackedEntityAttribute']?['id'];
return ProgramTrackedEntityAttribute(
id: jsonData['id'],
attribute:
jsonData['attribute'] ?? jsonData['trackedEntityAttribute']?['id'],
attribute: attribute,
renderOptionsAsRadio: jsonData['renderOptionsAsRadio'],
name: jsonData['trackedEntityAttribute']?['name'] ?? jsonData['name'],
displayName: jsonData['trackedEntityAttribute']?['displayName'] ??
Expand All @@ -105,8 +106,9 @@ class ProgramTrackedEntityAttribute extends BaseEntity {
[])
.map((option) => AttributeOption.fromJson({
...option,
'id': '${option['id']}_${jsonData['id']}}',
'id': '${option['id']}_${jsonData['id']}_$attribute',
'programTrackedEntityAttribute': jsonData['id'],
'attribute': attribute,
'dirty': false
}))
.toList(),
Expand Down
8 changes: 6 additions & 2 deletions lib/shared/queries/base.query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ class BaseQuery<T extends BaseEntity> {
ilike(
{required String attribute,
required dynamic value,
String? filterCondition}) {
String? filterCondition,
String? key,
String? keyValue}) {
this.filters?.add(QueryFilter(
attribute: attribute,
condition: QueryCondition.Ilike,
value: value,
filterCondition: filterCondition));
filterCondition: filterCondition,
key: key,
keyValue: keyValue));
return this;
}

Expand Down
60 changes: 46 additions & 14 deletions lib/shared/utilities/query_filter.util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ class QueryFilter {
QueryCondition condition;
dynamic value;
String? filterCondition;
String? key;
String? keyValue;
QueryFilter(
{required this.attribute,
required this.condition,
required this.value,
this.filterCondition});
this.filterCondition,
this.key,
this.keyValue});

static String? getWhereParameters(
List<Column> columns, List<QueryFilter>? filters) {
Expand All @@ -35,7 +39,7 @@ class QueryFilter {
return '${filter.attribute} LIKE ${QueryFilter.getTypedValue(attributeColumn, filter.value)}';

case QueryCondition.Ilike:
return '${filter.attribute} LIKE ${QueryFilter.getTypedValue(attributeColumn, filter.value, isLikeFilter: true, filterCondition: filter.filterCondition)}';
return '${filter.attribute} LIKE ${QueryFilter.getTypedValue(attributeColumn, filter.value, isLikeFilter: true, filterCondition: filter.filterCondition, key: filter.key, keyValue: filter.keyValue)}';

case QueryCondition.LessThan:
return '${filter.attribute} < ${QueryFilter.getTypedValue(attributeColumn, filter.value)}';
Expand Down Expand Up @@ -109,11 +113,17 @@ class QueryFilter {
}

static getTypedValue(Column attributeColumn, dynamic value,
{bool? isLikeFilter, String? filterCondition}) {
{bool? isLikeFilter,
String? filterCondition,
String? key,
String? keyValue}) {
switch (attributeColumn.columnType) {
case 'TEXT':
return getTextFiler(value,
isLikeFilter: isLikeFilter, filterCondition: filterCondition);
isLikeFilter: isLikeFilter,
filterCondition: filterCondition,
key: key,
keyValue: keyValue);
case 'BOOLEAN':
return value == true ? 1 : 0;
default:
Expand All @@ -122,19 +132,41 @@ class QueryFilter {
}

static getTextFiler(dynamic value,
{bool? isLikeFilter, String? filterCondition}) {
{bool? isLikeFilter,
String? filterCondition,
String? key,
String? keyValue}) {
if (isLikeFilter == false || isLikeFilter == null) {
return '"$value"';
}
switch (filterCondition) {
case 'startsWith':
return '"$value%"';
case 'endsWith':
return '"%$value"';
case 'includes':
return '"%$value%"';
default:
return '"%$value%"';
if (key != null && keyValue != null) {
return filterWithAdditionalAttributes(value,
key: key, keyValue: keyValue);
} else {
switch (filterCondition) {
case 'startsWith':
return '"$value%"';
case 'endsWith':
return '"%$value"';
case 'includes':
return '"%$value%"';
default:
return '"%$value%"';
}
}
}
}

filterWithAdditionalAttributes(dynamic value,
{String? filterCondition, String? key, String? keyValue}) {
switch (filterCondition) {
case 'startsWith':
return '"$value%" AND $key = "$keyValue"';
case 'endsWith':
return '"%$value" AND "$key" = "$keyValue"';
case 'includes':
return '"%$value%" AND $key = "$keyValue"';
default:
return '"%$value%" AND $key = "$keyValue"';
}
}
23 changes: 15 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -175,7 +175,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -274,7 +274,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
json_annotation:
dependency: transitive
description:
Expand All @@ -296,6 +296,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -323,7 +330,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
path_provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -531,7 +538,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sqflite:
dependency: "direct main"
description:
Expand Down Expand Up @@ -608,7 +615,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.9"
timing:
dependency: transitive
description:
Expand All @@ -629,7 +636,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -680,5 +687,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.15.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.1"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: d2_touch
description: DHIS2 Flutter SDK
version: 1.0.0-beta.11
version: 1.0.0-beta.13
homepage:
repository: https://github.com/udsm-dhis2-lab/d2-touch

Expand Down

0 comments on commit 9c5ed3b

Please sign in to comment.