Commit d3009be
Changed files (2)
lib
model
export_import
storage
lib/model/export_import/column.dart
@@ -11,6 +11,7 @@ class NativeColumn extends ExportColumn {
NativeColumn._create(this._csvTitle, this._restoreableType, this._encode, this._decode) {
allColumns.add(this);
}
+ static final List<NativeColumn> allColumns = [];
final String _csvTitle;
final RowDataFieldType _restoreableType;
@@ -75,8 +76,6 @@ class NativeColumn extends ExportColumn {
}
);
- static final List<NativeColumn> allColumns = [];
-
@override
String get csvTitle => _csvTitle;
@@ -94,7 +93,7 @@ class NativeColumn extends ExportColumn {
String? get formatPattern => null;
@override
- String get internalIdentifier => 'buildin.$csvTitle';
+ String get internalIdentifier => 'native.$csvTitle';
@override
RowDataFieldType? get restoreAbleType => _restoreableType;
@@ -105,33 +104,50 @@ class NativeColumn extends ExportColumn {
}
-// TODO: add class for formattedTimestamp
-// TODO: keep pulsePressure option
+/// Useful columns that are present by default and recreatable through a formatPattern.
+class BuildInColumn extends ExportColumn {
+ /// Creates a build in column and adds it to allColumns.
+ ///
+ /// [internalIdentifier] will be csvTitle prefixed with "buildin".
+ BuildInColumn._create(this.csvTitle, String formatString, this._userTitle) {
+ allColumns.add(this);
+ }
+
+ static final List<BuildInColumn> allColumns = [];
+
+ static final pulsePressure = BuildInColumn._create(
+ 'pulsePressure',
+ r'{{$SYS-$DIA}}',
+ (localizations) => localizations.pulsePressure
+ );
+ @override
+ String get internalIdentifier => 'buildin.$csvTitle';
-/// Interface for converters that allow formatting and provide metadata.
-sealed class ExportColumn implements Formatter {
- /// Unique internal identifier that is used to identify a column in the app.
- ///
- /// A identifier can be any string, but is usually structured with a prefix and
- /// a name. For example `buildin.sys`, `user.fancyvalue` or `convert.myheartsys`.
- /// These examples are not guaranteed to be the prefixes used in the rest of the
- /// app.
- ///
- /// It should not be used instead of [csvTitle].
- String get internalIdentifier;
+ @override
+ final String csvTitle;
- /// Column title in a csv file.
- ///
- /// May not contain characters intended for CSV column separation (e.g. `,`).
- String get csvTitle;
+ final String Function(AppLocalizations localizations) _userTitle;
- /// Column title in user facing places that don't require strict rules.
- ///
- /// It will be displayed on the exported PDF file or in the column selection.
- String userTitle(AppLocalizations localizations);
+ @override
+ String userTitle(AppLocalizations localizations) => _userTitle(localizations);
+
+ late final Formatter _formatter;
+
+ @override
+ (RowDataFieldType, dynamic)? decode(String pattern) => _formatter.decode(pattern);
+
+ @override
+ String encode(BloodPressureRecord record) => _formatter.encode(record);
+
+ @override
+ String? get formatPattern => _formatter.formatPattern;
+
+ @override
+ RowDataFieldType? get restoreAbleType => _formatter.restoreAbleType;
}
+// TODO: add class for formattedTimestamp
/// Class for storing export behavior of columns.
///
@@ -168,3 +184,27 @@ class UserColumn extends ExportColumn {
@override
RowDataFieldType? get restoreAbleType => formatter.restoreAbleType;
}
+
+
+/// Interface for converters that allow formatting and provide metadata.
+sealed class ExportColumn implements Formatter {
+ /// Unique internal identifier that is used to identify a column in the app.
+ ///
+ /// A identifier can be any string, but is usually structured with a prefix and
+ /// a name. For example `buildin.sys`, `user.fancyvalue` or `convert.myheartsys`.
+ /// These examples are not guaranteed to be the prefixes used in the rest of the
+ /// app.
+ ///
+ /// It should not be used instead of [csvTitle].
+ String get internalIdentifier;
+
+ /// Column title in a csv file.
+ ///
+ /// May not contain characters intended for CSV column separation (e.g. `,`).
+ String get csvTitle;
+
+ /// Column title in user facing places that don't require strict rules.
+ ///
+ /// It will be displayed on the exported PDF file or in the column selection.
+ String userTitle(AppLocalizations localizations);
+}
lib/model/storage/export_columns_store.dart
@@ -43,10 +43,11 @@ class ExportColumnsManager extends ChangeNotifier { // TODO: separate ExportColu
/// Get any defined column (user or build in) by identifier.
ExportColumn? getColumn(String identifier) {// TODO test
- return userColumns[identifier] ??
- NativeColumn.allColumns.where(
- (c) => c.internalIdentifier == identifier)
- .firstOrNull; // ?? ...
+ return userColumns[identifier]
+ ?? NativeColumn.allColumns.where(
+ (c) => c.internalIdentifier == identifier).firstOrNull
+ ?? BuildInColumn.allColumns.where(
+ (c) => c.internalIdentifier == identifier).firstOrNull; // ?? ...
}
String toJson() {