ctucx.git: oeffi-web

[nimlang] oeffisearch fork that works without javascript

commit 5c5717745f2512a349c3926047312f662a0a6123
parent e4115a0f7f7f5499363f2b2133a98c5325dab8f3
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 21 Jan 2021 22:47:39 +0100

journeyView: add more details
2 files changed, 62 insertions(+), 17 deletions(-)
M
src/formaters/renderJourney.nim
|
57
+++++++++++++++++++++++++++++++++++++++++----------------
M
templates/journey.tpl
|
22
+++++++++++++++++++++-
diff --git a/src/formaters/renderJourney.nim b/src/formaters/renderJourney.nim
@@ -59,11 +59,16 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
         })
 
     else:
-      let arrivalTime     = getPlannedOrPrognosedTime(leg.arrival)
-      let departureTime   = getPlannedOrPrognosedTime(leg.departure)
+      let arrivalTime      = getPlannedOrPrognosedTime(leg.arrival)
+      let departureTime    = getPlannedOrPrognosedTime(leg.departure)
 
-      var legDuration:    int64
-      var additionalName: string
+      var legDuration:       int64
+      var hasAdditionalName: bool
+      var additionalName:    string
+      var hasMarudorUrl:     bool
+      var marudorUrl:        string
+      var hasTrainType:      bool
+      var trainType:         string
 
       # is this leg a change?
       if lastArrival.plannedTime != 0:

@@ -78,8 +83,22 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
 
       lastArrival = leg.arrival
       
+      if leg.line.get.product == nationalExp or leg.line.get.product == national or leg.line.get.product == regionalExp or leg.line.get.product == regional:
+        hasMarudorUrl = true
+
       if not leg.line.get.additionalName.isNone():
-        additionalName = leg.line.get.additionalName.get
+        hasAdditionalName = true
+        additionalName    = leg.line.get.additionalName.get
+        marudorUrl        = "https://marudor.de/details/" & leg.line.get.additionalName.get & "/" & $(leg.departure.plannedTime*1000)
+      else:
+        hasAdditionalName = false
+        marudorUrl        = "https://marudor.de/details/" & leg.line.get.name & "/" & $(leg.departure.plannedTime*1000)
+    
+      if not leg.line.get.trainType.isNone():
+        hasTrainType      = true
+        trainType         = leg.line.get.trainType.get
+      else:
+        hasTrainType      = false
     
       var remarks = newJArray()
       if not leg.remarks.isNone():

@@ -114,7 +133,7 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
             if delay > 0:
               departureDelay = "+"
 
-            departureDelay & $delay
+            departureDelay &= $delay
 
           if stopover.arrival.plannedTime.isSome and stopover.arrival.prognosedTime.isSome:
             let delay = floorDiv((stopover.arrival.prognosedTime.get - stopover.arrival.plannedTime.get), 60)

@@ -173,16 +192,22 @@ proc renderJourney*(data: CacheObject, id: string): JsonNode =
       inc(changes)
 
       result["LEGS"].add(%* {
-          "IS_VEHICLE":      true,
-          "IS_CANCELLED":    leg.cancelled,
-          "LINE":            leg.line.get.name,
-          "ADDITIOAL_NAME":  additionalName,
-          "DIRECTION":       leg.direction.get,
-          "LEG_DURATION":    %formatDuration(legDuration),
-          "ARRIVAL_POINT":   formatPoint(leg.arrival.point),
-          "DEPARTURE_POINT": formatPoint(leg.departure.point),
-          "STOPOVERS":       stopovers,
-          "REMARKS":         remarks
+          "IS_VEHICLE":              true,
+          "IS_CANCELLED":            leg.cancelled,
+          "LINE":                    leg.line.get.name,
+          "HAS_ADDITIONAL_NAME":     hasAdditionalName,
+          "ADDITIONAL_NAME":         additionalName,
+          "HAS_MARUDOR_URL":         hasMarudorUrl,
+          "MARUDOR_URL":             marudorUrl,
+          "HAS_TRAIN_TYPE":          hasTrainType,
+          "TRAIN_TYPE":              trainType,
+          "DIRECTION":               leg.direction.get,
+          "LEG_DURATION":            formatDuration(legDuration),
+          "LEG_DEPARTURE_TIMESTAMP": leg.departure.plannedTime,
+          "ARRIVAL_POINT":           formatPoint(leg.arrival.point),
+          "DEPARTURE_POINT":         formatPoint(leg.departure.point),
+          "STOPOVERS":               stopovers,
+          "REMARKS":                 remarks
         })
 
   result["CHANGES"] = %(changes-1)
diff --git a/templates/journey.tpl b/templates/journey.tpl
@@ -38,12 +38,32 @@
 			<thead>
 				<tr>
 					<td colspan="4">
+						{{#HAS_MARUDOR_URL}}
+						<span><a href="{{MARUDOR_URL}}">{{LINE}}</a> → {{DIRECTION}} {{#IS_CANCELLED}}<b class="cancelled-text"> {{LABEL_CANCELLED}}!</b>{{/IS_CANCELLED}}</span>
+						{{/HAS_MARUDOR_URL}}
+						{{^HAS_MARUDOR_URL}}
 						<span>{{LINE}} → {{DIRECTION}} {{#IS_CANCELLED}}<b class="cancelled-text"> {{LABEL_CANCELLED}}!</b>{{/IS_CANCELLED}}</span>
+						{{/HAS_MARUDOR_URL}}
+
 					</td>
 				</tr>
 				<tr>
 					<td colspan="4">
-						<span>{{LABEL_DURATION}}: {{LEG_DURATION}}</span>
+						<div class="train-details">
+							{{#HAS_ADDITIONAL_NAME}}
+								<div class="train-detail">
+									Trip: {{ADDITIONAL_NAME}}
+								</div>
+							{{/HAS_ADDITIONAL_NAME}}
+							{{#HAS_TRAIN_TYPE}}
+								<div class="train-detail">
+									Train type: {{TRAIN_TYPE}}
+								</div>
+							{{/HAS_TRAIN_TYPE}}
+							<div class="train-detail">
+								{{LABEL_DURATION}}: {{LEG_DURATION}}
+							</div>
+						</div>
 					</td>
 				</tr>
 				<tr>