-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
executable file
·214 lines (188 loc) · 4.96 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Firefighter App Offline</title>
<style>
html,
body {
margin: 0;
padding: 0;
font-family: 'Assistant', sans-serif;
background: #222;
color: white;
}
.button-area {
display: flex;
justify-content: center;
align-items: center;
align-items: stretch;
flex-direction: row;
margin-top: 50px;
}
button {
height: 100px;
display: inline-block;
border-radius: 20px;
background: red;
margin: 5px;
width: 11%;
cursor: pointer;
font-size: 16px;
text-transform: uppercase;
border: none;
letter-spacing: 0.03em;
box-shadow: inset 0 0 0 1px hsla(0, 0%, 0%, .1),
inset 0 -.3em 0 hsla(0, 0%, 0%, .25),
0 .3em .3em hsla(0, 0%, 0%, .05);
font-weight: bold;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.3);
transition: 0.2s all ease;
transform: translate3d(0, 0, 0);
}
button:focus {
outline: 1px dashed #666;
border-radius: 20px;
}
button:active {
box-shadow: inset 0 0 0 1px hsla(0, 0%, 0%, .2),
inset 0 2px 0 hsla(0, 0%, 100%, .1),
inset 0 .25em .5em hsla(0, 0%, 0%, .05);
transform: translate3d(0, 5px, 0);
padding-bottom: .5em;
}
.green,
.enroute,
.status {
background: #19a974;
}
.blue,
.water {
background: #659ce4;
}
.yellow,
.clear {
background: #ffde37;
}
.purple,
.details {
background: #a463f2;
}
.orange {
background: #ff6300;
}
.red,
.scene {
background: #fb2a34;
}
.dark-red,
.backup {
background: #e7040f;
}
.light-blue,
.available {
background: #96ccff;
}
.status {
padding: 2px 10px;
text-align: center;
}
.status p {
margin: 7px 0;
}
.info {
margin: 50px auto 0;
width: 60%;
padding: 10px;
border: 1px solid #555;
background: #111;
}
.info p {
padding: 12px;
margin: 0;
border-bottom: 1px solid #333;
color: #ccc;
letter-spacing: 0.03em;
}
.info p span {
color: white;
text-transform: uppercase;
}
.info p:last-child {
border-bottom: 0;
}
</style>
<link href="https://fonts.googleapis.com/css?family=Assistant:400,700" rel="stylesheet">
</head>
<body>
<div id="app">
<div :class="[{ red: offline }]" class="status">
<p>{{ status }}</p>
</div>
<div class="button-area">
<button @click="requestButton(type)" v-for="type in typesOfRequest" :class="type">
{{ type }}
</button>
</div>
<div v-if="responseSuccess" class="info">
<p v-for="item in messageQueue" v-html="item"></p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
status: '',
offline: false,
responseSuccess: false,
messageQueue: [],
typesOfRequest: ['enroute', 'on scene', 'water', 'backup', 'clear returning', 'get details', 'available']
},
methods: {
isOnline() {
if (navigator.onLine) {
this.status = `Online. Clear to send.`
this.offline = false
}
else {
this.status = `Offline. But don't worry, your requests will still be processed soon as you are connected.`
this.offline = true
}
},
updateRequest(response, type) {
if (response === 200) {
this.responseSuccess = true
this.messageQueue.push(`You successfully sent a message: <span>${type}</span>`)
}
},
requestButton(type) {
var vueThis = this
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js').then((registration) => {
return navigator.serviceWorker.ready;
}).then((registration) => {
registration.sync.register(`request-${type}`).then(() => {
console.log('%c sync registered', 'font-size: 16px; background: #e27403; color: #ffffff; border-radius: 5px; padding: 5px 25px 5px 10px; line-height: 30px;');
}).catch(function (error) {
console.log('Unable to fetch resources.');
});
}).catch(function (error) {
console.log('Unable to register Service Worker.');
});
}
else {
console.log('Service Worker functionality not supported.');
}
}
}
})
window.addEventListener('online', vm.isOnline);
window.addEventListener('offline', vm.isOnline);
vm.isOnline();
navigator.serviceWorker.addEventListener('message', function handler(event) {
vm.updateRequest(event.data.response, event.data.resource)
});
</script>
</body>
</html>