-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweekdays.html
536 lines (486 loc) · 17.4 KB
/
weekdays.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<html>
<head>
<style>
h1 {
text-align: center;
}
h3 {
text-align: center !important;
margin: 10px 0;
}
h4 {
font-size: 15px;
line-height: 20px;
text-align: left;
margin: 0;
overflow-wrap: break-word; /* Break long words if necessary (modern standard) */
word-wrap: break-word; /* Compatibility with older browsers */
word-break: break-word; /* Break long words between letters (if needed) */
white-space: normal; /* Allow text to wrap onto multiple lines */
}
span {
line-height: 18px;
}
.date {
width: 100%;
display: block;
text-align: center;
font-size: small;
}
.planner {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 8px;
}
.day {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
padding: 8px;
min-height: 100px;
position: relative;
}
.entry {
padding: 12px;
margin: 8px 0;
border-radius: 3px;
font-size: smaller;
color: #fff;
cursor: pointer;
display: flex;
flex-direction: column;
gap: 8px;
}
.planning {
opacity: 0.6;
border: 4px dashed red;
background-color: orange;
}
.header {
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.dailyEstimate {
width: 100%;
display: block;
text-align: center;
}
.info {
margin: 0 auto 0 0;
}
@media (max-width: 1024px) {
.planner {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 480px) {
.planner {
grid-template-columns: 1fr;
}
}
.ecount {
font-size: smaller;
color: #fff;
display: inline-block;
text-align: right;
width: 100%;
}
.status {
font-size: smaller;
color: #fff;
background: black;
padding: 2px 5px;
border-radius: 5px;
border: 1px solid gray;
}
.buttons {
display: flex;
justify-content: center;
margin-bottom: 16px;
margin-top: 16px;
gap: 8px;
}
.buttons button, .buttons select {
padding: 8px 16px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="buttons">
<button id="back">En uge tilbage</button>
<button id="today">idag</button>
<button id="forward">En uge frem</button> <button id="showPlanned">
Viser planlagte
</button>
<select id="nameDropdown">
<option value="">All</option>
</select>
</div>
<div class="planner">
<div class="day" data-day="Monday">
<div class="header">
<h3>Monday</h3>
<span class="date"></span>
<span class="dailyEstimate"></span>
</div>
<div class="entries"></div>
</div>
<div class="day" data-day="Tuesday">
<div class="header">
<h3>Tuesday</h3>
<span class="date"></span>
<span class="dailyEstimate"></span>
</div>
<div class="entries"></div>
</div>
<div class="day" data-day="Wednesday">
<div class="header">
<h3>Wednesday</h3>
<span class="date"></span>
<span class="dailyEstimate"></span>
</div>
<div class="entries"></div>
</div>
<div class="day" data-day="Thursday">
<div class="header">
<h3>Thursday</h3>
<span class="date"></span>
<span class="dailyEstimate"></span>
</div>
<div class="entries"></div>
</div>
<div class="day" data-day="Friday">
<div class="header">
<h3>Friday</h3>
<span class="date"></span>
<span class="dailyEstimate"></span>
</div>
<div class="entries"></div>
</div>
</div>
<script>
window.dates = [];
dates = window.dates;
//##dates##
(function runimmed() {
debugger;
let showPlanned = 0;
const warningEstimatMsDailymax = 21600000; // 6 hours
const distinctNames = [
...new Set(dates.map((d) => d.assigned)),
];
window.jobUrlPrefix =
'https://app.ninox.com/#/teams/YWCzwq4FcnwWeXwbp/database/x5hqdm6zeqtz/module/Z/view/KlHGseS4XsiJ2udr/node/Z';
window.taskUrlPrefix =
'https://app.ninox.com/#/teams/YWCzwq4FcnwWeXwbp/database/x5hqdm6zeqtz/module/BB/view/z5sJXMv2QzbMxaW7/node/BB';
window.currentStartDay = Date.now();
window.currentAssigned = //##userName##;
// Function to convert Unix timestamp to Date object
function changeShowPlanned() {
showPlanned++;
if (showPlanned > 2) {
showPlanned = 0;
}
const btn = document.getElementById('showPlanned');
if (showPlanned === 0) {
btn.innerText = 'Viser planlagte';
}
if (showPlanned === 1) {
btn.innerText = 'Viser ikke planlagte';
}
if (showPlanned === 2) {
btn.innerText = 'Viser alle';
}
};
// Function to convert Unix timestamp to Date object
function unixToDate(unix) {
return new Date(unix);
}
// Function to check if a date is a weekday (Monday to Friday)
function isWeekday(date) {
const day = date.getDay();
return day >= 1 && day <= 5; // 1 = Monday, 5 = Friday
}
function msToHoursAndMinutes(ms) {
const hours = Math.floor(ms / (60 * 60 * 1000)); // Get whole hours
const minutes = Math.floor((ms % (60 * 60 * 1000)) / (60 * 1000)); // Get remaining minutes
return `${hours}:${minutes.toString().padStart(2, '0')}`; // Format minutes to 2 digits
}
function decimalToHours(decimal) {
const hoursDec = decimal / 3600000;
const hours = Math.floor(hoursDec); // Get the whole number part as hours
const minutes = Math.round((decimal - hours) * 60); // Get the decimal part and convert to minutes
return `${hours}:${minutes} `;
}
// Function to create calendar entries
function createCalendarEntries(dates) {
let calendarEntries = [];
dates.forEach((entry) => {
const startDate = unixToDate(entry.startUnix);
const endDate = entry.endUnix
? unixToDate(entry.endUnix)
: new Date();
let td = new Date(startDate);
let n = 0;
let t = 0;
while (td <= endDate) {
const isFridayButNotLastDay = td.getDay() === 5 && td < endDate;
if (isWeekday(td) && !isFridayButNotLastDay) {
t++;
}
td.setDate(td.getDate() + 1);
}
let currentDate = new Date(startDate);
// Loop through the date range
while (currentDate <= endDate) {
const isFridayButNotLastDay =
currentDate.getDay() === 5 && currentDate < endDate;
if (isWeekday(currentDate) && !isFridayButNotLastDay) {
calendarEntries.push({
type: entry.type,
name: entry.name,
status: entry.status,
client: entry.client,
project: entry.project,
used: entry.used,
estimateMs: entry.estimateMs,
tasksEstimateMs: entry.tasksEstimateMs,
usedMs: entry.usedMs,
date: currentDate.toLocaleDateString('da-DK'),
assigned: entry.assigned,
id: entry.id,
n: ++n,
t,
});
}
currentDate.setDate(currentDate.getDate() + 1);
}
});
return calendarEntries;
}
// Generate calendar entries
const calendarEntries = createCalendarEntries(dates);
function generateColor(name) {
const hash = Array.from(name).reduce(
(acc, char) => acc + char.charCodeAt(0),
0
);
// Generate RGB values based on the hash
const red = Math.max(0, (hash * 3) % 128); // Scale and wrap red value (0-127)
const green = Math.max(0, (hash * 5) % 128); // Scale and wrap green value (0-127)
const blue = Math.max(50, (hash * 7) % 256); // Ensure blue is at least 50 for contrast
// Ensure gray shades
if (red === green && green === blue) {
// If all are equal, adjust to create a gray shade
return `rgb(${red}, ${red}, ${red})`; // Return gray
}
return `rgb(${red}, ${green}, ${blue})`; // Return the RGB color
}
// Get the current week number and dates
function getWeekInfo(start) {
const now = new Date(start);
const startOfWeek = now.getDate() - now.getDay() + 1; // Adjust to get Monday
let weekDates = [];
for (let ix = 0; ix < 5; ix++) {
const date = new Date(now.setDate(startOfWeek + ix));
weekDates.push(date.toLocaleDateString('da-DK')); // Format: YYYY-MM-DD
}
return weekDates;
}
function runthis(start, assigned = null) {
debugger;
// Populate the planner with entries
const weekDates = getWeekInfo(start);
const dayElements = document.querySelectorAll('.day');
dayElements.forEach((day, index) => {
let totalDailyEstimate = 0;
const date = weekDates[index];
day.querySelector('.date').textContent = date;
day.querySelector('.entries').innerHTML = ''; // Clear existing entries
calendarEntries.forEach((entry) => {
let estimateMs = entry.estimateMs;
try {
if (showPlanned === 0) {
// vis kun planlagt
if (entry.status === 'Planning') return;
}
if (showPlanned === 1) {
// vis kun planning
if (entry.status !== 'Planning') return;
}
entry.assigned = entry.assigned.trim();
if (
entry.date === date &&
(assigned === null || entry.assigned === assigned)
) {
// Create a new entry element
const entryDiv = document.createElement('div');
let entryName = entry.name;
if (entry.status === 'Planning') {
entryDiv.className = 'entry planning';
} else {
entryDiv.className = 'entry ';
entryDiv.style.backgroundColor = generateColor(
entry.name + entry.id
);
}
if (entry.type === 'task') {
entryName = 'Task: ' + entryName;
}
let tempHtml = '<h4>' + entryName + '</h4>';
tempHtml +=
'<span><span class="status">' +
entry.status +
'</span> ' +
entry.assigned +
'</span>';
tempHtml +=
'<span class="info">' +
entry.client +
' / ' +
entry.project +
'</span>';
// tempHtml += '<span class="estimate">Total used: ' + entry.used + '</span> ';
if (entry.type !== 'task') {
estimateMs = estimateMs - entry.tasksEstimateMs;
}
// job/task is spread over multiple days
if (entry.t > 1) {
totalDailyEstimate += estimateMs / entry.t;
tempHtml +=
'<span class="estimate">Estimate daily / total : ' +
msToHoursAndMinutes(estimateMs / entry.t) +
' / ' +
msToHoursAndMinutes(estimateMs) +
'</span> ';
tempHtml +=
'<div class="ecount"> (' +
entry.n +
'/' +
entry.t +
')</div>';
} else {
totalDailyEstimate += estimateMs;
tempHtml +=
'<span class="estimate">Total estimate: ' +
msToHoursAndMinutes(estimateMs) +
'</span> ';
}
entryDiv.innerHTML = tempHtml;
entryDiv.addEventListener('click', function () {
if (entry.type === 'task') {
window.open(taskUrlPrefix + entry.id, entry.id);
} else {
window.open(jobUrlPrefix + entry.id, entry.id);
}
});
// Append the entry to the appropriate day
day.querySelector('.entries').appendChild(entryDiv);
}
} catch (error) {
debugger;
alert(error.message);
}
});
// insert totalDailyEstimate
if (
totalDailyEstimate > warningEstimatMsDailymax &&
window.currentAssigned != null
) {
day.querySelector('.dailyEstimate').innerHTML =
'<span style="color:red">' +
msToHoursAndMinutes(totalDailyEstimate) +
' !!!</span>';
} else {
day.querySelector('.dailyEstimate').innerHTML =
'<span>' + msToHoursAndMinutes(totalDailyEstimate) + '</span>';
}
});
}
// Populate the dropdown
const dropdown = document.getElementById('nameDropdown');
distinctNames.forEach((name) => {
const option = document.createElement('option');
if(name === '' || name === null) {
return;
}
option.value = name;
option.textContent = name;
dropdown.appendChild(option);
});
// Function to call on change
function handleChange(event) {
const selectedName = event.target.value;
console.log('Selected:', selectedName);
window.currentAssigned = selectedName;
sessionStorage.setItem('lastSelectedName', selectedName);
if(selectedName === '') {
window.currentAssigned = null;
}
runthis(window.currentStartDay, window.currentAssigned);
}
// Attach event listener
dropdown.addEventListener('change', handleChange);
const lastSelectedName = sessionStorage.getItem('lastSelectedName');
if (lastSelectedName) {
dropdown.value = lastSelectedName;
}
function getUniqueAssignedValues(entries) {
const assignedValues = entries.map((entry) => entry.assigned); // Extract assigned values
const uniqueAssignedValues = [...new Set(assignedValues)]; // Use Set to get unique values
return uniqueAssignedValues;
}
function addSevenDays(unixTimestamp) {
const date = new Date(unixTimestamp);
date.setDate(date.getDate() + 7); // Add 7 days
return date.getTime(); // Return the updated timestamp
}
function subSevenDays(unixTimestamp) {
const date = new Date(unixTimestamp);
date.setDate(date.getDate() - 7); // Subtract 7 days
return date.getTime(); // Return the updated timestamp
}
document.getElementById('today').addEventListener('click', function () {
window.currentStartDay = Date.now();
sessionStorage.setItem('selectedDate', window.currentStartDay);
runthis(window.currentStartDay, window.currentAssigned);
});
document
.getElementById('forward')
.addEventListener('click', function () {
window.currentStartDay = addSevenDays(window.currentStartDay);
sessionStorage.setItem('selectedDate', window.currentStartDay);
runthis(window.currentStartDay, window.currentAssigned);
});
document.getElementById('back').addEventListener('click', function () {
window.currentStartDay = subSevenDays(window.currentStartDay);
sessionStorage.setItem('selectedDate', window.currentStartDay);
runthis(window.currentStartDay, window.currentAssigned);
});
document
.getElementById('showPlanned')
.addEventListener('click', function () {
changeShowPlanned();
runthis(window.currentStartDay, window.currentAssigned);
});
runthis(window.currentStartDay, window.currentAssigned);
})();
</script>
<span
style="
font-size: 10px;
color: #313131;
display: block;
text-align: center;
margin-top: 16px;
">
V1.1.3</span
>
</body>
</html>