Skip to content

Commit

Permalink
The confirm command uses the dialog plugin to show the question.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed May 13, 2024
1 parent db866e5 commit 3c34c5c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/Di/Traits/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jaxon\Di\Traits;

use Jaxon\App\Config\ConfigManager;
use Jaxon\App\Dialog\Library\DialogLibraryManager;
use Jaxon\App\I18n\Translator;
use Jaxon\Di\Container;
use Jaxon\Plugin\Manager\PluginManager;
Expand All @@ -25,8 +26,8 @@ private function registerResponses()
{
// Global Response
$this->set(Response::class, function($di) {
return new Response($di->g(PluginManager::class),
$di->g(Psr17Factory::class), $di->g(ServerRequestInterface::class));
return new Response($di->g(Psr17Factory::class), $di->g(ServerRequestInterface::class),
$di->g(PluginManager::class), $di->g(DialogLibraryManager::class));
});
// Response Manager
$this->set(ResponseManager::class, function($di) {
Expand Down Expand Up @@ -62,8 +63,8 @@ public function getResponse(): ResponseInterface
*/
public function newResponse(): ResponseInterface
{
return new Response($this->g(PluginManager::class),
$this->g(Psr17Factory::class), $this->g(ServerRequestInterface::class));
return new Response($this->g(Psr17Factory::class), $this->g(ServerRequestInterface::class),
$this->g(PluginManager::class), $this->g(DialogLibraryManager::class));
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Jaxon\Response;

use Jaxon\App\Dialog\Library\DialogLibraryManager;
use Jaxon\Plugin\Manager\PluginManager;
use Jaxon\Plugin\Response\DataBag\DataBagContext;
use Jaxon\Plugin\Response\DataBag\DataBagPlugin;
Expand Down Expand Up @@ -49,6 +50,11 @@ class Response implements ResponseInterface
*/
protected $xPluginManager;

/**
* @var DialogLibraryManager
*/
protected $xDialogManager;

/**
* @var Psr17Factory
*/
Expand All @@ -62,15 +68,18 @@ class Response implements ResponseInterface
/**
* The constructor
*
* @param PluginManager $xPluginManager
* @param Psr17Factory $xPsr17Factory
* @param PsrRequestInterface $xRequest
* @param PluginManager $xPluginManager
* @param DialogLibraryManager $xDialogManager
*/
public function __construct(PluginManager $xPluginManager, Psr17Factory $xPsr17Factory, PsrRequestInterface $xRequest)
public function __construct(Psr17Factory $xPsr17Factory, PsrRequestInterface $xRequest,
PluginManager $xPluginManager, DialogLibraryManager $xDialogManager)
{
$this->xPluginManager = $xPluginManager;
$this->xPsr17Factory = $xPsr17Factory;
$this->xRequest = $xRequest;
$this->xPluginManager = $xPluginManager;
$this->xDialogManager = $xDialogManager;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Response/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ public function sleep(int $tenths): ResponseInterface;
* following this one, will be skipped.
*
* @param integer $nCommandCount The number of commands to skip upon cancel
* @param string $sMessage The message to display to the user
* @param string $sQuestion The question to ask to the user
* @param array $aArgs The arguments for the placeholders in the question
*
* @return ResponseInterface
*/
public function confirmCommands(int $nCommandCount, string $sMessage): ResponseInterface;
public function confirmCommands(int $nCommandCount, string $sMessage, array $aArgs = []): ResponseInterface;

/**
* Add a command to display an alert message to the user
Expand Down
10 changes: 6 additions & 4 deletions src/Response/Traits/ScriptTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ abstract protected function str($xData): string;
* following this one, will be skipped.
*
* @param integer $nCommandCount The number of commands to skip upon cancel
* @param string $sQuestion The message to display to the user
* @param string $sQuestion The question to ask to the user
* @param array $aArgs The arguments for the placeholders in the question
*
* @return ResponseInterface
*/
public function confirmCommands(int $nCommandCount, string $sQuestion): ResponseInterface
public function confirmCommands(int $nCommandCount, string $sQuestion, array $aArgs = []): ResponseInterface
{
return $this->addCommand('script.confirm', [
'count' => $nCommandCount,
'question' => $this->str($sQuestion),
'question' => $this->xDialogManager->confirm($this->str($sQuestion), $aArgs),
]);
}

Expand All @@ -82,7 +83,8 @@ public function call(string $sFunc): ResponseInterface
*/
public function alert(string $sMessage): ResponseInterface
{
return $this->addCommand('script.alert', ['message' => $this->str($sMessage)]);
$this->plugin('dialog')->info($this->str($sMessage));
return $this;
}

/**
Expand Down

0 comments on commit 3c34c5c

Please sign in to comment.