-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDutyRoster.html
More file actions
198 lines (178 loc) · 7.18 KB
/
Copy pathDutyRoster.html
File metadata and controls
198 lines (178 loc) · 7.18 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Duty Roster: Today & Tomorrow</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f4f4f4;
color: #333;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
text-align: center;
width: 90%;
max-width: 800px;
}
h1 {
color: #0056b3; /* Original Deep Blue */
margin-bottom: 20px;
}
#currentDateTime {
font-size: 1.2em;
margin-bottom: 20px;
color: #555;
}
#dutyDisplay {
margin-top: 20px;
padding-top: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
margin-bottom: 25px;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #007bff; /* Original Bright Blue */
color: white;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #e9e9e9; /* Original Light Grey Hover */
}
.date-heading {
font-size: 1.3em;
color: #007bff; /* Bright Blue for sub-headings */
margin-top: 20px;
margin-bottom: 10px;
font-weight: bold;
}
.no-duty {
color: #dc3545; /* Standard Error Red */
font-style: italic;
margin-bottom: 15px;
}
.loading {
font-style: italic;
color: #666;
}
.error {
color: #dc3545; /* Standard Error Red */
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Duty Roster: Today & Tomorrow</h1>
<div id="currentDateTime"></div>
<div id="dutyDisplay">
<p class="loading">Loading duty data...</p>
</div>
</div>
<script>
// *** IMPORTANT: REPLACE THIS WITH YOUR PUBLISHED GOOGLE SHEET CSV URL ***
const GOOGLE_SHEET_CSV_URL = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vSgLfwYITRlKT7-8CMYIHEKmMKmB0eSYdu6j5LU87U_mNXw499I6HhMGUrzgNzbY15hgBGZpOsarJkv/pub?output=csv'; // Example: 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR_YOUR_SHEET_ID_HERE/pub?gid=0&single=true&output=csv';
document.addEventListener('DOMContentLoaded', () => {
displayCurrentDateTime();
fetchDutyData();
});
function displayCurrentDateTime() {
const now = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' };
document.getElementById('currentDateTime').textContent = `Current Time: ${now.toLocaleDateString('en-US', options)}`;
}
async function fetchDutyData() {
const dutyDisplay = document.getElementById('dutyDisplay');
dutyDisplay.innerHTML = '<p class="loading">Fetching data from Google Sheet...</p>';
try {
const response = await fetch(GOOGLE_SHEET_CSV_URL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const csvText = await response.text();
parseAndDisplayDuty(csvText);
} catch (error) {
console.error("Error fetching duty data:", error);
dutyDisplay.innerHTML = `<p class="error">Failed to load duty data. Please check the sheet URL and your internet connection. Error: ${error.message}</p>`;
}
}
function parseAndDisplayDuty(csvText) {
const dutyDisplay = document.getElementById('dutyDisplay');
const lines = csvText.trim().split('\n');
if (lines.length < 2) {
dutyDisplay.innerHTML = '<p class="no-duty">No duty data available or sheet is empty.</p>';
return;
}
const headers = lines[0].split(',').map(header => header.trim());
const dataRows = lines.slice(1);
const today = new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(today.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
let todayDutiesHTML = '';
let tomorrowDutiesHTML = '';
let todayFound = false;
let tomorrowFound = false;
const tableHeaderHTML = '<thead><tr><th>Date</th>' + headers.slice(1).map(h => `<th>${h}</th>`).join('') + '</tr></thead>';
dataRows.forEach(row => {
const values = row.split(',').map(value => value.trim());
if (values.length === 0) return;
const dateString = values[0];
const rowDate = new Date(dateString);
rowDate.setHours(0, 0, 0, 0);
let rowHTML = '<tr>';
rowHTML += `<td>${dateString}</td>`;
for (let i = 1; i < headers.length; i++) {
const dutyValue = values[i] || 'N/A';
rowHTML += `<td>${dutyValue}</td>`;
}
rowHTML += '</tr>';
if (rowDate.getTime() === today.getTime()) {
todayDutiesHTML += rowHTML;
todayFound = true;
} else if (rowDate.getTime() === tomorrow.getTime()) {
tomorrowDutiesHTML += rowHTML;
tomorrowFound = true;
}
});
let finalDisplayHTML = '';
// --- Display Today's Duty ---
finalDisplayHTML += '<div class="date-heading">Today\'s Duty</div>';
if (todayFound) {
finalDisplayHTML += '<table>' + tableHeaderHTML + '<tbody>' + todayDutiesHTML + '</tbody></table>';
} else {
finalDisplayHTML += '<p class="no-duty">No duty scheduled for today.</p>';
}
// --- Display Tomorrow's Duty ---
finalDisplayHTML += '<div class="date-heading">Tomorrow\'s Duty</div>';
if (tomorrowFound) {
finalDisplayHTML += '<table>' + tableHeaderHTML + '<tbody>' + tomorrowDutiesHTML + '</tbody></table>';
} else {
finalDisplayHTML += '<p class="no-duty">No duty scheduled for tomorrow.</p>';
}
dutyDisplay.innerHTML = finalDisplayHTML;
}
</script>
</body>
</html>