-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
473 lines (441 loc) · 18.6 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="refresh" content="86400">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<title>Digital Signage</title>
<!-- CSS only -->
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="./styles/bootstrap_icons/bootstrap-icons.css" rel="stylesheet">
<link rel="stylesheet" href="./styles/styles.css">
</head>
<body>
<!-- The video -->
<video autoplay muted loop id="myVideo">
<source src="./assets/starburst.mp4" type="video/mp4">
</video>
<!-- Melhorar aqui! carregar os módulos marcados no painel da adm-->
<!--
<div class="widgetsHolder" class="d-print-none">
<div class="widget calendar"></div>
<div class="widget clock"></div>
<div class="widget weather"><div class="temp"></div><div class="image"></div></div>
<div class="widget currency"></div>
<div class="widget qr-code" style="display:none;"><h5>PEDIDOS DE ASSADOS</h5><img src="./assets/newYearOrdersQR/qr-code.png" alt="qr-code"></div>
</div>
-->
<div class="container-fluid">
<div class="row" style="height: 100vh;">
<div class="col-12 banner d-sm-none d-md-block d-print-none">
<div class="carousel carousel-dark slide" id="productsCarousel" data-bs-ride="carousel">
<div class="carousel-inner"></div>
</div>
</div>
<!-- Melhorar Aqui! Tabela Opcional na ADM-->
<!--
<div class="col priceTable">
<table class="table" id="tableProdList">
<thead>
<tr>
<th class="text-center">#</th>
<th>Produto</th>
<th class="text-center">Preço</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
-->
</div>
</div>
<!-- jQuery -->
<script src="jquery/jquery-3.6.0.min.js"></script>
<!-- Popper Production version -->
<script src="scripts/popper.min.js"></script>
<!-- JavaScript Bundle with Popper -->
<script src="bootstrap/js/bootstrap.js"></script>
<script>
"use strict";
var jsonResponse="", lastResponseLen=false;
var myCarousel = document.getElementById('productsCarousel');
const className = 'table-primary';
var source;
var varUpdateClockTimer;
var currentDate, currentTime;
$(function(e){
// make the carousel
// make the products list
getProdList('butchery');
// make active the first carousel item on the products list
let itemCode = $('div.carousel-item.active').data('item');
$(`tr#${itemCode}`, 'table#tableProdList').addClass( className )
// monitor products price
//start_price_monitor_task();
// update clock
/*
updateClock();
varUpdateClockTimer = setInterval( function(){
updateClock();
}, 1000 );
*/
// get current weather
//getCurrentWeather( true );
// get current currency
//getCurrentCurrency();
// refresh every hour
/*
setTimeout(function(){
getCurrentWeather( true );
//location.reload();
}, 3600000);
*/
/*
let cMonth = new Date().getMonth();
if( cMonth >=10 ){
document.getElementsByClassName('qr-code').style.display = "block";
}
*/
});
myCarousel.addEventListener('slide.bs.carousel', function (e) {
//console.log('e.to: ', e.to );
let itemCode = $('div.carousel-item').eq( e.to ).data('item');
//let itemPrice = Number( $('td.cPrice', `table#tableProdList tbody tr#${itemCode}`).text().replace(/[^0-9.-]/g,'') );
$.each($('div.carousel-item'), function(idx, item){
let thisItemCode = $(item).data('item');
let thisItemPrice = Number( $('td.cPrice', `table#tableProdList tbody tr#${thisItemCode}`).text().replace(/[^0-9.-]/g,'') );
//console.log( 'productsCarousel item: ', thisItemCode );
//console.log( 'productsCarousel price: ', thisItemPrice );
// check the price of this item
$.ajax({
url : 'functions.ajax.php',
method : 'GET',
data : { 'action':'checkProdPrice', 'prodCode':thisItemCode, 'price':thisItemPrice },
dataType : 'json',
beforeSend : function( jqXHR, settings ){},
error : function( jqXHR, textStatus, errorThrown ){
//alert(`Carrousel ${textStatus} ${jqXHR.status}: ${errorThrown}`);
location.reload();
},
success : function( data, textStatus, jqXHR ){
//console.log( 'checkProdPrice data:', data );
if( data.result ){
// update table
thisItemPrice = Number( data.product.price );
var thisItemClass=false;
if( data.product.specialStatus==1 && !isNaN(data.product.specialPrice) && data.product.specialPrice > 0 ){
thisItemPrice = Number( data.product.specialPrice );
thisItemClass=true;
}
// update tableProdList
$('td.cPrice',`table#tableProdList tbody tr#${thisItemCode}`).html( `${Intl.NumberFormat().format(thisItemPrice)}/${data.product.unit}` );
if( thisItemClass ){
$('td.cPrice',`table#tableProdList tbody tr#${thisItemCode}`).addClass( "special" );
$(`div[data-item="${thisItemCode}"]`, `div#productsCarousel`).closest('div.carousel-item').css('background','none');
} else {
$('td.cPrice',`table#tableProdList tbody tr#${thisItemCode}`).removeClass( "special" );
$(`div[data-item="${thisItemCode}"]`, `div#productsCarousel`).closest('div.carousel-item').css('background','#f5f5f5');
}
// update Carousel
$(`div[data-item="${thisItemCode}"] p.price`, `div#productsCarousel`).html( Intl.NumberFormat().format( thisItemPrice ) );
}
},
complete : function( jqXHR, textStatus ){}
});
});
// make the current element focuses in the table
$(`tr`, 'div.priceTable').removeClass( className ); // first remove the class of all elements ...
$(`tr#${itemCode}`, 'table#tableProdList').addClass( className ); // ... and then add the class to the current one
})
function getProdList( listType ){
var ajaxRequestGetProdList = $.ajax({
method : 'GET',
url : 'functions.ajax.php',
data : { 'action':'getProdList', 'listType' : listType },
dataType : 'json',
beforeSend : function( jqXHR, settings ){
//console.log('beforeSend -> settings', settings);
if( ajaxRequestGetProdList ){
//console.log( 'ajaxRequestGetProdList', ajaxRequestGetProdList );
ajaxRequestGetProdList.abort();
}
},
success : function( data, textStatus, jqXHR ){
if( data.result ){
//console.log('data.prodList', data.prodList);
// clear previous content
$('table#tableProdList tbody').html('');
// create the new content
$.each(data.prodList, function(idx,row){
// create the products table
$('<tr/>',{
id:`row_${row.prodCode}`,
class:``,
html:`<td class="text-center">${idx + 1}</td><td>${row.prodNamePTBR}</td><td class="text-center cPrice">${Intl.NumberFormat().format(row.normal_price)}/${row.unit_text}</td>`
}).appendTo('table#tableProdList tbody');
// create the carousel element
$('<div/>',{
'id':``,
'style':'background:#f5f5f5;',
'class':`carousel-item`,
'data-item':`row_${row.prodCode}`,
'html':`<img src="assets/${row.prod_image}" alt="${row.prod_image}" class="d-block h-100 mx-auto">
<div class="carousel-caption d-none d-md-block">
<h1>${row.prodNamePTBR}</h1>
<p class="price ${row.unit_text}">${Intl.NumberFormat().format(row.normal_price)}</p>
</div>`
}).appendTo('div#productsCarousel div.carousel-inner');
});
// activate the first carousel item
$('tr:first-child()', 'table#tableProdList tbody').addClass( className );
$('div.carousel-item:first-child()').addClass('active');
} else {
//console.log( 'data', data );
}
},
error : function( jqXHR, textStatus, errorThrown ){
alert( `getProdList ${textStatus} ${jqXHR.status}: ${errorThrown}` );
console.alert(`text: ${textStatus}`);
console.alert(`error: ${errorThrown}`);
location.reload();
},
complete : function( jqXHR, textStatus ){}
});
}
function populateProductsTables(){
var ajaxRequestPopulateProductsTable = $.ajax({
method : 'POST',
url : 'functions.ajax.php',
data : { 'action' : 'populateProductsTables' },
dataType : 'json',
beforeSend : function( jqXHR, settings ){
if( ajaxRequestPopulateProductsTable ){
// abort previous request if it still running
ajaxRequestPopulateProductsTable.abort();
}
},
success : function( data, textStatus, jqXHR ){
if( data ){
//console.log( 'data', data );
} else {
//console.log( 'there is no data to show');
}
},
error : function( jqXHR, textStatus, errorThrown ){
//console.log(`ERROR ${textStatus}: `, errorThrown)
alert(`populateProductsTables ERROR ${textStatus}: ${errorThrown}`);
location.reload();
},
complete : function( jqXHR, textStatus ){}
});
return;
}
function getBrowserCurrentWindowId(){
var ajaxRequestGetBrowserCurrentWindowId = $.ajax({
method : 'POST',
url : 'functions.ajax.php',
data : {'action':'reload-browser'},
dataType : 'json',
beforeSend : function( jqXHR, settings ){
if( ajaxRequestGetBrowserCurrentWindowId ){
ajaxRequestGetBrowserCurrentWindowId.abort();
}
},
error : function( jqXHR, textStatus, errorThrown ){
alert(`getBrowserCurrentWindowId ERROR ${textStatus}!\n` + errorThrown );
location.reload();
},
success : function( data, textStatus, jqXHR ){
if( data.result ){
//console.log( 'data.output', data.output );
}
},
complete : function( jqXHR, textStatus ){}
});
return false;
}
function start_price_monitor_task(){
source = new EventSource('admin/products.datatable.ajax.php?action=updateDigitalDisplay');
// a message is received
source.addEventListener('message', function(e){
var result = JSON.parse( e.data );
//console.log('EventSource Message', result);
// Do whatever with e.data
if( e.data.search('TERMINATE') != -1 ){
source.close();
}
});
source.addEventListener('error', function(e){
//console.log('Event Source error occured');
source.close();
});
}
function stop_price_monitor_task(){
source.close();
}
function updateClock(){
/*
This function update the clock widget and in defined hours, execute another functions
*/
// get the current date/time
var dateObject = new Date();
currentDate = dateObject.getFullYear()+'-'+( (dateObject.getMonth()+1)<10?'0':'') + (dateObject.getMonth()+1)+'-'+dateObject.getDate();
//console.log( 'currentDate: ', currentDate );
currentTime = dateObject.getHours()+':'+((dateObject.getMinutes()<10)?'0':'')+dateObject.getMinutes()+':'+((dateObject.getSeconds()<10)?'0':'')+dateObject.getSeconds();
//console.log( 'currentTime: ', currentTime );
// update the clock widget
$('div.clock').html(`<div>${dateObject.getHours()}:${((dateObject.getMinutes()<10)?'0':'')+dateObject.getMinutes()}</div>`);
// update the weather/currency widget every hour
if( dateObject.getMinutes()==0 && dateObject.getSeconds()==0 ){
getCurrentWeather( true );
//location.reload();
}
if( dateObject.getHours()==12 && dateObject.getMinutes()==0 && dateObject.getSeconds()==0 ){
getCurrentCurrency( true );
}
// if clock='0:00:00' it's a new day, update the calendar
if( $('div.calendar').html()=='' || currentTime=='0:00:00' ){
let date = dateObject.getDate();
let day = dateObject.getDay(); // 0=Sunday, 1=Monday, etc
let daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let html = `<div class="weekday">${daysOfWeek[day]}</div>
<div class="date">${date}</div>`;
$('div.calendar').html( html );
}
}
function getCurrentWeather( forceNew=false ){
// get openweather url
let url = 'https://api.openweathermap.org/data/2.5/weather';
// get openWeather API id from DB
let apiID = '75cb8a96e644076ef980491088dd2a53';
// get lang
let lang = 'pt_br';
// get units
let temp_unit = '℉'; //℃=℃ ℉=℉
let units = 'metric';
if( units=='metric'){
temp_unit = '℃';
} else {
temp_unit = '℉';
}
// get location from DB
let location = encodeURIComponent('fukuroi,shizuoka,jp');
// try get info from DB if exists...
$.getJSON(`functions.ajax.php?action=getWeather&location=${location}&date=${currentDate}`,function(data,textStatus,jqXHR){
console.log( 'getWeather', data );
/*
if( !forceNew && data.result ){
let main=data.data.weather;
let temp=data.data.temp;
let description=data.data.description;
// update widget
$('div.weather').addClass(`${main}`);
$('div.temp', $('div.weather')).html(`${temp}${temp_unit}<small>${description}</small>`);
} else {*/
// ... if don't, get from Internet
$.getJSON(`${url}?q=${location}&units=${units}&lang=${lang}&appid=${apiID}`, function(data){
//console.log('current weather: ', data);
let currentWeather = data;
// update widget
let temp = Math.round( Number( currentWeather.main.temp ) );
let main = currentWeather.weather[0].main;
let description = currentWeather.weather[0].description;
// update widget
$('div.weather').addClass(`${main}`);
$('div.temp', $('div.weather')).html(`${temp}${temp_unit}<small>${description}</small>`);
console.log('current weather', currentWeather);
// save info to DB
var saveWeatherRequest = $.ajax({
method:'POST',
url:'functions.ajax.php',
data:{ action:'saveWeather', date:currentDate, time:currentTime, location:location, weather:main, description:description, temp:temp, temp_min:currentWeather.main.temp_min, temp_max:currentWeather.main.temp_max },
dataType:'json',
beforeSend:function(jqXHR, settings){
if( saveWeatherRequest ){
saveWeatherRequest.abort();
saveWeatherRequest=false;
}
},
error:function(jqXHR,textStatus,errorThrown){
alert(`getCurrentWeather ${textStatus}: ${errorThrown}`);
location.reload();
},
success:function(data,textStatus,jqXHR){
console.log('saveWeather SUCCESS', data);
},
complete:function(jqXHR,textStatus){}
});
});
/*}*/
});
}
function getCurrentCurrency( forceNew=false ){
// try get current currency from DB if exists ...
var getCurrencyRequest = $.ajax({
method:'GET',
url:'functions.ajax.php',
data:{ action:'getCurrency', date:currentDate },
dataType:'json',
beforeSend: function( jqXHR, settings ){
if( getCurrencyRequest ){
getCurrencyRequest.abort();
getCurrencyRequest=false;
}
},
error: function( jqXHR, textStatus, errorThrown ){
alert( `getCurrentCurrency ${textStatus} ${jqXHR.status}: ${errorThrown}` );
location.reload();
},
success: function( data, textStatus, jqXHR ){
if( data.result && !forceNew ){
// log the success
console.log('getCurrency SUCCESS: ', data.data);
// get base_currency
let base_currency='USD';
// desired currencies array
let target_currencies=['JPY', 'BRL'];
let currentCurrency=data.data;
target_currencies.forEach(function(val, idx){
console.log( val, currentCurrency[val] );
// clear old content
$('div.widget.currency').html('');
// append new content
$('div.widget.currency').append(`<div>${base_currency}1 = ${val} ${currentCurrency[val]}</div>`);
});
} else {
// if don't, get it from internet
console.log('getCurrency FAIL: ', data);
// get apikey
const apikey = 'CoTbZz7wgpk7CakFfb2hhK3dqVlhjbaY';
var myHeaders = new Headers();
myHeaders.append("apikey", "CoTbZz7wgpk7CakFfb2hhK3dqVlhjbaY");
var requestOptions = {
method: 'GET',
redirect: 'follow',
headers: myHeaders
};
fetch("https://api.apilayer.com/currency_data/live?source=USD¤cies=JPY%2C%20BRL", requestOptions)
.then((response) => {
return response.json()
})
.then( (result) => {
const data = result;
console.log('currencies exchange', data);
$('div.widget.currency')
.html('')
.append(`<div>${data.source} 1 = JPY `+Intl.NumberFormat('ja-JP', {maximumFractionDigits:2}).format(data.quotes.USDJPY)+`</div><div>${data.source} 1 = BRL `+Intl.NumberFormat('ja-JP',{maximumFractionDigits:2}).format(data.quotes.USDBRL)+`</div>`);
})
.catch(error => console.log('error', error));
}
},
complete: function( jqXHR, textStatus ){}
});
}
</script>
</body>
</html>