use CakePHP-Enum-Behavior to add support for ENUMs to the Monitor model. This should fix #48
This commit is contained in:
parent
b62343fb2c
commit
1b1b93f811
|
@ -2,3 +2,6 @@
|
||||||
path = web/api/app/Plugin/Crud
|
path = web/api/app/Plugin/Crud
|
||||||
url = https://github.com/FriendsOfCake/crud.git
|
url = https://github.com/FriendsOfCake/crud.git
|
||||||
branch = 3.0
|
branch = 3.0
|
||||||
|
[submodule "web/api/app/Plugin/CakePHP-Enum-Behavior"]
|
||||||
|
path = web/api/app/Plugin/CakePHP-Enum-Behavior
|
||||||
|
url = https://github.com/asper/CakePHP-Enum-Behavior.git
|
||||||
|
|
|
@ -70,6 +70,7 @@ Cache::config('default', array('engine' => 'Apc'));
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
CakePlugin::load('Crud');
|
CakePlugin::load('Crud');
|
||||||
|
CakePlugin::load('CakePHP-Enum-Behavior');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can attach event listeners to the request lifecycle as Dispatcher Filter. By default CakePHP bundles two filters:
|
* You can attach event listeners to the request lifecycle as Dispatcher Filter. By default CakePHP bundles two filters:
|
||||||
|
|
|
@ -15,10 +15,13 @@ class MonitorsController extends AppController {
|
||||||
*/
|
*/
|
||||||
public $components = array('Paginator', 'RequestHandler');
|
public $components = array('Paginator', 'RequestHandler');
|
||||||
|
|
||||||
|
public function beforeRender() {
|
||||||
|
$this->set($this->Monitor->enumValues());
|
||||||
|
}
|
||||||
public function beforeFilter() {
|
public function beforeFilter() {
|
||||||
parent::beforeFilter();
|
parent::beforeFilter();
|
||||||
$canView = $this->Session->Read('monitorPermission');
|
$canView = $this->Session->Read('monitorPermission');
|
||||||
if ($canView =='None') {
|
if ($canView == 'None') {
|
||||||
throw new UnauthorizedException(__('Insufficient Privileges'));
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -109,10 +112,9 @@ class MonitorsController extends AppController {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add() {
|
public function add() {
|
||||||
if ($this->request->is('post')) {
|
if ( $this->request->is('post') ) {
|
||||||
|
|
||||||
if ($this->Session->Read('systemPermission') != 'Edit')
|
if ( $this->Session->Read('systemPermission') != 'Edit' ) {
|
||||||
{
|
|
||||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,8 +122,15 @@ class MonitorsController extends AppController {
|
||||||
$this->Monitor->create();
|
$this->Monitor->create();
|
||||||
if ($this->Monitor->save($this->request->data)) {
|
if ($this->Monitor->save($this->request->data)) {
|
||||||
$this->daemonControl($this->Monitor->id, 'start');
|
$this->daemonControl($this->Monitor->id, 'start');
|
||||||
return $this->flash(__('The monitor has been saved.'), array('action' => 'index'));
|
//return $this->flash(__('The monitor has been saved.'), array('action' => 'index'));
|
||||||
|
$message = 'Saved';
|
||||||
|
} else {
|
||||||
|
$message = 'Error';
|
||||||
}
|
}
|
||||||
|
$this->set(array(
|
||||||
|
'message' => $message,
|
||||||
|
'_serialize' => array('message')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +147,7 @@ class MonitorsController extends AppController {
|
||||||
if (!$this->Monitor->exists($id)) {
|
if (!$this->Monitor->exists($id)) {
|
||||||
throw new NotFoundException(__('Invalid monitor'));
|
throw new NotFoundException(__('Invalid monitor'));
|
||||||
}
|
}
|
||||||
if ($this->Session->Read('monitorPermission') != 'Edit')
|
if ($this->Session->Read('monitorPermission') != 'Edit') {
|
||||||
{
|
|
||||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,10 @@ class Monitor extends AppModel {
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * hasMany associations
|
* hasMany associations
|
||||||
* *
|
*
|
||||||
* * @var array
|
* @var array
|
||||||
* */
|
*/
|
||||||
public $hasAndBelongsToMany = array(
|
public $hasAndBelongsToMany = array(
|
||||||
'Group' => array(
|
'Group' => array(
|
||||||
'className' => 'Group',
|
'className' => 'Group',
|
||||||
|
@ -108,5 +108,16 @@ class Monitor extends AppModel {
|
||||||
'counterQuery' => ''
|
'counterQuery' => ''
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
public $actsAs = array(
|
||||||
|
'CakePHP-Enum-Behavior.Enum' => array(
|
||||||
|
'Type' => array('Local','Remote','File','Ffmpeg','Libvlc','cURL'),
|
||||||
|
'Function' => array('None','Monitor','Modect','Record','Mocord','Nodect'),
|
||||||
|
'Orientation' => array('0','90','180','270','hori','vert'),
|
||||||
|
'OutputCodec' => array('h264','mjpeg','mpeg1','mpeg2'),
|
||||||
|
'OutputContainer' => array('auto','mp4','mkv'),
|
||||||
|
'DefaultView' => array('Events','Control'),
|
||||||
|
'Status' => array('Unknown','NotRunning','Running','NoSignal','Signal'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7108489f218c54d36d235d3af91d6da2f8311237
|
|
@ -0,0 +1,2 @@
|
||||||
|
echo json_encode($message);
|
||||||
|
echo json_encode($monitor);
|
|
@ -0,0 +1,2 @@
|
||||||
|
$xml = Xml::fromArray(array('response' => $message));
|
||||||
|
echo $xml->asXML();
|
Loading…
Reference in New Issue