add devel/grid_example sample from our docs

This commit is contained in:
Ad Schellevis 2019-07-17 20:55:59 +02:00
parent f69b0c1337
commit 13b49ba2c4
10 changed files with 272 additions and 0 deletions

View file

@ -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"

View file

@ -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

View file

@ -0,0 +1,71 @@
<?php
/**
* Copyright (C) 2019 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.
*
*/
namespace OPNsense\GridExample\Api;
use \OPNsense\Base\ApiMutableModelControllerBase;
/**
* a settings controller for our GridExample app, uses our ApiMutableModelControllerBase type
* @package OPNsense\GridExample
*/
class SettingsController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'gridexample';
protected static $internalModelClass = 'OPNsense\GridExample\GridExample';
public function searchItemAction()
{
return $this->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);
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Copyright (C) 2019 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.
*
*/
namespace OPNsense\GridExample;
/**
* Class IndexController
* @package OPNsense\GridExample
*/
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->pick('OPNsense/GridExample/index');
$this->view->formDialogAddress = $this->getForm("dialogAddress");
}
}

View file

@ -0,0 +1,13 @@
<form>
<field>
<id>address.enabled</id>
<label>enabled</label>
<type>checkbox</type>
<help>Enable this address</help>
</field>
<field>
<id>address.email</id>
<label>Email</label>
<type>text</type>
</field>
</form>

View file

@ -0,0 +1,9 @@
<acl>
<page-user-gridexample>
<name>Lobby: GridExample</name>
<patterns>
<pattern>ui/gridexample/*</pattern>
<pattern>api/gridexample/*</pattern>
</patterns>
</page-user-gridexample>
</acl>

View file

@ -0,0 +1,35 @@
<?php
/**
* Copyright (C) 2019 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.
*
*/
namespace OPNsense\GridExample;
use OPNsense\Base\BaseModel;
class GridExample extends BaseModel
{
}

View file

@ -0,0 +1,19 @@
<model>
<mount>//OPNsense/GridExample</mount>
<description>
the OPNsense "GridExample" application
</description>
<items>
<addresses>
<address type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<email type="EmailField">
<Required>Y</Required>
</email>
</address>
</addresses>
</items>
</model>

View file

@ -0,0 +1,5 @@
<menu>
<Lobby>
<GridExample VisibleName="Grid Example" cssClass="fa fa-comment-o fa-fw" url="/ui/gridexample"/>
</Lobby>
</menu>

View file

@ -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.
#}
<script>
$( document ).ready(function() {
$("#grid-addresses").UIBootgrid(
{ search:'/api/gridexample/settings/searchItem/',
get:'/api/gridexample/settings/getItem/',
set:'/api/gridexample/settings/setItem/',
add:'/api/gridexample/settings/addItem/',
del:'/api/gridexample/settings/delItem/',
toggle:'/api/gridexample/settings/toggleItem/'
}
);
});
</script>
<table id="grid-addresses" class="table table-condensed table-hover table-striped" data-editDialog="DialogAddress">
<thead>
<tr>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="email" data-type="string">{{ lang._('Email') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
{{ partial("layout_partials/base_dialog",['fields':formDialogAddress,'id':'DialogAddress','label':lang._('Edit address')])}}