Code

Added list actions
[gosa.git] / gosa-core / plugins / admin / newConfigManagement / class_newConfigManagement.inc
index f1eb09d3afb6dd0a2419e227c4f6fae3f5afa0c5..f038f01b399189f217070530afeff19b0ce6d364 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;
@@ -18,7 +18,7 @@ class newConfigManagement extends plugin
     function __construct($config, $dn)
     {
         $this->config = &$config;
-        $this->listing = new ConfigManagementListing($this->config, get_userinfo());
+        $this->listing = new ConfigManagementListing($this->config, get_userinfo(), $this);
 
         // Request an update of the data model
         $this->updateDataModel();
@@ -41,39 +41,17 @@ class newConfigManagement extends plugin
             return(NULL);
         }
         foreach($res as $dist){
-            $this->dataModel->addItem('Distribution','/root', $dist);
+            $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);
 
-            // 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);
+                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');
+                    $rpc = $this->config->getRpcHandle();
+                    $res = $rpc->getPackages($data['name']);
+
+                    return;
+                    foreach($res as $itemPath => $type){
+                
+                        // Make names dataModel conform
+                        $itemPath = $path.'/'.preg_replace("/^\//","/root", $itemPath);
+                        $name = preg_replace("/^.*\//","",$itemPath);   
+                        $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
+                        $this->dataModel->addItem($type, $itemPath, $name); 
+                    }
+                }
+            }
+        }
     }
 
 
@@ -117,13 +133,16 @@ class newConfigManagement extends plugin
      */
     function execute()
     {
+
         // 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);
-        print_a($item);
+        $path = $this->selectedContainer.$this->selectedItem;
+        $item = $this->dataModel->getItemByPath($path);
+        session::set('CONFIG_ITEM', $item);
+        $this->listing->setListingTypes($this->getListingTypes());
 
-        return($this->listing->renderList());
+        return($this->listing->execute());
     }
 
 
@@ -131,14 +150,13 @@ 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()
     {
-        $res = array();
-        $dist = $this->selectedDistribution;
-        $list = $this->dataModel->getItemsByType('Release');
-        foreach($list as $base => $entry){
-            if($entry['parentPath'] != $dist) continue;
-            $res[$entry['path']] = $entry['name'];
+        $data = $this->dataModel->getItemByPath($this->selectedContainer);
+        $res = array(""=>"/");
+        if($data['type'] != 'Release'){
+        }else{
+            $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
         }
         return($res);
     }
@@ -150,14 +168,29 @@ class newConfigManagement extends plugin
      */
     function getDistList()
     {
-        $list = $this->dataModel->getItemsByType('Distribution');
+        $data = $this->dataModel->getItemByPath('/root');
+        $res["/root"] = "/";
+        $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
+        return($res);
+    }
+    
+
+    function __recurseItem($item, $types, $parent = "")
+    {
         $res = array();
-        foreach($list as $base => $entry){
-            $res[$entry['path']] = $entry['name'];
+        if(in_array($item['type'], $types)){
+            $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
+            $res[$path] = $item['name'];
+        }
+        if(count($item['children'])){
+            foreach($item['children'] as $child){
+                $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
+            }
         }
         return($res);
     }
-    
+
+
 
     function remove_lock()
     {
@@ -192,6 +225,43 @@ class newConfigManagement extends plugin
     }
 
 
+    function getListingTypes()
+    {
+        $types= array();
+        $types['Distribution']['objectClass'] = 'Distribution';
+        $types['Distribution']['label'] = _('Distribution');
+        $types['Distribution']['image'] = 'images/lists/edit.png';
+        $types['Distribution']['category'] = 'Device';
+        $types['Distribution']['class'] = 'Device';
+
+        $types['Release']['objectClass'] = 'Release';
+        $types['Release']['label'] = _('Release');
+        $types['Release']['image'] = 'images/lists/delete.png';
+        $types['Release']['category'] = 'Device';
+        $types['Release']['class'] = 'Device';
+
+        $types['Component']['objectClass'] = 'Component';
+        $types['Component']['label'] = _('Component');
+        $types['Component']['image'] = 'plugins/users/images/select_user.png';
+        $types['Component']['category'] = 'Device';
+        $types['Component']['class'] = 'Device';
+        return($types);
+    }
+
+
+
+    function editEntry($id)
+    {
+        print_a($id);
+    }
+
+
+    function removeEntry($id)
+    {
+        print_a($id); 
+    }
+
+
     public static function plInfo()
     {
         return (array(