mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
(Traffic shaper) work in progress, initial searchable grid implementation
This commit is contained in:
parent
a6198444b7
commit
a72ac678a4
@ -31,102 +31,60 @@ namespace OPNsense\TrafficShaper\Api;
|
||||
use \OPNsense\Base\ApiControllerBase;
|
||||
use \OPNsense\Core\Config;
|
||||
use \OPNsense\TrafficShaper\TrafficShaper;
|
||||
use \OPNsense\Base\UIModelGrid;
|
||||
|
||||
/**
|
||||
* Class SettingsController
|
||||
* Class SettingsController Handles settings related API actions for the Traffic Shaper
|
||||
* @package OPNsense\Proxy
|
||||
*/
|
||||
class SettingsController extends ApiControllerBase
|
||||
{
|
||||
/**
|
||||
* retrieve settings
|
||||
* retrieve pipe settings
|
||||
* @param $uuid item unique id
|
||||
* @return array
|
||||
*/
|
||||
public function getAction()
|
||||
public function getPipeAction($uuid)
|
||||
{
|
||||
$result = array('rows'=>array());
|
||||
|
||||
for ($i=1; $i<100; $i++) {
|
||||
$result['rows'][] = array('id'=>$i,'sender'=>$i.'xyz','receiver'=>'xxx'.$i);
|
||||
if ($uuid != null) {
|
||||
$mdlShaper = new TrafficShaper();
|
||||
$node = $mdlShaper->getNodeByReference('pipes.pipe.'.$uuid);
|
||||
if ($node != null) {
|
||||
return $node->getNodes();
|
||||
}
|
||||
}
|
||||
|
||||
$result['rowCount'] = count($result['rows']);
|
||||
$result['current'] = 1;
|
||||
|
||||
return $result;
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve settings
|
||||
* search traffic shaper pipes
|
||||
* @return array
|
||||
*/
|
||||
public function searchPipesAction()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$mdlShaper = new TrafficShaper();
|
||||
// fetch query parameters
|
||||
$itemsPerPage = $this->request->getPost('rowCount', 'int', 9999);
|
||||
$currentPage = $this->request->getPost('current', 'int', 1);
|
||||
$sortBy = array("number");
|
||||
$sortDescending = false;
|
||||
|
||||
// parse search parameters
|
||||
if ($this->request->hasPost('rowCount')) {
|
||||
$itemsPerPage = $this->request->getPost('rowCount');
|
||||
} else {
|
||||
$itemsPerPage = 9999;
|
||||
}
|
||||
if ($this->request->hasPost('current')) {
|
||||
$currentPage = $this->request->getPost('current');
|
||||
} else {
|
||||
$currentPage = 1;
|
||||
}
|
||||
|
||||
if ($this->request->hasPost('sort')) {
|
||||
if ($this->request->hasPost('sort') && is_array($this->request->getPost("sort"))) {
|
||||
$sortBy = array_keys($this->request->getPost("sort"));
|
||||
if ($this->request->getPost("sort")[$sortBy[0]] == "desc") {
|
||||
$sortDescending = true;
|
||||
} else {
|
||||
$sortDescending = false;
|
||||
}
|
||||
} else {
|
||||
$sortBy = array("number");
|
||||
$sortDescending = false;
|
||||
}
|
||||
|
||||
$searchPhrase = $this->request->getPost('searchPhrase', 'string', '');
|
||||
|
||||
|
||||
//searchPhrase
|
||||
//sort
|
||||
|
||||
//$mdlShaper
|
||||
|
||||
$result = array('rows'=>array());
|
||||
|
||||
$fields = array("number", "bandwidth","bandwidthMetric");
|
||||
$recordIndex = 0;
|
||||
foreach ($mdlShaper->pipes->pipe->sortedBy($sortBy, $sortDescending) as $pipe) {
|
||||
if (count($result['rows']) < $itemsPerPage &&
|
||||
$recordIndex >= ($itemsPerPage*($currentPage-1))
|
||||
) {
|
||||
$row = array();
|
||||
$row['uuid'] = $pipe->getAttributes()['uuid'];
|
||||
foreach ($fields as $fieldname) {
|
||||
$row[$fieldname] = $pipe->$fieldname->getNodeData();
|
||||
if (is_array($row[$fieldname])) {
|
||||
foreach ($row[$fieldname] as $fieldKey => $fieldValue) {
|
||||
if ($fieldValue['selected'] == 1) {
|
||||
$row[$fieldname] = $fieldValue['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$result['rows'][] = $row;
|
||||
}
|
||||
$recordIndex++;
|
||||
}
|
||||
|
||||
|
||||
$result['rowCount'] = count($result['rows']);
|
||||
$result['total'] = $recordIndex;
|
||||
$result['current'] = (int)$currentPage;
|
||||
|
||||
return $result;
|
||||
// create model and fetch query resuls
|
||||
$fields = array("number", "bandwidth","bandwidthMetric","description");
|
||||
$mdlShaper = new TrafficShaper();
|
||||
$grid = new UIModelGrid($mdlShaper->pipes->pipe);
|
||||
return $grid->fetch($fields, $itemsPerPage, $currentPage, $sortBy, $sortDescending, $searchPhrase);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -53,7 +53,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
/* Executes after data is loaded and rendered */
|
||||
grid.find(".command-edit").on("click", function(e)
|
||||
{
|
||||
alert("You pressed edit on row: " + $(this).data("row-id"));
|
||||
$('#form_uuid').attr('value',$(this).data("row-id"));
|
||||
$('#myModal').modal();
|
||||
}).end().find(".command-delete").on("click", function(e)
|
||||
{
|
||||
alert("You pressed delete on row: " + $(this).data("row-id"));
|
||||
@ -64,7 +65,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
$("#test").click(function(){
|
||||
var rows =$("#grid-basic").bootgrid('getSelectedRows');
|
||||
alert(rows);
|
||||
$("#grid-basic").bootgrid("reload")
|
||||
$("#grid-basic").bootgrid("reload");
|
||||
setFormData('testfrm')
|
||||
// var rowIds = [];
|
||||
// for (var i = 0; i < rows.length; i++)
|
||||
// {
|
||||
@ -80,14 +82,13 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<table id="grid-basic" class="table table-condensed table-hover table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="number" data-type="number">Number</th>
|
||||
<th data-column-id="bandwidth" data-type="number">Bandwidth</th>
|
||||
<th data-column-id="bandwidthMetric" data-type="string">BandwidthMetric</th>
|
||||
<th data-column-id="description" data-type="string">description</th>
|
||||
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">ID</th>
|
||||
</tr>
|
||||
@ -101,4 +102,43 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
<th></th>
|
||||
<th><button id="test">test</button></th>
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="testfrm">
|
||||
<input id="form_uuid">
|
||||
<table class="table table-striped table-condensed table-responsive">
|
||||
<colgroup>
|
||||
<col class="col-md-3"/>
|
||||
<col class="col-md-4"/>
|
||||
<col class="col-md-5"/>
|
||||
</colgroup>
|
||||
<tbody>
|
||||
{{ partial("layout_partials/form_input_tr",
|
||||
['id': 'general.port',
|
||||
'label':'port',
|
||||
'type':'text',
|
||||
'help':'kjdhkjashdkjds'
|
||||
])
|
||||
}}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user