blob: 4fb1cd4bc0100320645bba1a5f41d33182c671ce (
plain)
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
|
function part_to_hour (f) {
return Math.floor(10 * 24 * f) / 10;
}
function hour_to_part (hour) {
return 100 * (hour / 24)
}
function time_to_percent (time) {
// Decimal time
return hour_to_part(time.getHours() + (time.getMinutes() / 60)) + "%"
}
let start_time = new Date();
let end_time = new Date();
var event_start_time = 0
var start_fraq = 0
var parent
var createdEvent = false
function onmousedownhandler (e) {
last = this
event = e
var comp = this
console.log(comp.clientHeight)
while (! comp.classList.contains("events")) {
comp = comp.parentElement
}
console.log(e);
parent = comp
console.log(comp.clientHeight)
fraq = e.offsetY / comp.clientHeight
start_fraq = fraq
event_start_time = part_to_hour(fraq);
createdEvent = document.createElement("div");
createdEvent.className = "event generated";
createdEvent.style.pointerEvents = "none";
createdEvent.style.width = "100%";
createdEvent.style.top = fraq * 100 + "%";
createdEvent.innerText = "New Event";
}
function onmousemovehandler (e) {
if (createdEvent) {
fraq = e.offsetY / this.clientHeight
var diff = fraq - start_fraq;
if (! createdEvent.parentElement) {
for (let e of this.children) {
e.style.pointerEvents = "none";
}
this.appendChild(createdEvent);
}
createdEvent.style.height = diff * 100 + "%";
}
}
function onmouseuphandler (e) {
var end_time = part_to_hour(e.offsetY / this.clientHeight);
console.log("Creating event " + event_start_time + " - " + end_time);
createdEvent = false;
for (let e of parent.children) {
e.style.pointerEvents = "initial";
}
}
function time_to_date (time) {
return [ time.getFullYear(),
String(time.getMonth() + 1).padStart(2, '0'),
String(time.getDate()).padStart(2, '0') ].join("-");
}
var bar_object = false
var current_cell = false
function update_current_time_bar () {
var now = new Date()
/* TODO
The bar and box doesn't get cleared when we leave our time interval.
*/
if (! (start_time <= now.getTime() && now.getTime() < end_time))
return;
var event_area = document.getElementById(time_to_date(now))
if (event_area) {
if (bar_object) {
bar_object.parentNode.removeChild(bar_object)
} else {
bar_object = document.createElement("div")
bar_object.className = "event current-time"
bar_object.id = "bar"
}
bar_object.style.top = time_to_percent(now)
event_area.append(bar_object)
}
/* */
if (current_cell) {
current_cell.style.border = "";
}
current_cell = document.getElementById("td-" + time_to_date(now))
current_cell.style.border = "1px solid black";
}
function toggle_event_pupup () {
console.log(this);
this.getElementsByClassName("popup")[0].classList.toggle("show");
}
window.onload = function () {
start_time.setTime(document.querySelector("meta[name='start-time']").content * 1000)
end_time.setTime(document.querySelector("meta[name='end-time']").content * 1000)
update_current_time_bar()
// once a minute for now, could probably be slowed to every 10 minutes
window.setInterval(update_current_time_bar, 1000 * 60)
for (let c of document.getElementsByClassName("events")) {
c.onmousedown = onmousedownhandler;
c.onmouseup = onmouseuphandler;
c.onmousemove = onmousemovehandler;
}
for (let e of document.getElementsByClassName("event-inner")) {
e.onclick = toggle_event_pupup;
}
}
|