* refactor

* Add event AFTER_DISPLAY_PAGE
This commit is contained in:
Eric Espie
2021-12-31 11:06:03 +01:00
parent fba78e7d9b
commit 374b71c017
21 changed files with 144 additions and 94 deletions

View File

@@ -10,6 +10,8 @@ use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
class AjaxPage extends WebPage implements iTabbedPage
{
@@ -209,6 +211,7 @@ class AjaxPage extends WebPage implements iTabbedPage
// Echo global HTML
echo $sHtml;
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}

View File

@@ -15,6 +15,8 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* CLI page
@@ -37,6 +39,7 @@ class CLIPage implements Page
public function output()
{
$this->FireAfterDisplayEvent();
if (class_exists('DBSearch')) {
DBSearch::RecordQueryTrace();
}
@@ -45,6 +48,13 @@ class CLIPage implements Page
}
}
protected function FireAfterDisplayEvent()
{
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
$aData['object'] = $this;
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
}
public function add($sText)
{
echo $sText;

View File

@@ -15,6 +15,8 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* Simple web page with no includes or fancy formatting, useful to generateXML documents
@@ -52,6 +54,7 @@ class CSVPage extends WebPage
echo trim($this->s_content);
echo "\n";
$oKpi->ComputeAndReport('Echoing ('.round(strlen($this->s_content) / 1024).' Kb)');
$this->FireAfterDisplayEvent();
if (class_exists('DBSearch')) {
DBSearch::RecordQueryTrace();

View File

@@ -4,6 +4,9 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* Class DownloadPage
@@ -52,6 +55,7 @@ class DownloadPage extends AjaxPage
$oKpi->ComputeAndReport(get_class($this).' output');
echo $sContent;
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sContent) / 1024).' Kb)');
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}
}

View File

@@ -4,6 +4,9 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* Class JsonPage
*
@@ -99,6 +102,7 @@ class JsonPage extends WebPage
echo $sJSON;
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sJSON) / 1024).' Kb)');
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}

View File

@@ -18,6 +18,8 @@
*/
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
@@ -142,7 +144,6 @@ EOF
/**
* Generates the PDF document and returns the PDF content as a string
*
* @return string
* @see WebPage::output()
*/
public function output()
@@ -158,6 +159,7 @@ EOF
}
$this->flush();
echo $this->oPdf->Output($this->s_title.'.pdf', 'S');
$this->FireAfterDisplayEvent();
}
public function get_pdf()

View File

@@ -22,6 +22,8 @@ use Combodo\iTop\Application\Branding;
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
$sPortalBaseFolderRelPath = 'env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/';
$sPortalSourcesFolderRelPath = $sPortalBaseFolderRelPath . 'src/';
@@ -174,6 +176,8 @@ class UnauthenticatedWebPage extends NiceWebPage
$oKpi->ComputeAndReport(get_class($this).' output');
echo $sHtml;
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}
/**

View File

@@ -17,6 +17,8 @@ use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
@@ -1344,9 +1346,17 @@ JS;
if (class_exists('DBSearch')) {
DBSearch::RecordQueryTrace();
}
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}
protected function FireAfterDisplayEvent()
{
$aData['debug_info'] = 'from: '.get_class($this).":[$this->s_title]";
$aData['object'] = $this;
EventService::FireEvent(EventName::AFTER_DISPLAY_PAGE, get_class($this), $aData);
}
/**
* Build a series of hidden field[s] from an array
*

View File

@@ -23,6 +23,9 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* Simple web page with no includes or fancy formatting, useful to generateXML documents
* The page adds the content-type text/XML and the encoding into the headers
@@ -71,6 +74,7 @@ class XMLPage extends WebPage
if (class_exists('DBSearch')) {
DBSearch::RecordQueryTrace();
}
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
}

View File

@@ -22,6 +22,8 @@ use Combodo\iTop\Application\UI\Base\UIBlock;
use Combodo\iTop\Application\UI\Printable\BlockPrintHeader\BlockPrintHeader;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer;
use Combodo\iTop\Service\EventName;
use Combodo\iTop\Service\EventService;
/**
* Web page with some associated CSS and scripts (jquery) for a fancier display
@@ -950,6 +952,7 @@ HTML;
$oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)');
DBSearch::RecordQueryTrace();
$this->FireAfterDisplayEvent();
ExecutionKPI::ReportStats();
return;