From 08191f9f755f2b0cbdbc33b17e420ca62b8e3a72 Mon Sep 17 00:00:00 2001 From: Igor Veremsky Date: Wed, 31 Oct 2018 00:21:01 +0200 Subject: [PATCH 1/2] add set layout options feature --- README.md | 48 +++++++++++++++++--------------------- helpers/AdminLteHelper.php | 36 +++++++++++++++++++++++++++- web/AdminLteAsset.php | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index e870333..9705d69 100644 --- a/README.md +++ b/README.md @@ -181,39 +181,35 @@ Here is the list of available skins: "skin-green-light" ``` -#### Disabling skin file loading, when using bundled assets +### Layout - Yii::$container->set( - AdminLteAsset::className(), - [ - 'skin' => false, - ] - ); +By default the extension uses default layout for AdminLTE. You can change it in config file. -If you want to use native DOM of headers AdminLTE - -```html -

- About static page -

+```php +'components' => [ + 'assetManager' => [ + 'bundles' => [ + 'dmstr\web\AdminLteAsset' => [ + 'layout' => dmstr\helpers\AdminLteHelper::LAYOUT_OPTION_FIXED, + ], + ], + ], +], ``` -then you can follow the code: - -```php -/* @var $this yii\web\View */ +**Note:** Best way to set layout option is to use options constants from `AdminLteHelper`. -$this->params['breadcrumbs'][] = 'About'; +And then just add class specific for layout to body. You can use `AdminLteHelper::layoutHtmlClass()` if you want to get always correct html class and don't want to alter every view file when you change layout option. +```html + +``` -$this->beginBlock('content-header'); ?> -About static page -endBlock(); ?> +#### Template Examples -
-

This is the About page. You may modify the following file to customize its content:

- -
-``` +* [Fixed](https://adminlte.io/themes/AdminLTE/pages/layout/fixed.html) +* [Collapsed Sidebar](https://adminlte.io/themes/AdminLTE/pages/layout/collapsed-sidebar.html) +* [Boxed Layout](https://adminlte.io/themes/AdminLTE/pages/layout/boxed.html) +* [Top Navigation](https://adminlte.io/themes/AdminLTE/pages/layout/top-nav.html) ### Left sidebar menu - Widget Menu diff --git a/helpers/AdminLteHelper.php b/helpers/AdminLteHelper.php index f663295..65c710f 100644 --- a/helpers/AdminLteHelper.php +++ b/helpers/AdminLteHelper.php @@ -5,7 +5,12 @@ class AdminLteHelper { - /** + const LAYOUT_OPTION_FIXED = 'fixed'; + const LAYOUT_OPTION_COLLAPSED_SIDEBAR = 'sidebar-collapse'; + const LAYOUT_OPTION_BOXED_LAYOUT = 'boxed'; + const LAYOUT_OPTION_TOP_NAVIGATION = 'top-nav'; + + /** * It allows you to get the name of the css class. * You can add the appropriate class to the body tag for dynamic change the template's appearance. * Note: Use this fucntion only if you override the skin through configuration. @@ -20,4 +25,33 @@ public static function skinClass() return $bundle->skin; } + + /** + * It allows you to get the name of the layout wrapper html class. + * You can add the appropriate class to the body tag for dynamic change the template's appearance. + * + * @return string + */ + public static function layoutHtmlClass() + { + /** @var \dmstr\web\AdminLteAsset $bundle */ + $bundle = Yii::$app->assetManager->getBundle('dmstr\web\AdminLteAsset'); + + return ($layout = $bundle->layout) ? self::getLayoutHtmlClassOptions()[$layout] : ''; + } + + /** + * Get layout wrapper html classes options + * + * @return array + */ + public static function getLayoutHtmlClassOptions() + { + return [ + self::LAYOUT_OPTION_FIXED => 'fixed', + self::LAYOUT_OPTION_COLLAPSED_SIDEBAR => 'sidebar-collapse', + self::LAYOUT_OPTION_BOXED_LAYOUT => 'layout-boxed', + self::LAYOUT_OPTION_TOP_NAVIGATION => 'layout-top-nav', + ]; + } } diff --git a/web/AdminLteAsset.php b/web/AdminLteAsset.php index 0173beb..5677408 100644 --- a/web/AdminLteAsset.php +++ b/web/AdminLteAsset.php @@ -1,7 +1,9 @@ css[] = sprintf('css/skins/%s.min.css', $this->skin); } + // Append layout options + if ($layout = $this->layout) { + if (!array_key_exists($layout, AdminLteHelper::getLayoutHtmlClassOptions())) { + throw new InvalidConfigException('Invalid layout specified'); + } + + $layoutExtraAssetsOptions = self::getLayoutExtraAssetsOptions(); + if (array_key_exists($layout, $layoutExtraAssetsOptions)) { + if (isset($layoutExtraAssetsOptions[$layout]['js'])) { + array_merge($this->js, $layoutExtraAssetsOptions[$layout]['js']); + } + if (isset($layoutExtraAssetsOptions[$layout]['css'])) { + array_merge($this->css, $layoutExtraAssetsOptions[$layout]['css']); + } + } + } + parent::init(); } + + /** + * Get extra scripts and styles options needed to specific layout + * + * @return array + */ + public static function getLayoutExtraAssetsOptions() + { + return [ + AdminLteHelper::LAYOUT_OPTION_FIXED => [ + 'js' => [ + '../bower_components/jquery-slimscroll/jquery.slimscroll.min.js' + ] + ], + ]; + } } From 864db422121be3d2269a41073e852894e31d997b Mon Sep 17 00:00:00 2001 From: Igor Veremsky Date: Wed, 31 Oct 2018 00:59:36 +0200 Subject: [PATCH 2/2] add layout option assets depends feature --- web/AdminLteAsset.php | 11 +++++++---- web/AdminLteFixedLayoutAsset.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 web/AdminLteFixedLayoutAsset.php diff --git a/web/AdminLteAsset.php b/web/AdminLteAsset.php index 5677408..85455e2 100644 --- a/web/AdminLteAsset.php +++ b/web/AdminLteAsset.php @@ -66,10 +66,13 @@ public function init() $layoutExtraAssetsOptions = self::getLayoutExtraAssetsOptions(); if (array_key_exists($layout, $layoutExtraAssetsOptions)) { if (isset($layoutExtraAssetsOptions[$layout]['js'])) { - array_merge($this->js, $layoutExtraAssetsOptions[$layout]['js']); + $this->js = array_merge($this->js, $layoutExtraAssetsOptions[$layout]['js']); } if (isset($layoutExtraAssetsOptions[$layout]['css'])) { - array_merge($this->css, $layoutExtraAssetsOptions[$layout]['css']); + $this->css = array_merge($this->css, $layoutExtraAssetsOptions[$layout]['css']); + } + if (isset($layoutExtraAssetsOptions[$layout]['depends'])) { + $this->depends = array_merge($this->depends, $layoutExtraAssetsOptions[$layout]['depends']); } } } @@ -86,8 +89,8 @@ public static function getLayoutExtraAssetsOptions() { return [ AdminLteHelper::LAYOUT_OPTION_FIXED => [ - 'js' => [ - '../bower_components/jquery-slimscroll/jquery.slimscroll.min.js' + 'depends' => [ + AdminLteFixedLayoutAsset::class ] ], ]; diff --git a/web/AdminLteFixedLayoutAsset.php b/web/AdminLteFixedLayoutAsset.php new file mode 100644 index 0000000..479cd17 --- /dev/null +++ b/web/AdminLteFixedLayoutAsset.php @@ -0,0 +1,17 @@ +