N°1325 Dashboards: Unknown dashlets: keep the original type of the unknown dashlet

SVN:trunk[5855]
This commit is contained in:
Eric Espié
2018-06-12 08:56:41 +00:00
parent cb19520b6b
commit 362cd72e87
4 changed files with 38 additions and 34 deletions

View File

@@ -151,11 +151,13 @@ abstract class Dashboard
$sClass = $oDomNode->getAttribute('xsi:type');
// Test if dashlet can be instanciated, otherwise (uninstalled, broken, ...) we display a placeholder
$sDashletType = $sClass;
if(!class_exists($sClass))
{
$sClass = 'DashletUnknown';
}
$oNewDashlet = new $sClass($this->oMetaModel, $sId);
$oNewDashlet->SetDashletType($sDashletType);
$oNewDashlet->FromDOMNode($oDomNode);
return $oNewDashlet;
@@ -234,7 +236,7 @@ abstract class Dashboard
$oNode = $oDoc->createElement('dashlet');
$oDashletsNode->appendChild($oNode);
$oNode->setAttribute('id', $oDashlet->GetID());
$oNode->setAttribute('xsi:type', get_class($oDashlet));
$oNode->setAttribute('xsi:type', $oDashlet->GetDashletType());
$oDashletRank = $oDoc->createElement('rank', $iDashletRank);
$oNode->appendChild($oDashletRank);
$iDashletRank++;
@@ -258,8 +260,9 @@ abstract class Dashboard
{
$sDashletClass = $aDashletParams['dashlet_class'];
$sId = $aDashletParams['dashlet_id'];
$sType = $aDashletParams['dashlet_type'];
$oNewDashlet = new $sDashletClass($this->oMetaModel, $sId);
$oNewDashlet->SetDashletType($sType);
$oForm = $oNewDashlet->GetForm();
$oForm->SetParamsContainer($sId);
$oForm->SetPrefix('');

View File

@@ -32,6 +32,7 @@ abstract class Dashlet
protected $bFormRedrawNeeded;
protected $aProperties; // array of {property => value}
protected $aCSSClasses;
protected $sDashletType;
public function __construct(ModelReflection $oModelReflection, $sId)
{
@@ -41,6 +42,7 @@ abstract class Dashlet
$this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields)
$this->aProperties = array(); // By default: there is no property
$this->aCSSClasses = array('dashlet');
$this->sDashletType = get_class($this);
}
// Assuming that a property has the type of its default value, set in the constructor
@@ -214,9 +216,10 @@ abstract class Dashlet
if ($bEditMode)
{
$sClass = get_class($this);
$sType = $this->sDashletType;
$oPage->add_ready_script(
<<<EOF
$('#dashlet_$sId').dashlet({dashlet_id: '$sId', dashlet_class: '$sClass'});
$('#dashlet_$sId').dashlet({dashlet_id: '$sId', dashlet_class: '$sClass', 'dashlet_type': '$sType'});
EOF
);
}
@@ -293,6 +296,9 @@ EOF
$oDashletClassField = new DesignerHiddenField('dashlet_class', '', get_class($this));
$oForm->AddField($oDashletClassField);
$oDashletTypeField = new DesignerHiddenField('dashlet_type', '', $this->sDashletType);
$oForm->AddField($oDashletTypeField);
$oDashletIdField = new DesignerHiddenField('dashlet_id', '', $this->GetID());
$oForm->AddField($oDashletIdField);
@@ -345,6 +351,21 @@ EOF
return $aGroupBy;
}
/**
* @return string
*/
public function GetDashletType()
{
return $this->sDashletType;
}
/**
* @param string $sDashletType
*/
public function SetDashletType($sDashletType)
{
$this->sDashletType = $sDashletType;
}
}
/**
@@ -364,33 +385,15 @@ class DashletUnknown extends Dashlet
public function __construct($oModelReflection, $sId)
{
parent::__construct($oModelReflection, $sId);
$this->sOriginalDashletClass = 'Unknown';
$this->sOriginalDashletXML = '';
$this->aCSSClasses[] = 'dashlet-unknown';
}
public function GetOriginalDashletClass()
{
return $this->sOriginalDashletClass;
}
public function SetOriginalDashletClass($sOriginalDashletClass)
{
$this->sOriginalDashletClass = $sOriginalDashletClass;
}
public function FromDOMNode($oDOMNode)
{
// Parent won't do anything as there is no property declared
parent::FromDOMNode($oDOMNode);
// Original dashlet
// - Class
if($oDOMNode->hasAttribute('xsi:type'))
{
$this->sOriginalDashletClass = $oDOMNode->getAttribute('xsi:type');
}
// Build properties from XML
$this->sOriginalDashletXML = "";
foreach($oDOMNode->childNodes as $oDOMChildNode)
@@ -432,7 +435,7 @@ class DashletUnknown extends Dashlet
$aInfos = static::GetInfo();
$sIconUrl = utils::GetAbsoluteUrlAppRoot().$aInfos['icon'];
$sExplainText = ($bEditMode) ? Dict::Format('UI:DashletUnknown:RenderText:Edit', $this->sOriginalDashletClass) : Dict::S('UI:DashletUnknown:RenderText:View');
$sExplainText = ($bEditMode) ? Dict::Format('UI:DashletUnknown:RenderText:Edit', $this->GetDashletType()) : Dict::S('UI:DashletUnknown:RenderText:View');
$oPage->add('<div class="dashlet-content">');
@@ -447,7 +450,7 @@ class DashletUnknown extends Dashlet
$aInfos = static::GetInfo();
$sIconUrl = utils::GetAbsoluteUrlAppRoot().$aInfos['icon'];
$sExplainText = Dict::Format('UI:DashletUnknown:RenderNoDataText:Edit', $this->sOriginalDashletClass);
$sExplainText = Dict::Format('UI:DashletUnknown:RenderNoDataText:Edit', $this->GetDashletType());
$oPage->add('<div class="dashlet-content">');
@@ -522,9 +525,6 @@ class DashletUnknown extends Dashlet
class DashletProxy extends DashletUnknown
{
protected $sOriginalDashletClass;
protected $sOriginalDashletXML;
public function __construct($oModelReflection, $sId)
{
parent::__construct($oModelReflection, $sId);
@@ -535,8 +535,6 @@ class DashletProxy extends DashletUnknown
unset($this->aCSSClasses[$key]);
}
$this->sOriginalDashletClass = 'Proxy';
$this->sOriginalDashletXML = '';
$this->aCSSClasses[] = 'dashlet-proxy';
}

View File

@@ -84,14 +84,14 @@ $(function()
var oDashletParams = oDashlet.get_params();
var sId = oDashletParams.dashlet_id;
oState[sId] = oDashletParams;
aList.push({dashlet_id: sId, dashlet_class: oDashletParams.dashlet_class} );
aList.push({dashlet_id: sId, dashlet_class: oDashletParams.dashlet_class, dashlet_type: oDashletParams.dashlet_type} );
}
});
if (aList.length == 0)
{
oState[0] = {dashlet_id: 0, dashlet_class: 'DashletEmptyCell'};
aList.push({dashlet_id: 0, dashlet_class: 'DashletEmptyCell'});
oState[0] = {dashlet_id: 0, dashlet_class: 'DashletEmptyCell', dashlet_type: 'DashletEmptyCell'};
aList.push({dashlet_id: 0, dashlet_class: 'DashletEmptyCell', dashlet_type: 'DashletEmptyCell'});
}
oState.cells.push(aList);
});

View File

@@ -9,7 +9,8 @@ $(function()
options:
{
dashlet_id: '',
dashlet_class: ''
dashlet_class: '',
dashlet_type: ''
},
// the constructor
@@ -75,7 +76,7 @@ $(function()
{
this.element.addClass('dashlet-selected');
this.closeBox.fadeIn(500);
$('#event_bus').trigger('dashlet-selected', {'dashlet_id': this.options.dashlet_id, 'dashlet_class': this.options.dashlet_class});
$('#event_bus').trigger('dashlet-selected', {'dashlet_id': this.options.dashlet_id, 'dashlet_class': this.options.dashlet_class, 'dashlet_type': this.options.dashlet_type});
},
deselect: function()
{
@@ -114,6 +115,7 @@ $(function()
oParams.dashlet_id = this.options.dashlet_id;
oParams.dashlet_class = this.options.dashlet_class;
oParams.dashlet_type = this.options.dashlet_type;
return oParams;
},
get_drag_icon: function()
@@ -127,11 +129,12 @@ $(function()
{
var iDashletId = this.options.dashlet_id;
var sDashletClass = this.options.dashlet_class;
var sDashletType = this.options.dashlet_type;
var oContainer = this.element.parent();
$('#dashlet_properties_'+iDashletId).remove();
this.element.remove();
$('#event_bus').trigger('dashlet-removed', {'dashlet_id': iDashletId, 'dashlet_class': sDashletClass, 'container': oContainer});
$('#event_bus').trigger('dashlet-removed', {'dashlet_id': iDashletId, 'dashlet_class': sDashletClass, 'dashlet_type': sDashletType, 'container': oContainer});
$('.itop-dashboard').trigger('mark_as_modified');
}
});