SycPropertyForm: Prepared form for sync property. refs: #9709
This commit is contained in:
parent
6d65ce5066
commit
250fbeabe2
|
@ -67,6 +67,19 @@ class Director_ListController extends ActionController
|
|||
$this->render('table');
|
||||
}
|
||||
|
||||
public function syncpropertyAction()
|
||||
{
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('Add sync property rule'),
|
||||
'director/syncproperty/add'
|
||||
);
|
||||
|
||||
$this->setImportTabs()->activate('syncproperty');
|
||||
$this->view->title = $this->translate('Sync property');
|
||||
$this->view->table = $this->loadTable('syncproperty')->setConnection($this->db());
|
||||
$this->render('table');
|
||||
}
|
||||
|
||||
public function datalistentryAction()
|
||||
{
|
||||
$listId = $this->params->get('list_id');
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Objects\SyncProperty;
|
||||
use Icinga\Module\Director\Sync\Sync;
|
||||
use Icinga\Exception\InvalidPropertyException;
|
||||
use Icinga\Web\Notification;
|
||||
|
||||
class Director_SyncpropertyController extends ActionController
|
||||
{
|
||||
public function addAction()
|
||||
{
|
||||
$this->forward('index', 'syncproperty', 'director');
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
{
|
||||
$this->forward('index', 'syncproperty', 'director');
|
||||
}
|
||||
|
||||
public function runAction()
|
||||
{
|
||||
if ($runId = Import::run($id = SyncProperty::load($this->params->get('id'), $this->db()))) {
|
||||
Notification::success('adf' . $runId);
|
||||
$this->redirectNow('director/list/syncproperty');
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$edit = false;
|
||||
|
||||
if ($id = $this->params->get('id')) {
|
||||
$edit = true;
|
||||
}
|
||||
|
||||
if ($edit) {
|
||||
$this->view->title = $this->translate('Edit sync property rule');
|
||||
$this->getTabs()->add('edit', array(
|
||||
'url' => 'director/syncproperty/edit' . '?id=' . $id,
|
||||
'label' => $this->view->title,
|
||||
))->activate('edit');
|
||||
} else {
|
||||
$this->view->title = $this->translate('Add sync property rule');
|
||||
$this->getTabs()->add('add', array(
|
||||
'url' => 'director/syncproperty/add',
|
||||
'label' => $this->view->title,
|
||||
))->activate('add');
|
||||
}
|
||||
|
||||
$form = $this->view->form = $this->loadForm('syncProperty')
|
||||
->setSuccessUrl('director/list/syncproperty')
|
||||
->setDb($this->db());
|
||||
|
||||
if ($edit) {
|
||||
$form->loadObject($id);
|
||||
}
|
||||
|
||||
$form->handleRequest();
|
||||
|
||||
$this->render('object/form', null, true);
|
||||
}
|
||||
}
|
|
@ -9,43 +9,47 @@ class SyncPropertyForm extends DirectorObjectForm
|
|||
{
|
||||
public function setup()
|
||||
{
|
||||
$this->addElement('text', 'source_name', array(
|
||||
'label' => $this->translate('Source name'),
|
||||
$this->addElement('select', 'rule_id', array(
|
||||
'label' => $this->translate('Rule Name'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('text', 'source_field', array(
|
||||
'label' => $this->translate('Source field'),
|
||||
'description' => $this->translate('This must be a column from the source'),
|
||||
$this->addElement('select', 'source_id', array(
|
||||
'label' => $this->translate('Source Name'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('text', 'destination_field', array(
|
||||
'label' => $this->translate('Destination field'),
|
||||
'description' => $this->translate('The value of the source will be transformed to the given attribute'),
|
||||
$this->addElement('text', 'source_expression', array(
|
||||
'label' => $this->translate('Source Expression'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('text', 'priority', array(
|
||||
'label' => $this->translate('Priority'),
|
||||
'description' => $this->translate('This allows to prioritize the import of a field, synced from different sources for the same object'),
|
||||
'required' => true,
|
||||
));
|
||||
$this->addElement('text', 'destination_field', array(
|
||||
'label' => $this->translate('Destination Field'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('text', 'filter', array(
|
||||
$this->addElement('text', 'priority', array(
|
||||
'label' => $this->translate('Priority'),
|
||||
'description' => $this->translate('Priority for the specified source expression'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('text', 'filter_expression', array(
|
||||
'label' => $this->translate('Filter Expression'),
|
||||
'description' => $this->translate('This allows to filter for specific parts within the given source field'),
|
||||
'required' => true,
|
||||
'description' => $this->translate('This allows to filter for specific parts within the given source expression'),
|
||||
'required' => false,
|
||||
));
|
||||
|
||||
$this->addElement('select', 'merge', array(
|
||||
'label' => $this->translate('Source Type'),
|
||||
|
||||
$this->addElement('select', 'merge_policy', array(
|
||||
'label' => $this->translate('Merge Policy'),
|
||||
'description' => $this->translate('Whether you want to merge or override the destination field'),
|
||||
'required' => true,
|
||||
'multiOptions' => array(
|
||||
'null' => '- please choose -',
|
||||
'merge' => 'merge',
|
||||
'override' => 'override'
|
||||
)
|
||||
'multiOptions' => array(
|
||||
'null' => '- please choose -',
|
||||
'merge' => 'merge',
|
||||
'override' => 'override'
|
||||
)
|
||||
));
|
||||
|
||||
}
|
||||
|
@ -66,4 +70,13 @@ class SyncPropertyForm extends DirectorObjectForm
|
|||
*/
|
||||
parent::onSuccess();
|
||||
}
|
||||
|
||||
public function setDb($db)
|
||||
{
|
||||
parent::setDb($db);
|
||||
$this->getElement('rule_id')->setMultiOptions($this->optionalEnum($db->enumSyncRule()));
|
||||
$this->getElement('source_id')->setMultiOptions($this->optionalEnum($db->enumImportSource()));
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,13 @@ class SyncRuleForm extends DirectorObjectForm
|
|||
{
|
||||
$this->addElement('text', 'rule_name', array(
|
||||
'label' => $this->translate('Rule name'),
|
||||
'description' => $this->translate('Please provide a rule name'),
|
||||
'required' => true,
|
||||
));
|
||||
|
||||
$this->addElement('select', 'object_type', array(
|
||||
'label' => $this->translate('Object Type'),
|
||||
'description' => $this->translate('This must be a column from the source'),
|
||||
'description' => $this->translate('Choose a object type'),
|
||||
'required' => true,
|
||||
'multiOptions' => array(
|
||||
'null' => '- please choose -',
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class SyncpropertyTable extends QuickTable
|
||||
{
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 's.id',
|
||||
'rule_id' => 's.rule_id',
|
||||
'source_id' => 's.source_id',
|
||||
'source_expression' => 's.source_expression',
|
||||
'destination_field' => 's.destination_field',
|
||||
'priority' => 's.priority',
|
||||
'filter_expression' => 's.filter_expression',
|
||||
'merge_policy' => 's.merge_policy'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/syncproperty/add', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'source_id' => $view->translate('Source id'),
|
||||
'source_expression' => $view->translate('Source field'),
|
||||
'destination_field' => $view->translate('Destination')
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
$db = $this->connection()->getConnection();
|
||||
|
||||
$query = $db->select()->from(
|
||||
array('s' => 'sync_property'),
|
||||
array()
|
||||
)->order('id');
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
|
@ -197,6 +197,16 @@ class Db extends DbConnection
|
|||
return $this->db()->fetchPairs($select);
|
||||
}
|
||||
|
||||
public function enumSyncRule()
|
||||
{
|
||||
$select = $this->db()->select()->from('sync_rule', array(
|
||||
'id',
|
||||
'rule_name'
|
||||
))->order('rule_name ASC');
|
||||
|
||||
return $this->db()->fetchPairs($select);
|
||||
}
|
||||
|
||||
public function enumHostgroups()
|
||||
{
|
||||
$select = $this->db()->select()->from('icinga_hostgroup', array(
|
||||
|
@ -233,6 +243,15 @@ class Db extends DbConnection
|
|||
return $this->db()->fetchPairs($select);
|
||||
}
|
||||
|
||||
public function enumImportSource()
|
||||
{
|
||||
$select = $this->db()->select()->from('import_source', array(
|
||||
'id',
|
||||
'source_name',
|
||||
))->order('source_name ASC');
|
||||
return $this->db()->fetchPairs($select);
|
||||
}
|
||||
|
||||
public function enumUsergroups()
|
||||
{
|
||||
$select = $this->db()->select()->from('icinga_usergroup', array(
|
||||
|
|
|
@ -74,10 +74,14 @@ abstract class ActionController extends Controller
|
|||
)->add('syncrule', array(
|
||||
'label' => $this->translate('Sync rule'),
|
||||
'url' => 'director/list/syncrule')
|
||||
)->add('syncproperty', array(
|
||||
'label' => $this->translate('Sync Property'),
|
||||
'url' => 'director/list/syncproperty')
|
||||
);
|
||||
return $this->view->tabs;
|
||||
}
|
||||
|
||||
|
||||
protected function db()
|
||||
{
|
||||
if ($this->db === null) {
|
||||
|
|
Loading…
Reference in New Issue