17
17
< link rel ="stylesheet " href ="https://use.fontawesome.com/releases/v5.7.0/css/all.css " integrity ="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ " crossorigin ="anonymous ">
18
18
< script src ="https://code.jquery.com/jquery-3.5.1.min.js " integrity ="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0= " crossorigin ="anonymous "> </ script >
19
19
< script src ="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js " integrity ="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF " crossorigin ="anonymous "> </ script >
20
-
20
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js "> </ script >
21
+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data.min.js "> </ script >
22
+
21
23
< style type ="text/css ">
22
24
.feed-row { transition : background-color 2s ease; }
23
25
.rgb-cell { transition : color 0.5s ease, background-color 0.5s ease; }
58
60
59
61
$ ( document ) . ready ( function ( ) {
60
62
63
+ var timezones = moment . tz . names ( ) ;
64
+ var select = document . getElementById ( "timezone" ) ;
65
+ var current_tz = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
66
+
67
+ for ( var i = 0 ; i < timezones . length ; i ++ ) {
68
+ var opt = document . createElement ( 'option' ) ;
69
+ opt . value = timezones [ i ] ;
70
+ opt . innerHTML = timezones [ i ] ;
71
+ if ( timezones [ i ] === current_tz ) {
72
+ opt . selected = true ;
73
+ }
74
+ select . appendChild ( opt ) ;
75
+ }
76
+
61
77
// set default inputs
62
78
if ( ! thingspeak [ 'timezone' ] ) { thingspeak [ 'timezone' ] = 'Etc/UTC' ; }
63
79
116
132
thingspeak [ 'channel' ] = $ ( '#channel' ) . val ( ) ;
117
133
thingspeak [ 'read_api_key' ] = $ ( '#read_api_key' ) . val ( ) ;
118
134
thingspeak [ 'results' ] = $ ( '#results' ) . val ( ) ;
119
- thingspeak [ 'timezone' ] = $ ( '#timezone' ) . val ( ) ;
135
+ thingspeak [ 'timezone' ] = $ ( '#timezone' ) . val ( ) || 'Etc/UTC' ;
120
136
121
137
// save to local storage
122
138
localStorage . setItem ( 'thingspeak' , JSON . stringify ( thingspeak ) ) ;
123
139
124
140
// clear output
125
141
$ ( '#header' ) . html ( '' ) ;
142
+ $ ( '#description' ) . html ( '' ) ;
126
143
$ ( '#output' ) . html ( '' ) ;
127
144
128
145
}
183
200
// set headers
184
201
$ ( '#header' ) . html ( data . channel . name + ' <a href="' + thingspeak [ 'api' ] + '" target="_blank"><span class="fas fa-external-link-alt"></span></a>' ) ;
185
202
203
+ // add channel description
204
+ if ( data . channel . description ) {
205
+ $ ( '#description' ) . html ( data . channel . description ) ;
206
+ }
207
+
186
208
// create table head and body if they do not exist
187
209
if ( $ ( '#output' ) . find ( 'thead' ) . length == 0 ) {
188
210
193
215
$ ( '#output' ) . find ( 'thead' ) . append ( "<th>Update Time</th>" ) ;
194
216
195
217
// add header for each field
196
- if ( data . channel . hasOwnProperty ( 'field1' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 1</th>" ) ; }
197
- if ( data . channel . hasOwnProperty ( 'field2' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 2</th>" ) ; }
198
- if ( data . channel . hasOwnProperty ( 'field3' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 3</th>" ) ; }
199
- if ( data . channel . hasOwnProperty ( 'field4' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 4</th>" ) ; }
200
- if ( data . channel . hasOwnProperty ( 'field5' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 5</th>" ) ; }
201
- if ( data . channel . hasOwnProperty ( 'field6' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 6</th>" ) ; }
202
- if ( data . channel . hasOwnProperty ( 'field7' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 7</th>" ) ; }
203
- if ( data . channel . hasOwnProperty ( 'field8' ) ) { $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 8</th>" ) ; }
218
+ if ( data . channel . hasOwnProperty ( 'field1' ) ) {
219
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 1 <br>" + data . channel . field1 + "</th>" ) ;
220
+ }
221
+ if ( data . channel . hasOwnProperty ( 'field2' ) ) {
222
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 2 <br>" + data . channel . field2 + "</th>" ) ;
223
+ }
224
+ if ( data . channel . hasOwnProperty ( 'field3' ) ) {
225
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 3 <br>" + data . channel . field3 + "</th>" ) ;
226
+ }
227
+ if ( data . channel . hasOwnProperty ( 'field4' ) ) {
228
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 4 <br>" + data . channel . field4 + "</th>" ) ;
229
+ }
230
+ if ( data . channel . hasOwnProperty ( 'field5' ) ) {
231
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 5 <br>" + data . channel . field5 + "</th>" ) ;
232
+ }
233
+ if ( data . channel . hasOwnProperty ( 'field6' ) ) {
234
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 6 <br>" + data . channel . field6 + "</th>" ) ;
235
+ }
236
+ if ( data . channel . hasOwnProperty ( 'field7' ) ) {
237
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 7 <br>" + data . channel . field7 + "</th>" ) ;
238
+ }
239
+ if ( data . channel . hasOwnProperty ( 'field8' ) ) {
240
+ $ ( '#output' ) . find ( 'thead' ) . append ( "<th>Field 8 <br>" + data . channel . field8 + "</th>" ) ;
241
+ }
204
242
205
243
// add location fields if included
206
244
if ( thingspeak [ 'location' ] ) {
@@ -729,7 +767,7 @@ <h3 id="channels-header"></h3>
729
767
< div class ="col-lg-6 ">
730
768
< div class ="form-group ">
731
769
< label class ="form-control-label "> Timezone</ label >
732
- < input type =" text " class ="form-control feed-form " id ="timezone ">
770
+ < select class ="form-control feed-form " id ="timezone "> </ select >
733
771
</ div >
734
772
</ div >
735
773
</ div >
@@ -750,8 +788,10 @@ <h3 id="channels-header"></h3>
750
788
</ div >
751
789
</ div >
752
790
753
- < div class ="card-block ">
791
+ < div class ="card-block " style =" padding: 10px; " >
754
792
< h1 id ="header "> </ h1 >
793
+ < p id ="description "> </ p >
794
+ < h3 > Channel Data</ h3 >
755
795
756
796
< table class ="table table-striped " id ="output "> </ table >
757
797
</ div >
0 commit comments