Skip to content

Commit

Permalink
Merge pull request #501 from hplato/ia7
Browse files Browse the repository at this point in the history
Tracking latest changes of Howard for the IA7 web interface
  • Loading branch information
hollie committed Apr 11, 2015
2 parents da3714e + d8e27c9 commit 0e4c64f
Show file tree
Hide file tree
Showing 28 changed files with 611 additions and 100 deletions.
15 changes: 9 additions & 6 deletions data/web/collections.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"106" : {
"link" : "/organizer/calendar.pl",
"name" : "Calendar",
"keys" : "true",
"icon" : "fa-calendar"
},
"52" : {
Expand Down Expand Up @@ -194,6 +195,7 @@
"108" : {
"link" : "/organizer/tasks.pl",
"name" : "TODO List",
"keys" : "true",
"icon" : "fa-list"
},
"94" : {
Expand Down Expand Up @@ -237,7 +239,7 @@
"link" : "/ia7/#path=/objects&type=Voice_Cmd&category=Photos"
},
"59" : {
"external" : "http://www.weather.com/weather/local/91403",
"iframe" : "http://www.weather.com/weather/local/91403",
"icon" : "fa-cloud",
"name" : "Weather.com - Local"
},
Expand Down Expand Up @@ -383,7 +385,7 @@
"113" : {
"name" : "LED Clock",
"icon" : "fa-clock-o",
"link" : "/clock"
"link" : "/clock/index.html"
},
"71" : {
"name" : "Camera Files",
Expand Down Expand Up @@ -429,7 +431,7 @@
"98" : {
"icon" : "fa-volume-up",
"name" : "Speak Text",
"link" : "/ia5/speak/speakframe.html"
"link" : "/ia7/house/speaktext.shtml"
},
"96" : {
"link" : "/ia7/#path=/objects&type=Voice_Cmd&category=Music",
Expand Down Expand Up @@ -479,6 +481,7 @@
"107" : {
"link" : "/organizer/contacts.pl",
"icon" : "fa-book",
"keys" : "true",
"name" : "Address Book"
},
"26" : {
Expand Down Expand Up @@ -689,7 +692,7 @@
"58" : {
"name" : "Weather Underground",
"icon" : "fa-sun-o",
"external" : "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=91403"
"iframe" : "http://www.wunderground.com/cgi-bin/findweather/getForecast?query=91403"
},
"115" : {
"name" : "Browse Timed_Events",
Expand Down Expand Up @@ -778,8 +781,8 @@
"name" : "Authorize",
"icon" : "fa-lock"
},
"600" : {
"600" : {
"link" : "/ia7/#path=/objects&parents=ia7_status_items",
"name" : "Status"
}
}
}
5 changes: 2 additions & 3 deletions lib/Generic_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,13 @@ If set to 1, the object will not show up on Tk or Web menus. Can only be run at
=cut

sub hidden {
return unless $main::Reload;
my ($self, $flag) = @_;
# Set it
if (defined $flag) {
return unless $main::Reload;
$self->{hidden} = $flag;
}
else { # Return it, but this currently only will work on $Reload.
return $self->{hidden};
return $self->{hidden}; # HP - really, no reason why this can't be a read-only method any time?
}
}

Expand Down
97 changes: 93 additions & 4 deletions lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ =head2 METHODS
use HTML::Entities; # So we can encode characters like <>& etc
use JSON qw(decode_json);
use IO::Compress::Gzip qw(gzip);
use vars qw(%json_table);

sub json {
my ($request_type, $path_str, $arguments, $body) = @_;
Expand Down Expand Up @@ -162,8 +163,16 @@ sub json_get {
$collection_file = "$config_parms{data_dir}/web/collections.json"
if -e "$config_parms{data_dir}/web/collections.json";
# Consider copying the source file to the user data dir here.
my $json_collections = file_read($collection_file);
$json_data{'collections'} = decode_json($json_collections);

eval {
my $json_collections = file_read($collection_file);
$json_data{'collections'} = decode_json($json_collections); #HP, wrap this in eval to prevent MH crashes
};
if ($@){
print_log "Json_Server.pl: WARNING: decode_json failed for collection.json. Please check this file!";
$json_data{'collections'} = decode_json('{ "0" : { "name" : "error" } }'); #write a blank collection

}
}

# List objects
Expand Down Expand Up @@ -287,6 +296,16 @@ sub json_get {
$json_data{vars} = \%json_vars;
}

if ( $path[0] eq 'table_data') {
#print Dumper $json_table{$args{var}[0]};# if $Debug{json};
if ($args{var}) {
my $jt_time = int($json_table{$args{var}[0]}{time});
if (($args{time} && int($args{time}[0]) < $jt_time) or (!$args{time})) {
$json_data{'table_data'} = $json_table{$args{var}[0]};
}
}
}

# List print_log phrases
if ( $path[0] eq 'print_log' || $path[0] eq '' ) {
my @log;
Expand Down Expand Up @@ -507,7 +526,7 @@ sub json_object_detail {

my $ref = ref \$object;
return unless $ref eq 'REF';
return if $object->can('hidden') and $object->hidden; #Not sure about this
#return if $object->can('hidden') and $object->hidden; #Not sure about this, HP - should just return a hidden property
my $object_name = $object->{object_name};

# Skip object if time arg supplied and not changed
Expand All @@ -534,7 +553,7 @@ sub json_object_detail {
my %json_objects;
my %json_complete_object;
my @f = qw( category filename measurement rf_id set_by members
state states state_log type label sort_order groups parents
state states state_log type label sort_order groups hidden parents
idle_time text html seconds_remaining level);

# Build list of fields based on those requested.
Expand All @@ -559,6 +578,14 @@ sub json_object_detail {
my @a = $object->$method;
$value = \@a;
}
#if ( $f eq 'hidden' ) {
# my $a = $object->$method;
# if ($a == 1 or $a eq "1") {
# print_log "json true";
# } else {
# print_log "json false";
# }
#}
else {
$value = $object->$method;
$value = encode_entities( $value, "\200-\377&<>" );
Expand Down Expand Up @@ -726,6 +753,68 @@ sub json_usage {
return $html;
}


sub json_table_create {
my ($key) = @_;

return 0 if (defined $json_table{$key}{exist});

$json_table{$key}{exist} = 1;
return 1;
}

sub json_table_delete {
my ($key) = @_;

return 0 if (!defined $json_table{$key}{exist});

$json_table{$key} = {};
return 1;
}

sub json_table_put_header {
my ($key,$pos,$value) = @_;

return 0 if (!defined $json_table{$key}{exist});

$json_table{$key}{head}[$pos] = $value;
return 1;
}

sub json_table_get_header {
my ($key,$pos) = @_;

return 0 if (!defined $json_table{$key}{exist});

return $json_table{$key}{head}[$pos];
}

sub json_table_put_data {
my ($key,$posx,$posy,$value) = @_;

return 0 if (!defined $json_table{$key}{exist});

$json_table{$key}{data}[$posx][$posy] = $value;
return 1;
}

sub json_table_get_data {
my ($key,$posx,$posy) = @_;

return 0 if (!defined $json_table{$key}{data}[$posx][$posy]);

return $json_table{$key}{data}[$posx][$posy];
}

sub json_table_push {
my ($key) = @_;

return 0 if (!defined $json_table{$key});

$json_table{$key}{time} = &get_tickcount;
return 1;
}

return 1; # Make require happy


Expand Down
56 changes: 40 additions & 16 deletions web/clock/index.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
<HEAD>
<TITLE>JavaClock</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ramandeep Singh (ramandeepji@yahoo.com) -->

<!-- <!-- Original: Ramandeep Singh (ramandeepji@yahoo.com) -->
<!-- Web Site: http://hard-drive.hypermart.net -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin

<!-- IA7 updates -->
var img_prefix = "";
var img_suffix = "";

var loc = window.location.toString();
if (loc.indexOf("&_collection_key") !== 0) {
img_prefix = "/clock/";
img_suffix = "w";
}


var dn;
c1 = new Image(); c1.src = "numbers/c1.gif";
c2 = new Image(); c2.src = "numbers/c2.gif";
c3 = new Image(); c3.src = "numbers/c3.gif";
c4 = new Image(); c4.src = "numbers/c4.gif";
c5 = new Image(); c5.src = "numbers/c5.gif";
c6 = new Image(); c6.src = "numbers/c6.gif";
c7 = new Image(); c7.src = "numbers/c7.gif";
c8 = new Image(); c8.src = "numbers/c8.gif";
c9 = new Image(); c9.src = "numbers/c9.gif";
c0 = new Image(); c0.src = "numbers/c0.gif";
cb = new Image(); cb.src = "numbers/cb.gif";
cam = new Image(); cam.src = "numbers/cam.gif";
cpm = new Image(); cpm.src = "numbers/cpm.gif";
c1 = new Image(); c1.src = img_prefix+"numbers/c1"+img_suffix+".gif";
c2 = new Image(); c2.src = img_prefix+"numbers/c2"+img_suffix+".gif";
c3 = new Image(); c3.src = img_prefix+"numbers/c3"+img_suffix+".gif";
c4 = new Image(); c4.src = img_prefix+"numbers/c4"+img_suffix+".gif";
c5 = new Image(); c5.src = img_prefix+"numbers/c5"+img_suffix+".gif";
c6 = new Image(); c6.src = img_prefix+"numbers/c6"+img_suffix+".gif";
c7 = new Image(); c7.src = img_prefix+"numbers/c7"+img_suffix+".gif";
c8 = new Image(); c8.src = img_prefix+"numbers/c8"+img_suffix+".gif";
c9 = new Image(); c9.src = img_prefix+"numbers/c9"+img_suffix+".gif";
c0 = new Image(); c0.src = img_prefix+"numbers/c0"+img_suffix+".gif";
cb = new Image(); cb.src = img_prefix+"numbers/cb"+img_suffix+".gif";
cc = new Image(); cc.src = img_prefix+"numbers/colon"+img_suffix+".gif";
cam = new Image(); cam.src = img_prefix+"numbers/cam"+img_suffix+".gif";
cpm = new Image(); cpm.src = img_prefix+"numbers/cpm"+img_suffix+".gif";
function extract(h,m,s,type) {
if (!document.images) return;

document.images.c.src = cc.src;
document.images.c.src = eval("cc.src");
document.images.f.src = cc.src;
document.images.f.src = eval("cc.src");

if (h <= 9) {
document.images.a.src = cb.src;
document.images.b.src = eval("c"+h+".src");
Expand Down Expand Up @@ -78,10 +98,10 @@
<table>
<tr>
<td><a href='javascript:history.go(-1)'> <img src='/graphics/1pixel.gif' width='200' height='150' border=0></a></td>
<td><a href='/' target='_top'> <img src='/graphics/1pixel.gif' width='200' height='150' border=0></a></td>
<td><a href='/ia5/index_menu.shtml' target='_top'> <img src='/graphics/1pixel.gif' width='200' height='150' border=0></a></td>
<td><a href='/' target='_top'> <img src='/graphics/1pixel.gif' width='200' height='150' border=0></a></td>
</tr></table>

<table>
<center>
<img height=100 src="numbers/cb.gif" width=72 name=a>
<img height=100 src="numbers/cb.gif" width=72 name=b>
Expand All @@ -93,12 +113,16 @@
<img height=100 src="numbers/cb.gif" width=72 name=h>
<img height=100 src="numbers/cam.gif" width=72 name=j>
</center>
</table>

<table>
<tr>
<td><a href='/misc/photos.html' target='_top'> <img src='/graphics/1pixel.gif' width='600' height='150' border=0></a></td>
</tr></table>

<script>
show3();
</script>
<!-- Ever seen the TV series 24? :)
<EMBED src='/data/clock_tick2.wav' autostart=true loop=false volume=10 hidden=true>
Expand Down
Binary file added web/clock/numbers/c0w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c1w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c2w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c3w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c4w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c5w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c6w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c7w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c8w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/c9w.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/camw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/cbw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/colonw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/clock/numbers/cpmw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified web/ia7/fonts/weathericons-regular-webfont.woff
Binary file not shown.
40 changes: 40 additions & 0 deletions web/ia7/house/speaktext.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class='row top-buffer'>
<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'>

Type something below to have MisterHouse
process the text to speech and send a wav file to your browser, using
<a href=/bin/browse.pl?/code/common/eliza_server.pl>common/eliza_server.pl</a>.
If you are in need of some consoling, click the Eliza checkbot,
and a ChatBot version of the famous Eliza psychologist will have a conversation with you.
Or have MisterHouse read you a deep thought, read a tagline or
show what was <a target=speech href=/ia7/#path=/print_speaklog>recently spoken</a>,<br>

<center>
<form target="speech">
<textarea rows=2 cols=40 id="speakText" name=eliza_data></textarea>
<input type="button" value="Speak it!" id="speakNow"/>
</form>

</div>
</div>
</div>

<script>

$(document).ready(function() {
$('#speakNow').click(function() {
//alert($('#speakText').val());
var url = '/SET;last_response?eliza_data=' + $('#speakText').val();
$.get( url, function(data) {
var start = data.toLowerCase().indexOf('<body>') + 6;
var end = data.toLowerCase().indexOf('</body>');
$('#lastResponse').find('.modal-body').html(data.substring(start, end));
$('#lastResponse').modal({
show: true
});
});
});
});

</script>
22 changes: 22 additions & 0 deletions web/ia7/include/iframe.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<iframe id="mhIframe" src="" width="100%" height="100%" marginheight="0" frameborder="0"></iframe>

<script>
//set up the iframe to have height of the window and then add in the src passed in the URL...
var newheight = $(window.parent.document).height();
var loc = window.location.toString(),
params = loc.split('?');
var url = params[1];
for (var i = 2; i < params.length; i++){
url += "?"+params[i];
}
//check if http / https is in the URL...
var prefix = "http://";
if (url.indexOf("http") == 0) prefix = "";
var params2 = prefix + url.split('&_collection_key')[0];
//alert("pref="+prefix+" url="+params2);

$('#mhIframe').attr("src",params2);
$('#mhIframe').attr("height",newheight+"px");

</script>
Loading

0 comments on commit 0e4c64f

Please sign in to comment.