N°3524 Add keyboard shortcuts to global actions

This commit is contained in:
Stephen Abello
2021-03-17 10:56:18 +01:00
parent 8dd8f98b61
commit a8ede8b857
26 changed files with 345 additions and 33 deletions

View File

@@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\GlobalSearch;
use Combodo\iTop\Application\UI\Base\UIBlock;
use iKeyboardShortcut;
use MetaModel;
use utils;
@@ -32,7 +33,7 @@ use utils;
* @internal
* @since 3.0.0
*/
class GlobalSearch extends UIBlock
class GlobalSearch extends UIBlock implements iKeyboardShortcut
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-global-search';
@@ -172,4 +173,14 @@ class GlobalSearch extends UIBlock
{
return $this->iMaxHistoryResults;
}
public static function GetShortcutKeys(): array
{
return [['id' => 'ibo-open-global-search', 'label' => 'UI:Component:GlobalSearch:KeyboardShortcut:OpenDrawer', 'key' => 'g', 'event' => 'open_drawer']];
}
public static function GetShortcutTriggeredElementSelector(): string
{
return "[data-role='".static::BLOCK_CODE."']";
}
}

View File

@@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\QuickCreate;
use Combodo\iTop\Application\UI\Base\UIBlock;
use iKeyboardShortcut;
use MetaModel;
use UserRights;
use utils;
@@ -33,7 +34,7 @@ use utils;
* @internal
* @since 3.0.0
*/
class QuickCreate extends UIBlock
class QuickCreate extends UIBlock implements iKeyboardShortcut
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-quick-create';
@@ -201,4 +202,14 @@ class QuickCreate extends UIBlock
{
return $this->iMaxHistoryResults;
}
public static function GetShortcutKeys(): array
{
return [['id' => 'ibo-open-quick-create', 'label' => 'UI:Component:QuickCreate:KeyboardShortcut:OpenDrawer', 'key' => 'c', 'event' => 'open_drawer']];
}
public static function GetShortcutTriggeredElementSelector(): string
{
return "[data-role='".static::BLOCK_CODE."']";
}
}

View File

@@ -30,6 +30,7 @@ use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
use Combodo\iTop\Application\UI\Base\UIBlock;
use DBObjectSearch;
use Dict;
use iKeyboardShortcut;
use MetaModel;
use UIExtKeyWidget;
use UserRights;
@@ -43,7 +44,7 @@ use utils;
* @internal
* @since 3.0.0
*/
class NavigationMenu extends UIBlock
class NavigationMenu extends UIBlock implements iKeyboardShortcut
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-navigation-menu';
@@ -444,4 +445,14 @@ JS;
return $this;
}
public static function GetShortcutKeys(): array
{
return [['id' => 'ibo-open-menu-filter', 'label' => 'UI:Layout:NavigationMenu:KeyboardShortcut:FocusFilter', 'key'=> 'alt+m', 'event' => 'filter_shortcut']];
}
public static function GetShortcutTriggeredElementSelector(): string
{
return "[data-role='".static::BLOCK_CODE."']";
}
}

View File

@@ -11,13 +11,15 @@ use cmdbAbstractObject;
use Combodo\iTop\Application\UI\Base\Component\Panel\Panel;
use Combodo\iTop\Application\UI\Helper\UIHelper;
use DBObject;
use iKeyboardShortcut;
use MetaModel;
class ObjectDetails extends Panel
class ObjectDetails extends Panel implements iKeyboardShortcut
{
// Overloaded constants
public const BLOCK_CODE = 'ibo-object-details';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/layouts/object/object-details/layout';
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/layouts/object/object-details/layout';
/** @var string Class name of the object (eg. "UserRequest") */
protected $sClassName;
@@ -197,4 +199,17 @@ class ObjectDetails extends Panel
$this->sStatusColor = UIHelper::GetColorFromStatus($this->sClassName, $this->sStatusCode);
}
}
public static function GetShortcutKeys(): array
{
return [['id' => 'ibo-edit-object', 'label' => 'UI:Layout:ObjectDetails:KeyboardShortcut:EditObject', 'key' => 'e', 'event' => 'edit_object'],
['id' => 'ibo-delete-object', 'label' => 'UI:Layout:ObjectDetails:KeyboardShortcut:DeleteObject', 'key' => 'd', 'event' => 'delete_object'],
['id' => 'ibo-new-object', 'label' => 'UI:Layout:ObjectDetails:KeyboardShortcut:NewObject', 'key' => 'n', 'event' => 'new_object'],
['id' => 'ibo-save-object', 'label' => 'UI:Layout:ObjectDetails:KeyboardShortcut:SaveObject', 'key' => 's', 'event' => 'save_object']];
}
public static function GetShortcutTriggeredElementSelector(): string
{
return "[data-role='".static::BLOCK_CODE."']";
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @since 3.0.0
*/
interface iKeyboardShortcut
{
/**
* Return default keys combination to trigger shortcut element
* @return array
*/
public static function GetShortcutKeys(): array;
/**
* Element to be triggered when shortcut key combination is pressed
* @return string
*/
public static function GetShortcutTriggeredElementSelector(): string;
}

View File

@@ -81,7 +81,7 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->SetTopBarLayout(TopBarFactory::MakeStandard($this->GetBreadCrumbsNewEntry()));
utils::InitArchiveMode();
$this->m_aMessages = array();
$this->SetRootUrl(utils::GetAbsoluteUrlAppRoot());
$this->add_header("Content-type: text/html; charset=".self::PAGES_CHARSET);
@@ -134,6 +134,9 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.magnific-popup.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/moment-with-locales.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/showdown.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/mousetrap/mousetrap.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/mousetrap/mousetrap-record.min.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/pages/backoffice/keyboard-shortcuts.js');
$this->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/pages/backoffice/toolbox.js');
}
@@ -176,6 +179,16 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
$this->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/selectize.default.css');
}
/**
* @since 3.0.0
*/
protected function InitializeKeyboardShortcuts(): void
{
$aShortcuts = utils::GetKeyboardShortcutPref();
$sShortcuts = json_encode($aShortcuts);
$this->add_script("aKeyboardShortcuts = $sShortcuts;");
}
/**
*
*/
@@ -861,6 +874,8 @@ HTML;
// Components
// Note: For now all components are either included in the layouts above or put in page through the AddUiBlock() API, so there is no need to do anything more.
$this->InitializeKeyboardShortcuts();
// Variable content of the page
$aData['aPage'] = array_merge(
$aData['aPage'],