SyncPropertyForm: choose lists by name, cleanup

fixes #1048
This commit is contained in:
Thomas Gelf 2018-06-01 14:52:10 +02:00
parent a005ac3228
commit 32a1352ac9
2 changed files with 60 additions and 19 deletions

View File

@ -27,6 +27,9 @@ class SyncPropertyForm extends DirectorObjectForm
const EXPRESSION = '__EXPRESSION__';
/**
* @throws \Zend_Form_Exception
*/
public function setup()
{
$this->addHidden('rule_id', $this->rule->get('id'));
@ -144,6 +147,11 @@ class SyncPropertyForm extends DirectorObjectForm
return false;
}
/**
* @param $destination
* @return $this
* @throws \Zend_Form_Exception
*/
protected function addSourceColumnElement($destination)
{
$error = false;
@ -162,17 +170,9 @@ class SyncPropertyForm extends DirectorObjectForm
}
if ($destination === 'import') {
$funcTemplates = 'enum' . ucfirst($this->rule->get('object_type')) . 'Templates';
if (method_exists($this->db, $funcTemplates)) {
$templates = $this->db->$funcTemplates();
if (! empty($templates)) {
$templates = array_combine($templates, $templates);
}
$importTitle = $this->translate('Existing templates');
$columns[$importTitle] = $templates;
natsort($columns[$importTitle]);
}
$this->addIcingaTempateColumns($columns);
} elseif ($destination === 'list_id') {
$this->addDatalistsColumns($columns);
}
$xpTitle = $this->translate('Expert mode');
@ -222,6 +222,33 @@ class SyncPropertyForm extends DirectorObjectForm
return $this;
}
protected function addIcingaTempateColumns(& $columns)
{
$funcTemplates = 'enum' . ucfirst($this->rule->get('object_type')) . 'Templates';
if (method_exists($this->db, $funcTemplates)) {
$templates = $this->db->$funcTemplates();
if (! empty($templates)) {
$templates = array_combine($templates, $templates);
}
$title = $this->translate('Existing templates');
$columns[$title] = $templates;
natsort($columns[$title]);
}
}
protected function addDatalistsColumns(& $columns)
{
// Clear other columns, we don't allow them right now
$columns = [];
$db = $this->db->getDbAdapter();
$enum = $db->fetchPairs(
$db->select()->from('director_datalist', ['id', 'list_name'])->order('list_name')
);
$columns[$this->translate('Existing Data Lists')] = $enum;
}
protected function enumImportSource()
{
$sources = $this->db->enumImportSource();
@ -247,6 +274,11 @@ class SyncPropertyForm extends DirectorObjectForm
);
}
/**
* @return array
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\NotFoundError
*/
protected function listSourceColumns()
{
$columns = array();
@ -265,8 +297,8 @@ class SyncPropertyForm extends DirectorObjectForm
protected function listDestinationFields()
{
$props = array();
$special = array();
$props = [];
$special = [];
$dummy = $this->dummyObject();
if ($dummy instanceof IcingaObject) {
@ -317,14 +349,20 @@ class SyncPropertyForm extends DirectorObjectForm
ksort($props);
return array(
$this->translate('Special properties') => $special,
$this->translate('Object properties') => $props
);
$result = [];
if (! empty($special)) {
$result[$this->translate('Special properties')] = $special;
}
if (! empty($props)) {
$result[$this->translate('Object properties')] = $props;
}
return $result;
}
/**
* @return ImportSource
* @throws \Icinga\Exception\NotFoundError
*/
protected function getImportSource()
{
@ -341,6 +379,8 @@ class SyncPropertyForm extends DirectorObjectForm
/**
* @return ImportSourceHook
* @throws \Icinga\Exception\ConfigurationError
* @throws \Icinga\Exception\NotFoundError
*/
protected function getImportSourceHook()
{
@ -368,13 +408,13 @@ class SyncPropertyForm extends DirectorObjectForm
$this->removeElement('source_column');
if ($sourceColumn !== self::EXPRESSION) {
$object->source_expression = $sourceColumn;
$object->set('source_expression', $sourceColumn);
}
$destination = $this->getValue('destination_field');
if ($destination === 'vars.*') {
$destination = $this->getValue('customvar');
$object->destination_field = 'vars.' . $destination;
$object->set('destination_field', 'vars.' . $destination);
}
return parent::onSuccess();

View File

@ -31,6 +31,7 @@ before switching to a new version.
* FEATURE: Show usage of Commands over templates and objects (#335)
* FEATURE: Allow horizontal size increase of Import Source DB Query field (#299)
* FEATURE: Small UI improvements like #1308
* FEATURE: Data Lists can be chosen by name in Sync rules (#1048)
* FIX: Don't suggest Command templates where Commands are required (#1414)
* FIX: Do not allow to delete Commands being used by other objects (#1443)
* FIX: Show 'Inspect' tab only for Endpoints with an ApiUser (#1293)