X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Fgoto-ng%2Fadmin%2FnewConfigManagement%2Fclass_newConfigManagement.inc;h=3f1dac3867245ebf8e9d56e12492f74b9311455e;hb=3cf9eb71dbd0d61608f04751276ce09b4be30783;hp=a5bcdd1dc13f6c34cbc8801a40e6eedad890c2ce;hpb=3e667d16f34b93bc2655bf62d38f7ad36d6bf037;p=gosa.git diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc index a5bcdd1dc..3f1dac386 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc @@ -14,6 +14,11 @@ class newConfigManagement extends plugin var $listing = NULL; var $cfgTypeMap = NULL; + var $cfgItemMap = NULL; + + var $addableContainerItems = array(); + var $currentObject = NULL; + /*! \brief Initialize the plugin and finally update the data model. */ @@ -25,7 +30,6 @@ class newConfigManagement extends plugin // Load the template engine and tell her what template // to use for the HTML it produces. $this->TemplateEngine = new TemplateEngine($config); - $this->TemplateEngine->setTemplate('puppet.tpl'); // Request an update of the data model $this->loadInstallationMethods(); @@ -49,7 +53,8 @@ class newConfigManagement extends plugin msg_dialog::display(_("Setup"), $this->errorMessage, ERROR_DIALOG); return(FALSE); }else{ - + + $this->TemplateEngine->setTemplate($str.".tpl"); $this->itemConfig = $this->installationMethods[$str]['items']; $this->invalidInstallMethod =FALSE; $this->TemplateEngine->load($this->itemConfig); @@ -89,16 +94,15 @@ class newConfigManagement extends plugin msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG); return(NULL); }else{ + $this->cfgTypeMap = array(); foreach($res as $dist){ + $dist['__removeable'] = TRUE; $this->dataModel->addItem('Distribution','/root', $dist['name'], $dist); + $this->cfgTypeMap['/root/'.$dist['name']] = $dist['installation_method']; foreach($dist['releases'] as $release){ $distPath = "/root/{$dist['name']}"; + $release['__removeable'] = TRUE; $this->dataModel->addItem('Release',$distPath, $release['name'], $release); - - # foreach($dist['components'] as $component){ - # $comPath = "{$distPath}/{$release['name']}"; - # $this->dataModel->addItem('Component',$comPath, $component['name'], $component); - # } } } } @@ -166,22 +170,31 @@ class newConfigManagement extends plugin // Walk through each entry and then try to add it to the model foreach($sLen as $unused => $itemPath){ + // Do not add the root element '/' + if($itemPath == "/") continue; + $type = $res[$itemPath]; // Root installation objects do not have a name, so we use 'root' here. - $itemPath = trim($path."/root/".$itemPath); + $targetPath = trim($path."/".$itemPath); // Remove trailing and duplicated slashes - $itemPath = rtrim($itemPath, '/'); - $itemPath = preg_replace("/\/\/*/","/", $itemPath); + $targetPath = rtrim($targetPath, '/'); + $targetPath = preg_replace("/\/\/*/","/", $targetPath); // Extract the items name - $name = preg_replace("/^.*\//","", $itemPath); + $name = preg_replace("/^.*\//","", $targetPath); // Cleanup the path and then add the item. - $itemPath = preg_replace("/[^\/]*$/","", $itemPath); - $itemPath = rtrim($itemPath,'/'); - $this->dataModel->addItem($type, $itemPath, $name); + $targetPath = preg_replace("/[^\/]*$/","", $targetPath); + $targetPath = rtrim($targetPath,'/'); + $this->dataModel->addItem($type, $targetPath, $name, + array( + '__editable' => TRUE, + '__removeable' => TRUE, + '__path' => $itemPath, + '__release' => $path + ),'-' ); } $this->dataModel->setItemStatus($path, 'fetched'); } @@ -207,11 +220,18 @@ class newConfigManagement extends plugin $this->listing->setContainer($cont); // Set the correct installation method for the selected item - $item = $this->dataModel->getItemByPath($cont); - if($this->cfgTypeMap[$item['type']]){ - $method = $this->cfgTypeMap[$item['type']]; + if(isset($this->cfgTypeMap[$cont])){ + $method = $this->cfgTypeMap[$cont]; $this->setInstallMethod($method); } + + // Update the list of addable sub objects + $item = $this->dataModel->getItemByPath($cont); + if(isset($this->itemConfig[$item['type']]['container'])){ + $this->addableContainerItems = $this->itemConfig[$item['type']]['container']; + }else{ + $this->addableContainerItems = array(); + } } @@ -299,20 +319,26 @@ class newConfigManagement extends plugin return; } $this->installationMethods = $res; + if(!count($this->installationMethods)){ $this->errorMessage = _("No selectable install methods returned!"); msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG); $this->initFailed = TRUE; return; }else{ - - $this->cfgTypeMap = array(); - foreach($this->installationMethods as $methodName => $data){ - foreach($data['items'] as $itemName => $itemData){ - $this->cfgTypeMap[$itemName] = $methodName; + $this->cfgItemMap = array(); + foreach($this->installationMethods as $method => $items){ + foreach($items['items'] as $itemName => $item){ + $this->cfgItemMap[$itemName] = $method; + + // This enables us to create the first level of config items when + // a release is selected. + if($item['name'] == "/"){ + $this->installationMethods[$method]['items']['Release'] = + &$this->installationMethods[$method]['items'][$itemName]; + } } } - } } @@ -399,6 +425,152 @@ class newConfigManagement extends plugin { } + function removeEntry($ids) + { + $item = $this->dataModel->getItemById($ids[0]); + $release = preg_replace("/^.*\//","",$item['values']['__release']); + $path = $item['values']['__path']; + $rpc = $this->config->getRpcHandle(); + $rpc->removeConfigItem($release, $path); + + if(!$rpc->success()){ + msg_dialog::display(_("Error"), sprintf(_("Failed to remove: %s"), $rpc->get_error()),ERROR_DIALOG); + return(NULL); + } + } + + function editEntry($ids) + { + // Update the template engine to use another type of item and + // some other values. + $item = $this->dataModel->getItemById($ids[0]); + + if(isset($this->cfgItemMap[$item['type']])){ + $release = preg_replace("/^.*\//","",$item['values']['__release']); + $path = $item['values']['__path']; + $method = $this->cfgItemMap[$item['type']]; + + // Load item values on demand + if($item['status'] == '-'){ + $rpc = $this->config->getRpcHandle(); + $item['values']['itemValues'] = $rpc->getConfigItem($release, $path); + $this->dataModel->setItemStatus($item['path'], 'fetched'); + $this->dataModel->setItemValues($item['path'], $item['values']); + } + $this->setInstallMethod($method); + $this->TemplateEngine->setValues($item['type'],$item['values']['itemValues']); + $this->listing->setDialogObject($this->TemplateEngine); + $this->currentObject = $item; + } + } + + function newEntry($type) + { + $method = $this->cfgItemMap[$type]; + $this->setInstallMethod($method); + $this->TemplateEngine->setValues($type,array()); + $this->listing->setDialogObject($this->TemplateEngine); + $this->currentObject = NULL; + } + + + function getItemPath($fullPath) + { + $fPath = $fullPath.'/'; + while(preg_match("/\//", $fPath)){ + $fPath = preg_replace("/\/[^\/]*$/","", $fPath); + $item = $this->dataModel->getItemByPath($fPath); + if(isset($this->cfgItemMap[$item['type']])){ + return(preg_replace("/".preg_quote($item['parentPath'],'/')."/", "", $fullPath)); + } + } + return(NULL); + } + + function getReleasePath($fullPath) + { + $fullPath.='/'; + while(preg_match("/\//", $fullPath)){ + $fullPath = preg_replace("/\/[^\/]*$/","", $fullPath); + $item = $this->dataModel->getItemByPath($fullPath); + if($item['type'] == 'Release'){ + return($fullPath); + } + } + return(NULL); + } + + function saveItemChanges() + { + $item = $this->currentObject; + + // Null means a new object has to be added. + if($item == NULL){ + + // Save template engine modifications + $this->TemplateEngine->save_object(); + $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer)); + $type = $this->TemplateEngine->getItemType(); + + // Collect modified values + $values = array(); + foreach($this->TemplateEngine->getWidgets() as $w){ + $values[$w->getName()] = $w->getValue(); + } + + // Create the elements target path + $path = $this->getItemPath($this->selectedContainer)."/".$values['name']; + + // Add the new item + $rpc = $this->config->getRpcHandle(); + $res = $rpc->setConfigItem($release, $path, $type, $values); + if(!$rpc->success()){ + msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG); + return(NULL); + }else{ + + // We've successfully added the item, now add it to the tree. + $this->dataModel->addItem($type, $this->selectedContainer, $values['name'], + array( + '__editable' => TRUE, + '__removeable' => TRUE, + '__path' => $path, + '__release' => $this->getReleasePath($this->selectedContainer) + ), '-' ); + + // Finally - close the dialog. + $this->listing->clearDialogObject(); + } + }else{ + + // Collect modified values. + $this->TemplateEngine->save_object(); + $values = array(); + foreach($this->TemplateEngine->getWidgets() as $w){ + $values[$w->getName()] = $w->getValue(); + } + + // Get the items release & path info + $release = preg_replace("/^.*\//","",$item['values']['__release']); + $path = $item['values']['__path']; + + // Write the modifications back to the server. + $rpc = $this->config->getRpcHandle(); + $res = $rpc->setConfigItem($release, $path, $item['type'], $values); + if(!$rpc->success()){ + msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG); + return(NULL); + }else{ + + // Update the data model + $item['values']['itemValues'] = $values; + $this->dataModel->setItemValues($item['path'], $item['values']); + $this->listing->clearDialogObject(); + } + } + } } + + ?>