From 05c8ddf153f1aec2496b7867912740b04c0e4482 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Fri, 24 May 2013 20:13:14 -0400 Subject: [PATCH] Reworked to allow displaying of monitors from many views with less code. * Moved getStreamSrc from Monitors Controller to Monitors Model * Minor indenting of code * Removed some old code * Changed how I lookup ZM_MPEG_LIVE_FORMAT from within getStreamSrc * Changed Monitors View view to use divs instead of tables --- web/app/Controller/MonitorsController.php | 36 +++++------------------ web/app/Model/Monitor.php | 18 +++++++++++- web/app/View/Monitors/index.ctp | 23 ++++----------- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index 12df03d6b..b079d1683 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -3,21 +3,17 @@ public $helpers = array('LiveStream'); public function index() { - $monitoroptions['fields'] = array('Name', 'Id', 'Function'); + $zmBandwidth = $this->Cookie->read('zmBandwidth'); + $monitoroptions = array( 'fields' => array('Name', 'Id', 'Function'), 'recursive' => -1); $this->set('monitors', $this->Monitor->find('all', $monitoroptions)); - $monitors = $this->Monitor->find('list', array('fields' => array('Id'))); - $intervals = array('HOUR', 'DAY', 'WEEK', 'MONTH'); - foreach ($monitors as $monitor) { - foreach ($intervals as $interval) { - - } - } - - + $monitors = $this->Monitor->find('all', array('recursive' => -1, 'fields' => array('Id', 'StreamReplayBuffer'))); + foreach ($monitors as $monitor => $mon) { + $streamSrc[$monitor] = $this->Monitor->getStreamSrc($monitor['Monitor']['Id'], $zmBandwidth, $monitor['Monitor']['StreamReplayBuffer']); + } + $this->set('streamSrc', $streamSrc); } public function view($id = null) { - $this->loadModel('Config'); if (!$id) { throw new NotFoundException(__('Invalid monitor')); } @@ -30,24 +26,8 @@ $zmBandwidth = $this->Cookie->read('zmBandwidth'); - - $ZM_MPEG_LIVE_FORMAT = $this->Config->find('first', array( - 'fields' => array('Value'), 'conditions' => array('Name' => 'ZM_MPEG_LIVE_FORMAT') - )); - - $ZM_WEB_STREAM_METHOD = $this->Config->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth); - $ZM_WEB_VIDEO_BITRATE = $this->Config->getWebOption('ZM_WEB_VIDEO_BITRATE', $zmBandwidth); - $ZM_WEB_VIDEO_MAXFPS = $this->Config->getWebOption('ZM_WEB_VIDEO_MAXFPS', $zmBandwidth); - $ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT['Config']['Value']; $buffer = $monitor['Monitor']['StreamReplayBuffer']; - - if ($ZM_WEB_STREAM_METHOD == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) { - $this->set('streamSrc', "/cgi-bin/nph-zms?mode=mpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT"); - } else { - $this->set('streamSrc', "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer"); - } - - + $this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer)); } diff --git a/web/app/Model/Monitor.php b/web/app/Model/Monitor.php index 06e1e10e7..9f050e2a0 100644 --- a/web/app/Model/Monitor.php +++ b/web/app/Model/Monitor.php @@ -13,6 +13,22 @@ 'foreignKey' => 'MonitorId', 'fields' => 'Zone.Id' ) - ); +); + + public function getStreamSrc($id = null, $zmBandwidth, $buffer) { + + $ZM_MPEG_LIVE_FORMAT = Configure::read('ZM_MPEG_LIVE_FORMAT'); + $ZM_WEB_STREAM_METHOD = ClassRegistry::init('Config')->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth); + $ZM_WEB_VIDEO_BITRATE = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_BITRATE', $zmBandwidth); + $ZM_WEB_VIDEO_MAXFPS = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_MAXFPS', $zmBandwidth); + $ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT; + + if ($ZM_WEB_STREAM_METHOD == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) { + return "/cgi-bin/nph-zms?mode=mpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT"; + } else { + return "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer"; + } + + } } ?> diff --git a/web/app/View/Monitors/index.ctp b/web/app/View/Monitors/index.ctp index 0349eb9c6..34da398af 100644 --- a/web/app/View/Monitors/index.ctp +++ b/web/app/View/Monitors/index.ctp @@ -1,23 +1,12 @@

Monitors

- - - - - - - - - - - - + $mon): ?> +
+ Html->link($mon['Monitor']['Name'],array('controller' => 'monitors', 'action' => 'view', $mon['Monitor']['Id'])); ?> + LiveStream->makeLiveStream($mon['Monitor']['Name'], $streamSrc[$monitor], $mon['Monitor']['Id']); ?> + Html->link($mon['Monitor']['Function'], array('action' => 'edit', $mon['Monitor']['Id'])); ?> +
-
NameFunctionZones
- Html->link($monitor['Monitor']['Name'],array('controller' => 'monitors', 'action' => 'view', $monitor['Monitor']['Id'])); ?> - - Html->link($monitor['Monitor']['Function'], array('action' => 'edit', $monitor['Monitor']['Id'])); ?> -
Html->link( 'Add Monitor', array('controller' => 'monitors', 'action' => 'add')