mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-01 06:28:46 +02:00
N°2847 - Work on the ActivityPanel and PopoverMenu features
- Deprecate cmdbAbstractObject::DisplayBareHistory() as history will be replace by ActivityPanel - Rename illustrations to original filenames to find source more easily - Remove unused "max_history_case_log_entry_length" config. parameter - Activity panel: Introduce iCMDBChangeOp and iCMDBChangeOpSetAttribute interface for better dependency injection - Activity panel: Add placeholder when no entry - Activity panel: Fix tab toolbar icons color - Activity panel: Add history entries (entries after the first 50 are not loaded yet) - Popover menu: Fix no border-radius on first/last entries hover
This commit is contained in:
@@ -41,8 +41,13 @@ class ActivityEntry extends UIBlock
|
||||
const HTML_TEMPLATE_REL_PATH = 'layouts/activity-panel/activity-entry/layout';
|
||||
|
||||
// Specific constants
|
||||
/** @var string DEFAULT_ORIGIN */
|
||||
const DEFAULT_ORIGIN = 'unknown';
|
||||
/** @var string DEFAULT_DECORATION_CLASSES */
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-mortar-pestle';
|
||||
|
||||
/** @var string $sDecorationClasses CSS classes to use to decorate the entry */
|
||||
protected $sDecorationClasses;
|
||||
/** @var string $sContent Raw content of the entry itself (should not have been processed / escaped) */
|
||||
protected $sContent;
|
||||
/** @var \DateTime $oDateTime Date / time the entry occurred */
|
||||
@@ -63,23 +68,48 @@ class ActivityEntry extends UIBlock
|
||||
/**
|
||||
* ActivityEntry constructor.
|
||||
*
|
||||
* @param string $sContent
|
||||
* @param \DateTime $oDateTime
|
||||
* @param \User $sAuthorLogin
|
||||
* @param string $sId
|
||||
* @param string $sContent
|
||||
* @param string $sIdCode
|
||||
*
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function __construct($sContent, DateTime $oDateTime, $sAuthorLogin, $sId = null)
|
||||
public function __construct(DateTime $oDateTime, $sAuthorLogin, $sContent = null, $sIdCode = null)
|
||||
{
|
||||
parent::__construct($sId);
|
||||
parent::__construct($sIdCode);
|
||||
|
||||
$this->SetDecorationClasses(static::DEFAULT_DECORATION_CLASSES);
|
||||
$this->SetContent($sContent);
|
||||
$this->SetDateTime($oDateTime);
|
||||
$this->SetAuthor($sAuthorLogin);
|
||||
$this->SetOrigin(static::DEFAULT_ORIGIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the CSS decoration classes
|
||||
*
|
||||
* @param string $sDecorationClasses Must be a space-separated list of CSS classes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDecorationClasses($sDecorationClasses)
|
||||
{
|
||||
$this->sDecorationClasses = $sDecorationClasses;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string of the space separated CSS decoration classes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDecorationClasses()
|
||||
{
|
||||
return $this->sDecorationClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content without any filtering / escaping
|
||||
*
|
||||
|
||||
@@ -21,8 +21,11 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry;
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use CMDBChangeOp;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Class ActivityEntryFactory
|
||||
@@ -34,6 +37,31 @@ use MetaModel;
|
||||
*/
|
||||
class ActivityEntryFactory
|
||||
{
|
||||
/**
|
||||
* Make an ActivityEntry entry (for ActivityPanel) based on the $oChangeOp.
|
||||
*
|
||||
* @param \CMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(CMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$sFactoryFqcn = static::GetCmdbChangeOpFactoryClass($oChangeOp);
|
||||
|
||||
// If no factory found, throw an exception as the developer most likely forgot to create it
|
||||
if(empty($sFactoryFqcn))
|
||||
{
|
||||
throw new Exception('No factory found for '.get_class($oChangeOp).', did you forgot to create one?');
|
||||
}
|
||||
|
||||
/** @var \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry $oEntry */
|
||||
/** @noinspection PhpUndefinedMethodInspection Call static method from the $sFactoryFqcn class */
|
||||
$oEntry = $sFactoryFqcn::MakeFromCmdbChangeOp($oChangeOp);
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a CaseLogEntry entry (for ActivityPanel) from an ormCaseLog array entry.
|
||||
*
|
||||
@@ -51,12 +79,51 @@ class ActivityEntryFactory
|
||||
$sUserLogin = ($oUser === null) ? '' : $oUser->Get('login');
|
||||
|
||||
$oEntry = new CaseLogEntry(
|
||||
$aOrmEntry['message_html'],
|
||||
DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $aOrmEntry['date']),
|
||||
$sUserLogin,
|
||||
$sAttCode
|
||||
$sAttCode,
|
||||
$aOrmEntry['message_html']
|
||||
);
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the FQCN of the best fitted factory for the $oChangeOp. If none found, null will be returned.
|
||||
*
|
||||
* @param \CMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @return string|null
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected static function GetCmdbChangeOpFactoryClass(CMDBChangeOp $oChangeOp)
|
||||
{
|
||||
// Classes to search a factory for
|
||||
$aClassesTree = [get_class($oChangeOp)];
|
||||
|
||||
// Add parent classes to tree if not a root class
|
||||
$aParentClasses = class_parents($oChangeOp);
|
||||
if(is_array($aParentClasses))
|
||||
{
|
||||
$aClassesTree = array_merge($aClassesTree, array_values($aParentClasses));
|
||||
}
|
||||
|
||||
$sFactoryFqcn = null;
|
||||
foreach($aClassesTree as $sClass)
|
||||
{
|
||||
// Warning: This will replace all occurrences of 'CMDBChangeOp' which can be an issue on classes using this
|
||||
// We used the case sensitive search to limit this issue.
|
||||
$sSimplifiedClass = (new ReflectionClass($sClass))->getShortName();
|
||||
$sFactoryFqcnToTry = __NAMESPACE__ . '\\CMDBChangeOp\\' . $sSimplifiedClass . 'Factory';
|
||||
|
||||
// Stop at the first factory found
|
||||
if(class_exists($sFactoryFqcnToTry))
|
||||
{
|
||||
$sFactoryFqcn = $sFactoryFqcnToTry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $sFactoryFqcn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpAttachmentAddedFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpAttachmentAddedFactory extends CMDBChangeOpFactory
|
||||
{
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-paperclip';
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use iCMDBChangeOp;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpAttachmentRemovedFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpAttachmentRemovedFactory extends CMDBChangeOpFactory
|
||||
{
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-unlink';
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use iCMDBChangeOp;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpCreateFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpCreateFactory extends CMDBChangeOpFactory
|
||||
{
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-unlink';
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$oEntry = parent::MakeFromCmdbChangeOp($oChangeOp);
|
||||
$oEntry->SetDecorationClasses('fas fa-fw fa-seedling');
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use iCMDBChangeOp;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpDeleteFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpDeleteFactory extends CMDBChangeOpFactory
|
||||
{
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-unlink';
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$oEntry = parent::MakeFromCmdbChangeOp($oChangeOp);
|
||||
$oEntry->SetDecorationClasses('fas fa-fw fa-trash');
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry;
|
||||
use DateTime;
|
||||
use iCMDBChangeOp;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpFactory
|
||||
*
|
||||
* Default factory for CMDBChangeOp change ops
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpFactory
|
||||
{
|
||||
/** @var string DEFAULT_DECORATION_CLASSES Use to overload the decoration classes from the ActivityEntry */
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-mortar-pestle';
|
||||
|
||||
/**
|
||||
* Make an ActivityEntry from the iCMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @param \iCMDBChangeOp $oChangeOp
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp)
|
||||
{
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
$sContent = $oChangeOp->GetDescription();
|
||||
|
||||
$oEntry = new ActivityEntry($oDateTime, $sAuthorFriendlyname, $sContent);
|
||||
$oEntry->SetDecorationClasses(static::DEFAULT_DECORATION_CLASSES);
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry;
|
||||
use DateTime;
|
||||
use iCMDBChangeOpSetAttribute;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpSetAttributeFactory
|
||||
*
|
||||
* Default factory for CMDBChangeOpSetAttribute change ops
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp
|
||||
*/
|
||||
class CMDBChangeOpSetAttributeFactory
|
||||
{
|
||||
/**
|
||||
* Make an EditsEntry from the iCMDBChangeOpSetAttribute $oChangeOp
|
||||
*
|
||||
* @param \iCMDBChangeOpSetAttribute $oChangeOp
|
||||
*
|
||||
* @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp)
|
||||
{
|
||||
$sHostObjectClass = $oChangeOp->Get('objclass');
|
||||
$sAttCode = $oChangeOp->Get('attcode');
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
|
||||
$oEntry = new EditsEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass);
|
||||
$oEntry->AddAttribute($sAttCode, $oChangeOp->GetDescription());
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp;
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use iCMDBChangeOpSetAttribute;
|
||||
use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\TransitionEntry;
|
||||
use DateTime;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Class CMDBChangeOpSetAttributeScalarFactory
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp\Factory
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class CMDBChangeOpSetAttributeScalarFactory extends CMDBChangeOpSetAttributeFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp)
|
||||
{
|
||||
$sHostObjectClass = $oChangeOp->Get('objclass');
|
||||
$sAttCode = $oChangeOp->Get('attcode');
|
||||
|
||||
// Specific ActivityEntry for transition, otherwise just a regular EditsEntry
|
||||
if($sAttCode === MetaModel::GetStateAttributeCode($sHostObjectClass))
|
||||
{
|
||||
$oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date'));
|
||||
$sAuthorFriendlyname = $oChangeOp->Get('userinfo');
|
||||
|
||||
$sOriginStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('oldvalue'));
|
||||
$sTargetStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('newvalue'));
|
||||
|
||||
$oEntry = new TransitionEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass, $sOriginStateLabel, $sTargetStateLabel);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oEntry = parent::MakeFromCmdbChangeOp($oChangeOp);
|
||||
}
|
||||
|
||||
return $oEntry;
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,7 @@
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry;
|
||||
|
||||
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
use DateTime;
|
||||
use User;
|
||||
use UserRights;
|
||||
|
||||
/**
|
||||
* Class CaseLogEntry
|
||||
@@ -51,17 +47,17 @@ class CaseLogEntry extends ActivityEntry
|
||||
/**
|
||||
* CaseLogEntry constructor.
|
||||
*
|
||||
* @param string $sContent
|
||||
* @param \DateTime $oDateTime
|
||||
* @param \User $sAuthorLogin
|
||||
* @param string $sAttCode
|
||||
* @param string $sContentCode
|
||||
* @param string $sId
|
||||
*
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function __construct($sContent, DateTime $oDateTime, $sAuthorLogin, $sAttCode, $sId = null)
|
||||
public function __construct(DateTime $oDateTime, $sAuthorLogin, $sAttCode, $sContentCode, $sId = null)
|
||||
{
|
||||
parent::__construct($sContent, $oDateTime, $sAuthorLogin, $sId);
|
||||
parent::__construct($oDateTime, $sAuthorLogin, $sContentCode, $sId);
|
||||
|
||||
$this->sAttCode = $sAttCode;
|
||||
$this->SetCaseLogRank(static::DEFAULT_CASELOG_RANK);
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry;
|
||||
|
||||
|
||||
use DateTime;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Class EditsEntry
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry
|
||||
* @internal
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class EditsEntry extends ActivityEntry
|
||||
{
|
||||
// Overloaded constants
|
||||
const BLOCK_CODE = 'ibo-edits-entry';
|
||||
const HTML_TEMPLATE_REL_PATH = 'layouts/activity-panel/activity-entry/edits-entry';
|
||||
|
||||
// Specific constants
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-pen';
|
||||
|
||||
/** @var string $sObjectClass */
|
||||
protected $sObjectClass;
|
||||
/** @var array $aAttributes Array of edited attributes with their code, label and description */
|
||||
protected $aAttributes;
|
||||
|
||||
/**
|
||||
* EditsEntry constructor.
|
||||
*
|
||||
* @param \DateTime $oDateTime
|
||||
* @param \User $sAuthorLogin
|
||||
* @param string $sObjectClass Class of the object concerned by the edits
|
||||
* @param string $sId
|
||||
*
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function __construct(DateTime $oDateTime, $sAuthorLogin, $sObjectClass, $sId = null)
|
||||
{
|
||||
parent::__construct($oDateTime, $sAuthorLogin, null, $sId);
|
||||
|
||||
$this->sObjectClass = $sObjectClass;
|
||||
$this->SetAttributes([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class of the object concerned by the edits
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetObjectClass()
|
||||
{
|
||||
return $this->sObjectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all attributes at once, replacing all existing.
|
||||
*
|
||||
* @param array $aAttributes
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttributes($aAttributes)
|
||||
{
|
||||
$this->aAttributes = $aAttributes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of edited attributes with their code, label and description
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetAttributes()
|
||||
{
|
||||
return $this->aAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the attribute identified by $sAttCode to the edited attribute.
|
||||
* Note that if an attribute with the same $sAttCode already exists, it will be replaced.
|
||||
*
|
||||
* @param string $sAttCode
|
||||
* @param string $sEditDescriptionAsHtml The description of the edit already in HTML, it MUSt have been sanitized first (Already in HTML because most of the time it comes from CMDBChangeOp::GetDescription())
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function AddAttribute($sAttCode, $sEditDescriptionAsHtml)
|
||||
{
|
||||
$this->aAttributes[$sAttCode] = [
|
||||
'code' => $sAttCode,
|
||||
'label' => MetaModel::GetLabel($this->sObjectClass, $sAttCode),
|
||||
'description' => $sEditDescriptionAsHtml,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the attribute of code $sAttCode from the edited attributes.
|
||||
* Note that if there is no attribute with this code, it will proceed silently.
|
||||
*
|
||||
* @param string $sAttCode
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function RemoveAttribute($sAttCode)
|
||||
{
|
||||
if(array_key_exists($sAttCode, $this->aAttributes))
|
||||
{
|
||||
unset($this->aAttributes[$sAttCode]);
|
||||
}
|
||||
|
||||
return $this->aAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge $oEntry into the current one ($this).
|
||||
* Note that edits on any existing attribute codes will be replaced.
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry $oEntry
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function Merge(EditsEntry $oEntry)
|
||||
{
|
||||
if($oEntry->GetObjectClass() !== $this->GetObjectClass())
|
||||
{
|
||||
throw new Exception("Cannot merge an entry from {$oEntry->GetObjectClass()} into {$this->GetObjectClass()}, they must be for the same class");
|
||||
}
|
||||
|
||||
// Merging attributes
|
||||
foreach($oEntry->GetAttributes() as $sAttCode => $aAttData)
|
||||
{
|
||||
$this->aAttributes[$sAttCode] = $aAttData;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the short description of the edits entry in HTML
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetShortDescriptionAsHtml()
|
||||
{
|
||||
// We need the array to be indexed by numbers instead of being associative
|
||||
$aAttributesData = array_values($this->GetAttributes());
|
||||
$iAttributesCount = count($aAttributesData);
|
||||
switch($iAttributesCount)
|
||||
{
|
||||
case 0:
|
||||
$sDescriptionAsHtml = '';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$sDescriptionAsHtml = $aAttributesData[0]['description'];
|
||||
break;
|
||||
|
||||
default:
|
||||
$sFirstAttLabelAsHtml = '<span class="ibo-edits-entry--attribute-label" data-attribute-code="'.$aAttributesData[0]['code'].'">'.$aAttributesData[0]['label'].'</span>';
|
||||
$sSecondAttLabelAsHtml = '<span class="ibo-edits-entry--attribute-label" data-attribute-code="'.$aAttributesData[1]['code'].'">'.$aAttributesData[1]['label'].'</span>';
|
||||
|
||||
switch($iAttributesCount)
|
||||
{
|
||||
case 2:
|
||||
$sDescriptionAsHtml = Dict::Format('Change:TwoAttributesChanged', $sFirstAttLabelAsHtml, $sSecondAttLabelAsHtml);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$sDescriptionAsHtml = Dict::Format('Change:ThreeAttributesChanged', $sFirstAttLabelAsHtml, $sSecondAttLabelAsHtml);
|
||||
break;
|
||||
|
||||
default:
|
||||
$sDescriptionAsHtml = Dict::Format('Change:FourOrMoreAttributesChanged', $sFirstAttLabelAsHtml, $sSecondAttLabelAsHtml, count($aAttributesData) - 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $sDescriptionAsHtml;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry;
|
||||
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Class TransitionEntry
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry
|
||||
* @internal
|
||||
* @since 2.8.0
|
||||
*/
|
||||
class TransitionEntry extends ActivityEntry
|
||||
{
|
||||
// Overloaded constants
|
||||
const BLOCK_CODE = 'ibo-transition-entry';
|
||||
const HTML_TEMPLATE_REL_PATH = 'layouts/activity-panel/activity-entry/transition-entry';
|
||||
|
||||
// Specific constants
|
||||
const DEFAULT_DECORATION_CLASSES = 'fas fa-fw fa-map-signs';
|
||||
|
||||
/** @var string $sOriginStateCode Code of the state before the transition */
|
||||
protected $sOriginStateCode;
|
||||
/** @var string $sOriginStateLabel Label of the $sOriginStateCode state */
|
||||
protected $sOriginStateLabel;
|
||||
/** @var string $sTargetStateCode Code of the state after the transition */
|
||||
protected $sTargetStateCode;
|
||||
/** @var string $sTargetStateLabel Label of the $sTargetStateCode state */
|
||||
protected $sTargetStateLabel;
|
||||
|
||||
/**
|
||||
* TransitionEntry constructor.
|
||||
*
|
||||
* @param \DateTime $oDateTime
|
||||
* @param \User $sAuthorLogin
|
||||
* @param string $sObjectClass Class of the object which made the transition
|
||||
* @param string $sOriginStateCode
|
||||
* @param string $sTargetStateCode
|
||||
* @param string $sId
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \OQLException
|
||||
*/
|
||||
public function __construct(DateTime $oDateTime, $sAuthorLogin, $sObjectClass, $sOriginStateCode, $sTargetStateCode, $sId = null)
|
||||
{
|
||||
parent::__construct($oDateTime, $sAuthorLogin, null, $sId);
|
||||
|
||||
$this->SetOriginalState($sObjectClass, $sOriginStateCode);
|
||||
$this->SetTargetState($sObjectClass, $sTargetStateCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the code / label of the state before the transition
|
||||
*
|
||||
* @param string $sObjectClass Class of the object the state is from
|
||||
* @param string $sStateCode
|
||||
*
|
||||
* @return $this
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function SetOriginalState($sObjectClass, $sStateCode)
|
||||
{
|
||||
$this->sOriginStateCode = $sStateCode;
|
||||
$this->sOriginStateLabel = \MetaModel::GetStateLabel($sObjectClass, $sStateCode);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the code of the state before the transition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetOriginalStateCode()
|
||||
{
|
||||
return $this->sOriginStateCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the label of the state before the transition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetOriginalStateLabel()
|
||||
{
|
||||
return $this->sOriginStateLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the code / label of the state after the transition
|
||||
*
|
||||
* @param string $sObjectClas
|
||||
* @param string $sStateCode
|
||||
*
|
||||
* @return $this
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function SetTargetState($sObjectClas, $sStateCode)
|
||||
{
|
||||
$this->sTargetStateCode = $sStateCode;
|
||||
$this->sTargetStateLabel = \MetaModel::GetStateLabel($sObjectClas, $sStateCode);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the code of the state after the transition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTargetStateCode()
|
||||
{
|
||||
return $this->sTargetStateCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the label of the state after the transition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTargetStateLabel()
|
||||
{
|
||||
return $this->sTargetStateLabel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user