Skip to content

Commit

Permalink
Fix sidebar, terminal link
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-wdmg committed Jul 6, 2023
1 parent 5c5e209 commit 5005574
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function bootstrap($app)
$app->getUrlManager()->addRules(
[
'/admin' => 'admin/admin/index',
'/admin/<action:(index|modules|login|logout|restore|search|favourites|checkpoint|bugreport|info|error)>' => 'admin/admin/<action>',
'/admin/<action:(index|modules|login|logout|restore|search|favourites|terminal|checkpoint|bugreport|info|error)>' => 'admin/admin/<action>',

'<module:\w+>/<submodule:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<submodule>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
Expand All @@ -55,7 +55,7 @@ public function bootstrap($app)
$app->getUrlManager()->addRules(
[
'/admin' => 'admin/admin/index',
'/admin/<action:(index|modules|login|logout|restore|search|favourites|checkpoint|bugreport|info|error)>' => 'admin/admin/<action>',
'/admin/<action:(index|modules|login|logout|restore|search|favourites|terminal|checkpoint|bugreport|info|error)>' => 'admin/admin/<action>',
],
true
);
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

## 1.4.6 (2023-07-06)
* Fix sidebar, terminal link

## 1.4.5 (2023-06-28)
* Count fixed in sidebar menu

Expand Down
10 changes: 5 additions & 5 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Admin dashboard for Butterfly.CMS
*
* @category Module
* @version 1.4.5
* @version 1.4.6
* @author Alexsander Vyshnyvetskyy <[email protected]>
* @link https://github.com/wdmg/yii2-admin
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine
Expand Down Expand Up @@ -89,7 +89,7 @@ class Module extends BaseModule
/**
* @var string the module version
*/
private $version = "1.4.5";
private $version = "1.4.6";

/**
* @var integer, priority of initialization
Expand Down Expand Up @@ -153,9 +153,9 @@ class Module extends BaseModule
];

/**
* @var array of main menu items
* @var array of sidebar menu items
*/
private $menu = [
private $sidebarMenu = [
[
'label' => 'Dashboard',
'icon' => 'fa fa-fw fa-tachometer-alt',
Expand Down Expand Up @@ -419,7 +419,7 @@ public function getSupportModules()
*/
public function getMenuItems()
{
return ArrayHelper::merge((is_array($this->customSidebarMenu) ? $this->customSidebarMenu : []), $this->menu);
return ArrayHelper::merge((is_array($this->customSidebarMenu) ? $this->customSidebarMenu : []), $this->sidebarMenu);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ Use the `Module::dashboardNavItems()` method of the module to generate a navigat
?>

# Status and version [ready to use]
* v.1.4.6 - Fix sidebar, terminal link
* v.1.4.5 - Count fixed in sidebar menu
* v.1.4.4 - Add task and tickets counters
* v.1.4.3 - Add server date and time to dashboard UI
* v.1.4.2 - Fix add to favourites
* v.1.4.4 - Add task and tickets counters
36 changes: 21 additions & 15 deletions components/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,35 @@ public function getSidebarMenuItems()
// Check the presence of the module identifier among the available packages
foreach ($modules as $module) {
if ($menu['item'] == $module['module']) {
if($module = Yii::$app->getModule('admin/'. $module['module'], false)) {
if ($module = Yii::$app->getModule('admin/'. $module['module'], false)) {


// Call Module::dashboardNavItems() to get its native menu
$navitems = [];
$moduleNavitems = $module->dashboardNavItems();
if (ArrayHelper::isIndexed($moduleNavitems) && !ArrayHelper::isAssociative($moduleNavitems, true)) {
foreach ($moduleNavitems as $moduleNavitem) {
if (isset($moduleNavitem['label'])) {
$navitems[] = $moduleNavitem;
}
}
} else {
if (isset($moduleNavitems['label'])) {
$navitems[] = $moduleNavitems;
}
}

if (isset($moduleNavitems['items'])) {
$navitems['items'] = $moduleNavitems['items'];
} else {
if (ArrayHelper::isIndexed($moduleNavitems) && !ArrayHelper::isAssociative($moduleNavitems, true)) {
foreach ($moduleNavitems as $moduleNavitem) {
if (isset($moduleNavitem['label'])) {
$navitems[] = $moduleNavitem;
}
}
} else {
if (isset($moduleNavitems['label'])) {
$navitems[] = $moduleNavitems;
}
}
}

// Check if the received menu item contains a direct link
if (isset($navitems['url']))
$menu['url'] = $navitems['url'];

// Check if the received menu item contains sub-items
if ($navitems['items']) {
if (!empty($navitems['items'])) {
$menu['items'] = $navitems['items'];
}

Expand All @@ -154,8 +160,8 @@ public function getSidebarMenuItems()
}
}

// Check if the menu item has nested sub-items
if (isset($menu['items']) && is_array($menu['items'])) {
// Check if the menu item has nested sub-items
if (isset($menu['items']) && is_array($menu['items'])) {

// If the nested item is not represented by an array, then this is the module identifier,
// of the module in which you need to call Module::dashboardNavItems() to get its native menu
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["yii2", "yii2-admin", "dashboard", "wdmg"],
"type": "yii2-extension",
"license": "MIT",
"version": "1.4.5",
"version": "1.4.6",
"homepage": "https://github.com/wdmg/yii2-admin",
"support": {
"source": "https://github.com/wdmg/yii2-admin",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yii2-admin-assets",
"version": "1.4.5",
"version": "1.4.6",
"description": "Admin Module Assets",
"main": "gulpfile.js",
"scripts": {
Expand Down
25 changes: 20 additions & 5 deletions views/admin/modules/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
'format' => 'raw',
'contentOptions' => [
'style' => "word-break:break-all;"
]
],
'value' => function($data) {
return "<code>".var_export($data->require, true)."</code>";
}
],
[
'attribute' => 'type',
Expand All @@ -45,21 +48,30 @@
'format' => 'raw',
'contentOptions' => [
'style' => "word-break:break-all;"
]
],
'value' => function($data) {
return Html::a($data->homepage, $data->homepage, ['target' => "_blank"]);
}
],
[
'attribute' => 'support',
'format' => 'raw',
'contentOptions' => [
'style' => "word-break:break-all;"
]
],
'value' => function($data) {
return "<code>".var_export($data->support, true)."</code>";
}
],
[
'attribute' => 'authors',
'format' => 'raw',
'contentOptions' => [
'style' => "word-break:break-all;"
]
],
'value' => function($data) {
return "<code>".var_export($data->authors, true)."</code>";
}
],

'license:ntext',
Expand All @@ -81,7 +93,10 @@
'format' => 'raw',
'contentOptions' => [
'style' => "word-break:break-all;"
]
],
'value' => function($data) {
return "<code>".var_export($data->options, true)."</code>";
}
],

'status:ntext',
Expand Down
11 changes: 7 additions & 4 deletions views/layouts/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@
if (Yii::$app->getModule('admin/terminal', false))
$items[] = [
'label' => '<span class="fa fa-fw fa-terminal"></span> ' . Yii::t('app/modules/admin', 'Terminal'),
'url' => '#terminal'
'url' => '#terminal',
'linkOptions' => [
'data-route' => Url::to(['/admin/terminal/terminal'])
]
];

if (isset($this->params['favourites'])) {
Expand Down Expand Up @@ -517,13 +520,13 @@ function showTime() {
<?php
// Register dashboard terminal assets
if (Yii::$app->getModule('admin/terminal', false)) {
$url = Url::to(['/admin/terminal/index']);
$this->registerJs(<<< JS
$(function() {
$('body').delegate('a[href="#terminal"]', 'click', function(event) {
event.preventDefault();
let route = event.target.dataset.route;
$.get(
'$url',
route,
function (data) {
$('#terminalModal .modal-body').html($(data).remove('.modal-footer'));
if ($(data).find('.modal-footer').length > 0) {
Expand Down Expand Up @@ -578,7 +581,7 @@ function (data) {
</footer>

<?php
$url = Url::to(['admin/bugreport']);
$url = Url::to(['/admin/bugreport']);
$this->registerJs(<<< JS
$('body').delegate('a[href="#bugreport"]', 'click', function(event) {
event.preventDefault();
Expand Down

0 comments on commit 5005574

Please sign in to comment.