Skip to content

Commit 3ee5150

Browse files
committed
handle creating a URL and change condition for no alert message
1 parent e0dfed4 commit 3ee5150

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

script.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ let feedTimestamp = '';
4242
let alertsByLine = {};
4343
// let alertsByStop = {};
4444

45+
let dataReturned = false;
46+
4547
let railAlerts = {
4648
'all': [],
4749
'current': {},
@@ -68,7 +70,8 @@ fetch(DATA_SOURCE, {
6870
throw new Error('Network response was not ok.');
6971
})
7072
.then(data => {
71-
console.log('Request successfull!');
73+
console.log('Request successful!');
74+
dataReturned = true;
7275
console.log(data);
7376
updateLastUpdated(data.header.timestamp);
7477
processAlerts(data.entity);
@@ -529,6 +532,7 @@ function updateView() {
529532
let filteredAlerts = [];
530533
let service = getServiceSelected();
531534
let nowvsLater = getStatusSelected();
535+
let routeName = '';
532536

533537
switch (serviceSelected) {
534538
case SERVICE.RAIL:
@@ -546,11 +550,13 @@ function updateView() {
546550
alertList.innerHTML = '';
547551

548552
if (Object.keys(filteredAlerts).length == 0) {
549-
let noAlerts = document.createElement("div");
550-
noAlerts.classList.add("alert-item");
551-
noAlerts.innerHTML = `There are no ${nowvsLater} alerts for ${service}. Last updated: ${feedTimestamp}.`;
552-
553-
alertList.appendChild(noAlerts);
553+
if (dataReturned) {
554+
let noAlerts = document.createElement("div");
555+
noAlerts.classList.add("alert-item");
556+
noAlerts.innerHTML = `There are no ${nowvsLater} alerts for ${service}. Last updated: ${feedTimestamp}.`;
557+
558+
alertList.appendChild(noAlerts);
559+
}
554560
} else {
555561
// Loop through each key in the filteredAlerts object
556562
for (let item in filteredAlerts) {
@@ -581,26 +587,32 @@ function updateView() {
581587
switch (railRoute) {
582588
case '801':
583589
railIcon.src = LINE_ICONS['801'];
590+
routeName = 'A Line';
584591
railIcon.alt = 'A Line';
585592
break;
586593
case '802':
587594
railIcon.src = LINE_ICONS['802'];
595+
routeName = 'B Line';
588596
railIcon.alt = 'B Line';
589597
break;
590598
case '803':
591599
railIcon.src = LINE_ICONS['803'];
600+
routeName = 'C Line';
592601
railIcon.alt = 'C Line';
593602
break;
594603
case '804':
595604
railIcon.src = LINE_ICONS['804'];
605+
routeName = 'E Line';
596606
railIcon.alt = 'D Line';
597607
break;
598608
case '805':
599609
railIcon.src = LINE_ICONS['805'];
610+
routeName = 'D Line';
600611
railIcon.alt = 'E Line';
601612
break;
602613
case '807':
603614
railIcon.src = LINE_ICONS['807'];
615+
routeName = 'K Line';
604616
railIcon.alt = 'K Line';
605617
break;
606618
}
@@ -618,23 +630,27 @@ function updateView() {
618630
case '901':
619631
busIcon.src = LINE_ICONS['901'];
620632
busIcon.alt = 'G Line';
633+
routeName = 'G Line';
621634
icon.classList.add("alert-item__icon--bus-icon");
622635
icon.appendChild(busIcon);
623636
break;
624637
case '910':
625638
busIcon.src = LINE_ICONS['910'];
626639
busIcon.alt = 'J Line';
640+
routeName = 'J Line';
627641
icon.classList.add("alert-item__icon--bus-icon");
628642
icon.appendChild(busIcon);
629643
break;
630644
case '950':
631645
busIcon.src = LINE_ICONS['950'];
632646
busIcon.alt = 'J Line';
647+
routeName = 'J Line';
633648
icon.classList.add("alert-item__icon--bus-icon");
634649
icon.appendChild(busIcon);
635650
break;
636651
default:
637652
icon.classList.add("alert-item__icon--bus");
653+
routeName = `Line ${busRoute}`;
638654
}
639655

640656
icon.innerHTML = `<div>${item}</div>`;
@@ -669,6 +685,11 @@ function updateView() {
669685
content_description.classList.add("alert-item__description");
670686
content_description.innerHTML = alert.alert.description_text.translation[0].text;
671687

688+
if (alert.alert.url) {
689+
content_description.innerHTML += `<br><br><a href="${alert.alert.url.translation[0].text}" target="_blank">More info on service impact to ${routeName}.</a>`;
690+
}
691+
692+
672693
content_description.innerHTML += '<br><br>Starting on: ' + convertDateTime(alert.alert.active_period[0].start);
673694
if (alert.alert.active_period[0].end) {
674695
content_description.innerHTML += '<br>Ending on: ' + convertDateTime(alert.alert.active_period[0].end);

0 commit comments

Comments
 (0)