X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=raspberry-kiosk%2Fkiosk.js;fp=raspberry-kiosk%2Fkiosk.js;h=0000000000000000000000000000000000000000;hp=778ed47cff532f25350d5ca55c9c2cd2b4995efe;hb=a34e51d757fe52cb19de2937ae1b211894167524;hpb=c775b5528f8f96e75c28264b9cea8525c6da9298 diff --git a/raspberry-kiosk/kiosk.js b/raspberry-kiosk/kiosk.js deleted file mode 100644 index 778ed47..0000000 --- a/raspberry-kiosk/kiosk.js +++ /dev/null @@ -1,464 +0,0 @@ -function min(a,b) -{ - if (a > b) - return b; - else - return a; -} - -function writeGooglePlusEvents(data, elem) -{ - var ghtml = ""; - //var gplusimgwidth = parseInt($('').css("width")); - var gplusimgwidth = 495; - var minimgwidth=78; - for (var i=0; i< data.items.length; i++) - { - var item = data.items[i]; - var noteobj = item.object; - var attach = noteobj.attachments; - var notetxt = noteobj.content; - var noteimgs = new Array(); - if (attach) - { - for (var a=0; a
"+notetxt; - } - } - } - ghtml += '
' - ghtml += '

'+item.updated.substring(0,16).replace("T"," ")+'

'; - ghtml += '

'+notetxt+'

'; - if (noteimgs.length>0) - { - var bigimglimit; - ghtml += '
'; - if (noteimgs.length > 3) - { - var gplusimgmaxwidth = gplusimgwidth - (minimgwidth * ((noteimgs.length -1) / 3)); - bigimglimit = "max-height:"+(minimgwidth*3)+"px; max-width:"+gplusimgmaxwidth+"px;" - ghtml += ''; - for (var ni=1; ni
'; - } - ghtml += ''; - } - } - else - { - var gplusimgmaxwidth = gplusimgwidth / noteimgs.length; - bigimglimit = "max-width:"+gplusimgmaxwidth+"px;" - for (var ni=0; ni'; - } - } - ghtml += '
'; - } - ghtml += ''; - } - elem.innerHTML=ghtml; -} - - -function loadGooglePlusEvents() -{ - var gpak = "AIzaSyD9xBFM-KWwSYBgZ8VzftJ5wYYvurOxEHg"; - var gplusuri = "https://www.googleapis.com/plus/v1/people/113737596421797426873/activities/public?maxResults=4&key="+gpak; - var gpluscontainer=document.getElementById("gplusevents"); - $.getJSON(gplusuri, function(data){ - writeGooglePlusEvents(data, gpluscontainer); - }); -} - -function weekday2str(dow) -{ - var weekday=new Array(7); - weekday[0]="So"; - weekday[1]="Mo"; - weekday[2]="Di"; - weekday[3]="Mi"; - weekday[4]="Do"; - weekday[5]="Fr"; - weekday[6]="Sa"; - weekday[7]="So"; - if (dow >=0 && dow <=7) - return weekday[dow]; - else - return ""; -} - -function calendarItemEnhancer(data) -{ - for (var s=0; s dt) - { - when = "JETZT"; - } - else - { - var weekday = weekday2str((new Date(dt)).getDay()); - var month = data[s].start.substring(5,7); - if (month[0] == '0') - month = month[1]; - var dayofmonth = data[s].start.substring(8,10); - if (dayofmonth[0] == '0') - dayofmonth = dayofmonth[1]; - if (stime) { - while (stime.substring(stime.length-3,stime.length) == ":00") - { - stime=stime.substring(0,stime.length-3); - } - if (stime.length <= 2) { stime+="h"; } - when = weekday + " " + dayofmonth+"."+month +", "+stime; - } else { - when = weekday + " " + dayofmonth+"."+month; - } - } - data[s].when = when - } - return data -} - -function loadCalendarKiosk() -{ - var calcontainer=document.getElementById("grical_upcoming_kiosk"); - $.getJSON('/shmcache/grical_realraum.json', function(data){ - var calhtml = ""; - $.each(calendarItemEnhancer(data), function(index, itm) { - calhtml += '
  • '+itm.when+' - '+itm.title+'
  • '+"\n"; - }); - calcontainer.innerHTML=''; - }); -} - -function loadCalendarMainPage() -{ - //old URI: //grical.realraum.at/s/?query=!realraum&limit=9&view=json - var calcontainer=document.getElementById("grical_upcoming"); - $.getJSON('/shmcache/grical_realraum.json', function(data){ - var calhtml = ""; - $.each(calendarItemEnhancer(data), function(index, itm) { - calhtml += '
  • '+itm.when+' - '+itm.title+'
  • '+"\n"; - }); - calcontainer.innerHTML=''; - }); -} - -var gauges = {} -function drawGauge(targetelem, label, temp, options) { - // Create and draw the visualization. - if (targetelem) - { - var data = google.visualization.arrayToDataTable([["Label", "Value"],[label,temp]]); - if (!gauges.hasOwnProperty(targetelem.id)) { - gauges[targetelem.id] = new google.visualization.Gauge(targetelem); - } - gauges[targetelem.id].draw(data, options); - } -} - -var linecharts = {} -function drawLineGraph(targetelem, dataarray, options, x_is_epochdate) { - if (dataarray && targetelem) { - var data; - if (x_is_epochdate) { - data=new google.visualization.DataTable(); - data.addColumn('datetime',dataarray[0][0]); - for (var c=1; c= sisize[i][0]) { siid=sisize[i][1]; num=num/sisize[i][0]; break;} - - } - return (Math.round(num*10)/10)+siid+unit; -} - -function writeAnwesenheitStatus(data) -{ - var html=""; - var sensorshtml=""; - var sensorstd=""; - if (data.open) - { - iconuri=data.icon.open; - statuscolor="lime"; - } - else - { - iconuri=data.icon.closed; - statuscolor="red"; - } - var anwesenheit_status_kiosk = document.getElementById('anwesenheit_status_kiosk'); - var anwesenheit_status_frontpage = document.getElementById('anwesenheit_status'); - var statusage = parseInt((new Date()).getTime()/1000) - data.lastchange; - var statusagestatus = ""; - if (statusage > 600) - { - //var statusagestatus = 'Status older than ' + siNumberString(statusage,"s") + ''; - var statusagestatus = '
    Status older than ' + siNumberString(statusage,"s") + '
    '; - } - if (anwesenheit_status_kiosk) - { - anwesenheit_status_kiosk.innerHTML='
    '+data.status+'
    '; - } - if (anwesenheit_status_frontpage) - { - //anwesenheit_status_frontpage.innerHTML=''+statusagestatus+'
    '+data.status+'
    '; - anwesenheit_status_frontpage.innerHTML='
    '+data.status+statusagestatus+'
    '; - } - - if (data.sensors) - { - if (data.sensors.temperature) - { - sensorstd+='Temperatur'; - $.each( data.sensors.temperature, function(s, sensorobj) { - sensorstd+='
    '+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit; - drawGauge(document.getElementById('tempgauge'), "Temp "+sensorobj.location, sensorobj.value, {redFrom: 33, redTo: 40, yellowFrom:29, yellowTo: 33, minorTicks: 4, min:0, max:40}); - }); - sensorstd+=''; - } - if (data.sensors.ext_illumination) - { - sensorstd+='Licht'; - $.each( data.sensors.ext_illumination, function(s, sensorobj) { - sensorstd+='
    '+sensorobj.location+': '+sensorobj.value; - drawGauge(document.getElementById('lightgauge'), "Licht "+sensorobj.location, sensorobj.value, {redFrom: 950, redTo: 1024,yellowFrom:0, yellowTo: 200,minorTicks: 4, min:0, max:1024}); - }); - sensorstd+=''; - } - if (data.sensors.door_locked) - { - sensorstd+='Eingangstür'; - $.each( data.sensors.door_locked, function(s, sensorobj) { - var lockstatus="Auf"; - if (sensorobj.value) { lockstatus = "Zu"; } - sensorstd+='
    '+sensorobj.location+': '+lockstatus; - }); - sensorstd+=''; - } - if (data.sensors.ext_door_ajar) - { - sensorstd+='Türkontakt'; - $.each( data.sensors.ext_door_ajar, function(s, sensorobj) { - var lockstatus="Auf"; - if (sensorobj.value) { lockstatus = "Zu"; } - sensorstd+='
    '+sensorobj.location+': '+lockstatus; - }); - sensorstd+=''; - } - if (data.sensors.ext_dust) - { - sensorstd+='Staub'; - $.each( data.sensors.ext_dust, function(s, sensorobj) { - sensorstd+='
    '+sensorobj.location+': '+sensorobj.value+sensorobj.unit+''; - }); - sensorstd+=''; - - } - if (sensorstd != "") - { - sensorshtml=''+sensorstd+'
    '; - document.getElementById('sensor_status').innerHTML=sensorshtml; - } - } -} - -function updateAnwesenheitStatus() -{ - //var req = new XMLHttpRequest(); - url = "/status.json"; - //req.open("GET", url ,false); - //google chrome workaround - //req.setRequestHeader("googlechromefix",""); - //req.send(null); - var jqxhr = $.getJSON(url, writeAnwesenheitStatus); -} - -function updateDateClock(now) -{ - var daynames = new Array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'); - var datetimestr = daynames[now.getDay()]; - datetimestr += ' ' + now.getDate(); - datetimestr += '.' + (now.getMonth() + 1); - datetimestr += '.' + now.getFullYear(); - datetimestr += (now.getHours() > 9 ? ' ' : ' 0') + now.getHours(); - datetimestr += (now.getMinutes() > 9 ? ':' : ':0') + now.getMinutes(); - datetimestr += (now.getSeconds() > 9 ? ':' : ':0') + now.getSeconds(); - $('#dateclock').html(datetimestr); -} - -function highlightEntry(idx, color, value) -{ - if(value == 0) { - if(idx%2 == 0) - $('#upnext' + idx).css('background-color', 'white'); - else - $('#upnext' + idx).css('background-color', '#E0E0E0'); - } else { - $('#upnext' + idx).css('background-color', color); - } -} - -var seconds = 0; -function clock(now) -{ - var now = new Date(new Date().valueOf() + 300); - updateDateClock(now); - seconds++; - if(seconds >= 20) { - seconds = 0; - } -} - -function showError(XMLHttpRequest, textStatus, errorThrown) -{ - alert("Error: " + textStatus); -} - -function updateSensors() -{ - reloadImg(document.getElementById("tempsensor")); - reloadImg(document.getElementById("movementsensor")); - reloadImg(document.getElementById("lightsensor")); -} - -function IsImageOk(img) { - if (!img.complete) - { - return false; - } - if (typeof img.naturalWidth == "undefined" || (typeof img.naturalWidth == "number" && img.naturalWidth == 0)) - { - return false; - } - return true; -} - -var img_orig_src = {}; -function reloadImgAlt(element) -{ - if(element.complete) - { - var new_image = new Image(); - //set up the new image - new_image.id = element.id; - new_image.className = element.className; - if (! img_orig_src[element.id]) - { - img_orig_src[element.id] = element.src; - } - new_image.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString(); - if (IsImageOk(new_image)) - { - element.parentNode.insertBefore(new_image,element); - element.parentNode.removeChild(element); - } - } -} -function reloadImg(element) -{ - if (! img_orig_src[element.id]) - { - img_orig_src[element.id] = element.src; - } - element.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString(); -} - -$(document).ready(function() -{ - updateAnwesenheitStatus(); - setInterval("updateAnwesenheitStatus()", 10*1000); - if (document.getElementById("dateclock")) - { - updateDateClock(new Date()); - setInterval("clock()", 500); - } - if (document.getElementById("grical_upcoming_kiosk")) - { - loadCalendarKiosk(); - setInterval("loadCalendarKiosk()", 123*1000); - } - if (document.getElementById("grical_upcoming")) - { - loadCalendarMainPage(); - setInterval("loadCalendarMainPage()", 123*1000); - } -// if (document.getElementById("sensorgraphs")) -// { -// setInterval("updateSensors()",145*1000); -// } - if (document.getElementById("tempgooglegraph") || document.getElementById("lightgooglegraph") || document.getElementById("movementgooglegraph")) - { - loadAndDrawSensorData(); - setInterval("loadAndDrawSensorData()",145*1000); - } - if (document.getElementById("gplusevents")) - { - loadGooglePlusEvents(); - setInterval("loadGooglePlusEvents()", 1207*1000); - } -});