Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7132 - Portal & silo : unable to see workflow graph on some objects #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
66 changes: 9 additions & 57 deletions ajax-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

namespace Combodo\iTop\Extension\WorkflowGraphicalView;

use Combodo\iTop\Extension\WorkflowGraphicalView\Helper\ConfigHelper;
use Combodo\iTop\Extension\WorkflowGraphicalView\Service\GraphvizGenerator;
use Combodo\iTop\Extension\WorkflowGraphicalView\Service\LifecycleManager;
use Combodo\iTop\Extension\WorkflowGraphicalView\Helper\LifecycleGraphHelper;
use Exception;
use LoginWebPage;
use MetaModel;
Expand All @@ -34,72 +32,26 @@
require_once APPROOT.'/application/loginwebpage.class.inc.php';

// Check user is logged in
LoginWebPage::DoLoginEx(null, false);
LoginWebPage::DoLoginEx('backoffice', false);

// Retrieve parameters
$sObjClass = utils::ReadParam('object_class', '', false, 'class');
$iObjID = (int) utils::ReadParam('object_id', 0, false, 'integer');
$sOutputFormat = utils::ReadParam('output_format', 'image');
$sObjClass = utils::ReadParam('object_class', '', false, utils::ENUM_SANITIZATION_FILTER_CLASS);
$iObjID = (int) utils::ReadParam('object_id', 0, false, utils::ENUM_SANITIZATION_FILTER_INTEGER);
$sOutputFormat = utils::ReadParam('output_format', 'image', false, utils::ENUM_SANITIZATION_FILTER_PARAMETER);

try
{
// Retrieve object
$oObject = MetaModel::GetObject($sObjClass, $iObjID);
[ $sContent, $sHttpResponseCode,$aHeaders] = LifecycleGraphHelper::GetLifecycleGraph($oObject, $sOutputFormat);
Molkobain marked this conversation as resolved.
Show resolved Hide resolved

if(!LifecycleManager::IsEligibleObject($oObject))
{
throw new Exception('TOTR: Cannot show lifecycle for '.$sObjClass.'#'.$iObjID.', object is not eligible.');
}
header('Content-type: '.$aHeaders['Content-type']);
echo $sContent;

// Get module parameters
// - stimuli to hide
$aStimuliToHide = array();
$aModuleParameter = ConfigHelper::GetModuleSetting('stimuli_to_hide');
if(is_array($aModuleParameter) && isset($aModuleParameter[$sObjClass]))
{
foreach(explode(',', $aModuleParameter[$sObjClass]) as $sStimulusCode)
{
$aStimuliToHide[] = trim($sStimulusCode);
}
}
// - internal stimuli to hide
$bHideInternalStimuli = ConfigHelper::GetModuleSetting('hide_internal_stimuli');

$oLM = new LifecycleManager($oObject);
$sImageFilePath = $oLM->GetLifecycleImage($aStimuliToHide, $bHideInternalStimuli);

// Send content
switch($sOutputFormat)
{
case 'base64':
header('Content-type: text/plain');
echo base64_encode(file_get_contents($sImageFilePath));
break;

case 'binary':
default:
header('Content-type: image/png');
echo file_get_contents($sImageFilePath);
break;
}


// If image in temp. dir., we delete it (means that it's not the default image)
if(stripos($sImageFilePath, GraphvizGenerator::$sTmpFolderPath) !== false)
{
@unlink($sImageFilePath);
}
}
catch(Exception $oException)
{
http_response_code(500);
header('Content-type: text/html');
echo "<h3>{$oException->getMessage()}</h3>";
}

//$oController = new AjaxOperationsController(MODULESROOT.ConfigHelper::GetModuleCode().'/view', ConfigHelper::GetModuleCode());
//
//// Allow parallel execution
//session_write_close();
//
//$oController->HandleOperation();
}
1 change: 1 addition & 0 deletions cs.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions da.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
2 changes: 1 addition & 1 deletion datamodel.combodo-workflow-graphical-view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.7">
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.2">
<module_parameters>
<parameters id="combodo-workflow-graphical-view" _delta="define">
<hide_internal_stimuli type="boolean">false</hide_internal_stimuli>
Expand Down
1 change: 1 addition & 0 deletions de.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Interne Statusübergänge',
'workflow-graphical-view:Error:NoStateAttribute' => 'Es kann kein Lebenszyklusdiagramm für %1$s erstellt werden, da es kein Statusattribut hat.',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Hoppla! Der Lebenszyklus konnte nicht erstellt werden. Überprüfen Sie das Error-Log für weitere Informationen.',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions en.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible',
));
1 change: 1 addition & 0 deletions es_cr.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions fr.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Transitions internes',
'workflow-graphical-view:Error:NoStateAttribute' => 'Impossible de générer le graphique du cycle de vie pour %1$s car la classe n\'a pas d\'attribut portant le cycle de vie.',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Oups ! Le cycle de vie n\'a pas pu être chargé, vérifiez le journal des erreurs pour plus d\'informations.',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Impossible d\'afficher le cycle de vie pour l\'objet %1$s#%2$s, il n\'est pas disponible.',
));
1 change: 1 addition & 0 deletions hu.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions it.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions ja.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
8 changes: 6 additions & 2 deletions module.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/** @noinspection PhpUnhandledExceptionInspection */
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'combodo-workflow-graphical-view/1.1.1',
'combodo-workflow-graphical-view/1.2.0',
array(
// Identification
//
Expand All @@ -29,7 +29,10 @@

// Setup
//
'dependencies' => array(),
'dependencies' => array(
//optional dependance with the portal as it can be used in the back office only
'itop-portal-base/3.2.0 || itop-structure/3.2.0',
),
'mandatory' => false,
'visible' => true,

Expand All @@ -39,6 +42,7 @@
// Module's autoloader
'vendor/autoload.php',
// Explicitly load APIs classes
'src/Portal/Router/LifecycleBrickRouter.php',
'src/Hook/ConsoleUIExtension.php',
'src/Hook/PortalUIExtension.php',
),
Expand Down
1 change: 1 addition & 0 deletions nl.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions pl.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions pt_br.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions ru.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
1 change: 1 addition & 0 deletions sk.dict.combodo-workflow-graphical-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
'workflow-graphical-view:UI:Legend:Item:InternalStimuli' => 'Internal stimuli~~',
'workflow-graphical-view:Error:NoStateAttribute' => 'Cannot generate lifecycle graph for %1$s as it has no state attribute.~~',
'workflow-graphical-view:Error:GraphVizGeneration' => 'Whoops! Lifecycle could not be generated, check the error log for more information.~~',
'workflow-graphical-view:Error:ObjectNotEligible' => 'Cannot show lifecycle for %1$s#%2$s, object is not eligible~~',
));
87 changes: 87 additions & 0 deletions src/Helper/LifecycleGraphHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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\Extension\WorkflowGraphicalView\Helper;

use Combodo\iTop\Extension\WorkflowGraphicalView\Service\GraphvizGenerator;
use Combodo\iTop\Extension\WorkflowGraphicalView\Service\LifecycleManager;
use Symfony\Component\HttpFoundation\Response;

/**
* Class LifecycleGraphHelper
*
* @package Combodo\iTop\Extension\WorkflowGraphicalView\Helper
*/
class LifecycleGraphHelper
{
public static function GetLifecycleGraph($oObject, $sOutputFormat)
{
$sObjClass = get_class($oObject);
try {
if (!LifecycleManager::IsEligibleObject($oObject)) {
throw new Exception(Dict::Format('workflow-graphical-view:Error:ObjectNotEligible', $sObjClass, $oObject->GetKey()));
}

// Get module parameters
// - stimuli to hide
$aStimuliToHide = array();
$aModuleParameter = ConfigHelper::GetModuleSetting('stimuli_to_hide');
if (is_array($aModuleParameter) && isset($aModuleParameter[$sObjClass])) {
foreach (explode(',', $aModuleParameter[$sObjClass]) as $sStimulusCode) {
$aStimuliToHide[] = trim($sStimulusCode);
}
}
// - internal stimuli to hide
$bHideInternalStimuli = ConfigHelper::GetModuleSetting('hide_internal_stimuli');

$oLM = new LifecycleManager($oObject);
$sImageFilePath = $oLM->GetLifecycleImage($aStimuliToHide, $bHideInternalStimuli);

$aHeaders = [];
$sFileContent = null;
// Send content
switch ($sOutputFormat) {
case 'base64':
$aHeaders['Content-type'] = 'text/plain';
$sFileContent = base64_encode(file_get_contents($sImageFilePath));
break;

case 'binary':
default:
$aHeaders['Content-type'] = 'image/png';
$sFileContent = file_get_contents($sImageFilePath);
break;
}


// If image in temp. dir., we delete it (means that it's not the default image)
if (stripos($sImageFilePath, GraphvizGenerator::$sTmpFolderPath) !== false) {
@unlink($sImageFilePath);
}

return [$sFileContent, Response::HTTP_OK, $aHeaders];
}
catch (Exception $oException) {
$aHeaders['Content-type'] = 'text/html';

return ["<h3>{$oException->getMessage()}</h3>", Response::HTTP_INTERNAL_SERVER_ERROR, $aHeaders];
}
}
}
34 changes: 24 additions & 10 deletions src/Hook/ConsoleUIExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ class ConsoleUIExtension extends AbstractApplicationUIExtension
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
{
// Check if extension allowed
if(!ConfigHelper::IsAllowed('backoffice'))
{
if (!ConfigHelper::IsAllowed('backoffice')) {
return;
}

if(!LifecycleManager::IsEligibleObject($oObject))
{
if (!LifecycleManager::IsEligibleObject($oObject)) {
return;
}

Expand All @@ -56,14 +54,30 @@ public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false
$aJSFiles = $oLM->GetJSFilesUrls();
$sJSWidgetSnippet = $oLM->GetJSWidgetSnippetForObjectDetails();

// Add resources
foreach($aCSSFiles as $sCSSFile)
{
$oPage->add_linked_stylesheet($sCSSFile);
/**
* @since 3.2.0
*/
//remove require itopdesignformat at the same time as version_compare(ITOP_DESIGN_LATEST_VERSION , '3.2') < 0
if (!defined("ITOP_DESIGN_LATEST_VERSION")) {
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
}
foreach($aJSFiles as $sJSFile)
if (version_compare(ITOP_DESIGN_LATEST_VERSION, 3.2, '>=')) {
// Add resources
foreach ($aCSSFiles as $sCSSFile) {
$oPage->LinkStylesheetFromURI($sCSSFile);
}
foreach ($aJSFiles as $sJSFile) {
$oPage->LinkScriptFromURI($sJSFile);
}
} else
{
$oPage->add_linked_script($sJSFile);
// Add resources
foreach ($aCSSFiles as $sCSSFile) {
$oPage->add_linked_stylesheet($sCSSFile);
}
foreach ($aJSFiles as $sJSFile) {
$oPage->add_linked_script($sJSFile);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify that if it's only for 3.2+

}

// Add script
Expand Down
3 changes: 2 additions & 1 deletion src/Hook/PortalUIExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function GetJSInline(Container $oContainer)
$sWidgetName = LifecycleManager::GetJSWidgetNameForUI();
$sShowButtonCSSClassesAsJSON = json_encode(LifecycleManager::GetShowButtonCSSClasses());
$sLegendHTMLAsJSON = json_encode(LifecycleManager::GetLegendHTMLMarkup());
$sEndpoint = LifecycleManager::GetEndpoint();
$oRouter = $oContainer->get('router');
$sEndpoint = $oRouter->generate('p_lifecycle_view_object');

$sDictEntryShowButtonTooltipAsJSON = json_encode(Dict::S('workflow-graphical-view:UI:Button:ShowLifecycle'));
$sDictEntryModalTitleAsJSON = json_encode(Dict::S('workflow-graphical-view:UI:Modal:Title'));
Expand Down
Loading