2024-11-07 05:52:03 +01:00
|
|
|
import 'package:ambito/src/entity/_general/filter/item_filter.dart';
|
|
|
|
import 'package:ambito/src/entity/_general/filter/item_filter_repository.dart';
|
|
|
|
import 'package:ambito/src/entity/measure/measure_repository.dart';
|
2024-12-04 16:21:50 +01:00
|
|
|
import 'package:ambito/src/entity/measure/types/measure_types.dart';
|
2024-11-07 05:52:03 +01:00
|
|
|
import 'package:ambito/src/extensions/extensions.dart';
|
|
|
|
import 'package:ambito/src/packages/ambito_theme/ambito_theme.dart';
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-11-18 09:15:00 +01:00
|
|
|
import 'package:screen_breakpoints/screen_breakpoints.dart';
|
2024-11-07 05:52:03 +01:00
|
|
|
import 'package:syncfusion_flutter_calendar/calendar.dart';
|
|
|
|
|
2024-11-09 22:03:03 +01:00
|
|
|
import '../../consts/consts.dart';
|
2024-11-07 05:52:03 +01:00
|
|
|
import '../../widgets/appbar/ambito_appbar.dart';
|
|
|
|
|
|
|
|
class CalendarPage extends StatefulWidget {
|
|
|
|
const CalendarPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => CalendarPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class CalendarPageState extends State<CalendarPage> {
|
|
|
|
List<Appointment> appointments = <Appointment>[];
|
|
|
|
|
2024-11-20 17:09:53 +01:00
|
|
|
Set<ItemFilter>? monthFilter = {};
|
2024-11-07 05:52:03 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
initDataSource();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
initDataSource() {
|
|
|
|
monthFilter = ItemFilterRepository().getByType('month');
|
|
|
|
for (String month in months) {
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
int monthInt = months.indexOf(month) + 1;
|
|
|
|
|
|
|
|
DateTime startDate = DateTime(now.year, monthInt, 1, 0, 0, 0);
|
|
|
|
DateTime endDate = DateTime(
|
|
|
|
now.year, monthInt, startDate.lastDayOfMonth.day, 23, 59, 59);
|
|
|
|
|
|
|
|
ItemFilter? itemFilter =
|
|
|
|
monthFilter?.firstWhereOrNull((item) => item.name == month);
|
|
|
|
if (itemFilter != null) {
|
2024-12-04 16:21:50 +01:00
|
|
|
List<MeasureTypes?> currentMeasures =
|
2024-11-07 05:52:03 +01:00
|
|
|
MeasureRepository().getByIds(itemFilter.ids!);
|
|
|
|
for (var measure in currentMeasures) {
|
|
|
|
appointments.add(
|
|
|
|
Appointment(
|
|
|
|
startTime: startDate,
|
|
|
|
endTime: endDate,
|
|
|
|
isAllDay: true,
|
2024-12-04 16:21:50 +01:00
|
|
|
subject: measure!.measureType ?? '',
|
|
|
|
color: actionGroupColors[measure.measureGroup!.value!]!,
|
2024-11-07 05:52:03 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-20 17:09:53 +01:00
|
|
|
final AmbitoTheme theme = getTheme(context);
|
|
|
|
|
2024-11-07 05:52:03 +01:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AmbitoAppbar(
|
|
|
|
links: const ['dashboard', 'massnahmen'],
|
2024-11-18 09:15:00 +01:00
|
|
|
breakpoint: Breakpoint.fromContext(context),
|
2024-11-20 17:09:53 +01:00
|
|
|
theme: theme,
|
2024-11-07 05:52:03 +01:00
|
|
|
),
|
|
|
|
body: Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(32),
|
|
|
|
child: SfCalendar(
|
|
|
|
firstDayOfWeek: 1,
|
|
|
|
showNavigationArrow: true,
|
|
|
|
view: CalendarView.month,
|
|
|
|
dataSource: _AppointmentDataSource(appointments),
|
|
|
|
monthViewSettings: const MonthViewSettings(
|
|
|
|
appointmentDisplayMode: MonthAppointmentDisplayMode.appointment,
|
|
|
|
appointmentDisplayCount: 64,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_AppointmentDataSource _getCalendarDataSource() {
|
|
|
|
List<Appointment> appointments = <Appointment>[];
|
|
|
|
appointments.add(Appointment(
|
|
|
|
startTime: DateTime.now(),
|
2024-11-20 17:09:53 +01:00
|
|
|
endTime: DateTime.now().add(const Duration(minutes: 10)),
|
2024-11-07 05:52:03 +01:00
|
|
|
subject: 'Meeting',
|
|
|
|
isAllDay: true,
|
|
|
|
color: Colors.blue,
|
|
|
|
startTimeZone: '',
|
|
|
|
endTimeZone: '',
|
|
|
|
));
|
|
|
|
|
|
|
|
return _AppointmentDataSource(appointments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppointmentDataSource extends CalendarDataSource {
|
|
|
|
_AppointmentDataSource(List<Appointment> source) {
|
|
|
|
appointments = source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*class ActionDataSource extends CalendarDataSource {
|
|
|
|
ActionDataSource(List<Action> source) {
|
|
|
|
appointments = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
DateTime getStartTime(int index) {
|
|
|
|
return appointments![index].from;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
DateTime getEndTime(int index) {
|
|
|
|
return appointments![index].to;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool isAllDay(int index) {
|
|
|
|
return appointments![index].isAllDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String getSubject(int index) {
|
|
|
|
return appointments![index].eventName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String getStartTimeZone(int index) {
|
|
|
|
return appointments![index].startTimeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String getEndTimeZone(int index) {
|
|
|
|
return appointments![index].endTimeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Color getColor(int index) {
|
|
|
|
return appointments![index].background;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Action {
|
|
|
|
Action(
|
|
|
|
{this.eventName = '',
|
|
|
|
required this.from,
|
|
|
|
required this.to,
|
|
|
|
required this.background,
|
|
|
|
this.isAllDay = false});
|
|
|
|
|
|
|
|
String eventName;
|
|
|
|
DateTime from;
|
|
|
|
DateTime to;
|
|
|
|
Color background;
|
|
|
|
bool isAllDay;
|
|
|
|
}*/
|