Commit 05194786 authored by Per von Zweigbergk's avatar Per von Zweigbergk

(base) Fixups of ApiMutableTableModelControllerBase

Changed base class from ApiControllerBase to ApiMutableModelControllerBase
Fixed incorrect string concatenation (+ instead of .) in getNodes()
Removed stray parentheses
Extracted static fields for gridFields and gridDefaultSort
parent ea9be4a9
...@@ -34,14 +34,15 @@ namespace OPNsense\Base; ...@@ -34,14 +34,15 @@ namespace OPNsense\Base;
* an API that exposes a model for tables. * an API that exposes a model for tables.
* @package OPNsense\Base * @package OPNsense\Base
*/ */
abstract class ApiMutableTableModelControllerBase extends ApiControllerBase abstract class ApiMutableTableModelControllerBase extends ApiMutableModelControllerBase
{ {
// FIXME What about validation? // FIXME What about validation?
static protected $modelPathPrefix = ''; static protected $modelPathPrefix = '';
static protected $gridFields = array();
static protected $gridDefaultSort = null;
private function getNodes() { private function getNodes() {
$ref = static::$modelPathPrefix $ref = static::$modelPathPrefix . static::$internalModelName;
+ static::$internalModelName;
return $this->getModel()->getNodeByReference($ref); return $this->getModel()->getNodeByReference($ref);
} }
private function getNodeByUUID($uuid) { private function getNodeByUUID($uuid) {
...@@ -98,12 +99,12 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase ...@@ -98,12 +99,12 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
public function addItemAction() public function addItemAction()
{ {
$result = array("result"=>"failed"); $result = array("result"=>"failed");
if ($this->request->isPost() && $this->request->hasPost(static::$internalModelName))) { if ($this->request->isPost() && $this->request->hasPost(static::$internalModelName)) {
$mdl = $this->getModel(); $mdl = $this->getModel();
// FIXME Is this correct? // FIXME Is this correct?
$node = $this->getNodes()->add(); $node = $this->getNodes()->add();
$node->setNodes($this->request->getPost(static::$internalModelName))); $node->setNodes($this->request->getPost(static::$internalModelName));
return $this->save($mdl, $node, static::$internalModelName)); return $this->save($mdl, $node, static::$internalModelName);
} }
return $result; return $result;
} }
...@@ -172,11 +173,6 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase ...@@ -172,11 +173,6 @@ abstract class ApiMutableTableModelControllerBase extends ApiControllerBase
$this->sessionClose(); $this->sessionClose();
$mdl = $this->getModel(); $mdl = $this->getModel();
$grid = new UIModelGrid($this->getNodes()); $grid = new UIModelGrid($this->getNodes());
return $grid->fetchBindRequest( return $grid->fetchBindRequest($this->request, static::$gridFields, static::$gridDefaultSort);
$this->request,
// FIXME Where do we get this list from? Is this something to be supplied by class implementor?
array("enabled","number", "bandwidth","bandwidthMetric","burst","description","mask","origin"),
"number"
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment