-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-script.js
142 lines (121 loc) · 5.86 KB
/
main-script.js
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
'use strict'
const form = document.querySelector('.form');
// const done = document.querySelector('done')
// const cancel = document.querySelector('cancel')
const distanceInput = document.querySelector('.distance');
const durationInput = document.querySelector('.duration');
const elevationInput = document.getElementById('cycling-elevevation--levels')
const unitMeasure = document.querySelector('.unit-measure');
const btnOptions = document.querySelector('.btn-options') // sort order
const placeholder = document.querySelector('.placeholder');
const strengtInput = document.getElementById('level')
const dotsIcon = document.querySelector('.dots-icon');
const okayInput = document.getElementById('done')
const cancelForm = document.getElementById('cancel')
const info = document.querySelector('.info')
const body = document.querySelector('.body')
const workoutInputType = document.querySelector('.select');
const typeWorkout = document.getElementById('type')
const dashboard = document.querySelector('.bar');
const btn = document.querySelector('.close-dashboard');
const features = document.querySelector('.features');
const options = document.querySelector('.options');
const map = document.getElementById('map')
const themes = document.querySelector('.opt-ft');
const formBG = document.querySelector('.bg-color');
const infoText = document.querySelector('.info-text')
// sort order of list info
body.innerHTML = '';
let count = 0;
// CODE STRUCTURE
class Workout{
#date = new Date(); // date of workout
#id = (Date.now() + '').slice(-10); // unique id for each workout
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
timeStr = `${this.#date.getDate()}${this.#date.getMonth()}${this.#date.getHours()}${this.#date.getMinutes()}${this.#date.getSeconds()}`
constructor(currentPosition, destination, level, duration, distance){
this.currentPosition = currentPosition; // [lat, lng]
this.destination = destination; // [lat, lng]
this.distance = distance; // km
this.level = level; // string
this.duration = duration; // minutes
}
_descriptionMethod(){
this.description = `${this.type[0].toUpperCase() + this.type.slice(1)} on ${this.months[this.#date.getMonth()]} ${this.#date.getDate()}`
const html = `
<div class='info ${this.type}-stripe' id='${this.#id}' data-date='${this.#date}' data-distance='${this.distance}' data-location='${this.destination}' data-duration='${this.duration}'>
<div class="info-text">
<span>${this.description}</span>
<div class="features">
<span class="btn-options"><ion-icon name="ellipsis-horizontal-outline" class ='dots-icon' title="my icon"></ion-icon></span>
<ul class="options">
<li class="edit">Edit</li>
<li class="theme"><select name="theme" class="opt-ft">
<option value="theme">Select theme</option>
<option value="light-mode" class="light">Light theme</option>
<option value="dark-mode" class="dark">Dark theme</option>
</select></li>
<li class="delete">Delete</li>
<li class="delete-all">Delete all</li>
<li><select name="sort" class="sort opt-ft">
<option value="sort">Sort by</option>
<option value="by-distance" class="sort-by--distance">distance</option>
<option value="by-location" class="sort-by--location">location</option>
<option value="by-duration" class="sort-by--duration">duration</option>
<option value="by-date-modified" class="sort-by--date-modified">date modified</option>
</select></li>
<li class="view-all">View all workouts</li>
</ul>
</div>
</div>
<div class="info-data">
<span class="distance">${this.avatar} ${this.distance.toFixed(1)}km</span>
<span class="duration">⌚ ${this.duration.toFixed(1)}mins</span>
<span class="cadence">⚡ ${this.type === 'running'? this.cadence.length > 1 ? `${this.cadence[0]} - ${this.cadence[1]}` + 'steps/min' : this.cadence[0] + 'steps/min' :
this.elevation + 'gain'}</span>
<span class="energy">${this.#date.getHours()} : ${`${this.#date.getMinutes()}`.padStart(2, 0)} : ${`${this.#date.getSeconds()}`.padStart(2, 0)}</span>
</div>
<div class="overflow">
<span class="workout-count">${++count}</span>
</div>
</div>
`;
this.workoutInfo = html;
body.insertAdjacentHTML('afterbegin', html)
this.dateMonth = [`${this.#date.getDate()}${this.#date.getMonth()}${this.#date.getHours()}${this.#date.getMinutes()}${this.#date.getSeconds()}`.toString()]
}
getId(){
return this.#id
}
_getDate(){
return this.#date
}
}
class Running extends Workout{
type = 'running';
constructor(currentPosition, destination, level, duration, distance, cadence){
super(currentPosition, destination, level, duration, distance);
this.cadence = cadence;
this.avatar = '🏃♂️';
this._pace();
this._descriptionMethod()
}
_pace(){
this.pace = this.duration / this.distance;
return this.pace;
}
}
class Cycling extends Workout{
type = 'cycling';
constructor(currentPosition, destination, level, duration, distance, elvation){
super(currentPosition, destination, level, duration, distance);
this.elevation = elvation;
this.avatar = '🚴♀️';
this._speed()
this._descriptionMethod()
}
_speed(){
this.speed = this.distance / (this.duration / 60);
return this.speed;
}
}