-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
70 lines (67 loc) · 2.02 KB
/
app.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
Vue.component('goal', {
props: ['goal'],
template:
'<div class="goal-item bookmark-section bookmark-section-background">\n' +
'<h3 class="goal-item-label">{{ goal.title }}</h3>\n' +
'<h3 class="goal-item-value">{{ goal.value }}</h3>\n' +
'</div>'
});
Vue.component('bookmark', {
props: ['page'],
template: '' +
'<div class="bookmark-item">\n' +
' <h4>Page</h4>\n' +
' <h3>{{ page }}</h3>\n' +
'</div>'
})
const app = new Vue({
el: '#app-core',
data: {
goals: {
daily: {
title: "Daily goal",
value: 0
},
total: {
title: "Total",
value: 0
}
},
bookmarks: [],
begin: 0,
end: 1,
duration: 7
},
methods: {
calculateBookmarks: function() {
if ( this.begin === this.end ){
window.alert("Begin cannot be equal to end");
}
else if ( this.begin > this.end ){
window.alert("End cannot be less than begin");
}
else {
const total = this.end - this.begin;
const daily = Math.floor( total / this.duration );
let index = 0;
if ( daily === 0 ){
window.alert("Total cannot be 0");
} else {
this.bookmarks = [];
for ( let page = this.begin + daily ; page <= (this.end - daily) ; page += daily ){
this.bookmarks.push({
id: index++,
page: page
});
}
this.bookmarks.push({
id: index,
page: this.end
})
this.goals.daily.value = daily;
this.goals.total.value = total;
}
}
}
}
});