From bcae71155ebcb3b75c335032fc895af193b66913 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 23 Nov 2015 19:55:49 +0100 Subject: [PATCH] add backend theme AdminLte, bind reception/transaction to a permission --- backend/components/AdminMenuStructure.php | 16 +- backend/components/LTEAdminMenu.php | 78 ++++++ backend/controllers/SiteController.php | 4 + backend/controllers/UserController.php | 42 +++- backend/models/RoleForm.php | 46 ++++ backend/views/layouts-orig/main.php | 79 ++++++ backend/views/layouts/content.php | 26 ++ backend/views/layouts/header.php | 69 ++++++ backend/views/layouts/left.php | 20 ++ backend/views/layouts/main-login.php | 29 +++ backend/views/layouts/main.php | 124 +++++----- backend/views/site/error.php | 46 ++-- backend/views/site/index.php | 7 +- backend/views/site/login.php | 74 ++++-- backend/views/site_orig/error.php | 27 ++ backend/views/site_orig/index.php | 17 ++ backend/views/site_orig/login.php | 35 +++ backend/views/user/role.php | 72 ++++++ common/models/Account.php | 4 +- common/models/LoginForm.php | 18 +- common/models/User.php | 2 + composer.json | 3 +- composer.lock | 230 +++++++++++++++++- ...500_add_permission_reception_transfers.php | 29 +++ frontend/components/FrontendMenuStructure.php | 24 +- 25 files changed, 993 insertions(+), 128 deletions(-) create mode 100644 backend/components/LTEAdminMenu.php create mode 100644 backend/models/RoleForm.php create mode 100644 backend/views/layouts-orig/main.php create mode 100644 backend/views/layouts/content.php create mode 100644 backend/views/layouts/header.php create mode 100644 backend/views/layouts/left.php create mode 100644 backend/views/layouts/main-login.php create mode 100644 backend/views/site_orig/error.php create mode 100644 backend/views/site_orig/index.php create mode 100644 backend/views/site_orig/login.php create mode 100644 backend/views/user/role.php create mode 100644 console/migrations/m151123_172500_add_permission_reception_transfers.php diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 68ff846..5976176 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -8,6 +8,7 @@ use yii\helpers\Html; class AdminMenuStructure{ public $menuItems; + public $emptyUrl = '#';//maybe null public function __construct(){ $this->menuItems = []; @@ -43,7 +44,8 @@ class AdminMenuStructure{ // Beállítások ///////////////////////////// $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']]; - $this->menuItems[] = ['label' => 'Beállítások', 'url' => null, + $items[] = ['label' => 'Jogosultságok', 'url' =>['/user/role']]; + $this->menuItems[] = ['label' => 'Beállítások', 'url' => $this->emptyUrl, 'items' => $items ]; @@ -57,7 +59,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ]; $items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ]; // $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; - $this->menuItems[] = ['label' => 'Törszadatok', 'url' => null, + $this->menuItems[] = ['label' => 'Törszadatok', 'url' =>$this->emptyUrl, 'items' => $items ]; @@ -65,10 +67,10 @@ class AdminMenuStructure{ // BÉRLETEK ///////////////////////////// $items = []; - $items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] ]; + $items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] , 'target_url' => ['/customer/index' ,'/customer/view','/ticket/index-customer'] ]; $items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ]; $items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ]; - $this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => null, + $this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => $this->emptyUrl, 'items' => $items ]; @@ -78,7 +80,7 @@ class AdminMenuStructure{ $items = []; $items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ]; $items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ]; - $this->menuItems[] = ['label' => 'Termékek', 'url' => null, + $this->menuItems[] = ['label' => 'Termékek', 'url' => $this->emptyUrl, 'items' => $items ]; ///////////////////////////// @@ -88,7 +90,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ]; $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; $items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; - $this->menuItems[] = ['label' => 'Pénzügy', 'url' => null, + $this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl, 'items' => $items ]; @@ -112,7 +114,7 @@ class AdminMenuStructure{ public function run(){ $this->addUserMainMenu(); - $this->addLoginMainMenu(); +// $this->addLoginMainMenu(); return $this->menuItems; } diff --git a/backend/components/LTEAdminMenu.php b/backend/components/LTEAdminMenu.php new file mode 100644 index 0000000..700cd08 --- /dev/null +++ b/backend/components/LTEAdminMenu.php @@ -0,0 +1,78 @@ +controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + $arrayRoute = explode('/', ltrim($route, '/')); + $arrayThisRoute = explode('/', $this->route); + if ($arrayRoute[0] !== $arrayThisRoute[0]) { + continue; + } + if (isset($arrayRoute[1]) && $arrayRoute[1] !== $arrayThisRoute[1]) { + continue; + } + if (isset($arrayRoute[2]) && $arrayRoute[2] !== $arrayThisRoute[2]) { + continue; + } + return true; + } + return false; + }else if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) { + $route = $item['url'][0]; + if ($route[0] !== '/' && Yii::$app->controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + $arrayRoute = explode('/', ltrim($route, '/')); + $arrayThisRoute = explode('/', $this->route); + if ($arrayRoute[0] !== $arrayThisRoute[0]) { + return false; + } + if (isset($arrayRoute[1]) && $arrayRoute[1] !== $arrayThisRoute[1]) { + return false; + } + if (isset($arrayRoute[2]) && $arrayRoute[2] !== $arrayThisRoute[2]) { + return false; + } +// unset($item['url']['#']); +// if (count($item['url']) > 1) { +// foreach (array_splice($item['url'], 1) as $name => $value) { +// if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) { +// return false; +// } +// } +// } + return true; + } + return false; + } + + } + + +?> \ No newline at end of file diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index 52a7eac..73bd4ec 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -66,6 +66,10 @@ class SiteController extends Controller } $model = new LoginForm(); + $model->roles = [ + 'admin', + 'employee' + ]; if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { diff --git a/backend/controllers/UserController.php b/backend/controllers/UserController.php index 6a41097..60c42f4 100644 --- a/backend/controllers/UserController.php +++ b/backend/controllers/UserController.php @@ -30,9 +30,9 @@ class UserController extends \backend\controllers\BackendController 'rules' => [ // allow authenticated users [ - 'actions' => [ 'index','view' ], + 'actions' => [ 'index','view' ,'role'], 'allow' => true, - 'roles' => ['employee','admin','reception'], + 'roles' => ['employee','admin' ], ], // allow authenticated users [ @@ -176,6 +176,44 @@ class UserController extends \backend\controllers\BackendController return $this->redirect(['index']); } + + /** + * Creates a new User model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionRole() + { + $model = new \backend\models\RoleForm(); + + $model->availablePermissions = [ + [ + 'name' => "reception.transfers", + 'description' => 'Tranzakciók' + ] + ]; + + + + + if ($model->load(Yii::$app->request->post()) ) { + if ( $model->validate() && $model->save()){ + Yii::$app->session->setFlash('success', 'Jogosultságok elmentve'); + return $this->redirect(['role' ]); + } + }else{ + $am = Yii::$app->authManager; + $children = $am->getChildren(User::ROLE_RECEPTION); + $model->permissions = []; + foreach ($children as $child){ + $model->permissions[] = $child->name; + } + } + + return $this->render('role', [ + 'model' => $model, + ]); + } /** * Finds the User model based on its primary key value. diff --git a/backend/models/RoleForm.php b/backend/models/RoleForm.php new file mode 100644 index 0000000..40f555b --- /dev/null +++ b/backend/models/RoleForm.php @@ -0,0 +1,46 @@ +$attribute)) { + echo "invalid arr"; + $this->addError($attribute, 'Invalid array'); + } + } + ], + ]; + } + + public function save(){ + $am = \Yii::$app->authManager; + //remove all reception permission + $receptionItem = $am->getRole(User::ROLE_RECEPTION); + $am->removeChildren($receptionItem); + + if ( isset($receptionItem)){ + foreach ($this->permissions as $permissionName){ + $permission = $am->getPermission($permissionName); + if ( isset( $permission )){ + $am->addChild($receptionItem, $permission); + } + } + } + return true; + } + +} \ No newline at end of file diff --git a/backend/views/layouts-orig/main.php b/backend/views/layouts-orig/main.php new file mode 100644 index 0000000..88466f6 --- /dev/null +++ b/backend/views/layouts-orig/main.php @@ -0,0 +1,79 @@ +run(); +?> +beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + + + head() ?> + + + +beginBody() ?> + +
+ 'Botond Fitness WebAdmin', + 'brandUrl' => Yii::$app->homeUrl, + 'options' => [ + 'class' => 'navbar-inverse navbar-fixed-top', + ], + ]); + echo Nav::widget([ + 'options' => ['class' => 'navbar-nav navbar-right'], + 'items' => $items, + ]); + NavBar::end(); + ?> + +
+ isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], + ]) ?> + + true, + 'type' => AlertBlock::TYPE_GROWL, + 'delay' => '1' + ]); + ?> + +
+
+ + + +endBody() ?> + + +endPage() ?> diff --git a/backend/views/layouts/content.php b/backend/views/layouts/content.php new file mode 100644 index 0000000..d38d50d --- /dev/null +++ b/backend/views/layouts/content.php @@ -0,0 +1,26 @@ + +
+
+ + isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], + ] + ) ?> +
+ +
+ + +
+
+ + + diff --git a/backend/views/layouts/header.php b/backend/views/layouts/header.php new file mode 100644 index 0000000..969b2c3 --- /dev/null +++ b/backend/views/layouts/header.php @@ -0,0 +1,69 @@ + + +
+ + AFitness Admin', Yii::$app->homeUrl, ['class' => 'logo']) ?> + + +
diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php new file mode 100644 index 0000000..3546f98 --- /dev/null +++ b/backend/views/layouts/left.php @@ -0,0 +1,20 @@ + + +run(); + $items = $menu; + +?> + diff --git a/backend/views/layouts/main-login.php b/backend/views/layouts/main-login.php new file mode 100644 index 0000000..c6525db --- /dev/null +++ b/backend/views/layouts/main-login.php @@ -0,0 +1,29 @@ + +beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + head() ?> + + + +beginBody() ?> + + + +endBody() ?> + + +endPage() ?> diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php index b5af7e6..a0b545e 100644 --- a/backend/views/layouts/main.php +++ b/backend/views/layouts/main.php @@ -1,76 +1,74 @@ controller->action->id === 'login') { +/** + * Do not use this code in your template. Remove it. + * Instead, use the code $this->layout = '//main-login'; in your controller. + */ + echo $this->render( + 'main-login', + ['content' => $content] + ); +} else { -$adminMenu = new AdminMenuStructure(); -$items = $adminMenu->run(); -?> -beginPage() ?> - - - - - - - <?= Html::encode($this->title) ?> - head() ?> - - -beginBody() ?> + if (class_exists('backend\assets\AppAsset')) { + backend\assets\AppAsset::register($this); + } else { + app\assets\AppAsset::register($this); + } -
- 'Botond Fitness WebAdmin', - 'brandUrl' => Yii::$app->homeUrl, - 'options' => [ - 'class' => 'navbar-inverse navbar-fixed-top', - ], - ]); - echo Nav::widget([ - 'options' => ['class' => 'navbar-nav navbar-right'], - 'items' => $items, - ]); - NavBar::end(); + dmstr\web\AdminLteAsset::register($this); + + $directoryAsset = Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist'); ?> + beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + head() ?> + + + + beginBody() ?> +
-
- isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], - ]) ?> - - true, - 'type' => AlertBlock::TYPE_GROWL, - 'delay' => '1' - ]); + render( + 'header.php', + ['directoryAsset' => $directoryAsset] + ) ?> + + render( + 'left.php', + ['directoryAsset' => $directoryAsset] + ) ?> - + + render( + 'content.php', + ['content' => $content, 'directoryAsset' => $directoryAsset] + ) ?> +
-
-
-
-

© name ?> params['version'] ?> Fitness - WebAdmin

- -

-
-
- -endBody() ?> - - -endPage() ?> + endBody() ?> + + + endPage() ?> + diff --git a/backend/views/site/error.php b/backend/views/site/error.php index 0ba2574..fe51789 100644 --- a/backend/views/site/error.php +++ b/backend/views/site/error.php @@ -1,27 +1,45 @@ title = $name; ?> -
+ +
-

title) ?>

+
+

-
- +
+

+ +

+ +

+ +

+ The above error occurred while the Web server was processing your request. + Please contact us if you think this is a server error. Thank you. + Meanwhile, you may return to dashboard or try using the search + form. +

+ +
+
+ + +
+ +
+
+
+
-

- The above error occurred while the Web server was processing your request. -

-

- Please contact us if you think this is a server error. Thank you. -

- -
+
diff --git a/backend/views/site/index.php b/backend/views/site/index.php index 8b029ca..d2d663c 100644 --- a/backend/views/site/index.php +++ b/backend/views/site/index.php @@ -2,16 +2,11 @@ /* @var $this yii\web\View */ -$this->title = 'My Yii Application'; +$this->title = Yii::$app->name; ?>
-

Web Admin

-

Üdvözöljük adminisztrációs felületünkön

-
- -
diff --git a/backend/views/site/login.php b/backend/views/site/login.php index 29bffcd..cc236dc 100644 --- a/backend/views/site/login.php +++ b/backend/views/site/login.php @@ -1,35 +1,59 @@ title = 'Bejelentkezés'; -$this->title = Yii::t('common/site' , 'Login'); -$this->params['breadcrumbs'][] = $this->title; +$fieldOptions1 = [ + 'options' => ['class' => 'form-group has-feedback'], + 'inputTemplate' => "{input}" +]; + +$fieldOptions2 = [ + 'options' => ['class' => 'form-group has-feedback'], + 'inputTemplate' => "{input}" +]; ?> -