From 13b49ba2c4e15b852e1476cd6b80bbbca8987e71 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 17 Jul 2019 20:55:59 +0200 Subject: [PATCH] add devel/grid_example sample from our docs --- devel/grid_example/Makefile | 6 ++ devel/grid_example/pkg-descr | 4 ++ .../GridExample/Api/SettingsController.php | 71 +++++++++++++++++++ .../OPNsense/GridExample/IndexController.php | 42 +++++++++++ .../GridExample/forms/dialogAddress.xml | 13 ++++ .../models/OPNsense/GridExample/ACL/ACL.xml | 9 +++ .../OPNsense/GridExample/GridExample.php | 35 +++++++++ .../OPNsense/GridExample/GridExample.xml | 19 +++++ .../models/OPNsense/GridExample/Menu/Menu.xml | 5 ++ .../app/views/OPNsense/GridExample/index.volt | 68 ++++++++++++++++++ 10 files changed, 272 insertions(+) create mode 100644 devel/grid_example/Makefile create mode 100644 devel/grid_example/pkg-descr create mode 100644 devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/Api/SettingsController.php create mode 100644 devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/IndexController.php create mode 100644 devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/forms/dialogAddress.xml create mode 100644 devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/ACL/ACL.xml create mode 100644 devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/GridExample.php create mode 100644 devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/GridExample.xml create mode 100644 devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/Menu/Menu.xml create mode 100644 devel/grid_example/src/opnsense/mvc/app/views/OPNsense/GridExample/index.volt diff --git a/devel/grid_example/Makefile b/devel/grid_example/Makefile new file mode 100644 index 000000000..dfc4cf776 --- /dev/null +++ b/devel/grid_example/Makefile @@ -0,0 +1,6 @@ +PLUGIN_NAME= grid_example +PLUGIN_VERSION= 1.0 +PLUGIN_COMMENT= A sample framework application +PLUGIN_MAINTAINER= ad@opnsense.org + +.include "../../Mk/plugins.mk" diff --git a/devel/grid_example/pkg-descr b/devel/grid_example/pkg-descr new file mode 100644 index 000000000..6b92b42fb --- /dev/null +++ b/devel/grid_example/pkg-descr @@ -0,0 +1,4 @@ +The goal of the "grid_example" plugin is to showcase the capabilities +of the OPNsense plugin framework in relation to the grid/table system. + +WWW: https://docs.opnsense.org/development/examples/using_grids.html diff --git a/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/Api/SettingsController.php b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/Api/SettingsController.php new file mode 100644 index 000000000..b0ec04b77 --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/Api/SettingsController.php @@ -0,0 +1,71 @@ +searchBase("addresses.address", array('enabled', 'email'), "email"); + } + + public function setItemAction($uuid) + { + return $this->setBase("address", "addresses.address", $uuid); + } + + public function addItemAction() + { + return $this->addBase("address", "addresses.address"); + } + + public function getItemAction($uuid = null) + { + return $this->getBase("address", "addresses.address", $uuid); + } + + public function delItemAction($uuid) + { + return $this->delBase("addresses.address", $uuid); + } + + public function toggleItemAction($uuid, $enabled = null) + { + return $this->toggleBase("addresses.address", $uuid, $enabled); + } +} diff --git a/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/IndexController.php b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/IndexController.php new file mode 100644 index 000000000..ac070c662 --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/IndexController.php @@ -0,0 +1,42 @@ +view->pick('OPNsense/GridExample/index'); + $this->view->formDialogAddress = $this->getForm("dialogAddress"); + } +} diff --git a/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/forms/dialogAddress.xml b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/forms/dialogAddress.xml new file mode 100644 index 000000000..9a65a91a7 --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/controllers/OPNsense/GridExample/forms/dialogAddress.xml @@ -0,0 +1,13 @@ +
+ + address.enabled + + checkbox + Enable this address + + + address.email + + text + +
diff --git a/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/ACL/ACL.xml b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/ACL/ACL.xml new file mode 100644 index 000000000..6fb024088 --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/ACL/ACL.xml @@ -0,0 +1,9 @@ + + + Lobby: GridExample + + ui/gridexample/* + api/gridexample/* + + + diff --git a/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/GridExample.php b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/GridExample.php new file mode 100644 index 000000000..4b06e192a --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/GridExample.php @@ -0,0 +1,35 @@ + + //OPNsense/GridExample + + the OPNsense "GridExample" application + + + +
+ + 1 + Y + + + Y + +
+
+
+ diff --git a/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/Menu/Menu.xml b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/Menu/Menu.xml new file mode 100644 index 000000000..a70ef4dc7 --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/models/OPNsense/GridExample/Menu/Menu.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/devel/grid_example/src/opnsense/mvc/app/views/OPNsense/GridExample/index.volt b/devel/grid_example/src/opnsense/mvc/app/views/OPNsense/GridExample/index.volt new file mode 100644 index 000000000..f6249956c --- /dev/null +++ b/devel/grid_example/src/opnsense/mvc/app/views/OPNsense/GridExample/index.volt @@ -0,0 +1,68 @@ +{# + +Copyright (c) 2019 by Deciso B.V. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +#} + + + + + + + + + + + + + + + + + + + + +
{{ lang._('ID') }}{{ lang._('Enabled') }}{{ lang._('Email') }}{{ lang._('Commands') }}
+ + +
+ + +{{ partial("layout_partials/base_dialog",['fields':formDialogAddress,'id':'DialogAddress','label':lang._('Edit address')])}}