-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
463 lines (382 loc) · 12.5 KB
/
index.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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<style>
html, body {
padding: 0;
margin: 0;
}
html {
height: 100%;
font-family: sans-serif;
}
body {
display: flex;
flex-direction: column;
height: 100%;
}
textarea {
display: grid;
flex-direction: row;
width: 100%;
margin-right: 0em;
font-family: monospace;
}
.grid-container {
display: flex;
flex-direction: column;
height: 100%;
}
.header {
color: white;
background-color: black;
}
.scroll {
overflow-y: scroll;
}
.comfort {
padding: 1em;
}
.pad-left {
padding-left: 1em;
}
.flex {
flex: 1;
}
.flex-grow {
/* flex: 1; */
}
.row {
display: flex;
flex-direction: row;
}
.panel {
margin: 1em;
}
.no-side-margin {
margin-left: initial;
margin-right: initial;
}
.foot {
font-size: smaller;
text-align: center;
background-color: #eee;
}
.foot > ul {
display: inline-block;
margin: initial;
}
.foot > ul > li {
display: inline-block;
}
a:visited {
color: inherit;
}
.card {
box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.4);
padding: 1em;
margin-bottom: 1em;
border-radius: 0.7em;
}
</style>
<title>Spartan Harriers: Route Text Generator</title>
</head>
<body>
<div class="grid-container">
<div class="header">
<a href="#!/" style="text-decoration: none;">
<h3 class="pad-left">Spartan Harriers: Route Text Generator</h3>
</a>
</div>
<div class="middle scroll comfort flex js-content">
</div>
<div class="foot comfort">
Spartan Harriers - 2018
<ul>
<li><a href="#!/help">[help]</a></li>
<li>Other Apps:</li>
<li><a href="post-composer.html">Post Composer</a></li>
</ul>
</div>
</div>
<div hidden id="templates">
<div class="left-right-container js-main-inputs">
<div class="lrleft">
<label for="date">
Date<br/>
<input id="date" type="date" onchange="render()">
</label>
<br/>
<label>
Distance<br/>
<input id="distance" type="number" placeholder="Distance" onchange="render()">km
</label><br/>
<label>
Route Text<br/>
<textarea rows="8" oninput="render()" style="resize: none;"></textarea>
</label>
</div>
<div class="lrright flex-grow">
<textarea rows="8" class="result" readonly style="resize:vertical;"></textarea>
</div>
<div class="panel no-side-margin row">
<button data-action="copyResult">Copy</button>
</div>
</div>
<div class="js-help">
<a href="#!/">Back</a>
<h1>Help</h1>
<article>
<section>
<h1>What is this?</h1>
<p>
The tools available in this app was created to save some time when
mapping run routes when received from my running captain.
</p>
<p>
The routes for the next week is received in a MS Word document in a
cue-style:
</p>
<div class="card">
<pre>
<code>
Club – Ladies Mile – Parish Church
(water)(Regroup) – Parish Rd –– Left into
Southern Cross (water top of
Rhodes)(Regroup) – Rhodes Drive -Right
into Hohenort – left Spilhaus – right
Hohenhort – left into Brommersvlei (water at
Hotel) Regroup – right Constantia Rd – left
Spaanschemat – left Kendal – Owen – Club.
</code>
</pre>
Verbatim example
</div>
<p>
To the trained eye, this is bit of an eyesore with dashes, n-, and m-dashes
as well as double dashes: "<code> -- </code>". When trying to read from that
when creating a route on Strava is really painful.
</p>
<p>
So I've smashed together some apps over time to help me normalise
the information for easier use and assisting in consistently creating
route posts that I post to Strava. (Doing it by hand was a mission of saving
a text document, copying, updating and double-checking that everything is
correct.)
</p>
<p>
With this app, the same input is transformed to the following, simply by
pasting it into a textarea:
</p>
<div class="card">
<pre>
<code>
15km:Sat:2019-02-09
======
Club
Ladies Mile
Parish Church (water)(Regroup)
Parish Rd
Left into Southern Cross (water top of Rhodes)(Regroup)
Rhodes Drive
Right into Hohenort
left Spilhaus
right Hohenhort
left into Brommersvlei (water at Hotel) Regroup
right Constantia Rd
left Spaanschemat
left Kendal
Owen
Club
~~~~~~
</code>
</pre>
Verbatim example of transformed input
</div>
</section>
<section>
<h1>Process Overview</h1>
<ol> <h4>Part 1: This parser</h4>
<li>Open Document</li>
<li>Locate Day</li>
<li>Locate Distance</li>
<li>Copy Route Cue</li>
<li>Go <a href="#!/">here</a></li>
<li>Select Date</li>
<li>Set Distance</li>
<li>Paste Copied Cue</li>
<li>Click Copy button</li>
<li>Go to Part 2</li>
</ol>
<ol> <h4>Part 2: Strava</h4>
<li>
In a new browser tab, go to
<a href="http://strava.com/routes/new">Strava</a> to create a
new route.
</li>
<li>
Locate the clubhouse in the map view by zooming and panning
to Meadowridge.
</li>
<li>
Referencing the parser's transformed text, click a start
point in one of the roads next to the club, according to the
cue details.
</li>
<li>
Add points along the roads to complete the map and the end point.
</li>
<li>Click Save</li>
<li>Paste the previously copied text into the description input.</li>
<li>
Copy the first line for the route name, and paste it in the
Name field.
</li>
<li>Make sure the route is public (Private remains unchecked)</li>
<li>Click Save</li>
<li>Click <em>View My Route</em></li>
<li>Copy the URL for use elsewhere (most likely <a href="post-composer.html">here</a>)</li>
<li>
If you are helping out a buddy that does the post for the week's runs,
send them this URL.
</li>
<li>
Repeat for every distance :)
</li>
<li>
If you are the buddy composing the post for the week's runs, go to
Part 3.
</li>
</ol>
<ol> <h4>Part 3: Post Composer</h4>
<p>The Post Composer is a utility to create weekly posts in a consistent
format. It allows adding dates, and distances for each date as well
as starting times.</p>
<li>Open the <a href="post-composer.html">composer</a></li>
<li>
Click "Add Date" once for each day, and set the date using the
calendar selector.
</li>
<li>
Set the time.
</li>
<li>
Click "Add Distance" for each distance for that date.
</li>
<li>
Set the distance.
</li>
<li>
Paste the link.
</li>
<li>
Repeat for all days and distances.
</li>
<li>
If additional notes are required, click "Add Note"
</li>
<li>
When finally done, click the now enabled, "Get Text". A dialog
will pop up with the formatted route text. It will also select
the text and copy it to your clipboard.
</li>
<li>
Head over to your Strava club's group and create a new post from
the text just copied. Remember to include a nice running-related
picture!
</li>
</ol>
</section>
</article>
</div>
</div>
</body>
<script>
console.info('hello world');
function copyResult(e) {
e.preventDefault();
document.querySelector('textarea.result').select();
document.execCommand('copy');
alert('text copied!');
}
let state = {
date: undefined,
distance: 0,
routeText: ''
};
let fixRoute = routeString => {
return routeString
.replace(/\s+/g, " ")
.replace(/\./g, "")
.split(" ")
.join(' ').split(/\-|–/)
.map(s => s.trim());
};
let transformText = (selector) => {
let text = document.querySelector(selector).value;
return fixRoute(text).join('\n');
};
let dateText = selector => {
let dateInput = document.querySelector(selector).value;
let d = new Date(dateInput);
return `${dow(d)}:${dateInput}`;
};
function updateState() {
state.routeText = transformText('textarea');
state.date = dateText('#date');
state.distance = Number(document.querySelector('#distance').value);
console.info('state: ', state);
}
function hasLength(x) {
return (x || '').length > 0;
}
function dow(dt) {
let ds = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return ds[dt.getDay()];
}
function render() {
updateState();
let resultText = document.querySelector('.result');
resultText.value = [
`${state.distance}km:${state.date}`,
`======`,
state.routeText,
`~~~~~~`
].filter(hasLength)
.join('\n');
}
document.addEventListener('click', e => {
if (e.target.dataset.action) {
window[e.target.dataset.action](e);
}
});
window.addEventListener('load', e => {
views.updateView();
});
const views = {
jsContent: () => {
let jsContent = document.querySelector('.js-content');
let oldContent = jsContent.firstChild;
templates.appendChild(oldContent);
return jsContent;
},
'/help': () => {
console.info('instating /help');
let jsContent = views.jsContent();
jsContent.appendChild(document.querySelector('.js-help'));
},
default: () => {
let jsContent = views.jsContent();
jsContent.appendChild(document.querySelector('.js-main-inputs'));
},
updateView: () => {
(views[location.hash.split('#!')[1]] || views.default)();
}
};
window.addEventListener('hashchange', e => {
console.info('hash: ', location.hash);
views.updateView();
});
</script>
</html>