diff --git a/giiTemplates/crud/my/views/view.php b/giiTemplates/crud/my/views/view.php index df5ea82..d20849e 100644 --- a/giiTemplates/crud/my/views/view.php +++ b/giiTemplates/crud/my/views/view.php @@ -24,8 +24,8 @@ $this->params['breadcrumbs'][] = $this->title;

- Html::a(generateString('Редактировать') ?>, ['update', ], ['class' => 'btn btn-primary']) ?> - Html::a(generateString('Удалить') ?>, ['delete', ], [ + Html::a(, ['update', ], ['class' => 'btn btn-primary']) ?> + Html::a(, ['delete', ], [ 'class' => 'btn btn-danger', 'data' => [ 'confirm' => generateString('Are you sure you want to delete this item?') ?>, diff --git a/migrations/m170101_235536_create_setting.php b/migrations/m170101_235536_create_setting.php new file mode 100644 index 0000000..3325929 --- /dev/null +++ b/migrations/m170101_235536_create_setting.php @@ -0,0 +1,27 @@ +db->driverName === 'mysql') { + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('setting', [ + 'id' => $this->primaryKey(), + 'key' => $this->string()->notNull(), + 'title' => $this->string()->notNull(), + 'value' => $this->string(), + ], $tableOptions); + } + + public function safeDown() + { + $this->dropTable('setting'); + } +} diff --git a/migrations/m170101_235740_fill_settings.php b/migrations/m170101_235740_fill_settings.php new file mode 100644 index 0000000..b62b562 --- /dev/null +++ b/migrations/m170101_235740_fill_settings.php @@ -0,0 +1,31 @@ +insert('setting', [ + 'key' => 'log.user_connection', + 'title' => 'Логирование подключений пользователей', + 'value' => 0, + ]); + + $this->insert('setting', [ + 'key' => 'log.board_connection', + 'title' => 'Логирование подключений плат', + 'value' => 1, + ]); + } + + public function safeDown() + { + $this->delete('setting', [ + 'key' => [ + 'log.board_connection', + 'log.user_connection', + ], + ]); + } +} diff --git a/models/Room.php b/models/Room.php index 1ab8902..ace37a8 100644 --- a/models/Room.php +++ b/models/Room.php @@ -3,6 +3,7 @@ namespace app\models; use Yii; +use yii\helpers\ArrayHelper; /** * This is the model class for table "room". @@ -62,4 +63,12 @@ class Room extends \yii\db\ActiveRecord { return new RoomQuery(get_called_class()); } + + /** + * @return array + */ + public static function getList() + { + return ArrayHelper::map(self::find()->all(), 'id', 'name'); + } } diff --git a/models/Setting.php b/models/Setting.php new file mode 100644 index 0000000..418ca1c --- /dev/null +++ b/models/Setting.php @@ -0,0 +1,64 @@ + 255], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'key' => 'Ключ', + 'title' => 'Название', + 'value' => 'Значение', + ]; + } + + /** + * @param string|int $key + * @return null|string + */ + public static function getValueByKey($key) + { + /** @var self $model */ + $model = self::find()->where(['key' => $key])->select('value')->one(); + + if (!$model) { + return null; + } + + return $model->value; + } +} diff --git a/models/User.php b/models/User.php index 4dc45d4..75a4b18 100644 --- a/models/User.php +++ b/models/User.php @@ -65,7 +65,8 @@ class User extends ActiveRecord implements IdentityInterface [['password_hash'], 'required', 'on' => 'create'], [['auth_token'], 'default', 'value' => null], [['status'], 'default', 'value' => self::STATUS_ACTIVE], - [['status'], 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], + [['status'], 'in', 'range' => self::getStatuses()], + [['group'], 'in', 'range' => self::getGroupsArray()], ]; } @@ -81,7 +82,7 @@ class User extends ActiveRecord implements IdentityInterface 'email' => 'Email', 'status' => 'Статус', 'group' => 'Группа', - 'api_token' => 'API ключ', + 'api_key' => 'API ключ', 'auth_token' => 'Auth токен', 'created_at' => 'Дата создания', 'updated_at' => 'Дата изменения', @@ -91,7 +92,7 @@ class User extends ActiveRecord implements IdentityInterface /** * @return array */ - public static function getStatusesArray() + public static function getStatuses() { return [ self::STATUS_ACTIVE => 'Активен', @@ -99,12 +100,47 @@ class User extends ActiveRecord implements IdentityInterface ]; } + /** + * @return array + */ + public static function getStatusesArray() + { + return array_keys(self::getStatuses()); + } + + /** + * @return array + */ + public static function getGroups() + { + return [ + self::GROUP_ADMIN => 'Администратор', + self::GROUP_USER => 'Пользователь', + ]; + } + + /** + * @return array + */ + public static function getGroupsArray() + { + return array_keys(self::getGroups()); + } + /** * @return string */ public function getStatusLabel() { - return self::getStatusesArray()[$this->status]; + return self::getStatuses()[$this->status]; + } + + /** + * @return string + */ + public function getGroupLabel() + { + return self::getGroups()[$this->group]; } /** diff --git a/models/UserSearch.php b/models/UserSearch.php index 560146b..11f2c45 100644 --- a/models/UserSearch.php +++ b/models/UserSearch.php @@ -18,7 +18,7 @@ class UserSearch extends User public function rules() { return [ - [['id', 'status', 'created_at', 'updated_at'], 'integer'], + [['id', 'status', 'group', 'created_at', 'updated_at'], 'integer'], [['username', 'email'], 'safe'], ]; } @@ -61,6 +61,7 @@ class UserSearch extends User $query->andFilterWhere([ 'id' => $this->id, 'status' => $this->status, + 'group' => $this->group, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); diff --git a/modules/admin/controllers/SettingController.php b/modules/admin/controllers/SettingController.php new file mode 100644 index 0000000..cdb5a0d --- /dev/null +++ b/modules/admin/controllers/SettingController.php @@ -0,0 +1,39 @@ +all(); + + return $this->render('index', [ + 'models' => $models, + ]); + } + + public function actionSave() + { + $settings = Yii::$app->request->post('Settings'); + + foreach ($settings as $key => $value) { + $model = Setting::findOne(['key' => $key]); + + if (!$model) { + throw new NotFoundHttpException(); + } + + $model->value = $value; + $model->save(); + } + + return $this->redirect(['index']); + } + +} diff --git a/modules/admin/views/item/index.php b/modules/admin/views/item/index.php index 346ab32..482d0e9 100644 --- a/modules/admin/views/item/index.php +++ b/modules/admin/views/item/index.php @@ -6,6 +6,7 @@ use app\models\Board; use app\models\Item; +use app\models\Room; use yii\helpers\Html; use yii\grid\GridView; use yii\widgets\Pjax; @@ -38,6 +39,14 @@ $this->params['breadcrumbs'][] = $this->title; 'contentOptions' => ['style' => 'width: 5%'] ], 'name', + [ + 'attribute' => 'room_id', + 'filter' => Room::getList(), + 'value' => function ($model) { + /** @var $model Item */ + return $model->room->name; + }, + ], [ 'attribute' => 'board_id', 'filter' => Board::getList(), diff --git a/modules/admin/views/room/index.php b/modules/admin/views/room/index.php index 7d40bb5..9d3e63f 100644 --- a/modules/admin/views/room/index.php +++ b/modules/admin/views/room/index.php @@ -24,10 +24,7 @@ $this->params['breadcrumbs'][] = $this->title; 'layout' => '{summary}

{items}
{pager}', 'filterModel' => $searchModel, 'columns' => [ - [ - 'attribute' => 'id', - 'contentOptions' => ['style' => 'width: 5%'] - ], + 'id', 'name', 'bg', diff --git a/modules/admin/views/setting/index.php b/modules/admin/views/setting/index.php new file mode 100644 index 0000000..1021351 --- /dev/null +++ b/modules/admin/views/setting/index.php @@ -0,0 +1,37 @@ +title = 'Настройки'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

+ title ?> +

+ +
+ + + +
+ + +
+ + +
+ 'btn btn-primary']) ?> +
+
+ +
diff --git a/modules/admin/views/task/index.php b/modules/admin/views/task/index.php index 98bf274..1c92423 100644 --- a/modules/admin/views/task/index.php +++ b/modules/admin/views/task/index.php @@ -25,7 +25,10 @@ $this->params['breadcrumbs'][] = $this->title; 'layout' => '{summary}
{items}
{pager}', 'filterModel' => $searchModel, 'columns' => [ - 'id', + [ + 'attribute' => 'id', + 'contentOptions' => ['style' => 'width: 5%'] + ], [ 'filter' => Task::getTypes(), 'attribute' => 'type', diff --git a/modules/admin/views/trigger/create.php b/modules/admin/views/trigger/create.php index f7213d9..d510d54 100644 --- a/modules/admin/views/trigger/create.php +++ b/modules/admin/views/trigger/create.php @@ -5,8 +5,8 @@ use yii\helpers\Html; -$this->title = 'Добавить Trigger'; -$this->params['breadcrumbs'][] = ['label' => 'Triggers', 'url' => ['index']]; +$this->title = 'Добавить Триггер'; +$this->params['breadcrumbs'][] = ['label' => 'Триггеры', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?>
diff --git a/modules/admin/views/trigger/index.php b/modules/admin/views/trigger/index.php index 7bce55b..df462af 100644 --- a/modules/admin/views/trigger/index.php +++ b/modules/admin/views/trigger/index.php @@ -9,7 +9,7 @@ use yii\helpers\Html; use yii\grid\GridView; use yii\widgets\Pjax; -$this->title = 'Triggers'; +$this->title = 'Триггеры'; $this->params['breadcrumbs'][] = $this->title; ?>
@@ -31,7 +31,10 @@ $this->params['breadcrumbs'][] = $this->title; 'layout' => '{summary}
{items}
{pager}', 'filterModel' => $searchModel, 'columns' => [ - 'id', + [ + 'attribute' => 'id', + 'contentOptions' => ['style' => 'width: 5%'] + ], [ 'filter' => [ 0 => 'Нет', diff --git a/modules/admin/views/trigger/update.php b/modules/admin/views/trigger/update.php index 5d3a28a..9583e26 100644 --- a/modules/admin/views/trigger/update.php +++ b/modules/admin/views/trigger/update.php @@ -5,8 +5,8 @@ use yii\helpers\Html; -$this->title = 'Изменить Trigger: ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Triggers', 'url' => ['index']]; +$this->title = 'Изменить Триггер: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Триггеры', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = 'Редактирование'; ?> diff --git a/modules/admin/views/trigger/view.php b/modules/admin/views/trigger/view.php index d9cea51..40c7e9a 100644 --- a/modules/admin/views/trigger/view.php +++ b/modules/admin/views/trigger/view.php @@ -7,7 +7,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; $this->title = $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Triggers', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => 'Триггеры', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?>
diff --git a/modules/admin/views/user/_form.php b/modules/admin/views/user/_form.php index 5d63a45..2a9093c 100644 --- a/modules/admin/views/user/_form.php +++ b/modules/admin/views/user/_form.php @@ -24,7 +24,9 @@ if ($model->isNewRecord) { field($model, 'email')->input('email') ?> - field($model, 'status')->dropDownList(User::getStatusesArray()) ?> + field($model, 'status')->dropDownList(User::getStatuses()) ?> + + field($model, 'group')->dropDownList(User::getGroups()) ?> field($model, 'api_key')->textInput() ?> diff --git a/modules/admin/views/user/index.php b/modules/admin/views/user/index.php index 76a9c9d..75cb812 100644 --- a/modules/admin/views/user/index.php +++ b/modules/admin/views/user/index.php @@ -21,17 +21,28 @@ $this->params['breadcrumbs'][] = $this->title; 'summaryOptions' => ['class' => 'alert alert-info'], 'layout' => '{summary}
{items}
{pager}', 'columns' => [ - 'id', + [ + 'attribute' => 'id', + 'contentOptions' => ['style' => 'width: 5%'] + ], 'username', 'email', [ - 'filter' => User::getStatusesArray(), + 'filter' => User::getStatuses(), 'attribute' => 'status', 'value' => function ($model) { /** @var $model User */ return $model->getStatusLabel(); }, ], + [ + 'filter' => User::getGroups(), + 'attribute' => 'group', + 'value' => function ($model) { + /** @var $model User */ + return $model->getGroupLabel(); + }, + ], ['class' => 'app\components\ActionButtonColumn'], ], diff --git a/modules/admin/views/user/view.php b/modules/admin/views/user/view.php index e92746b..f3ddcc5 100644 --- a/modules/admin/views/user/view.php +++ b/modules/admin/views/user/view.php @@ -6,7 +6,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; -$this->title = $model->username; +$this->title = 'Пользователь ' . $model->username; $this->params['breadcrumbs'][] = ['label' => 'Пользователи', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> @@ -34,6 +34,10 @@ $this->params['breadcrumbs'][] = $this->title; 'attribute' => 'status', 'value' => $model->getStatusLabel(), ], + [ + 'attribute' => 'group', + 'value' => $model->getGroupLabel(), + ], 'api_key', 'created_at:datetime', 'updated_at:datetime', diff --git a/servers/Panel.php b/servers/Panel.php index 273e684..b7b9a86 100644 --- a/servers/Panel.php +++ b/servers/Panel.php @@ -4,6 +4,7 @@ namespace app\servers; use app\helpers\IPHelper; use app\models\Board; +use app\models\Setting; use app\models\Task; use app\models\Trigger; use app\models\History; @@ -837,6 +838,10 @@ class Panel implements MessageComponentInterface */ protected function logBoardConnection($board, $connected) { + if (!Setting::getValueByKey('log.board_connection')) { + return; + } + $model = new History(); $model->type = History::TYPE_BOARD_CONNECTION; $model->board_id = $board->id; @@ -855,6 +860,10 @@ class Panel implements MessageComponentInterface */ protected function logUserConnection($user, $connected) { + if (!Setting::getValueByKey('log.user_connection')) { + return; + } + $model = new History(); $model->type = History::TYPE_USER_CONNECTION; $model->user_id = $user->id; diff --git a/views/layouts/_left.php b/views/layouts/_left.php index 35335da..ef4a566 100644 --- a/views/layouts/_left.php +++ b/views/layouts/_left.php @@ -27,7 +27,7 @@ ['label' => 'Настройки', 'options' => ['class' => 'header']], ['label' => 'Элементы', 'icon' => 'fa fa-toggle-on', 'url' => ['/admin/item/index']], ['label' => 'Платы', 'icon' => 'fa fa-hdd-o', 'url' => ['/admin/board/index']], - ['label' => 'Triggers', 'icon' => 'fa fa-feed', 'url' => ['/admin/trigger/index']], + ['label' => 'Триггеры', 'icon' => 'fa fa-feed', 'url' => ['/admin/trigger/index']], ['label' => 'Задачи', 'icon' => 'fa fa-check', 'url' => ['/admin/task/index']], ['label' => 'Комнаты', 'icon' => 'fa fa-folder-open', 'url' => ['/admin/room/index']], // ['label' => 'История', 'icon' => 'fa fa-bar-chart', 'url' => ['/admin/history/index']], diff --git a/views/site/index.php b/views/site/index.php index 976ac51..9da5a7c 100644 --- a/views/site/index.php +++ b/views/site/index.php @@ -3,6 +3,8 @@ /* @var $this yii\web\View */ $this->title = 'Главная'; + +\yii\helpers\VarDumper::dump(\app\models\Setting::getValueByKey('log.user_connection'),10,true); ?>

title ?>