-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
307 lines (249 loc) · 12.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>Shopping List</title>
<!-- mobile styling -->
<meta name="theme-color" content="#448AFF">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#448AFF">
<meta name="apple-mobile-web-app-title" content="Shopping List">
<!-- Material Design icons and fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!-- Material Design styles for Vue.js -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/vue-material.css">
<!-- our styles -->
<link href="shoppinglist.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<!-- PWA manifest -->
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- Vue app -->
<div id="app" class="app-viewport" v-cloak>
<!-- top bar -->
<md-whiteframe md-elevation="3" class="main-toolbar">
<md-toolbar>
<!-- back button -->
<md-button class="md-icon-button" v-if="mode != 'showlist'" v-on:click="onBack">
<md-icon>arrow_back</md-icon>
</md-button>
<!-- page title -->
<h2 class="md-title" style="flex: 1">{{ pagetitle }}</h2>
<!-- save new shopping list button -->
<md-button class="md-icon-button" v-if="mode == 'addlist'" v-on:click="onClickSaveShoppingList" v-bind:disabled="singleList.title.length == 0">
<md-icon>check</md-icon>
</md-button>
<!-- settings -->
<md-button class="md-icon-button" v-if="mode == 'showlist'" v-on:click="onClickSettings">
<md-icon>settings</md-icon>
</md-button>
<!-- about -->
<md-button class="md-icon-button" v-if="mode == 'showlist'" v-on:click="onClickAbout">
<md-icon>info_outline</md-icon>
</md-button>
</md-toolbar>
</md-whiteframe> <!-- top bar -->
<!-- main content -->
<main class="main-content">
<!-- add new shopping list form-->
<md-card v-if="mode == 'addlist'">
<md-card-header>Add Shopping List</md-card-header>
<md-card-content>
<!-- shopping list name -->
<md-input-container>
<label>List name</label>
<md-input placeholder="e.g. Food" v-model="singleList.title"></md-input>
</md-input-container>
<!-- shopping place name -->
<md-input-container>
<label>Place name</label>
<md-input placeholder="e.g. Whole Foods, Reno" v-model="singleList.place.title"></md-input>
<md-button class="md-raised" v-bind:disabled="singleList.place.title.length==0" v-on:click="onClickLookup">Lookup</md-button>
</md-input-container>
<!-- shopping place pull-down list -->
<md-input-container v-if="places.length > 1">
<label for="movie">Choose address</label>
<md-select v-bind="selectedPlace" v-on:change="onChangePlace" v-bind:disabled="places.length == 0">
<md-option v-for="place in places" :key="place.place_id" v-bind:value="place.place_id">{{ place.display_name }}</md-option>
</md-select>
</md-input-container>
<!-- shopping place road -->
<md-input-container v-if="singleList.place.address.road">
<label>Road</label>
<md-input readonly v-model="singleList.place.address.road"></md-input>
</md-input-container >
<!-- shopping place town -->
<md-input-container v-if="singleList.place.address.town">
<label>Town</label>
<md-input readonly v-model="singleList.place.address.town"></md-input>
</md-input-container >
<!-- shopping place city -->
<md-input-container v-if="singleList.place.address.city">
<label>City</label>
<md-input readonly v-model="singleList.place.address.city"></md-input>
</md-input-container >
<!-- shopping place state -->
<md-input-container v-if="singleList.place.address.state">
<label>State</label>
<md-input readonly v-model="singleList.place.address.state"></md-input>
</md-input-container >
<!-- shopping place address -->
<md-input-container v-if="singleList.place.address.postcode">
<label>Postcode</label>
<md-input readonly v-model="singleList.place.address.postcode"></md-input>
</md-input-container >
<!-- shopping place latitude -->
<md-input-container v-if="singleList.place.lat != null">
<label>Latitude</label>
<md-input readonly v-model="singleList.place.lat"></md-input>
</md-input-container>
<!-- shopping place longitude -->
<md-input-container v-if="singleList.place.lon != null">
<label>Longitude</label>
<md-input readonly v-model="singleList.place.lon"></md-input>
</md-input-container>
<!-- shopping place licence -->
<md-input-container v-if="singleList.place.license">
<label>Licence</label>
<md-input readonly v-model="singleList.place.license"></md-input>
</md-input-container>
</md-card-content>
</md-card> <!-- add new shopping list form -->
<!-- shopping list item editor -->
<md-list class="itemedit" v-if="mode == 'itemedit'">
<!-- shopping list item add form -->
<md-list-item>
<!-- shopping item title -->
<md-input-container>
<md-input v-model="newItemTitle" placeholder="New item e.g. eggs" @keyup.enter.native="onAddListItem"></md-input>
</md-input-container>
<!-- shopping item add button -->
<md-button class="md-icon-button md-list-action" v-on:click="onAddListItem" v-bind:disabled="newItemTitle.length == 0">
<md-icon class="md-primary">add_shopping_cart</md-icon>
</md-button>
</md-list-item>
<!-- shopping list items -->
<md-list-item v-for="item in sortedShoppingListItems" :key="item._id" v-if="item.list == currentListId">
<!-- checkbox against each item -->
<div>
<md-checkbox v-model="item.checked" class="md-primary" v-on:change="onCheckListItem(item._id)"></md-checkbox>
</div>
<!-- shopping list item title -->
<div class="md-list-text-container">
<span v-bind:class="{ cardchecked: item.checked}">{{ item.title }}</span>
</div>
<!-- shopping list item delete button -->
<md-button v-on:click="onDeleteItem(item._id)" class="md-icon-button md-list-action">
<md-icon>cancel</md-icon>
</md-button>
<md-divider></md-divider>
</md-list-item>
</md-list> <!-- shopping list item editor -->
<!-- list of shopping lists -->
<md-list v-if="mode == 'showlist'">
<md-card v-for="list in sortedShoppingLists" :key="list._id" :data-id="list._id">
<md-card-header>
<!-- shopping list title -->
<div class="md-title" v-bind:class="{ cardchecked: list.checked}">{{ list.title }}</div>
<!-- shopping place title -->
<div class="md-subhead">{{ list.place.title }}</div>
<!-- 'speed dial' buttons -->
<md-speed-dial md-open="hover" md-direction="left" class="md-fab-top-right">
<!-- more ... button -->
<md-button class="md-fab" md-fab-trigger>
<md-icon md-icon-morph>more_vert</md-icon>
<md-icon>more_horiz</md-icon>
</md-button>
<!-- edit button -->
<md-button class="md-fab md-primary md-mini md-clean" v-on:click="onClickEdit(list._id, list.title)">
<md-icon>edit</md-icon>
</md-button>
<!-- delete button -->
<md-button class="md-fab md-primary md-mini md-clean" v-on:click="onClickDelete(list._id)">
<md-icon>delete</md-icon>
</md-button>
</md-speed-dial>
</md-card-header>
<!-- counts of numbers of items in the list and numbers checked e.g 4/10 -->
<md-card-content v-if="counts[list._id]">
{{ counts[list._id].checked }} / {{ counts[list._id].total }}
</md-card-content>
<md-card-actions>
<!-- button to edit the list items -->
<md-button v-on:click="onClickList(list._id, list.title)">
<md-icon>chevron_right</md-icon>
</md-button>
</md-card-actions>
</md-card>
</md-list> <!-- list of shopping list -->
<!-- settings -->
<md-card v-if="mode == 'settings'">
<md-card-header>Settings</md-card-header>
<md-card-content>
You can sync your shopping lists to a remote Apache CouchDB, IBM Cloudant or PouchDB server. Supply the URL, including
credentials and database name and hit "Start Sync".
<!-- Cloudant URL -->
<md-input-container>
<label>Sync URL</label>
<md-input placeholder="e.g http://localhost:5984/list" type="url" v-model="syncURL"></md-input>
</md-input-container>
<h4>Sync Status</h4>
<!-- visualisation of sync status -->
<md-chip v-if="syncStatus == 'notsyncing'">Not Syncing</md-chip>
<md-chip v-if="syncStatus == 'syncing'" class="md-primary">Syncing</md-chip>
<md-chip v-if="syncStatus == 'syncerror'" class="md-warn">Sync Error</md-chip>
</md-card-content>
<md-card-actions>
<!-- submit button that saves the Cloudant URL -->
<md-button v-on:click="onClickStartSync">
Start Sync
</md-button>
</md-card-actions>
</md-card> <!-- settings -->
<!-- about -->
<md-card v-if="mode == 'about'">
<md-card-header>About</md-card-header>
<md-card-content>
<a href="https://github.com/ibm-watson-data-lab/shopping-list">Shopping List is a series of Offline First demo apps, each built using a different stack.</a> These demo apps cover Progressive Web Apps, hybrid mobile apps, native mobile apps, and desktop apps. This particular demo app is a <b>Progressive Web App</b> built using <b>Vue.js and PouchDB</b>. <a href="https://github.com/ibm-watson-data-lab/shopping-list-vuejs-pouchdb">Get the source code.</a>
</md-card-content>
<md-card-actions>
<!-- No action -->
</md-card-actions>
</md-card> <!-- about -->
<!-- floating 'add shopping list' button -->
<div class="floatingbutton" v-if="mode == 'showlist'">
<md-button class="md-fab md-primary md-raised" v-on:click="onClickAddShoppingList">
<md-icon>add</md-icon>
</md-button>
</div> <!-- floating 'add shopping list' button -->
</main> <!-- main content -->
</div> <!-- app -->
<!-- service worker -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('worker.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
<!-- JavaScript Scripts-->
<!-- cuid - unique id generator -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/cuid/1.3.8/browser-cuid.min.js"></script>
<!-- PouchDB - in-browser database -->
<script src="https://cdn.jsdelivr.net/gh/pouchdb/[email protected]/dist/pouchdb.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/pouchdb/[email protected]/dist/pouchdb.find.min.js"></script>
<!-- Vue.js - framework that handles DOM/Model interaction -->
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<!-- vue-material - Material Design for Vue.js -->
<script src="https://unpkg.com/[email protected]/dist/vue-material.js"></script>
<!-- our code -->
<script src="shoppinglist.js"></script>
</body>
</html>