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
Either run
```
php composer.phar require --prefer-dist hrzg/yii2-widgets2-module "*"
```
or add
```
"hrzg/yii2-widgets2-module": "*"
composer require hrzg/yii2-widgets2-module
```
to the require section of your `composer.json` file.
......@@ -37,16 +31,75 @@ setup.sh
```
### Settings
`availablePhpClasses`
Usage
-----
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)
- [Twig documentation](http://twig.sensiolabs.org/documentation)
```
{{ use ('hrzg/widget/widgets') }}
{{ widget_container_widget({id: 'main'}) }}
```
\ No newline at end of file
{{ 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)
{
"name": "hrzg/yii2-widgets2-module",
"description": "Yii 2.0 Framework Widget Manager",
"type": "yii2-extension",
"keywords": ["yii2","extension"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Tobias Munk",
"email": "tobias@diemeisterei.de"
}
],
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-twig": "^2.0.4",
"beowulfenator/yii2-json-editor": "^1.1"
},
"autoload": {
"psr-4": {
"hrzg\\widget\\": "src/"
}
"name": "hrzg/yii2-widgets2-module",
"description": "Yii 2.0 Framework Widget Manager",
"type": "yii2-extension",
"keywords": [
"yii2",
"extension"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Tobias Munk",
"email": "tobias@diemeisterei.de"
}
],
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-twig": "^2.0.4",
"dmstr/yii2-web": "*",
"beowulfenator/yii2-json-editor": "^1.1"
},
"autoload": {
"psr-4": {
"hrzg\\widget\\": "src/"
}
}
}
......@@ -10,7 +10,6 @@ class Module extends \yii\base\Module
{
parent::init();
// custom initialization code goes here
}
......@@ -18,6 +17,7 @@ class Module extends \yii\base\Module
{
parent::beforeAction($action);
\Yii::$app->controller->view->params['breadcrumbs'][] = ['label' => 'Widget', 'url' => ['/widgets']];
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
{
public function actionIndex()
{
$searchModel = new WidgetTemplate;
$searchModel = new WidgetTemplate();
$dataProvider = $searchModel->search([]);
return $this->render('index', ['templatesDataProvider' => $dataProvider]);
}
}
<?php
/**
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2
*
* @package default
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2.
*/
namespace hrzg\widget\controllers\crud;
use hrzg\widget\models\crud\search\WidgetContent;
......@@ -35,6 +31,7 @@ class WidgetController extends \hrzg\widget\controllers\crud\base\WidgetControll
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg);
}
return $this->render('create', ['model' => $model]);
}
}
<?php
/**
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2
*
* @package default
* /app/src/../runtime/giiant/49eb2de82346bc30092f584268252ed2.
*/
namespace hrzg\widget\controllers\crud;
/**
......@@ -13,5 +9,4 @@ namespace hrzg\widget\controllers\crud;
*/
class WidgetTemplateController extends \hrzg\widget\controllers\crud\base\WidgetTemplateController
{
}
<?php
/**
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544
*
* @package default
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544.
*/
namespace hrzg\widget\controllers\crud\api;
/**
/*
* This is the class for REST controller "WidgetController".
*/
use yii\filters\AccessControl;
......@@ -19,8 +15,8 @@ class WidgetController extends \yii\rest\ActiveController
public $modelClass = 'hrzg\widget\models\crud\Widget';
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function behaviors()
......@@ -34,19 +30,17 @@ class WidgetController extends \yii\rest\ActiveController
[
'allow' => true,
/**
/*
*
*/
'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]);
},
]
]
]
],
],
],
]
);
}
}
<?php
/**
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544
*
* @package default
* /app/src/../runtime/giiant/f197ab8e55d1e29a2dea883e84983544.
*/
namespace hrzg\widget\controllers\crud\api;
/**
/*
* This is the class for REST controller "WidgetTemplateController".
*/
use yii\filters\AccessControl;
......@@ -19,8 +15,8 @@ class WidgetTemplateController extends \yii\rest\ActiveController
public $modelClass = 'hrzg\widget\models\crud\WidgetTemplate';
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function behaviors()
......@@ -34,19 +30,17 @@ class WidgetTemplateController extends \yii\rest\ActiveController
[
'allow' => true,
/**
/*
*
*/
'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]);
},
]
]
]
],
],
],
]
);
}
}
<?php
/**
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47
*
* @package default
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47.
*/
// This class was automatically generated by a giiant build task
// You should not change it manually as it will be overwritten on next build
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\WidgetContent;
use yii\filters\AccessControl;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\HttpException;
use yii\helpers\Url;
use yii\filters\AccessControl;
use dmstr\bootstrap\Tabs;
/**
* WidgetController implements the CRUD actions for Widget model.
*/
class WidgetController extends 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.
* @var bool 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.
*/
public $enableCsrfValidation = false;
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function behaviors()
......@@ -46,20 +41,19 @@ class WidgetController extends Controller
[
'allow' => true,
/**
/*
*
*/
'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]);
},
]
]
]
],
],
],
];
}
/**
* Lists all Widget models.
*
......@@ -67,7 +61,7 @@ class WidgetController extends Controller
*/
public function actionIndex()
{
$searchModel = new WidgetSearch;
$searchModel = new WidgetSearch();
$dataProvider = $searchModel->search($_GET);
Tabs::clearLocalStorage();
......@@ -81,11 +75,10 @@ class WidgetController extends Controller
]);
}
/**
* Displays a single Widget model.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -100,7 +93,6 @@ class WidgetController extends Controller
]);
}
/**
* Creates a new Widget model.
* If creation is successful, the browser will be redirected to the 'view' page.
......@@ -109,7 +101,7 @@ class WidgetController extends Controller
*/
public function actionCreate()
{
$model = new WidgetContent;
$model = new WidgetContent();
try {
if ($model->load($_POST) && $model->save()) {
......@@ -121,15 +113,15 @@ class WidgetController extends Controller
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg);
}
return $this->render('create', ['model' => $model]);
}
/**
* Updates an existing Widget model.
* If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -146,12 +138,11 @@ class WidgetController extends Controller
}
}
/**
* Deletes an existing Widget model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -162,10 +153,10 @@ class WidgetController extends Controller
} catch (\Exception $e) {
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
\Yii::$app->getSession()->addFlash('error', $msg);
return $this->redirect(Url::previous());
}
// TODO: improve detection
$isPivot = strstr('$id', ',');
if ($isPivot == true) {
......@@ -181,14 +172,13 @@ class WidgetController extends Controller
}
}
/**
* Finds the Widget model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @throws HttpException if the model cannot be found
*
* @param integer $id
* @param int $id
*
* @return WidgetContent the loaded model
*/
......@@ -200,6 +190,4 @@ class WidgetController extends Controller
throw new HttpException(404, 'The requested page does not exist.');
}
}
}
<?php
/**
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47
*
* @package default
* /app/src/../runtime/giiant/358b0e44f1c1670b558e36588c267e47.
*/
// This class was automatically generated by a giiant build task
// You should not change it manually as it will be overwritten on next build
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\WidgetTemplate;
use yii\filters\AccessControl;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\HttpException;
use yii\helpers\Url;
use yii\filters\AccessControl;
use dmstr\bootstrap\Tabs;
/**
* WidgetTemplateController implements the CRUD actions for WidgetTemplate model.
*/
class WidgetTemplateController extends 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.
* @var bool 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.
*/
public $enableCsrfValidation = false;
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function behaviors()
......@@ -46,20 +41,19 @@ class WidgetTemplateController extends Controller
[
'allow' => true,
/**
/*
*
*/
'matchCallback' => function ($rule, $action) {
return \Yii::$app->user->can($this->module->id.'_'.$this->id.'_'.$action->id,
['route' => true]);
},
]
]
]
],
],
],
];
}
/**
* Lists all WidgetTemplate models.
*
......@@ -67,7 +61,7 @@ class WidgetTemplateController extends Controller
*/
public function actionIndex()
{
$searchModel = new WidgetTemplateSearch;
$searchModel = new WidgetTemplateSearch();
$dataProvider = $searchModel->search($_GET);
Tabs::clearLocalStorage();
......@@ -81,11 +75,10 @@ class WidgetTemplateController extends Controller
]);
}
/**
* Displays a single WidgetTemplate model.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -100,7 +93,6 @@ class WidgetTemplateController extends Controller
]);
}
/**
* Creates a new WidgetTemplate model.
* If creation is successful, the browser will be redirected to the 'view' page.
......@@ -109,7 +101,7 @@ class WidgetTemplateController extends Controller
*/
public function actionCreate()
{
$model = new WidgetTemplate;
$model = new WidgetTemplate();
try {
if ($model->load($_POST) && $model->save()) {
......@@ -121,15 +113,15 @@ class WidgetTemplateController extends Controller
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg);
}
return $this->render('create', ['model' => $model]);
}
/**
* Updates an existing WidgetTemplate model.
* If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -146,12 +138,11 @@ class WidgetTemplateController extends Controller
}
}
/**
* Deletes an existing WidgetTemplate model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @param int $id
*
* @return mixed
*/
......@@ -162,10 +153,10 @@ class WidgetTemplateController extends Controller
} catch (\Exception $e) {
$msg = (isset($e->errorInfo[2])) ? $e->errorInfo[2] : $e->getMessage();
\Yii::$app->getSession()->addFlash('error', $msg);
return $this->redirect(Url::previous());
}
// TODO: improve detection
$isPivot = strstr('$id', ',');
if ($isPivot == true) {
......@@ -181,14 +172,13 @@ class WidgetTemplateController extends Controller
}
}
/**
* Finds the WidgetTemplate model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @throws HttpException if the model cannot be found
*
* @param integer $id
* @param int $id
*
* @return WidgetTemplate the loaded model
*/
......@@ -200,6 +190,4 @@ class WidgetTemplateController extends Controller
throw new HttpException(404, 'The requested page does not exist.');
}
}
}
......@@ -11,7 +11,7 @@ class m160401_152059_add_widget_table extends Migration
'name' => 'VARCHAR(255) NOT NULL',
'php_class' => 'VARCHAR(255) NOT NULL',
'json_schema' => 'TEXT NOT NULL',
'twig_template' => 'TEXT NULL'
'twig_template' => 'TEXT NULL',
]);
$this->createTable('{{%hrzg_widget_content}}', [
......@@ -48,5 +48,4 @@ class m160401_152059_add_widget_table extends Migration
$this->dropTable('{{%hrzg_widget_content}}');
$this->dropTable('{{%hrzg_widget_template}}');
}
}
......@@ -36,7 +36,5 @@ class m160401_152910_add_widget_auth_item extends Migration
} else {
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 @@
namespace hrzg\widget\models\crud;
use hrzg\widget\models\crud\base\Widget as BaseWidget;
use Yii;
use yii\helpers\ArrayHelper;
/**
......@@ -29,8 +28,9 @@ class WidgetContent extends BaseWidget
*/
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);
return $file;
}
}
......@@ -4,10 +4,41 @@ namespace hrzg\widget\models\crud;
use hrzg\widget\models\crud\base\WidgetTemplate as BaseWidgetTemplate;
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".
*/
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;
/**
* This is the base-model class for table "app_hrzg_widget".
*
* @property integer $id
* @property int $id
* @property string $status
* @property string $widget_template_id
* @property string $default_properties_json
......@@ -29,10 +29,8 @@ use Yii;
*/
abstract class Widget extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
......@@ -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.
*/
public static function find()
......@@ -50,7 +49,8 @@ abstract class Widget extends \yii\db\ActiveRecord
/**
* 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
*/
public function getAliasModel($plural = false)
......@@ -63,7 +63,7 @@ abstract class Widget extends \yii\db\ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
......@@ -76,12 +76,12 @@ abstract class Widget extends \yii\db\ActiveRecord
[['name_id'], 'string', 'max' => 64],
[['rank', 'access_owner'], 'string', 'max' => 11],
[['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()
{
......@@ -105,7 +105,7 @@ abstract class Widget extends \yii\db\ActiveRecord
];
}
/**
/*
* @inheritdoc
*/
/*public function attributeHints()
......@@ -131,6 +131,4 @@ abstract class Widget extends \yii\db\ActiveRecord
'updated_at' => Yii::t('app', 'Updated At'),
]);
}*/
}
......@@ -9,17 +9,15 @@ use Yii;
/**
* This is the base-model class for table "app_hrzg_widget_template".
*
* @property integer $id
* @property int $id
* @property string $name
* @property string $json_schema
* @property string $twig_template
*/
abstract class WidgetTemplate extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function tableName()
{
......@@ -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.
*/
public static function find()
......@@ -37,7 +36,8 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
/**
* 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
*/
public function getAliasModel($plural = false)
......@@ -50,19 +50,19 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'php_class', 'json_schema'], 'required'],
[['json_schema', 'twig_template'], 'string'],
[['name'], 'string', 'max' => 255]
[['name'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
* {@inheritdoc}
*/
public function attributeLabels()
{
......@@ -70,12 +70,12 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Name'),
'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()
{
......@@ -88,6 +88,4 @@ abstract class WidgetTemplate extends \yii\db\ActiveRecord
'twig_template' => Yii::t('app', 'Template'),
]);
}
}
......@@ -16,7 +16,8 @@ class WidgetQuery extends \yii\db\ActiveQuery
}*/
/**
* @inheritdoc
* {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetContent[]|array
*/
public function all($db = null)
......@@ -25,7 +26,8 @@ class WidgetQuery extends \yii\db\ActiveQuery
}
/**
* @inheritdoc
* {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetContent|array|null
*/
public function one($db = null)
......
......@@ -16,7 +16,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery
}*/
/**
* @inheritdoc
* {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetTemplate[]|array
*/
public function all($db = null)
......@@ -25,7 +26,8 @@ class WidgetTemplateQuery extends \yii\db\ActiveQuery
}
/**
* @inheritdoc
* {@inheritdoc}
*
* @return \hrzg\widget\models\crud\WidgetTemplate|array|null
*/
public function one($db = null)
......
<?php
/**
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2
*
* @package default
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2.
*/
namespace hrzg\widget\models\crud\search;
use Yii;
use hrzg\widget\models\crud\WidgetContent as WidgetModel;
use yii\base\Model;
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`.
*/
class WidgetContent extends WidgetModel
{
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function rules()
......@@ -44,17 +38,16 @@ class WidgetContent extends WidgetModel
'access_update',
'access_delete',
'created_at',
'updated_at'
'updated_at',
],
'safe'
'safe',
],
];
}
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function scenarios()
......@@ -63,9 +56,8 @@ class WidgetContent extends WidgetModel
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* Creates data provider instance with search query applied.
*
*
* @param array $params
......@@ -110,6 +102,4 @@ class WidgetContent extends WidgetModel
return $dataProvider;
}
}
<?php
/**
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2
*
* @package default
* /app/src/../runtime/giiant/e0080b9d6ffa35acb85312bf99a557f2.
*/
namespace hrzg\widget\models\crud\search;
use Yii;
use hrzg\widget\models\crud\WidgetTemplate as WidgetTemplateModel;
use yii\base\Model;
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`.
*/
class WidgetTemplate extends WidgetTemplateModel
{
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function rules()
......@@ -32,10 +26,9 @@ class WidgetTemplate extends WidgetTemplateModel
];
}
/**
* {@inheritdoc}
*
* @inheritdoc
* @return unknown
*/
public function scenarios()
......@@ -44,9 +37,8 @@ class WidgetTemplate extends WidgetTemplateModel
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* Creates data provider instance with search query applied.
*
*
* @param array $params
......@@ -79,6 +71,4 @@ class WidgetTemplate extends WidgetTemplateModel
return $dataProvider;
}
}
<?php
/**
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03
*
* @package default
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03.
*/
use dmstr\bootstrap\Tabs;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model
......@@ -31,8 +27,8 @@ use yii\helpers\Html;
'wrapper' => 'col-sm-10',
'error' => '',
'hint' => 'hidden',
]
]
],
],
]
);
?>
......@@ -43,9 +39,11 @@ use yii\helpers\Html;
<p>
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?php echo $form->field($model, 'php_class')->textInput(['maxlength' => true]) ?>
<?php echo $form->field($model, 'json_schema')->widget(\trntv\aceeditor\AceEditor::className()) ?>
<?php echo $form->field($model, 'twig_template')->widget(\trntv\aceeditor\AceEditor::className()) ?>
<?php echo $form->field($model, 'php_class')->dropDownList($model->optPhpClass()) ?>
<?php echo $form->field($model, 'json_schema')
->widget(\trntv\aceeditor\AceEditor::className(), ['mode' => 'json']) ?>
<?php echo $form->field($model, 'twig_template')
->widget(\trntv\aceeditor\AceEditor::className(), ['mode' => 'twig']) ?>
</p>
<?php $this->endBlock(); ?>
......@@ -60,7 +58,7 @@ use yii\helpers\Html;
'content' => $this->blocks['main'],
'active' => true,
],
]
],
]
);
?>
......@@ -73,7 +71,7 @@ use yii\helpers\Html;
($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')),
[
'id' => 'save-'.$model->formName(),
'class' => 'btn btn-success'
'class' => 'btn btn-success',
]
);
?>
......
<?php
/**
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1
*
* @package default
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1.
*/
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\search\WidgetTemplate $model
......
<?php
/**
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215
*
* @package default
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215.
*/
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model
......@@ -19,12 +15,15 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="giiant-crud widget-template-create">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
<?php echo $model->name ?> </small>
</h1>
<div class="clearfix crud-navigation">
<div class="pull-left">
<?php echo Html::a(
......@@ -34,8 +33,12 @@ $this->params['breadcrumbs'][] = $this->title;
</div>
</div>
<hr>
<?php echo $this->render('_form', [
'model' => $model,
]); ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php
/**
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22
*
* @package default
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22.
*/
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
/**
/*
*
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
......@@ -25,12 +21,13 @@ $this->params['breadcrumbs'][] = $this->title;
<?php // echo $this->render('_search', ['model' =>$searchModel]);
?>
<?php \insolita\wgadminlte\Box::begin() ?>
<?php \yii\widgets\Pjax::begin([
'id' => 'pjax-main',
'enableReplaceState' => false,
'linkSelector' => '#pjax-main ul.pagination a, th a',
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}']
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'],
]) ?>
<h1>
......@@ -45,30 +42,10 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'btn btn-success']) ?>
</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>
<hr/>
<div class="table-responsive">
<?php echo GridView::widget([
......@@ -77,7 +54,7 @@ $this->params['breadcrumbs'][] = $this->title;
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last')
'lastPageLabel' => Yii::t('app', 'Last'),
],
'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
......@@ -88,18 +65,23 @@ $this->params['breadcrumbs'][] = $this->title;
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
// 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;
return Url::toRoute($params);
},
'contentOptions' => ['nowrap' => 'nowrap']
'contentOptions' => ['nowrap' => 'nowrap'],
],
'name',
'php_class',
],
]); ?>
</div>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php
/**
* /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74
*
* @package default
* /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74.
*/
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model
*/
$this->title = $model->getAliasModel().$model->name.', '.Yii::t('app', 'Edit');
$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');
?>
<div class="giiant-crud widget-template-update">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
......@@ -31,8 +29,12 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
</div>
<hr>
<?php echo $this->render('_form', [
'model' => $model,
]); ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php
/**
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee
*
* @package default
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee.
*/
use dmstr\bootstrap\Tabs;
use dmstr\helpers\Html;
use yii\widgets\DetailView;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetTemplate $model
......@@ -19,7 +15,7 @@ $copyParams = $model->attributes;
$this->title = $model->getAliasModel().$model->name;
$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');
?>
<div class="giiant-crud widget-template-view">
......@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</span>
<?php endif; ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
......@@ -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'),
['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
<?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']) ?>
<?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> '.Yii::t('app', 'New'), ['create'],
['class' => 'btn btn-success']) ?>
......@@ -58,6 +56,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</div>
<hr>
<?php $this->beginBlock('hrzg\widget\models\crud\WidgetTemplate'); ?>
......@@ -97,8 +96,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
'content' => $this->blocks['hrzg\widget\models\crud\WidgetTemplate'],
'active' => true,
],
]
],
]
);
?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php
/**
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03
*
* @package default
* /app/src/../runtime/giiant/4b7e79a8340461fe629a6ac612644d03.
*/
namespace _;
use dmstr\bootstrap\Tabs;
use franciscomaya\sceditor\SCEditorAsset;
use insolita\wgadminlte\Box;
use Yii;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model
......@@ -35,8 +32,8 @@ use yii\helpers\Html;
'wrapper' => 'col-sm-10',
'error' => '',
'hint' => 'hidden',
]
]
],
],
]
);
......@@ -80,31 +77,38 @@ JS;
?>
<div class="row">
<div class="col-sm-8">
<div class="col-sm-9">
<?php Box::begin() ?>
<?php echo $form->field($model, 'widget_template_id')->dropDownList($model::optsWidgetTemplateId(),
[
'onchange' => 'widgets.updateTemplate()'
'onchange' => 'widgets.updateTemplate()',
]
) ?>
<?php \yii\widgets\Pjax::begin(['id' => 'pjax-widget-form']) ?>
<?php echo $form->field($model, 'default_properties_json')
->widget(\beowulfenator\JsonEditor\JsonEditorWidget::className(), [
'schema' => $schema,
'clientOptions' => [
'theme' => 'bootstrap3',
'disable_collapse' => true,
#'disable_edit_json' => true,
'disable_properties' => true,
#'no_additional_properties' => true,
],
]); ?>
<?php \yii\widgets\Pjax::end() ?>
<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 echo $form->field($model, 'default_properties_json')
->widget(\beowulfenator\JsonEditor\JsonEditorWidget::className(), [
'schema' => $schema,
'clientOptions' => [
'theme' => 'bootstrap3',
'disable_collapse' => true,
#'disable_edit_json' => true,
'disable_properties' => true,
#'no_additional_properties' => true,
],
]); ?>
<?php \yii\widgets\Pjax::end() ?>
</div>
<?php Box::end() ?>
</div>
<div class="col-sm-4">
<div class="col-sm-3">
<?php Box::begin() ?>
<?php echo $form->field($model, 'status')->checkbox() ?>
......@@ -119,7 +123,7 @@ JS;
<?php Box::begin([
'title' => 'Access',
'collapse' => true,
'collapseDefault' => true
'collapseDefault' => true,
]) ?>
<?php echo $form->field($model, 'access_domain')->textInput(['maxlength' => true]) ?>
<?php echo $form->field($model, 'access_owner')->textInput(['maxlength' => true]) ?>
......@@ -134,20 +138,7 @@ JS;
</p>
<?php $this->endBlock(); ?>
<?php echo
Tabs::widget(
[
'encodeLabels' => false,
'items' => [
[
'label' => $model->getAliasModel(),
'content' => $this->blocks['main'],
'active' => true,
],
]
]
);
?>
<?php echo $this->blocks['main'] ?>
<hr/>
<?php echo $form->errorSummary($model); ?>
......@@ -157,7 +148,7 @@ JS;
($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save')),
[
'id' => 'save-'.$model->formName(),
'class' => 'btn btn-success'
'class' => 'btn btn-success',
]
);
?>
......
<?php
/**
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1
*
* @package default
* /app/src/../runtime/giiant/eeda5c365686c9888dbc13dbc58f89a1.
*/
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\search\WidgetContent $model
......
<?php
/**
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215
*
* @package default
* /app/src/../runtime/giiant/fccccf4deb34aed738291a9c38e87215.
*/
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model
......@@ -19,6 +15,8 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="giiant-crud widget-create">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
......@@ -34,6 +32,8 @@ $this->params['breadcrumbs'][] = $this->title;
</div>
</div>
<?php \insolita\wgadminlte\Box::end() ?>
<?php echo $this->render('_form', [
'model' => $model,
]); ?>
......
<?php
/**
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22
*
* @package default
* /app/src/../runtime/giiant/a0a12d1bd32eaeeb8b2cff56d511aa22.
*/
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
/**
/*
*
* @var yii\web\View $this
* @var yii\data\ActiveDataProvider $dataProvider
......@@ -24,13 +20,13 @@ $this->params['breadcrumbs'][] = $this->title;
<?php // echo $this->render('_search', ['model' =>$searchModel]);
?>
<?php \insolita\wgadminlte\Box::begin() ?>
<?php \yii\widgets\Pjax::begin([
'id' => 'pjax-main',
'enableReplaceState' => false,
'linkSelector' => '#pjax-main ul.pagination a, th a',
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}']
'clientOptions' => ['pjax:success' => 'function(){alert("yo")}'],
]) ?>
<h1>
......@@ -45,30 +41,10 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'btn btn-success']) ?>
</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>
<hr>
<div class="table-responsive">
<?php echo GridView::widget([
......@@ -77,7 +53,7 @@ $this->params['breadcrumbs'][] = $this->title;
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last')
'lastPageLabel' => Yii::t('app', 'Last'),
],
'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
......@@ -88,17 +64,22 @@ $this->params['breadcrumbs'][] = $this->title;
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
// 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;
return Url::toRoute($params);
},
'contentOptions' => ['nowrap' => 'nowrap']
'contentOptions' => ['nowrap' => 'nowrap'],
],
[
'attribute' => 'template.name',
'header' => 'Template',
'contentOptions' => ['nowrap' => 'nowrap'],
],
'access_domain',
'route',
'request_param',
'container_id',
'widget_template_id',
'name_id',
'rank',
'status',
......@@ -107,12 +88,13 @@ $this->params['breadcrumbs'][] = $this->title;
/*'access_update'*/
/*'access_delete'*/
],
]); ?>
</div>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
<?php \yii\widgets\Pjax::end() ?>
<?php
/**
namespace _;
/*
* /app/src/../runtime/giiant/fcd70a9bfdf8de75128d795dfc948a74
*
* @package default
*/
use Yii;
use yii\helpers\Html;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model
*/
$this->title = $model->getAliasModel().$model->id.', '.Yii::t('app', 'Edit');
$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');
?>
<div class="giiant-crud widget-update">
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
......@@ -31,8 +36,11 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Edit');
['view', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
</div>
<?php \insolita\wgadminlte\Box::end() ?>
<?php echo $this->render('_form', [
'model' => $model,
]); ?>
</div>
<?php
/**
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee
*
* @package default
* /app/src/../runtime/giiant/d4b4964a63cc95065fa0ae19074007ee.
*/
use dmstr\bootstrap\Tabs;
use dmstr\helpers\Html;
use yii\widgets\DetailView;
/**
/*
*
* @var yii\web\View $this
* @var hrzg\widget\models\crud\WidgetContent $model
......@@ -19,7 +15,7 @@ $copyParams = $model->attributes;
$this->title = $model->getAliasModel().$model->id;
$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');
?>
<div class="giiant-crud widget-view">
......@@ -33,6 +29,8 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</span>
<?php endif; ?>
<?php \insolita\wgadminlte\Box::begin() ?>
<h1>
<?php echo $model->getAliasModel() ?>
<small>
......@@ -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'),
['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
<?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'],
['class' => 'btn btn-success']) ?>
</div>
......@@ -57,6 +55,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
</div>
<hr/>
<?php $this->beginBlock('hrzg\widget\models\crud\Widget'); ?>
......@@ -107,8 +106,10 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'View');
'content' => $this->blocks['hrzg\widget\models\crud\Widget'],
'active' => true,
],
]
],
]
);
?>
<?php \insolita\wgadminlte\Box::end() ?>
</div>
......@@ -2,8 +2,10 @@
namespace _;
use insolita\wgadminlte\Box;
use yii\widgets\ListView;
use hrzg\widget\models\crud\search\WidgetTemplate;
use hrzg\widget\models\crud\WidgetContent;
use insolita\wgadminlte\SmallBox;
use yii\helpers\Html;
/*
* @var yii\web\View $this
......@@ -14,19 +16,46 @@ use yii\widgets\ListView;
<div class="col-sm-6">
<?= \insolita\wgadminlte\SmallBox::widget(
[
'head' => 'Co',
'footer' => 'Widget Contents',
'footer_link' => ['crud/widget']
'head' => WidgetContent::find()->count(),
'footer' => 'Contents',
'footer_link' => ['crud/widget'],
]
) ?>
</div>
<div class="col-sm-6">
<div class="col-sm-4">
<?= \insolita\wgadminlte\SmallBox::widget(
[
'head' => 'Wi',
'head' => WidgetTemplate::find()->count(),
'type' => SmallBox::TYPE_PURPLE,
'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>
<?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
/**
* @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\widgets;
use yii\base\Widget;
......@@ -20,6 +20,7 @@ class TwigTemplate extends Widget
{
try {
$output = $this->renderFile($this->_view, $this->_properties);
return $output;
} catch (\Exception $e) {
return $e->getMessage();
......
<?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\widgets;
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\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
class WidgetContainer extends Widget
{
public function init(){
public function init()
{
\Yii::$app->trigger('registerMenuItems', new Event(['sender' => $this]));
if (\Yii::$app->user->can('widgets')) {
WidgetAsset::register(\Yii::$app->view);
}
}
public function run()
......@@ -35,61 +43,93 @@ class WidgetContainer extends Widget
'container_id' => $this->id,
'route' => \Yii::$app->requestedRoute,
'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language
'access_domain' => \Yii::$app->language,
])
->all();
return $models;
}
private function renderWidgets()
{
$html = '';
foreach ($this->queryWidgets() AS $widget) {
$html = Html::beginTag('div',['class'=>'hrzg-widget-widget-container']);
if (\Yii::$app->user->can('widgets')) {
$html .= $this->generateContainerControls();
}
foreach ($this->queryWidgets() as $widget) {
$properties = Json::decode($widget->default_properties_json);
$class = \Yii::createObject($widget->template->php_class);
$class->setView($widget->getViewFile());
if($properties) {
if ($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 .= Html::endTag('div');
}
$html .= Html::endTag('div');
return $html;
}
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 [
[
'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' => [
'/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
]
]
'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' => [
'/widgets/crud/widget/index',
'WidgetContent' => [
'route' => \Yii::$app->requestedRoute,
'container_id' => $this->id,
'request_param' => \Yii::$app->request->get('id'),
'access_domain' => \Yii::$app->language
]
]
]
'access_domain' => \Yii::$app->language,
],
],
],
];
}
}
\ No newline at end of file
}
......@@ -2,7 +2,6 @@
namespace app\config;
use hrzg\widget\models\crud\WidgetTemplate;
use schmunk42\giiant\generators\crud\callbacks\base\Callback;
use schmunk42\giiant\generators\crud\callbacks\yii\Db;
use schmunk42\giiant\generators\crud\callbacks\yii\Html;
......@@ -50,38 +49,38 @@ CODE;
);
return [
'aliases' => [
'aliases' => [
'@hrzg/widget' => '/app/vendor/hrzg/yii2-widgets2-module/src'
],
'params' => [
'yii.migrations' => [
'@vendor/hrzg/yii2-widgets2-module/src/migrations'
]
'yii.migrations' => [
'@vendor/hrzg/yii2-widgets2-module/src/migrations'
]
],
'controllerMap' => [
'widget-cruds' => [
'class' => 'schmunk42\giiant\commands\BatchController',
'overwrite' => true,
'modelNamespace' => 'hrzg\\widget\\models\\crud',
'modelQueryNamespace' => 'hrzg\\widget\\models\\crud\\query',
'modelGenerateQuery' => true,
'crudTidyOutput' => true,
'crudAccessFilter' => true,
'crudControllerNamespace' => 'hrzg\\widget\\controllers\\crud',
'class' => 'schmunk42\giiant\commands\BatchController',
'overwrite' => true,
'modelNamespace' => 'hrzg\\widget\\models\\crud',
'modelQueryNamespace' => 'hrzg\\widget\\models\\crud\\query',
'modelGenerateQuery' => true,
'crudTidyOutput' => true,
'crudAccessFilter' => true,
'crudControllerNamespace' => 'hrzg\\widget\\controllers\\crud',
'crudSearchModelNamespace' => 'hrzg\\widget\\models\\crud\\search',
'crudViewPath' => '@hrzg/widget/views/crud',
'crudPathPrefix' => '/crud/',
'crudProviders' => [
'crudViewPath' => '@hrzg/widget/views/crud',
'crudPathPrefix' => '/crud/',
'crudProviders' => [
'schmunk42\\giiant\\generators\\crud\\providers\\optsProvider',
],
'tablePrefix' => 'app_hrzg_',
'tables' => [
'tablePrefix' => 'app_hrzg_',
'tables' => [
'app_hrzg_widget',
'app_hrzg_widget_template',
]
]
],
'modules' => [
'modules' => [
'widget' => [
'class' => 'hrzg\widget\Module',
'layout' => '@admin-views/layouts/box',
......
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