Code

Updated config management class
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 21 Oct 2010 13:33:45 +0000 (13:33 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 21 Oct 2010 13:33:45 +0000 (13:33 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20111 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
gosa-core/plugins/admin/newConfigManagement/main.inc

index 5cc4b060b008433cee74b3431864e60d87c0be97..31ff3628bba60abe251ef6a1f96a561a3e64cf48 100644 (file)
@@ -6,8 +6,8 @@
     <table summary="{$HEADLINE}">
      <tr>
       <td>{$RELOAD}</td>
-      <td class="left-border">{t}Release{/t} {$RELEASE}</td>
-      <td class="left-border">{t}Item{/t} {$ITEM}</td>
+      <td class="left-border">{t}Release{/t} {$DISTRIBUTION}</td>
+      <td class="left-border">{t}Item{/t} {$RELEASE}</td>
       <td class="left-border">{$ACTIONS}</td>
       <td class="left-border">{$FILTER}</td>
      </tr>
index 054ad2e131f3cf810e914aec63676db44ff83aac..c6613a2f067b7477bbda3cf8e3baadcd16704005 100644 (file)
@@ -3,6 +3,8 @@
 class ConfigManagementDataModel
 {
     private $data = array();
+    private $typeToPath = array();
+    private $idToPath = array();
 
     function __construct()
     {
@@ -12,36 +14,67 @@ class ConfigManagementDataModel
         $this->addItem('root', '','root', array());
     }
 
+    function getDataModel()
+    {
+        return($this->data);
+    }
+
+    
+
 
-    function addItem($type, $base, $name, $values, $status = "")
+    function addItem($type, $path, $name, $values = array(), $status = "")
     {
-        if($base == ""){
+        if($path == ""){
             $parentItem = &$this->data['recursive'];
             $parentId = NULL;
-        }elseif(isset($this->data['linear'][$base])){
-            $parentItem = &$this->data['linear'][$base]['children'];
-            $parentId = $this->data['linear'][$base]['id'];
+            $parentDn = "";
+        }elseif(isset($this->data['linear'][$path])){
+            $parentItem = &$this->data['linear'][$path]['children'];
+            $parentId = $this->data['linear'][$path]['id'];
+            $parentDn = $this->data['linear'][$path]['dn'];
         }else{
             echo "No parent";
             return(FALSE);
         }
 
         $this->currentID ++;
-        $entryBase = "{$base}/{$name}";
+        $entryPath = "{$path}/{$name}";
+        $entryDn  = rtrim("cn={$name},{$parentDn}",',');
         $entryId =  $this->currentID;
         
-        $entry['dn'] = $entryBase;
+        $entry['path'] = $entryPath;
+        $entry['dn'] = $entryDn;
         $entry['id'] = $entryId;
         $entry['parentId'] = $parentId;
         $entry['name'] = $name;
-        $entry['base'] = $base;
+        $entry['path'] = $entryPath;
+        $entry['parentPath'] = $path;
+        $entry['type'] = $type;
         $entry['status'] = $status;
         $entry['values'] = $values;
         $entry['children'] = array();
 
-        $parentItem[$entryBase] = &$entry;
-        $this->data['linear'][$entryBase] = &$parentItem[$entryBase];
-        return(TRUE);
+        $parentItem[$entryPath] = &$entry;
+        $this->data['linear'][$entryPath] = &$parentItem[$entryPath];
+
+        $this->idToPath[$entryId] = $entryPath;
+        $this->typeToPath[$type][$name] = $entryPath;
+    
+        return($entryId);
+    }
+
+    function pathToDn($path)
+    {
+        
+    }
+
+    function getItemsByType($type)
+    {
+        $res = array();
+        foreach($this->typeToPath[$type] as $path){
+            $res[$path] = $this->data['linear'][$path];
+        }
+        return($res);
     }
 }
 
index b62e5a60f5593c6f0670a48f9613a12798b92e7f..2e0de2bed2b4232c4d5f2fbb3aecebc01894a984 100644 (file)
@@ -5,8 +5,8 @@ class ConfigManagementListing extends management
 
     private $base = "";
 
+    private $distributionSelector = NULL;
     private $releaseSelector = NULL;
-    private $itemSelector = NULL;
 
 
     function __construct($config, $ui)
@@ -15,32 +15,48 @@ class ConfigManagementListing extends management
         $this->storagePoints = array("");
         $this->rebuildListing();
 
-       
-        $this->releaseSelector = new ItemSelector(array('cn=/'=>'/'),"cn=/","cn=/"); 
-        $this->itemSelector = new ItemSelector(array('cn=/'=>'/'),"cn=/","cn=/"); 
+        $this->distributionSelector = new ItemSelector(array('cn=root'=>'root'),"cn=root","cn=root"); 
+        $this->releaseSelector = new ItemSelector(array('cn=root'=>'root'),"cn=root","cn=root");
     }
 
-    function setRelease($base)
+    function save_object()
     {
-        $this->releaseSelector->setBase($base);
+        $this->distributionSelector->update();    
+        $this->releaseSelector->update();    
     }
 
-    function setReleases ($releases) 
+    function getSelectedDistribution()
     {
-        $this->releaseSelector->setBases($releases);
+        return($this->distributionSelector->getBase());
+    }
+
+    function getSelectedRelease()
+    {
+        return($this->releaseSelector->getBase());
     }
 
+    function setDistribution($base)
+    {
+        $this->distributionSelector->setBase($base);
+    }
 
-    function setItem($base)
+    function setDistributions($distributions) 
     {
-        $this->itemSelector->setBase($base);
+        $this->distributionSelector->setBases($distributions);
+        $this->distributionSelector->update(TRUE);
     }
 
-    function setItems ($items) 
+    function setRelease($base)
     {
-        $this->itemSelector->setBases($items);
+        $this->releaseSelector->setBase($base);
     }
-    function setAllowedItems() {} 
+
+    function setReleases($releases) 
+    {
+        $this->releaseSelector->setBases($releases);
+        $this->releaseSelector->update(TRUE);
+    }
+
     function renderList()
     {
         session::set('DEVICE_ITEMS', array());
@@ -50,11 +66,8 @@ class ConfigManagementListing extends management
         $headpage->update();
         $smarty = get_smarty();
         
-        $this->releaseSelector->update(TRUE);    
-        $this->itemSelector->update(TRUE);    
-
+        $smarty->assign("DISTRIBUTION", $this->distributionSelector->render());
         $smarty->assign("RELEASE", $this->releaseSelector->render());
-        $smarty->assign("ITEM", $this->itemSelector->render());
         $display = $headpage->render();
         return($this->getHeader().$display);
 
@@ -80,19 +93,7 @@ class ConfigManagementListing extends management
         $headpage->setFilter($filter);
 
         parent::__construct($this->config, $this->ui, "services", $headpage);
-
-        // Register default actions
-        $this->registerAction("new",        "newEntry");
-        $this->registerAction("edit",       "openEntry"); // !! We forward 'edit' to 'open' to have a department like navigation.
-        $this->registerAction("editEntry",  "editEntry");
-
-        $this->registerAction("saveItemChanges", "saveItemChanges");
-        $this->registerAction("cancelItemEdit", "closeDialogs");
-        $this->registerAction("cancelItemAdd", "closeDialogs");
-        $this->registerAction("saveItemAdd", "saveItemAdd");
     }
-
-    
 } 
 
 ?>
index 3694b9d38faedd3a3738dbaffad3fe238f9b9c5e..d5d08878f0c57e3e18197b89e00682fbe39caf49 100644 (file)
@@ -8,59 +8,54 @@ class newConfigManagement extends plugin
 
     var $installationMethods = array();
 
+    var $selectedDistribution;
+
     function __construct($config, $dn)
     {
         $this->config = &$config;
-
         $this->listing = new ConfigManagementListing($this->config, get_userinfo());
         $this->dataModel = new ConfigManagementDataModel();
 
+        // Load distributions 
+        $rpc = $this->config->getRpcHandle();
+        $res = $rpc->getDistributions();
+        if(!$rpc->success()){
+            msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
+            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);
+                }
+            }
+        }
 
-#       $dists = $this->getDistributions();
-#       foreach($dists as $name => $dist){
-#
-#           
-#           $this->dataModel->addItem
-#   
-#           
-#       }
-#        
-#   
-#
-#
-#
-#       // Get installation methods from the backend.
-#       $this->loadInstallationMethods();
     }
 
-    
-    function getDistributions()
+    function save_object()
     {
-        return(
-            array(
-                'debian' => 
-                    array('type' => 'deb', 'install_method' => 'puppet'),
-                'suse' => 
-                    array('type' => 'rpm', 'install_method' => 'muppet')
-            ));
+        $this->listing->save_object();
+        $this->selectedDistribution = $this->listing->getSelectedDistribution();
+        $this->selectedRelease = $this->listing->getSelectedRelease();
     }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     
     /*! \brief  Intializes this plugin
      *          All available installation methods will be loaded
@@ -87,34 +82,52 @@ class newConfigManagement extends plugin
             $this->initFailed = TRUE;
             return;
         }
+    }
 
 
-        $this->getReleases();
+    function execute()
+    {
+        $this->listing->setDistributions($this->getDistList());
+        $this->listing->setReleases($this->getReleaseList());
+        return($this->listing->renderList());
     }
 
-    
 
-   
-    function getReleases()
+    function getReleaseList()
     {
-        $rpc = $this->config->getRpcHandle();
-        $res = $rpc->getReleases();
-        if(!$rpc->success()){
-            $this->rpcError = TRUE;
-            $this->errorMessage = $rpc->get_error();;
-            return(NULL);
+        $res = array();
+        $res = array("cn=root" => '/');
+        if(isset($this->distributionMap[$this->selectedDistribution])){
+           $dist = $this->distributionMap[$this->selectedDistribution];
+           $list = $this->dataModel->getItemsByType('Release');
+           $this->releaseMap = array();
+           foreach($list as $base => $entry){
+               if($entry['parentPath'] != $dist) continue;
+               $res["cn={$entry['name']},cn=root"] = $entry['name'];
+               $this->releaseMap["cn={$entry['name']},cn=root"] = $entry['path'];
+           }
         }
         return($res);
     }
-
-    function execute()
+    
+    
+    function getDistList()
     {
-        return($this->listing->renderList());
+        $list = $this->dataModel->getItemsByType('Distribution');
+        $res = array();
+        $res = array("cn=root" => '');
+        $this->distributionMap = array();
+        foreach($list as $base => $entry){
+            $res["cn={$entry['name']},cn=root"] = $entry['name'];
+            $this->distributionMap["cn={$entry['name']},cn=root"] = $entry['path'];
+        }
+        return($res);
     }
+    
 
     function remove_lock()
-    {}
+    {
+    }
 
     public static function plInfo()
     {
@@ -131,8 +144,5 @@ class newConfigManagement extends plugin
                     "plProvidedAcls"=> array()
                     ));
     }
-
 }
-
-
 ?>
index 26ce1e3628eb407d0845f5726715242fd6db7855..0eea23740ad6364c4c8a1cad64c4c64630865c83 100644 (file)
@@ -18,6 +18,7 @@ if ( $cleanup ){
         session::set('newConfigManagement',$newConfigManagement);
     }
     $newConfigManagement = session::get('newConfigManagement');
+    $display= $newConfigManagement->save_object();
     $display= $newConfigManagement->execute();
 
     /* Reset requested? */