فهرست منبع

#757 Better UI to manage direct linksets: added the ability to provide the "reverse query" by specifying a '<filter>' tag on AttributeLinkedSet.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2942 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 11 سال پیش
والد
کامیت
a567494f60

+ 36 - 3
application/ui.linksdirectwidget.class.inc.php

@@ -243,7 +243,21 @@ class UILinksWidgetDirect
 	public function GetObjectsSelectionDlg($oPage, $oCurrentObj)
 	{
 		$sHtml = "<div class=\"wizContainer\" style=\"vertical-align:top;\">\n";
-		$oFilter = new DBObjectSearch($this->sLinkedClass);
+		
+		$oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
+		$valuesDef = $oLinksetDef->GetValuesDef();				
+		if ($valuesDef === null)
+		{
+			$oFilter = new DBObjectSearch($this->sLinkedClass);
+		}
+		else
+		{
+			if (!$valuesDef instanceof ValueSetObjects)
+			{
+				throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet ('.$this->sClass.'/'.$this->sAttCode.').');
+			}
+			$oFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression());
+		}
 		if ($oCurrentObj != null)
 		{
 			$this->SetSearchDefaultFromContext($oCurrentObj, $oFilter);
@@ -276,7 +290,21 @@ class UILinksWidgetDirect
 		{
 			$sRemoteClass = $this->sLinkedClass;
 		}
-		$oFilter = new DBObjectSearch($sRemoteClass);
+		$oLinksetDef = MetaModel::GetAttributeDef($this->sClass, $this->sAttCode);
+		$valuesDef = $oLinksetDef->GetValuesDef();				
+		if ($valuesDef === null)
+		{
+			$oFilter = new DBObjectSearch($this->sLinkedClass);
+		}
+		else
+		{
+			if (!$valuesDef instanceof ValueSetObjects)
+			{
+				throw new Exception('Error: only ValueSetObjects are supported for "allowed_values" in AttributeLinkedSet ('.$this->sClass.'/'.$this->sAttCode.').');
+			}
+			$oFilter = DBObjectSearch::FromOQL($valuesDef->GetFilterExpression());
+		}
+		
 		if (($oCurrentObj != null) && MetaModel::IsSameFamilyBranch($sRemoteClass, $this->sClass))
 		{
 			// Prevent linking to self if the linked object is of the same family
@@ -290,7 +318,12 @@ class UILinksWidgetDirect
 		{
 			$oFilter->AddCondition('id', $aAlreadyLinked, 'NOTIN');
 		}
-		$oSet = new CMDBObjectSet($oFilter);
+		$aArgs = array();
+		if ($oCurrentObj != null)
+		{
+			$aArgs = $oCurrentObj->ToArgs('this');
+		}
+		$oFilter->SetInternalParams($aArgs);
 		$oBlock = new DisplayBlock($oFilter, 'list', false);
 		$oBlock->Display($oP, "ResultsToAdd_{$this->sInputid}", array('menu' => false, 'cssCount'=> '#count_'.$this->sInputid , 'selection_mode' => true, 'table_id' => 'add_'.$this->sInputid)); // Don't display the 'Actions' menu on the results
 	}

+ 12 - 8
core/metamodel.class.php

@@ -3311,7 +3311,7 @@ abstract class MetaModel
 			{
 				if(!self::IsValidAttCode($sClass, $sAttCode))
 				{
-					$aErrors[$sClass][] = "Unkown attribute code '".$sAttCode."' for the name definition";
+					$aErrors[$sClass][] = "Unknown attribute code '".$sAttCode."' for the name definition";
 					$aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass));
 				}
 			}				
@@ -3320,7 +3320,7 @@ abstract class MetaModel
 			{
 				if (!empty($sReconcKeyAttCode) && !self::IsValidAttCode($sClass, $sReconcKeyAttCode))
 				{
-					$aErrors[$sClass][] = "Unkown attribute code '".$sReconcKeyAttCode."' in the list of reconciliation keys";
+					$aErrors[$sClass][] = "Unknown attribute code '".$sReconcKeyAttCode."' in the list of reconciliation keys";
 					$aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass));
 				}
 			}
@@ -3335,7 +3335,7 @@ abstract class MetaModel
 				{
 					if (!self::IsValidClass($oAttDef->GetTargetClass()))
 					{
-						$aErrors[$sClass][] = "Unkown class '".$oAttDef->GetTargetClass()."' for the external key '$sAttCode'";
+						$aErrors[$sClass][] = "Unknown class '".$oAttDef->GetTargetClass()."' for the external key '$sAttCode'";
 						$aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetClasses())."}";
 					}
 				}
@@ -3344,7 +3344,7 @@ abstract class MetaModel
 					$sKeyAttCode = $oAttDef->GetKeyAttCode();
 					if (!self::IsValidAttCode($sClass, $sKeyAttCode) || !self::IsValidKeyAttCode($sClass, $sKeyAttCode))
 					{
-						$aErrors[$sClass][] = "Unkown key attribute code '".$sKeyAttCode."' for the external field $sAttCode";
+						$aErrors[$sClass][] = "Unknown key attribute code '".$sKeyAttCode."' for the external field $sAttCode";
 						$aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetKeysList($sClass))."}";
 					}
 					else
@@ -3354,11 +3354,15 @@ abstract class MetaModel
 						$sExtAttCode = $oAttDef->GetExtAttCode();
 						if (!self::IsValidAttCode($sTargetClass, $sExtAttCode))
 						{
-							$aErrors[$sClass][] = "Unkown key attribute code '".$sExtAttCode."' for the external field $sAttCode";
+							$aErrors[$sClass][] = "Unknown key attribute code '".$sExtAttCode."' for the external field $sAttCode";
 							$aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetKeysList($sTargetClass))."}";
 						}
 					}
 				}
+				else if ($oAttDef->IsLinkSet())
+				{
+					// Do nothing...
+				}
 				else // standard attributes
 				{
 					// Check that the default values definition is a valid object!
@@ -3391,7 +3395,7 @@ abstract class MetaModel
 					{
 						if (!self::IsValidAttCode($sClass, $sDependOnAttCode))
 						{
-							$aErrors[$sClass][] = "Unkown attribute code '".$sDependOnAttCode."' in the list of prerequisite attributes";
+							$aErrors[$sClass][] = "Unknown attribute code '".$sDependOnAttCode."' in the list of prerequisite attributes";
 							$aSugFix[$sClass][] = "Expecting a value in ".implode(", ", self::GetAttributesList($sClass));
 						}
 					}
@@ -3418,7 +3422,7 @@ abstract class MetaModel
 				// Lifecycle - check that the state attribute does exist as an attribute
 				if (!self::IsValidAttCode($sClass, $sStateAttCode))
 				{
-					$aErrors[$sClass][] = "Unkown attribute code '".$sStateAttCode."' for the state definition";
+					$aErrors[$sClass][] = "Unknown attribute code '".$sStateAttCode."' for the state definition";
 					$aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetAttributesList($sClass))."}";
 				}
 				else
@@ -3492,7 +3496,7 @@ abstract class MetaModel
 				{
 					if (!self::IsValidAttCode($sClass, $sMyAttCode))
 					{
-						$aErrors[$sClass][] = "Unkown attribute code '".$sMyAttCode."' from ZList '$sListCode'";
+						$aErrors[$sClass][] = "Unknown attribute code '".$sMyAttCode."' from ZList '$sListCode'";
 						$aSugFix[$sClass][] = "Expecting a value in {".implode(", ", self::GetAttributesList($sClass))."}";
 					}
 				}

+ 5 - 4
datamodels/2.x/itop-change-mgmt-itil/datamodel.itop-change-mgmt-itil.xml

@@ -170,28 +170,29 @@
         <field id="related_request_list" xsi:type="AttributeLinkedSet">
           <linked_class>UserRequest</linked_class>
           <ext_key_to_me>parent_change_id</ext_key_to_me>
-          <edit_mode>none</edit_mode>
+          <edit_mode>add_remove</edit_mode>
           <count_min>0</count_min>
           <count_max>0</count_max>
         </field>
         <field id="related_incident_list" xsi:type="AttributeLinkedSet">
           <linked_class>Incident</linked_class>
           <ext_key_to_me>parent_change_id</ext_key_to_me>
-          <edit_mode>none</edit_mode>
+          <edit_mode>add_remove</edit_mode>
           <count_min>0</count_min>
           <count_max>0</count_max>
         </field>
         <field id="related_problems_list" xsi:type="AttributeLinkedSet">
           <linked_class>Problem</linked_class>
           <ext_key_to_me>related_change_id</ext_key_to_me>
-          <edit_mode>none</edit_mode>
+          <edit_mode>add_remove</edit_mode>
           <count_min>0</count_min>
           <count_max>0</count_max>
         </field>
         <field id="child_changes_list" xsi:type="AttributeLinkedSet">
           <linked_class>Change</linked_class>
           <ext_key_to_me>parent_id</ext_key_to_me>
-          <edit_mode>none</edit_mode>
+          <edit_mode>add_remove</edit_mode>
+          <filter><![CDATA[SELECT Change WHERE id != :this->id]]></filter>
           <count_min>0</count_min>
           <count_max>0</count_max>
         </field>

+ 1 - 0
datamodels/2.x/itop-change-mgmt/datamodel.itop-change-mgmt.xml

@@ -130,6 +130,7 @@
           <linked_class>Change</linked_class>
           <ext_key_to_me>parent_id</ext_key_to_me>
           <edit_mode>add_remove</edit_mode>
+          <filter><![CDATA[SELECT Change WHERE id != :this->id]]></filter>
           <count_min>0</count_min>
           <count_max>0</count_max>
         </field>

+ 9 - 1
setup/compiler.class.inc.php

@@ -723,7 +723,6 @@ EOF;
 			{
 				$aParameters['linked_class'] = $this->GetPropString($oField, 'linked_class', '');
 				$aParameters['ext_key_to_me'] = $this->GetPropString($oField, 'ext_key_to_me', '');
-				$aParameters['allowed_values'] = 'null';
 				$aParameters['count_min'] = $this->GetPropNumber($oField, 'count_min', 0);
 				$aParameters['count_max'] = $this->GetPropNumber($oField, 'count_max', 0);
 				$sEditMode = $oField->GetChildText('edit_mode');
@@ -731,6 +730,15 @@ EOF;
 				{
 					$aParameters['edit_mode'] = $this->EditModeToPHP($sEditMode);
 				}
+				if ($sOql = $oField->GetChildText('filter'))
+				{
+					$sEscapedOql = self::QuoteForPHP($sOql);
+					$aParameters['allowed_values'] = "new ValueSetObjects($sEscapedOql)";
+				}
+				else
+				{
+					$aParameters['allowed_values'] = 'null';
+				}
 				$aParameters['depends_on'] = $sDependencies;
 			}
 			elseif ($sAttType == 'AttributeExternalKey')