Cleanup Dashboard and dashlet unused methods and ajax end points

This commit is contained in:
Eric Espie
2026-01-27 17:52:36 +01:00
parent 814f91bd48
commit 3fa658edb5
13 changed files with 10 additions and 1558 deletions

View File

@@ -60,67 +60,4 @@ class DashletBadge extends Dashlet
return $oDashletContainer;
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer($this->sId, ['dashlet-content']);
$sClass = $this->aProperties['class'];
$sIconUrl = utils::HtmlEntities($this->oModelReflection->GetClassIcon($sClass, false));
$sClassLabel = $this->oModelReflection->GetName($sClass);
$sId = $this->sId;
$sClassCreate = Dict::Format('UI:ClickToCreateNew', $sClassLabel);
$sHtml = <<<HTML
<div id="block_fake_$sId" class="display_block">
<div class="ibo-dashlet-badge--body" data-role="ibo-dashlet-badge--body" title="$sClassLabel">
<div class="ibo-dashlet-badge--icon-container"><img class="ibo-dashlet-badge--icon" src="$sIconUrl"></div>
<div class="ibo-dashlet-badge--actions"><a class="ibo-dashlet-badge--action-list" href="#" data-role="ibo-dashlet-badge--action-list"><span class="ibo-dashlet-badge--action-list-count">4</span><span class="ibo-dashlet-badge--action-list-label">$sClassLabel</span></a><a class="ibo-dashlet-badge--action-create" href="#"><span class="ibo-dashlet-badge--action-create-icon fas fa-plus"></span><span class="ibo-dashlet-badge--action-create-label"> $sClassCreate </span></a></div>
</div>
</div>
HTML;
$oDashletContainer->AddHtml($sHtml);
return $oDashletContainer;
}
protected static $aClassList = null;
/**
* @inheritdoc
*
* @throws \Exception
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
if (is_null(self::$aClassList)) {
// Cache the ordered list of classes (ordered on the label)
// (has a significant impact when editing a page with lots of badges)
//
$aClasses = [];
foreach ($this->oModelReflection->GetClasses('bizmodel', true /*exclude links*/) as $sClass) {
$aClasses[$sClass] = $this->oModelReflection->GetName($sClass);
}
asort($aClasses);
self::$aClassList = [];
foreach ($aClasses as $sClass => $sLabel) {
$sIconUrl = $this->oModelReflection->GetClassIcon($sClass, false);
if ($sIconUrl == '') {
// The icon does not exist, let's use a transparent one of the same size.
$sIconUrl = utils::GetAbsoluteUrlAppRoot().'images/transparent_32_32.png';
}
self::$aClassList[] = ['value' => $sClass, 'label' => $sLabel, 'icon' => $sIconUrl];
}
}
$oField = new DesignerIconSelectionField('class', Dict::S('UI:DashletBadge:Prop-Class'), $this->aProperties['class']);
$oField->SetAllowedValues(self::$aClassList);
$oForm->AddField($oField);
}
}

View File

@@ -258,297 +258,6 @@ abstract class DashletGroupBy extends Dashlet
return $oPanel;
}
/**
* @return array
*/
protected function MakeSimulatedData()
{
$sQuery = $this->aProperties['query'];
$oQuery = $this->oModelReflection->GetQuery($sQuery);
$sClass = $oQuery->GetClass();
$aDisplayValues = [];
if ($this->oModelReflection->IsValidAttCode($sClass, $this->sGroupByAttCode)) {
$aAttributeTypes = $this->oModelReflection->ListAttributes($sClass);
$sAttributeType = $aAttributeTypes[$this->sGroupByAttCode];
if (is_subclass_of($sAttributeType, 'AttributeDateTime') || $sAttributeType == 'AttributeDateTime') {
// Note: an alternative to this somewhat hardcoded way of doing things would be to implement...
//$oExpr = Expression::FromOQL($this->sGroupByExpr);
//$aTranslationData = array($oQuery->GetClassAlias() => array($this->sGroupByAttCode => new ScalarExpression(date('Y-m-d H:i:s', $iTime))));
//$sRawValue = CMDBSource::QueryToScalar('SELECT '.$oExpr->Translate($aTranslationData)->Render());
//$sValueLabel = $oExpr->MakeValueLabel(oFilter, $sRawValue, $sRawValue);
// Anyhow, this requires :
// - an update to the prototype of MakeValueLabel() so that it takes ModelReflection parameters
// - propose clever date/times samples
$aValues = [];
switch ($this->sFunction) {
case 'hour':
$aValues = [8, 9, 15, 18];
break;
case 'month':
$aValues = ['2013 '.Dict::S('Month-11'), '2013 '.Dict::S('Month-12'), '2014 '.Dict::S('Month-01'), '2014 '.Dict::S('Month-02'), '2014 '.Dict::S('Month-03')];
break;
case 'day_of_week':
$aValues = [Dict::S('DayOfWeek-Monday'), Dict::S('DayOfWeek-Wednesday'), Dict::S('DayOfWeek-Thursday'), Dict::S('DayOfWeek-Friday')];
break;
case 'day_of_month':
$aValues = [Dict::S('Month-03').' 30', Dict::S('Month-03').' 31', Dict::S('Month-04').' 01', Dict::S('Month-04').' 02', Dict::S('Month-04').' 03'];
break;
}
foreach ($aValues as $sValue) {
$aDisplayValues[] = ['label' => $sValue, 'value' => (int)rand(1, 15)];
}
} elseif (is_subclass_of($sAttributeType, 'AttributeEnum') || $sAttributeType == 'AttributeEnum') {
$aAllowed = $this->oModelReflection->GetAllowedValues_att($sClass, $this->sGroupByAttCode);
if ($aAllowed) { // null for non enums
foreach ($aAllowed as $sValue => $sValueLabel) {
$iCount = (int)rand(2, 100);
$aDisplayValues[] = [
'label' => $sValueLabel,
'value' => $iCount,
];
}
}
} else {
$aDisplayValues[] = ['label' => 'a', 'value' => 123];
$aDisplayValues[] = ['label' => 'b', 'value' => 321];
$aDisplayValues[] = ['label' => 'c', 'value' => 456];
}
}
return $aDisplayValues;
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer(null, ['dashlet-content']);
$oDashletContainer->AddHtml('error!');
return $oDashletContainer;
}
/**
* @inheritdoc
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletGroupBy:Prop-Title'), $this->aProperties['title']);
$oForm->AddField($oField);
$oField = new DesignerLongTextField('query', Dict::S('UI:DashletGroupBy:Prop-Query'), $this->aProperties['query']);
$oField->SetMandatory();
$oField->AddCSSClass("ibo-query-oql");
$oField->AddCSSClass("ibo-is-code");
$oForm->AddField($oField);
try {
// Group by field: build the list of possible values (attribute codes + ...)
$aGroupBy = $this->GetGroupByOptions($this->aProperties['query']);
$oField = new DesignerComboField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), $this->aProperties['group_by']);
$oField->SetMandatory();
$oField->SetAllowedValues($aGroupBy);
} catch (Exception $e) {
$oField = new DesignerTextField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), $this->aProperties['group_by']);
$oField->SetReadOnly();
$aGroupBy = [];
}
$oForm->AddField($oField);
$aStyles = [
'pie' => Dict::S('UI:DashletGroupByPie:Label'),
'bars' => Dict::S('UI:DashletGroupByBars:Label'),
'table' => Dict::S('UI:DashletGroupByTable:Label'),
];
$oField = new DesignerComboField('style', Dict::S('UI:DashletGroupBy:Prop-Style'), $this->aProperties['style']);
$oField->SetMandatory();
$oField->SetAllowedValues($aStyles);
$oForm->AddField($oField);
$aFunctionAttributes = $this->GetNumericAttributes($this->aProperties['query']);
$aFunctions = $this->GetAllowedFunctions($aFunctionAttributes);
$oSelectorField = new DesignerFormSelectorField('aggregation_function', Dict::S('UI:DashletGroupBy:Prop-Function'), $this->aProperties['aggregation_function']);
$oForm->AddField($oSelectorField);
$oSelectorField->SetMandatory();
// Count sub-menu
$oSubForm = new DesignerForm();
$oSelectorField->AddSubForm($oSubForm, Dict::S('UI:GroupBy:count'), 'count');
foreach ($aFunctions as $sFct => $sLabel) {
$oSubForm = new DesignerForm();
$oField = new DesignerComboField('aggregation_attribute', Dict::S('UI:DashletGroupBy:Prop-FunctionAttribute'), $this->aProperties['aggregation_attribute']);
$oField->SetMandatory();
$oField->SetAllowedValues($aFunctionAttributes);
$oSubForm->AddField($oField);
$oSelectorField->AddSubForm($oSubForm, $sLabel, $sFct);
}
$aOrderField = [];
if (isset($this->aProperties['group_by']) && isset($aGroupBy[$this->aProperties['group_by']])) {
$aOrderField['attribute'] = $aGroupBy[$this->aProperties['group_by']];
}
if ($this->aProperties['aggregation_function'] == 'count') {
$aOrderField['function'] = Dict::S('UI:GroupBy:count');
} else {
$aOrderField['function'] = $aFunctions[$this->aProperties['aggregation_function']];
}
$oSelectorField = new DesignerFormSelectorField('order_by', Dict::S('UI:DashletGroupBy:Prop-OrderField'), $this->aProperties['order_by']);
$oForm->AddField($oSelectorField);
$oSelectorField->SetMandatory();
foreach ($aOrderField as $sField => $sLabel) {
$oSubForm = new DesignerForm();
if ($sField == 'function') {
$oField = new DesignerIntegerField('limit', Dict::S('UI:DashletGroupBy:Prop-Limit'), $this->aProperties['limit']);
$oSubForm->AddField($oField);
}
$oSelectorField->AddSubForm($oSubForm, $sLabel, $sField);
}
$aOrderDirections = [
'asc' => Dict::S('UI:DashletGroupBy:Order:asc'),
'desc' => Dict::S('UI:DashletGroupBy:Order:desc'),
];
$sOrderDirection = empty($this->aProperties['order_direction']) ? $this->sOrderDirection : $this->aProperties['order_direction'];
$oField = new DesignerComboField('order_direction', Dict::S('UI:DashletGroupBy:Prop-OrderDirection'), $sOrderDirection);
$oField->SetMandatory();
$oField->SetAllowedValues($aOrderDirections);
$oForm->AddField($oField);
}
/**
* @return array
*/
protected function GetOrderBy()
{
if (is_null($this->sClass)) {
return [];
}
return [
$this->aProperties['group_by'] => $this->oModelReflection->GetLabel($this->sClass, $this->aProperties['group_by']),
'_itop_'.$this->aProperties['aggregation_function'].'_' => Dict::S('UI:GroupBy:'.$this->aProperties['aggregation_function']),
];
}
/**
* @param array $aFunctionAttributes
*
* @return array
*/
protected function GetAllowedFunctions($aFunctionAttributes)
{
$aFunctions = [];
if (!empty($aFunctionAttributes) || is_null($this->sClass)) {
$aFunctions['sum'] = Dict::S('UI:GroupBy:sum');
$aFunctions['avg'] = Dict::S('UI:GroupBy:avg');
$aFunctions['min'] = Dict::S('UI:GroupBy:min');
$aFunctions['max'] = Dict::S('UI:GroupBy:max');
}
return $aFunctions;
}
/**
* @param string $sOql
*
* @return array
*/
protected function GetNumericAttributes($sOql)
{
$aFunctionAttributes = [];
try {
$oQuery = $this->oModelReflection->GetQuery($sOql);
$sClass = $oQuery->GetClass();
if (is_null($sClass)) {
return $aFunctionAttributes;
}
foreach ($this->oModelReflection->ListAttributes($sClass) as $sAttCode => $sAttType) {
switch ($sAttType) {
case 'AttributeDecimal':
case 'AttributeDuration':
case 'AttributeInteger':
case 'AttributePercentage':
case 'AttributeSubItem': // TODO: Known limitation: no unit displayed (values in sec)
$sLabel = $this->oModelReflection->GetLabel($sClass, $sAttCode);
$aFunctionAttributes[$sAttCode] = $sLabel;
break;
}
}
} catch (Exception $e) {
// In case the OQL is bad
}
return $aFunctionAttributes;
}
/**
* @inheritdoc
*/
public function Update($aValues, $aUpdatedFields)
{
if (in_array('query', $aUpdatedFields)) {
try {
$sCurrQuery = $aValues['query'];
$oCurrSearch = $this->oModelReflection->GetQuery($sCurrQuery);
$sCurrClass = $oCurrSearch->GetClass();
$sPrevQuery = $this->aProperties['query'];
$oPrevSearch = $this->oModelReflection->GetQuery($sPrevQuery);
$sPrevClass = $oPrevSearch->GetClass();
if ($sCurrClass != $sPrevClass) {
$this->bFormRedrawNeeded = true;
// wrong but not necessary - unset($aUpdatedFields['group_by']);
$this->aProperties['group_by'] = '';
}
} catch (Exception $e) {
$this->bFormRedrawNeeded = true;
}
}
$oDashlet = parent::Update($aValues, $aUpdatedFields);
if (in_array('style', $aUpdatedFields)) {
switch ($aValues['style']) {
// Style changed, mutate to the specified type of chart
case 'pie':
$oDashlet = new DashletGroupByPie($this->oModelReflection, $this->sId);
break;
case 'bars':
$oDashlet = new DashletGroupByBars($this->oModelReflection, $this->sId);
break;
case 'table':
$oDashlet = new DashletGroupByTable($this->oModelReflection, $this->sId);
break;
}
$oDashlet->FromParams($aValues);
$oDashlet->bRedrawNeeded = true;
$oDashlet->bFormRedrawNeeded = true;
}
if (in_array('aggregation_attribute', $aUpdatedFields) || in_array('order_direction', $aUpdatedFields) || in_array('order_by', $aUpdatedFields) || in_array('limit', $aUpdatedFields)) {
$oDashlet->bRedrawNeeded = true;
}
if (in_array('group_by', $aUpdatedFields) || in_array('aggregation_function', $aUpdatedFields)) {
$oDashlet->bRedrawNeeded = true;
$oDashlet->bFormRedrawNeeded = true;
}
return $oDashlet;
}
/**
* @inheritdoc
*/
@@ -556,35 +265,4 @@ abstract class DashletGroupBy extends Dashlet
{
return true;
}
/**
* @inheritdoc
*/
public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL = null)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletGroupBy:Prop-Title'), '');
$oForm->AddField($oField);
$oField = new DesignerHiddenField('query', Dict::S('UI:DashletGroupBy:Prop-Query'), $sOQL);
$oField->SetMandatory();
$oField->AddCSSClass("ibo-query-oql");
$oField->AddCSSClass("ibo-is-code");
$oForm->AddField($oField);
if (!is_null($sOQL)) {
$oField = new DesignerComboField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), null);
$aGroupBy = $this->GetGroupByOptions($sOQL);
$oField->SetAllowedValues($aGroupBy);
} else {
// Creating a form for reading parameters!
$oField = new DesignerTextField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), null);
}
$oField->SetMandatory();
$oForm->AddField($oField);
$oField = new DesignerHiddenField('style', '', $this->aProperties['style']);
$oField->SetMandatory();
$oForm->AddField($oField);
}
}

View File

@@ -33,80 +33,4 @@ class DashletGroupByBars extends DashletGroupBy
parent::__construct($oModelReflection, $sId);
$this->aProperties['style'] = 'bars';
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer(null, ['dashlet-content']);
$sTitle = $this->aProperties['title'];
$sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$HTMLsTitle = ($sTitle != '') ? '<h1 style="text-align:center">'.utils::HtmlEntities($sTitle).'</h1>' : '';
$oDashletContainer->AddHtml("<div style=\"background-color:#fff;padding:0.25em;\">$HTMLsTitle<div id=\"$sBlockId\" style=\"background-color:#fff;\"></div></div>");
$aDisplayValues = $this->MakeSimulatedData();
$aNames = [];
foreach ($aDisplayValues as $idx => $aValue) {
$aNames[$idx] = $aValue['label'];
}
$sJSNames = json_encode($aNames);
$sJson = json_encode($aDisplayValues);
$oPage->add_ready_script(
<<<EOF
window.setTimeout(function() {
var chart = c3.generate({
bindto: '#{$sBlockId}',
data: {
json: $sJson,
keys: {
x: 'label',
value: ["value"]
},
selection: {
enabled: true
},
type: 'bar'
},
axis: {
x: {
tick: {
culling: {max: 25}, // Maximum 24 labels on x axis (2 years).
centered: true,
rotate: 90,
multiline: false
},
type: 'category' // this needed to load string x value
}
},
grid: {
y: {
show: true
}
},
legend: {
show: false,
},
tooltip: {
grouped: false,
format: {
title: function() { return '' },
name: function (name, ratio, id, index) {
var aNames = $sJSNames;
return aNames[index];
}
}
}
});
}, 100);
EOF
);
return $oDashletContainer;
}
}

View File

@@ -56,54 +56,4 @@ class DashletGroupByPie extends DashletGroupBy
WebResourcesHelper::GetCSSFilesRelPathsForC3JS()
);
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer(null, ['dashlet-content']);
$sTitle = $this->aProperties['title'];
$sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$HTMLsTitle = ($sTitle != '') ? '<h1 style="text-align:center">'.utils::HtmlEntities($sTitle).'</h1>' : '';
$oDashletContainer->AddHtml("<div style=\"background-color:#fff;padding:0.25em;\">$HTMLsTitle<div id=\"$sBlockId\" style=\"background-color:#fff;\"></div></div>");
$aDisplayValues = $this->MakeSimulatedData();
$aColumns = [];
$aNames = [];
foreach ($aDisplayValues as $idx => $aValue) {
$aColumns[] = ['series_'.$idx, (int)$aValue['value']];
$aNames['series_'.$idx] = $aValue['label'];
}
$sJSColumns = json_encode($aColumns);
$sJSNames = json_encode($aNames);
$oPage->add_ready_script(
<<<EOF
window.setTimeout(function() {
var chart = c3.generate({
bindto: '#{$sBlockId}',
data: {
columns: $sJSColumns,
type: 'pie',
names: $sJSNames,
},
legend: {
show: true,
position: 'right',
},
tooltip: {
format: {
value: function (value, ratio, id) { return value; }
}
}
});}, 100);
EOF
);
return $oDashletContainer;
}
}

View File

@@ -32,48 +32,4 @@ class DashletGroupByTable extends DashletGroupBy
parent::__construct($oModelReflection, $sId);
$this->aProperties['style'] = 'table';
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer();
$aDisplayValues = $this->MakeSimulatedData();
$iTotal = 0;
foreach ($aDisplayValues as $iRow => $aDisplayData) {
$iTotal += $aDisplayData['value'];
}
$sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$sHtml = '';
$sHtml .= '<div id="'.$sBlockId.'" class="display_block">';
$sHtml .= '<div class="dashlet-content">';
$sHtml .= '<p>'.Dict::Format('UI:Pagination:HeaderNoSelection', $iTotal).'</p>';
$sHtml .= '<table class="listResults">';
$sHtml .= '<thead>';
$sHtml .= '<tr>';
$sHtml .= '<th class="header" title="">'.$this->sGroupByLabel.'</th>';
$sHtml .= '<th class="header" title="'.Dict::S('UI:GroupBy:Count+').'">'.Dict::S('UI:GroupBy:Count').'</th>';
$sHtml .= '</tr>';
$sHtml .= '</thead>';
$sHtml .= '<tbody>';
foreach ($aDisplayValues as $aDisplayData) {
$sHtml .= '<tr class="even">';
$sHtml .= '<td class=""><span title="Active">'.$aDisplayData['label'].'</span></td>';
$sHtml .= '<td class=""><a>'.$aDisplayData['value'].'</a></td>';
$sHtml .= '</tr>';
}
$sHtml .= '</tbody>';
$sHtml .= '</table>';
$sHtml .= '</div>';
$sHtml .= '</div>';
$oDashletContainer->AddHtml($sHtml);
return $oDashletContainer;
}
}

View File

@@ -149,178 +149,4 @@ class DashletHeaderDynamic extends Dashlet
return $oPanel;
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$sTitle = utils::HtmlEntities($this->aProperties['title']);
$sIcon = $this->aProperties['icon'];
$sSubtitle = utils::HtmlEntities($this->aProperties['subtitle']);
$sQuery = $this->aProperties['query'];
$sGroupBy = $this->aProperties['group_by'];
$aValueLabels = [];
$aValues = [];
try {
$oQuery = $this->oModelReflection->GetQuery($sQuery);
$sClass = $oQuery->GetClass();
$aValues = $this->GetValues();
foreach ($aValues as $sValue) {
$aValueLabels[] = $this->oModelReflection->GetValueLabel($sClass, $sGroupBy, $sValue);
}
} catch (UnknownClassOqlException $e) {
$aValueLabels[] = $e->GetUserFriendlyDescription();
$aValues[] = 1;
}
$oIconSelect = $this->oModelReflection->GetIconSelectionField('icon');
$sIconPath = utils::HtmlEntities($oIconSelect->MakeFileUrl($sIcon));
$oDashletContainer = new DashletContainer(null, ['dashlet-content']);
$sHtml = '';
$sHtml .= '<img src="'.$sIconPath.'">';
$sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM)
$iTotal = 0;
$sHtml .= '<div class="display_block" id="'.$sBlockId.'">';
$sHtml .= '<div class="summary-details">';
$sHtml .= '<table><tbody>';
$sHtml .= '<tr>';
foreach ($aValueLabels as $sValueLabel) {
$sHtml .= ' <th>'.$sValueLabel.'</th>';
}
$sHtml .= '</tr>';
$sHtml .= '<tr>';
foreach ($aValues as $sValue) {
$iCount = rand(2, 100);
$iTotal += $iCount;
$sHtml .= ' <td>'.$iCount.'</td>';
}
$sHtml .= '</tr>';
$sHtml .= '</tbody></table>';
$sHtml .= '</div>';
$sTitle = $this->oModelReflection->DictString($sTitle);
$sSubtitle = $this->oModelReflection->DictFormat($sSubtitle, $iTotal);
$sHtml .= '<h1>'.utils::HtmlEntities($sTitle).'</h1>';
$sHtml .= '<a class="summary">'.utils::HtmlEntities($sSubtitle).'</a>';
$sHtml .= '</div>';
$oDashletContainer->AddHtml($sHtml);
return $oDashletContainer;
}
/**
* @inheritdoc
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletHeaderDynamic:Prop-Title'), $this->aProperties['title']);
$oForm->AddField($oField);
$oField = $this->oModelReflection->GetIconSelectionField('icon', Dict::S('UI:DashletHeaderDynamic:Prop-Icon'), $this->aProperties['icon']);
$oField->AddAllowedValue(['value' => '', 'label' => Dict::S('UI:DashletIcon:None'), 'icon' => '']);
$oForm->AddField($oField);
$oField = new DesignerTextField('subtitle', Dict::S('UI:DashletHeaderDynamic:Prop-Subtitle'), $this->aProperties['subtitle']);
$oForm->AddField($oField);
$oField = new DesignerLongTextField('query', Dict::S('UI:DashletHeaderDynamic:Prop-Query'), $this->aProperties['query']);
$oField->SetMandatory();
$oField->AddCSSClass("ibo-query-oql");
$oField->AddCSSClass("ibo-is-code");
$oForm->AddField($oField);
try {
// Group by field: build the list of possible values (attribute codes + ...)
$oQuery = $this->oModelReflection->GetQuery($this->aProperties['query']);
$sClass = $oQuery->GetClass();
$aGroupBy = $this->GetGroupByOptions($this->aProperties['query']);
$oField = new DesignerComboField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']);
$oField->SetMandatory();
$oField->SetAllowedValues($aGroupBy);
} catch (Exception $e) {
$oField = new DesignerTextField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']);
$oField->SetReadOnly();
}
$oForm->AddField($oField);
$oField = new DesignerComboField('values', Dict::S('UI:DashletHeaderDynamic:Prop-Values'), $this->aProperties['values']);
$oField->MultipleSelection(true);
if (isset($sClass) && $this->oModelReflection->IsValidAttCode($sClass, $this->aProperties['group_by'])) {
$aValues = $this->oModelReflection->GetAllowedValues_att($sClass, $this->aProperties['group_by']);
$oField->SetAllowedValues($aValues);
} else {
$oField->SetReadOnly();
}
$oForm->AddField($oField);
}
/**
* @inheritdoc
*/
public function Update($aValues, $aUpdatedFields)
{
if (in_array('query', $aUpdatedFields)) {
try {
$sCurrQuery = $aValues['query'];
$oCurrSearch = $this->oModelReflection->GetQuery($sCurrQuery);
$sCurrClass = $oCurrSearch->GetClass();
$sPrevQuery = $this->aProperties['query'];
$oPrevSearch = $this->oModelReflection->GetQuery($sPrevQuery);
$sPrevClass = $oPrevSearch->GetClass();
if ($sCurrClass != $sPrevClass) {
$this->bFormRedrawNeeded = true;
// wrong but not necessary - unset($aUpdatedFields['group_by']);
$this->aProperties['group_by'] = '';
$this->aProperties['values'] = [];
}
} catch (Exception $e) {
$this->bFormRedrawNeeded = true;
}
}
if (in_array('group_by', $aUpdatedFields)) {
$this->bFormRedrawNeeded = true;
$this->aProperties['values'] = [];
}
return parent::Update($aValues, $aUpdatedFields);
}
/**
* @inheritdoc
*/
protected function PropertyFromDOMNode($oDOMNode, $sProperty)
{
if ($sProperty == 'icon') {
$oIconField = $this->oModelReflection->GetIconSelectionField('icon');
return $oIconField->ValueFromDOMNode($oDOMNode);
} else {
return parent::PropertyFromDOMNode($oDOMNode, $sProperty);
}
}
/**
* @inheritdoc
*/
protected function PropertyToDOMNode($oDOMNode, $sProperty, $value)
{
if ($sProperty == 'icon') {
$oIconField = $this->oModelReflection->GetIconSelectionField('icon');
$oIconField->ValueToDOMNode($oDOMNode, $value);
} else {
parent::PropertyToDOMNode($oDOMNode, $sProperty, $value);
}
}
}

View File

@@ -55,44 +55,4 @@ class DashletHeaderStatic extends Dashlet
return DashletFactory::MakeForDashletHeaderStatic($this->oModelReflection->DictString($sTitle), $sIconPath);
}
/**
* @inheritdoc
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletHeaderStatic:Prop-Title'), $this->aProperties['title']);
$oForm->AddField($oField);
$oField = $this->oModelReflection->GetIconSelectionField('icon', Dict::S('UI:DashletHeaderStatic:Prop-Icon'), $this->aProperties['icon']);
$oField->AddAllowedValue(['value' => '', 'label' => Dict::S('UI:DashletIcon:None'), 'icon' => '']);
$oForm->AddField($oField);
}
/**
* @inheritdoc
*/
protected function PropertyFromDOMNode($oDOMNode, $sProperty)
{
if ($sProperty == 'icon') {
$oIconField = $this->oModelReflection->GetIconSelectionField('icon');
return $oIconField->ValueFromDOMNode($oDOMNode);
} else {
return parent::PropertyFromDOMNode($oDOMNode, $sProperty);
}
}
/**
* @inheritdoc
*/
protected function PropertyToDOMNode($oDOMNode, $sProperty, $value)
{
if ($sProperty == 'icon') {
$oIconField = $this->oModelReflection->GetIconSelectionField('icon');
$oIconField->ValueToDOMNode($oDOMNode, $value);
} else {
parent::PropertyToDOMNode($oDOMNode, $sProperty, $value);
}
}
}

View File

@@ -77,44 +77,6 @@ class DashletObjectList extends Dashlet
return $oPanel;
}
/**
* @inheritdoc
*/
public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = [])
{
$oDashletContainer = new DashletContainer($this->sId, ['dashlet-content']);
$sTitle = $this->aProperties['title'];
$sQuery = $this->aProperties['query'];
$bShowMenu = $this->aProperties['menu'];
$sHtmlTitle = utils::HtmlEntities($this->oModelReflection->DictString($sTitle));
if ($sHtmlTitle != '') {
$sHtmlTitle = '<h1>'.$sHtmlTitle.'</h1>';
}
$oQuery = $this->oModelReflection->GetQuery($sQuery);
$sClass = $oQuery->GetClass();
$sId = $this->sId;
$sMessage = Dict::S('UI:NoObjectToDisplay');
$sMenu = '';
if ($bShowMenu) {
$sMenu = '<p><a>'.Dict::Format('UI:ClickToCreateNew', $this->oModelReflection->GetName($sClass)).'</a></p>';
}
$sHtml = <<<HTML
<div class="dashlet-content">
<h1>$sHtmlTitle</h1>
<div id="block_fake_$sId" class="display_block">
<p>$sMessage</p>
$sMenu
</div>
</div>
HTML;
$oDashletContainer->AddHtml($sHtml);
return $oDashletContainer;
}
public function GetDBSearch($aExtraParams = [])
{
$sQuery = $this->aProperties['query'];
@@ -130,24 +92,6 @@ HTML;
return DBObjectSearch::FromOQL($sQuery, $aQueryParams);
}
/**
* @inheritdoc
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletObjectList:Prop-Title'), $this->aProperties['title']);
$oForm->AddField($oField);
$oField = new DesignerLongTextField('query', Dict::S('UI:DashletObjectList:Prop-Query'), $this->aProperties['query']);
$oField->SetMandatory();
$oField->AddCSSClass("ibo-query-oql");
$oField->AddCSSClass("ibo-is-code");
$oForm->AddField($oField);
$oField = new DesignerBooleanField('menu', Dict::S('UI:DashletObjectList:Prop-Menu'), $this->aProperties['menu']);
$oForm->AddField($oField);
}
/**
* @inheritdoc
*/
@@ -155,22 +99,4 @@ HTML;
{
return true;
}
/**
* @inheritdoc
*/
public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL = null)
{
$oField = new DesignerTextField('title', Dict::S('UI:DashletObjectList:Prop-Title'), '');
$oForm->AddField($oField);
$oField = new DesignerHiddenField('query', Dict::S('UI:DashletObjectList:Prop-Query'), $sOQL);
$oField->SetMandatory();
$oField->AddCSSClass("ibo-query-oql");
$oField->AddCSSClass("ibo-is-code");
$oForm->AddField($oField);
$oField = new DesignerBooleanField('menu', Dict::S('UI:DashletObjectList:Prop-Menu'), $this->aProperties['menu']);
$oForm->AddField($oField);
}
}

View File

@@ -50,14 +50,4 @@ class DashletPlainText extends Dashlet
return DashletFactory::MakeForDashletPlainText($sText, $sId);
}
/**
* @inheritdoc
*/
public function GetPropertiesFields(DesignerForm $oForm)
{
$oField = new DesignerLongTextField('text', Dict::S('UI:DashletPlainText:Prop-Text'), $this->aProperties['text']);
$oField->SetMandatory();
$oForm->AddField($oField);
}
}