Skip to content

Commit

Permalink
Cron & Tobi Fixes
Browse files Browse the repository at this point in the history
Fixed jqCron needing 1-7 for DOW. added in conversion subroutine. Included Tobi's fixes for datepicker.
  • Loading branch information
hplato authored Sep 25, 2016
1 parent 090c4eb commit 9f09508
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 33 deletions.
100 changes: 69 additions & 31 deletions web/ia7/include/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,10 @@ var object_history = function(items,start,days,time) {

$('.update_history').click(function() {
console.log ("start="+$('.hist_start').val()+" end="+$('.hist_end').val());
var new_start = new Date($('.hist_start').val()).getTime();
var new_end = new Date($('.hist_end').val()).getTime();
// var new_start = new Date($('.hist_start').val()).getTime();
// var new_end = new Date($('.hist_end').val()).getTime();
var new_start = new Date($('.hist_start').val().split('-')).getTime();
var new_end = new Date($('.hist_end').val().split('-')).getTime();
var end_days = (new_start - new_end) / (24 * 60 * 60 * 1000)
new_start = new_start / 1000;
object_history(items,new_start,end_days);
Expand Down Expand Up @@ -1722,15 +1724,18 @@ var object_history = function(items,start,days,time) {
for (var i = 0; i < json.data.data.length; i++) {
if (json.data.data[i].label == key) {
data.push(json.data.data[i]);
return true;
return true;
}
}
});
// take away the border so that it looks better and span the graph from start to end.
json.data.options.grid.borderWidth = 0;

json.data.options.xaxis.min = new Date($('.hist_end').val()).getTime();
json.data.options.xaxis.max = new Date($('.hist_start').val()).getTime() + (24 * 60 * 60 * 1000);
// json.data.options.xaxis.min = new Date($('.hist_end').val()).getTime();
// json.data.options.xaxis.max = new Date($('.hist_start').val()).getTime() + (24 * 60 * 60 * 1000);
json.data.options.xaxis.min = new Date($('.hist_end').val().split('-')).getTime();
json.data.options.xaxis.max = new Date($('.hist_start').val().split('-')).getTime() + (24 * 60 * 60 * 1000);

//console.log("data="+JSON.stringify(data));
//console.log("xmin="+json.data.options.xaxis.min+" xmax="+json.data.options.xaxis.max);
$.plot($("#hist-graph"), data, json.data.options);
Expand Down Expand Up @@ -1833,6 +1838,7 @@ var fp_display_height=0; // updated by fp_resize_floorplan_image
var fp_scale = 100; // updated by fp_reposition_entities
var fp_grabbed_entity = null; // store item for drag & drop
var fp_icon_select_item_id = null; // store item id on right click for icon set selection
var fp_icon_image_size = 48;

var noDragDrop = function() {
return false;
Expand All @@ -1853,7 +1859,7 @@ var fp_getOrCreateIcon = function (json, entity, i, coords){
'<a title="'+entity+'"><img '+popover_html+' ' +
'id="'+entityId+'"' +
'class="entity='+entityId+' floorplan_item coords='+coords+'" '+
'"></img></a>'+
'></img></a>'+
'</span>';
if (coords !== ""){
$('#graphic').append(html);
Expand Down Expand Up @@ -1884,16 +1890,17 @@ var fp_resize_floorplan_image = function(){

var fp_reposition_entities = function(){
var t0 = performance.now();
var offset = $("#fp_graphic").offset();
var fp_graphic_offset = $("#fp_graphic").offset();
console.log("fp_graphic_offset: "+ JSON.stringify(fp_graphic_offset));
var width = fp_display_width;
var hight = fp_display_height;
var onePercentWidthInPx = width/100;
var onePercentHeightInPx = hight/100;
var fp_get_offset_from_location = function(item) {
var y = item[0];
var x = item[1];
var newy = offset.top + y * onePercentHeightInPx;
var newx = offset.left + x * onePercentWidthInPx;
var newy = fp_graphic_offset.top + y * onePercentHeightInPx;
var newx = fp_graphic_offset.left + x * onePercentWidthInPx;
return {
"top": newy,
"left": newx
Expand All @@ -1918,21 +1925,22 @@ var fp_reposition_entities = function(){
} else {
nwidth = 790;
}

fp_scale = Math.round( width/nwidth * 100);
var fp_scale = width/nwidth;
var fp_scale_percent = Math.round( fp_scale * 100);

console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale);
console.log("width="+width+" nwidth="+nwidth+" scale="+fp_scale_percent);
// update the location of all the objects...
$(".floorplan_item").each(function(index) {
var classstr = $(this).attr("class");
var coords = classstr.split(/coords=/)[1];
$(this).width(fp_scale + "%");
$(this).width(fp_scale_percent + "%");

if (coords.length === 0){
return;
}
var fp_location = coords.split(/x/);
var fp_offset = fp_get_offset_from_location(fp_location);
console.log("coords="+coords);

// this seems to make the repositioning slow
// ~ 300+ms on my nexus7 firefox-beta vs <100ms with this code commented out
Expand All @@ -1942,13 +1950,14 @@ var fp_reposition_entities = function(){
// } else {
// $(this).attr('src',$(this).attr('src').replace('32.png','48.png'));
// }

var adjust = $(this).width()/2;
var element_id = $(this).attr('id');
var adjust = fp_icon_image_size*fp_scale/2;
console.log("adjust="+adjust+" fp_offset.top="+fp_offset.top+" fp_offset.left="+fp_offset.left);
var fp_off_center = {
"top": fp_offset.top - adjust,
"left": fp_offset.left - adjust
};
fp_set_pos($(this).attr('id'), fp_off_center);
fp_set_pos(element_id, fp_off_center);
});

$('.icon_select img').each(function(){
Expand All @@ -1962,7 +1971,23 @@ var fp_set_pos = function(id, offset){
var item = $('#' + id);
// do not move the span, this make the popup to narrow somehow
// item.closest("span").offset(offset);
var left11 = item.css("left");
var left12 = item[0].style.left;
var top11 = item.css("top");
var top12 = item[0].style.top;
var before = item.offset();
var init = false
if (item.css("left") == "auto") {
console.log("auto found, fixing left property");
offset.left = 0 - fp_icon_image_size/2;
}
item.offset(offset);
var after = item.offset();
var left21 = item.css("left");
var left22 = item[0].style.left;
console.log("offset.top="+offset.top+" offset.left="+offset.left+" before.top="+before.top+" before.left="+before.left+" after.top="+after.top+" after.left="+after.left);
console.log("top11="+top11+" top12="+top12);
console.log("left11="+left11+" left12="+left12+" left21="+left21+" left22="+left22);
};

var fp_is_point_on_fp = function (p){
Expand Down Expand Up @@ -2062,14 +2087,14 @@ var floorplan = function(group,time) {
if (fp_grabbed_entity === null)
return;

set_set_coordinates_from_offset(fp_grabbed_entity.id);
set_coordinates_from_offset(fp_grabbed_entity.id);
fp_reposition_entities();
fp_grabbed_entity = null;
});

}

var set_set_coordinates_from_offset = function (id)
var set_coordinates_from_offset = function (id)
{
var E = $('#'+id);
var offsetE = E.offset();
Expand Down Expand Up @@ -2403,14 +2428,13 @@ var get_fp_image = function(item,size,orientation) {
var image_name;
var image_color = getButtonColor(item.state);
var baseimg_width = $(window).width();
var image_size = "48";
// if (baseimg_width < 500) image_size = "32" // iphone scaling
//kvar image_size = "32"
// if (baseimg_width < 500) fp_icon_image_size = "32" // iphone scaling
//kvar fp_icon_image_size = "32"
if (item.fp_icons !== undefined) {
if (item.fp_icons[item.state] !== undefined) return item.fp_icons[item.state];
}
if (item.fp_icon_set !== undefined) {
return "fp_"+item.fp_icon_set+"_"+image_color+"_"+image_size+".png";
return "fp_"+item.fp_icon_set+"_"+image_color+"_"+fp_icon_image_size+".png";
}
// if item.fp_icons.return item.fp_icons[state];
if(item.type === "Light_Item" || item.type === "Fan_Light" ||
Expand All @@ -2422,25 +2446,25 @@ var get_fp_image = function(item,size,orientation) {
item.type === "UIO_Item" || item.type === "X10_Item" ||
item.type === "xPL_Plugwise" || item.type === "X10_Appliance") {

return "fp_light_"+image_color+"_"+image_size+".png";
return "fp_light_"+image_color+"_"+fp_icon_image_size+".png";
}

if(item.type === "Motion_Item" || item.type === "X10_Sensor" ||
item.type === "Insteon::MotionSensor" ) {
return "fp_motion_"+image_color+"_"+image_size+".png";
return "fp_motion_"+image_color+"_"+fp_icon_image_size+".png";

}

if(item.type === "Door_Item" || item.type === "Insteon::IOLinc_door") {
return "fp_door_"+image_color+"_"+image_size+".png";
return "fp_door_"+image_color+"_"+fp_icon_image_size+".png";

}

if(item.type === "FPCamera_Item" ) {
return "fp_camera_default_"+image_size+".png";
return "fp_camera_default_"+fp_icon_image_size+".png";
}

return "fp_unknown_info_"+image_size+".png";
return "fp_unknown_info_"+fp_icon_image_size+".png";
};

var create_img_popover = function(entity) {
Expand Down Expand Up @@ -2530,7 +2554,18 @@ var create_state_modal = function(entity) {
$('#control').find('.modal-footer').find('.sched_submit').remove();
// Unique Schedule Data here
if (json_store.objects[entity].schedule !== undefined) {


var modify_jqcon_dow = function(cronstr,offset) {
var cron = cronstr.split(/\s+/);
console.log("dow="+cron[cron.length-1]);
cron[cron.length-1] = cron[cron.length-1].replace(/\d/gi, function adjust(x) {
console.log("x="+x+" offset="+offset);
return parseInt(x) + parseInt(offset);
});;
console.log("dow="+cron[cron.length-1]);
return cron.join(" ");
}

var add_schedule = function(index,cron,label,state_sets) {
if (cron === null) return;
if (label == undefined) label = index;
Expand Down Expand Up @@ -2609,7 +2644,7 @@ var create_state_modal = function(entity) {
console.log("schedule.length="+json_store.objects[entity].schedule.length);
for (var i = 1; i < json_store.objects[entity].schedule.length; i++){
var sched_index = json_store.objects[entity].schedule[i][0];
var sched_cron = json_store.objects[entity].schedule[i][1];
var sched_cron = modify_jqcon_dow(json_store.objects[entity].schedule[i][1],1);
var sched_label = json_store.objects[entity].schedule[i][2];
console.log("si="+sched_index+",sc="+sched_cron+",sl="+sched_label+",ss="+sched_states);
add_schedule(sched_index,sched_cron,sched_label,sched_states);
Expand All @@ -2633,7 +2668,10 @@ var create_state_modal = function(entity) {
if ($(this).hasClass("disabled")) return;
var string = "";
$('.mhsched').each(function(index,value) {
string += $( this ).attr("id") + ',"' + $( this ).text() + '",' + $( this ).attr("label") + ',';
console.log("string="+string);
// string += $( this ).attr("id") + ',"' + $( this ).text() + '",' + $( this ).attr("label") + ',';
string += $( this ).attr("id") + ',"' + modify_jqcon_dow($(this).text(),"-1") + '",' + $( this ).attr("label") + ',';
console.log("string="+string);
});
string = string.replace(/,\s*$/, ""); //remove the last comma
var url="/SUB?ia7_update_schedule"+encodeURI("("+$(this).parents('.control-dialog').attr("entity")+","+string+")");
Expand Down Expand Up @@ -3019,4 +3057,4 @@ $(document).ready(function() {
//
// You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//
4 changes: 2 additions & 2 deletions web/ia7/include/jqCron.en.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jqCronDefaultSettings.texts.en = {
error2: 'Bad number of elements',
error3: 'The jquery_element should be set into jqCron settings',
error4: 'Unrecognized expression',
weekdays_short: ['M','Tu','W','Th','F','Sa','Su'],
weekdays: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'],
weekdays_short: ['Su','M','Tu','W','Th','F','Sa'],
weekdays: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'],
months: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']
};

0 comments on commit 9f09508

Please sign in to comment.