Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Exception;
use MetaModel;
use RunTimeEnvironment;
use SecurityException;
use SetupUtils;
use utils;

Expand Down Expand Up @@ -83,10 +84,11 @@ public function OperationAnalysisResult(): void
{
$aParams = [];

if (SetupUtils::IsSessionSetupTokenValid()) {
try {
//from setup wizard/mtp
SetupUtils::CheckSetupToken();
SetupUtils::EraseSetupToken();
} else {
} catch (SecurityException $e) {
//from same module
$this->ValidateTransactionId();
}
Comment thread
Lenaick marked this conversation as resolved.
Expand All @@ -100,6 +102,7 @@ public function OperationAnalysisResult(): void
'removed_extensions' => '[]',
'extensions_not_uninstallable' => '[]',
'copy_setup_files' => 1,
'return_button_label' => '',
];

$aHiddenInputs = [];
Expand All @@ -108,6 +111,10 @@ public function OperationAnalysisResult(): void
}
$aParams['aHiddenInputs'] = $aHiddenInputs;

if ($aHiddenInputs['return_button_label'] !== '') {
$aParams['sReturnButtonURL'] = utils::GetAbsoluteUrlModulePage('itsm-designer-connector', 'launch.php');
}

$aAddedExtensions = json_decode($aHiddenInputs['added_extensions'], true);

$aRemovedExtensions = json_decode($aHiddenInputs['removed_extensions'], true);
Expand Down Expand Up @@ -179,6 +186,10 @@ public function OperationAnalysisResult(): void
$aParams['aSetupParams']["_params[$sInputName]"] = $sInputValue;
}

if ($aHiddenInputs['return_button_label'] !== '') {
$aParams['sReturnButtonURL'] = utils::GetAbsoluteUrlModulePage('itsm-designer-connector', 'launch.php');
Comment thread
Lenaick marked this conversation as resolved.
}

[$aParams['aDeletionPlanSummary'], $aParams['iQueryCount'], $aParams['bDeletionPossible']] = $this->GetDeletionPlanSummaryTable($aGetRemovedClasses);
[$aParams['aDeletionExecutionSummary'], $aParams['bHasDeletionExecution']] = $this->GetExecutionSummaryTable();
$aParams['bDeletionNeeded'] = ($aParams['iQueryCount'] > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@
{% endif %}
{% endif %}

{% UIForm Standard {} %}
{% UIInput ForHidden { sName:'transaction_id', sValue:sTransactionId} %}
{% UIInput ForHidden { sName:'operation', sValue:'Main'} %}
{% UIToolbar ForButton {} %}
{% UIButton ForPrimaryAction {sLabel:'UI:Button:BackToMain'|dict_s, sName:'btn_back', sId:'btn_back', bIsSubmit:true} %}
{% EndUIToolbar %}
{% EndUIForm %}
{% if aHiddenInputs.return_button_label != '' %}
{% UIButton ForAlternativeSecondaryAction { sLabel:aHiddenInputs.return_button_label, OnClickJsCode: 'window.location.href="' ~ sReturnButtonURL ~ '"'} %}
{% else %}
{% UIForm Standard {} %}
{% UIInput ForHidden { sName:'transaction_id', sValue:sTransactionId} %}
{% UIInput ForHidden { sName:'operation', sValue:'Main'} %}
{% UIToolbar ForButton {} %}
{% UIButton ForPrimaryAction {sLabel:'UI:Button:BackToMain'|dict_s, sName:'btn_back', sId:'btn_back', bIsSubmit:true} %}
{% EndUIToolbar %}
{% EndUIForm %}
{% endif %}
{% EndUIPanel %}
8 changes: 4 additions & 4 deletions setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ function WizardAsyncAction(sActionCode, oParams, OnErrorFunction)
function WizardUpdateButtons()
{
if (CanMoveForward()) {
$("#btn_next").prop('disabled', false);
$("#btn_next").removeClass('ibo-is-hidden');
}
else {
$("#btn_next").prop('disabled', true);
$("#btn_next").addClass('ibo-is-hidden');
}

if (CanMoveBackward()) {
$("#btn_back").prop('disabled', false);
$("#btn_back").removeClass('ibo-is-hidden');
}
else {
$("#btn_back").prop('disabled', true);
$("#btn_back").addClass('ibo-is-hidden');
}
}

Expand Down
12 changes: 8 additions & 4 deletions setup/wizardcontroller.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ protected function Next()
$sCurrentState = utils::ReadParam('_state', $this->sInitialState);
$oStep = $this->GetWizardStep($sCurrentStepClass, $sCurrentState);
if ($oStep->ValidateParams()) {
if ($oStep->CanComeBack()) {
$aPossibleSteps = $oStep->GetPossibleSteps();
if ($oStep->CanMoveBackward()) {
$this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]);
}
$aPossibleSteps = $oStep->GetPossibleSteps();
$oWizardState = $oStep->UpdateWizardStateAndGetNextStep(true); // true => moving forward
if (in_array($oWizardState->GetNextStep(), $aPossibleSteps)) {
$oNextStep = $this->GetWizardStep($oWizardState->GetNextStep(), $oWizardState->GetState());
Expand Down Expand Up @@ -237,8 +237,12 @@ protected function DisplayStep(WizardStep $oStep): void

$oPage->add('<input type="hidden" name="_steps" value="'.utils::EscapeHtml(json_encode($this->aWizardSteps)).'"/>');
$oPage->add('<table style="width:100%;" class="ibo-setup--wizard--buttons-container"><tr>');
if ((count($this->aWizardSteps) > 0) && ($oStep->CanMoveBackward())) {
$oPage->add('<td style="text-align: left"><button id="btn_back" class="ibo-button ibo-is-alternative ibo-is-neutral" type="submit" name="operation" value="back"><span class="ibo-button--label">Back</span></button></td>');
if (count($this->aWizardSteps) > 0) {
if ($oStep->CanMoveBackward()) {
$oPage->add('<td style="text-align: left"><button id="btn_back" class="ibo-button ibo-is-alternative ibo-is-neutral" type="submit" name="operation" value="back"><span class="ibo-button--label">Back</span></button></td>');
} else {
$oPage->add('<td style="text-align: left"><button id="btn_back" class="ibo-button ibo-is-alternative ibo-is-neutral ibo-is-hidden" type="submit" name="operation" value="back"><span class="ibo-button--label">Back</span></button></td>');
}
}
if ($oStep->CanMoveForward()) {
$oPage->add('<td style="text-align:right;"><button id="btn_next" class="default ibo-button ibo-is-regular ibo-is-primary" type="submit" name="operation" value="next"><span class="ibo-button--label">'.utils::EscapeHtml($oStep->GetNextButtonLabel()).'</span></button></td>');
Expand Down
47 changes: 38 additions & 9 deletions setup/wizardsteps/WizStepDataAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ public function CanMoveForward()
}
}

public function UpdateWizardStateAndGetNextStep($bMoveForward = true): WizardState
/**
* Tells whether this step/state allows to go back or not
* @return boolean True if the '<< Back' button should be displayed
*/
public function CanMoveBackward()
{
return new WizardState(WizStepSummary::class);
return false;
}

public function CanComeBack()
public function UpdateWizardStateAndGetNextStep($bMoveForward = true): WizardState
{
return false;
return new WizardState(WizStepSummary::class);
}

public function Display(SetupPage $oPage): void
Expand Down Expand Up @@ -108,6 +112,7 @@ public function PostFormDisplay(SetupPage $oPage)
'removed_extensions' => '[]',
'extensions_not_uninstallable' => '[]',
'copy_setup_files' => 1,
'return_button_label' => '',
];
$aHiddenInputs = '';
foreach ($aParams as $sParamName => $defaultValue) {
Expand All @@ -123,23 +128,43 @@ public function PostFormDisplay(SetupPage $oPage)
<<<HTML
<form id="data-feature-removal" class="ibo-setup--wizard ibo-is-hidden" method="post" action="$sApplicationUrl">
<input type="hidden" name="operation" value="AnalysisResult"/>
<input type="hidden" name="setup_token" value="$sUID"/>
<input type="hidden" name="authent" value="$sUID"/>
$aHiddenInputs
</form>
HTML
);

$sButtonLabel = $this->oWizard->GetParameter('return_button_label', '');
if ($sButtonLabel !== '') {
$sButtonLabel = utils::HtmlEntities($sButtonLabel);
$sButtonUrl = utils::GetAbsoluteUrlModulePage('itsm-designer-connector', 'launch.php');
$sButtonUrl = utils::HtmlEntities($sButtonUrl);
$oPage->add_ready_script(
<<<JS
$('.ibo-setup--wizard--buttons-container tr td:nth-child(1)').after('<td style="text-align:center;"><button id="return-button" class="ibo-button ibo-is-alternative ibo-is-neutral ibo-is-hidden" type="button" onclick="window.location.href=\'$sButtonUrl\'"><span class="ibo-button--label">$sButtonLabel</span></button></td>');
Comment thread
Lenaick marked this conversation as resolved.
JS
);
}
Comment thread
Lenaick marked this conversation as resolved.
}

protected function AddProgressErrorScript($oPage, $aRes)
{
$oPage->add_ready_script(
<<<JS
if ($('#return-button').length > 0) {
$('#return-button').removeClass('ibo-is-hidden');
}
JS
);

if (isset($aRes['error_code']) && $aRes['error_code'] === DataAuditSequencer::DATA_AUDIT_FAILED) {
$oPage->add_ready_script(
<<<EOF
$('.ibo-setup--wizard--buttons-container tr td:nth-child(2)').before('<td style="text-align:center;"><button class="ibo-button ibo-is-alternative ibo-is-neutral" type="submit" name="operation" value="next" id="ignore_and_continue"><span class="ibo-button--label">Ignore and continue</span></button></td>');
<<<JS
$('.ibo-setup--wizard--buttons-container tr td:nth-child(2)').after('<td style="text-align:center;"><button class="ibo-button ibo-is-alternative ibo-is-neutral" type="submit" name="operation" value="next" id="ignore_and_continue"><span class="ibo-button--label">Ignore and continue</span></button></td>');
$('#ignore_and_continue').on('click', function() {
return confirm("If you skip the cleanup you won't be able to run the process later. You'll have to migrate or delete unconsistent data manually.");
});
$('.ibo-setup--wizard--buttons-container tr td:nth-child(2)').after('<td style="text-align:center;"><span id="submit-wait" class="ibo-spinner ibo-is-inline ibo-is-hidden ibo-spinner ibo-block" data-role="ibo-spinner"><i class="ibo-spinner--icon fas fa-sync-alt fa-spin" aria-hidden="true"></i></span>&nbsp;<button id="goto-data-feature-removal" class="default ibo-button ibo-is-regular ibo-is-primary" type="button"><span class="ibo-button--label">Cleanup my data</span></button></td>');
$('.ibo-setup--wizard--buttons-container tr td:nth-child(3)').after('<td style="text-align:center;"><span id="submit-wait" class="ibo-spinner ibo-is-inline ibo-is-hidden ibo-spinner ibo-block" data-role="ibo-spinner"><i class="ibo-spinner--icon fas fa-sync-alt fa-spin" aria-hidden="true"></i></span>&nbsp;<button id="goto-data-feature-removal" class="default ibo-button ibo-is-regular ibo-is-primary" type="button"><span class="ibo-button--label">Cleanup my data</span></button></td>');
$('#goto-data-feature-removal').on("click", function() {
$('#goto-data-feature-removal').prop('disabled', true);
$('#submit-wait').removeClass("ibo-is-hidden");
Expand All @@ -148,7 +173,7 @@ protected function AddProgressErrorScript($oPage, $aRes)

$("#wiz_form").data("installation_status", "cleanup_needed");
$('#btn_next').hide();
EOF
JS
);
}

Expand All @@ -161,6 +186,10 @@ public function JSCanMoveForward()

public function JSCanMoveBackward()
{
if ($this->oWizard->GetParameter('return_button_label', '') !== '') {
return 'return false;';
}

return 'return ["not started", "error", "cleanup_needed"].indexOf($("#wiz_form").data("installation_status")) !== -1;';
}
}
5 changes: 5 additions & 0 deletions setup/wizardsteps/WizStepDone.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public function CanMoveBackward()
return false;
}

public function JSCanMoveBackward()
{
return 'return false;';
}

/**
* Tells whether this step of the wizard requires that the configuration file be writable
* @return bool True if the wizard will possibly need to modify the configuration at some point
Expand Down
71 changes: 48 additions & 23 deletions setup/wizardsteps/WizStepInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public function CanMoveForward()
}
}

public function CanMoveBackward()
{
$sLabel = $this->oWizard->GetParameter('return_button_label', '');
SetupLog::Info(__METHOD__.": return_button_label [$sLabel]");
return $sLabel === '';
}

public function UpdateWizardStateAndGetNextStep($bMoveForward = true): WizardState
{
return new WizardState(WizStepDone::class);
Expand Down Expand Up @@ -109,6 +116,20 @@ public function Display(SetupPage $oPage): void
JS);
}

public function PostFormDisplay(SetupPage $oPage)
{
$sButtonLabel = $this->oWizard->GetParameter('return_button_label', '');
SetupLog::Info(__METHOD__.": return_button_label [$sButtonLabel]");
if ($sButtonLabel !== '') {
$sButtonUrl = utils::GetAbsoluteUrlModulePage('itsm-designer-connector', 'launch.php');
$oPage->add_ready_script(
<<<JS
$('.ibo-setup--wizard--buttons-container tr td:nth-child(1)').after('<td style="text-align:center;"><button id="return-button" class="ibo-button ibo-is-alternative ibo-is-neutral ibo-is-hidden" type="button" onclick="window.location.href=\'$sButtonUrl\'"><span class="ibo-button--label">$sButtonLabel</span></button></td>');
Comment thread
Lenaick marked this conversation as resolved.
JS
);
}
Comment thread
Lenaick marked this conversation as resolved.
}

/**
* @throws \Exception
*/
Expand All @@ -125,48 +146,52 @@ public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
// Tell the web page to move the progress bar and to launch the next step
$sMessage = addslashes(utils::EscapeHtml($aRes['next-step-label']));
$oPage->add_ready_script(
<<<EOF
$("#wiz_form").data("installation_status", "running");
WizardUpdateButtons();
$('#setup_msg').html('$sMessage');
$('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100} );

//$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
ExecuteStep('{$aRes['next-step']}');
EOF
<<<JS
$("#wiz_form").data("installation_status", "running");
WizardUpdateButtons();
$('#setup_msg').html('$sMessage');
$('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100} );
//$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
ExecuteStep('{$aRes['next-step']}');
JS
);
static::AddPrevStepSuccessMessage($oPage, $aRes['prev-step-success-message']);
} elseif ($aRes['status'] !== StepSequencer::ERROR) {
// Installation complete, move to the next step of the wizard
$oPage->add_ready_script(
<<<EOF
$("#wiz_form").data("installation_status", "completed");
$('#progress').progression( {Current:100, Maximum: 100} );
WizardUpdateButtons();
$("#btn_next").off("click.install");
$("#btn_next").trigger('click');
EOF
<<<JS
$('#progress').progression( {Current:100, Maximum: 100} );
$("#wiz_form").data("installation_status", "completed");
$("#btn_next").trigger('click');
JS
);
static::AddPrevStepSuccessMessage($oPage, $aRes['prev-step-success-message']);
} else {
//Error case
$sMessage = addslashes(utils::EscapeHtml($aRes['message']));
$sMessage = str_replace("\n", '<br>', $sMessage);
$oPage->add_ready_script(
<<<EOF
$("#wiz_form").data("installation_status", "error");
$("#progress .progress").addClass('progress-error');
WizardUpdateButtons();
$('#setup_error').html('$sMessage').show();
EOF
<<<JS
$("#wiz_form").data("installation_status", "error");
$("#progress .progress").addClass('progress-error');
WizardUpdateButtons();
$('#setup_error').html('$sMessage').show();
JS
);
$this->AddProgressErrorScript($oPage, $aRes);
}
}

protected function AddProgressErrorScript($oPage, $aRes)
{

$oPage->add_ready_script(
<<<JS
if ($('#return-button').length > 0) {
$('#return-button').removeClass('ibo-is-hidden');
}
JS
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion setup/wizardsteps/WizStepLandingBeforeAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function GetNextButtonLabel()
return 'Next';
}

public function CanComeBack()
public function CanMoveBackward()
{
return false;
}
Expand Down
Loading