From f87a89a5ce1064b2492cc7f767768576347e3018 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 4 Jul 2017 11:51:23 -0400 Subject: [PATCH] more fixes --- web/skins/classic/views/js/montagereview.js | 93 +++++++++------ .../classic/views/js/montagereview.js.php | 106 +++++++++--------- 2 files changed, 111 insertions(+), 88 deletions(-) diff --git a/web/skins/classic/views/js/montagereview.js b/web/skins/classic/views/js/montagereview.js index 58067e123..63ffb2636 100644 --- a/web/skins/classic/views/js/montagereview.js +++ b/web/skins/classic/views/js/montagereview.js @@ -88,14 +88,18 @@ function loadImage2Monitor(monId,url) { } else { if ( monitorImageObject[monId].src == url ) return; // do nothing if it's the same if ( url == 'no data' ) { - monitorCanvasCtx[monId].fillStyle="white"; - monitorCanvasCtx[monId].fillRect(0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height); - var textSize=monitorCanvasObj[monId].width * 0.15; - var text="No Data"; - monitorCanvasCtx[monId].font = "600 " + textSize.toString() + "px Arial"; - monitorCanvasCtx[monId].fillStyle="black"; - var textWidth = monitorCanvasCtx[monId].measureText(text).width; - monitorCanvasCtx[monId].fillText(text,monitorCanvasObj[monId].width/2 - textWidth/2,monitorCanvasObj[monId].height/2); + if ( ! monitorCanvasCtx[monId] ) { + alert("No ctx for " + monId); + } else { + monitorCanvasCtx[monId].fillStyle="white"; + monitorCanvasCtx[monId].fillRect(0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height); + var textSize=monitorCanvasObj[monId].width * 0.15; + var text="No Data"; + monitorCanvasCtx[monId].font = "600 " + textSize.toString() + "px Arial"; + monitorCanvasCtx[monId].fillStyle="black"; + var textWidth = monitorCanvasCtx[monId].measureText(text).width; + monitorCanvasCtx[monId].fillText(text,monitorCanvasObj[monId].width/2 - textWidth/2,monitorCanvasObj[monId].height/2); + } } else { monitorLoading[monId]=true; monitorLoadStartTimems[monId]=new Date().getTime(); @@ -655,38 +659,42 @@ function maxfit2(divW, divH) // >>>>>>>>>>>>>>>> Handles individual monitor clicks and navigation to the standard event/watch display -function showOneMonitor(monId) // link out to the normal view of one event's data -{ - // We know the monitor, need to determine the event based on current time - var url; - if(liveMode!=0) url="?view=watch&mid=" + monId.toString(); - else - for(var i=0; i= eStartSecs[i] && currentTimeSecs <= eEndSecs[i]) - url="?view=event&eid=" + eId[i] + '&fid=' + parseInt(Math.max(1, Math.min(eventFrames[i], eventFrames[i] * (currentTimeSecs - eStartSecs[i]) / (eEndSecs[i] - eStartSecs[i] + 1) ) )); +function showOneMonitor(monId) { + // link out to the normal view of one event's data + // We know the monitor, need to determine the event based on current time + var url; + if ( liveMode != 0 ) + url="?view=watch&mid=" + monId.toString(); + else + for ( var i=0, len=eId.length; i= eStartSecs[i] && currentTimeSecs <= eEndSecs[i] ) + url="?view=event&eid=" + eId[i] + '&fid=' + parseInt(Math.max(1, Math.min(eventFrames[i], eventFrames[i] * (currentTimeSecs - eStartSecs[i]) / (eEndSecs[i] - eStartSecs[i] + 1) ) )); + break; + } createPopup(url, 'zmEvent', 'event', monitorWidth[eMonId[i]], monitorHeight[eMonId[i]]); } -function zoom(monId,scale) -{ - var lastZoomMonPriorScale=monitorZoomScale[monId]; - monitorZoomScale[monId] *= scale; - if(redrawScreen()==0) // failure here is probably because we zoomed too far - { - monitorZoomScale[monId]=lastZoomMonPriorScale; - alert("You can't zoom that far -- rolling back"); - redrawScreen(); // put things back and hope it works - } +function zoom(monId,scale) { + var lastZoomMonPriorScale = monitorZoomScale[monId]; + monitorZoomScale[monId] *= scale; + if ( redrawScreen() == 0 ) {// failure here is probably because we zoomed too far + monitorZoomScale[monId] = lastZoomMonPriorScale; + alert("You can't zoom that far -- rolling back"); + redrawScreen(); // put things back and hope it works + } } -function clickMonitor(event,monId) -{ - var pos_x = event.offsetX ? (event.offsetX) : event.pageX - $("Monitor"+monId.toString()).offsetLeft; - var pos_y = event.offsetY ? (event.offsetY) : event.pageY - $("Monitor"+monId.toString()).offsetTop; - if(pos_x < $("Monitor"+monId.toString()).width/4 && pos_y < $("Monitor"+monId.toString()).height/4) zoom(monId,1.15); - else if(pos_x > $("Monitor"+monId.toString()).width * 3/4 && pos_y < $("Monitor"+monId.toString()).height/4) zoom(monId,1/1.15); - else showOneMonitor(monId); - return; +function clickMonitor(event,monId) { + var monitor_element = $("Monitor"+monId.toString()); + var pos_x = event.offsetX ? (event.offsetX) : event.pageX - monitor_element.offsetLeft; + var pos_y = event.offsetY ? (event.offsetY) : event.pageY - monitor_element.offsetTop; + if ( pos_x < monitor_element.width/4 && pos_y < monitor_element.height/4 ) + zoom(monId,1.15); + else if ( pos_x > monitor_element.width * 3/4 && pos_y < monitor_element.height/4 ) + zoom(monId,1/1.15); + else + showOneMonitor(monId); + return; } // >>>>>>>>> Initialization that runs on window load by being at the bottom @@ -694,10 +702,21 @@ function clickMonitor(event,monId) function initPage() { canvas=$("timeline"); ctx=canvas.getContext('2d'); - for ( var i = 0; i < monitorPtr.length; i += 1 ) { + for ( var i = 0, len=monitorPtr.length; i < len; i += 1 ) { var monId = monitorPtr[i]; + if ( ! monId ) continue; monitorCanvasObj[monId] = $('Monitor'+monId ); - monitorCanvasCtx[monId]=monitorCanvasObj[monId].getContext('2d'); + if ( ! monitorCanvasObj[monId] ) { + alert("Couldn't find DOM element for Monitor"+monId + "monitorPtr.length="+len); + } else { + monitorCanvasCtx[monId]=monitorCanvasObj[monId].getContext('2d'); + monitorImageObject[monId]=new Image(); + monitorImageObject[monId].src = monitorImageURL[monId]; + monitorImageObject[monId].monId = monId; + monitorImageObject[monId].onload = function() {imagedone(this, this.monId, true )}; + monitorImageObject[monId].onerror = function() {imagedone(this, this.monId, false )}; + } + } drawGraph(); setSpeed(speedIndex); diff --git a/web/skins/classic/views/js/montagereview.js.php b/web/skins/classic/views/js/montagereview.js.php index 8248a2c67..29ef15245 100644 --- a/web/skins/classic/views/js/montagereview.js.php +++ b/web/skins/classic/views/js/montagereview.js.php @@ -24,8 +24,8 @@ var groupStr=; // Because we might not have time as the criteria, figure out the min/max time when we run the query -$minTimeSecs = strtotime("2036-01-01 01:01:01"); -$maxTimeSecs = strtotime("1950-01-01 01:01:01"); +$minTimeSecs = strtotime('2036-01-01 01:01:01'); +$maxTimeSecs = strtotime('1950-01-01 01:01:01'); // This builds the list of events that are eligible from this range @@ -33,34 +33,36 @@ $index=0; $anyAlarms=false; foreach( dbFetchAll( $eventsSql ) as $event ) { - if( $minTimeSecs > $event['StartTimeSecs']) $minTimeSecs = $event['StartTimeSecs']; - if( $maxTimeSecs < $event['CalcEndTimeSecs']) $maxTimeSecs = $event['CalcEndTimeSecs']; - echo "eMonId[$index]=" . $event['MonitorId'] . "; - eId[$index]=" . $event['Id'] . "; - eStartSecs[$index]=" . $event['StartTimeSecs'] . "; - eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; - eventFrames[$index]=" . $event['Frames'] . ";\n"; + if ( $minTimeSecs > $event['StartTimeSecs'] ) $minTimeSecs = $event['StartTimeSecs']; + if ( $maxTimeSecs < $event['CalcEndTimeSecs'] ) $maxTimeSecs = $event['CalcEndTimeSecs']; + echo " +eMonId[$index]=" . $event['MonitorId'] . "; +eId[$index]=" . $event['Id'] . "; +eStartSecs[$index]=" . $event['StartTimeSecs'] . "; +eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; +eventFrames[$index]=" . $event['Frames'] . "; - $index = $index + 1; - if($event['MaxScore']>0) - $anyAlarms = true; - echo "\n"; +"; + + $index = $index + 1; + if ( $event['MaxScore'] > 0 ) + $anyAlarms = true; } // if there is no data set the min/max to the passed in values -if($index == 0) { - if(isset($minTime) && isset($maxTime)) { +if ( $index == 0 ) { + if ( isset($minTime) && isset($maxTime) ) { $minTimeSecs = strtotime($minTime); $maxTimeSecs = strtotime($maxTime); } else { // this is the case of no passed in times AND no data -- just set something arbitrary - $minTimeSecs=strtotime('1950-06-01 01:01:01'); // random time so there's something to display - $maxTimeSecs=time() + 86400; + $minTimeSecs = strtotime('1950-06-01 01:01:01'); // random time so there's something to display + $maxTimeSecs = time() + 86400; } } // We only reset the calling time if there was no calling time -if(!isset($minTime) || !isset($maxTime)) { +if ( !isset($minTime) || !isset($maxTime) ) { $maxTime = strftime($maxTimeSecs); $minTime = strftime($minTimeSecs); } else { @@ -82,42 +84,47 @@ $fromSecs=-1; $toSecs=-1; $maxScore=-1; -if($anyAlarms) { +if ( $anyAlarms ) { foreach( dbFetchAll ($frameSql) as $frame ) { - if($mId<0) { - $mId=$frame['MonitorId']; - $fromSecs=$frame['TimeStampSecs']; - $toSecs=$frame['TimeStampSecs']; - $maxScore=$frame['Score']; - } else if ($mId != $frame['MonitorId'] || $frame['TimeStampSecs'] - $toSecs > 10) { + if ( $mId < 0 ) { + $mId = $frame['MonitorId']; + $fromSecs = $frame['TimeStampSecs']; + $toSecs = $frame['TimeStampSecs']; + $maxScore = $frame['Score']; + } else if ( $mId != $frame['MonitorId'] || $frame['TimeStampSecs'] - $toSecs > 10 ) { // dump this one start a new $index++; - echo " fMonId[$index]=" . $mId . ";"; - echo " fTimeFromSecs[$index]=" . $fromSecs . ";"; - echo " fTimeToSecs[$index]=" . $toSecs . ";"; - echo " fScore[$index]=" . $maxScore . ";\n"; - $mId=$frame['MonitorId']; - $fromSecs=$frame['TimeStampSecs']; - $toSecs=$frame['TimeStampSecs']; - $maxScore=$frame['Score']; + echo " + fMonId[$index]= $mId; + fTimeFromSecs[$index]= $fromSecs; + fTimeToSecs[$index]= $toSecs; + fScore[$index]= $maxScore; +"; + $mId = $frame['MonitorId']; + $fromSecs = $frame['TimeStampSecs']; + $toSecs = $frame['TimeStampSecs']; + $maxScore = $frame['Score']; } else { // just add this one on - $toSecs=$frame['TimeStampSecs']; - if($maxScore < $frame['Score']) $maxScore=$frame['Score']; + $toSecs = $frame['TimeStampSecs']; + if ( $maxScore < $frame['Score'] ) $maxScore = $frame['Score']; } } } -if($mId>0) { - echo " fMonId[$index]=" . $mId . ";"; - echo " fTimeFromSecs[$index]=" . $fromSecs . ";"; - echo " fTimeToSecs[$index]=" . $toSecs . ";"; - echo " fScore[$index]=" . $maxScore . ";\n"; +if ( $mId > 0 ) { + echo " + fMonId[$index]= $mId; + fTimeFromSecs[$index]= $fromSecs; + fTimeToSecs[$index]= $toSecs; + fScore[$index]= $maxScore; +"; } echo "var maxScore=$maxScore;\n"; // used to skip frame load if we find no alarms. echo "var monitorName = [];\n"; echo "var monitorLoading = [];\n"; echo "var monitorImageObject = [];\n"; +echo "var monitorImageURL = [];\n"; echo "var monitorLoadingStageURL = [];\n"; echo "var monitorLoadStartTimems = [];\n"; echo "var monitorLoadEndTimems = [];\n"; @@ -135,20 +142,17 @@ echo "var monitorPtr = []; // monitorName[monitorPtr[0]] is first monitor\n"; $numMonitors=0; // this array is indexed by the monitor ID for faster access later, so it may be sparse $avgArea=floatval(0); // Calculations the normalizing scale -foreach ($monitors as $m) { +foreach ( $monitors as $m ) { $avgArea = $avgArea + floatval($m->Width() * $m->Height()); $numMonitors++; } -if($numMonitors>0) $avgArea= $avgArea / $numMonitors; +if ( $numMonitors > 0 ) $avgArea = $avgArea / $numMonitors; -$numMonitors=0; -foreach ($monitors as $m) { +$numMonitors = 0; +foreach ( $monitors as $m ) { echo " monitorLoading[" . $m->Id() . "]=false;\n"; - echo " monitorImageObject[" . $m->Id() . "]=new Image();\n"; - echo " monitorImageObject[" . $m->Id() . "].src='".$m->getStreamSrc( array('mode'=>'single','scale'=>$defaultScale) )."';\n"; - echo " monitorImageObject[" . $m->Id() . "].onload = function() {imagedone(this, ".$m->Id().",true )};\n"; - echo " monitorImageObject[" . $m->Id() . "].onerror = function() {imagedone(this, ".$m->Id().",false )};\n"; + echo " monitorImageURL[" . $m->Id() . "]='".$m->getStreamSrc( array('mode'=>'single','scale'=>$defaultScale), '&' )."';\n"; echo " monitorLoadingStageURL[" . $m->Id() . "] = '';\n"; echo " monitorColour[" . $m->Id() . "]=\"" . $m->WebColour() . "\";\n"; echo " monitorWidth[" . $m->Id() . "]=" . $m->Width() . ";\n"; @@ -174,13 +178,13 @@ if(isset($defaultCurrentTime)) else echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n"; -echo "var speeds=["; +echo 'var speeds=['; for ($i=0; $i0)?", ":"") . $speeds[$i]; + echo (($i>0)?', ':'') . $speeds[$i]; echo "];\n"; ?> -var scrubAsObject=document.getElementById('scrub'); +var scrubAsObject=$('scrub'); var cWidth; // save canvas width var cHeight; // save canvas height var canvas; // global canvas definition so we don't have to keep looking it up