b9639650e5
Port the web client's list/save/delete schedule request shapes and reply checks, with a typed record that preserves the whole server payload including unknown fields. Revision stays the CAS token; server refusals propagate unchanged.
42 lines
1.3 KiB
Dart
42 lines
1.3 KiB
Dart
import '../../../core/api_gateway.dart';
|
|
import 'schedule_json.dart';
|
|
|
|
/// Weekday keys the server accepts for an interval rule.
|
|
const scheduleDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
|
|
/// The timer part of a saved schedule (`rule` on the wire).
|
|
///
|
|
/// This is a view over the decoded server record, not a timer implementation:
|
|
/// it never calculates due times, converts timezones or starts runs. Unknown
|
|
/// rule fields stay in [raw] and are returned by [toJson].
|
|
class ScheduleRule {
|
|
ScheduleRule([JsonMap? raw]) : raw = cloneJsonMap(raw ?? const {});
|
|
|
|
final JsonMap raw;
|
|
|
|
/// Go-style duration such as `24h` or `1h30m`; empty for a clock rule.
|
|
String get every => _text(raw['every']);
|
|
|
|
/// Distinct 24-hour times such as `09:00`; empty for an interval rule.
|
|
List<String> get times => _texts(raw['times']);
|
|
|
|
/// Empty means every day (written as absent on the wire).
|
|
List<String> get days => _texts(raw['days']);
|
|
|
|
/// Empty or `Local` means the server's timezone.
|
|
String get timezone => _text(raw['timezone']);
|
|
|
|
bool get isClock => times.isNotEmpty;
|
|
|
|
JsonMap toJson() => cloneJsonMap(raw);
|
|
}
|
|
|
|
String _text(dynamic value) => value is String ? value : '';
|
|
|
|
List<String> _texts(dynamic value) => value is List
|
|
? [
|
|
for (final item in value)
|
|
if (item is String) item,
|
|
]
|
|
: const [];
|