fist commit ftc staff app clone
This commit is contained in:
136
lib/controllers/rota/book_holiday_screen_controller.dart
Normal file
136
lib/controllers/rota/book_holiday_screen_controller.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event_list.dart';
|
||||
import 'package:ftc_mobile_app/models/requests/HolidayRequestData.dart';
|
||||
import 'package:ftc_mobile_app/models/staffWorkload/StaffWorkloadResponse.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../ftc_mobile_app.dart';
|
||||
|
||||
class BookHolidayScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final targetDateTime = DateTime.now().obs;
|
||||
|
||||
final agreeToRules = false.obs;
|
||||
|
||||
final holidayStartDate = DateTime.now().obs;
|
||||
final holidayEndDate = Rx<DateTime>(DateTime.now());
|
||||
final holidayDays = 0.obs;
|
||||
final holidayHours = 0.obs;
|
||||
|
||||
final myWorkLoads = Rx<StaffWorkLoads?>(null);
|
||||
|
||||
final _controller = Get.put(RotaDashboardScreenController());
|
||||
|
||||
Rx<EventList<Event>> get markedDatesMap => _controller.markedDatesMap;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_calculateDaysAndHours();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
fetchRecords();
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
onRangeSelect(
|
||||
DateTime rangeStart, DateTime? rangeEnd, List<String> selectedDates) {
|
||||
print(
|
||||
"rangeStart: ${rangeStart.toString()}\nrangeEnd: ${rangeEnd.toString()}");
|
||||
|
||||
holidayStartDate.value = rangeStart;
|
||||
|
||||
holidayEndDate.value = rangeEnd ?? (rangeStart);
|
||||
_calculateDaysAndHours();
|
||||
}
|
||||
|
||||
_calculateDaysAndHours() {
|
||||
holidayDays.value = holidayEndDate().difference(holidayStartDate()).inDays;
|
||||
if (DateFormatter.dateFormatter.format(holidayStartDate()) !=
|
||||
DateFormatter.dateFormatter.format(holidayEndDate())) {
|
||||
holidayDays.value += 1;
|
||||
} else {
|
||||
holidayDays.value = 1;
|
||||
}
|
||||
|
||||
//Filtering out shifts that fall between the holiday ranges
|
||||
final shifts = _controller.myShiftsList.where((shift) {
|
||||
final dateNotNull = shift.shiftDateTime != null;
|
||||
|
||||
final isWithinHolidayRange =
|
||||
shift.shiftDateTime!.isAfter(holidayStartDate()) &&
|
||||
shift.shiftDateTime!.isBefore(holidayEndDate());
|
||||
|
||||
final onHolidayStartDate =
|
||||
DateFormatter.dateFormatter.format(shift.shiftDateTime!) ==
|
||||
DateFormatter.dateFormatter.format(holidayStartDate());
|
||||
|
||||
final onHolidayEndDate =
|
||||
DateFormatter.dateFormatter.format(shift.shiftDateTime!) ==
|
||||
DateFormatter.dateFormatter.format(holidayEndDate());
|
||||
|
||||
return (dateNotNull &&
|
||||
(onHolidayStartDate || isWithinHolidayRange || onHolidayEndDate));
|
||||
}).toList();
|
||||
|
||||
holidayHours.value = shifts.fold(
|
||||
0, (previousValue, shift) => (shift.workHrs ?? 0) + previousValue);
|
||||
|
||||
// holidayHours.value =
|
||||
// holidayEndDate().difference(holidayStartDate()).inHours;
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
Future<void> fetchRecords() async {
|
||||
var response = await RotaService().getStaffWorkload().showLoader();
|
||||
if (response is StaffWorkloadResponse) {
|
||||
final workLoads = response.data?.staffWorkLoads ?? [];
|
||||
|
||||
if (workLoads.isNotEmpty) {
|
||||
myWorkLoads.value = workLoads.first;
|
||||
}
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> requestHoliday() async {
|
||||
if (agreeToRules.isFalse) {
|
||||
FrequentFunctions.showToast(
|
||||
message: "Please select agree to booking rules first");
|
||||
return false;
|
||||
}
|
||||
|
||||
var response = await RotaService()
|
||||
.requestHoliday(
|
||||
request: HolidayRequestData(
|
||||
hldRqStartDate: holidayStartDate().toUtc().millisecondsSinceEpoch,
|
||||
hldRqEndDate: holidayEndDate().toUtc().millisecondsSinceEpoch,
|
||||
hldRqTotalDays: holidayDays(),
|
||||
hldRqTotalHours: holidayHours(),
|
||||
hldRqStatus: "pending",
|
||||
hldRequestType: "holiday",
|
||||
),
|
||||
)
|
||||
.showLoader();
|
||||
if (response is ResponseModel) {
|
||||
return true;
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<BookHolidayScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
122
lib/controllers/rota/calendar_view_screen_controller.dart
Normal file
122
lib/controllers/rota/calendar_view_screen_controller.dart
Normal file
@@ -0,0 +1,122 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event_list.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../ftc_mobile_app.dart';
|
||||
|
||||
class CalendarViewScreenController extends GetxController {
|
||||
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
// Rx<EventList<Event>> markedDatesMap = EventList<Event>(events: {},).obs;
|
||||
Rx<DateTime> targetDateTime = DateTime(2024, 1, 1).obs;
|
||||
RxString currentMonthName =
|
||||
DateFormat.yMMM().format(DateTime(2024, 1, 1)).obs;
|
||||
Rx<EventList<Event>> events = EventList<Event>(
|
||||
events: {},
|
||||
).obs;
|
||||
// RxList<MarkDatesModel> markedDatesList = RxList();
|
||||
RxList<RotaShift> datesToShowList = RxList();
|
||||
Rx<MarkDatesModel> selectedDate = MarkDatesModel.empty().obs;
|
||||
|
||||
// RxList<MonthWiseRecord> monthWiseRecord = RxList();
|
||||
RxList<RotaShift> rotaShiftList = RxList();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
fetchRecords();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void markDatesOnCalendar() {
|
||||
// markedDatesList.removeAt(0); //for removing late initialization error
|
||||
// for (var rotaShift in rotaShiftList) {
|
||||
// markedDatesList.add(
|
||||
// MarkDatesModel.addDate(date: rotaShift.shiftTime, title: "Possible"));
|
||||
// datesToShowList.add(rotaShift);
|
||||
// }
|
||||
|
||||
// for (var markedDate in markedDatesList) {
|
||||
// markedDatesMap.value.add(
|
||||
// DateTime(
|
||||
// markedDate.date.year, markedDate.date.month, markedDate.date.day),
|
||||
// Event(
|
||||
// date: DateTime(
|
||||
// markedDate.date.year, markedDate.date.month, markedDate.date.day),
|
||||
// // date: markedDate.date,
|
||||
// title: markedDate.title,
|
||||
// icon: markedDate.title == "Possible"
|
||||
// ? _underlineIcon(
|
||||
// markedDate.date.day.toString(),
|
||||
// )
|
||||
// : _shiftIcon(
|
||||
// markedDate.date.day.toString(),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// datesToShowList = datesToShowList; // to ask from panday G
|
||||
}
|
||||
|
||||
Widget _shiftIcon(String day) => CircleAvatar(
|
||||
backgroundColor: CustomAppColors.kSecondaryColor,
|
||||
child: Text(
|
||||
day,
|
||||
style:
|
||||
const TextStyle(color: CustomAppColors.kWhiteColor, fontSize: 13),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _underlineIcon(String day) => Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: CustomAppColors.kSecondaryColor,
|
||||
width: 3.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
void onNextMonthTap() {
|
||||
targetDateTime.value = DateTime(targetDateTime.value.year,
|
||||
targetDateTime.value.month + 1, targetDateTime.value.day);
|
||||
currentMonthName.value = DateFormat.yMMM().format(targetDateTime.value);
|
||||
}
|
||||
|
||||
void onPreviousMonthTap() {
|
||||
targetDateTime.value = DateTime(targetDateTime.value.year,
|
||||
targetDateTime.value.month - 1, targetDateTime.value.day);
|
||||
currentMonthName.value = DateFormat.yMMM().format(targetDateTime.value);
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(scaffoldKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
Future<void> fetchRecords() async {
|
||||
isLoading.value = true;
|
||||
// markedDatesList.add(MarkDatesModel.addDate(
|
||||
// date: DateTime(2022, 6, 1),
|
||||
// title: "Possible")); //for removing late initialization error
|
||||
for (var index = 1; index <= 12; index++) {
|
||||
var result = await RotaService().serviceUserShifts(
|
||||
serviceUserId: "65682ad0a01b6c9e6dcde088", month: index, year: 2024);
|
||||
if (result is MonthWiseRecord) {
|
||||
// monthWiseRecord.add(result);
|
||||
rotaShiftList.addAll(FrequentFunctions().findDaysWithData(result));
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
targetDateTime = rotaShiftList.first.shiftTime.obs;
|
||||
currentMonthName =
|
||||
DateFormat.yMMM().format(rotaShiftList.first.shiftTime).obs;
|
||||
isLoading.value = false;
|
||||
markDatesOnCalendar();
|
||||
}
|
||||
}
|
||||
5
lib/controllers/rota/export_rota_controller.dart
Normal file
5
lib/controllers/rota/export_rota_controller.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
export 'calendar_view_screen_controller.dart';
|
||||
export 'rota_dashboard_screen_controller.dart';
|
||||
export 'book_holiday_screen_controller.dart';
|
||||
export 'pick_up_shifts_screen_controller.dart';
|
||||
export 'your_rota_screen_controller.dart';
|
||||
61
lib/controllers/rota/pick_up_shifts_screen_controller.dart
Normal file
61
lib/controllers/rota/pick_up_shifts_screen_controller.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/LiveRoasterResponseData.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/WeekArrayData.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../ftc_mobile_app.dart';
|
||||
|
||||
class PickUpShiftsScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final loadingShifts = false.obs;
|
||||
final myShiftsList = RxList<DaysArrayData>();
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
getAvailableShifts();
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
Future<void> getAvailableShifts() async {
|
||||
loadingShifts.value = true;
|
||||
|
||||
var response = await RotaService().getAvailableShifts();
|
||||
if (response is LiveRoasterResponseData) {
|
||||
myShiftsList.value = response.daysArray ?? [];
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
|
||||
loadingShifts.value = false;
|
||||
}
|
||||
|
||||
Future<void> claimShifts(int index, DaysArrayData data) async {
|
||||
if (data.rosterId!.isNullOrEmpty() ||
|
||||
data.id.isNullOrEmpty() ||
|
||||
(data.locationId?.id).isNullOrEmpty()) return;
|
||||
|
||||
var response = await RotaService()
|
||||
.claimShift(
|
||||
rosterId: data.rosterId!,
|
||||
locationId: data.locationId!.id!,
|
||||
dayId: data.id!)
|
||||
.showLoader();
|
||||
if (response is LiveRoasterResponseData) {
|
||||
myShiftsList[index].isRequested = true;
|
||||
myShiftsList.refresh();
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<PickUpShiftsScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
102
lib/controllers/rota/rota_dashboard_screen_controller.dart
Normal file
102
lib/controllers/rota/rota_dashboard_screen_controller.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event.dart';
|
||||
import 'package:flutter_calendar_carousel/classes/event_list.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/WeekArrayData.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../ftc_mobile_app.dart';
|
||||
import '../../models/rota/LiveRoasterResponseData.dart';
|
||||
|
||||
class RotaDashboardScreenController extends GetxController
|
||||
with GetSingleTickerProviderStateMixin {
|
||||
late TabController tabController = TabController(length: 2, vsync: this);
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final loadingShifts = false.obs;
|
||||
final myShiftsList = RxList<DaysArrayData>();
|
||||
|
||||
//it holds shifts list for the selected date
|
||||
final dateFilteredShiftsList = RxList<DaysArrayData>();
|
||||
|
||||
final targetDateTime = DateTime.now().obs;
|
||||
final markedDatesMap = EventList<Event>(events: {}).obs;
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getMyShifts();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<void> getMyShifts() async {
|
||||
loadingShifts.value = true;
|
||||
|
||||
var response = await RotaService().getMyShifts(
|
||||
startDateMills: DateTime.now().subtract(30.days).millisecondsSinceEpoch,
|
||||
endDateMills: DateTime.now().add(30.days).millisecondsSinceEpoch);
|
||||
if (response is LiveRoasterResponseData) {
|
||||
myShiftsList.value = response.daysArray ?? [];
|
||||
|
||||
createCalendarEvents(myShiftsList());
|
||||
|
||||
_filterShifts(targetDateTime());
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
|
||||
loadingShifts.value = false;
|
||||
}
|
||||
|
||||
createCalendarEvents(List<DaysArrayData> list) {
|
||||
final Map<DateTime, List<Event>> map = {};
|
||||
for (final data in list) {
|
||||
// final date = DateTime.fromMillisecondsSinceEpoch(data.shiftDate!);
|
||||
|
||||
if (data.shiftDateTime == null) return;
|
||||
|
||||
map.addAll({
|
||||
DateTime(data.shiftDateTime!.year, data.shiftDateTime!.month,
|
||||
data.shiftDateTime!.day): [
|
||||
Event(
|
||||
date: DateTime(data.shiftDateTime!.year, data.shiftDateTime!.month,
|
||||
data.shiftDateTime!.day),
|
||||
title: data.serviceUserId?.displayName ?? "",
|
||||
icon: CalendarWidget.underlineIcon(),
|
||||
)
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
markedDatesMap.value.events
|
||||
..clear()
|
||||
..addAll(map);
|
||||
|
||||
markedDatesMap.refresh();
|
||||
}
|
||||
|
||||
onDateSelect(DateTime date, List<Event> events) {
|
||||
targetDateTime.value = date;
|
||||
|
||||
if (events.isNotEmpty) {
|
||||
_filterShifts(date);
|
||||
}
|
||||
}
|
||||
|
||||
_filterShifts(DateTime date) {
|
||||
dateFilteredShiftsList.value = myShiftsList.where((e) {
|
||||
return DateFormatter.dateFormatter
|
||||
.format(DateTime.fromMillisecondsSinceEpoch(e.shiftDate!)) ==
|
||||
DateFormatter.dateFormatter.format(date);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
tabController.dispose();
|
||||
Get.delete<RotaDashboardScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
46
lib/controllers/rota/your_rota_screen_controller.dart
Normal file
46
lib/controllers/rota/your_rota_screen_controller.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/LiveRoasterResponseData.dart';
|
||||
import 'package:ftc_mobile_app/models/rota/WeekArrayData.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../ftc_mobile_app.dart';
|
||||
|
||||
class YourRotaScreenController extends GetxController{
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
final loadingShifts = false.obs;
|
||||
final myShiftsList = RxList<DaysArrayData>();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
getAvailableShifts();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
Future<void> getAvailableShifts() async {
|
||||
loadingShifts.value = true;
|
||||
|
||||
var response = await RotaService().getMyShifts(
|
||||
startDateMills:
|
||||
DateTime.now().toUtc().subtract(30.days).millisecondsSinceEpoch,
|
||||
endDateMills:
|
||||
DateTime.now().toUtc().add(30.days).millisecondsSinceEpoch);
|
||||
if (response is LiveRoasterResponseData) {
|
||||
myShiftsList.value = response.daysArray ?? [];
|
||||
} else if (response is String && response.isNotEmpty) {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
|
||||
loadingShifts.value = false;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<YourRotaScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user