[gnome-maps/wip/mlundblad/transit-plugin-resrobot: 2/5] transitPlan: Add method to insert new itineraries



commit a54b939949a6faba70346ecd3a7862f1ae3610b0
Author: Marcus Lundblad <ml update uu se>
Date:   Sun Oct 6 09:36:23 2019 +0200

    transitPlan: Add method to insert new itineraries
    
    Adds a method to add new itineraris, either setting
    a fresh set, or extending the previous. Sorted either
    on departure time ascending, or arrival time descending.
    This was previously done in the OpenTripPlanner plugin,
    but moved to avoid code duplication in new plugins.

 src/transitPlan.js | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/src/transitPlan.js b/src/transitPlan.js
index 0229c4d..4133aea 100644
--- a/src/transitPlan.js
+++ b/src/transitPlan.js
@@ -130,6 +130,29 @@ var Plan = GObject.registerClass({
         this.emit('update');
     }
 
+    /**
+     * Update plan with new itineraries, setting the new itineraries if it's
+     * the first fetch for a query, or extending the existing ones if it's
+     * a request to load more
+     */
+    updateWithNewItineraries(itineraries, arriveBy, extendPrevious) {
+        /* sort itineraries, by departure time ascending if querying
+         * by leaving time, by arrival time descending when querying
+         * by arriving time
+         */
+        if (arriveBy)
+            itineraries.sort(sortItinerariesByArrivalDesc);
+        else
+            itineraries.sort(sortItinerariesByDepartureAsc);
+
+        let newItineraries =
+            extendPrevious ? this.itineraries.concat(itineraries) : itineraries;
+
+        this.update(newItineraries);
+    }
+
+
+
     reset() {
         this._itineraries = [];
         this.bbox = null;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]