Selaa lähdekoodia

Compiler: added the auto_load option + fixed issue with parent menu declared in another module

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1949 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 vuotta sitten
vanhempi
commit
ebb59fd623

+ 4 - 0
application/menunode.class.inc.php

@@ -586,6 +586,10 @@ class OQLMenuNode extends MenuNode
 	public function SetParameters($aParams)
 	{
 		$this->m_aParams = $aParams;
+		foreach($aParams as $sKey => $value)
+		{
+			$this->aReflectionProperties[$sKey] = $value;
+		}
 	}
 	
 	public function RenderContent(WebPage $oPage, $aExtraParams = array())

+ 4 - 0
datamodel/itop-change-mgmt-1.0.0/datamodel.itop-change-mgmt.xml

@@ -2985,24 +2985,28 @@
     <menu id="MyChanges" type="OQLMenuNode">
       <oql value="SELECT Change WHERE agent_id = :current_contact_id AND status NOT IN (&quot;closed&quot;, &quot;resolved&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Change:Shortcuts"/>
       <rank value="1"/>
     </menu>
     <menu id="Changes" type="OQLMenuNode">
       <oql value="SELECT Change WHERE status != &quot;closed&quot;"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Change:Shortcuts"/>
       <rank value="2"/>
     </menu>
     <menu id="WaitingApproval" type="OQLMenuNode">
       <oql value="SELECT ApprovedChange WHERE status IN (&quot;plannedscheduled&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Change:Shortcuts"/>
       <rank value="3"/>
     </menu>
     <menu id="WaitingAcceptance" type="OQLMenuNode">
       <oql value="SELECT NormalChange WHERE status IN (&quot;new&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Change:Shortcuts"/>
       <rank value="4"/>
     </menu>

+ 0 - 13
datamodel/itop-change-mgmt-1.0.0/main.itop-change-mgmt.php

@@ -14,17 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oMyMenuGroup = new MenuGroup('ChangeManagement', 50 /* fRank */);
-new TemplateMenuNode('Change:Overview', dirname(__FILE__).'/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
-new NewObjectMenuNode('NewChange', 'Change', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
-new SearchMenuNode('SearchChanges', 'Change', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
-$oShortcutNode = new TemplateMenuNode('Change:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
-$oNode = new OQLMenuNode('MyChanges', 'SELECT Change WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('Changes', 'SELECT Change WHERE status != "closed"', $oShortcutNode->GetIndex(), 2 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('WaitingApproval', 'SELECT ApprovedChange WHERE status IN ("plannedscheduled")', $oShortcutNode->GetIndex(), 3 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('WaitingAcceptance', 'SELECT NormalChange WHERE status IN ("new")', $oShortcutNode->GetIndex(), 4 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
 ?>

+ 0 - 39
datamodel/itop-config-mgmt-1.0.0/main.itop-config-mgmt.php

@@ -22,43 +22,4 @@ MetaModel::RegisterRelation("depends on", array("description"=>"That impacts ",
 // choice 'All Organizations' will always be available in the menu
 ApplicationMenu::SetFavoriteSiloQuery('SELECT Organization');
 
-$oAdminMenu = new MenuGroup('DataAdministration', 70 /* fRank */, 'Organization', UR_ACTION_MODIFY, UR_ALLOWED_YES|UR_ALLOWED_DEPENDS);
-$iAdminGroup = $oAdminMenu->GetIndex();
-
-new WebPageMenuNode('Audit', utils::GetAbsoluteUrlAppRoot().'pages/audit.php', $iAdminGroup, 33 /* fRank */);
-
-$oTypologyNode = new TemplateMenuNode('Catalogs', '', $iAdminGroup, 50 /* fRank */);
-$iTopology = $oTypologyNode->GetIndex();
-new OQLMenuNode('Organization', 'SELECT Organization', $iTopology, 10 /* fRank */, true /* bSearch */);
-new OQLMenuNode('Application', 'SELECT Application', $iTopology, 20 /* fRank */);
-new OQLMenuNode('DBServer', 'SELECT DBServer', $iTopology, 40 /* fRank */);
-
-
-$oConfigManagementGroup = new MenuGroup('ConfigManagement', 20 /* fRank */);
-
-// Create an entry, based on a custom template, for the Configuration management overview, under the top-level group
-new TemplateMenuNode('ConfigManagementOverview', dirname(__FILE__).'/overview.html', $oConfigManagementGroup->GetIndex(), 0 /* fRank */);
-
-
-$oContactNode = new TemplateMenuNode('Contact', dirname(__FILE__).'/contacts_menu.html', $oConfigManagementGroup->GetIndex(), 1 /* fRank */);
-new NewObjectMenuNode('NewContact', 'Contact', $oContactNode->GetIndex(), 1 /* fRank */);
-new SearchMenuNode('SearchContacts', 'Contact', $oContactNode->GetIndex(), 2 /* fRank */);
-
-new OQLMenuNode('Document', 'SELECT Document', $oConfigManagementGroup->GetIndex(), 2 /* fRank */, true /* bSearch */);
-new OQLMenuNode('Location', 'SELECT Location', $oConfigManagementGroup->GetIndex(), 3 /* fRank */, true /* bSearch */);
-new OQLMenuNode('Group', 'SELECT Group', $oConfigManagementGroup->GetIndex(), 4 /* fRank */, true /* bSearch */);
-
-
-$oCINode = new TemplateMenuNode('ConfigManagementCI', dirname(__FILE__).'/cis_menu.html', $oConfigManagementGroup->GetIndex(), 5 /* fRank */);
-new NewObjectMenuNode('NewCI', 'FunctionalCI', $oCINode->GetIndex(), 0 /* fRank */);
-new SearchMenuNode('SearchCIs', 'FunctionalCI', $oCINode->GetIndex(), 1 /* fRank */);
-
-$oShortcutsNode = new TemplateMenuNode('ConfigManagement:Shortcuts', '', $oConfigManagementGroup->GetIndex(), 6 /* fRank */);
-new OQLMenuNode('Server', 'SELECT Server', $oShortcutsNode->GetIndex(), 1 /* fRank */);
-new OQLMenuNode('NetworkDevice', 'SELECT NetworkDevice', $oShortcutsNode->GetIndex(), 2 /* fRank */);
-new OQLMenuNode('Printer', 'SELECT Printer', $oShortcutsNode->GetIndex(), 3 /* fRank */);
-new OQLMenuNode('PC', 'SELECT PC', $oShortcutsNode->GetIndex(), 4 /* fRank */);
-new OQLMenuNode('BusinessProcess', 'SELECT BusinessProcess', $oShortcutsNode->GetIndex(), 5 /* fRank */);
-new OQLMenuNode('ApplicationSolution', 'SELECT ApplicationSolution', $oShortcutsNode->GetIndex(), 6 /* fRank */);
-
 ?>

+ 3 - 0
datamodel/itop-incident-mgmt-1.0.0/datamodel.itop-incident-mgmt.xml

@@ -734,18 +734,21 @@
     <menu id="Incident:MyIncidents" type="OQLMenuNode">
       <oql value="SELECT Incident WHERE agent_id = :current_contact_id AND status NOT IN (&quot;closed&quot;, &quot;resolved&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Incident:Shortcuts"/>
       <rank value="1"/>
     </menu>
     <menu id="Incident:EscalatedIncidents" type="OQLMenuNode">
       <oql value="SELECT Incident WHERE status IN (&quot;escalated_tto&quot;, &quot;escalated_ttr&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="Incident:Shortcuts"/>
       <rank value="2"/>
     </menu>
     <menu id="Incident:OpenIncidents" type="OQLMenuNode">
       <oql value="SELECT Incident WHERE status IN (&quot;new&quot;, &quot;assigned&quot;, &quot;escalated_tto&quot;, &quot;escalated_ttr&quot;, &quot;resolved&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="standard"/>
       <parent value="Incident:Shortcuts"/>
       <rank value="3"/>
     </menu>

+ 0 - 12
datamodel/itop-incident-mgmt-1.0.0/main.itop-incident-mgmt.php

@@ -14,16 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oMyMenuGroup = new MenuGroup('IncidentManagement', 40 /* fRank */);
-new TemplateMenuNode('Incident:Overview', dirname(__FILE__).'/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
-new NewObjectMenuNode('NewIncident', 'Incident', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
-new SearchMenuNode('SearchIncidents', 'Incident', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
-$oShortcutNode = new TemplateMenuNode('Incident:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
-$oNode = new OQLMenuNode('Incident:MyIncidents', 'SELECT Incident WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('Incident:EscalatedIncidents', 'SELECT Incident WHERE status IN ("escalated_tto", "escalated_ttr")', $oShortcutNode->GetIndex(), 2 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('Incident:OpenIncidents', 'SELECT Incident WHERE status IN ("new", "assigned", "escalated_tto", "escalated_ttr", "resolved")', $oShortcutNode->GetIndex(), 3 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'standard'));
-
 ?>

+ 0 - 7
datamodel/itop-knownerror-mgmt-1.0.0/main.itop-knownerror-mgmt.php

@@ -14,11 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oMyMenuGroup = new MenuGroup('ProblemManagement', 42 /* fRank */);
-$iIndex = $oMyMenuGroup->GetIndex();
-new NewObjectMenuNode('NewError', 'KnownError', $iIndex, 3 /* fRank */);
-new SearchMenuNode('SearchError', 'KnownError', $iIndex, 4 /* fRank */);
-$oShortcutNode = new TemplateMenuNode('Problem:Shortcuts', '', $iIndex, 5 /* fRank */);
-new OQLMenuNode('Problem:KnownErrors', 'SELECT KnownError', $oShortcutNode->GetIndex(), 3 /* fRank */,true /*bsearch */);
-
 ?>

+ 0 - 9
datamodel/itop-problem-mgmt-1.0.0/main.itop-problem-mgmt.php

@@ -14,13 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oMyMenuGroup = new MenuGroup('ProblemManagement', 42 /* fRank */); // Will create if it does not exist
-$iIndex = $oMyMenuGroup->GetIndex();
-new TemplateMenuNode('Problem:Overview', dirname(__FILE__).'/overview.html', $iIndex /* oParent */, 0 /* fRank */);
-new NewObjectMenuNode('NewProblem', 'Problem', $iIndex, 1 /* fRank */);
-new SearchMenuNode('SearchProblems', 'Problem', $iIndex, 2 /* fRank */);
-$oShortcutNode = new TemplateMenuNode('Problem:Shortcuts', '', $iIndex, 5 /* fRank */);
-new OQLMenuNode('Problem:MyProblems', 'SELECT Problem WHERE agent_id = :current_contact_id AND status NOT IN ("closed", "resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
-new OQLMenuNode('Problem:OpenProblems', 'SELECT Problem WHERE status IN ("new", "assigned", "resolved")', $oShortcutNode->GetIndex(), 2 /* fRank */);
-
 ?>

+ 3 - 0
datamodel/itop-request-mgmt-1.0.0/datamodel.itop-request-mgmt.xml

@@ -696,18 +696,21 @@
     <menu id="UserRequest:MyRequests" type="OQLMenuNode">
       <oql value="SELECT UserRequest WHERE agent_id = :current_contact_id AND status NOT IN (&quot;closed&quot;,&quot;resolved&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="UserRequest:Shortcuts"/>
       <rank value="1"/>
     </menu>
     <menu id="UserRequest:EscalatedRequests" type="OQLMenuNode">
       <oql value="SELECT UserRequest WHERE status IN (&quot;escalated_tto&quot;, &quot;escalated_ttr&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="UserRequest:Shortcuts"/>
       <rank value="2"/>
     </menu>
     <menu id="UserRequest:OpenRequests" type="OQLMenuNode">
       <oql value="SELECT UserRequest WHERE status IN (&quot;new&quot;, &quot;assigned&quot;, &quot;escalated_tto&quot;, &quot;escalated_ttr&quot;, &quot;frozen&quot;, &quot;resolved&quot;)"/>
       <do_search value=""/>
+      <auto_reload value="fast"/>
       <parent value="UserRequest:Shortcuts"/>
       <rank value="3"/>
     </menu>

+ 0 - 13
datamodel/itop-request-mgmt-1.0.0/main.itop-request-mgmt.php

@@ -14,17 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oMyMenuGroup = new MenuGroup('RequestManagement', 30 /* fRank */);
-
-new TemplateMenuNode('UserRequest:Overview', dirname(__FILE__).'/overview.html', $oMyMenuGroup->GetIndex() /* oParent */, 0 /* fRank */);
-new NewObjectMenuNode('NewUserRequest', 'UserRequest', $oMyMenuGroup->GetIndex(), 1 /* fRank */);
-new SearchMenuNode('SearchUserRequests', 'UserRequest', $oMyMenuGroup->GetIndex(), 2 /* fRank */);
-$oShortcutNode = new TemplateMenuNode('UserRequest:Shortcuts', '', $oMyMenuGroup->GetIndex(), 3 /* fRank */);
-$oNode = new OQLMenuNode('UserRequest:MyRequests', 'SELECT UserRequest WHERE agent_id = :current_contact_id AND status NOT IN ("closed","resolved")', $oShortcutNode->GetIndex(), 1 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('UserRequest:EscalatedRequests', 'SELECT UserRequest WHERE status IN ("escalated_tto", "escalated_ttr")', $oShortcutNode->GetIndex(), 2 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-$oNode = new OQLMenuNode('UserRequest:OpenRequests', 'SELECT UserRequest WHERE status IN ("new", "assigned", "escalated_tto", "escalated_ttr", "frozen", "resolved")', $oShortcutNode->GetIndex(), 3 /* fRank */);
-$oNode->SetParameters(array('auto_reload' => 'fast'));
-
 ?>

+ 0 - 10
datamodel/itop-service-mgmt-1.0.0/main.itop-service-mgmt.php

@@ -14,14 +14,4 @@
 //   along with this program; if not, write to the Free Software
 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-$oServiceManagementGroup = new MenuGroup('ServiceManagement', 60 /* fRank */);
-$iRank = 0;
-new TemplateMenuNode('Service:Overview', dirname(__FILE__).'/overview.html', $oServiceManagementGroup->GetIndex() /* oParent */, $iRank++ /* fRank */);
-new OQLMenuNode('ProviderContract', 'SELECT ProviderContract', $oServiceManagementGroup->GetIndex(), $iRank++,true /* bsearch */);
-new OQLMenuNode('CustomerContract', 'SELECT CustomerContract', $oServiceManagementGroup->GetIndex(),  $iRank++,true /* bsearch */);
-new OQLMenuNode('Service', 'SELECT Service', $oServiceManagementGroup->GetIndex(), $iRank++,true /* bsearch */);
-new OQLMenuNode('ServiceSubcategory', 'SELECT ServiceSubcategory', $oServiceManagementGroup->GetIndex(), $iRank++,true /* bsearch */);
-new OQLMenuNode('SLA', 'SELECT SLA', $oServiceManagementGroup->GetIndex(), $iRank++,true /* bsearch */);
-new OQLMenuNode('SLT', 'SELECT SLT', $oServiceManagementGroup->GetIndex(), $iRank++,true /* bsearch */);
-
 ?>

+ 32 - 6
setup/compiler.class.inc.php

@@ -171,16 +171,29 @@ EOF;
 EOF;
 				file_put_contents($sResultFile, $sMenusHeader, FILE_APPEND);
 
+				// Preliminary: determine parent menus not defined within the current module
+				$aMenusToLoad = array();
 				foreach($oMenus as $oMenu)
 				{
+					if ($oParent = $this->GetOptionalElement($oMenu, 'parent'))
+					{
+						$aMenusToLoad[] = $oParent->GetAttribute('value');
+					}
+					// Note: the order matters: the parents must be defined BEFORE
+					$aMenusToLoad[] = $oMenu->GetAttribute('id');
+				}
+				$aMenusToLoad = array_unique($aMenusToLoad);
+				foreach($aMenusToLoad as $sMenuId)
+				{
+					$oMenu = $this->oFactory->GetMenu($sMenuId);
 					try
 					{
 						$this->CompileMenu($oMenu, $sResultFile, $sRelativeDir, $oP);
 					}
 					catch (ssDOMFormatException $e)
 					{
-						$sClass = $oClass->getAttribute("name");
-						throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
+						$sMenu = $oMenu->getAttribute("name");
+						throw new Exception("Failed to process menu '$sMenu', from '$sModuleRootDir': ".$e->getMessage());
 					}
 				}
 			}
@@ -868,20 +881,33 @@ EOF;
 				$sNewMenu = "new MenuGroup('$sMenuId', $fRank);";
 			}
 		}
-		$sIndent = '  ';
-		$sPHPMenu = "\$__comp_menus__['$sMenuId'] = $sNewMenu";
+
+		$sIndent = '';
+		$aPHPMenu = array("\$__comp_menus__['$sMenuId'] = $sNewMenu");
+		if ($oAutoReload = $this->GetOptionalElement($oMenu, 'auto_reload'))
+		{
+			$sAutoReload = addslashes($oAutoReload->GetAttribute("value"));
+			$aPHPMenu[] = "\$__comp_menus__['$sMenuId']->SetParameters(array('auto_reload' => '$sAutoReload'));";
+		}
 
 		$oAdminOnly = $this->GetOptionalElement($oMenu, 'enable_admin_only');
 		if ($oAdminOnly && $oAdminOnly->GetAttribute('value') == '1')
 		{
 			$sPHP = $sIndent."if (UserRights::IsAdministrator())\n";
 			$sPHP .= $sIndent."{\n";
-			$sPHP .= $sIndent."   $sPHPMenu\n";
+			foreach($aPHPMenu as $sPHPLine)
+			{
+				$sPHP .= $sIndent."   $sPHPLine\n";
+			}
 			$sPHP .= $sIndent."}\n";
 		}
 		else
 		{
-			$sPHP = $sIndent."$sPHPMenu\n";
+			$sPHP = '';
+			foreach($aPHPMenu as $sPHPLine)
+			{
+				$sPHP .= $sIndent.$sPHPLine."\n";
+			}
 		}
 
 		file_put_contents($sResFile, $sPHP, FILE_APPEND);

+ 25 - 0
setup/modelfactory.class.inc.php

@@ -1159,6 +1159,31 @@ EOF
 		return $this->_priv_GetNodes($sXPath, $this->oMenus);
 	}
 		
+	/**
+	 * Get a menu, given its is id
+	 * @param string $sModuleName
+	 * @param bool $bFlattenLayers
+	 * @throws Exception
+	 */
+	public function GetMenu($sMenuId, $bFlattenLayers = true)
+	{
+		if (!array_key_exists($sMenuId, self::$aLoadedMenus))
+		{
+			return null;
+		}
+		$oMenuNode = self::$aLoadedMenus[$sMenuId];
+		if ($bFlattenLayers)
+		{
+			$sOperation = $oMenuNode->getAttribute('_operation');
+			if ($sOperation == 'removed')
+			{
+				$oMenuNode = null;
+			}
+		}
+		return $oMenuNode;
+	}
+	
+
 	public function ApplyChanges()
 	{
 		$oNodes = $this->ListChanges();