-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrow-311-today.html
142 lines (126 loc) · 3.76 KB
/
row-311-today.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NYC Today - In a row format</title>
<style>
main {
display: flex;
flex-direction: row;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 20px;
color: #333333;
}
.row {
display: flex;
flex-direction: column;
align-items: center;
flex: 1 1 33%;
}
.icon {
max-width: 45px;
}
h3,
h4,
p {
margin: 0;
text-align: center;
}
h3 {
font-weight: normal;
}
p {
font-size: small;
}
#datafor {
color: #5d5d5d;
font-size: smaller;
margin-bottom: 1rem;
}
#detail-name{
margin-left: 0.5rem;
}
</style>
</head>
<body>
<form id="datafor">
<label for="date">Date:</label>
<input type="date" id="date" name="date" />
<span id="detail-name"></span>
</form>
<main id="app"></main>
</body>
<script>
const app = document.getElementById("app");
const dateInput = document.getElementById("date");
const detailName = document.getElementById("detail-name")
const cors =
"https://4dvj5dcxge.execute-api.us-east-1.amazonaws.com/staging/";
const url = "https://portal.311.nyc.gov/home-cal/";
function update(url, gmt = " GMT") { // work around for today vs another date
fetch(cors + url)
.then((res) => res.json())
.then((d) => {
const date = new Date(d.date + gmt);
const dayofweek = date.getDay();
const rows = d.results;
let key = "";
switch (dayofweek) {
case 6:
key = "Saturday";
break;
case 7:
key = "Sunday";
break;
default:
key = "WeekDay";
break;
}
app.innerHTML = rows
.map((row) => {
const {
IconUrl,
CalendarName,
CalendarDetailName,
CalendarDetailStatus,
CalendarDetailMessage,
} = row;
//holidays
if (CalendarDetailName.trim()) {
detailName.innerText = CalendarDetailName
return `<div class="row">
<img class="icon" alt="${CalendarName} icon" src="${IconUrl}"></img>
<h3>${CalendarName}</h3>
<h4>${CalendarDetailStatus}</h4>
<p>${CalendarDetailMessage}</p>
</div>`;
}
detailName.innerText = date.toLocaleString('en-US', { weekday: 'long'})
return `<div class="row">
<img class="icon" alt="${CalendarName} icon" src="${IconUrl}"></img>
<h3>${CalendarName}</h3>
<h4>${row[key + "RecordName"]}</h4>
<p>${row[key + "ContentFormat"]}</p>
</div>`;
})
.join("");
});
}
//init
const today = (new Date()).toLocaleDateString('en-CA') //workaround to get today's date not UTC date
dateInput.value = today
update(url);
dateInput.addEventListener("change", (e) => {
const date = e.target.valueAsDate;
const day = date.getUTCDate();
const month = date.getUTCMonth() + 1;
const year = date.getUTCFullYear();
update(
`https://portal.311.nyc.gov/home-cal/?today=${month}/${day}/${year}`,
""
);
});
</script>
</html>