dutyinfo_page.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. Row(
  93. mainAxisAlignment: MainAxisAlignment.center,
  94. mainAxisSize: MainAxisSize.max,
  95. children: [
  96. if (widget.params.des != null)
  97. WCitypair(
  98. iata1: "${widget.params.dep}",
  99. iata2: widget.params.des ?? "---")
  100. else
  101. WAirport(iata: widget.params.dep ?? "---"),
  102. ],
  103. ),
  104. Row(
  105. mainAxisAlignment: MainAxisAlignment.center,
  106. mainAxisSize: MainAxisSize.max,
  107. children: [
  108. WHour(jiffy: widget.params.jdep!),
  109. if (widget.params.jdes != null) ...[
  110. const Gap(20),
  111. WHour(jiffy: widget.params.jdes!)
  112. ],
  113. ]),
  114. const Gap(10)
  115. ],
  116. ),
  117. ),
  118. const Gap(20),
  119. _notifiedCrew(),
  120. ],
  121. ),
  122. );
  123. }
  124. Jiffy? _dateNotifiedcrew;
  125. static List<Pnleg> filterPnleg(Map data) {
  126. final List<Pnleg> pnleg = data["pnleg"];
  127. final DutyinfoParams filter = data["filter"];
  128. return pnleg
  129. .where((leg) => ((filter.jdep == null || leg.jdep == filter.jdep) &&
  130. (filter.jdes == null || leg.jarr == filter.jdes) &&
  131. (filter.dep == null || leg.dep == filter.dep) &&
  132. (filter.des == null || leg.arr == filter.des) &&
  133. (filter.label == null || leg.label == filter.label) &&
  134. (filter.dutytype == null || leg.dutytype == filter.dutytype)))
  135. .toList();
  136. }
  137. List<Pnleg> crewPnleg = [];
  138. bool crewPnlegLoading = false;
  139. crewPnlegLoad() async {
  140. crewPnlegLoading = true;
  141. setState(() {});
  142. final data = ref.watch(dataProvider);
  143. final pnleg = data.pnleg;
  144. _dateNotifiedcrew = data.pnlegupdate;
  145. crewPnleg =
  146. await compute(filterPnleg, {"pnleg": pnleg, "filter": widget.params});
  147. crewPnlegLoading = false;
  148. setState(() {});
  149. }
  150. _notifiedCrew() {
  151. final qualif = ref.watch(qualifProvider(CrewFilter()));
  152. // final crewPnleg = pnleg.where((leg) =>
  153. // ((widget.params.jdep == null || leg.jdep == widget.params.jdep) &&
  154. // (widget.params.jdes == null || leg.jarr == widget.params.jdes) &&
  155. // (widget.params.dep == null || leg.dep == widget.params.dep) &&
  156. // (widget.params.des == null || leg.arr == widget.params.des) &&
  157. // (widget.params.label == null || leg.label == widget.params.label) &&
  158. // (widget.params.dutytype == null ||
  159. // leg.dutytype == widget.params.dutytype)));
  160. return WCadre(
  161. titleright: crewPnlegLoading
  162. ? Padding(
  163. padding: const EdgeInsets.all(5.0),
  164. child: CircularProgressIndicator(),
  165. )
  166. : null,
  167. title: "Notified Crew (alt)",
  168. bottomright: _dateNotifiedcrew != null
  169. ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
  170. style: GoogleFonts.robotoMono(
  171. fontSize: 10, fontWeight: FontWeight.w300))
  172. : null,
  173. child: crewPnleg.isEmpty
  174. ? const Text("No Flights found !")
  175. : Column(
  176. children: [
  177. Padding(
  178. padding: const EdgeInsets.all(8.0),
  179. child: Column(
  180. children: crewPnleg
  181. .mapIndexed((int i, leg) => {
  182. "index": i,
  183. "college": (["F", ""].contains(leg.type))
  184. ? "DH"
  185. : (qualif
  186. .firstWhereOrNull((e) =>
  187. (e.tlc == leg.tlc) &&
  188. (e.ac == leg.actype))
  189. ?.college ??
  190. qualif
  191. .firstWhereOrNull(
  192. (e) => e.tlc == leg.tlc)
  193. ?.college ??
  194. "--")
  195. })
  196. .sortedByCompare(
  197. (e) => e["college"].toString(), collegeSort)
  198. .map<Widget>((e) {
  199. final x = crewPnleg.elementAt(e["index"] as int);
  200. final pn = qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  201. return WCrew(
  202. college: pn?.college,
  203. mle: x.tlc,
  204. base: pn?.base,
  205. name: "${pn?.lname}, ${pn?.fname}",
  206. );
  207. }).toList()),
  208. )
  209. // Padding(
  210. // padding: const EdgeInsets.all(8.0),
  211. // child: Column(
  212. // children: crewPnleg[
  213. // crewPnleg.keys.elementAt(crewPosPnleg)]!
  214. // .map<Widget>((x) {
  215. // final pn =
  216. // qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
  217. // return WCrew(
  218. // college: pn?.college,
  219. // mle: x.tlc,
  220. // base: pn?.base,
  221. // name: "${pn?.lname}, ${pn?.fname}",
  222. // );
  223. // }).toList()),
  224. // )
  225. ],
  226. ),
  227. );
  228. }
  229. }
  230. class DutyinfoParams {
  231. const DutyinfoParams({
  232. this.date,
  233. this.start,
  234. this.end,
  235. this.label,
  236. this.dutytype,
  237. this.jdep,
  238. this.jdes,
  239. this.dep,
  240. this.des,
  241. });
  242. final Jiffy? start;
  243. final Jiffy? end;
  244. final String? date;
  245. final String? label;
  246. final String? dutytype;
  247. final Jiffy? jdep;
  248. final Jiffy? jdes;
  249. final String? dep;
  250. final String? des;
  251. }
  252. int collegeSort(String a, String b) {
  253. // Define the order based on your requirements
  254. final order = ['CP', 'FO', 'PU', 'SE', 'ST', 'JU'];
  255. // Get the index of each element in the order list
  256. final indexA = order.indexOf(a);
  257. final indexB = order.indexOf(b);
  258. // Compare based on the index
  259. return indexA.compareTo(indexB);
  260. }