Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ia7 v1.5.300 #703

Merged
merged 6 commits into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/Voice_Cmd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,16 @@ sub set {
}
return if &main::check_for_tied_filters( $self, $state );

&main::print_log("DB Voice_Cmd : state=$state, set_by=$set_by, no_log=$no_log, respond=$respond") if $main::Debug{voice};

#don't process voice command if via xAP, this can cause scalability issues if all MH instances
#have mh_control.pl enabled (multiple check http server commands will run)
#if xAP voice commands need to execute, then turn on $config_parms{xap_enable_voice_cmds} = 1

return if (($set_by =~ m/^xAP/) and ((!defined $::config_parms{xap_enable_voice_cmds}) or ((defined $::config_parms{xap_enable_voice_cmds}) and ($::config_parms{xap_enable_voice_cmds} == 0))));

&main::print_log("DB Voice_Cmd : executing $cmd") if $main::Debug{voice};

# Cannot do this! Respond_Target is shared by everything and its brother!
# if app passes explicit targets, then they are passed along and eventually responded to
# otherwise set_by is used
Expand Down
38 changes: 38 additions & 0 deletions lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,44 @@ sub json_get {
$json_data{vars_global} = \%json_vars_global;
}

if ( $path[0] eq 'tagline' || $path[0] eq '' ) {
my $file;
if ( -e "$config_parms{data_dir}/remarks/1100tags.txt" ) {
$file = "$config_parms{data_dir}/remarks/1100tags.txt";
} else {
$file = "$Pgm_Root/data/remarks/1100tags.txt";
}
srand;
my $tagline = "could not retrieve tagline";

eval {
open FILE, "<$file" or warn "Could not open filename: $!\n";
rand($.)<1 and ($tagline=$_) while <FILE>;
close FILE;
};
if ($@) {
print_log "Json_Server.pl: WARNING: Could not open tagline file!";
}

$json_data{tagline} = $tagline
}

if ( $path[0] eq 'stats' || $path[0] eq '' ) {
#13:28 up 48 days, 2:19, 8 users, load averages: 3.15 3.30 2.78
my $uptime;
if ( $OS_win or $^O eq 'cygwin' ) {
$uptime = "$Tk_objects{label_uptime_mh} &nbsp;&nbsp; $Tk_objects{label_uptime_cpu}";
} else {
$uptime = `uptime`;
}
my ($time,$upt,$users,$load) = $uptime =~ /^(\S+)\s+up\s(.*),\s(\d+)\susers,\s+load\saverages?:\s(.*)/;
$json_data{stats}{time} = $time;
$json_data{stats}{uptime} = $upt;
$json_data{stats}{users} = $users;
$json_data{stats}{load} = $load;
$json_data{stats}{web_counter} = $Save{"web_count_default"};
}

if ( $path[0] eq 'vars_save' || $path[0] eq '' ) {
my %json_vars_save;

Expand Down
2 changes: 1 addition & 1 deletion web/ia7/house/main.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<div class='col-sm-12 col-sm-offset-0 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2'>
<div class='col-sm-12'>
<p class="text-muted"><small> MisterHouse was created by Bruce Winter. Ron Klinkien developed the v2.3 web interface. Kevin Robert Keegan
designed the IA7 web prototype, updates by H.Plato. IA7 v1.4.500 Font Awesome by Dave Gandy - http://fontawesome.io</small></p>
designed the IA7 web prototype, updates by H.Plato. IA7 v1.5.300 Font Awesome by Dave Gandy - http://fontawesome.io</small></p>
</div>
</div>
</div>
Expand Down
183 changes: 142 additions & 41 deletions web/ia7/include/javascript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// v1.4.500
// v1.5.300

var entity_store = {}; //global storage of entities
var json_store = {};
Expand All @@ -14,6 +14,9 @@ var audioElement = document.getElementById('sound_element');
var authorized = "false";
var developer = false;
var show_tooltips = true;
var rrd_refresh_loop;
var stats_loop;
var stat_refresh = 60;

var ctx; //audio context
var buf; //audio buffer
Expand Down Expand Up @@ -140,6 +143,8 @@ function changePage (){
}
});
} else {
if ((json_store.ia7_config.prefs.static_tagline !== undefined) && json_store.ia7_config.prefs.static_tagline == "yes") clearTimeout(stats_loop);
if (json_store.ia7_config.prefs.stat_refresh !== undefined) stat_refresh = json_store.ia7_config.prefs.stat_refresh;
if (json_store.ia7_config.prefs.header_button == "no") $("#mhstatus").remove();
if (json_store.ia7_config.prefs.audio_controls !== undefined && json_store.ia7_config.prefs.audio_controls == "yes") {
$("#sound_element").attr("controls", "controls"); //Show audio Controls
Expand Down Expand Up @@ -854,7 +859,17 @@ var filterSubstate = function (state) {
return filter;
};

var brightnessStates = function (states) {

for(var i = 0; i < states.length; i++)
{
if(states[i].indexOf('%') != -1)
{
return 1
}
}
return 0;
}

var sortArrayByArray = function (listArray, sortArray){
listArray.sort(function(a,b) {
Expand Down Expand Up @@ -1343,6 +1358,42 @@ var something_went_wrong = function(module,text) {

}

var get_stats = function(tagline) {
var URLHash = URLToHash();

if (tagline === undefined){
$.ajax({
type: "GET",
url: "/json/tagline",
dataType: "json",
success: function( json ) {
JSONStore(json);
get_stats(json.data);
}
});
return;
}
$.ajax({
type: "GET",
url: "/json/stats",
dataType: "json",
success: function( json, statusText, jqXHR ) {
if (jqXHR.status == 200) {
//console.log("tagline="+tagline);
$('.tagline').text(tagline);
$('.uptime').text(json.data.time+" Up "+json.data.uptime+", "+json.data.users+" users, load averages: "+json.data.load);
$('.counter').text("Page Views: "+json.data.web_counter);
//console.log("uptime="+json.data.uptime);
}
if (jqXHR.status == 200 || jqXHR.status == 204) {
stats_loop = setTimeout(function(){
get_stats();
}, stat_refresh * 1000); }
}
});
}



var get_notifications = function(time) {
if (time === undefined) time = new Date().getTime();
Expand Down Expand Up @@ -1527,16 +1578,20 @@ var graph_rrd = function(start,group,time) {
var URLHash = URLToHash();
var new_data = 1;
var data_timeout = 0;
var refresh = 60; //refresh data every 60 seconds by default

if (json_store.ia7_config.prefs.rrd_refresh !== undefined) refresh = json_store.ia7_config.prefs.rrd_refresh;

if (typeof time === 'undefined'){
$('#list_content').html("<div id='top-graph' class='row top-buffer'>");
$('#top-graph').append("<div id='rrd-periods' class='row'>");
$('#top-graph').append("<div id='rrd-graph' class='col-sm-12 col-sm-offset-0 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2 col-xs-11 col-xs-offset-0'>");
$('#top-graph').append("<div id='rrd-legend' class='rrd-legend-class'><br>");
new_data = 0;
time = 0;
clearTimeout(rrd_refresh_loop); //prevent any previous loops from updating.
}
var refresh = 20; //refresh data every 60 seconds by default
var refresh_loop;

if (json_store.ia7_config.prefs.rrd_graph_refresh !== undefined) refresh = json_store.ia7_config.prefs.rrd_graph_refresh;

URLHash.time = time;
Expand All @@ -1562,7 +1617,6 @@ var graph_rrd = function(start,group,time) {
success: function( json, statusText, jqXHR ) {
var requestTime = time;
if (jqXHR.status == 200) {
JSONStore(json);
// HP should probably use jquery, but couldn't get sequencing right.
// HP jquery would allow selected values to be replaced in the future.

Expand All @@ -1574,6 +1628,7 @@ var graph_rrd = function(start,group,time) {
return;
}
}
JSONStore(json);
var dropdown_html = '<div class="dropdown"><button class="btn btn-default rrd-period-dropdown" data-target="#" type="button" data-toggle="dropdown">';
var dropdown_html_list = "";
var dropdown_current = "Unknown ";
Expand Down Expand Up @@ -1720,7 +1775,7 @@ var graph_rrd = function(start,group,time) {
//If the graph page is still active request more data
//Just manually pull a refresh since json_server constantly polling RRD data is a performance problem

refresh_loop = setTimeout(function(){
rrd_refresh_loop = setTimeout(function(){
graph_rrd(start,group,0);
}, refresh * 1000);
}
Expand Down Expand Up @@ -2570,7 +2625,7 @@ var create_state_modal = function(entity) {
if (json_store.objects[entity].label !== undefined) name = json_store.objects[entity].label;
$('#control').modal('show');
var modal_state = json_store.objects[entity].state;
$('#control').find('.object-title').html(name + " - " + json_store.objects[entity].state);
$('#control').find('.object-title').html(name + " - <span class='object-state'>" + json_store.objects[entity].state + "</span>");
$('#control').find('.control-dialog').attr("entity", entity);
var modal_states = json_store.objects[entity].states;
// HP need to have at least 2 states to be a controllable object...
Expand All @@ -2596,40 +2651,86 @@ var create_state_modal = function(entity) {
grid_buttons = 4;
group_buttons = 3;
}

for (var i = 0; i < modal_states.length; i++){
if (filterSubstate(modal_states[i]) == 1) {
advanced_html += "<button class='btn btn-default col-sm-"+grid_buttons+" col-xs-"+grid_buttons+" hidden'>"+modal_states[i]+"</button>";
continue
} else {
//buttonlength += 2 + modal_states[i].length
buttonlength ++;
}
//if (buttonlength >= 25) {
if (buttonlength > group_buttons) {
stategrp++;
$('#control').find('.states').append("<div class='btn-group btn-block stategrp"+stategrp+"'></div>");
buttonlength = 1;
}
var color = getButtonColor(modal_states[i])
var disabled = ""
if (modal_states[i] == json_store.objects[entity].state) {
disabled = "disabled";
}
//global override
if (json_store.ia7_config.prefs.disable_current_state !== undefined && json_store.ia7_config.prefs.disable_current_state == "no") {
disabled = "";
}
//per object override
if (json_store.ia7_config.objects !== undefined && json_store.ia7_config.objects[entity] !== undefined) {
if (json_store.ia7_config.objects[entity].disable_current_state !== undefined && json_store.ia7_config.objects[entity].disable_current_state == "yes") {
disabled = "disabled";
} else {
//if it's a brightness object then put ON/OFF and a slider unless overriden in the prefs file
if (!brightnessStates(json_store.objects[entity].states) || (json_store.ia7_config.prefs.brightness_slider !== undefined && json_store.ia7_config.prefs.brightness_slider == "no")) {
for (var i = 0; i < modal_states.length; i++){
if (filterSubstate(modal_states[i]) == 1) {
advanced_html += "<button class='btn btn-default col-sm-"+grid_buttons+" col-xs-"+grid_buttons+" hidden'>"+modal_states[i]+"</button>";
continue
} else {
//buttonlength += 2 + modal_states[i].length
buttonlength ++;
}
//if (buttonlength >= 25) {
if (buttonlength > group_buttons) {
stategrp++;
$('#control').find('.states').append("<div class='btn-group btn-block stategrp"+stategrp+"'></div>");
buttonlength = 1;
}
var color = getButtonColor(modal_states[i])
var disabled = ""
if (modal_states[i] == json_store.objects[entity].state) {
disabled = "disabled";
}
//global override
if (json_store.ia7_config.prefs.disable_current_state !== undefined && json_store.ia7_config.prefs.disable_current_state == "no") {
disabled = "";
}
}
$('#control').find('.states').find(".stategrp"+stategrp).append("<button class='btn col-sm-"+grid_buttons+" col-xs-"+grid_buttons+" btn-"+color+" "+disabled+"'>"+modal_states[i]+"</button>");
}
}
//per object override
if (json_store.ia7_config.objects !== undefined && json_store.ia7_config.objects[entity] !== undefined) {
if (json_store.ia7_config.objects[entity].disable_current_state !== undefined && json_store.ia7_config.objects[entity].disable_current_state == "yes") {
disabled = "disabled";
} else {
disabled = "";
}
}
$('#control').find('.states').find(".stategrp"+stategrp).append("<button class='btn col-sm-"+grid_buttons+" col-xs-"+grid_buttons+" btn-"+color+" "+disabled+"'>"+modal_states[i]+"</button>");
}
} else {
$('#control').find('.states').find(".stategrp0").append("<button class='btn col-sm-6 col-xs-6 btn-success'>on</button>");
$('#control').find('.states').find(".stategrp0").append("<button class='btn col-sm-6 col-xs-6 btn-default'>off</button>");
$('#control').find('.states').append("<div id='slider' class='brightness-slider'></div>");
var val = $(".object-state").text();
if (val == "on") {
val = 100;
} else if (val == "off") {
val = 0;
} else {
val = parseInt(val);
}
$('#slider' ).slider({
min: 0,
max: 100,
value: val,
});
$( "#slider" ).on( "slide", function(event, ui) {
var sliderstate = ui.value;
if (sliderstate == "100") {
sliderstate = "on";
} else if (sliderstate == "0") {
sliderstate = "off";
} else {
sliderstate += "%";
}
//console.log("Slider Change "+ui.value+":"+sliderstate);
$('#control').find('.object-state').text(sliderstate);

});
$( "#slider" ).on( "slidechange", function(event, ui) {
var sliderstate = ui.value;
if (sliderstate == "100") {
sliderstate = "on";
} else if (sliderstate == "0") {
sliderstate = "off";
} else {
sliderstate += "%";
}
url= '/SET;none?select_item='+$(this).parents('.control-dialog').attr("entity")+'&select_state='+sliderstate;
$('#control').modal('hide');
$.get( url);
});

}
$('#control').find('.states').append("<div class='btn-group advanced btn-block'>"+advanced_html+"</div>");
$('#control').find('.states').find('.btn').click(function (){
url= '/SET;none?select_item='+$(this).parents('.control-dialog').attr("entity")+'&select_state='+$(this).text();
Expand Down Expand Up @@ -2956,8 +3057,8 @@ $(document).ready(function() {

// Load up 'globals' -- notification and the status
updateItem("ia7_status");
get_notifications();

get_notifications();
get_stats();
$("#toolButton").click( function () {
// Need a 'click' event to turn on sound for mobile devices
if (mobile_device() == "ios" ) {
Expand Down
13 changes: 13 additions & 0 deletions web/ia7/include/jquery-ui-1.12.1.min.js

Large diffs are not rendered by default.

Loading