Commit ddcb88f4 authored by Tobias Munk's avatar Tobias Munk

Merge commit '59289d09' into feature/tests

parents a9f4db29 59289d09
...@@ -11,13 +11,7 @@ The preferred way to install this extension is through [composer](http://getcomp ...@@ -11,13 +11,7 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run Either run
``` ```
php composer.phar require --prefer-dist hrzg/yii2-widgets2-module "*" composer require hrzg/yii2-widgets2-module
```
or add
```
"hrzg/yii2-widgets2-module": "*"
``` ```
to the require section of your `composer.json` file. to the require section of your `composer.json` file.
...@@ -37,16 +31,75 @@ setup.sh ...@@ -37,16 +31,75 @@ setup.sh
``` ```
### Settings
`availablePhpClasses`
Usage Usage
----- -----
Once the extension is installed, simply use it in your code by : Once the extension is installed, simply use it in your code by :
### Twig ### Layout
Example with `yii2-prototype-module`
- [Yii 2.0 Twig extension](https://github.com/yiisoft/yii2-twig/tree/master/docs/guide) - [Yii 2.0 Twig extension](https://github.com/yiisoft/yii2-twig/tree/master/docs/guide)
- [Twig documentation](http://twig.sensiolabs.org/documentation)
``` ```
{{ use ('hrzg/widget/widgets') }} {{ use ('hrzg/widget/widgets') }}
{{ widget_container_widget({id: 'main'}) }} {{ widget_container_widget({id: 'header'}) }}
<div class="container">
{{ widget_container_widget({id: 'container'}) }}
</div>
``` ```
### Widget
Standard Twig widget `hrzg\widget\widgets\TwigTemplate`
### JSON
- [JSON schema editor](https://github.com/jdorn/json-editor)
### Widget example
#### Basic
```
{
"title": "Basic",
"type": "object",
"properties": {
"headline": {
"type": "string",
"default": "Avo vole tioma profitanto ts,"
},
"text_html": {
"type": "string",
"format": "html",
"default": "Ja sub kiam aliu, fo unt fora danke helpverbo, dev bv tele kibi piedpilko.",
"options": {
"wysiwyg": true
}
}
}
}
```
```
<h2>{{ headline }}</h2>
<p>{{ text_html }}</p>
```
:warning: Workaround required for editor asset.
```
<?php \franciscomaya\sceditor\SCEditorAsset::register($this) ?>
```
For more examples, please see the [docs](./docs)
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
"name": "hrzg/yii2-widgets2-module", "name": "hrzg/yii2-widgets2-module",
"description": "Yii 2.0 Framework Widget Manager", "description": "Yii 2.0 Framework Widget Manager",
"type": "yii2-extension", "type": "yii2-extension",
"keywords": ["yii2","extension"], "keywords": [
"yii2",
"extension"
],
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"authors": [ "authors": [
{ {
...@@ -13,6 +16,7 @@ ...@@ -13,6 +16,7 @@
"require": { "require": {
"yiisoft/yii2": "*", "yiisoft/yii2": "*",
"yiisoft/yii2-twig": "^2.0.4", "yiisoft/yii2-twig": "^2.0.4",
"dmstr/yii2-web": "*",
"beowulfenator/yii2-json-editor": "^1.1" "beowulfenator/yii2-json-editor": "^1.1"
}, },
"autoload": { "autoload": {
......
...@@ -10,7 +10,6 @@ class Module extends \yii\base\Module ...@@ -10,7 +10,6 @@ class Module extends \yii\base\Module
{ {
parent::init(); parent::init();
// custom initialization code goes here // custom initialization code goes here
} }
...@@ -18,6 +17,7 @@ class Module extends \yii\base\Module ...@@ -18,6 +17,7 @@ class Module extends \yii\base\Module
{ {
parent::beforeAction($action); parent::beforeAction($action);
\Yii::$app->controller->view->params['breadcrumbs'][] = ['label' => 'Widget', 'url' => ['/widgets']]; \Yii::$app->controller->view->params['breadcrumbs'][] = ['label' => 'Widget', 'url' => ['/widgets']];
return true; return true;
} }
} }
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace hrzg\widget\assets;
use yii\web\AssetBundle;
class WidgetAsset extends AssetBundle
{
public $sourcePath = __DIR__.'/web';
public $css = [
'widgets.less'
];
}
\ No newline at end of file
.hrzg-widget-widget-container {
min-height: 32px;
&:hover {
outline: 2px dashed #ccc;
}
.hrzg-widget-widget-controls {
opacity: 0.3;
position: absolute;
&:hover {
opacity: 1;
}
}
.hrzg-widget-container-controls {
opacity: 0.3;
&:hover {
opacity: 1;
}
}
.hrzg-widget-widget {
&:hover {
outline: 4px solid gray;
}
}
}
...@@ -9,8 +9,9 @@ class DefaultController extends Controller ...@@ -9,8 +9,9 @@ class DefaultController extends Controller
{ {
public function actionIndex() public function actionIndex()
{ {
$searchModel = new WidgetTemplate; $searchModel = new WidgetTemplate();
$dataProvider = $searchModel->search([]); $dataProvider = $searchModel->search([]);
return $this->render('index', ['templatesDataProvider' => $dataProvider]); return $this->render('index', ['templatesDataProvider' => $dataProvider]);
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2 * /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2.
*
* @package default
*/ */
namespace hrzg\widget\controllers\crud; namespace hrzg\widget\controllers\crud;
use hrzg\widget\models\crud\search\WidgetContent; use hrzg\widget\models\crud\search\WidgetContent;
...@@ -35,6 +31,7 @@ class WidgetController extends \hrzg\widget\controllers\crud\base\WidgetControll ...@@ -35,6 +31,7 @@ class WidgetController extends \hrzg\widget\controllers\crud\base\WidgetControll
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage(); $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg); $model->addError('_exception', $msg);
} }
return $this->render('create', ['model' => $model]); return $this->render('create', ['model' => $model]);
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2 * /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2.
*
* @package default
*/ */
namespace hrzg\widget\controllers\crud; namespace hrzg\widget\controllers\crud;
/** /**
...@@ -13,5 +9,4 @@ namespace hrzg\widget\controllers\crud; ...@@ -13,5 +9,4 @@ namespace hrzg\widget\controllers\crud;
*/ */
class WidgetTemplateController extends \hrzg\widget\controllers\crud\base\WidgetTemplateController class WidgetTemplateController extends \hrzg\widget\controllers\crud\base\WidgetTemplateController
{ {
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544 * /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544.
*
* @package default
*/ */
namespace hrzg\widget\controllers\crud\api; namespace hrzg\widget\controllers\crud\api;
/** /*
* This is the class for REST controller "WidgetController". * This is the class for REST controller "WidgetController".
*/ */
use yii\filters\AccessControl; use yii\filters\AccessControl;
...@@ -19,8 +15,8 @@ class WidgetController extends \yii\rest\ActiveController ...@@ -19,8 +15,8 @@ class WidgetController extends \yii\rest\ActiveController
public $modelClass = 'hrzg\widget\models\crud\Widget'; public $modelClass = 'hrzg\widget\models\crud\Widget';
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function behaviors() public function behaviors()
...@@ -34,19 +30,17 @@ class WidgetController extends \yii\rest\ActiveController ...@@ -34,19 +30,17 @@ class WidgetController extends \yii\rest\ActiveController
[ [
'allow' => true, 'allow' => true,
/** /*
* *
*/ */
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id, return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]); ['route' => true]);
}, },
] ],
] ],
] ],
] ]
); );
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544 * /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544.
*
* @package default
*/ */
namespace hrzg\widget\controllers\crud\api; namespace hrzg\widget\controllers\crud\api;
/** /*
* This is the class for REST controller "WidgetTemplateController". * This is the class for REST controller "WidgetTemplateController".
*/ */
use yii\filters\AccessControl; use yii\filters\AccessControl;
...@@ -19,8 +15,8 @@ class WidgetTemplateController extends \yii\rest\ActiveController ...@@ -19,8 +15,8 @@ class WidgetTemplateController extends \yii\rest\ActiveController
public $modelClass = 'hrzg\widget\models\crud\WidgetTemplate'; public $modelClass = 'hrzg\widget\models\crud\WidgetTemplate';
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function behaviors() public function behaviors()
...@@ -34,19 +30,17 @@ class WidgetTemplateController extends \yii\rest\ActiveController ...@@ -34,19 +30,17 @@ class WidgetTemplateController extends \yii\rest\ActiveController
[ [
'allow' => true, 'allow' => true,
/** /*
* *
*/ */
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id, return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]); ['route' => true]);
}, },
] ],
] ],
] ],
] ]
); );
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47 * /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47.
*
* @package default
*/ */
// This class was automatically generated by a giiant build task // This class was automatically generated by a giiant build task
// You should not change it manually as it will be overwritten on next build // You should not change it manually as it will be overwritten on next build
namespace hrzg\widget\controllers\crud\base; namespace hrzg\widget\controllers\crud\base;
use hrzg\widget\models\crud\WidgetContent; use dmstr\bootstrap\Tabs;
use hrzg\widget\models\crud\search\WidgetContent as WidgetSearch; use hrzg\widget\models\crud\search\WidgetContent as WidgetSearch;
use hrzg\widget\models\crud\WidgetContent;
use yii\filters\AccessControl;
use yii\helpers\Url;
use yii\web\Controller; use yii\web\Controller;
use yii\web\HttpException; use yii\web\HttpException;
use yii\helpers\Url;
use yii\filters\AccessControl;
use dmstr\bootstrap\Tabs;
/** /**
* WidgetController implements the CRUD actions for Widget model. * WidgetController implements the CRUD actions for Widget model.
*/ */
class WidgetController extends Controller class WidgetController extends Controller
{ {
/** /**
* * @var bool whether to enable CSRF validation for the actions in this controller.
* @var boolean whether to enable CSRF validation for the actions in this controller.
* CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true. * CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true.
*/ */
public $enableCsrfValidation = false; public $enableCsrfValidation = false;
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function behaviors() public function behaviors()
...@@ -46,20 +41,19 @@ class WidgetController extends Controller ...@@ -46,20 +41,19 @@ class WidgetController extends Controller
[ [
'allow' => true, 'allow' => true,
/** /*
* *
*/ */
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id, return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]); ['route' => true]);
}, },
] ],
] ],
] ],
]; ];
} }
/** /**
* Lists all Widget models. * Lists all Widget models.
* *
...@@ -67,7 +61,7 @@ class WidgetController extends Controller ...@@ -67,7 +61,7 @@ class WidgetController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$searchModel = new WidgetSearch; $searchModel = new WidgetSearch();
$dataProvider = $searchModel->search($_GET); $dataProvider = $searchModel->search($_GET);
Tabs::clearLocalStorage(); Tabs::clearLocalStorage();
...@@ -81,11 +75,10 @@ class WidgetController extends Controller ...@@ -81,11 +75,10 @@ class WidgetController extends Controller
]); ]);
} }
/** /**
* Displays a single Widget model. * Displays a single Widget model.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -100,7 +93,6 @@ class WidgetController extends Controller ...@@ -100,7 +93,6 @@ class WidgetController extends Controller
]); ]);
} }
/** /**
* Creates a new Widget model. * Creates a new Widget model.
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
...@@ -109,7 +101,7 @@ class WidgetController extends Controller ...@@ -109,7 +101,7 @@ class WidgetController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new WidgetContent; $model = new WidgetContent();
try { try {
if ($model->load($_POST) && $model->save()) { if ($model->load($_POST) && $model->save()) {
...@@ -121,15 +113,15 @@ class WidgetController extends Controller ...@@ -121,15 +113,15 @@ class WidgetController extends Controller
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage(); $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg); $model->addError('_exception', $msg);
} }
return $this->render('create', ['model' => $model]); return $this->render('create', ['model' => $model]);
} }
/** /**
* Updates an existing Widget model. * Updates an existing Widget model.
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -146,12 +138,11 @@ class WidgetController extends Controller ...@@ -146,12 +138,11 @@ class WidgetController extends Controller
} }
} }
/** /**
* Deletes an existing Widget model. * Deletes an existing Widget model.
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -162,10 +153,10 @@ class WidgetController extends Controller ...@@ -162,10 +153,10 @@ class WidgetController extends Controller
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage(); $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
\Yii::$app->getSession()->addFlash('error', $msg); \Yii::$app->getSession()->addFlash('error', $msg);
return $this->redirect(Url::previous()); return $this->redirect(Url::previous());
} }
// TODO: improve detection // TODO: improve detection
$isPivot = strstr('$id', ','); $isPivot = strstr('$id', ',');
if ($isPivot == true) { if ($isPivot == true) {
...@@ -181,14 +172,13 @@ class WidgetController extends Controller ...@@ -181,14 +172,13 @@ class WidgetController extends Controller
} }
} }
/** /**
* Finds the Widget model based on its primary key value. * Finds the Widget model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
* *
* @throws HttpException if the model cannot be found * @throws HttpException if the model cannot be found
* *
* @param integer $id * @param int $id
* *
* @return WidgetContent the loaded model * @return WidgetContent the loaded model
*/ */
...@@ -200,6 +190,4 @@ class WidgetController extends Controller ...@@ -200,6 +190,4 @@ class WidgetController extends Controller
throw new HttpException(404, 'The requested page does not exist.'); throw new HttpException(404, 'The requested page does not exist.');
} }
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47 * /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47.
*
* @package default
*/ */
// This class was automatically generated by a giiant build task // This class was automatically generated by a giiant build task
// You should not change it manually as it will be overwritten on next build // You should not change it manually as it will be overwritten on next build
namespace hrzg\widget\controllers\crud\base; namespace hrzg\widget\controllers\crud\base;
use hrzg\widget\models\crud\WidgetTemplate; use dmstr\bootstrap\Tabs;
use hrzg\widget\models\crud\search\WidgetTemplate as WidgetTemplateSearch; use hrzg\widget\models\crud\search\WidgetTemplate as WidgetTemplateSearch;
use hrzg\widget\models\crud\WidgetTemplate;
use yii\filters\AccessControl;
use yii\helpers\Url;
use yii\web\Controller; use yii\web\Controller;
use yii\web\HttpException; use yii\web\HttpException;
use yii\helpers\Url;
use yii\filters\AccessControl;
use dmstr\bootstrap\Tabs;
/** /**
* WidgetTemplateController implements the CRUD actions for WidgetTemplate model. * WidgetTemplateController implements the CRUD actions for WidgetTemplate model.
*/ */
class WidgetTemplateController extends Controller class WidgetTemplateController extends Controller
{ {
/** /**
* * @var bool whether to enable CSRF validation for the actions in this controller.
* @var boolean whether to enable CSRF validation for the actions in this controller.
* CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true. * CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true.
*/ */
public $enableCsrfValidation = false; public $enableCsrfValidation = false;
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function behaviors() public function behaviors()
...@@ -46,20 +41,19 @@ class WidgetTemplateController extends Controller ...@@ -46,20 +41,19 @@ class WidgetTemplateController extends Controller
[ [
'allow' => true, 'allow' => true,
/** /*
* *
*/ */
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id, return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]); ['route' => true]);
}, },
] ],
] ],
] ],
]; ];
} }
/** /**
* Lists all WidgetTemplate models. * Lists all WidgetTemplate models.
* *
...@@ -67,7 +61,7 @@ class WidgetTemplateController extends Controller ...@@ -67,7 +61,7 @@ class WidgetTemplateController extends Controller
*/ */
public function actionIndex() public function actionIndex()
{ {
$searchModel = new WidgetTemplateSearch; $searchModel = new WidgetTemplateSearch();
$dataProvider = $searchModel->search($_GET); $dataProvider = $searchModel->search($_GET);
Tabs::clearLocalStorage(); Tabs::clearLocalStorage();
...@@ -81,11 +75,10 @@ class WidgetTemplateController extends Controller ...@@ -81,11 +75,10 @@ class WidgetTemplateController extends Controller
]); ]);
} }
/** /**
* Displays a single WidgetTemplate model. * Displays a single WidgetTemplate model.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -100,7 +93,6 @@ class WidgetTemplateController extends Controller ...@@ -100,7 +93,6 @@ class WidgetTemplateController extends Controller
]); ]);
} }
/** /**
* Creates a new WidgetTemplate model. * Creates a new WidgetTemplate model.
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
...@@ -109,7 +101,7 @@ class WidgetTemplateController extends Controller ...@@ -109,7 +101,7 @@ class WidgetTemplateController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new WidgetTemplate; $model = new WidgetTemplate();
try { try {
if ($model->load($_POST) && $model->save()) { if ($model->load($_POST) && $model->save()) {
...@@ -121,15 +113,15 @@ class WidgetTemplateController extends Controller ...@@ -121,15 +113,15 @@ class WidgetTemplateController extends Controller
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage(); $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg); $model->addError('_exception', $msg);
} }
return $this->render('create', ['model' => $model]); return $this->render('create', ['model' => $model]);
} }
/** /**
* Updates an existing WidgetTemplate model. * Updates an existing WidgetTemplate model.
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -146,12 +138,11 @@ class WidgetTemplateController extends Controller ...@@ -146,12 +138,11 @@ class WidgetTemplateController extends Controller
} }
} }
/** /**
* Deletes an existing WidgetTemplate model. * Deletes an existing WidgetTemplate model.
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* *
* @param integer $id * @param int $id
* *
* @return mixed * @return mixed
*/ */
...@@ -162,10 +153,10 @@ class WidgetTemplateController extends Controller ...@@ -162,10 +153,10 @@ class WidgetTemplateController extends Controller
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage(); $msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
\Yii::$app->getSession()->addFlash('error', $msg); \Yii::$app->getSession()->addFlash('error', $msg);
return $this->redirect(Url::previous()); return $this->redirect(Url::previous());
} }
// TODO: improve detection // TODO: improve detection
$isPivot = strstr('$id', ','); $isPivot = strstr('$id', ',');
if ($isPivot == true) { if ($isPivot == true) {
...@@ -181,14 +172,13 @@ class WidgetTemplateController extends Controller ...@@ -181,14 +172,13 @@ class WidgetTemplateController extends Controller
} }
} }
/** /**
* Finds the WidgetTemplate model based on its primary key value. * Finds the WidgetTemplate model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
* *
* @throws HttpException if the model cannot be found * @throws HttpException if the model cannot be found
* *
* @param integer $id * @param int $id
* *
* @return WidgetTemplate the loaded model * @return WidgetTemplate the loaded model
*/ */
...@@ -200,6 +190,4 @@ class WidgetTemplateController extends Controller ...@@ -200,6 +190,4 @@ class WidgetTemplateController extends Controller
throw new HttpException(404, 'The requested page does not exist.'); throw new HttpException(404, 'The requested page does not exist.');
} }
} }
} }
...@@ -11,7 +11,7 @@ class m160401_152059_add_widget_table extends Migration ...@@ -11,7 +11,7 @@ class m160401_152059_add_widget_table extends Migration
'name' => 'VARCHAR(255) NOT NULL', 'name' => 'VARCHAR(255) NOT NULL',
'php_class' => 'VARCHAR(255) NOT NULL', 'php_class' => 'VARCHAR(255) NOT NULL',
'json_schema' => 'TEXT NOT NULL', 'json_schema' => 'TEXT NOT NULL',
'twig_template' => 'TEXT NULL' 'twig_template' => 'TEXT NULL',
]); ]);
$this->createTable('{{%hrzg_widget_content}}', [ $this->createTable('{{%hrzg_widget_content}}', [
...@@ -48,5 +48,4 @@ class m160401_152059_add_widget_table extends Migration ...@@ -48,5 +48,4 @@ class m160401_152059_add_widget_table extends Migration
$this->dropTable('{{%hrzg_widget_content}}'); $this->dropTable('{{%hrzg_widget_content}}');
$this->dropTable('{{%hrzg_widget_template}}'); $this->dropTable('{{%hrzg_widget_template}}');
} }
} }
...@@ -36,7 +36,5 @@ class m160401_152910_add_widget_auth_item extends Migration ...@@ -36,7 +36,5 @@ class m160401_152910_add_widget_auth_item extends Migration
} else { } else {
throw new \yii\base\Exception('Application authManager must be an instance of \yii\rbac\DbManager'); throw new \yii\base\Exception('Application authManager must be an instance of \yii\rbac\DbManager');
} }
} }
} }
<?php
use yii\db\Migration;
class m160624_011345_settings extends Migration
{
public function up()
{
Yii::$app->settings->set('availablePhpClasses', '{"hrzg\\\widget\\\widgets\\\TwigTemplate": "Twig layout"}', 'widgets', 'object');
return true;
}
public function down()
{
Yii::$app->settings->delete('availablePhpClasses', 'widgets');
return true;
}
}
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace hrzg\widget\models\crud; namespace hrzg\widget\models\crud;
use hrzg\widget\models\crud\base\Widget as BaseWidget; use hrzg\widget\models\crud\base\Widget as BaseWidget;
use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
/** /**
...@@ -29,8 +28,9 @@ class WidgetContent extends BaseWidget ...@@ -29,8 +28,9 @@ class WidgetContent extends BaseWidget
*/ */
public function getViewFile() public function getViewFile()
{ {
$file = '/'.\Yii::getAlias('@runtime')."/".md5($this->template->twig_template).".twig"; $file = '/'.\Yii::getAlias('@runtime').'/'.md5($this->template->twig_template).'.twig';
file_put_contents($file, $this->template->twig_template); file_put_contents($file, $this->template->twig_template);
return $file; return $file;
} }
} }
...@@ -4,10 +4,41 @@ namespace hrzg\widget\models\crud; ...@@ -4,10 +4,41 @@ namespace hrzg\widget\models\crud;
use hrzg\widget\models\crud\base\WidgetTemplate as BaseWidgetTemplate; use hrzg\widget\models\crud\base\WidgetTemplate as BaseWidgetTemplate;
use Yii; use Yii;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
/** /**
* This is the model class for table "app_hrzg_widget_template". * This is the model class for table "app_hrzg_widget_template".
*/ */
class WidgetTemplate extends BaseWidgetTemplate class WidgetTemplate extends BaseWidgetTemplate
{ {
public function rules()
{
return ArrayHelper::merge(
parent::rules(),
[
[
'json_schema',
function ($attribute, $params) {
try {
Json::decode($this->$attribute);
} catch (InvalidParamException $e) {
$this->addError($attribute, 'Invalid JSON: '.$e->getMessage());
}
},
],
]
);
}
public function optPhpClass()
{
$json = Yii::$app->settings->get('availablePhpClasses', 'widgets', []);
if (!isset($json->scalar)) {
return [];
}
return Json::decode($json->scalar);
}
} }
...@@ -9,7 +9,7 @@ use Yii; ...@@ -9,7 +9,7 @@ use Yii;
/** /**
* This is the base-model class for table "app_hrzg_widget". * This is the base-model class for table "app_hrzg_widget".
* *
* @property integer $id * @property int $id
* @property string $status * @property string $status
* @property string $widget_template_id * @property string $widget_template_id
* @property string $default_properties_json * @property string $default_properties_json
...@@ -29,10 +29,8 @@ use Yii; ...@@ -29,10 +29,8 @@ use Yii;
*/ */
abstract class Widget extends \yii\db\ActiveRecord abstract class Widget extends \yii\db\ActiveRecord
{ {
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public static function tableName() public static function tableName()
{ {
...@@ -40,7 +38,8 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -40,7 +38,8 @@ abstract class Widget extends \yii\db\ActiveRecord
} }
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\query\WidgetQuery the active query used by this AR class. * @return \hrzg\widget\models\crud\query\WidgetQuery the active query used by this AR class.
*/ */
public static function find() public static function find()
...@@ -50,7 +49,8 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -50,7 +49,8 @@ abstract class Widget extends \yii\db\ActiveRecord
/** /**
* Alias name of table for crud viewsLists all Area models. * Alias name of table for crud viewsLists all Area models.
* Change the alias name manual if needed later * Change the alias name manual if needed later.
*
* @return string * @return string
*/ */
public function getAliasModel($plural = false) public function getAliasModel($plural = false)
...@@ -63,7 +63,7 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -63,7 +63,7 @@ abstract class Widget extends \yii\db\ActiveRecord
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function rules() public function rules()
{ {
...@@ -76,12 +76,12 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -76,12 +76,12 @@ abstract class Widget extends \yii\db\ActiveRecord
[['name_id'], 'string', 'max' => 64], [['name_id'], 'string', 'max' => 64],
[['rank', 'access_owner'], 'string', 'max' => 11], [['rank', 'access_owner'], 'string', 'max' => 11],
[['request_param', 'access_read', 'access_update', 'access_delete'], 'string', 'max' => 255], [['request_param', 'access_read', 'access_update', 'access_delete'], 'string', 'max' => 255],
[['access_domain'], 'string', 'max' => 8] [['access_domain'], 'string', 'max' => 8],
]; ];
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function attributeLabels() public function attributeLabels()
{ {
...@@ -105,7 +105,7 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -105,7 +105,7 @@ abstract class Widget extends \yii\db\ActiveRecord
]; ];
} }
/** /*
* @inheritdoc * @inheritdoc
*/ */
/*public function attributeHints() /*public function attributeHints()
...@@ -131,6 +131,4 @@ abstract class Widget extends \yii\db\ActiveRecord ...@@ -131,6 +131,4 @@ abstract class Widget extends \yii\db\ActiveRecord
'updated_at' => Yii::t('app', 'Updated At'), 'updated_at' => Yii::t('app', 'Updated At'),
]); ]);
}*/ }*/
} }
...@@ -9,17 +9,15 @@ use Yii; ...@@ -9,17 +9,15 @@ use Yii;
/** /**
* This is the base-model class for table "app_hrzg_widget_template". * This is the base-model class for table "app_hrzg_widget_template".
* *
* @property integer $id * @property int $id
* @property string $name * @property string $name
* @property string $json_schema * @property string $json_schema
* @property string $twig_template * @property string $twig_template
*/ */
abstract class WidgetTemplate extends \yii\db\ActiveRecord abstract class WidgetTemplate extends \yii\db\ActiveRecord
{ {
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public static function tableName() public static function tableName()
{ {
...@@ -27,7 +25,8 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord ...@@ -27,7 +25,8 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
} }
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\query\WidgetTemplateQuery the active query used by this AR class. * @return \hrzg\widget\models\crud\query\WidgetTemplateQuery the active query used by this AR class.
*/ */
public static function find() public static function find()
...@@ -37,7 +36,8 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord ...@@ -37,7 +36,8 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
/** /**
* Alias name of table for crud viewsLists all Area models. * Alias name of table for crud viewsLists all Area models.
* Change the alias name manual if needed later * Change the alias name manual if needed later.
*
* @return string * @return string
*/ */
public function getAliasModel($plural = false) public function getAliasModel($plural = false)
...@@ -50,19 +50,19 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord ...@@ -50,19 +50,19 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function rules() public function rules()
{ {
return [ return [
[['name', 'php_class', 'json_schema'], 'required'], [['name', 'php_class', 'json_schema'], 'required'],
[['json_schema', 'twig_template'], 'string'], [['json_schema', 'twig_template'], 'string'],
[['name'], 'string', 'max' => 255] [['name'], 'string', 'max' => 255],
]; ];
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function attributeLabels() public function attributeLabels()
{ {
...@@ -70,12 +70,12 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord ...@@ -70,12 +70,12 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
'id' => Yii::t('app', 'ID'), 'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Name'), 'name' => Yii::t('app', 'Name'),
'json_schema' => Yii::t('app', 'Json Schema'), 'json_schema' => Yii::t('app', 'Json Schema'),
'twig_template' => Yii::t('app', 'Template'), 'twig_template' => Yii::t('app', 'Twig Template'),
]; ];
} }
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
public function attributeHints() public function attributeHints()
{ {
...@@ -88,6 +88,4 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord ...@@ -88,6 +88,4 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
'twig_template' => Yii::t('app', 'Template'), 'twig_template' => Yii::t('app', 'Template'),
]); ]);
} }
} }
...@@ -16,7 +16,8 @@ class WidgetQuery extends \yii\db\ActiveQuery ...@@ -16,7 +16,8 @@ class WidgetQuery extends \yii\db\ActiveQuery
}*/ }*/
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetContent[]|array * @return \hrzg\widget\models\crud\WidgetContent[]|array
*/ */
public function all($db = null) public function all($db = null)
...@@ -25,7 +26,8 @@ class WidgetQuery extends \yii\db\ActiveQuery ...@@ -25,7 +26,8 @@ class WidgetQuery extends \yii\db\ActiveQuery
} }
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetContent|array|null * @return \hrzg\widget\models\crud\WidgetContent|array|null
*/ */
public function one($db = null) public function one($db = null)
......
...@@ -16,7 +16,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery ...@@ -16,7 +16,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery
}*/ }*/
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetTemplate[]|array * @return \hrzg\widget\models\crud\WidgetTemplate[]|array
*/ */
public function all($db = null) public function all($db = null)
...@@ -25,7 +26,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery ...@@ -25,7 +26,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery
} }
/** /**
* @inheritdoc * {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetTemplate|array|null * @return \hrzg\widget\models\crud\WidgetTemplate|array|null
*/ */
public function one($db = null) public function one($db = null)
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2 * /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2.
*
* @package default
*/ */
namespace hrzg\widget\models\crud\search; namespace hrzg\widget\models\crud\search;
use Yii; use hrzg\widget\models\crud\WidgetContent as WidgetModel;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use hrzg\widget\models\crud\WidgetContent as WidgetModel;
/** /**
* Widget represents the model behind the search form about `hrzg\widget\models\crud\Widget`. * Widget represents the model behind the search form about `hrzg\widget\models\crud\Widget`.
*/ */
class WidgetContent extends WidgetModel class WidgetContent extends WidgetModel
{ {
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function rules() public function rules()
...@@ -44,17 +38,16 @@ class WidgetContent extends WidgetModel ...@@ -44,17 +38,16 @@ class WidgetContent extends WidgetModel
'access_update', 'access_update',
'access_delete', 'access_delete',
'created_at', 'created_at',
'updated_at' 'updated_at',
], ],
'safe' 'safe',
], ],
]; ];
} }
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function scenarios() public function scenarios()
...@@ -63,9 +56,8 @@ class WidgetContent extends WidgetModel ...@@ -63,9 +56,8 @@ class WidgetContent extends WidgetModel
return Model::scenarios(); return Model::scenarios();
} }
/** /**
* Creates data provider instance with search query applied * Creates data provider instance with search query applied.
* *
* *
* @param array $params * @param array $params
...@@ -110,6 +102,4 @@ class WidgetContent extends WidgetModel ...@@ -110,6 +102,4 @@ class WidgetContent extends WidgetModel
return $dataProvider; return $dataProvider;
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2 * /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2.
*
* @package default
*/ */
namespace hrzg\widget\models\crud\search; namespace hrzg\widget\models\crud\search;
use Yii; use hrzg\widget\models\crud\WidgetTemplate as WidgetTemplateModel;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use hrzg\widget\models\crud\WidgetTemplate as WidgetTemplateModel;
/** /**
* WidgetTemplate represents the model behind the search form about `hrzg\widget\models\crud\WidgetTemplate`. * WidgetTemplate represents the model behind the search form about `hrzg\widget\models\crud\WidgetTemplate`.
*/ */
class WidgetTemplate extends WidgetTemplateModel class WidgetTemplate extends WidgetTemplateModel
{ {
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function rules() public function rules()
...@@ -32,10 +26,9 @@ class WidgetTemplate extends WidgetTemplateModel ...@@ -32,10 +26,9 @@ class WidgetTemplate extends WidgetTemplateModel
]; ];
} }
/** /**
* {@inheritdoc}
* *
* @inheritdoc
* @return unknown * @return unknown
*/ */
public function scenarios() public function scenarios()
...@@ -44,9 +37,8 @@ class WidgetTemplate extends WidgetTemplateModel ...@@ -44,9 +37,8 @@ class WidgetTemplate extends WidgetTemplateModel
return Model::scenarios(); return Model::scenarios();
} }
/** /**
* Creates data provider instance with search query applied * Creates data provider instance with search query applied.
* *
* *
* @param array $params * @param array $params
...@@ -79,6 +71,4 @@ class WidgetTemplate extends WidgetTemplateModel ...@@ -79,6 +71,4 @@ class WidgetTemplate extends WidgetTemplateModel
return $dataProvider; return $dataProvider;
} }
} }
<?php <?php
/** /**
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03 * /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03.
*
* @package default
*/ */
use dmstr\bootstrap\Tabs; use dmstr\bootstrap\Tabs;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model * @var hrzg\widget\models\crud\WidgetTemplate $model
...@@ -31,8 +27,8 @@ use yii\helpers\Html; ...@@ -31,8 +27,8 @@ use yii\helpers\Html;
'wrapper' => 'col-sm-10', 'wrapper' => 'col-sm-10',
'error' => '', 'error' => '',
'hint' => 'hidden', 'hint' => 'hidden',
] ],
] ],
] ]
); );
?> ?>
...@@ -43,9 +39,11 @@ use yii\helpers\Html; ...@@ -43,9 +39,11 @@ use yii\helpers\Html;
<p> <p>
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]) ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?php echo $form->field($model, 'php_class')->textInput(['maxlength' => true]) ?> <?php echo $form->field($model, 'php_class')->dropDownList($model->optPhpClass()) ?>
<?php echo $form->field($model, 'json_schema')->widget(\trntv\aceeditor\AceEditor::className()) ?> <?php echo $form->field($model, 'json_schema')
<?php echo $form->field($model, 'twig_template')->widget(\trntv\aceeditor\AceEditor::className()) ?> ->widget(\trntv\aceeditor\AceEditor::className(), ['mode' => 'json']) ?>
<?php echo $form->field($model, 'twig_template')
->widget(\trntv\aceeditor\AceEditor::className(), ['mode' => 'twig']) ?>
</p> </p>
<?php $this->endBlock(); ?> <?php $this->endBlock(); ?>
...@@ -60,7 +58,7 @@ use yii\helpers\Html; ...@@ -60,7 +58,7 @@ use yii\helpers\Html;
'content' => $this->blocks['main'], 'content' => $this->blocks['main'],
'active' => true, 'active' => true,
], ],
] ],
] ]
); );
?> ?>
...@@ -73,7 +71,7 @@ use yii\helpers\Html; ...@@ -73,7 +71,7 @@ use yii\helpers\Html;
($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')), ($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')),
[ [
'id' => 'save-'.$model->formName(), 'id' => 'save-'.$model->formName(),
'class' => 'btn btn-success' 'class' => 'btn btn-success',
] ]
); );
?> ?>
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1 * /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1.
*
* @package default
*/ */
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\search\WidgetTemplate $model * @var hrzg\widget\models\crud\search\WidgetTemplate $model
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215 * /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215.
*
* @package default
*/ */
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model * @var hrzg\widget\models\crud\WidgetTemplate $model
...@@ -19,12 +15,15 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -19,12 +15,15 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="giiant-crud widget-template-create"> <div class="giiant-crud widget-template-create">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
<?php echo $model->name ?> </small> <?php echo $model->name ?> </small>
</h1> </h1>
<div class="clearfix crud-navigation"> <div class="clearfix crud-navigation">
<div class="pull-left"> <div class="pull-left">
<?php echo Html::a( <?php echo Html::a(
...@@ -34,8 +33,12 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -34,8 +33,12 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
</div> </div>
<hr>
<?php echo $this->render('_form', [ <?php echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div> </div>
<?php <?php
/** /**
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22 * /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22.
*
* @package default
*/ */
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider * @var yii\data\ActiveDataProvider $dataProvider
...@@ -25,12 +21,13 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -25,12 +21,13 @@ $this->params['breadcrumbs'][] = $this->title;
<?php // echo $this->render('_search', ['model' =>$searchModel]); <?php // echo $this->render('_search', ['model' =>$searchModel]);
?> ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<?php \yii\widgets\Pjax::begin([ <?php \yii\widgets\Pjax::begin([
'id' => 'pjax-main', 'id' => 'pjax-main',
'enableReplaceState' => false, 'enableReplaceState' => false,
'linkSelector' => '#pjax-main ul.pagination a, th a', 'linkSelector' => '#pjax-main ul.pagination a, th a',
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'] 'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'],
]) ?> ]) ?>
<h1> <h1>
...@@ -45,30 +42,10 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -45,30 +42,10 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'btn btn-success']) ?> ['class' => 'btn btn-success']) ?>
</div> </div>
<div class="pull-right">
<?php echo
\yii\bootstrap\ButtonDropdown::widget(
[
'id' => 'giiant-relations',
'encodeLabel' => false,
'label' => '<span class="glyphicon glyphicon-paperclip"></span> '.Yii::t('app', 'Relations'),
'dropdown' => [
'options' => [
'class' => 'dropdown-menu-right'
],
'encodeLabels' => false,
'items' => []
],
'options' => [
'class' => 'btn-default'
]
]
);
?> </div>
</div> </div>
<hr/>
<div class="table-responsive"> <div class="table-responsive">
<?php echo GridView::widget([ <?php echo GridView::widget([
...@@ -77,7 +54,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -77,7 +54,7 @@ $this->params['breadcrumbs'][] = $this->title;
'pager' => [ 'pager' => [
'class' => yii\widgets\LinkPager::className(), 'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => Yii::t('app', 'First'), 'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last') 'lastPageLabel' => Yii::t('app', 'Last'),
], ],
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'], 'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
...@@ -88,18 +65,23 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -88,18 +65,23 @@ $this->params['breadcrumbs'][] = $this->title;
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) { 'urlCreator' => function ($action, $model, $key, $index) {
// using the column name as key, not mapping to 'id' like the standard generator // using the column name as key, not mapping to 'id' like the standard generator
$params = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key]; $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key];
$params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id.'/'.$action : $action; $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id.'/'.$action : $action;
return Url::toRoute($params); return Url::toRoute($params);
}, },
'contentOptions' => ['nowrap' => 'nowrap'] 'contentOptions' => ['nowrap' => 'nowrap'],
], ],
'name', 'name',
'php_class',
], ],
]); ?> ]); ?>
</div> </div>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php <?php
/** /**
* /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74 * /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74.
*
* @package default
*/ */
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model * @var hrzg\widget\models\crud\WidgetTemplate $model
*/ */
$this->title = $model->getAliasModel().$model->name.', '.Yii::t('app', 'Edit'); $this->title = $model->getAliasModel().$model->name.', '.Yii::t('app', 'Edit');
$this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => (string) $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Edit'); $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
?> ?>
<div class="giiant-crud widget-template-update"> <div class="giiant-crud widget-template-update">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
...@@ -31,8 +29,12 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit'); ...@@ -31,8 +29,12 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?> ['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
</div> </div>
<hr>
<?php echo $this->render('_form', [ <?php echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div> </div>
<?php <?php
/** /**
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee * /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee.
*
* @package default
*/ */
use dmstr\bootstrap\Tabs; use dmstr\bootstrap\Tabs;
use dmstr\helpers\Html; use dmstr\helpers\Html;
use yii\widgets\DetailView; use yii\widgets\DetailView;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model * @var hrzg\widget\models\crud\WidgetTemplate $model
...@@ -19,7 +15,7 @@ $copyParams = $model->attributes; ...@@ -19,7 +15,7 @@ $copyParams = $model->attributes;
$this->title = $model->getAliasModel().$model->name; $this->title = $model->getAliasModel().$model->name;
$this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => (string) $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'View'); $this->params['breadcrumbs'][] = Yii::t('app', 'View');
?> ?>
<div class="giiant-crud widget-template-view"> <div class="giiant-crud widget-template-view">
...@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</span> </span>
<?php endif; ?> <?php endif; ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
...@@ -46,7 +44,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -46,7 +44,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
<?php echo Html::a('<span class="glyphicon glyphicon-pencil"></span> '.Yii::t('app', 'Edit'), <?php echo Html::a('<span class="glyphicon glyphicon-pencil"></span> '.Yii::t('app', 'Edit'),
['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?> ['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
<?php echo Html::a('<span class="glyphicon glyphicon-copy"></span> '.Yii::t('app', 'Copy'), <?php echo Html::a('<span class="glyphicon glyphicon-copy"></span> '.Yii::t('app', 'Copy'),
['create', 'id' => $model->id, 'WidgetTemplate ' => $copyParams], ['create', 'id' => $model->id, 'WidgetTemplate' => $copyParams],
['class' => 'btn btn-success']) ?> ['class' => 'btn btn-success']) ?>
<?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> '.Yii::t('app', 'New'), ['create'], <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> '.Yii::t('app', 'New'), ['create'],
['class' => 'btn btn-success']) ?> ['class' => 'btn btn-success']) ?>
...@@ -58,6 +56,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -58,6 +56,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</div> </div>
<hr>
<?php $this->beginBlock('hrzg\widget\models\crud\WidgetTemplate'); ?> <?php $this->beginBlock('hrzg\widget\models\crud\WidgetTemplate'); ?>
...@@ -97,8 +96,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -97,8 +96,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
'content' => $this->blocks['hrzg\widget\models\crud\WidgetTemplate'], 'content' => $this->blocks['hrzg\widget\models\crud\WidgetTemplate'],
'active' => true, 'active' => true,
], ],
] ],
] ]
); );
?> ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div> </div>
<?php <?php
/** /**
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03 * /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03.
*
* @package default
*/ */
namespace _; namespace _;
use dmstr\bootstrap\Tabs; use franciscomaya\sceditor\SCEditorAsset;
use insolita\wgadminlte\Box; use insolita\wgadminlte\Box;
use Yii; use Yii;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model * @var hrzg\widget\models\crud\WidgetContent $model
...@@ -35,8 +32,8 @@ use yii\helpers\Html; ...@@ -35,8 +32,8 @@ use yii\helpers\Html;
'wrapper' => 'col-sm-10', 'wrapper' => 'col-sm-10',
'error' => '', 'error' => '',
'hint' => 'hidden', 'hint' => 'hidden',
] ],
] ],
] ]
); );
...@@ -80,14 +77,20 @@ JS; ...@@ -80,14 +77,20 @@ JS;
?> ?>
<div class="row"> <div class="row">
<div class="col-sm-8"> <div class="col-sm-9">
<?php Box::begin() ?> <?php Box::begin() ?>
<?php echo $form->field($model, 'widget_template_id')->dropDownList($model::optsWidgetTemplateId(), <?php echo $form->field($model, 'widget_template_id')->dropDownList($model::optsWidgetTemplateId(),
[ [
'onchange' => 'widgets.updateTemplate()' 'onchange' => 'widgets.updateTemplate()',
] ]
) ?> ) ?>
<div style="overflow: auto">
<?php
# TODO: workaround for editor registration
\franciscomaya\sceditor\SCEditorAsset::register($this)
?>
<?php \yii\widgets\Pjax::begin(['id' => 'pjax-widget-form']) ?> <?php \yii\widgets\Pjax::begin(['id' => 'pjax-widget-form']) ?>
<?php echo $form->field($model, 'default_properties_json') <?php echo $form->field($model, 'default_properties_json')
->widget(\beowulfenator\JsonEditor\JsonEditorWidget::className(), [ ->widget(\beowulfenator\JsonEditor\JsonEditorWidget::className(), [
...@@ -101,10 +104,11 @@ JS; ...@@ -101,10 +104,11 @@ JS;
], ],
]); ?> ]); ?>
<?php \yii\widgets\Pjax::end() ?> <?php \yii\widgets\Pjax::end() ?>
</div>
<?php Box::end() ?> <?php Box::end() ?>
</div> </div>
<div class="col-sm-4"> <div class="col-sm-3">
<?php Box::begin() ?> <?php Box::begin() ?>
<?php echo $form->field($model, 'status')->checkbox() ?> <?php echo $form->field($model, 'status')->checkbox() ?>
...@@ -119,7 +123,7 @@ JS; ...@@ -119,7 +123,7 @@ JS;
<?php Box::begin([ <?php Box::begin([
'title' => 'Access', 'title' => 'Access',
'collapse' => true, 'collapse' => true,
'collapseDefault' => true 'collapseDefault' => true,
]) ?> ]) ?>
<?php echo $form->field($model, 'access_domain')->textInput(['maxlength' => true]) ?> <?php echo $form->field($model, 'access_domain')->textInput(['maxlength' => true]) ?>
<?php echo $form->field($model, 'access_owner')->textInput(['maxlength' => true]) ?> <?php echo $form->field($model, 'access_owner')->textInput(['maxlength' => true]) ?>
...@@ -134,20 +138,7 @@ JS; ...@@ -134,20 +138,7 @@ JS;
</p> </p>
<?php $this->endBlock(); ?> <?php $this->endBlock(); ?>
<?php echo <?php echo $this->blocks['main'] ?>
Tabs::widget(
[
'encodeLabels' => false,
'items' => [
[
'label' => $model->getAliasModel(),
'content' => $this->blocks['main'],
'active' => true,
],
]
]
);
?>
<hr/> <hr/>
<?php echo $form->errorSummary($model); ?> <?php echo $form->errorSummary($model); ?>
...@@ -157,7 +148,7 @@ JS; ...@@ -157,7 +148,7 @@ JS;
($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')), ($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')),
[ [
'id' => 'save-'.$model->formName(), 'id' => 'save-'.$model->formName(),
'class' => 'btn btn-success' 'class' => 'btn btn-success',
] ]
); );
?> ?>
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1 * /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1.
*
* @package default
*/ */
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\search\WidgetContent $model * @var hrzg\widget\models\crud\search\WidgetContent $model
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215 * /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215.
*
* @package default
*/ */
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model * @var hrzg\widget\models\crud\WidgetContent $model
...@@ -19,6 +15,8 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -19,6 +15,8 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="giiant-crud widget-create"> <div class="giiant-crud widget-create">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
...@@ -34,6 +32,8 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -34,6 +32,8 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
</div> </div>
<?php \insolita\wgadminlte\Box::end() ?>
<?php echo $this->render('_form', [ <?php echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>
......
<?php <?php
/** /**
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22 * /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22.
*
* @package default
*/ */
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider * @var yii\data\ActiveDataProvider $dataProvider
...@@ -24,13 +20,13 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -24,13 +20,13 @@ $this->params['breadcrumbs'][] = $this->title;
<?php // echo $this->render('_search', ['model' =>$searchModel]); <?php // echo $this->render('_search', ['model' =>$searchModel]);
?> ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<?php \yii\widgets\Pjax::begin([ <?php \yii\widgets\Pjax::begin([
'id' => 'pjax-main', 'id' => 'pjax-main',
'enableReplaceState' => false, 'enableReplaceState' => false,
'linkSelector' => '#pjax-main ul.pagination a, th a', 'linkSelector' => '#pjax-main ul.pagination a, th a',
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'] 'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'],
]) ?> ]) ?>
<h1> <h1>
...@@ -45,30 +41,10 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -45,30 +41,10 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'btn btn-success']) ?> ['class' => 'btn btn-success']) ?>
</div> </div>
<div class="pull-right">
<?php echo
\yii\bootstrap\ButtonDropdown::widget(
[
'id' => 'giiant-relations',
'encodeLabel' => false,
'label' => '<span class="glyphicon glyphicon-paperclip"></span> '.Yii::t('app', 'Relations'),
'dropdown' => [
'options' => [
'class' => 'dropdown-menu-right'
],
'encodeLabels' => false,
'items' => []
],
'options' => [
'class' => 'btn-default'
]
]
);
?> </div>
</div> </div>
<hr>
<div class="table-responsive"> <div class="table-responsive">
<?php echo GridView::widget([ <?php echo GridView::widget([
...@@ -77,7 +53,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -77,7 +53,7 @@ $this->params['breadcrumbs'][] = $this->title;
'pager' => [ 'pager' => [
'class' => yii\widgets\LinkPager::className(), 'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => Yii::t('app', 'First'), 'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last') 'lastPageLabel' => Yii::t('app', 'Last'),
], ],
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'], 'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
...@@ -88,17 +64,22 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -88,17 +64,22 @@ $this->params['breadcrumbs'][] = $this->title;
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) { 'urlCreator' => function ($action, $model, $key, $index) {
// using the column name as key, not mapping to 'id' like the standard generator // using the column name as key, not mapping to 'id' like the standard generator
$params = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key]; $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key];
$params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id.'/'.$action : $action; $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id.'/'.$action : $action;
return Url::toRoute($params); return Url::toRoute($params);
}, },
'contentOptions' => ['nowrap' => 'nowrap'] 'contentOptions' => ['nowrap' => 'nowrap'],
],
[
'attribute' => 'template.name',
'header' => 'Template',
'contentOptions' => ['nowrap' => 'nowrap'],
], ],
'access_domain', 'access_domain',
'route', 'route',
'request_param', 'request_param',
'container_id', 'container_id',
'widget_template_id',
'name_id', 'name_id',
'rank', 'rank',
'status', 'status',
...@@ -107,12 +88,13 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -107,12 +88,13 @@ $this->params['breadcrumbs'][] = $this->title;
/*'access_update'*/ /*'access_update'*/
/*'access_delete'*/ /*'access_delete'*/
], ],
]); ?> ]); ?>
</div> </div>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php <?php
/**
namespace _;
/*
* /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74 * /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74
* *
* @package default * @package default
*/ */
use Yii;
use yii\helpers\Html; use yii\helpers\Html;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model * @var hrzg\widget\models\crud\WidgetContent $model
*/ */
$this->title = $model->getAliasModel().$model->id.', '.Yii::t('app', 'Edit'); $this->title = $model->getAliasModel().$model->id.', '.Yii::t('app', 'Edit');
$this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->id, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => (string) $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'Edit'); $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
?> ?>
<div class="giiant-crud widget-update"> <div class="giiant-crud widget-update">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
...@@ -31,8 +36,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit'); ...@@ -31,8 +36,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?> ['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
</div> </div>
<?php \insolita\wgadminlte\Box::end() ?>
<?php echo $this->render('_form', [ <?php echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>
</div> </div>
<?php <?php
/** /**
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee * /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee.
*
* @package default
*/ */
use dmstr\bootstrap\Tabs; use dmstr\bootstrap\Tabs;
use dmstr\helpers\Html; use dmstr\helpers\Html;
use yii\widgets\DetailView; use yii\widgets\DetailView;
/** /*
* *
* @var yii\web\View $this * @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model * @var hrzg\widget\models\crud\WidgetContent $model
...@@ -19,7 +15,7 @@ $copyParams = $model->attributes; ...@@ -19,7 +15,7 @@ $copyParams = $model->attributes;
$this->title = $model->getAliasModel().$model->id; $this->title = $model->getAliasModel().$model->id;
$this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->getAliasModel(true), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => (string)$model->id, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => (string) $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('app', 'View'); $this->params['breadcrumbs'][] = Yii::t('app', 'View');
?> ?>
<div class="giiant-crud widget-view"> <div class="giiant-crud widget-view">
...@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</span> </span>
<?php endif; ?> <?php endif; ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<h1> <h1>
<?php echo $model->getAliasModel() ?> <?php echo $model->getAliasModel() ?>
<small> <small>
...@@ -46,7 +44,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -46,7 +44,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
<?php echo Html::a('<span class="glyphicon glyphicon-pencil"></span> '.Yii::t('app', 'Edit'), <?php echo Html::a('<span class="glyphicon glyphicon-pencil"></span> '.Yii::t('app', 'Edit'),
['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?> ['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
<?php echo Html::a('<span class="glyphicon glyphicon-copy"></span> '.Yii::t('app', 'Copy'), <?php echo Html::a('<span class="glyphicon glyphicon-copy"></span> '.Yii::t('app', 'Copy'),
['create', 'id' => $model->id, 'Widget ' => $copyParams], ['class' => 'btn btn-success']) ?> ['create', 'id' => $model->id, 'Widget' => $copyParams], ['class' => 'btn btn-success']) ?>
<?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> '.Yii::t('app', 'New'), ['create'], <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> '.Yii::t('app', 'New'), ['create'],
['class' => 'btn btn-success']) ?> ['class' => 'btn btn-success']) ?>
</div> </div>
...@@ -57,6 +55,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -57,6 +55,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</div> </div>
<hr/>
<?php $this->beginBlock('hrzg\widget\models\crud\Widget'); ?> <?php $this->beginBlock('hrzg\widget\models\crud\Widget'); ?>
...@@ -107,8 +106,10 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View'); ...@@ -107,8 +106,10 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
'content' => $this->blocks['hrzg\widget\models\crud\Widget'], 'content' => $this->blocks['hrzg\widget\models\crud\Widget'],
'active' => true, 'active' => true,
], ],
] ],
] ]
); );
?> ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div> </div>
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
namespace _; namespace _;
use insolita\wgadminlte\Box; use hrzg\widget\models\crud\search\WidgetTemplate;
use yii\widgets\ListView; use hrzg\widget\models\crud\WidgetContent;
use insolita\wgadminlte\SmallBox;
use yii\helpers\Html;
/* /*
* @var yii\web\View $this * @var yii\web\View $this
...@@ -14,19 +16,46 @@ use yii\widgets\ListView; ...@@ -14,19 +16,46 @@ use yii\widgets\ListView;
<div class="col-sm-6"> <div class="col-sm-6">
<?= \insolita\wgadminlte\SmallBox::widget( <?= \insolita\wgadminlte\SmallBox::widget(
[ [
'head' => 'Co', 'head' => WidgetContent::find()->count(),
'footer' => 'Widget Contents', 'footer' => 'Contents',
'footer_link' => ['crud/widget'] 'footer_link' => ['crud/widget'],
] ]
) ?> ) ?>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-4">
<?= \insolita\wgadminlte\SmallBox::widget( <?= \insolita\wgadminlte\SmallBox::widget(
[ [
'head' => 'Wi', 'head' => WidgetTemplate::find()->count(),
'type' => SmallBox::TYPE_PURPLE,
'footer' => 'Templates', 'footer' => 'Templates',
'footer_link' => ['crud/widget-template'] 'footer_link' => ['crud/widget-template'],
]
) ?>
</div>
<div class="col-sm-2">
<?= \insolita\wgadminlte\SmallBox::widget(
[
'head' => '+',
'type' => SmallBox::TYPE_GREEN,
'footer' => 'New template',
'footer_link' => ['crud/widget-template/create'],
] ]
) ?> ) ?>
</div> </div>
</div> </div>
<?php \insolita\wgadminlte\Box::begin() ?>
<p>
<code>widgets</code>
<code>availablePhpClasses</code>
JSON
</p>
<h4>Example</h4>
<p>
<code>{"hrzg\\widget\\widgets\\TwigTemplate": "Twig layout"}</code></p>
<?= Html::a('Open settings', ['/settings'], ['class' => 'btn btn-default']) ?>
<?= Html::a('Online documentation', 'https://git.hrzg.de/hrzg/yii2-widgets2-module', ['class' => 'btn btn-info']) ?>
<?php \insolita\wgadminlte\Box::end() ?>
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2015 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
?>
<?php $this->beginContent('@backend/views/layouts/main.php'); ?>
<div class="box box-default">
<div class="box-body">
<?= $content ?>
</div>
<!-- /.box-body -->
</div>
<?php $this->endContent(); ?>
\ No newline at end of file
<?php <?php
/** /**
* @link http://www.diemeisterei.de/ * @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart * @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace hrzg\widget\widgets; namespace hrzg\widget\widgets;
use yii\base\Widget; use yii\base\Widget;
...@@ -20,6 +20,7 @@ class TwigTemplate extends Widget ...@@ -20,6 +20,7 @@ class TwigTemplate extends Widget
{ {
try { try {
$output = $this->renderFile($this->_view, $this->_properties); $output = $this->renderFile($this->_view, $this->_properties);
return $output; return $output;
} catch (\Exception $e) { } catch (\Exception $e) {
return $e->getMessage(); return $e->getMessage();
......
<?php <?php
/** /**
* @link http://www.diemeisterei.de/ * @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart * @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace hrzg\widget\widgets; namespace hrzg\widget\widgets;
use hrzg\widget\models\crud\WidgetContent; use hrzg\widget\models\crud\WidgetContent;
use hrzg\widget\assets\WidgetAsset;
use rmrevin\yii\fontawesome\AssetBundle;
use rmrevin\yii\fontawesome\component\Icon;
use rmrevin\yii\fontawesome\FA;
use yii\base\Event; use yii\base\Event;
use yii\base\Widget; use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json; use yii\helpers\Json;
class WidgetContainer extends Widget class WidgetContainer extends Widget
{ {
public function init(){ public function init()
{
\Yii::$app->trigger('registerMenuItems', new Event(['sender' => $this])); \Yii::$app->trigger('registerMenuItems', new Event(['sender' => $this]));
if (\Yii::$app->user->can('widgets')) {
WidgetAsset::register(\Yii::$app->view);
}
} }
public function run() public function run()
...@@ -35,61 +43,93 @@ class WidgetContainer extends Widget ...@@ -35,61 +43,93 @@ class WidgetContainer extends Widget
'container_id' => $this->id, 'container_id' => $this->id,
'route' => \Yii::$app->requestedRoute, 'route' => \Yii::$app->requestedRoute,
'request_param' => \Yii::$app->request->get('id'), 'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language 'access_domain' => \Yii::$app->language,
]) ])
->all(); ->all();
return $models; return $models;
} }
private function renderWidgets() private function renderWidgets()
{ {
$html = ''; $html = Html::beginTag('div',['class'=>'hrzg-widget-widget-container']);
foreach ($this->queryWidgets() AS $widget) {
if (\Yii::$app->user->can('widgets')) {
$html .= $this->generateContainerControls();
}
foreach ($this->queryWidgets() as $widget) {
$properties = Json::decode($widget->default_properties_json); $properties = Json::decode($widget->default_properties_json);
$class = \Yii::createObject($widget->template->php_class); $class = \Yii::createObject($widget->template->php_class);
$class->setView($widget->getViewFile()); $class->setView($widget->getViewFile());
if($properties) { if ($properties) {
$class->setProperties($properties); $class->setProperties($properties);
} }
$html .= Html::beginTag('div',['class'=>'hrzg-widget-widget']);
if (\Yii::$app->user->can('widgets')) {
$html .= $this->generateWidgetControls($widget);
}
$html .= $class->run(); $html .= $class->run();
$html .= Html::endTag('div');
} }
$html .= Html::endTag('div');
return $html; return $html;
} }
private function createWidget() private function createWidget()
{ {
}
private function generateContainerControls(){
$html = Html::beginTag('div',['class'=>'hrzg-widget-container-controls pull-right']);
$html .= Html::a('Add', ['/widgets/crud/widget/create',
'WidgetContent' => [
'route' => \Yii::$app->requestedRoute,
'container_id' => $this->id,
'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language,
]], ['class'=>'btn btn-default']);
$html .= Html::endTag('div');
return $html;
} }
public function getMenuItems(){ private function generateWidgetControls($widget){
$html = Html::beginTag('div',['class'=>'hrzg-widget-widget-controls']);
$html .= Html::a('Edit', ['/widgets/crud/widget/update', 'id'=>$widget->id], ['class'=>'btn btn-default']);
$html .= Html::endTag('div');
return $html;
}
public function getMenuItems()
{
// todo, register FA-asset from asset bundle
AssetBundle::register($this->view);
return [ return [
[ [
'label' => 'Create '.$this->id.' <span class="label label-info">widget</span>', 'label' => FA::icon(FA::_PLUS_SQUARE).' <b>'.$this->id.'</b> <span class="label label-info">widget</span>',
'url' => [ 'url' => [
'/widgets/crud/widget/create', '/widgets/crud/widget/create',
'WidgetContent' => [ 'WidgetContent' => [
'route' => \Yii::$app->requestedRoute, 'route' => \Yii::$app->requestedRoute,
'container_id' => $this->id, 'container_id' => $this->id,
'request_param' => \Yii::$app->request->get('id'), 'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language 'access_domain' => \Yii::$app->language,
] ],
] ],
], ],
[ [
'label' => 'Edit '.$this->id.' <span class="label label-info">widget</span>', 'label' => FA::icon(FA::_EDIT).' <b>'.$this->id.'</b> <span class="label label-info">widget</span>',
'url' => [ 'url' => [
'/widgets/crud/widget/index', '/widgets/crud/widget/index',
'WidgetContent' => [ 'WidgetContent' => [
'route' => \Yii::$app->requestedRoute, 'route' => \Yii::$app->requestedRoute,
'container_id' => $this->id, 'container_id' => $this->id,
'request_param' => \Yii::$app->request->get('id'), 'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language 'access_domain' => \Yii::$app->language,
] ],
] ],
] ],
]; ];
} }
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
namespace app\config; namespace app\config;
use hrzg\widget\models\crud\WidgetTemplate;
use schmunk42\giiant\generators\crud\callbacks\base\Callback; use schmunk42\giiant\generators\crud\callbacks\base\Callback;
use schmunk42\giiant\generators\crud\callbacks\yii\Db; use schmunk42\giiant\generators\crud\callbacks\yii\Db;
use schmunk42\giiant\generators\crud\callbacks\yii\Html; use schmunk42\giiant\generators\crud\callbacks\yii\Html;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment