Commit 213cd4b6 authored by JackV's avatar JackV

Merge branch 'master' into python3

parents 892c6595 1688d49d
module("browser_handler", function (require, exports) { module("browser_handler", function (require, exports) {
"use strict"; "use strict";
var doc = require("document"), var doc = require("document"),
debug = require("debug"), debug = require("debug"),
query = require("peppy").query, query = require("peppy").query,
Raphael = require("Raphael"), Raphael = require("Raphael"),
moment = require("moment"),
sede,
sedeValue, sede,
sedeTimestamp, sedeValue,
sedeModifiedBy, sedeTimestamp,
temp, sedeModifiedBy,
tempValue, temp,
tempTrend, tempValue,
msg, tempTrend,
msgTimestamp, msg,
msgUser, msgTimestamp,
msgValue, msgUser,
head, msgValue,
title, head,
favicon, title,
trend, favicon,
tempGraph, trend,
lastTimestamp, tempGraph,
tempGraphValuesY = [], lastTimestamp,
tempGraphTimestampValues = [], tempGraphValuesY = [],
tempGraphHeight = 380, tempGraphTimestampValues = [],
tempGraphWidth = 380; tempGraphHeight = 380,
tempGraphWidth = 380;
/* HELPERS */
/* HELPERS */
function seq(x, y) {
var container = []; function seq(x, y) {
var container = [];
if (x < y) {
while (x < y) { if (x < y) {
container[container.length] = x; while (x < y) {
x++; container[container.length] = x;
} x++;
} else { }
while (x < y) { } else {
container[container.length] = x; while (x < y) {
x--; container[container.length] = x;
x--;
}
} }
return container;
} }
return container; // Show a DOM hidden element
} function show(elem) {
debug.log("Showing", elem.id);
$(elem).fadeIn();
}
// Show a DOM hidden element function hide(elem) {
function show(elem) { debug.log("Hiding", elem.id);
debug.log("Showing", elem.id); $(elem).fadeOut();
elem.setAttribute("style", "display: block"); }
}
// Return a new string capitalized // Return a new string capitalized
function capitalize(string) { function capitalize(string) {
debug.log("Capitilizing string", string); debug.log("Capitilizing string", string);
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1);
} }
// Change the favicon icon of the site. // Change the favicon icon of the site.
function changeIcon(status) { function changeIcon(status) {
debug.log("Changing favicon", status); debug.log("Changing favicon", status);
var link = doc.createElement("link"); var link = doc.createElement("link");
head.removeChild(favicon); head.removeChild(favicon);
link.href = "static/" + status + ".ico"; link.href = "static/" + status + ".ico";
link.rel = "shortcut icon"; link.rel = "shortcut icon";
head.appendChild(link); head.appendChild(link);
favicon = link; favicon = link;
} }
// the Trend object contains an old state off the value defined function changeFAB(status) {
// - newValue debug.log("Changing floating action button", status);
// add a new state to the _oldValue_ state and
// assign the difference between the new state and the
// old value to the _diff_ state.
//
// - toString
// Respond to the toString message, transorm the object in an intelligible form.
// In this case the trend arcs.
function Trend() {
debug.log("New Trend Object instanziated");
this.oldValue = undefined;
this.diff = 0;
}
Trend.prototype.newValue = function (value) { $("#hq-status-fab button")
if (this.oldValue !== undefined) { .removeClass("btn-gialla")
this.diff = value - this.oldValue; .removeClass("btn-open")
debug.log("The difference between the current temp and the old temp is", this.diff); .removeClass("btn-closed")
.addClass("btn-" + status);
} }
debug.log("The value of the oldTemp is now", value);
this.oldValue = value; // the Trend object contains an old state off the value defined
// - newValue
return this; // add a new state to the _oldValue_ state and
}; // assign the difference between the new state and the
// old value to the _diff_ state.
Trend.prototype.toString = function () { //
if (this.diff === 0) { // - toString
return ""; // Respond to the toString message, transorm the object in an intelligible form.
} else if (this.diff > 0) { // In this case the trend arcs.
return ""; function Trend() {
} else { debug.log("New Trend Object instanziated");
return ""; this.oldValue = undefined;
this.diff = 0;
} }
};
function swith(elem, callback) { Trend.prototype.newValue = function (value) {
if (elem !== undefined) { if (this.oldValue !== undefined) {
debug.log(elem, "selected"); this.diff = value - this.oldValue;
if (callback !== undefined) { debug.log("The difference between the current temp and the old temp is", this.diff);
callback();
} }
} else { debug.log("The value of the oldTemp is now", value);
debug.error(elem, "not selectable"); this.oldValue = value;
}
} return this;
};
Trend.prototype.toString = function () {
if (this.diff === 0) {
return "";
} else if (this.diff > 0) {
return "";
} else {
return "";
}
};
/* END HELPERS */ /* END HELPERS */
/* DOM Selecting initialization */ /* DOM Selecting initialization */
main(function () { main(function () {
sede = doc.getElementById("sede"); moment.locale('it');
swith(sede, function () {
sedeValue = query(".value", sede)[0];
sedeTimestamp = query(".timestamp", sede)[0];
sedeModifiedBy = query(".modified_by", sede)[0];
});
temp = doc.getElementById("temp"); sede = $("#sede")[0];
swith(temp, function () { sedeValue = $("#sede .value")[0];
tempValue = query(".value", temp)[0]; sedeTimestamp = $("#sede .timestamp")[0];
tempTrend = query(".trend", temp)[0]; sedeModifiedBy = $("#sede .modified_by")[0];
});
msg = query("#last.msg")[0]; temp = $("#temp")[0];
swith(msg, function () { tempValue = $("#temp .value")[0];
msgUser = query(".user", msg)[0]; tempTrend = $("#temp .trend")[0];
msgTimestamp = query(".timestamp", msg)[0];
msgValue = query(".value", msg)[0]; msg = $("#last.msg")[0];
}); msgUser = $("#last.msg .user")[0];
msgTimestamp = $("#last.msg .timestamp")[0];
msgValue = $("#last.msg .value")[0];
title = doc.title; title = doc.title;
swith(title); favicon = query('[rel="icon"]')[0];
favicon = query('[rel="icon"]')[0]; head = doc.head || doc.getElementsByTagName('head')[0];
swith(favicon);
head = doc.head || doc.getElementsByTagName('head')[0]; if ($("#temperature_graph").length > 0)
swith(head); tempGraph = Raphael("temperature_graph", tempGraphWidth, tempGraphHeight);
tempGraph = Raphael("temperature_graph", tempGraphWidth, tempGraphHeight); trend = new Trend();
});
trend = new Trend(); /* Handler functions definition */
});
/* Handler functions definition */ // Handle BITS status change.
// Handle BITS status change. function statusHandler(status, first) {
function statusHandler(status, first) { debug.log("browserHandler handling status");
debug.log("browserHandler handling status"); if (first) {
if (first) { show(sede);
show(sede); }
var value = status.value === "open" ? "open" : "closed";
changeIcon(value);
changeFAB(value);
doc.title = capitalize(value) + " " + title;
sedeValue.setAttribute("class", value + " value");
sedeTimestamp.innerHTML = moment(status.timestamp).startOf('hour').fromNow();
sedeModifiedBy.innerHTML = status.modifiedby;
} }
var value = status.value === "open" ? "open" : "close";
changeIcon(value);
doc.title = capitalize(value) + " " + title;
sedeValue.setAttribute("class", value + " value");
sedeTimestamp.innerHTML = status.timestamp;
sedeModifiedBy.innerHTML = status.modifiedby;
}
// Handle MSGs arrival // Handle MSGs arrival
function msgHandler(message, first) { function msgHandler(message, first) {
debug.log("Displaying message"); debug.log("Displaying message");
if(first) { if (message.value.length > 0) {
show(msg); show(msg);
} else if (message.value.length === 0) {
hide(msg);
}
msgUser.innerHTML = message.user;
msgTimestamp.innerHTML = moment(message.timestamp).startOf('hour').fromNow();
msgValue.innerHTML = message.value;
} }
msgUser.innerHTML = message.user;
msgTimestamp.innerHTML = message.timestamp;
msgValue.innerHTML = message.value;
}
// Handle tempInt arrival // Handle tempInt arrival
function tempIntHandler(tempInt, first) { function tempIntHandler(tempInt, first) {
debug.log("browserHandler handling tempint"); debug.log("browserHandler handling tempint");
if (first) { if (first) {
show(temp); show(temp);
} }
tempValue.innerHTML = tempInt.value.toPrecision() + "°C";
tempValue.innerHTML = tempInt.value.toPrecision() + "°C";
if (lastTimestamp !== tempInt.timestamp) { if (lastTimestamp !== tempInt.timestamp) {
tempTrend.innerHTML = trend.newValue(tempInt.value); tempTrend.innerHTML = trend.newValue(tempInt.value);
if (!first) { if (!first) {
//TODO tempGraph.addTemp(tempInt); //TODO tempGraph.addTemp(tempInt);
}
} }
$(temp)
.removeClass("high")
.removeClass("low")
.addClass(tempInt.value > 20 ? "high" : "low");
} }
temp.setAttribute("class", tempInt.value > 20 ? "high" : "low");
}
function tempIntHistHandler(tempIntHist, first) { function tempIntHistHandler(tempIntHist, first) {
debug.log("browserHandler handling tempIntHist"); debug.log("browserHandler handling tempIntHist");
var cordX = 0, var cordX = 0,
cordY = 0, cordY = 0,
reversedHistory = tempIntHist.reverse(); reversedHistory = tempIntHist.reverse();
for (var i = 0; i < tempIntHist.length; i++) { for (var i = 0; i < tempIntHist.length; i++) {
tempGraphValuesY[tempGraphValuesY.length] = tempIntHist[i].value; tempGraphValuesY[tempGraphValuesY.length] = tempIntHist[i].value;
tempGraphTimestampValues[tempGraphTimestampValues.length] = tempIntHist[i].timestamp; tempGraphTimestampValues[tempGraphTimestampValues.length] = tempIntHist[i].timestamp;
}
tempGraph.linechart(
cordX, cordY,
tempGraphHeight, tempGraphWidth,
seq(0, tempGraphValuesY.length), tempGraphValuesY,
{
shade: true,
colors: ["#0F0"]
}
);
} }
tempGraph.linechart( // Exports only the browserHandler object in the global scope
cordX, cordY, exports.status = statusHandler;
tempGraphHeight, tempGraphWidth, exports.msg = msgHandler;
seq(0, tempGraphValuesY.length), tempGraphValuesY, exports.tempInt = tempIntHandler;
{ exports.tempIntHist = tempIntHistHandler;
shade: true,
colors: ["#0F0"]
}
);
} }
);
// Exports only the browserHandler object in the global scope
exports.status = statusHandler;
exports.msg = msgHandler;
exports.tempInt = tempIntHandler;
exports.tempIntHist = tempIntHistHandler;
});
...@@ -7,8 +7,9 @@ main(function (require) { ...@@ -7,8 +7,9 @@ main(function (require) {
location = require("location"), location = require("location"),
query = require("peppy").query, query = require("peppy").query,
debug = require("debug"), debug = require("debug"),
protocol = /https/.test(location.protocol)? "wss": "ws", protocol = /https/.test(location.protocol) ? "wss" : "ws",
ws = new WebSocket(protocol + "://" + location.hostname + ":" + location.port + "/ws"), ws = new WebSocket(protocol + "://" + location.hostname + ":" + location.port + "/ws"),
// ws = new WebSocket("wss://bits.poul.org/ws"),
handler = new Handler(browserHandler); handler = new Handler(browserHandler);
var debugMeta = query("meta[name='mode']")[0]; var debugMeta = query("meta[name='mode']")[0];
...@@ -26,3 +27,29 @@ main(function (require) { ...@@ -26,3 +27,29 @@ main(function (require) {
debug.error("WS Error", event); debug.error("WS Error", event);
}; };
}); });
let _sticky = false;
const setFABsticky = function (sticky) {
if (sticky === _sticky)
return;
if (sticky)
$("#hq-status-fab").addClass("stick-to-bar");
else
$("#hq-status-fab").removeClass("stick-to-bar");
_sticky = sticky;
};
$(document).ready(function () {
const navbar = $("nav.navbar");
const mainTop = $("#hq-status-fab").parent().offset().top;
$(window).scroll(function () {
const windowScroll = $(this).scrollTop();
const barBottom = navbar.outerHeight();
setFABsticky(windowScroll + barBottom > mainTop);
});
});
\ No newline at end of file
This diff is collapsed.
#poul-logo-top {
width: 65%;
}
.bg-very-dark {
background-color: #010101 !important;
}
.bg-a-bit-less-dark {
background-color: #1b1b1b !important;
}
.bg-kinda-dark {
background-color: #232323 !important;
}
.bg-black {
background-color: black !important;
}
.page-header {
height: 400px;
z-index: -1;
}
a {
color: #ffc500;
}
a:hover {
color: #ac8300;
}
strong {
font-weight: bold;
color: #ffc500;
}
footer ul li a {
color: #ffc500;
}
#hq-status-fab {
z-index: 2000;
text-align: center;
position: absolute;
top: -33px;
width: 100%;
}
#hq-status-fab button {
top: 0;
font-weight: bold;
}
.no-z-index {
z-index: unset !important;
}
.btn.btn-gialla {
color: #fff;
background-color: #ffc500;
border-color: #ffc500;
box-shadow: 0 2px 2px 0 rgba(255, 152, 0, 0.14), 0 3px 1px -2px rgba(255, 152, 0, 0.2), 0 1px 5px 0 rgba(255, 152, 0, 0.12);
}
.btn.btn-gialla:hover {
color: #fff;
background-color: #ffc500;
border-color: #7f6200;
}
.btn-gialla {
color: #212529;
background-color: #ffc500;
border-color: #ffc500;
box-shadow: none;
}
.btn.btn-gialla:after {
content: 'Sede gialla';
}
.btn-gialla:focus,
.btn-gialla.focus {
box-shadow: none, 0 0 0 0.2rem rgba(127, 98, 0, 1);
}
.btn-gialla.disabled,
.btn-gialla:disabled {
color: #212529;
background-color: #ffc500;
border-color: #ffc500;
}
.btn.btn-open {
color: #fff;
background-color: #387002;
border-color: #387002;
box-shadow: 0 2px 2px 0 rgba(28, 56, 1, 0.14), 0 3px 1px -2px rgba(28, 56, 1, 0.2), 0 1px 5px 0 rgba(28, 56,<