mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
implement response form (code 10)
This commit is contained in:
parent
4b296f309c
commit
5fda126ea9
5 changed files with 243 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab;
|
||||||
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title;
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title;
|
||||||
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar;
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar;
|
||||||
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content;
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content;
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response;
|
||||||
|
|
||||||
class Page
|
class Page
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +20,7 @@ class Page
|
||||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title;
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title;
|
||||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar;
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar;
|
||||||
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content;
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content;
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\Yggverse\Yoda\Entity\Browser\Container\Tab $tab
|
\Yggverse\Yoda\Entity\Browser\Container\Tab $tab
|
||||||
|
|
@ -54,6 +56,15 @@ class Page
|
||||||
$this->content->gtk
|
$this->content->gtk
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Init response bar
|
||||||
|
$this->response = new Response(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->pack_end(
|
||||||
|
$this->response->gtk
|
||||||
|
);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
$this->gtk->show_all();
|
$this->gtk->show_all();
|
||||||
}
|
}
|
||||||
|
|
@ -64,14 +75,26 @@ class Page
|
||||||
$this->content->refresh();
|
$this->content->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(
|
public function open(
|
||||||
|
?string $request = null,
|
||||||
bool $history = true
|
bool $history = true
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
// @TODO navbar
|
$this->navbar->request->setValue(
|
||||||
|
$request
|
||||||
|
);
|
||||||
|
|
||||||
$this->content->update(
|
$this->content->update(
|
||||||
$history
|
$history
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(
|
||||||
|
bool $history = true
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->content->update(
|
||||||
|
$history
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -185,6 +185,22 @@ class Content
|
||||||
// Process codes
|
// Process codes
|
||||||
switch ($response->getCode())
|
switch ($response->getCode())
|
||||||
{
|
{
|
||||||
|
case 10: // response expected
|
||||||
|
|
||||||
|
$this->page->title->setValue(
|
||||||
|
$address->getHost(),
|
||||||
|
sprintf(
|
||||||
|
'response expected (code %d)',
|
||||||
|
intval(
|
||||||
|
$response->getCode()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->page->response->show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 20: // ok
|
case 20: // ok
|
||||||
|
|
||||||
// Process content type
|
// Process content type
|
||||||
|
|
|
||||||
121
src/Entity/Browser/Container/Tab/Page/Response.php
Normal file
121
src/Entity/Browser/Container/Tab/Page/Response.php
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query;
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send;
|
||||||
|
|
||||||
|
use \Yggverse\Net\Address;
|
||||||
|
|
||||||
|
class Response
|
||||||
|
{
|
||||||
|
public \GtkBox $gtk;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page;
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Query $query;
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response\Send $send;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
private int $_margin = 8;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page
|
||||||
|
) {
|
||||||
|
// Init dependencies
|
||||||
|
$this->page = $page;
|
||||||
|
|
||||||
|
// Init container
|
||||||
|
$this->gtk = new \GtkBox(
|
||||||
|
\GtkOrientation::HORIZONTAL
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_top(
|
||||||
|
$this->_margin
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_bottom(
|
||||||
|
$this->_margin
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_start(
|
||||||
|
$this->_margin
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_end(
|
||||||
|
$this->_margin
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_spacing(
|
||||||
|
$this->_margin
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init query field
|
||||||
|
$this->query = new Query(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->pack_start(
|
||||||
|
$this->query->gtk,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init send button
|
||||||
|
$this->send = new Send(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->add(
|
||||||
|
$this->send->gtk
|
||||||
|
);
|
||||||
|
|
||||||
|
// Hide widget by default
|
||||||
|
$this->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(): void
|
||||||
|
{
|
||||||
|
$this->gtk->show_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hide(): void
|
||||||
|
{
|
||||||
|
$this->gtk->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refresh()
|
||||||
|
{
|
||||||
|
$this->query->refresh();
|
||||||
|
$this->send->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send(): void
|
||||||
|
{
|
||||||
|
$address = new Address(
|
||||||
|
$this->page->navbar->request->getValue()
|
||||||
|
);
|
||||||
|
|
||||||
|
$address->setQuery(
|
||||||
|
urlencode(
|
||||||
|
trim(
|
||||||
|
strval(
|
||||||
|
$this->query->getValue()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->page->open(
|
||||||
|
$address->get(),
|
||||||
|
false // disable history recording
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/Entity/Browser/Container/Tab/Page/Response/Query.php
Normal file
43
src/Entity/Browser/Container/Tab/Page/Response/Query.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response;
|
||||||
|
|
||||||
|
class Query extends \Yggverse\Yoda\Abstract\Entity\Entry
|
||||||
|
{
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
protected string $_placeholder = 'Enter response...';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response
|
||||||
|
) {
|
||||||
|
// Use parent features
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// Init dependency
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _onActivate(
|
||||||
|
\GtkEntry $entry
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->response->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _onKeyRelease(
|
||||||
|
\GtkEntry $entry,
|
||||||
|
\GdkEvent $event
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->response->refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refresh(): void
|
||||||
|
{
|
||||||
|
// @TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/Entity/Browser/Container/Tab/Page/Response/Send.php
Normal file
38
src/Entity/Browser/Container/Tab/Page/Response/Send.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response;
|
||||||
|
|
||||||
|
class Send extends \Yggverse\Yoda\Abstract\Entity\Button
|
||||||
|
{
|
||||||
|
// Dependencies
|
||||||
|
public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
protected string $_label = 'Send';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
\Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Response $response
|
||||||
|
) {
|
||||||
|
// Use parent features
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// Init dependency
|
||||||
|
$this->response = $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _onCLick(
|
||||||
|
\GtkButton $entity
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->response->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refresh(): void
|
||||||
|
{
|
||||||
|
$this->gtk->set_sensitive(
|
||||||
|
!empty($this->response->query->getValue())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue