mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement separated entities for auth pop-up
This commit is contained in:
parent
51e62ece26
commit
1d81089d87
3 changed files with 182 additions and 91 deletions
|
|
@ -7,7 +7,6 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Page;
|
||||||
use \Exception;
|
use \Exception;
|
||||||
use \GtkButtonsType;
|
use \GtkButtonsType;
|
||||||
use \GtkDialogFlags;
|
use \GtkDialogFlags;
|
||||||
use \GtkEntry;
|
|
||||||
use \GtkLabel;
|
use \GtkLabel;
|
||||||
use \GtkMessageDialog;
|
use \GtkMessageDialog;
|
||||||
use \GtkMessageType;
|
use \GtkMessageType;
|
||||||
|
|
@ -33,47 +32,17 @@ class Auth
|
||||||
public const DIALOG_FORMAT_SECONDARY_TEXT = 'Select identity';
|
public const DIALOG_FORMAT_SECONDARY_TEXT = 'Select identity';
|
||||||
public const DIALOG_MESSAGE_FORMAT = 'Authorization';
|
public const DIALOG_MESSAGE_FORMAT = 'Authorization';
|
||||||
public const DIALOG_CONTENT_OPTION_LABEL_CREATE = 'Create new for this resource';
|
public const DIALOG_CONTENT_OPTION_LABEL_CREATE = 'Create new for this resource';
|
||||||
public const DIALOG_CONTENT_OPTION_LABEL_IDENTITY_NAME = '#%d (%s)';
|
|
||||||
public const DIALOG_CONTENT_OPTION_LABEL_IDENTITY_NAME_DEFAULT = '#%d (no name)';
|
|
||||||
public const DIALOG_CONTENT_OPTION_MARGIN = 8;
|
public const DIALOG_CONTENT_OPTION_MARGIN = 8;
|
||||||
public const DIALOG_CONTENT_SPACING = 1;
|
public const DIALOG_CONTENT_SPACING = 1;
|
||||||
|
|
||||||
public const DIALOG_CONTENT_OPTION_NAME_ALIGNMENT = 0.5;
|
|
||||||
public const DIALOG_CONTENT_OPTION_NAME_MARGIN = 12;
|
|
||||||
public const DIALOG_CONTENT_OPTION_NAME_PLACEHOLDER = 'Local name (optional)';
|
|
||||||
|
|
||||||
// Extras
|
// Extras
|
||||||
private array $_options = []; // GtkRadioButton
|
private array $_options = []; // GtkRadioButton
|
||||||
private GtkEntry $_name;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Page $page
|
Page $page
|
||||||
) {
|
) {
|
||||||
// Init dependencies
|
// Init dependencies
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
|
|
||||||
// Init extras
|
|
||||||
$this->_name = new GtkEntry;
|
|
||||||
|
|
||||||
$this->_name->set_alignment(
|
|
||||||
$this::DIALOG_CONTENT_OPTION_NAME_ALIGNMENT
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->_name->set_placeholder_text(
|
|
||||||
_($this::DIALOG_CONTENT_OPTION_NAME_PLACEHOLDER)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->_name->set_margin_start(
|
|
||||||
$this::DIALOG_CONTENT_OPTION_NAME_MARGIN
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->_name->set_margin_end(
|
|
||||||
$this::DIALOG_CONTENT_OPTION_NAME_MARGIN
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->_name->set_margin_bottom(
|
|
||||||
$this::DIALOG_CONTENT_OPTION_NAME_MARGIN
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dialog(): bool
|
public function dialog(): bool
|
||||||
|
|
@ -103,14 +72,18 @@ class Auth
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init new certificate option
|
// Init new certificate option
|
||||||
$this->_options[0] = $this->_option(
|
$this->_options[0] = new Auth\Option\Identity(
|
||||||
_($this::DIALOG_CONTENT_OPTION_LABEL_CREATE)
|
$this
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_options[0]->join_group(
|
$this->_options[0]->setGroup(
|
||||||
$this->_options[0]
|
$this->_options[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->_options[0]->setLabel(
|
||||||
|
0, _($this::DIALOG_CONTENT_OPTION_LABEL_CREATE)
|
||||||
|
);
|
||||||
|
|
||||||
// Search database for auth records
|
// Search database for auth records
|
||||||
foreach ($this->page->container->browser->database->auth->like(
|
foreach ($this->page->container->browser->database->auth->like(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
|
@ -122,20 +95,18 @@ class Auth
|
||||||
// Get related identity records
|
// Get related identity records
|
||||||
if ($identity = $this->page->container->browser->database->identity->get($auth->identity))
|
if ($identity = $this->page->container->browser->database->identity->get($auth->identity))
|
||||||
{
|
{
|
||||||
$this->_options[$identity->id] = $this->_option(
|
$this->_options[$identity->id] = new Auth\Option\Identity(
|
||||||
$identity->name ? sprintf(
|
$this
|
||||||
_($this::DIALOG_CONTENT_OPTION_LABEL_IDENTITY_NAME),
|
|
||||||
$identity->id,
|
|
||||||
$identity->name
|
|
||||||
) : sprintf(
|
|
||||||
_($this::DIALOG_CONTENT_OPTION_LABEL_IDENTITY_NAME_DEFAULT),
|
|
||||||
$identity->id
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_options[$identity->id]->join_group(
|
$this->_options[$identity->id]->setGroup(
|
||||||
$this->_options[0]
|
$this->_options[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->_options[$identity->id]->setLabel(
|
||||||
|
$identity->id,
|
||||||
|
$identity->name
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,15 +122,15 @@ class Auth
|
||||||
{
|
{
|
||||||
// Append option
|
// Append option
|
||||||
$content->add(
|
$content->add(
|
||||||
$option
|
$option->gtk
|
||||||
);
|
);
|
||||||
|
|
||||||
// Is new
|
// Is new and option has name entity
|
||||||
if (!$id)
|
if (!$id && !is_null($option->name))
|
||||||
{
|
{
|
||||||
// Append name entry after new identity option
|
// Append name entry after new identity option
|
||||||
$content->add(
|
$content->add(
|
||||||
$this->_name,
|
$option->name,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
0
|
0
|
||||||
|
|
@ -173,7 +144,7 @@ class Auth
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set margin
|
// Set margin
|
||||||
$option->set_margin_bottom(
|
$option->gtk->set_margin_bottom(
|
||||||
self::DIALOG_CONTENT_OPTION_MARGIN
|
self::DIALOG_CONTENT_OPTION_MARGIN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +164,7 @@ class Auth
|
||||||
// Find active option
|
// Find active option
|
||||||
foreach ($this->_options as $id => $option)
|
foreach ($this->_options as $id => $option)
|
||||||
{
|
{
|
||||||
if ($option->get_active())
|
if ($option->gtk->get_active())
|
||||||
{
|
{
|
||||||
// Auth
|
// Auth
|
||||||
if ($id)
|
if ($id)
|
||||||
|
|
@ -249,50 +220,21 @@ class Auth
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _option(
|
public function refresh(): void
|
||||||
string $label,
|
|
||||||
int $margin = self::DIALOG_CONTENT_OPTION_MARGIN
|
|
||||||
): GtkRadioButton
|
|
||||||
{
|
|
||||||
$option = new GtkRadioButton;
|
|
||||||
|
|
||||||
$option->set_label(
|
|
||||||
$label
|
|
||||||
);
|
|
||||||
|
|
||||||
$option->set_margin_top(
|
|
||||||
$margin
|
|
||||||
);
|
|
||||||
|
|
||||||
$option->set_margin_start(
|
|
||||||
$margin
|
|
||||||
);
|
|
||||||
|
|
||||||
$option->set_margin_end(
|
|
||||||
$margin
|
|
||||||
);
|
|
||||||
|
|
||||||
$option->connect(
|
|
||||||
'toggled',
|
|
||||||
function(): void
|
|
||||||
{
|
{
|
||||||
// Detect active option
|
// Detect active option
|
||||||
foreach ($this->_options as $id => $option)
|
foreach ($this->_options as $id => $option)
|
||||||
{
|
{
|
||||||
// Is new
|
// Is new and option has name entity
|
||||||
if (!$id)
|
if (!$id && !is_null($option->name))
|
||||||
{
|
{
|
||||||
// Update sensibility
|
// Update sensibility
|
||||||
$this->_name->set_sensitive(
|
$option->name->gtk->set_sensitive(
|
||||||
$option->get_active()
|
$option->gtk->get_active()
|
||||||
);
|
);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
return $option;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
96
src/Entity/Browser/Container/Page/Auth/Option/Identity.php
Normal file
96
src/Entity/Browser/Container/Page/Auth/Option/Identity.php
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Auth\Option;
|
||||||
|
|
||||||
|
use \GtkRadioButton;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Entity\Browser\Container\Page\Auth;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Model\Identity\Gemini;
|
||||||
|
|
||||||
|
class Identity
|
||||||
|
{
|
||||||
|
// GTK
|
||||||
|
public GtkRadioButton $gtk;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public Auth $auth;
|
||||||
|
|
||||||
|
// Requirements
|
||||||
|
public ?Identity\Name $name = null;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
public const MARGIN = 12;
|
||||||
|
public const LABEL_DEFAULT = '#%d (%s)';
|
||||||
|
public const LABEL_NO_NAME = '#%d (no name)';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Auth $auth
|
||||||
|
) {
|
||||||
|
// Init dependencies
|
||||||
|
$this->auth = $auth;
|
||||||
|
|
||||||
|
// Init GTK
|
||||||
|
$this->gtk = new GtkRadioButton;
|
||||||
|
|
||||||
|
$this->gtk->set_margin_top(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_start(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->set_margin_end(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->show();
|
||||||
|
|
||||||
|
// Connect events
|
||||||
|
$this->gtk->connect(
|
||||||
|
'toggled',
|
||||||
|
function(): void
|
||||||
|
{
|
||||||
|
$this->auth->refresh();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGroup(
|
||||||
|
Identity $identity
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->gtk->join_group(
|
||||||
|
$identity->gtk
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(
|
||||||
|
int $id,
|
||||||
|
?string $label = null
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->gtk->set_label(
|
||||||
|
$label ? sprintf(
|
||||||
|
$this::LABEL_DEFAULT,
|
||||||
|
$id,
|
||||||
|
$label
|
||||||
|
) : sprintf(
|
||||||
|
$this::LABEL_NO_NAME,
|
||||||
|
$id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(
|
||||||
|
string $label
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->name = new Identity\Name(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Auth\Option\Identity;
|
||||||
|
|
||||||
|
use \GtkEntry;
|
||||||
|
|
||||||
|
class Name
|
||||||
|
{
|
||||||
|
// GTK
|
||||||
|
public GtkEntry $gtk;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
public Identity $identity;
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
public const ALIGNMENT = 0.5;
|
||||||
|
public const MARGIN = 8;
|
||||||
|
public const PLACEHOLDER = 'Local name (optional)';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
Identity $identity
|
||||||
|
) {
|
||||||
|
// Init dependencies
|
||||||
|
$this->identity = $identity;
|
||||||
|
|
||||||
|
// Init GTK
|
||||||
|
$this->gtk = new GtkEntry;
|
||||||
|
|
||||||
|
$this->_name->set_alignment(
|
||||||
|
$this::ALIGNMENT
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_name->set_placeholder_text(
|
||||||
|
_($this::PLACEHOLDER)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_name->set_margin_start(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_name->set_margin_end(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->_name->set_margin_bottom(
|
||||||
|
$this::MARGIN
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue