mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-22 00:32:16 +02:00
N°3537 run_query : fix query suggestion button
Was throwing plain old HTML Now use standard button component, and a new HtmlFactory to avoid calling \WebPage::GetP Also change "use this query" behavior : now also submits the form directly And : added a TODO 3.0.0 for the "query examples" buttons (will be done later)
This commit is contained in:
@@ -179,6 +179,7 @@ return array(
|
|||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchFactory' => $baseDir . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchFactory.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchFactory' => $baseDir . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchFactory.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchHelper' => $baseDir . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchHelper.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchHelper' => $baseDir . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchHelper.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\Html' => $baseDir . '/sources/application/UI/Base/Component/Html/Html.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\Html' => $baseDir . '/sources/application/UI/Base/Component/Html/Html.php',
|
||||||
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\HtmlFactory' => $baseDir . '/sources/application/UI/Base/Component/Html/HtmlFactory.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\AbstractInput' => $baseDir . '/sources/application/UI/Base/Component/Input/AbstractInput.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\AbstractInput' => $baseDir . '/sources/application/UI/Base/Component/Input/AbstractInput.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\Input' => $baseDir . '/sources/application/UI/Base/Component/Input/Input.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\Input' => $baseDir . '/sources/application/UI/Base/Component/Input/Input.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory' => $baseDir . '/sources/application/UI/Base/Component/Input/InputFactory.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory' => $baseDir . '/sources/application/UI/Base/Component/Input/InputFactory.php',
|
||||||
|
|||||||
@@ -409,6 +409,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
|
|||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchFactory.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchFactory.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchHelper' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchHelper.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\GlobalSearch\\GlobalSearchHelper' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/GlobalSearch/GlobalSearchHelper.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\Html' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Html/Html.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\Html' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Html/Html.php',
|
||||||
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Html\\HtmlFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Html/HtmlFactory.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\AbstractInput' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/AbstractInput.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\AbstractInput' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/AbstractInput.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\Input' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/Input.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\Input' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/Input.php',
|
||||||
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/InputFactory.php',
|
'Combodo\\iTop\\Application\\UI\\Base\\Component\\Input\\InputFactory' => __DIR__ . '/../..' . '/sources/application/UI/Base/Component/Input/InputFactory.php',
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use Combodo\iTop\Application\UI\Base\Component\CollapsibleSection\CollapsibleSec
|
|||||||
use Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSet;
|
use Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSet;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\Form\Form;
|
use Combodo\iTop\Application\UI\Base\Component\Form\Form;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
use Combodo\iTop\Application\UI\Base\Component\Html\Html;
|
||||||
|
use Combodo\iTop\Application\UI\Base\Component\Html\HtmlFactory;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\Input\InputFactory;
|
use Combodo\iTop\Application\UI\Base\Component\Input\InputFactory;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\Input\TextArea;
|
use Combodo\iTop\Application\UI\Base\Component\Input\TextArea;
|
||||||
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelFactory;
|
use Combodo\iTop\Application\UI\Base\Component\Panel\PanelFactory;
|
||||||
@@ -83,6 +84,8 @@ function ShowExamples($oP, $sExpression)
|
|||||||
$aDisplayData[Dict::S('UI:RunQuery:QueryExamples')][] = array(
|
$aDisplayData[Dict::S('UI:RunQuery:QueryExamples')][] = array(
|
||||||
'desc' => "<div style=\"$sHighlight\">".utils::EscapeHtml($sDescription)."</div>",
|
'desc' => "<div style=\"$sHighlight\">".utils::EscapeHtml($sDescription)."</div>",
|
||||||
'oql' => "<div style=\"$sHighlight\">".utils::EscapeHtml($sOql)."</div>",
|
'oql' => "<div style=\"$sHighlight\">".utils::EscapeHtml($sOql)."</div>",
|
||||||
|
//TODO 3.0.0 : buttons are not styled properly yet...
|
||||||
|
// This whole "query examples" may be migrated to TWIG using iTop Twig tags ?
|
||||||
'go' => "<form method=\"get\"><input type=\"hidden\" name=\"expression\" value=\"$sOql\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Test')."\" $sDisable>$sContext</form>\n",
|
'go' => "<form method=\"get\"><input type=\"hidden\" name=\"expression\" value=\"$sOql\"><input type=\"submit\" value=\"".Dict::S('UI:Button:Test')."\" $sDisable>$sContext</form>\n",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -301,6 +304,9 @@ EOF
|
|||||||
$oMoreInfoSection->EnableSaveCollapsibleState('run_query__more-info');
|
$oMoreInfoSection->EnableSaveCollapsibleState('run_query__more-info');
|
||||||
$oP->AddUiBlock($oMoreInfoSection);
|
$oP->AddUiBlock($oMoreInfoSection);
|
||||||
} elseif ($sSyntaxError) {
|
} elseif ($sSyntaxError) {
|
||||||
|
$oSyntaxErrorPanel = PanelFactory::MakeForFailure(Dict::S('UI:RunQuery:Error'));
|
||||||
|
$oP->AddUiBlock($oSyntaxErrorPanel);
|
||||||
|
|
||||||
if ($e instanceof OqlException) {
|
if ($e instanceof OqlException) {
|
||||||
$sWrongWord = $e->GetWrongWord();
|
$sWrongWord = $e->GetWrongWord();
|
||||||
$aSuggestedWords = $e->GetSuggestions();
|
$aSuggestedWords = $e->GetSuggestions();
|
||||||
@@ -313,27 +319,27 @@ EOF
|
|||||||
$sAfter = substr($sExpression, $e->GetColumn() + strlen($sWrongWord));
|
$sAfter = substr($sExpression, $e->GetColumn() + strlen($sWrongWord));
|
||||||
$sFixedExpression = $sBefore.$sSuggestedWord.$sAfter;
|
$sFixedExpression = $sBefore.$sSuggestedWord.$sAfter;
|
||||||
$sFixedExpressionHtml = $sBefore.'<span style="background-color:yellow">'.$sSuggestedWord.'</span>'.$sAfter;
|
$sFixedExpressionHtml = $sBefore.'<span style="background-color:yellow">'.$sSuggestedWord.'</span>'.$sAfter;
|
||||||
$sSyntaxErrorText .= $oP->GetP("Suggesting: $sFixedExpressionHtml");
|
$sSyntaxErrorText .= "<p>Suggesting: $sFixedExpressionHtml</p>";
|
||||||
$sEscapedExpression = utils::EscapeHtml(addslashes($sFixedExpression));
|
$oSyntaxErrorPanel->AddSubBlock(new Html($sSyntaxErrorText));
|
||||||
$sSyntaxErrorText .= $oP->GetP(<<<HTML
|
|
||||||
<button onClick="$('textarea[name=expression]')
|
|
||||||
.val('$sEscapedExpression')
|
|
||||||
.focus();">Use this query</button>
|
|
||||||
HTML
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$sSyntaxErrorText = $oP->GetP($e->getHtmlDesc());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$sSyntaxErrorText = $oP->GetP($e->getHtmlDesc());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$sSyntaxErrorText = $oP->GetP($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$oSyntaxErrorPanel = AlertFactory::MakeForFailure(Dict::S('UI:RunQuery:Error'), $sSyntaxErrorText);
|
$sEscapedExpression = utils::EscapeHtml(addslashes($sFixedExpression));
|
||||||
$oSyntaxErrorPanel->SetOpenedByDefault(true);
|
$oUseSuggestedQueryButton = ButtonFactory::MakeForDestructiveAction('Use this query');
|
||||||
$oP->AddUiBlock($oSyntaxErrorPanel);
|
$oUseSuggestedQueryButton->SetOnClickJsCode(<<<JS
|
||||||
|
let \$oQueryTextarea = $('textarea[name=expression]');
|
||||||
|
\$oQueryTextarea.val('$sEscapedExpression').focus();
|
||||||
|
\$oQueryTextarea.closest('form').submit();
|
||||||
|
JS
|
||||||
|
);
|
||||||
|
$oSyntaxErrorPanel->AddSubBlock($oUseSuggestedQueryButton);
|
||||||
|
} else {
|
||||||
|
$oSyntaxErrorPanel->AddSubBlock(HtmlFactory::MakeP($e->getHtmlDesc()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$oSyntaxErrorPanel->AddSubBlock(HtmlFactory::MakeP($e->getHtmlDesc()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$oSyntaxErrorPanel->AddSubBlock(HtmlFactory::MakeP($e->getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
|
|||||||
33
sources/application/UI/Base/Component/Html/HtmlFactory.php
Normal file
33
sources/application/UI/Base/Component/Html/HtmlFactory.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?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\Base\Component\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Combodo\iTop\Application\UI\Base\Component\Html
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
class HtmlFactory
|
||||||
|
{
|
||||||
|
public static function MakeP(string $sContent): Html
|
||||||
|
{
|
||||||
|
return new Html('<p>'.$sContent.'</p>');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user