Code

Updated config management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 22 Oct 2010 15:05:04 +0000 (15:05 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 22 Oct 2010 15:05:04 +0000 (15:05 +0000)
-Dynamically load configItems

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20127 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/newConfigManagement/DeviceConfig-list.tpl
gosa-core/plugins/admin/newConfigManagement/class_ConfigManagementDataModel.inc
gosa-core/plugins/admin/newConfigManagement/class_ConfigManagementListing.inc
gosa-core/plugins/admin/newConfigManagement/class_newConfigManagement.inc

index b32482581e349a05fdc4076f42aac3c7f15e3ec7..e4c7373b2eb65cfacc08a8b464aa975ba8aba5ba 100644 (file)
@@ -6,8 +6,8 @@
     <table summary="{$HEADLINE}">
      <tr>
       <td>{$RELOAD}</td>
-      <td class="left-border">{t}Distribution{/t} {$DISTRIBUTION}</td>
-      <td class="left-border">{t}Release{/t} {$RELEASE}</td>
+      <td class="left-border">{t}Container{/t} {$CONTAINER}</td>
+      <td class="left-border">{t}Item{/t} {$ITEM}</td>
       <td class="left-border">{$ACTIONS}</td>
       <td class="left-border">{$FILTER}</td>
      </tr>
index dcb5d598ae5870899c8ad8faccaf1e0db09169c8..2f35075ec0d7f752d04d8b6ac909af9861d0f45d 100644 (file)
@@ -68,6 +68,11 @@ class ConfigManagementDataModel
         
     }
 
+    function itemExistsByPath($path)
+    {
+        return(isset($this->data['linear'][$path]));
+    }
+    
     function getItemByPath($path)
     {
         if(isset($this->data['linear'][$path])){
@@ -76,6 +81,15 @@ class ConfigManagementDataModel
         return(NULL);
     }
 
+    function setItemStatus($path, $status)
+    {
+        if(!$this->itemExistsByPath($path)){
+            trigger_error("Invalid item path '{$path}'!");
+        }else{
+            $this->data['linear'][$path]['status'] = $status;
+        }
+    }
+
     function getItemsByType($type)
     {
         $res = array();
index bad03f55bfa41253ca365623b3b17cf166fd3340..427f02276abd18c8633342e913a64cd093ec4e84 100644 (file)
@@ -5,8 +5,8 @@ class ConfigManagementListing extends management
 
     private $base = "";
 
-    private $distributionSelector = NULL;
-    private $releaseSelector = NULL;
+    private $containerSelector = NULL;
+    private $itemSelector = NULL;
 
 
     function __construct($config, $ui)
@@ -15,47 +15,47 @@ class ConfigManagementListing extends management
         $this->storagePoints = array("");
         $this->rebuildListing();
 
-        $this->distributionSelector = new ItemSelector(array(),'/root','/root');
-        $this->releaseSelector = new ItemSelector(array(),'/root','/root');
+        $this->containerSelector = new ItemSelector(array(),'/root','/root');
+        $this->itemSelector = new ItemSelector(array(),'/root','/root');
     }
 
     function save_object()
     {
-        $this->distributionSelector->update();    
-        $this->releaseSelector->update();    
+        $this->containerSelector->update();    
+        $this->itemSelector->update();    
     }
 
-    function getSelectedDistribution()
+    function getSelectedContainer()
     {
-        return($this->distributionSelector->getBase());
+        return($this->containerSelector->getBase());
     }
 
-    function setDistribution($dist)
+    function setContainer($dist)
     {
-        return($this->distributionSelector->setBase($dist));
+        return($this->containerSelector->setBase($dist));
     }
 
-    function setRelease($rel)
+    function setItem($rel)
     {
-        return($this->releaseSelector->setBase($rel));
+        return($this->itemSelector->setBase($rel));
     }
 
-    function getSelectedRelease()
+    function getSelectedItem()
     {
-        return($this->releaseSelector->getBase());
+        return($this->itemSelector->getBase());
     }
 
 
-    function setDistributions($distributions) 
+    function setContainers($containers) 
     {
-        $this->distributionSelector->setBases($distributions);
-        $this->distributionSelector->update(TRUE);
+        $this->containerSelector->setBases($containers);
+        $this->containerSelector->update(TRUE);
     }
 
-    function setReleases($releases) 
+    function setItems($items) 
     {
-        $this->releaseSelector->setBases($releases);
-        $this->releaseSelector->update(TRUE);
+        $this->itemSelector->setBases($items);
+        $this->itemSelector->update(TRUE);
     }
 
     function renderList()
@@ -67,8 +67,8 @@ class ConfigManagementListing extends management
         $headpage->update();
         $smarty = get_smarty();
         
-        $smarty->assign("DISTRIBUTION", $this->distributionSelector->render());
-        $smarty->assign("RELEASE", $this->releaseSelector->render());
+        $smarty->assign("CONTAINER", $this->containerSelector->render());
+        $smarty->assign("ITEM", $this->itemSelector->render());
         $display = $headpage->render();
         return($this->getHeader().$display);
 
index 52b129e1b93aad51b24477a036ebb85a5b381039..8b7cf00d4be5cdb904ed0e8a2901f83440ce539b 100644 (file)
@@ -6,8 +6,8 @@ class newConfigManagement extends plugin
     var $plHeadline = "Config management";
     var $plDescription = "Config management";
 
-    var $selectedDistribution;
-    var $selectedRelease;
+    var $selectedContainer;
+    var $selectedItem;
 
     var $dataModel = NULL;
     var $listing = NULL;
@@ -41,39 +41,17 @@ class newConfigManagement extends plugin
             return(NULL);
         }
         foreach($res as $dist){
-            $this->dataModel->addItem('Distribution','/root', $dist);
-
-            // Load the releases for the current distribution
-            $releases = $rpc->getReleases($dist);
-            if(!$rpc->success()){
-                msg_dialog::display(_("Error"), sprintf(_("Failed to load releases, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
-                return(NULL);
-            }
-            foreach($releases as $release){
-                $this->dataModel->addItem('Release',"/root/{$dist}", $release);
-
-                // Load packages
-                $packages = $rpc->getPackages($release);
-                if(!$rpc->success()){
-                    msg_dialog::display(_("Error"), sprintf(_("Failed to load packages, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
-                    return(NULL);
-                }
-                foreach($packages as $package){
-                    $this->dataModel->addItem('Package',"/root/{$dist}/{$release}", $package['name'], $package);
-                }
-
-                // Load items
-                $items = $rpc->listConfigItems($release);
-                if(!$rpc->success()){
-                    msg_dialog::display(_("Error"), sprintf(_("Failed to load items, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
-                    return(NULL);
-                }
-                foreach($items as $package){
-                    $this->dataModel->addItem('Item',"/root/{$dist}/{$release}", $package['name'], $package);
+            $this->dataModel->addItem('Distribution','/root', $dist['name'], $dist);
+            foreach($dist['releases'] as $release){
+                $distPath = "/root/{$dist['name']}";
+                $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);
                 }
             }
         }
-
     }
 
 
@@ -88,27 +66,65 @@ class newConfigManagement extends plugin
         $this->listing->save_object();
 
         // Get the selected distribution and release from the listing widget.
-        $this->selectedDistribution = $this->listing->getSelectedDistribution();
-        $this->selectedRelease = $this->listing->getSelectedRelease();
-   
+        $this->selectedContainer = $this->listing->getSelectedContainer();
+        $this->selectedItem = $this->listing->getSelectedItem();
+  
         // Get a list of all available distributions and releases.
         $distList = $this->getDistList();
-        $releaseList = $this->getReleaseList();
+        $releaseList = $this->getItemList();
 
         // Ensure that we've valid values selected.
-        if(!isset($releaseList[$this->selectedRelease])){
+        if(!isset($releaseList[$this->selectedItem])){
             if(count($releaseList)){
-                $this->selectedRelease = key($releaseList);
+                $this->selectedItem = key($releaseList);
             }else{
-                $this->selectedRelease = "";
+                $this->selectedItem = "";
             }
         }
 
+        // Update list of items within the selected container. 
+        $this->updateItemList($this->selectedContainer);
+
         // Transfer checked values back to the listing class.
-        $this->listing->setDistribution($this->selectedDistribution);
-        $this->listing->setRelease($this->selectedRelease);
-        $this->listing->setDistributions($this->getDistList());
-        $this->listing->setReleases($this->getReleaseList());
+        $this->listing->setContainer($this->selectedContainer);
+        $this->listing->setItem($this->selectedItem);
+        $this->listing->setContainers($this->getDistList());
+        $this->listing->setItems($this->getItemList());
+    }
+
+
+    function updateItemList($path)
+    {
+        // Fist get Item and check if it is an release 
+        if($this->dataModel->itemExistsByPath($path)){
+            $data = $this->dataModel->getItemByPath($path);
+
+            // Only releases can contain config-items.
+            if($data['type'] == 'Release' && $data['status'] != "fetched"){
+
+                $rpc = $this->config->getRpcHandle();
+                $res = $rpc->listConfigItems($data['name']);
+                if(!$rpc->success()){
+                    msg_dialog::display(_("Error"), 
+                            sprintf(_("Failed to load distributions, error was '%s'!"), 
+                                $rpc->get_error()),ERROR_DIALOG);
+                }else{
+                    $this->dataModel->setItemStatus($path, 'käse');
+                    foreach($res as $itemPath => $type){
+                
+                        // Make names dataModel conform
+                        $itemPath = $path.preg_replace("/^\//","/root", $itemPath);
+                        $name = preg_replace("/^.*\//","",$itemPath);   
+
+                        $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
+
+                        print_a(array($type, $itemPath, $name));
+                        $this->dataModel->addItem($type, $itemPath, $name); 
+                    }
+                }
+            }
+        }
     }
 
 
@@ -120,7 +136,7 @@ class newConfigManagement extends plugin
         // Get the selected release and store it in a session variable
         //  to allow the configFilter to access it and display the
         //  packages and items.
-        $item = $this->dataModel->getItemByPath($this->selectedRelease);
+        $item = $this->dataModel->getItemByPath($this->selectedItem);
         session::set('CONFIG_ITEM', $item);
 
         return($this->listing->renderList());
@@ -131,12 +147,12 @@ class newConfigManagement extends plugin
      *          This list will then be used to generate the entries of the 
      *           ItemSelectors in the listing class.
      */
-    function getReleaseList()
+    function getItemList()
     {
         $data = $this->dataModel->getItemByPath('/root');
         return($this->__recurseItem($data));
         $res = array();
-        $dist = $this->selectedDistribution;
+        $dist = $this->selectedContainer;
         $list = $this->dataModel->getItemsByType('Release');
         foreach($list as $base => $entry){
             if($entry['parentPath'] != $dist) continue;
@@ -152,7 +168,6 @@ class newConfigManagement extends plugin
      */
     function getDistList()
     {
-
         $data = $this->dataModel->getItemByPath('/root');
         return($this->__recurseItem($data));
        
@@ -169,7 +184,7 @@ class newConfigManagement extends plugin
     function __recurseItem($item)
     {
         $res = array();
-        $res[$item['path']] = $item['name'];
+        $res[$item['path']] = $item['type'];
         if(count($item['children'])){
             foreach($item['children'] as $child){
                 $res = array_merge($res, $this->__recurseItem($child));