-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
280 lines (228 loc) · 8.46 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="mycuttie.webmanifest">
<link rel="icon" href="favicon.ico">
<link rel="icon" type="image/png" sizes="512x512" href="images/mycuttie-512.png">
<link rel="icon" type="image/png" sizes="256x256" href="images/mycuttie-256.png">
<link rel="icon" type="image/png" sizes="192x192" href="images/mycuttie-192.png">
<link rel="icon" type="image/png" sizes="128x128" href="images/mycuttie-128.png">
<link rel="icon" type="image/png" sizes="64x64" href="images/mycuttie-64.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/mycuttie-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/mycuttie-16.png">
<link rel="apple-touch-icon" sizes="128x128" href="images/mycuttie-128.png">
<link rel="stylesheet" href="3rdparty/css/w3.css">
<link rel="stylesheet" href="css/w3-theme-mycuttie.css">
<link rel="stylesheet" href="css/icons.css">
<link rel="stylesheet" href="css/slider.css">
<script src="upup.min.js"></script>
<script>
if (UpUp) {
UpUp.start({
'cache-version': 'v6',
'content-url': 'index.html',
'assets': [
'3rdparty/css/w3.css',
'css/slider.css',
'3rdparty/js/paho-mqtt-1.1.0.js',
"3rdparty/js/vue.js",
"3rdparty/js/vue-router.js",
"js/mc-basic.js",
"js/mc-mqtt.js",
"js/mc-vue.js",
"js/mc-config.js"
]
});
}
</script>
<script src="3rdparty/js/paho-mqtt-1.1.0.js" type="text/javascript"></script>
<script src="3rdparty/js/vue.js"></script>
<script src="3rdparty/js/vue-router.js"></script>
<script src="js/mc-basic.js"></script>
<script src="js/mc-mqtt.js"></script>
<script src="js/mc-vue.js"></script>
<script src="js/mc-config.js"></script>
<title>mycuttie</title>
<style> /* https://www.w3schools.com/howto/howto_css_switch.asp */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<div id="app">
<!-- Welcome page -->
<div class="w3-modal" style="display:block" v-show="first_visit">
<div class="w3-modal-content w3-card-4">
<header class="w3-container w3-theme-d2">
<span v-on:click="first_visit=false"
class="w3-button w3-display-topright">×</span>
<h2>Welcome to mycuttie</h2>
</header>
<div class="w3-container w3-theme-l4">
No MQTT server is configured.<br>
<br>
To see a demonstration, an MQTT demo server can be set on configuration page, which can be accessed by clicking the connection symbol (<span class="icon-state-disconnected"></span>) in the upper right corner.<br>
On that page just click '<i>Set test server</i>' to set the required parameters and afterwards '<i>Connect to server</i>'. A successfull connection is indicated in the upper right corner (<span class="icon-state-connected"></span>).<br>
<br>
Page definitions can also be configured on that page. For an example just click '<i>Set example page definition</i>'.<br>
<br>
For additional information head over the <a href="https://github.com/avanc/mycuttie">mycuttie project page</a>.
</div>
</div>
</div>
<!-- Connection indicator -->
<span class="w3-display-topright">
<router-link to="/config" style="text-decoration: none;">
<span v-show="mqtt_state.connected" class="icon-state-connected w3-xxlarge"></span>
<span v-show="!(mqtt_state.connected)" class="icon-state-disconnected w3-xxlarge"></span>
</router-link>
</span>
<!-- Navigation bar for large screens -->
<div class="w3-bar w3-theme-d2 w3-hide-small" style="min-height:2em">
<router-link class="w3-bar-item w3-button w3-hover-theme" v-for="link in link_list" :to="link.path" :key="link.path" active-class="w3-theme">{{ link.name }}</router-link>
</div>
<!-- Navigation bar for small screens -->
<div class="w3-row w3-theme w3-hide-medium w3-hide-large">
<a class="w3-col w3-button" style="width:50px" v-on:click="showMenu = !showMenu">☰</a>
<div class="w3-rest w3-red">
<div class="w3-bar-block w3-theme-d2">
<router-link class="w3-bar-item w3-button w3-hover-theme" v-bind:class="{ 'w3-show' : showMenu }" v-for="link in link_list" :to="link.path" :key="link.path" active-class="w3-theme w3-show">{{ link.name }}</router-link>
</div>
</div>
</div>
<router-view></router-view>
<div class="w3-container w3-center w3-theme-d2 w3-small"><a href="https://github.com/avanc/mycuttie">mycuttie</a>: 100% pure Open Source</div>
</div>
<script>
console.log(mc.config);
if (mc.config.hasOwnProperty("mqtt")) {
mc.mqtt.connect();
}
var routes = [
{ path: '/config', component: mc.vue.config, name: "Config", props: {pages: mc.config.pages} },
];
for (var i=0; i<mc.config.pages.length; i++) {
var route= {};
route["path"]='/' + mc.config.pages[i].shortname;
route["name"]=mc.config.pages[i].name;
route["component"]=mc.vue.page;
route["props"]={data: mc.config.pages[i], mqtt_state: mc.mqtt.state};
routes.push(route);
}
const router = new VueRouter({
routes: routes
})
var app = new Vue({
el: '#app',
data: {
mqtt_state: mc.mqtt.state,
pages: mc.config.pages,
config: mc.config,
first_visit: !(mc.mqtt.validateConfig()),
showMenu: true
},
computed: {
link_list: function () {
var list=[];
for (var i=0; i<this.pages.length; i++) {
list.push({name: this.pages[i].name, path: this.pages[i].shortname, rank: (typeof (this.pages[i].rank) == "undefined" ? 0 : this.pages[i].rank) });
}
list.sort(function(a, b){return b.rank - a.rank});
return list;
}
},
router: router
});
// Remove outdated pages and mark others as old
for( var i = mc.config.pages.length-1; i>=0; i--){
if ( mc.config.pages[i].outdated == true ) {
mc.config.pages.splice(i, 1);
} else {
mc.config.pages[i].outdated=true;
}
}
mc.mqtt.subscribe(mc.config.mqtt.topic, function(rec_data){
var validPage=mc.validatePage(rec_data.payload);
var found=false;
rec_data.payload.source=rec_data.topic;
rec_data.payload.outdated=false;
for (var i=0; i<mc.config.pages.length; i++) {
if (rec_data.topic == mc.config.pages[i].source) {
console.log("Page updated");
found=true;
if (validPage) {
mc.config.pages[i]=rec_data.payload;
} else {
mc.config.pages.splice(i,1);
}
}
}
if (!found) {
console.log("New page");
if (validPage) {
mc.config.pages.push(rec_data.payload);
var route= {};
route["path"]='/' + rec_data.payload.shortname;
route["name"]=rec_data.payload.name;
route["component"]=mc.vue.page;
route["props"]={data: rec_data.payload, mqtt_state: mc.mqtt.state}
app.$router.addRoutes([route])
}
}
mc.saveConfig();
});
</script>
</body>
</html>