N°3203 - Datamodel: Add semantic for image & state attributes Part. II

This commit is contained in:
Molkobain
2020-11-09 15:41:42 +01:00
parent 63d52787f0
commit f2ff5a4e83
28 changed files with 371 additions and 120 deletions

View File

@@ -1029,31 +1029,24 @@ EOF
// - Default attributes code
$sImageAttCode = "";
$sStateAttCode = "";
// - Parse optional semantic node
$oSemantic = $oProperties->GetOptionalElement('semantic');
if ($oSemantic) {
// - Parse optional fields semantic node
$oFieldsSemantic = $oProperties->GetOptionalElement('fields_semantic');
if ($oFieldsSemantic) {
// Image attribute
$oImageAttribute = $oSemantic->GetOptionalElement('image_attribute');
$oImageAttribute = $oFieldsSemantic->GetOptionalElement('image_attribute');
if ($oImageAttribute) {
$sImageAttCode = $oImageAttribute->GetText();
}
// State attribute, only if not already found from lifecycle
// $oStateAttribute = $oSemantic->GetOptionalElement('state_attribute');
// if(empty($sStateAttCode) && $oStateAttribute) {
// $sStateAttCode = $oStateAttribute->GetText();
// }
// State attribute (for XML v1.7- the lifecycle/attribute node should have been migrated in this one)
$oStateAttribute = $oFieldsSemantic->GetOptionalElement('state_attribute');
if($oStateAttribute) {
$sStateAttCode = $oStateAttribute->GetText();
}
}
$aClassParams['image_attcode'] = "'$sImageAttCode'";
$aClassParams['state_attcode'] = "'$sStateAttCode'";
// Lifecycle (overload any state attribute defined in the semantic node)
$oLifecycle = $oClass->GetOptionalElement('lifecycle');
if ($oLifecycle) {
$sStateAttCode = $oLifecycle->GetChildText('attribute');
$aClassParams['state_attcode'] = "'$sStateAttCode'";
}
// Reconcialiation
if ($oReconciliation = $oProperties->GetOptionalElement('reconciliation'))
{
@@ -1641,8 +1634,8 @@ EOF
//
$sLifecycle = '';
$sHighlightScale = '';
if ($oLifecycle)
{
$oLifecycle = $oClass->GetOptionalElement('lifecycle');
if ($oLifecycle) {
$sLifecycle .= "\t\t// Lifecycle (status attribute: $sStateAttCode)\n";
$sLifecycle .= "\t\t//\n";
@@ -1869,6 +1862,26 @@ EOF
}
}
}
// No "real" lifecycle with stimuli and such but still a state attribute, we need to define states from the enum. values
elseif ($oFieldsSemantic && $oStateAttribute) {
$sLifecycle .= "\t\t// States but no lifecycle declared in XML (status attribute: $sStateAttCode)\n";
$sLifecycle .= "\t\t//\n";
// Note: We can't use ModelFactory::GetField() as the current clas doesn't seem to be loaded yet.
$oField = $this->oFactory->GetNodes('field[@id="'.$sStateAttCode.'"]', $oFields)->item(0);
$oValues = $oField->GetUniqueElement('values');
$oValueNodes = $oValues->getElementsByTagName('value');
foreach($oValueNodes as $oValue)
{
$sLifecycle .= " MetaModel::Init_DefineState(\n";
$sLifecycle .= " \"".$oValue->GetText()."\",\n";
$sLifecycle .= " array(\n";
$sLifecycle .= " \"attribute_inherit\" => '',\n";
$sLifecycle .= " \"attribute_list\" => array()\n";
$sLifecycle .= " )\n";
$sLifecycle .= " );\n";
}
}
// ZLists
//

View File

@@ -95,7 +95,7 @@ class iTopDesignFormat
'go_to_previous' => 'From18To17',
'next' => null,
'go_to_next' => null,
)
),
);
/**
@@ -768,9 +768,35 @@ class iTopDesignFormat
*/
protected function From17To18($oFactory)
{
$oXPath = new DOMXPath($this->oDocument);
// N°3233 - Remove "display template" feature from MetaModel
$sPath = "/itop_design//class/properties/display_template";
$this->RemoveNodeFromXPath($sPath);
// N°3203 - Datamodel: Add semantic for image & state attributes
// - Move lifecycle attribute declaration to the semantic node
$oNodeList = $oXPath->query("/itop_design//class/lifecycle/attribute");
/** @var \DOMElement $oNode */
foreach ($oNodeList as $oNode) {
// Find semantic node or create it
$oPropertiesNode = $oXPath->query("../../properties", $oNode)->item(0);
$oFieldsSemanticNodeList = $oXPath->query("fields_semantic", $oPropertiesNode);
if ($oFieldsSemanticNodeList->length > 0) {
$oSemanticNode = $oFieldsSemanticNodeList->item(0);
}
else {
$oSemanticNode = $oPropertiesNode->ownerDocument->createElement("fields_semantic");
$oPropertiesNode->appendChild($oSemanticNode);
}
// Create state_attribute node
$oStateNode = $oSemanticNode->ownerDocument->createElement("state_attribute", $oNode->nodeValue);
$oSemanticNode->appendChild($oStateNode);
// Remove current node from lifecycle
$this->DeleteNode($oNode);
}
}
/**
@@ -780,6 +806,8 @@ class iTopDesignFormat
*/
protected function From18To17($oFactory)
{
$oXPath = new DOMXPath($this->oDocument);
// N°3182 - Remove style node from MenuGroup
$sPath = "/itop_design/menus/menu[@xsi:type='MenuGroup']/style";
$this->RemoveNodeFromXPath($sPath);
@@ -791,6 +819,27 @@ class iTopDesignFormat
// N°2982 - Speed up SCSS themes compilation during setup
$sPath = "/itop_design/branding/themes/theme/precompiled_stylesheet";
$this->RemoveNodeFromXPath($sPath);
// N°3203 - Datamodel: Add semantic for image & state attributes
// - Move state_attribute back to the lifecycle node if it has one
$oNodeList = $oXPath->query("/itop_design//class/properties/fields_semantic/state_attribute");
/** @var \DOMElement $oNode */
foreach ($oNodeList as $oNode) {
// Move node under lifecycle only if there is such a node
$oLifecycleNode = $oXPath->query("../../../lifecycle", $oNode)->item(0);
if($oLifecycleNode !== null)
{
// Create attribute node
$oAttributeNode = $oLifecycleNode->ownerDocument->createElement("attribute", $oNode->nodeValue);
$oLifecycleNode->appendChild($oAttributeNode);
}
// Remove current node from semantic in all cases
$this->DeleteNode($oNode);
}
// - Remove semantic node
$sPath = "/itop_design//class/properties/fields_semantic";
$this->RemoveNodeFromXPath($sPath);
}
/**