mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 23:32:17 +02:00
N°803 - Allow display & edition of attributes on n:n relations on Portal
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1802,3 +1802,22 @@ table .group-actions .item-action-wrapper .panel-body > p:last-child{
|
||||
.wiki_broken_link {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
/* Shameful area (things that should be refactored soon) */
|
||||
/**********************************************************/
|
||||
|
||||
/* Hide attributes label in link set edition, will be fixed during attributes refactoring */
|
||||
.form_linkedset_wrapper label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Add mandatory field column label */
|
||||
.form_linkedset_wrapper .dataTables_scrollHead th.mandatory:after {
|
||||
content: "*";
|
||||
position: relative;
|
||||
left: 3px;
|
||||
color: #EA7D1E;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ use BinaryExpression;
|
||||
use Combodo\iTop\Portal\Brick\CreateBrick;
|
||||
use Combodo\iTop\Portal\Helper\ApplicationHelper;
|
||||
use Combodo\iTop\Portal\Helper\ContextManipulatorHelper;
|
||||
use Combodo\iTop\Renderer\Bootstrap\FieldRenderer\BsLinkedSetFieldRenderer;
|
||||
use DBObject;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
@@ -1312,14 +1313,20 @@ class ObjectController extends BrickController
|
||||
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeValidator */
|
||||
$oScopeValidator = $this->get('scope_validator');
|
||||
|
||||
$aData = array();
|
||||
// Data array
|
||||
$aData = array(
|
||||
'js_inline' => '',
|
||||
'css_inline' => '',
|
||||
);
|
||||
|
||||
// Retrieving parameters
|
||||
$sObjectClass = $oRequestManipulator->ReadParam('sObjectClass', '');
|
||||
$sLinkClass = $oRequestManipulator->ReadParam('sLinkClass', '');
|
||||
$aObjectIds = $oRequestManipulator->ReadParam('aObjectIds', array(), FILTER_UNSAFE_RAW);
|
||||
$aObjectAttCodes = $oRequestManipulator->ReadParam('aObjectAttCodes', array(), FILTER_UNSAFE_RAW);
|
||||
if (empty($sObjectClass) || empty($aObjectIds) || empty($aObjectAttCodes))
|
||||
{
|
||||
$aLinkAttCodes = $oRequestManipulator->ReadParam('aLinkAttCodes', array(), FILTER_UNSAFE_RAW);
|
||||
|
||||
if (empty($sObjectClass) || empty($aObjectIds) || empty($aObjectAttCodes)) {
|
||||
IssueLog::Info(__METHOD__.' at line '.__LINE__.' : sObjectClass, aObjectIds and aObjectAttCodes expected, "'.$sObjectClass.'", "'.implode('/',
|
||||
$aObjectIds).'" given.');
|
||||
throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'Invalid request data, some information are missing');
|
||||
@@ -1338,15 +1345,35 @@ class ObjectController extends BrickController
|
||||
|
||||
// Checking that id is in the AttCodes
|
||||
// Note: We do that AFTER the array is used in OptimizeColumnLoad() because the function doesn't support this anymore.
|
||||
if (!in_array('id', $aObjectAttCodes))
|
||||
{
|
||||
if (!in_array('id', $aObjectAttCodes)) {
|
||||
$aObjectAttCodes = array_merge(array('id'), $aObjectAttCodes);
|
||||
}
|
||||
|
||||
// Retrieving objects
|
||||
while ($oObject = $oSet->Fetch())
|
||||
{
|
||||
$aData['items'][] = $this->PrepareObjectInformation($oObject, $aObjectAttCodes);
|
||||
while ($oObject = $oSet->Fetch()) {
|
||||
// Prepare link data
|
||||
$aObjectData = $this->PrepareObjectInformation($oObject, $aObjectAttCodes);
|
||||
// New link object (needed for renderers)
|
||||
$oNewLink = new $sLinkClass();
|
||||
foreach ($aLinkAttCodes as $sAttCode) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($sLinkClass, $sAttCode);
|
||||
$oField = $oAttDef->MakeFormField($oNewLink);
|
||||
$sFieldRendererClass = BsLinkedSetFieldRenderer::GetFieldRendererClass($oField);
|
||||
$sValue = $oAttDef->GetAsHTML($oNewLink->Get($sAttCode));
|
||||
if ($sFieldRendererClass !== null) {
|
||||
$oFieldRenderer = new $sFieldRendererClass($oField);
|
||||
$oFieldOutput = $oFieldRenderer->Render();
|
||||
$sValue = $oFieldOutput->GetHtml();
|
||||
}
|
||||
$aObjectData['attributes'][$sAttCode] = [
|
||||
'att_code' => $sAttCode,
|
||||
'value' => $sValue,
|
||||
'css_inline' => $oFieldOutput->GetCss(),
|
||||
'js_inline' => $oFieldOutput->GetJs(),
|
||||
];
|
||||
}
|
||||
|
||||
$aData['items'][] = $aObjectData;
|
||||
}
|
||||
|
||||
return new JsonResponse($aData);
|
||||
@@ -1356,7 +1383,7 @@ class ObjectController extends BrickController
|
||||
* Prepare a DBObject information as an array for a client side usage (typically, add a row in a table)
|
||||
*
|
||||
* @param \DBObject $oObject
|
||||
* @param array $aAttCodes
|
||||
* @param array $aAttCodes
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@@ -1372,8 +1399,8 @@ class ObjectController extends BrickController
|
||||
|
||||
$sObjectClass = get_class($oObject);
|
||||
$aObjectData = array(
|
||||
'id' => $oObject->GetKey(),
|
||||
'name' => $oObject->GetName(),
|
||||
'id' => $oObject->GetKey(),
|
||||
'name' => $oObject->GetName(),
|
||||
'attributes' => array(),
|
||||
);
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ use Exception;
|
||||
use ExceptionLog;
|
||||
use InlineImage;
|
||||
use IssueLog;
|
||||
use LogChannels;
|
||||
use MetaModel;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
@@ -859,7 +860,10 @@ class ObjectFormManager extends FormManager
|
||||
foreach ($aAttCodesToDisplay as $sAttCodeToDisplay)
|
||||
{
|
||||
$oAttDefToDisplay = MetaModel::GetAttributeDef($oField->GetTargetClass(), $sAttCodeToDisplay);
|
||||
$aAttributesToDisplay[$sAttCodeToDisplay] = $oAttDefToDisplay->GetLabel();
|
||||
$aAttributesToDisplay[$sAttCodeToDisplay] = [
|
||||
'label' => $oAttDefToDisplay->GetLabel(),
|
||||
'mandatory' => !$oAttDefToDisplay->IsNullAllowed(),
|
||||
];
|
||||
}
|
||||
$oField->SetAttributesToDisplay($aAttributesToDisplay);
|
||||
}
|
||||
@@ -869,7 +873,7 @@ class ObjectFormManager extends FormManager
|
||||
|
||||
/** @var \ormLinkSet $oFieldOriginalSet */
|
||||
$oFieldOriginalSet = $oField->GetCurrentValue();
|
||||
while ($oLink = $oFieldOriginalSet->Fetch()) {
|
||||
foreach ($oFieldOriginalSet as $oLink) {
|
||||
if ($oField->IsIndirect()) {
|
||||
$iRemoteKey = $oLink->Get($oAttDef->GetExtKeyToRemote());
|
||||
} else {
|
||||
@@ -1099,7 +1103,7 @@ class ObjectFormManager extends FormManager
|
||||
{
|
||||
$aData = parent::OnSubmit($aArgs);
|
||||
|
||||
if (! $aData['valid']) {
|
||||
if (!$aData['valid']) {
|
||||
return $aData;
|
||||
}
|
||||
|
||||
@@ -1282,6 +1286,15 @@ class ObjectFormManager extends FormManager
|
||||
$oLink = MetaModel::NewObject($sLinkedClass);
|
||||
$oLink->Set($oAttDef->GetExtKeyToRemote(), $iObjKey);
|
||||
$oLink->Set($oAttDef->GetExtKeyToMe(), $this->oObject->GetKey());
|
||||
// Set link attributes values...
|
||||
foreach ($aObjdata as $sLinkAttCode => $oAttValue) {
|
||||
if (!is_scalar($oAttValue)) {
|
||||
IssueLog::Debug("ObjectFormManager::OnUpdate invalid link attribute value, $sLinkAttCode is not a scalar value", LogChannels::PORTAL);
|
||||
continue;
|
||||
}
|
||||
$oLink->Set($sLinkAttCode, $oAttValue);
|
||||
}
|
||||
$oLinkSet->AddItem($oLink);
|
||||
}
|
||||
// ... or adding remote object when linkset id direct
|
||||
else
|
||||
@@ -1290,15 +1303,36 @@ class ObjectFormManager extends FormManager
|
||||
$oLink = MetaModel::GetObject($sLinkedClass, $iObjKey, false, true);
|
||||
}
|
||||
|
||||
if ($oLink !== null)
|
||||
{
|
||||
if ($oLink !== null) {
|
||||
$oLinkSet->AddItem($oLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checking links to modify
|
||||
// TODO: Not implemented yet as we can't change lnk properties in the portal
|
||||
if ($oAttDef->IsIndirect() && isset($value['current'])) {
|
||||
foreach ($value['current'] as $iObjKey => $aObjData) {
|
||||
if ($iObjKey < 0) {
|
||||
continue;
|
||||
}
|
||||
$oLink = null;
|
||||
$oLinkSet->Rewind();
|
||||
foreach ($oLinkSet as $oItem) {
|
||||
if ($oItem->Get('id') != $iObjKey) {
|
||||
continue;
|
||||
}
|
||||
$oLink = $oItem;
|
||||
foreach ($aObjData as $sLinkAttCode => $oAttValue) {
|
||||
if (!is_scalar($oAttValue)) {
|
||||
IssueLog::Debug("ObjectFormManager::OnUpdate invalid link attribute value, $sLinkAttCode is not a scalar value", LogChannels::PORTAL);
|
||||
continue;
|
||||
}
|
||||
$oLink->Set($sLinkAttCode, $oAttValue);
|
||||
}
|
||||
$oLinkSet->ModifyItem($oLink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setting value in the object
|
||||
$this->oObject->Set($sAttCode, $oLinkSet);
|
||||
|
||||
Reference in New Issue
Block a user