dutyinfo_page.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // ignore_for_file: unused_import
  2. import 'dart:developer';
  3. import 'package:collection/collection.dart';
  4. import 'package:flutter/foundation.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_riverpod/flutter_riverpod.dart';
  7. import 'package:gap/gap.dart';
  8. import 'package:go_router/go_router.dart';
  9. import 'package:google_fonts/google_fonts.dart';
  10. import 'package:jiffy/jiffy.dart';
  11. import 'package:linear_progress_bar/linear_progress_bar.dart';
  12. import 'package:tp5/core/core.dart';
  13. import 'package:tp5/csv/csv_data.dart';
  14. import 'package:tp5/csv/data.dart';
  15. import 'package:tp5/flightslist/w_flt.dart';
  16. import 'package:tp5/fltinfo/delaycodes.dart';
  17. import 'package:tp5/fltinfo/widget/w_cadre.dart';
  18. import 'package:tp5/ftl/widget/w_shadowbox.dart';
  19. import 'package:tp5/lido/lido_api.dart';
  20. import 'package:tp5/lido/model/Lidoapi_list.dart';
  21. import 'package:tp5/lido/model/Lidoapi_ofp.dart';
  22. import 'package:tp5/lido/w_lidoflt.dart';
  23. import 'package:tp5/pdf/pdf_page.dart';
  24. import 'package:tp5/roster/api/crewlink_api.dart';
  25. import 'package:tp5/roster/models/duty.dart';
  26. import 'package:tp5/roster/widgets/w_airport.dart';
  27. import 'package:tp5/roster/widgets/w_citypair.dart';
  28. import 'package:tp5/roster/widgets/w_crew.dart';
  29. import 'package:tp5/roster/widgets/w_day.dart';
  30. import 'package:tp5/roster/widgets/w_fnum.dart';
  31. import 'package:tp5/roster/widgets/w_hour.dart';
  32. import 'package:tp5/widgets/my_row.dart';
  33. class DutyinfoPage extends ConsumerStatefulWidget {
  34. const DutyinfoPage({required this.params, super.key});
  35. final DutyinfoParams params;
  36. @override
  37. ConsumerState<ConsumerStatefulWidget> createState() => _DutyinfoPageState();
  38. }
  39. class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
  40. @override
  41. void initState() {
  42. Future.delayed(Duration.zero, () {
  43. crewPnlegLoad();
  44. });
  45. super.initState();
  46. }
  47. // List crew = [];
  48. Jiffy _now = Jiffy.now().toUtc();
  49. @override
  50. Widget build(BuildContext context) {
  51. //final data = ref.watch(dataProvider);
  52. //final pnleg = data.pnleg;
  53. // final _dateNotifiedcrew = data.pnlegupdate;
  54. _now = ref.watch(clockProvider);
  55. //final qualif = ref.watch(dataProvider).qualif;
  56. return Scaffold(
  57. appBar: AppBar(
  58. title: MyRow(
  59. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  60. children: [
  61. Text(
  62. '${widget.params.dutytype ?? ""} ${widget.params.label ?? ""} ${widget.params.dep}${widget.params.des != null ? "-${widget.params.des}" : ""}'),
  63. const Gap(10),
  64. Text(widget.params.jdep!.format(pattern: "EEE ddMMM'yy"),
  65. style: const TextStyle(fontSize: 12)),
  66. ],
  67. ),
  68. leading: IconButton(
  69. icon: const Icon(Icons.arrow_back),
  70. onPressed: () {
  71. context.pop(context);
  72. },
  73. ),
  74. actions: [
  75. Text(
  76. '${widget.params.dutytype ?? "Duty"} info',
  77. style: TextStyle(
  78. fontSize: 12,
  79. fontWeight: FontWeight.w700,
  80. color: Colors.yellow),
  81. ),
  82. Gap(10)
  83. ],
  84. ),
  85. body: ListView(
  86. padding: const EdgeInsets.all(5),
  87. children: [
  88. WCadre(
  89. child: Column(
  90. children: [
  91. WDay(date: widget.params.jdep!),
  92. if (widget.params.label != null)
  93. Text(
  94. widget.params.label!,
  95. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  96. )
  97. else if (widget.params.dutytype != null)
  98. Text(
  99. widget.params.dutytype!,
  100. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  101. ),
  102. Row(
  103. mainAxisAlignment: MainAxisAlignment.center,
  104. mainAxisSize: MainAxisSize.max,
  105. children: [
  106. if (widget.params.des != null)
  107. WCitypair(
  108. iata1: "${widget.params.dep}",
  109. iata2: widget.params.des ?? "---")
  110. else
  111. WAirport(iata: widget.params.dep ?? "---"),
  112. ],
  113. ),
  114. Row(
  115. mainAxisAlignment: MainAxisAlignment.center,
  116. mainAxisSize: MainAxisSize.max,
  117. children: [
  118. WHour(jiffy: widget.params.jdep!),
  119. if (widget.params.jdes != null) ...[
  120. const Gap(20),
  121. WHour(jiffy: widget.params.jdes!)
  122. ],
  123. ]),
  124. const Gap(10)
  125. ],
  126. ),
  127. ),
  128. const Gap(20),
  129. _notifiedCrew(),
  130. ],
  131. ),
  132. );
  133. }
  134. Jiffy? _dateNotifiedcrew;
  135. static List<Pnleg> filterPnleg(Map data) {
  136. final List<Pnleg> pnleg = data["pnleg"];
  137. final DutyinfoParams filter = data["filter"];
  138. return pnleg
  139. .where((leg) => ((filter.jdep == null || leg.jdep == filter.jdep) &&
  140. (filter.jdes == null || leg.jarr == filter.jdes) &&
  141. (filter.dep == null || leg.dep == filter.dep) &&
  142. (filter.des == null || leg.arr == filter.des) &&
  143. (filter.label == null || leg.label == filter.label) &&
  144. (filter.dutytype == null || leg.dutytype == filter.dutytype)))
  145. .toList();
  146. }
  147. List<Pnleg> crewPnleg = [];
  148. bool crewPnlegLoading = false;
  149. crewPnlegLoad() async {
  150. crewPnlegLoading = true;
  151. setState(() {});
  152. final data = ref.watch(dataProvider);
  153. final pnleg = data.pnleg;
  154. _dateNotifiedcrew = data.pnlegupdate;
  155. crewPnleg =
  156. await compute(filterPnleg, {"pnleg": pnleg, "filter": widget.params});
  157. crewPnlegLoading = false;
  158. setState(() {});
  159. }
  160. _notifiedCrew() {
  161. final qualif = ref.watch(qualifProvider(CrewFilter()));
  162. // final crewPnleg = pnleg.where((leg) =>
  163. // ((widget.params.jdep == null || leg.jdep == widget.params.jdep) &&
  164. // (widget.params.jdes == null || leg.jarr == widget.params.jdes) &&
  165. // (widget.params.dep == null || leg.dep == widget.params.dep) &&
  166. // (widget.params.des == null || leg.arr == widget.params.des) &&
  167. // (widget.params.label == null || leg.label == widget.params.label) &&
  168. // (widget.params.dutytype == null ||
  169. // leg.dutytype == widget.params.dutytype)));
  170. return WCadre(
  171. titleright: crewPnlegLoading
  172. ? Padding(
  173. padding: const EdgeInsets.all(5.0),
  174. child: CircularProgressIndicator(),
  175. )
  176. : null,
  177. title: "Notified Crew (alt)",
  178. bottomright: _dateNotifiedcrew != null
  179. ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
  180. style: GoogleFonts.robotoMono(
  181. fontSize: 10, fontWeight: FontWeight.w300))
  182. : null,
  183. child: crewPnleg.isEmpty
  184. ? const Text("No data found !")
  185. : Column(
  186. children: [
  187. Padding(
  188. padding: const EdgeInsets.all(8.0),
  189. child: Column(
  190. children: crewPnleg
  191. .mapIndexed((int i, leg) => {
  192. "index": i,
  193. "college": (["F", ""].contains(leg.type))
  194. ? "DH"
  195. : (qualif
  196. .firstWhereOrNull((e) =>
  197. (e.tlc == leg.tlc) &&
  198. (e.ac == leg.actype))
  199. ?.college ??
  200. qualif
  201. .firstWhereOrNull(
  202. (e) => e.tlc == leg.tlc)
  203. ?.college ??
  204. "--")
  205. })
  206. .sortedByCompare(
  207. (e) => e["college"].toString(), collegeSort)
  208. .map<Widget>((e) {
  209. final x = crewPnleg.elementAt(e["index"] as int);
  210. final pn = qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  211. return WCrew(
  212. college: pn?.college,
  213. mle: x.tlc,
  214. base: pn?.base,
  215. name: "${pn?.lname}, ${pn?.fname}",
  216. );
  217. }).toList()),
  218. )
  219. ],
  220. ),
  221. );
  222. }
  223. }
  224. class DutyinfoParams {
  225. const DutyinfoParams({
  226. this.date,
  227. this.start,
  228. this.end,
  229. this.label,
  230. this.dutytype,
  231. this.jdep,
  232. this.jdes,
  233. this.dep,
  234. this.des,
  235. });
  236. final Jiffy? start;
  237. final Jiffy? end;
  238. final String? date;
  239. final String? label;
  240. final String? dutytype;
  241. final Jiffy? jdep;
  242. final Jiffy? jdes;
  243. final String? dep;
  244. final String? des;
  245. }
  246. int collegeSort(String a, String b) {
  247. // Define the order based on your requirements
  248. final order = ['CP', 'FO', 'PU', 'SE', 'ST', 'JU'];
  249. // Get the index of each element in the order list
  250. final indexA = order.indexOf(a);
  251. final indexB = order.indexOf(b);
  252. // Compare based on the index
  253. return indexA.compareTo(indexB);
  254. }