🎨 Code formatting on pages/schema.php

This commit is contained in:
Pierre Goiffon
2020-01-16 11:30:18 +01:00
parent 02265135e3
commit c7ca1eeab5

View File

@@ -32,7 +32,9 @@ ApplicationMenu::CheckMenuIdEnabled('DataModelMenu');
*/
function MakeClassHLink($sClass, $sContext)
{
return "<a href=\"schema.php?operation=details_class&class=$sClass{$sContext}\" title=\"".html_entity_decode(MetaModel::GetClassDescription($sClass),ENT_QUOTES,'UTF-8')."\"><span class=\"attrLabel\">".MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" .$sClass."</span><span class=\"parenthesis\">)</span></a>";
return "<a href=\"schema.php?operation=details_class&class=$sClass{$sContext}\" title=\"".html_entity_decode(MetaModel::GetClassDescription($sClass),
ENT_QUOTES,
'UTF-8')."\"><span class=\"attrLabel\">".MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$sClass."</span><span class=\"parenthesis\">)</span></a>";
}
/**
@@ -41,6 +43,7 @@ function MakeClassHLink($sClass, $sContext)
function MakeRelationHLink($sRelCode, $sContext)
{
$sDesc = MetaModel::GetRelationDescription($sRelCode);
return "<a href=\"schema.php?operation=details_relation&relcode=$sRelCode{$sContext}\" title=\"$sDesc\">".$sRelCode."</a>";
}
@@ -54,24 +57,24 @@ function DisplaySubclasses($oPage, $sClass, $sContext)
{
$oPage->add("<ul>\n");
$aOrderedClasses = array();
foreach($aChildClasses as $sClassName)
foreach ($aChildClasses as $sClassName)
{
// Skip indirect childs, they will be handled somewhere else
if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
{
$aOrderedClasses[$sClassName] = MetaModel::GetName($sClassName);
$aOrderedClasses[$sClassName] = MetaModel::GetName($sClassName);
}
}
// Sort on the display name
asort($aOrderedClasses);
foreach($aOrderedClasses as $sClassName => $sDisplayName)
foreach ($aOrderedClasses as $sClassName => $sDisplayName)
{
// Skip indirect childs, they will be handled somewhere else
if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
{
$oPage->add("<li class=\"open\">".MakeClassHLink($sClassName, $sContext)."\n");
DisplaySubclasses($oPage, $sClassName, $sContext);
$oPage->add("</li>\n");
$oPage->add("<li class=\"open\">".MakeClassHLink($sClassName, $sContext)."\n");
DisplaySubclasses($oPage, $sClassName, $sContext);
$oPage->add("</li>\n");
}
}
$oPage->add("</ul>\n");
@@ -122,7 +125,7 @@ EOF
$sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
$oPage->add("<li class=\"closed\"><span class=\"attrLabel\">$sStateLabel </span><span style=\"color:grey;\"><span class=\"parenthesis\">(</span><span class=\"attrCode\">$sStateCode</span><span class=\"parenthesis\">) </span>$sStateDescription</span>\n");
$oPage->add("<ul class=\"closed\">\n");
foreach(MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
foreach (MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
{
$sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
$sTargetState = $aTransitionDef['target_state'];
@@ -167,21 +170,36 @@ EOF
{
$sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
$sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
$oPage->add("<li class=\"closed\"><span class=\"attrLabel\">$sStateLabel </span><span style=\"color:grey;\"><span class=\"parenthesis\">(</span><span class=\"attrCode\">$sStateCode</span><span class=\"parenthesis\">) </span>$sStateDescription</span>\n");
$oPage->add("<li class=\"closed\"><span class=\"attrLabel\">$sStateLabel </span><span style=\"color:grey;\"><span class=\"parenthesis\">(</span><span class=\"attrCode\">$sStateCode</span><span class=\"parenthesis\">) </span>$sStateDescription</span>\n");
if (count($aStates[$sStateCode]['attribute_list']) > 0)
{
$oPage->add("<ul>\n");
foreach($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
foreach ($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
{
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
$sAttLabel = $oAttDef->GetLabel();
$aOptions = array();
if ($iOptions & OPT_ATT_HIDDEN) $aOptions[] = Dict::S('UI:Schema:LifeCycleHiddenAttribute');
if ($iOptions & OPT_ATT_READONLY) $aOptions[] = Dict::S('UI:Schema:LifeCycleReadOnlyAttribute');
if ($iOptions & OPT_ATT_MANDATORY) $aOptions[] = Dict::S('UI:Schema:LifeCycleMandatoryAttribute');
if ($iOptions & OPT_ATT_MUSTCHANGE) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustChange');
if ($iOptions & OPT_ATT_MUSTPROMPT) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustPrompt');
if ($iOptions & OPT_ATT_HIDDEN)
{
$aOptions[] = Dict::S('UI:Schema:LifeCycleHiddenAttribute');
}
if ($iOptions & OPT_ATT_READONLY)
{
$aOptions[] = Dict::S('UI:Schema:LifeCycleReadOnlyAttribute');
}
if ($iOptions & OPT_ATT_MANDATORY)
{
$aOptions[] = Dict::S('UI:Schema:LifeCycleMandatoryAttribute');
}
if ($iOptions & OPT_ATT_MUSTCHANGE)
{
$aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustChange');
}
if ($iOptions & OPT_ATT_MUSTPROMPT)
{
$aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustPrompt');
}
if (count($aOptions))
{
$sOptions = implode(', ', $aOptions);
@@ -190,7 +208,7 @@ EOF
{
$sOptions = "";
}
$oPage->add("<li class=\"closed\"><span style=\"color:purple;font-weight=bold;\">$sAttLabel</span> $sOptions</li>\n");
}
$oPage->add("</ul></li>\n");
@@ -201,9 +219,9 @@ EOF
}
}
$oPage->add("</ul>\n");
$oPage->add_ready_script('$("#LifeCycleList").treeview({collapsed: true,});');
$oPage->add_ready_script('$("#LifeCycleAttrOptList").treeview({collapsed: true,});');
}
$oPage->add_ready_script('$("#LifeCycleList").treeview({collapsed: true,});');
$oPage->add_ready_script('$("#LifeCycleAttrOptList").treeview({collapsed: true,});');
}
}
@@ -225,8 +243,8 @@ function DisplayClassesList($oPage, $sContext)
{
$oPage->add("<h1>".Dict::S('UI:Schema:Title')."</h1>\n");
$oPage->add("<label for='search-model'>" . Dict::S('UI:Schema:ClassFilter') ."</label><br/><input type=\"text\" id=\"search-model\" autofocus=\"autofocus\"/>");
$oPage->add("<div id=\"delDataModelSearch\"> <i class=\"fas fa-times-circle\"></i></div>");
$oPage->add("<label for='search-model'>".Dict::S('UI:Schema:ClassFilter')."</label><br/><input type=\"text\" id=\"search-model\" autofocus=\"autofocus\"/>");
$oPage->add("<div id=\"delDataModelSearch\"> <i class=\"fas fa-times-circle\"></i></div>");
$oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
$oPage->add_ready_script(
<<<EOF
@@ -280,7 +298,7 @@ EOF
);
// Get all the "root" classes for display
$aRootClasses = array();
foreach(MetaModel::GetClasses() as $sClassName)
foreach (MetaModel::GetClasses() as $sClassName)
{
if (MetaModel::IsRootClass($sClassName))
{
@@ -290,19 +308,19 @@ EOF
{
$aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
}
$sLabelClassName = MetaModel::GetName($sClassName);
$sLabelClassName = MetaModel::GetName($sClassName);
//Fetch classes names for autocomplete purpose
$oPage->add_script(
<<<EOF
$oPage->add_script(
<<<EOF
autocompleteClassLabelAndCode.push("$sLabelClassName ($sClassName)");
autocompleteClassLabel.push("$sLabelClassName");
autocompleteClassCode.push("$sClassName");
EOF
);
);
}
// Sort them alphabetically on their display name
asort($aRootClasses);
foreach($aRootClasses as $sClassName => $sDisplayName)
foreach ($aRootClasses as $sClassName => $sDisplayName)
{
if (MetaModel::IsRootClass($sClassName))
{
@@ -325,173 +343,190 @@ EOF
*/
function DisplayRelatedClassesGraph($oPage, $sClass)
{
try
{
$bOnTheLeft = true;
$bSkipLinkingClasses = false;
try
{
$bOnTheLeft = true;
$bSkipLinkingClasses = false;
// 1) Fetching referencing classes data
//
$aData = array();
$aOrigins = array('_' => true);
$aRefs = MetaModel::EnumReferencingClasses($sClass, $bSkipLinkingClasses);
$sSelfReference = "false";
if (count($aRefs) != 0)
{
foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
{
foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
{
if($sRemoteClass != $sClass)
//
$aData = array();
$aOrigins = array('_' => true);
$aRefs = MetaModel::EnumReferencingClasses($sClass, $bSkipLinkingClasses);
$sSelfReference = "false";
if (count($aRefs) != 0)
{
foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
{
foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
{
if ($sRemoteClass != $sClass)
{
// ref_prefix to avoid collision between attributes labels that refer to this class and local attributes label that references other classes
$aAttribute = array('label' => 'ref_'.$sExtKeyAttCode);
// Test if a distant attribut exists and if it uses a link class
if(!($oExtKeyAttDef->GetMirrorLinkAttribute() == null ? false : $oExtKeyAttDef->GetMirrorLinkAttribute() instanceof AttributeLinkedSetIndirect))
{
$aAttribute['related'] = $sRemoteClass;
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? -1 : 1;
$aAttribute['relation_type'] = 0;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
$sOrigin = MetaModel::GetAttributeOrigin($sRemoteClass, $sExtKeyAttCode);
$aAttribute['origin'] = $sOrigin;
$aOrigins[$sOrigin] = true;
$aData[$sExtKeyAttCode . $sRemoteClass] = $aAttribute;
}
}
}
}
}
$aAttribute = array('label' => 'ref_'.$sExtKeyAttCode);
// Test if a distant attribut exists and if it uses a link class
if (!($oExtKeyAttDef->GetMirrorLinkAttribute() == null ? false : $oExtKeyAttDef->GetMirrorLinkAttribute() instanceof AttributeLinkedSetIndirect))
{
$aAttribute['related'] = $sRemoteClass;
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? -1 : 1;
$aAttribute['relation_type'] = 0;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
$sOrigin = MetaModel::GetAttributeOrigin($sRemoteClass, $sExtKeyAttCode);
$aAttribute['origin'] = $sOrigin;
$aOrigins[$sOrigin] = true;
$aData[$sExtKeyAttCode.$sRemoteClass] = $aAttribute;
}
}
}
}
}
// 2) Fetching referenced classes data
//
$aDataRef = array(array('label' => $sClass, 'icon' => MetaModel::GetClassIcon($sClass, false), 'origin_index' => 0, 'alphabetical_index' => 0, 'origin' => '_'));
$bOnTheLeft = true;
$aOriginsRef = array('_' => true);
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{
$aAttribute = array('label' => $sAttCode);
if ($oAttDef->IsLinkSet())
{
if ($oAttDef->IsIndirect())
{
$sRemoteAttDef = $oAttDef->GetExtKeyToRemote();
$aAttribute['related'] = MetaModel::GetAttributeDef($oAttDef->GetLinkedClass(), $sRemoteAttDef)->GetTargetClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 0; //
$aAttribute['tooltip_data']['class'] = $oAttDef->GetLinkedClass();
$aAttribute['tooltip_data']['to_remote'] = $sRemoteAttDef;
$aAttribute['tooltip_data']['to_me'] = $oAttDef->GetExtKeyToMe();
// 2) Fetching referenced classes data
//
$aDataRef = array(
array(
'label' => $sClass,
'icon' => MetaModel::GetClassIcon($sClass, false),
'origin_index' => 0,
'alphabetical_index' => 0,
'origin' => '_',
),
);
$bOnTheLeft = true;
$aOriginsRef = array('_' => true);
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{
$aAttribute = array('label' => $sAttCode);
if ($oAttDef->IsLinkSet())
{
if ($oAttDef->IsIndirect())
{
$sRemoteAttDef = $oAttDef->GetExtKeyToRemote();
$aAttribute['related'] = MetaModel::GetAttributeDef($oAttDef->GetLinkedClass(), $sRemoteAttDef)->GetTargetClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 0; //
$aAttribute['tooltip_data']['class'] = $oAttDef->GetLinkedClass();
$aAttribute['tooltip_data']['to_remote'] = $sRemoteAttDef;
$aAttribute['tooltip_data']['to_me'] = $oAttDef->GetExtKeyToMe();
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
else
{
$aAttribute['related'] = $oAttDef->GetLinkedClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 1;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
else
{
$aAttribute['related'] = $oAttDef->GetLinkedClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 1;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
}
else if ($oAttDef->IsHierarchicalKey())
{
$aAttribute['related'] = $sClass;
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 2;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
$sSelfReference = "true";
}
else if ($oAttDef->IsExternalKey())
{
$aAttribute['related'] = $oAttDef->GetTargetClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 3;
}
else
{
if ($oAttDef->IsHierarchicalKey())
{
$aAttribute['related'] = $sClass;
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 2;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
$sSelfReference = "true";
}
else
{
if ($oAttDef->IsExternalKey())
{
$aAttribute['related'] = $oAttDef->GetTargetClass();
$aAttribute['related_icon'] = MetaModel::GetClassIcon($aAttribute['related'], false);
$aAttribute['related_position'] = $bOnTheLeft ? 1 : -1;
$aAttribute['relation_type'] = 3;
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
if ($oAttDef->IsLinkSet() || $oAttDef->IsHierarchicalKey() || $oAttDef->IsExternalKey()){
$sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
$bOnTheLeft = !$bOnTheLeft; // Toggle the side
}
}
}
if ($oAttDef->IsLinkSet() || $oAttDef->IsHierarchicalKey() || $oAttDef->IsExternalKey())
{
$sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
$aAttribute['origin'] = $sOrigin;
$aOriginsRef[$sOrigin] = true;
$aDataRef[$sAttCode] = $aAttribute;
$aOriginsRef[$sOrigin] = true;
$aDataRef[$sAttCode] = $aAttribute;
}
}
}
//sort referencing data
//sort referencing data
$aOrigins = array_keys($aOrigins);
$idx = 0;
$aOrigins = array_keys($aOrigins);
$idx = 0;
$bOnTheLeft = true;
foreach($aData as $sAttCode => $aAttribute)
{
$is_also_referenced = false;
foreach($aDataRef as $sAttCodeRef => $aAttributeRef)
{
if(!empty($aDataRef[$sAttCodeRef]['related']) && ($aData[$sAttCode]['related'] == $aDataRef[$sAttCodeRef]['related']))
$is_also_referenced = true;
}
if(!$is_also_referenced)
{
$aData[$sAttCode]['related_position'] = ($bOnTheLeft) ? -1 : 1;
$bOnTheLeft = !$bOnTheLeft;
$aData[$sAttCode]['origin_index'] = ($aData[$sAttCode]['related_position'] == -1) ? ++$idx : $idx;
}
else
{
unset($aData[$sAttCode]);
}
}
ksort($aData);
$idx = 0;
$aFinalDataReferencing = array();
foreach($aData as $sAttCode => $aAttribute)
{
$aData[$sAttCode]['alphabetical_index'] = $aAttribute['related_position'] == 1 ? ++$idx : $idx;
$aFinalDataReferencing[] = $aData[$sAttCode];
}
$sDataReferencing = json_encode($aFinalDataReferencing);
$sOriginsReferencing = json_encode(array_keys($aOrigins));
foreach ($aData as $sAttCode => $aAttribute)
{
$is_also_referenced = false;
foreach ($aDataRef as $sAttCodeRef => $aAttributeRef)
{
if (!empty($aDataRef[$sAttCodeRef]['related']) && ($aData[$sAttCode]['related'] == $aDataRef[$sAttCodeRef]['related']))
{
$is_also_referenced = true;
}
}
if (!$is_also_referenced)
{
$aData[$sAttCode]['related_position'] = ($bOnTheLeft) ? -1 : 1;
$bOnTheLeft = !$bOnTheLeft;
$aData[$sAttCode]['origin_index'] = ($aData[$sAttCode]['related_position'] == -1) ? ++$idx : $idx;
}
else
{
unset($aData[$sAttCode]);
}
}
ksort($aData);
$idx = 0;
$aFinalDataReferencing = array();
foreach ($aData as $sAttCode => $aAttribute)
{
$aData[$sAttCode]['alphabetical_index'] = $aAttribute['related_position'] == 1 ? ++$idx : $idx;
$aFinalDataReferencing[] = $aData[$sAttCode];
}
$sDataReferencing = json_encode($aFinalDataReferencing);
$sOriginsReferencing = json_encode(array_keys($aOrigins));
//sort referenced data
//sort referenced data
$idx = 1;
foreach($aDataRef as $sAttCode => $aAttribute)
{
$aDataRef[$sAttCode]['origin_index'] = $idx++;
}
$idx = 1;
foreach ($aDataRef as $sAttCode => $aAttribute)
{
$aDataRef[$sAttCode]['origin_index'] = $idx++;
}
$idx = 1;
$aFinalData = array();
foreach($aDataRef as $sAttCode => $aAttribute)
{
$aDataRef[$sAttCode]['alphabetical_index'] = $idx++;
$aFinalData[] = $aDataRef[$sAttCode];
}
$idx = 1;
$aFinalData = array();
foreach ($aDataRef as $sAttCode => $aAttribute)
{
$aDataRef[$sAttCode]['alphabetical_index'] = $idx++;
$aFinalData[] = $aDataRef[$sAttCode];
}
$sData = json_encode($aFinalData);
$sData = json_encode($aFinalData);
// 3) Processing data and building graph
//
$oPage->add(
<<<EOF
// 3) Processing data and building graph
//
$oPage->add(
<<<EOF
<div id="dataModelGraph">
<svg class="dataModelSchema" width="100%" height="800">
</svg>
</div>
EOF
);
$oPage->add_ready_script(
<<<JS
);
$oPage->add_ready_script(
<<<JS
var data = $sData;
var dataref = $sDataReferencing;
@@ -754,12 +789,12 @@ field.filter(function(d) {
.attr("transform", "translate(-12, -24)");
JS
);
}
catch(Exception $e)
{
$oPage->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->getMessage()).'</b>');
}
);
}
catch (Exception $e)
{
$oPage->p('<b>'.Dict::Format('UI:RunQuery:Error', $e->getMessage()).'</b>');
}
}
/**
@@ -775,7 +810,7 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
{
DisplayClassHeader($oPage, $sClass);
$aParentClasses = array();
foreach(MetaModel::EnumParentClasses($sClass) as $sParentClass)
foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass)
{
$aParentClasses[] = MakeClassHLink($sParentClass, $sContext);
}
@@ -793,10 +828,10 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
{
$oPage->add("<ul id=\"ClassHierarchy\">");
$oPage->add("<li class=\"closed\">".$sClass."\n");
DisplaySubclasses($oPage, $sClass,$sContext);
DisplaySubclasses($oPage, $sClass, $sContext);
$oPage->add("</li>\n");
$oPage->add("</ul>\n");
$oPage->add_ready_script('$("#ClassHierarchy").treeview();');
$oPage->add_ready_script('$("#ClassHierarchy").treeview();');
}
$oPage->p('');
$oPage->add("</div>");
@@ -808,11 +843,11 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
$aDetails = array();
$aOrigins = array();
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
foreach (MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
{
if ($oAttDef->IsExternalKey())
{
$sValue = Dict::Format('UI:Schema:ExternalKey_To',MakeClassHLink($oAttDef->GetTargetClass(), $sContext));
$sValue = Dict::Format('UI:Schema:ExternalKey_To', MakeClassHLink($oAttDef->GetTargetClass(), $sContext));
if (array_key_exists($sAttCode, $aForwardChangeTracking))
{
$oLinkSet = $aForwardChangeTracking[$sAttCode];
@@ -826,19 +861,19 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
}
else
{
$sValue = $oAttDef->GetDescription();
$sValue = $oAttDef->GetDescription();
}
$sType = get_class($oAttDef);
$sTypeDict = $oAttDef->GetType();
$sTypeDesc = $oAttDef->GetTypeDesc();
$sTypeDesc = $oAttDef->GetTypeDesc();
$sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
$aOrigins[$sOrigin] = true;
$sAllowedValues = "";
$sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
$aOrigins[$sOrigin] = true;
$sAllowedValues = "";
$sMoreInfo = "";
$sDefaultNullValue = '""';
$aCols = array();
foreach($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc)
foreach ($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc)
{
$aCols[] = "$sCol: $sFieldDesc";
}
@@ -846,24 +881,25 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
{
$aMoreInfo = array();
if($oAttDef->IsNullAllowed())
if ($oAttDef->IsNullAllowed())
{
$aMoreInfo[] = Dict::S('UI:Schema:NullAllowed');
$sDefaultNullValue = (!is_null($oAttDef->GetNullValue()) ? $oAttDef->GetNullValue() : null );
if(!is_null($sDefaultNullValue) && !is_string($sDefaultNullValue))
$sDefaultNullValue = (!is_null($oAttDef->GetNullValue()) ? $oAttDef->GetNullValue() : null);
if (!is_null($sDefaultNullValue) && !is_string($sDefaultNullValue))
{
$sDefaultNullValue = json_encode($sDefaultNullValue);
}
$sDefaultNullValue = (!is_null($sDefaultNullValue) ? json_encode(Dict::Format('UI:Schema:DefaultNullValue', $sDefaultNullValue)) : '""' );
$sDefaultNullValue = (!is_null($sDefaultNullValue) ? json_encode(Dict::Format('UI:Schema:DefaultNullValue',
$sDefaultNullValue)) : '""');
}
else
{
$aMoreInfo[] = Dict::S('UI:Schema:NullNotAllowed');
}
if($oAttDef->GetDefaultValue())
if ($oAttDef->GetDefaultValue())
{
$sDefaultValue = $oAttDef->GetDefaultValue();
if(!is_string($sDefaultValue))
if (!is_string($sDefaultValue))
{
$sDefaultValue = json_encode($sDefaultValue);
}
@@ -871,29 +907,29 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
}
$sMoreInfo .= implode(', ', $aMoreInfo);
}
$sAttrCode = $oAttDef->GetCode();
$sIsEnumValues = 'false';
$sAllowedValuesEscpd = '""';
$sAttrCode = $oAttDef->GetCode();
$sIsEnumValues = 'false';
$sAllowedValuesEscpd = '""';
if ($oAttDef instanceof AttributeEnum)
{
// Display localized values for the enum (which depend on the localization provided by the class)
$aLocalizedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array());
$aDescription = array();
foreach($aLocalizedValues as $val => $sDisplay)
foreach ($aLocalizedValues as $val => $sDisplay)
{
$aDescription[] = "<span class=\"attrLabel\">". $sDisplay ."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" . $val . "</span><span class=\"parenthesis\">)</span>";
$aDescription[] = "<span class=\"attrLabel\">".$sDisplay."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$val."</span><span class=\"parenthesis\">)</span>";
}
$sAllowedValues = implode(', ', $aDescription);
$sIsEnumValues = 'true';
$sIsEnumValues = 'true';
}
elseif (is_object($oAllowedValuesDef = $oAttDef->GetValuesDef()))
{
$sAllowedValues = str_replace("Filter: ", "", $oAllowedValuesDef->GetValuesDescription());
$sAllowedValuesEscpd = json_encode($sAllowedValues);
$sAllowedValuesEscpd = json_encode($sAllowedValues);
$sFilterURL = urlencode($sAllowedValues);
$sAllowedValues = "<span id=\"values" . $sAttrCode ."\"><a href=\"run_query.php?expression=" . $sFilterURL . "\">⚵</a>" . Dict::S('UI:Schema:Attribute/Filter') . "</span>";
}
$sFilterURL = urlencode($sAllowedValues);
$sAllowedValues = "<span id=\"values".$sAttrCode."\"><a href=\"run_query.php?expression=".$sFilterURL."\">⚵</a>".Dict::S('UI:Schema:Attribute/Filter')."</span>";
}
else
{
$sAllowedValues = '';
@@ -902,15 +938,17 @@ function DisplayClassDetails($oPage, $sClass, $sContext)
$sAttrTypeDescEscpd = json_encode($sTypeDesc);
$sAttrOriginEscpd = json_encode($sOrigin);
$aDetails[] = array('code' => "<span id=\"attr". $sAttrCode."\"><span class=\"attrLabel\">". $oAttDef->GetLabel() ."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" . $oAttDef->GetCode() ."</span><span class=\"parenthesis\">)</span></span>",
'type' => "<span id=\"type". $sAttrCode."\"><span class=\"attrLabel\">". $sTypeDict ."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" . $sType ."</span><span class=\"parenthesis\">)</span></span>",
'origincolor' => "<span class=\"originColor" . $sOrigin ."\"></span>",
'origin' => "<span id=\"origin" . $sAttrCode ."\">$sOrigin</span>",
'values' => $sAllowedValues,
'moreinfo' => "<span id=\"moreinfo" . $sAttrCode . "\"> $sMoreInfo</span>");
$aDetails[] = array(
'code' => "<span id=\"attr".$sAttrCode."\"><span class=\"attrLabel\">".$oAttDef->GetLabel()."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$oAttDef->GetCode()."</span><span class=\"parenthesis\">)</span></span>",
'type' => "<span id=\"type".$sAttrCode."\"><span class=\"attrLabel\">".$sTypeDict."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$sType."</span><span class=\"parenthesis\">)</span></span>",
'origincolor' => "<span class=\"originColor".$sOrigin."\"></span>",
'origin' => "<span id=\"origin".$sAttrCode."\">$sOrigin</span>",
'values' => $sAllowedValues,
'moreinfo' => "<span id=\"moreinfo".$sAttrCode."\"> $sMoreInfo</span>",
);
//tooltip construction
$oPage->add_ready_script(
<<<EOF
$oPage->add_ready_script(
<<<EOF
if($sAttrValueEscpd != ''){
$('#attr$sAttrCode').qtip( { content: $sAttrValueEscpd, show: 'mouseover', hide: {fixed : true, delay : 500}, style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );
}
@@ -930,23 +968,24 @@ EOF
);
}
}
$oPage->SetCurrentTab('UI:Schema:Attributes');
$aConfig = array( 'origincolor' => array('label' => "", 'description' => ""),
'code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')),
'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')),
'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')),
'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')),
'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')),
$aConfig = array(
'origincolor' => array('label' => "", 'description' => ""),
'code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')),
'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')),
'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')),
'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')),
'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')),
);
$oPage->table($aConfig, $aDetails);
$sOrigins = json_encode(array_keys($aOrigins));
$sOrigins = json_encode(array_keys($aOrigins));
//color calculation in order to keep 1 color for 1 extended class. Colors are interpolated and will be used for
//color calculation in order to keep 1 color for 1 extended class. Colors are interpolated and will be used for
// graph scheme color too
$oPage->add_ready_script(
<<< EOF
$oPage->add_ready_script(
<<< EOF
var aOrigins = $sOrigins;
var aColors = d3.scale.linear().domain([1,aOrigins.length])
.interpolate(d3.interpolateHcl)
@@ -959,15 +998,15 @@ EOF
});
EOF
);
);
$oPage->SetCurrentTab('UI:Schema:RelatedClasses');
DisplayRelatedClassesGraph($oPage, $sClass);
$oPage->SetCurrentTab('UI:Schema:ChildClasses');
$oPage->SetCurrentTab('UI:Schema:RelatedClasses');
DisplayRelatedClassesGraph($oPage, $sClass);
$oPage->SetCurrentTab('UI:Schema:ChildClasses');
DisplaySubclasses($oPage, $sClass, $sContext);
DisplaySubclasses($oPage, $sClass, $sContext);
$oPage->SetCurrentTab('UI:Schema:LifeCycle');
$oPage->SetCurrentTab('UI:Schema:LifeCycle');
DisplayLifecycle($oPage, $sClass);
$oPage->SetCurrentTab('UI:Schema:Triggers');
@@ -981,17 +1020,19 @@ EOF
/**
* Display the dropdown that allow to select the attributes/class display granularity
*/
function DisplayGranularityDisplayer($oPage){
function DisplayGranularityDisplayer($oPage)
{
$oPage->add("
<label id=\"displaySelectorLabel\"> <h1> ". Dict::S('UI:Schema:DisplayLabel') .
<label id=\"displaySelectorLabel\"> <h1> ".Dict::S('UI:Schema:DisplayLabel').
"<select id=\"displaySelector\">
<option value=\"labelandcode\">" . Dict::S('UI:Schema:DisplaySelector/LabelAndCode') . "</option>
<option value=\"label\">" . Dict::S('UI:Schema:DisplaySelector/Label') . "</option>
<option value=\"code\">" . Dict::S('UI:Schema:DisplaySelector/Code') . "</option>
<option value=\"labelandcode\">".Dict::S('UI:Schema:DisplaySelector/LabelAndCode')."</option>
<option value=\"label\">".Dict::S('UI:Schema:DisplaySelector/Label')."</option>
<option value=\"code\">".Dict::S('UI:Schema:DisplaySelector/Code')."</option>
</select> </h1></label>
<br/>");
$sDisplayDropDownValue = htmlentities(appUserPreferences::GetPref('datamodel_viewer_display_granularity','labelandcode'),ENT_QUOTES,"UTF-8");
$sDisplayDropDownValue = htmlentities(appUserPreferences::GetPref('datamodel_viewer_display_granularity', 'labelandcode'), ENT_QUOTES,
"UTF-8");
//granularity displayer listener
$oPage->add_ready_script(
@@ -1030,28 +1071,31 @@ function DisplayGranularityDisplayer($oPage){
EOF
);
}
/**
* Display the header of the class details page
*/
function DisplayClassHeader($oPage, $sClass){
function DisplayClassHeader($oPage, $sClass)
{
//scrollable class name / icon
$oPage->add("<div id=\"dataModelScrollableDiv\">");
$oPage->add("<div id=\"dataModelScrollableClassIcon\">" . MetaModel::GetClassIcon($sClass) . "</div>");
$oPage->add("<h2 id=\"dataModelScrollableClassName\"><span class=\"attrLabel\">" . MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" .$sClass."</span><span class=\"parenthesis\">)</span></h2>");
$oPage->add("<div id=\"dataModelScrollableClassIcon\">".MetaModel::GetClassIcon($sClass)."</div>");
$oPage->add("<h2 id=\"dataModelScrollableClassName\"><span class=\"attrLabel\">".MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$sClass."</span><span class=\"parenthesis\">)</span></h2>");
$oPage->add("</div>");
//content header
$oPage->add("<div id=\"dataModelHeader\">");
DisplayGranularityDisplayer($oPage);
$oPage->add("<div id=\"dataModelClassIcon\">" . MetaModel::GetClassIcon($sClass) . "</div>");
$oPage->add("<div id=\"dataModelClassIcon\">".MetaModel::GetClassIcon($sClass)."</div>");
$sClassDescritpion = MetaModel::GetClassDescription($sClass);
$oPage->add("<h2 id=\"classDetailsClassName\"><span class=\"attrLabel\">".MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">" .$sClass."</span><span class=\"parenthesis\">)</span>" . ($sClassDescritpion == "" ? "" : " - " . $sClassDescritpion) . "</h2>\n");
$oPage->add("<h2 id=\"classDetailsClassName\"><span class=\"attrLabel\">".MetaModel::GetName($sClass)."</span> <span class=\"parenthesis\">(</span><span class=\"attrCode\">".$sClass."</span><span class=\"parenthesis\">)</span>".($sClassDescritpion == "" ? "" : " - ".$sClassDescritpion)."</h2>\n");
if (MetaModel::IsAbstract($sClass))
{
$oPage->p(Dict::S('UI:Schema:AbstractClass'));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN BLOCK //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1068,9 +1112,10 @@ $operation = utils::ReadParam('operation', '');
$oPage = new iTopWebPage(Dict::S('UI:Schema:Title'));
$oPage->no_cache();
$oPage->SetBreadCrumbEntry('ui-tool-datamodel', Dict::S('Menu:DataModelMenu'), Dict::S('Menu:DataModelMenu+'), '', utils::GetAbsoluteUrlAppRoot().'images/wrench.png');
$oPage->SetBreadCrumbEntry('ui-tool-datamodel', Dict::S('Menu:DataModelMenu'), Dict::S('Menu:DataModelMenu+'), '',
utils::GetAbsoluteUrlAppRoot().'images/wrench.png');
$oPage->add_script(
<<<EOF
<<<EOF
var autocompleteClassLabelAndCode = [];
var autocompleteClassLabel = [];
var autocompleteClassCode = [];
@@ -1083,23 +1128,23 @@ DisplayClassesList($oPage, $sContext);
$oPage->add("</div>");
$oPage->add("<div class='ui-layout-center data-model-viewer'>");
switch($operation)
switch ($operation)
{
case 'details_class':
$sClass = utils::ReadParam('class', '', false, 'class');
//if we want to see class details & class is given then display it, otherwise act default (just show the class list)
if($sClass != '')
{
$oPage->add_ready_script(
<<<EOF
$sClass = utils::ReadParam('class', '', false, 'class');
//if we want to see class details & class is given then display it, otherwise act default (just show the class list)
if ($sClass != '')
{
$oPage->add_ready_script(
<<<EOF
$('#search-model').val('$sClass');
$('#search-model').trigger("input");
EOF
);
DisplayClassDetails($oPage, $sClass, $sContext);
break;
}
);
DisplayClassDetails($oPage, $sClass, $sContext);
break;
}
default:
DisplayGranularityDisplayer($oPage);
}
@@ -1107,7 +1152,7 @@ $oPage->add("</div>");
$oPage->add("</div>");
//split the page in 2 panels
$oPage->add_init_script(
<<<EOF
<<<EOF
$('#dataModelSplitPane').layout({
west : {size: "20%", minSize : 200,paneSize : 600}
});