-
Notifications
You must be signed in to change notification settings - Fork 0
/
milestones-view.html
253 lines (231 loc) · 9.62 KB
/
milestones-view.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
<!--B"H-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG to HTML Form</title>
<link rel="manifest" href="/app/manifest.json">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" type="text/css" href="./milestoneStyles.css">
<script src="./servicer.js"></script>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body>
<div class="container">
<div class="milestone-holder">
<div class="milestone-header">
<div class="milestone-info">
<div class="milestone-logo">
<img class="arrow" src="./img/arrow.svg">
<div class="miles-number" id="milesNum">4 m</div>
</div>
<div class="milestone-header-text">
<div>Milestones</div>
</div>
</div>
<div class="milestone-message">
Choose your daily milestones
</div>
</div>
<div class="milestone-list-container">
<div class="milestone-list" id="mList">
<div class="milestone">
<div class="milestone-label">
Put on Teffilin
</div>
<div class="milestone-check">
<div class="checkbox"></div>
</div>
</div>
<div class="milestone">
<div class="milestone-label">
Put on Teffilin
</div>
<div class="milestone-check">
<div class="checkbox"></div>
</div>
</div>
<div class="milestone">
<div class="milestone-label">
Put on Teffilin
</div>
<div class="milestone-check">
<div class="checkbox"></div>
</div>
</div>
<div class="milestone-list-more">
<img class="btn" src="./img/scroll-arrow.svg">
</div>
</div>
</div>
<div class="milestone-settings">
<img src="./img/start-btn.svg" id="startBtn" class="start btn">
</img>
</div>
</div>
</div>
<script src="./nav.js"></script>
<script>
//B"H
var startBtn = document.querySelector("#startBtn");
var m = document.querySelector("#mList");
var baseURL = "https://awtsmoos.whf.bz";
var mn = document.getElementById("milesNum");
try {
(async () => {
m.innerText = "Loading milestones..."
mn.textContent = "...";
try {
var sesh = await (
await fetch(baseURL, {
method: "POST",
body: new URLSearchParams({
action: "session"
})
})
).json();
if(sesh.success) {
window.SESSION = sesh.success;
if(SESSION?.name) {
var user = document.getElementById("username");
user.textContent = SESSION.name;
}
}
} catch(e) {
console.log(e);
}
var mile = null;
try {
mile = //B"H
await (await fetch(baseURL +"/?"+ new URLSearchParams({
type: "default"
}), {
method: "POST",
body: new URLSearchParams(
{
action: "read-milestones",
})
})).json();
} catch(e) {
m.textContent = "Problem loading";
console.log(e)
}
try {
if(Array.isArray(mile)) {
var selected = (await getSelectedMilestones())?.result || [];
console.log(window.sl = selected);
window.milestoneData = mile;
m.innerText = ""
mile.forEach(mi => {
// Create the main milestone div
const milestone = document.createElement("div");
milestone.classList.add("milestone");
milestone.dataset.id = mi.id;
var milestoneMainArea = document.createElement("div")
milestoneMainArea.className = "visible-area";
milestone.appendChild(milestoneMainArea);
var milestoneMessage = document.createElement("div");
milestoneMessage.className = "msg collapsed";
milestone.appendChild(milestoneMessage);
milestoneMessage.textContent = mi.description;
milestoneMainArea.onclick = (e) => {
if(e.target.classList.contains("checkbox")) {
return;
}
milestoneMessage.classList.toggle("collapsed")
}
// Create the milestone-label div
const milestoneLabel = document.createElement("div");
milestoneLabel.classList.add("milestone-label");
milestoneLabel.textContent = mi.headline;
// Create the milestone-check div
const milestoneCheck = document.createElement("div");
milestoneCheck.classList.add("milestone-check");
// Create the checkbox div
const checkbox = document.createElement("div");
checkbox.classList.add("checkbox");
// Append the checkbox to the milestone-check div
milestoneCheck.appendChild(checkbox);
var sel = selected?.find(w=>w?.milestone_selection == mi.id);
console.log(sel,selected,mi)
if(sel) {
checkbox.classList.add("checked")
}
// Append the milestone-label and milestone-check divs to the main milestone div
milestoneMainArea.appendChild(milestoneLabel);
milestoneMainArea.appendChild(milestoneCheck);
// console.log(window.a=m)
// Append the milestone div to the body or any other parent element
m.appendChild(milestone);
})
mn.textContent = mile.length + " m";
}
navify()
} catch(e) {
m.innerText = "Problem initializing"
console.log(e);
}
})();
if(startBtn) {
startBtn.onclick = async () => {
var res = await saveCheckedMilestones();
if(res) {
m.innerText = "Saved milestones! Redirecting...";
location.href="/app/view-milestones.html"
}
}
}
} catch(e) {
m.textContent = "There was a problem loading. "
console.log(e)
}
async function saveCheckedMilestones() {
var chk = getCheckedMilestones().map(w=>w.id);
try {
//B"H
var g = await (
await fetch(baseURL, {
method: "POST",
body: new URLSearchParams({
action: "select-milestones",
milestones: JSON.stringify(chk)
})
})
).json()
return g;
} catch(e) {
console.log(e);
return null;
}
}
async function getSelectedMilestones() {
//B"H
try {
var g = await (
await fetch(baseURL, {
method: "POST",
body: new URLSearchParams({
action: "get-milestone-selections"
})
})
).json()
return g;
} catch(e) {
console.log(e);
return []
}
}
function getCheckedMilestones() {
//B"H
if(!window.milestoneData) {
return console.log("no milestone data");
}
var ch =Array.from(document.querySelectorAll(".checked"))
.map(w=>( w.parentNode.parentNode.parentNode.dataset.id
))
return milestoneData.filter(w=>ch.includes(w.id))
}
</script>
</body>
</html>