-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathold_caldisplay_vue.html
More file actions
467 lines (451 loc) · 24 KB
/
Copy pathold_caldisplay_vue.html
File metadata and controls
467 lines (451 loc) · 24 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JSON Test</title>
<!-- Font -->
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<!-- FontAwesome Icons -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<!-- Bootstrap JS, Popper.js, and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<style>
body {
/* font-family: 'Roboto', sans-serif; */
}
label {
font-size: 1em;
}
.month-heading {
color: #707070;
text-decoration: underline;
}
.month-heading:hover {
color: #E95420;
cursor: pointer;
}
.filter-heading {
font-size: 1.2em;
-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;
}
.fa-chevron-up {
font-size: 0.7em;
}
.form-check-label {
font-size: 1em;
}
.card-body {
background-color: #da7652;
}
#selectedYear {
color: #E95420;
-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;
}
#selectedYear>i {
font-size: 0.8em;
}
#selectedYear>i:hover {
color: #707070;
cursor: pointer;
}
/* The animation code */
@keyframes chevron-flip {
0% {transform: rotate(0deg);}
100% {transform: rotate(180deg);}
}
.chevron-animate-up {
animation-name: chevron-flip;
animation-iteration-count: 1;
animation-duration: 0.4s;
animation-fill-mode: forwards;
animation-direction: normal;
}
.chevron-animate-down {
animation-name: chevron-flip;
animation-iteration-count: 1;
animation-duration: 0.4s;
animation-fill-mode: forwards;
animation-direction: reverse;
}
</style>
</head>
<body>
<div id="app" style="height: fit-content">
<div class="container-fluid">
<div class="row">
<div class="col-md-2 px-0 min-vh-100" style="background-color: #E95420;">
<div class="mx-1" style="height: 200px;">
<h5 class="text-white">Filter</h5>
<div>
<div class="form-group">
<input class="form-control" v-model="name_search_query" type="text" placeholder="Search name">
</div>
<a class="filter-heading d-block text-white" role="button">
Location <i class="fas fa-chevron-up"></i>
</a>
<div class="collapse">
<div class="card card-body">
<div class="form-group">
<label for="country">Choose Country</label>
<button type="button" class="btn btn-light btn-sm btn-block mb-2" @click="selectedCountries=[]">All locations</button>
<select multiple v-model="selectedCountries" class="form-control">
<option disabled selected hidden>...</option>
<option v-for="option in country_options" :value="option">{{ option }}</option>
</select>
</div>
</div>
</div>
<a class="filter-heading d-block text-white" role="button">
Competition <i class="fas fa-chevron-up"></i>
</a>
<div class="collapse">
<div class="card card-body">
<button type="button" class="btn btn-light btn-sm btn-block mb-2" @click="selectedCategories=[]">All competitions</button>
<div v-for="(cat, i) in compCategories" class="form-group form-check">
<input class="form-check-input" type="checkbox" :value="cat.value" :id="'id-category-' + i" v-model="selectedCategories">
<label class="form-check-label" :for="'id-category-' + i">{{ cat.label }}</label>
</div>
</div>
</div>
<a class="filter-heading d-block text-white" role="button">
Type <i class="fas fa-chevron-up"></i>
</a>
<div class="collapse">
<div class="card card-body">
<button type="button" class="btn btn-light btn-sm btn-block mb-2" @click="">All Types</button>
<div v-for="(type, i) in compTypes" class="form-group form-check">
<input class="form-check-input" :value="type.value" :id="'id-type-' + i" type="checkbox" v-model="selectedCompType">
<label class="form-check-label" :for="'id-type-' + i">{{ type.label }}</label>
</div>
</div>
</div>
<a class="filter-heading d-block text-white" role="button">
Age Groups <i class="fas fa-chevron-up"></i>
</a>
<div class="collapse">
<div class="card card-body">
<button type="button" class="btn btn-light btn-sm btn-block mb-2" @click="selectedAG=[]">All Age Groups</button>
<div v-for="(ag, i) in ageGroups" class="form-group form-check">
<input class="form-check-input" :value="ag.value" :id="'id-ag-' + i" type="checkbox" v-model="selectedAG">
<label class="form-check-label" :for="'id-ag-' + i">{{ ag.label }}</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-10 min-vh-100" style="background-color: #F0F0F0;">
<div class="col-md-11 mt-3">
<div class="row">
<div id="selectedYearContainer" class="mx-auto">
<h1 id="selectedYear" class="d-inline">
<i class="fas fa-angle-left mx-2" @click="decrementYear()"></i>
{{ selectedYear }}
<i class="fas fa-angle-right mx-2" @click="incrementYear()"></i>
</h1>
</div>
</div>
<div id="months-headings" class="row">
<div class="col-md-1 d-inline" v-for="month in months_data" >
<h5 class="month-heading d-block mb-0 text-center" v-on:click="applyDateFilter(month.num)">{{ month.name }}</h5>
<div class="d-block mx-auto" style="width:fit-content">
<span class="badge badge-pill badge-secondary">{{ month.numberOfComps }}</span>
</div>
</div>
</div>
</div>
<div class="col-md-11 mt-3">
<div class="d-flex flex-horizontal justify-content-between align-items-center">
<div>
<span v-if="filteredCompetitions" class="badge badge-secondary mb-0">{{ filteredCompetitions.length || 0 }} of {{ info && info.length || 0 }} competitions</span>
<a href="javascript:location.reload(true)">Reset filters</a>
</div>
<navigator class="float-right" :is-loading="isLoading" :total="filteredCompetitions && filteredCompetitions.length || 0" @movePage="mvPg" @changePage="setPg" :results-per-page="showOnPage"></navigator>
</div>
<table class="table table-sm list bg-white">
<thead class="bg-primary text-white">
<tr>
<th scope="col" class="d-lg-table-cell">Date</th>
<th scope="col">Full Name</th>
<th class="text-center" scope="col">Age Groups</th>
<th class="text-center" scope="col">Country</th>
<th class="text-center" scope="col">Type</th>
</tr>
</thead>
<tbody>
<tr v-if="paginatedCompetitions().length == 0">
<td>No competitions</td>
</tr>
<tr v-for="comp in paginatedCompetitions()" :key="comp.id">
<td style="width:125px">{{comp.date}}</td>
<td>{{comp.full_name}}</td>
<td class="text-center">{{comp.age_groups}}</td>
<td class="text-center">{{comp.country}}</td>
<td class="text-center">{{comp.type}}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-11">
<nav class="d-flex justify-content-center">
<navigator class="float-right" :is-loading="isLoading" :total="filteredCompetitions && filteredCompetitions.length || 0" @movePage="mvPg" @changePage="setPg" :results-per-page="showOnPage"></navigator>
</nav>
</div>
</div>
</div>
</div>
</div>
<!-- Navigator -->
<script type="text/template" id="navigator_template">
<ul class="pagination mr-0 my-1" v-if="isLoading || total > resultsPerPage" v-cloak>
<li :class="{'page-item': true, disabled: $parent.page == 0}">
<a class="page-link" @click="prevPage" aria-label="Previous">
<span aria-hidden="true" class="d-none d-lg-inline-block hidden-xs hidden-sm hidden-md">Prev</span>
<span class="d-inline-block d-lg-none hidden-lg">«</span>
</a>
</li>
<!-- partial -->
<li v-if="numPages > threshold && $parent.page > 2" :class="{'page-item': true, active: $parent.page == 1}"><a class="page-link" @click="setPage(1)">1</a></li>
<li v-if="numPages > threshold && $parent.page > 3" class="page-item disabled"><span class="page-link">...</span></li>
<li v-if="numPages > threshold" v-for="pi in _.range(Math.max(1, $parent.page - 1), Math.min(numPages, $parent.page + 2) + 1)"
:class="{'page-item': true, active: $parent.page == pi}">
<a @click="setPage(pi)" class="page-link">{{ pi }}</a>
</li>
<li v-if="numPages > threshold && $parent.page < numPages - 3" class="page-item disabled"><span class="page-link">...</span></li>
<li v-if="numPages > threshold && $parent.page < numPages - 2" class="page-item"><a class="page-link" @click="setPage(numPages)">{{ numPages }}</a></li>
<li v-else-if="numPages <= threshold" v-for="i in _.range(1, numPages+1)" :class="{'page-item': true, active: $parent.page == i}">
<a @click="setPage(i)" class="page-link">{{ i }}</a>
</li>
<li :class="{'page-item': true, disabled: $parent.page == numPages}">
<a class="page-link" @click="nextPage" aria-label="Next">
<span aria-hidden="true" class="d-none d-lg-inline-block hidden-xs hidden-sm hidden-md">
<span v-if="isLoading"><img src="./img/ajax-loading.gif" alt="Loading" /> Loading ...</span>
<span v-else>Next</span>
</span>
<span class="d-inline-block d-lg-none hidden-lg">
<span v-if="isLoading"><img src="./img/ajax-loading.gif" alt="Loading" /> Loading ...</span>
<span v-else>»</span>
</span>
</a>
</li>
</ul>
</script>
<!-- production version, optimized for size and speed -->
<!--script src="https://cdn.jsdelivr.net/npm/vue"></script-->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="./js/lodash.js"></script>
<script src="./js/navigator-script.js"></script>
<script>
$(document).ready(() => {
// Toggles the collapse of filters
$(".filter-heading.d-block.text-white").click(function(){
$(this).next().collapse('toggle');
});
$('.collapse').on('show.bs.collapse', function() {
var chevron = $(this).prev().children('i');
chevron.addClass('chevron-animate-up');
setTimeout(() => {
chevron.removeClass('chevron-animate-down');
var rotate = chevron.css('transform');
chevron.css('transform', rotate);
chevron.removeClass('chevron-animate-up');
}, 500);
});
$('.collapse').on('hide.bs.collapse', function() {
var chevron = $(this).prev().children('i');
chevron.addClass('chevron-animate-down');
setTimeout(() => {
chevron.removeClass('chevron-animate-up');
var rotate = chevron.css('transform');
chevron.css('transform', rotate);
chevron.removeClass('chevron-animate-down');
}, 500);
});
});
var app = new Vue({
el: '#app',
props: {
compCategories: {
type: Array,
default: function() {
return [{label:'European athletics events and meetings', value:'cat-1'}, {label:'IAAF events and meetings', value:'cat-2'}, {label:'Affiliated organisation competitions', value:'cat-3'}, {label:'International matches', value:'cat-4'}, {label:'National championships', value:'cat-5'}, {label:'International meetings with national permit', value:'cat-6'}];
}
},
ageGroups: {
type: Array,
default: function () {
return [{label:'Seniors',value:'S'}, {label:'Masters',value:'M'}, {label:'U23',value:'U23'}, {label:'U20',value:'U20'}, {label:'U18',value:'U18'}]
}
},
compTypes: {
type: Array,
default: function () {
return [{label:'Outdoor', value:'TRACK'}, {label:'Indoor', value:'Indoor'}, {label:'Road races', value:'Road races'}, {label:'Cross country', value:'Cross country'}, {label:'Mountain running', value:'Mountain running'}, {label:'Race walking', value:'Race walking'}]
}
},
allMonths: {
type: Array,
default: function () {
return ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
}
},
pageSize: {
type: Number,
default: function () { return 50 }
}
},
data() {
return {
info: [],
name_search_query: '',
all_months: [],
country_options: [],
selectedYear: new Date().getFullYear(),
selectedMonth: null,
selectedCompType: [],
selectedAG: [],
selectedCountries: [],
selectedCategories: [],
showOnPage: 20,
page: 1,
isLoading: true,
}
},
computed: {
filteredCompetitions: function () {
var self = this,
output = self.info || [];
if (self.name_search_query != '') {
output = output.filter(function (item) {
return item.full_name.toLowerCase().includes(self.name_search_query.toLowerCase())
})
}
if (self.selectedCountries.length > 0) {
output = output.filter(function (item) {
return self.selectedCountries.indexOf(item.country) >= 0
})
}
if (self.selectedAG.length > 0) {
output = output.filter(function (item) {
var ageGroups = item.age_groups.split(',').map(function(ag) { return ag.trim() });
var hits = ageGroups.map(function (ag) {
return self.selectedAG.indexOf(ag) >= 0
})
return hits.reduce(function (x, y) { return x || y }, false)
})
}
if (self.selectedYear || self.selectedMonth) {
output = self.filterByDate(self.selectedMonth, output);
}
return output
},
months_data: function() {
var self = this;
self.all_months = [];
if (self.info) {
for (month in self.allMonths) {
var monObject = {};
monObject.num = parseInt(month)+1;
monObject.name = self.allMonths[month];
var compList = self.filterByDate(String(monObject.num).padStart(2, '0'));
monObject.numberOfComps = compList.length;
self.all_months.push(monObject);
}
}
var output = self.all_months;
return output;
}
},
methods:{
incrementYear: function() {
var self = this;
self.selectedYear++;
self.fetchData();
},
decrementYear: function() {
var self = this;
self.selectedYear--;
self.fetchData();
},
applyDateFilter: function(month) {
this.selectedMonth = String(month).padStart(2, '0');
// Diplays which month is currently being filtered by
var calMonths = document.getElementById('months-headings');
Array.from(calMonths.children).forEach(mon => mon.children[0].style.color = "#707070");
var clickedMonth = calMonths.children[month-1];
clickedMonth.children[0].style.color = "#E95420";
// clickedMonth.classList.add("bg-primary", "text-white");
},
filterByDate: function(month, data) {
var output, self=this;
if (data) {
output = data;
} else {
output = this.info;
}
if (month) {
return output.filter((item)=>{
// Need to change this to selectedYear
return item.date.match(`${self.selectedYear}-${month}`);
})
} else {
return output.filter((item)=>{
// Need to change this to selectedYear
return item.date.match(`${self.selectedYear}`);
})
}
},
setPg: function (p) {
this.page = p
},
mvPg: function (i) {
this.page += i
},
maxPages: function () {
var self = this,
total = self.filteredCompetitions.length;
return Math.max(1, Math.ceil(total / self.showOnPage))
},
pageStartIdx: function () {
var self = this,
maxPages = self.maxPages();
if (self.page > maxPages)
self.page = maxPages;
return (self.page-1) * self.showOnPage + 1;
},
pageEndIdx: function () {
var self = this;
return Math.min(self.pageStartIdx() + self.showOnPage - 1, self.filteredCompetitions.length)
},
paginatedCompetitions: function () {
var self = this,
start = self.pageStartIdx() - 1;
return self.filteredCompetitions.slice(start, start + self.showOnPage)
},
fetchData: function() {
var self = this;
axios
.get(`https://file.opentrack.run/live/euroath/european_calendar_${self.selectedYear}.json`)
.then(response => {
self.info = response.data;
self.country_options = self.info.map(item => item.country
).filter((value, index, list) => list.indexOf(value) === index);
self.isLoading = false;
})
}
},
mounted() {
var self = this;
self.fetchData();
}
})
</script>
</body>
</html>