Fares 11 months ago
parent
commit
df18ff3f11
3 changed files with 239 additions and 131 deletions
  1. 99 13
      lib/fltinfo/view/dutyinfo_page.dart
  2. 108 94
      lib/roster/view/roster_page.dart
  3. 32 24
      lib/rosters/rosters_page.dart

+ 99 - 13
lib/fltinfo/view/dutyinfo_page.dart

@@ -137,7 +137,10 @@ class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
             ),
           ),
           const Gap(20),
-          _notifiedCrew(),
+          if (widget.params.dutytype == "standby")
+            _stdbyCrew()
+          else
+            _notifiedCrew(),
         ],
       ),
     );
@@ -149,8 +152,12 @@ class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
     final List<Pnleg> pnleg = data["pnleg"];
     final DutyinfoParams filter = data["filter"];
     return pnleg
-        .where((leg) => ((filter.jdep == null || leg.jdep == filter.jdep) &&
-            (filter.jdes == null || leg.jarr == filter.jdes) &&
+        .where((leg) => ((filter.jdep == null ||
+                (filter.sameday
+                    ? (leg.jdep?.startOf(Unit.day) ==
+                        filter.jdep?.startOf(Unit.day))
+                    : ((leg.jdep == filter.jdep) &&
+                        (filter.jdes == null || leg.jarr == filter.jdes)))) &&
             (filter.dep == null || leg.dep == filter.dep) &&
             (filter.des == null || leg.arr == filter.des) &&
             (filter.label == null || leg.label == filter.label) &&
@@ -176,14 +183,6 @@ class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
 
   _notifiedCrew() {
     final qualif = ref.watch(qualifProvider(CrewFilter()));
-    // final crewPnleg = pnleg.where((leg) =>
-    //     ((widget.params.jdep == null || leg.jdep == widget.params.jdep) &&
-    //         (widget.params.jdes == null || leg.jarr == widget.params.jdes) &&
-    //         (widget.params.dep == null || leg.dep == widget.params.dep) &&
-    //         (widget.params.des == null || leg.arr == widget.params.des) &&
-    //         (widget.params.label == null || leg.label == widget.params.label) &&
-    //         (widget.params.dutytype == null ||
-    //             leg.dutytype == widget.params.dutytype)));
 
     return WCadre(
       titleright: crewPnlegLoading
@@ -191,7 +190,12 @@ class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
               padding: const EdgeInsets.all(5.0),
               child: CircularProgressIndicator(),
             )
-          : null,
+          : ElevatedButton.icon(
+              label: const Text("Update", style: TextStyle(fontSize: 9)),
+              onPressed: () async {
+                await crewPnlegLoad();
+              },
+              icon: const Icon(Icons.update)),
       title: "Notified Crew (alt)",
       bottomright: _dateNotifiedcrew != null
           ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
@@ -238,10 +242,80 @@ class _DutyinfoPageState extends ConsumerState<DutyinfoPage> {
             ),
     );
   }
+
+  _stdbyCrew() {
+    final qualif = ref.watch(qualifProvider(CrewFilter()));
+    return WCadre(
+      titleright: crewPnlegLoading
+          ? Padding(
+              padding: const EdgeInsets.all(5.0),
+              child: CircularProgressIndicator(),
+            )
+          : ElevatedButton.icon(
+              label: const Text("Update", style: TextStyle(fontSize: 9)),
+              onPressed: () async {
+                await crewPnlegLoad();
+              },
+              icon: const Icon(Icons.update)),
+      title: "STDBY Crew",
+      bottomright: _dateNotifiedcrew != null
+          ? Text("data retrieved ${_dateNotifiedcrew?.from(_now)}",
+              style: GoogleFonts.robotoMono(
+                  fontSize: 10, fontWeight: FontWeight.w300))
+          : null,
+      child: crewPnleg.isEmpty
+          ? const Text("No data found !")
+          : Column(
+              children: [
+                Padding(
+                  padding: const EdgeInsets.all(8.0),
+                  child: Column(
+                      children: crewPnleg
+                          .mapIndexed((int i, leg) {
+                            // print(leg);
+                            return {
+                              "index": i,
+                              "college": (qualif
+                                      .firstWhereOrNull((e) => e.tlc == leg.tlc)
+                                      ?.college ??
+                                  "--"),
+                              // "jdep": (leg.jdep?.millisecondsSinceEpoch ?? 0)
+                              "jdep": (leg.label ?? "0")
+                            };
+                          })
+                          .sortedByCompare(
+                              (e) => [
+                                    e["jdep"].toString(),
+                                    e["college"].toString()
+                                  ],
+                              jdepcollegeSort)
+                          .map<Widget>((e) {
+                            final x = crewPnleg.elementAt(e["index"] as int);
+                            final pn =
+                                qualif.firstWhereOrNull((e) => e.tlc == x.tlc);
+                            return Row(
+                              children: [
+                                Text("${e["jdep"]}"),
+                                WCrew(
+                                  college: pn?.college,
+                                  mle: x.tlc,
+                                  base: pn?.base,
+                                  name: "${pn?.lname}, ${pn?.fname}",
+                                ),
+                              ],
+                            );
+                          })
+                          .toList()),
+                )
+              ],
+            ),
+    );
+  }
 }
 
 class DutyinfoParams {
   const DutyinfoParams({
+    this.sameday = false,
     this.date,
     this.start,
     this.end,
@@ -252,7 +326,7 @@ class DutyinfoParams {
     this.dep,
     this.des,
   });
-
+  final bool sameday;
   final Jiffy? start;
   final Jiffy? end;
   final String? date;
@@ -275,3 +349,15 @@ int collegeSort(String a, String b) {
   // Compare based on the index
   return indexA.compareTo(indexB);
 }
+
+int jdepcollegeSort(List<String> a, List<String> b) {
+  final String x = a[0];
+  final String y = b[0];
+
+  final res = x.compareTo(y);
+  if (res == 0) {
+    return collegeSort(a[1], b[1]);
+  } else {
+    return res;
+  }
+}

+ 108 - 94
lib/roster/view/roster_page.dart

@@ -352,107 +352,118 @@ class _RosterPageState extends ConsumerState<RosterPage> {
       InkWell(
         highlightColor: Colors.yellow[900],
         onTap: () {
-          log("Tap: ${duty.start?.Hm} ${duty.type} ${duty.data}",
-              name: "RosterPage");
-          switch (duty.type) {
-            case "changed":
-              AlertDialog(
-                title: const Text('Notification'),
-                content: const Text('Load and show pending notification?'),
-                actions: [
-                  TextButton(
-                      child: const Text("Load Notification",
-                          style: TextStyle(color: Colors.red, fontSize: 16)),
-                      onPressed: () async {
-                        ref.read(isLoadingProvider.notifier).state = true;
-
-                        final res = await ref
-                            .read(crewlinkapiProvider)
-                            .notif(download: true, fileid: fileidnotif);
-                        ref.read(isLoadingProvider.notifier).state = false;
-                        if (res is Map && res["data"]?["id"] != null) {
-                          _showNotif();
-                        } else {
-                          AlertDialog(
-                              title: const Text('Notification'),
-                              content: Text(res?["error"] ??
-                                  res?["data"]?["msg"] ??
-                                  'No pending notification found !!!'),
-                              actions: [
-                                TextButton(
-                                    child: const Text("OK"),
-                                    onPressed: () => context.pop())
-                              ]).show(context);
-                        }
-                      }),
-                  TextButton(
-                      child: const Text(
-                        "Discard",
-                        style: TextStyle(color: Colors.green),
-                      ),
-                      onPressed: () => context.pop())
-                ],
-              ).show(context);
-              break;
-            case "flight":
-              context.push("/fltinfo",
-                  extra: FltinfoParams(
-                      al: duty.data["al"],
-                      fnum: duty.data["fnum"],
-                      dep: duty.data["dep"],
-                      des: duty.data["des"],
-                      jdep: duty.start,
-                      jdes: duty.end));
-            case "dhflight":
-              context.push("/fltinfo",
-                  extra: FltinfoParams(
-                      al: duty.data["al"],
-                      fnum: duty.data["fnum"],
-                      dep: duty.data["dep"],
-                      des: duty.data["des"],
-                      jdep: duty.start,
-                      jdes: duty.end));
-            case "dhlimo":
-              final pseudoleg = Pnleg(
-                  dep: duty.data["dep"],
-                  arr: duty.data["des"],
-                  depdate: duty.start?.format(pattern: "dd/MM/yyyy"),
-                  deptime: duty.start?.format(pattern: "HHmm"),
-                  arrdate: duty.end?.format(pattern: "dd/MM/yyyy"),
-                  arrtime: duty.end?.format(pattern: "HHmm"),
-                  //label: duty.data["label"],
-                  type: "G");
-              context.push("/dutyinfo",
-                  extra: DutyinfoParams(
-                      dutytype: pseudoleg.dutytype,
-                      jdep: duty.start,
-                      jdes: duty.end,
-                      dep: duty.data["dep"],
-                      des: duty.data["des"]));
-              break;
-            case "ground":
-              final pseudoleg = Pnleg(
+          // log("Tap: ${duty.start?.Hm} ${duty.type} ${duty.data}",name: "RosterPage");
+          if (duty.type == "changed") {
+            AlertDialog(
+              title: const Text('Notification'),
+              content: const Text('Load and show pending notification?'),
+              actions: [
+                TextButton(
+                    child: const Text("Load Notification",
+                        style: TextStyle(color: Colors.red, fontSize: 16)),
+                    onPressed: () async {
+                      ref.read(isLoadingProvider.notifier).state = true;
+
+                      final res = await ref
+                          .read(crewlinkapiProvider)
+                          .notif(download: true, fileid: fileidnotif);
+                      ref.read(isLoadingProvider.notifier).state = false;
+                      if (res is Map && res["data"]?["id"] != null) {
+                        _showNotif();
+                      } else {
+                        AlertDialog(
+                            title: const Text('Notification'),
+                            content: Text(res?["error"] ??
+                                res?["data"]?["msg"] ??
+                                'No pending notification found !!!'),
+                            actions: [
+                              TextButton(
+                                  child: const Text("OK"),
+                                  onPressed: () => context.pop())
+                            ]).show(context);
+                      }
+                    }),
+                TextButton(
+                    child: const Text(
+                      "Discard",
+                      style: TextStyle(color: Colors.green),
+                    ),
+                    onPressed: () => context.pop())
+              ],
+            ).show(context);
+          } else if (duty.type == "flight") {
+            context.push("/fltinfo",
+                extra: FltinfoParams(
+                    al: duty.data["al"],
+                    fnum: duty.data["fnum"],
+                    dep: duty.data["dep"],
+                    des: duty.data["des"],
+                    jdep: duty.start,
+                    jdes: duty.end));
+          } else if (duty.type == "dhflight") {
+            context.push("/fltinfo",
+                extra: FltinfoParams(
+                    al: duty.data["al"],
+                    fnum: duty.data["fnum"],
+                    dep: duty.data["dep"],
+                    des: duty.data["des"],
+                    jdep: duty.start,
+                    jdes: duty.end));
+          } else if (duty.type == "dhlimo") {
+            final pseudoleg = Pnleg(
                 dep: duty.data["dep"],
                 arr: duty.data["des"],
                 depdate: duty.start?.format(pattern: "dd/MM/yyyy"),
                 deptime: duty.start?.format(pattern: "HHmm"),
                 arrdate: duty.end?.format(pattern: "dd/MM/yyyy"),
                 arrtime: duty.end?.format(pattern: "HHmm"),
-                label: duty.data["label"],
-                //type: "G",
-              );
+                //label: duty.data["label"],
+                type: "G");
+            context.push("/dutyinfo",
+                extra: DutyinfoParams(
+                    dutytype: pseudoleg.dutytype,
+                    jdep: duty.start,
+                    jdes: duty.end,
+                    dep: duty.data["dep"],
+                    des: duty.data["des"]));
+          } else if (duty.type == "ground") {
+            final pseudoleg = Pnleg(
+              dep: duty.data["dep"],
+              arr: duty.data["des"],
+              depdate: duty.start?.format(pattern: "dd/MM/yyyy"),
+              deptime: duty.start?.format(pattern: "HHmm"),
+              arrdate: duty.end?.format(pattern: "dd/MM/yyyy"),
+              arrtime: duty.end?.format(pattern: "HHmm"),
+              label: duty.data["label"],
+              type: "A",
+            );
+            if (pseudoleg.dutytype == "standby") {
+              context.push("/dutyinfo",
+                  extra: DutyinfoParams(
+                    dutytype: pseudoleg.dutytype,
+                    //label: pseudoleg.label,
+                    jdep: pseudoleg.jdep,
+                    jdes: pseudoleg.jarr,
+                    //start: duty.start,
+                    //end: duty.end,
+                    dep: pseudoleg.dep,
+                    des: pseudoleg.arr,
+                    sameday: true,
+                  ));
+            } else {
               context.push("/dutyinfo",
                   extra: DutyinfoParams(
-                      dutytype: pseudoleg.dutytype,
-                      label: pseudoleg.label,
-                      jdep: duty.start,
-                      jdes: duty.end,
-                      start: duty.start,
-                      end: duty.end,
-                      dep: duty.data["dep"],
-                      des: duty.data["des"]));
-              break;
-            default:
+                    // dutytype: pseudoleg.dutytype,
+                    label: pseudoleg.label,
+                    jdep: duty.start,
+                    jdes: duty.end,
+                    // start: duty.start,
+                    // end: duty.end,
+                    dep: duty.data["dep"],
+                    des: duty.data["des"],
+                    // sameday: true,
+                  ));
+            }
           }
         },
         child: WDuty(duty: duty),
@@ -530,7 +541,10 @@ class _RosterPageState extends ConsumerState<RosterPage> {
                   )))
           .then((res) {
         // if (res is Map && res["notif"]) _loadRoster();
-        if (res is Map && res["notif"]) context.go("/crewlink/roster");
+
+        //! check if the roster is still the same otherwise call _loadRoster
+        if (res is Map && res["notif"])
+          context.pushReplacement("/crewlink/roster");
       });
     }
   }

+ 32 - 24
lib/rosters/rosters_page.dart

@@ -198,7 +198,7 @@ class _RostersPageState extends ConsumerState<RostersPage> {
       "${leg.jarr?.format(pattern: "HHmm")}",
       style: const TextStyle(fontSize: 10, color: Colors.teal),
     );
-    if (leg.type == "L" || (leg.type == "F")) {
+    if (leg.dutytype == "dhflight" || leg.dutytype == "flight") {
       return InkWell(
         onTap: () {
           context.push("/fltinfo",
@@ -222,14 +222,13 @@ class _RostersPageState extends ConsumerState<RostersPage> {
           wharr,
         ]),
       );
-    } else if ((leg.type == "G") ||
-        ((leg.dep ?? "") != "" && (leg.arr ?? "") != "")) {
+    } else if (leg.dutytype == "dhlimo") {
       return InkWell(
         onTap: () {
           context.push("/dutyinfo",
               extra: DutyinfoParams(
                   dutytype: leg.dutytype,
-                  label: leg.label,
+                  // label: leg.label,
                   dep: leg.dep,
                   des: leg.arr,
                   jdep: leg.jdep,
@@ -249,26 +248,35 @@ class _RostersPageState extends ConsumerState<RostersPage> {
           wharr,
         ]),
       );
-    }
-    //  else if ((leg.type == "F") ||
-    //     ((leg.dep ?? "") != "" && (leg.arr ?? "") != "")) {
-    //   return MyRow(children: [
-    //     whdep,
-    //     const Gap(3),
-    //     const Text("DH ", style: TextStyle(fontSize: 11, color: Colors.amber)),
-    //     Text(
-    //       "${leg.dep}-${leg.arr}",
-    //       style:
-    //           GoogleFonts.robotoMono(fontSize: 11, fontWeight: FontWeight.w300),
-    //     ),
-    //     const Gap(3),
-    //     wharr,
-    //   ]);
-    // }
-    else if ((!["OFF", "CM", "CA", "PP"].contains(leg.label)) &&
-        (leg.jarr != null &&
-            leg.jdep != null &&
-            DTInterval(leg.jdep!, leg.jarr!).duration.inHours < 18)) {
+    } else if (leg.dutytype == "standby") {
+      return InkWell(
+        onTap: () {
+          context.push("/dutyinfo",
+              extra: DutyinfoParams(
+                sameday: true,
+                dutytype: leg.dutytype,
+                // label: leg.label,
+                // dep: leg.dep,
+                // des: leg.arr,
+                jdep: leg.jdep,
+                jdes: leg.jarr,
+              ));
+        },
+        child: MyRow(children: [
+          whdep,
+          const Gap(3),
+          Text("${leg.label}",
+              style: const TextStyle(fontSize: 11, color: Colors.amber)),
+          Text(
+            " ${leg.dep}",
+            style: GoogleFonts.robotoMono(
+                fontSize: 8, fontWeight: FontWeight.w300),
+          ),
+          const Gap(3),
+          wharr,
+        ]),
+      );
+    } else if (leg.dutytype == "ground") {
       return InkWell(
         onTap: () {
           context.push("/dutyinfo",