2021-10-26 23:25:40 +00:00
|
|
|
// import 'package:diameter/utils/date_time_utils.dart';
|
|
|
|
// import 'package:flutter/material.dart';
|
2021-10-22 23:08:09 +00:00
|
|
|
import 'package:parse_server_sdk_flutter/parse_server_sdk.dart';
|
|
|
|
import 'package:diameter/models/basal_profile.dart';
|
|
|
|
import 'package:diameter/components/data_table.dart';
|
|
|
|
|
|
|
|
class Basal extends DataTableContent {
|
|
|
|
late String? objectId;
|
|
|
|
late DateTime startTime;
|
|
|
|
late DateTime endTime;
|
|
|
|
late double units;
|
|
|
|
late String basalProfile;
|
|
|
|
|
|
|
|
Basal(ParseObject? object) {
|
|
|
|
if (object != null) {
|
|
|
|
objectId = object.get<String>('objectId');
|
2021-10-26 23:25:40 +00:00
|
|
|
startTime = object.get<DateTime>('startTime')!.toLocal();
|
|
|
|
endTime = object.get<DateTime>('endTime')!.toLocal();
|
2021-10-22 23:08:09 +00:00
|
|
|
units = object.get<num>('units')! / 100;
|
|
|
|
basalProfile =
|
|
|
|
object.get<ParseObject>('basalProfile')!.get<String>('objectId')!;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<Basal?> get(String objectId) async {
|
|
|
|
QueryBuilder<ParseObject> query =
|
|
|
|
QueryBuilder<ParseObject>(ParseObject('Basal'))
|
|
|
|
..whereEqualTo('objectId', objectId);
|
|
|
|
final ParseResponse apiResponse = await query.query();
|
|
|
|
|
|
|
|
if (apiResponse.success && apiResponse.results != null) {
|
|
|
|
return Basal(apiResponse.result.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<List<Basal>> fetchAllForBasalProfile(
|
|
|
|
BasalProfile basalProfile) async {
|
|
|
|
QueryBuilder<ParseObject> query =
|
|
|
|
QueryBuilder<ParseObject>(ParseObject('Basal'))
|
|
|
|
..whereEqualTo(
|
|
|
|
'basalProfile',
|
|
|
|
(ParseObject('BasalProfile')..objectId = basalProfile.objectId!)
|
2021-10-26 23:25:40 +00:00
|
|
|
.toPointer())
|
|
|
|
..orderByAscending('startTime');
|
2021-10-22 23:08:09 +00:00
|
|
|
final ParseResponse apiResponse = await query.query();
|
|
|
|
|
|
|
|
if (apiResponse.success && apiResponse.results != null) {
|
|
|
|
return apiResponse.results!.map((e) => Basal(e as ParseObject)).toList();
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> save({
|
|
|
|
required DateTime startTime,
|
|
|
|
required DateTime endTime,
|
|
|
|
required double units,
|
|
|
|
required String basalProfile,
|
|
|
|
}) async {
|
|
|
|
final basal = ParseObject('Basal')
|
2021-10-26 23:25:40 +00:00
|
|
|
..set('startTime', startTime.toUtc())
|
|
|
|
..set('endTime', endTime.toUtc())
|
2021-10-22 23:08:09 +00:00
|
|
|
..set('units', units * 100)
|
|
|
|
..set('basalProfile',
|
|
|
|
(ParseObject('BasalProfile')..objectId = basalProfile).toPointer());
|
|
|
|
await basal.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<void> update(
|
|
|
|
String objectId, {
|
|
|
|
DateTime? startTime,
|
|
|
|
DateTime? endTime,
|
|
|
|
double? units,
|
|
|
|
}) async {
|
|
|
|
var basal = ParseObject('Basal')..objectId = objectId;
|
|
|
|
if (startTime != null) {
|
2021-10-26 23:25:40 +00:00
|
|
|
basal.set('startTime', startTime.toUtc());
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
if (endTime != null) {
|
2021-10-26 23:25:40 +00:00
|
|
|
basal.set('endTime', endTime.toUtc());
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|
|
|
|
if (units != null) {
|
|
|
|
basal.set('units', units * 100);
|
|
|
|
}
|
|
|
|
await basal.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> delete() async {
|
|
|
|
var basal = ParseObject('Basal')..objectId = objectId;
|
|
|
|
await basal.delete();
|
|
|
|
}
|
2021-10-26 23:25:40 +00:00
|
|
|
//
|
|
|
|
// @override
|
|
|
|
// List<DataCell> asDataTableCells(List<Widget>? actions) {
|
|
|
|
// return [
|
|
|
|
// DataCell(Text(DateTimeUtils.displayTime(startTime))),
|
|
|
|
// DataCell(Text(DateTimeUtils.displayTime(endTime))),
|
|
|
|
// DataCell(Text('${units.toString()} U')),
|
|
|
|
// DataCell(
|
|
|
|
// Row(
|
|
|
|
// children: actions ?? [],
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ];
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// static List<DataColumn> asDataTableColumns() {
|
|
|
|
// return [
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Start Time'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('End Time'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Units'))),
|
|
|
|
// const DataColumn(label: Expanded(child: Text('Actions'))),
|
|
|
|
// ];
|
|
|
|
// }
|
2021-10-22 23:08:09 +00:00
|
|
|
}
|