N°2847 - Activity panel: Pass host object display mode

This commit is contained in:
Molkobain
2020-11-16 15:22:53 +01:00
parent 2f938814e0
commit 675a408ab9
6 changed files with 91 additions and 13 deletions

View File

@@ -66,13 +66,18 @@ require_once(APPROOT.'sources/application/search/criterionconversion/criterionto
abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
{
/** @var string ENUM_OBJECT_MODE_VIEW */
const ENUM_OBJECT_MODE_VIEW = 'view';
public const ENUM_OBJECT_MODE_VIEW = 'view';
/** @var string ENUM_OBJECT_MODE_EDIT */
const ENUM_OBJECT_MODE_EDIT = 'edit';
public const ENUM_OBJECT_MODE_EDIT = 'edit';
/** @var string ENUM_OBJECT_MODE_CREATE */
const ENUM_OBJECT_MODE_CREATE = 'create';
public const ENUM_OBJECT_MODE_CREATE = 'create';
/** @var string ENUM_OBJECT_MODE_STIMULUS */
const ENUM_OBJECT_MODE_STIMULUS = 'stimulus';
public const ENUM_OBJECT_MODE_STIMULUS = 'stimulus';
/**
* @var string DEFAULT_OBJECT_MODE
* @since 3.0.0
*/
public const DEFAULT_OBJECT_MODE = self::ENUM_OBJECT_MODE_VIEW;
protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)
protected static $iGlobalFormId = 1;
@@ -106,6 +111,24 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
$this->bAllowDelete = false;
}
/**
* Return the allowed object modes
*
* @see static::ENUM_OBJECT_MODE_XXX
*
* @return string[]
* @since 3.0.0
*/
public static function EnumObjectModes(): array
{
return [
static::ENUM_OBJECT_MODE_VIEW,
static::ENUM_OBJECT_MODE_EDIT,
static::ENUM_OBJECT_MODE_CREATE,
static::ENUM_OBJECT_MODE_STIMULUS,
];
}
/**
* returns what will be the next ID for the forms
*/

View File

@@ -478,7 +478,7 @@ try
$sClassLabel = MetaModel::GetName($sClass);
$oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW));
$oObj->DisplayDetails($oP);
}
}
@@ -733,7 +733,7 @@ EOF
{
throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id));
}
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_OBJECT_MODE_EDIT));
// Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
$oObj->DisplayModifyForm($oP, array('wizard_container' => 1)); // wizard_container: Display the title above the form
}
@@ -867,7 +867,7 @@ EOF
$sHeaderTitle = Dict::Format('UI:CreationTitle_Class', $sClassLabel);
// Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found
$oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObjToClone));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObjToClone, cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE));
cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array(), array('wizard_container' => 1)); // wizard_container: Display the title above the form
}
else

View File

@@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel;
use AttributeDateTime;
use cmdbAbstractObject;
use Combodo\iTop\Application\UI\Component\Button\ButtonFactory;
use Combodo\iTop\Application\UI\Component\Input\RichText\RichText;
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry;
@@ -28,6 +29,7 @@ use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CaseLogEntry;
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityNewEntryForm\ActivityNewEntryForm;
use Combodo\iTop\Application\UI\UIBlock;
use DBObject;
use Exception;
use MetaModel;
/**
@@ -50,6 +52,11 @@ class ActivityPanel extends UIBlock
/** @var \DBObject $oObject The object for which the activity panel is for */
protected $oObject;
/**
* @var string $sObjectMode Display mode of $oObject (create, edit, view, ...)
* @see \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
*/
protected $sObjectMode;
/** @var array $aCaseLogs Metadata of the case logs (att. code, color, ...), will be use to make the tabs and identify them easily */
protected $aCaseLogs;
/** @var ActivityEntry[] $aEntries */
@@ -77,6 +84,7 @@ class ActivityPanel extends UIBlock
$this->InitializeCaseLogTabs();
$this->SetObject($oObject);
$this->SetObjectMode(cmdbAbstractObject::DEFAULT_OBJECT_MODE);
$this->SetEntries($aEntries);
$this->bAreEntriesSorted = false;
}
@@ -118,6 +126,7 @@ class ActivityPanel extends UIBlock
{
return $this->oObject;
}
/**
* Return the object id for which the activity panel is for
*
@@ -126,6 +135,7 @@ class ActivityPanel extends UIBlock
public function GetObjectId(): int {
return $this->oObject->GetKey();
}
/**
* Return the object class for which the activity panel is for
*
@@ -135,6 +145,38 @@ class ActivityPanel extends UIBlock
return get_class($this->oObject);
}
/**
* Set the display mode of the $oObject
*
* @param string $sMode
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
*
* @return $this
* @throws \Exception
*/
public function SetObjectMode(string $sMode)
{
// Consistency check
if(!in_array($sMode, cmdbAbstractObject::EnumObjectModes())){
throw new Exception("Activity panel: Object mode '$sMode' not allowed, should be either ".implode(' / ', cmdbAbstractObject::EnumObjectModes()));
}
$this->sObjectMode = $sMode;
return $this;
}
/**
* Return the display mode of the $oObject
*
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
* @return string
*/
public function GetObjectMode(): string
{
return $this->sObjectMode;
}
/**
* Set all entries at once.
*

View File

@@ -20,6 +20,7 @@
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel;
use cmdbAbstractObject;
use CMDBChangeOpSetAttributeCaseLog;
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntryFactory;
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry;
@@ -44,17 +45,25 @@ class ActivityPanelFactory
* Make an activity panel for an object details layout, meaning that it should contain the case logs and the activity.
*
* @param \DBObject $oObject
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
*
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
*
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityPanel
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \Exception
* @throws \CoreUnexpectedValue
* @throws \DictExceptionMissingString
* @throws \MySQLException
* @throws \OQLException
*/
public static function MakeForObjectDetails(DBObject $oObject)
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE)
{
$sObjClass = get_class($oObject);
$iObjId = $oObject->GetKey();
$oActivityPanel = new ActivityPanel($oObject);
$oActivityPanel->SetObjectMode($sMode);
// Retrieve case logs entries
$aCaseLogAttCodes = array_keys($oActivityPanel->GetCaseLogTabs());

View File

@@ -20,6 +20,7 @@
namespace Combodo\iTop\Application\UI\Layout\PageContent;
use cmdbAbstractObject;
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityPanelFactory;
use DBObject;
@@ -46,12 +47,15 @@ class PageContentFactory
/**
* Make a standard object details page with the form in the middle and the logs / activity in the side panel
*
* @param \DBObject $oObject
* @param \DBObject $oObject
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
*
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
*
* @return \Combodo\iTop\Application\UI\Layout\PageContent\PageContentWithSideContent
* @throws \CoreException
*/
public static function MakeForObjectDetails(DBObject $oObject)
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE)
{
$oLayout = new PageContentWithSideContent();
@@ -59,7 +63,7 @@ class PageContentFactory
// TODO 3.0.0
// Add object activity layout
$oActivityPanel = ActivityPanelFactory::MakeForObjectDetails($oObject);
$oActivityPanel = ActivityPanelFactory::MakeForObjectDetails($oObject, $sMode);
$oLayout->AddSideBlock($oActivityPanel);
return $oLayout;

View File

@@ -1,4 +1,4 @@
<div id="{{ oUIBlock.GetId() }}" class="ibo-activity-panel" data-role="ibo-activity-panel" data-object-class="{{ oUIBlock.GetObjectClass() }}" data-object-id="{{ oUIBlock.GetObjectId() }}">
<div id="{{ oUIBlock.GetId() }}" class="ibo-activity-panel" data-role="ibo-activity-panel" data-object-class="{{ oUIBlock.GetObjectClass() }}" data-object-id="{{ oUIBlock.GetObjectId() }}" data-object-mode="{{ oUIBlock.GetObjectMode() }}">
<div class="ibo-activity-panel--header">
<div class="ibo-activity-panel--tabs">
{% for sCaseLogAttCode, aCaseLogData in oUIBlock.GetCaseLogTabs() %}