From 8bbe0c4bfc69cea3efc5710f6fccc51ff10f4943 Mon Sep 17 00:00:00 2001
From: 2deep4real <denis.peters@udo.edu>
Date: Thu, 27 Aug 2015 19:10:33 +0200
Subject: [PATCH] added filter on destination width of linenumber, time and
 delay dynamically tested with linenumber [00000]; time [00:00] and delay
 [+00] -> widths removed from style

---
 panels/departure/departures.php | 11 +++++++++++
 panels/departure/script.js      | 24 ++++++++++++++++++++----
 panels/departure/style.less     |  7 ++-----
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/panels/departure/departures.php b/panels/departure/departures.php
index e08149f..97868a5 100644
--- a/panels/departure/departures.php
+++ b/panels/departure/departures.php
@@ -78,6 +78,7 @@
 				echo "<div error><h1>NAME ERROR!</h1>$stop<br/>Not a propper stop name. Usage: city:stop[;city:stop]*</div>";
 			
 			// get departures
+			ob_start();
 			$plain = file_get_contents("http://vrrf.finalrewind.org/$stopsplit[0]/$stopsplit[1].json?frontend=json");
 			$data = json_decode($plain, true);
 			// version
@@ -115,6 +116,11 @@
 							continue;
 						}
 					}
+					if (isset($options['filter']['bl']['destination']) ) {
+						if (in_array($entry['destination'], $options['filter']['bl']['destination'])) {
+							continue;
+						}
+					}
 				}
 				if (isset($options['filter']['wl'])) {
 					if (isset($options['filter']['wl']['line']) ) {
@@ -132,6 +138,11 @@
 							continue;
 						}
 					}
+					if (isset($options['filter']['wl']['destination']) ) {
+						if (!in_array($entry['destination'], $options['filter']['wl']['destination'])) {
+							continue;
+						}
+					}
 				}
 				// !filter
 				
diff --git a/panels/departure/script.js b/panels/departure/script.js
index ab8405e..167826a 100755
--- a/panels/departure/script.js
+++ b/panels/departure/script.js
@@ -122,7 +122,7 @@ var update = function(config, fields) {
 				} else {
 					$(actDep.self).css("display", "");
 					$(actDep.line).html(strDep.line.toUpperCase());
-					$(actDep.name).html(strDep.destination);
+					$(actDep.name).html(strDep.destination.replace("Dortmund ", ""));
 					for (var j = 0; j < 3; ++j) {
 						var 
 							actStn = actDep.sttn[j],
@@ -135,7 +135,7 @@ var update = function(config, fields) {
 						} else {
 							$(actStn.self).css("display", "");
 							$(actStn.time).html(strStn.time);
-							$(actStn.name).html(strStn.name);
+							$(actStn.name).html(strStn.name.replace("Dortmund - ", ""));
 							if (strStn.cancel == 1) {
 								$(actStn.name).css("text-decoration", "outline");
 							} else {
@@ -163,6 +163,8 @@ var resize = function(panel, config, cont) {
 		lineStp		= $(cont).find('[data-stop]'),
 		infoTtl		= $(cont).find('[data-title]'),
 		infoMsg		= $(cont).find('[data-message]'),
+		stopTme		= $(lineStp).find('[data-time]'),
+		stopDly		= $(lineStp).find('[data-delay]'),
 		// setze größen der schriften mit scale * n wobei n in prozent von panelhöhe
 		lineHedH	= scale * 5,		// überschriften der linien
 		lineStpH	= scale * 4,		// haltestellen der linien
@@ -172,13 +174,17 @@ var resize = function(panel, config, cont) {
 	$(lineHed).css('height', lineHedH + 'px');
 	$(lineHed).css('fontSize', (lineHedH-2) + 'px');
 	$(lineHed).css('lineHeight', lineHedH + 'px');
-	$(lineLin).css('width', lineHedH * 2);
+	$(lineLin).css('width', getStringWidth((lineHedH-2), "00000"));
 
 	// setze linien haltestellen größe
 	$(lineStp).css('height', lineStpH + 'px');
 	$(lineStp).css('fontSize', (lineStpH-2) + 'px');
 	$(lineStp).css('lineHeight', lineStpH + 'px');
-
+	
+	// setze zeit und delay breite
+	$(stopTme).css('width', getStringWidth((lineStpH-2), "00:00") + 'px');
+	$(stopDly).css('width', getStringWidth((lineStpH-2), "+00") + 'px');
+	
 	// setze info überschriften größe
 	$(infoTtl).css('height', infoTtlH + 'px');
 	$(infoTtl).css('fontSize', (infoTtlH-2) + 'px');
@@ -190,6 +196,16 @@ var resize = function(panel, config, cont) {
 	$(infoMsg).css('lineHeight', infoMsgH + 'px');
 }
 
+var getStringWidth = function(fontSize, string) {
+	var 
+		o = $('<div>' + string + '</div>')
+		.css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden', 'font-family': 'display', 'fontSize': fontSize + 'px'})
+		.appendTo($('body')),
+		w = o.width();
+	o.remove();
+	return w;
+}
+
 var generate = function(config, stations, departs, tplDeparture, tplStop, tplMsg) {
 	console.log("departures: generating structure [" + config + "]");
 	var
diff --git a/panels/departure/style.less b/panels/departure/style.less
index 35817e3..690ddae 100755
--- a/panels/departure/style.less
+++ b/panels/departure/style.less
@@ -9,7 +9,6 @@
 	box-sizing: border-box;
 	overflow: hidden;
 	font-family: display;
-	/* font-weight: bold */
 
 	[data-departure] {
 		position: relative;
@@ -33,7 +32,7 @@
 				display: inline-table;
 				background-color: #FFFFFF;
 				color: #0000A0;
-				width: 10%;
+				/*width: 10%;*/
 				height: 100%;
 				text-align: right;
 				padding: 0px 5px;
@@ -63,7 +62,6 @@
 
 				[data-time] {
 					position: relative;
-					flex: 2;
 					height: 100%;
 					overflow: hidden;
 					text-align: right;
@@ -71,7 +69,6 @@
 				}
 				[data-delay] {
 					position: relative;
-					flex: 1;
 					height: 100%;
 					overflow: hidden;
 					text-align: right;
@@ -82,7 +79,7 @@
 
 				[data-name] {
 					position: relative;
-					flex: 16;
+					flex: 1;
 					height: 100%;
 					overflow: hidden;
 				}
-- 
GitLab