Workforce rotation settings and location permission handling
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/// Rotation configuration for the duty schedule generator.
|
||||
///
|
||||
/// Stored in `app_settings` with key `rotation_config`. Contains:
|
||||
/// - Ordered list of IT Staff IDs for general rotation
|
||||
/// - Ordered list of non-Islam IT Staff IDs for Friday AM rotation
|
||||
/// - Set of excluded IT Staff IDs
|
||||
/// - Initial AM and PM duty assignments for the next generated schedule
|
||||
class RotationConfig {
|
||||
RotationConfig({
|
||||
List<String>? rotationOrder,
|
||||
List<String>? fridayAmOrder,
|
||||
List<String>? excludedStaffIds,
|
||||
this.initialAmStaffId,
|
||||
this.initialPmStaffId,
|
||||
}) : rotationOrder = rotationOrder ?? [],
|
||||
fridayAmOrder = fridayAmOrder ?? [],
|
||||
excludedStaffIds = excludedStaffIds ?? [];
|
||||
|
||||
/// Ordered IDs for standard AM/PM rotation.
|
||||
final List<String> rotationOrder;
|
||||
|
||||
/// Ordered IDs for Friday AM duty (non-Islam staff only).
|
||||
final List<String> fridayAmOrder;
|
||||
|
||||
/// Staff IDs excluded from all rotation.
|
||||
final List<String> excludedStaffIds;
|
||||
|
||||
/// The staff member that should take AM duty on the first day of the next
|
||||
/// generated schedule. `null` means "continue from last week".
|
||||
final String? initialAmStaffId;
|
||||
|
||||
/// The staff member that should take PM duty on the first day of the next
|
||||
/// generated schedule. `null` means "continue from last week".
|
||||
final String? initialPmStaffId;
|
||||
|
||||
factory RotationConfig.fromJson(Map<String, dynamic> json) {
|
||||
return RotationConfig(
|
||||
rotationOrder: _toStringList(json['rotation_order']),
|
||||
fridayAmOrder: _toStringList(json['friday_am_order']),
|
||||
excludedStaffIds: _toStringList(json['excluded_staff_ids']),
|
||||
initialAmStaffId: json['initial_am_staff_id'] as String?,
|
||||
initialPmStaffId: json['initial_pm_staff_id'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'rotation_order': rotationOrder,
|
||||
'friday_am_order': fridayAmOrder,
|
||||
'excluded_staff_ids': excludedStaffIds,
|
||||
'initial_am_staff_id': initialAmStaffId,
|
||||
'initial_pm_staff_id': initialPmStaffId,
|
||||
};
|
||||
|
||||
RotationConfig copyWith({
|
||||
List<String>? rotationOrder,
|
||||
List<String>? fridayAmOrder,
|
||||
List<String>? excludedStaffIds,
|
||||
String? initialAmStaffId,
|
||||
String? initialPmStaffId,
|
||||
bool clearInitialAm = false,
|
||||
bool clearInitialPm = false,
|
||||
}) {
|
||||
return RotationConfig(
|
||||
rotationOrder: rotationOrder ?? this.rotationOrder,
|
||||
fridayAmOrder: fridayAmOrder ?? this.fridayAmOrder,
|
||||
excludedStaffIds: excludedStaffIds ?? this.excludedStaffIds,
|
||||
initialAmStaffId: clearInitialAm
|
||||
? null
|
||||
: (initialAmStaffId ?? this.initialAmStaffId),
|
||||
initialPmStaffId: clearInitialPm
|
||||
? null
|
||||
: (initialPmStaffId ?? this.initialPmStaffId),
|
||||
);
|
||||
}
|
||||
|
||||
static List<String> _toStringList(dynamic value) {
|
||||
if (value is List) return value.map((e) => e.toString()).toList();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user