-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
491 lines (452 loc) · 15.3 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
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
<head>
<!-- <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.11.1/tachyons.min.css"> -->
</head>
<body>
<h1>DC Rawhides Line Dances</h1>
<div class="grid-3 sort-section">
<a href="?sort=name" class="video-link">Sort By Name</a>
<a href="?sort=difficulty" class="video-link">Sort By Difficulty</a>
<a href="?sort=timesdanced" class="video-link">Sort By Frequency</a>
</div>
<div id="dance-cards-container">
<div class="loading-spacer">
<div class="video-link loading-rainbow"></div>
</div>
</div>
<div id="contribute" class="contribute-section grid-2">
<div>
<div class="contribute-header">
Add or Edit Content
</div>
<div class="grid-2">
<div class="video-link">
<div class="contribute-subheader">
What?
</div>
<div class="contribute-text">
We especially need instructional videos, example videos, and stepsheets where they are missing. Please add any that are similar to the way DC Rawhides does the dances.
</div>
</div>
<div class="video-link">
<div class="contribute-subheader">
How?
</div>
<div class="contribute-text">
Request access to <a href="https://docs.google.com/spreadsheets/d/1-l36tKe7PT3P1iYVJ4H7WpYfG5t0yXXTuH6wlFBbegY/edit#gid=0">this Google Spreadsheet</a> and edit it there directly yourself. This page will automatically update after refreshing the page (and maybe some time delay).
</div>
<div class="contribute-text">
Or, open the spreadsheet and comment on the cell that should be added to or changed. Someone with spreadsheet access will eventually put it into the spreadsheet directly.
</div>
</div>
</div>
</div>
<div>
<div class="contribute-header">
How This Works
</div>
<div class="video-link">
<div class="contribute-text">
This page reads data from a Google Spreadsheet, and displays it in a pretty way using Javascript in the browser. When the Google Spreadsheet gets updated, this page also gets updated automatically (after some time delay, and maybe a page refresh).
</div>
<div class="contribute-text">
Want to improve how the page looks visually? Or want to see how this works? Check out the <a href="https://github.com/caseywatts/dcrawhides-linedances">source code</a>.
</div>
</div>
</div>
</div>
<style>
:root {
--rawhides-blue: #1392f0;
--rawhides-red: #bf3a31;
--background-blue: #ECF5FC;
--other-blue: #6dc8ca;
--difficulty-beginner: green;
--difficulty-intermediate: blue;
--difficulty-advanced: purple;
}
body {
font-family: sans-serif;
background: white;
margin: 0px;
padding: 0px;
}
h1 {
text-align: center;
padding: 0px;
margin: 0px;
color: white;
background-color: black;
padding: 20px;
font-size: 4em;
border-bottom: 8px solid var(--rawhides-red);
}
h4 {
text-align: center;
padding: 0px;
margin: 0px;
padding-bottom: 20px;
color: white;
background: black;
}
.active-link {
filter: brightness(95%);
}
.contribute-please-container {
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
}
.contribute-please {
display: inline-block;
text-align: center;
padding: 10px;
border: 1px solid green;
border-radius: 15px;
font-size: 1.2em;
background: var(--rawhides-blue-light);
}
.sort-section {
max-width: 400px;
margin: auto;
margin-top: 20px;
}
.loading-spacer {
height: 100vh;
padding-right: 25vw;
padding-left: 25vw;
padding-top: 25vh;
padding-bottom: 25vh;
}
.loading-rainbow {
position: relative;
overflow: hidden;
height: 5vh;
}
.loading-rainbow:after {
content: '';
position: absolute;
top:0%;
left:0%;
width: 100%;
height: 100%;
background: linear-gradient(285deg,
transparent,
rgba(255, 0 , 0, .1),
rgba(255, 127, 0, .1),
rgba(255, 255, 0, .1),
rgba(0, 255, 0, .1),
rgba(0, 0, 255, .1),
/* rgba(75, 0, 130, .1), */
rgba(148, 0, 211, .1),
transparent
);
/* background: linear-gradient(100deg,transparent,transparent,rgba(255,0,0,.1),transparent,transparent); */
transform: translateX(-100%);
animation: loading .9s infinite;
}
@keyframes loading {
100% {
transform: translateX(100%);
}
}
#dance-cards-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
grid-auto-rows: auto;
grid-gap: 1rem;
}
@media only screen and (max-device-width: 500px) {
#dance-cards-container {
display: block;
}
}
.dance-card {
margin: 30px;
border: 3px solid var(--rawhides-blue);
box-shadow: 3px 3px 8px grey;
border-radius: 15px;
padding: 10px;
background: var(--background-blue);
}
.dance-name {
text-align: center;
color: var(--rawhides-red);
font-weight: bold;
font-size: 1.5em;
padding: 10px;
}
.subtitle {
align-items: center;
padding: 10px;
font-size: 1em;
text-align: center;
}
.subtitle-times-danced {
font-size: 1em;
}
.subtitle-times-danced-number {
font-size: 1.5em;
}
.video-links-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}
.video-link {
display: block;
border: 1px solid var(--rawhides-blue);
border-radius: 15px;
background: white;
margin: 10px;
padding: 10px;
text-align: center;
text-decoration: none;
}
.video-link:hover {
filter: brightness(95%);
}
.video-link-disabled {
background: #EEEEEE;
}
.grid-1 {
display: grid;
grid-template-columns: minmax(100px, 1fr);
}
.grid-2 {
display: grid;
grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr);
}
.grid-3 {
display: grid;
grid-template-columns: minmax(100px, 1fr) minmax(100px, 1fr) minmax(100px, 1fr);
}
.col-header {
text-align: center;
font-size: 1.2em;
color: var(--rawhides-red);
margin-top: 20px;
}
.difficulty-level {
font-size: 1.2em;
display: inline-block;
color: white;
padding: 5 10;
border-radius: 15px;
text-align: center;
}
.difficulty-beginner {
background: var(--difficulty-beginner);
filter: brightness(140%);
}
.difficulty-intermediate {
background: var(--difficulty-intermediate);
filter: brightness(140%);
}
.difficulty-advanced {
background: var(--difficulty-advanced);
filter: brightness(140%);
}
.contribute-section {
background-color: var(--background-blue);
padding: 30px;
border-top: 5px solid var(--rawhides-blue);
text-align: center;
line-height: 1.3em;
}
.contribute-header {
font-size: 1.5em;
color: var(--rawhides-red);
margin: 20px;
}
.contribute-subheader {
font-size: 1.2em;
color: var(--rawhides-red);
margin: 20px;
}
.contribute-text {
text-align: left;
margin: 10px;
}
</style>
<script>
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
(async () => {
(function highlightLinkToCurrentPage() {
const linkToCurrentPage = document.querySelector(`[href='${window.location.search}']`);
if (linkToCurrentPage) {
linkToCurrentPage.classList.add('active-link');
}
})()
// supporting functions
const fetchData = async () => {
const spreadsheetCsvUrl = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSoiGjL6JiGNx4Z2Sn7eqlYX1FfgAFI7A9hBd9yVSGzf7LxpxOvEMmBKDMC1xKev5v6fTOU-hrBofdM/pub?output=csv"
const dataStream = await fetch(spreadsheetCsvUrl)
const dataStreamText = await dataStream.text()
var lines = dataStreamText.split(/\r\n|\n/);
var headings = lines.shift().split(',');
var parsedData = [];
while (lines.length > 0) {
var danceEntry = new Map();
var columns = lines.shift().split(',')
for (var j = 0; j < columns.length; j++) {
danceEntry.set(headings[j], columns[j]);
}
parsedData.push(danceEntry);
}
return parsedData;
}
const mungeDanceData = (danceData) => {
return danceData.map((danceEntry) => {
const exampleVideos = [
danceEntry.get('Example Video'),
danceEntry.get('Example 2'),
].filter(x => x) // remove any that are empty
const instructionVideos = [
danceEntry.get('Instruction Video'),
danceEntry.get('Instruction 2'),
].filter(x => x) // remove any that are empty
return {
name: danceEntry.get('Dance Name'),
difficulty: danceEntry.get('Difficulty'),
type: danceEntry.get('Line Dance vs. Partner Dance'),
timesDanced: danceEntry.get('# of times danced in past 12 months'),
percentDanced: danceEntry.get('percent danced in past 12 months'),
exampleVideos: exampleVideos,
instructionVideos: instructionVideos,
stepsheet: danceEntry.get('Stepsheet'),
}
})
}
const sortAndFilterDanceData = (danceData, sort) => {
const sortByName = (danceA, danceB) => {
return danceA.name.localeCompare(danceB.name)
}
const sortByDifficulty = (danceA, danceB) => {
return danceA.difficulty.localeCompare(danceB.difficulty)
}
const sortByTimesDanced = (danceA, danceB) => {
return parseInt(danceB.timesDanced) - parseInt(danceA.timesDanced)
}
const filteredList = danceData
.filter(dance => dance.timesDanced > 0)
if (sort === "name") {
console.log('name')
return filteredList.sort(sortByName)
} else if (sort === "difficulty") {
console.log('difficulty')
return filteredList.sort(sortByDifficulty)
} else if (sort === "timesdanced") {
console.log('timesdanced')
return filteredList.sort(sortByTimesDanced)
} else {
return filteredList.sort(sortByName)
}
}
const componentExampleVideos = function(urls) {
if (urls.length > 0) {
return urls.map((url, index) => {
const videoNumber = index + 1
if (videoNumber === 1) {
return `<a class="video-link" href="${url}">Example Video</a>`
} else {
return `<a class="video-link" href="${url}">Example Video ${videoNumber}</a>`
}
}).join('') // no commas between elements
} else {
return '<a href="#contribute" class="video-link video-link-disabled">No Example Videos. Add one?</a>'
}
}
const componentInstructionVideos = function(urls) {
if (urls.length > 0) {
return urls.map((url, index) => {
const videoNumber = index + 1
if (videoNumber === 1) {
return `<a class="video-link" href="${url}">Instruction Video</a>`
} else {
return `<a class="video-link" href="${url}">Instruction Video ${videoNumber}</a>`
}
}).join('') // no commas between elements
} else {
return '<a href="#contribute" class="video-link video-link-disabled">No Instruction Videos. Add one?</a>'
}
}
const componentStepsheetLink = function(title, url) {
if (url) {
return `<a class="stepsheet video-link" href="${url}">${title}</a>`
} else {
return `<a href="#contribute" href="#contribute" class="stepsheet video-link video-link-disabled">No Stepsheet Available. Add one?</a>`
}
}
const componentSongs = function() {
return `
<a href="https://docs.google.com/spreadsheets/d/1-l36tKe7PT3P1iYVJ4H7WpYfG5t0yXXTuH6wlFBbegY/edit#gid=2072603583" class="video-link">Songs - see spreadsheet</a>
`
}
const componentDanceCard = (dance) => {
const difficultyCSS = {
"1 Beginner": 'difficulty-level difficulty-beginner',
"2 Intermediate": 'difficulty-level difficulty-intermediate',
"3 Advanced": 'difficulty-level difficulty-advanced'
};
const difficultyClass = difficultyCSS[dance.difficulty]
return `
<div class="dance-card">
<div class="dance-name">${dance.name}</div>
<div class="grid-2 subtitle">
<div class="subtitle-dance-difficulty">
<div class="${difficultyClass}">${dance.difficulty}</div>
</div>
<div class="subtitle-times-danced">
<div>danced at</div>
<div class="subtitle-times-danced-number">${dance.percentDanced}</div>
<div>of recent events</div>
</div>
</div>
<div class="grid-1">
${componentStepsheetLink("Stepsheet", dance.stepsheet)}
</div>
<div class="col-header">Videos</div>
<div class="grid-2">
<div>
${componentExampleVideos(dance.exampleVideos)}
</div>
<div>
${componentInstructionVideos(dance.instructionVideos)}
</div>
</div>
<div class="grid-1">
${componentSongs()}
</div>
</div>
`
}
const replaceContentsOfPage = (pageContents) => {
document.querySelector('#dance-cards-container').innerHTML = pageContents
}
// Initialization begins here
const loadPageContent = (filter) => {
const sortedAndFilteredDances = sortAndFilterDanceData(dances, getQueryVariable('sort'))
const allDanceCards = sortedAndFilteredDances.map((dance) => {
return componentDanceCard(dance)
}).join('') // no commas between cards
if (window.location.href.includes('donotload')) {
// noop
} else {
replaceContentsOfPage(allDanceCards);
}
}
const danceData = await fetchData()
const dances = mungeDanceData(danceData)
loadPageContent()
})()
</script>
</body>