-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.htm
215 lines (191 loc) · 6.69 KB
/
index.htm
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>KeySpot</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@4.0.0/dist/yeti/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.5.2/animate.min.css">
</head>
<body>
<nav class="navbar navbar-dark bg-primary">
<div class="container">
<strong class="navbar-brand">
<i class="fa fa-key fa-lg fa-rotate-270 text-warning"></i>Spot
</strong>
</div>
</nav>
<main id="KeySpotApp" class="container">
<spot-form v-on:add="add"></spot-form>
<div class="card mt-4">
<div class="card-header">
<h3 class="m-0">
<button type="button" class="close" data-toggle="modal" data-target="#SpotForm">+</button>
<div class="dropdown">
<button type="button" class="close pull-left mt-1 mr-2" type="button" id="SortMenu" data-toggle="dropdown">
<small>
<i class="fa fa-sort fa-fw" v-if="!isSorting"></i>
<i class="fa fa-sort fa-spin fa-fw" v-else></i>
</small>
</button>
<div class="dropdown-menu" aria-labelledby="SortMenu">
<button type="button" class="dropdown-item" v-on:click="sortDefault">
<i class="fa fa-sort-amount-asc fa-fw"></i> Default
</button>
<button type="button" class="dropdown-item" v-on:click="sortName">
<i class="fa fa-sort-alpha-asc fa-fw"></i> Name
</button>
<button type="button" class="dropdown-item" v-on:click="sortPasscode">
<i class="fa fa-sort-numeric-asc fa-fw"></i> Passcode
</button>
<button type="button" class="dropdown-item" v-on:click="sortDistance" v-show="'geolocation' in navigator">
<i class="fa fa-location-arrow fa-fw"></i> Distance
</button>
</div>
</div>
My spots
</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col" v-if="!spots.length">
<div class="alert alert-warning">
<span class="mr-2">Add a spot to begin.</span>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#SpotForm">+</button>
</div>
</div>
<div class="col-12 col-md-6 col-lg-4 mb-4" v-for="spot in spots">
<spot-card
v-bind:spot="spot"
v-bind:key="spot._id"
v-on:remove="remove">
</spot-card>
</div>
</div>
</div>
</div>
</main>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@1.0.22/webcomponents-lite.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vee-validate@2.0.4/dist/vee-validate.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/pouchdb@6.4.1/dist/pouchdb.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/rDuckDev/CoreJS@0.1.0-alpha/core.js"></script>
<script type="text/javascript">
(function () {
"use strict";
var DOM = {},
App = {},
Bundle = {},
Components = [];
Components.push("./component/form.htm");
Components.push("./component/card.htm");
var spotDB = new PouchDB("SpotDB");
function deg2rad (deg) {
return deg * (Math.PI/180);
}
function getDistance (lat1, lon1, lat2, lon2) {
// https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
function sortDefault () {
this. isSorting = true;
this.spots = _.sortBy(this.spots, [ "_id" ]);
this.isSorting = false;
}
function sortName () {
this.isSorting = true;
this.spots = _.sortBy(this.spots, [ "uName" ]);
this.isSorting = false;
}
function sortDistance () {
var self = this;
self.isSorting = true;
navigator.geolocation.getCurrentPosition(function (position) {
self.spots = _.sortBy(self.spots, [ function (spot) {
return getDistance(
position.coords.latitude,
position.coords.longitude,
spot.uLatitude,
spot.uLongitude
);
}, "uName" ]);
self.isSorting = false;
});
}
function sortPasscode () {
this.isSorting = true;
this.spots = _.sortBy(this.spots, [ "uCode", "uName" ]);
this.isSorting = false;
}
function loadData () {
var self = this;
spotDB.allDocs({ include_docs: true })
.then(function (results) {
_.forEach(results.rows, function (row) {
var rec = _.cloneDeep(row.doc);
delete rec._rev;
self.spots.push(rec);
});
});
}
function add (spot) {
var rec = {
_id: _.now().toString(),
uName: spot.uName,
uLatitude: spot.uLatitude,
uLongitude: spot.uLongitude,
uLink: spot.uLink,
uCode: spot.uCode
};
spotDB.put(rec);
this.spots.push(rec);
}
function remove (id) {
var index = _.findIndex(this.spots, [ "_id", id ]);
spotDB.get(this.spots[index]._id)
.then(function (rec) {
return spotDB.remove(rec);
});
this.spots.splice(index, 1);
}
function buildApp () {
new Vue({
el: "#KeySpotApp",
data: {
spots: [],
isSorting: false
},
methods: {
add: add,
remove: remove,
loadData: loadData,
sortDefault: sortDefault,
sortName: sortName,
sortDistance: sortDistance,
sortPasscode: sortPasscode
},
beforeMount: function () { this.loadData() }
});
}
jQuery(document).ready(function () {
Vue.use(VeeValidate);
CORE.loadComponents(Components, buildApp);
});
} ());
</script>
</body>
</html>