Commit d2d8cabf by Скуратович Александр

переделал круд по фильтрам + выпилил модуль админки

1 parent be538f7e
......@@ -16,12 +16,6 @@ $config = [
'@npm' => '@vendor/npm-asset',
],
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
'layout' => 'admin'
],
],
'components' => [
'assetManager' => [
'bundles' => [
......@@ -90,7 +84,6 @@ $config = [
//'<controller:(about|login)>' => 'site/index',
'<controller:(\w|-)+>/' => '<controller>/index',
'<controller:\w+>/<action:(\w|-)+>/<id:\d+>' => '<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:(\w|-)+>' => '<module>/<controller>/<action>',
'<controller:\w+>/<action:(\w|-)+>' => '<controller>/<action>'
],
],
......
......@@ -7,7 +7,7 @@ use yii\data\ActiveDataProvider;
use app\models\Filter;
/**
* HostSearch represents the model behind the search form of `app\models\Filter`.
* FilterSearch represents the model behind the search form of `app\models\Filter`.
*/
class FilterSearch extends Filter
{
......@@ -59,14 +59,13 @@ class FilterSearch extends Filter
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'pattern' => $this->pattern,
//'created' => $this->created,
'created' => $this->created,
'include' => $this->include,
'status' => $this->status,
'type' => $this->type,
]);
$query->andFilterWhere(['like', 'domain', $this->domain]);
$query->andFilterWhere(['like', 'pattern', $this->pattern]);
return $dataProvider;
}
......
<?php
namespace app\modules\admin;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
/**
* admin module definition class
*/
class Module extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'app\modules\admin\controllers';
public $defaultController='default';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}
<?php
namespace app\modules\admin\controllers;
use app\models\Order;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
/**
* Default controller for the `admin` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
// var_dump(Yii::$app->user->isGuest);
// var_dump(Yii::$app->user->identity);
//var_dump(Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId()));
return $this->render('index');
}
}
<?php
namespace app\modules\admin\controllers;
use Yii;
use app\models\Host;
use app\models\HostSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* HostController implements the CRUD actions for Host model.
*/
class HostController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Host models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HostSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Host model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Host model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Host();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Host model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Host model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Host model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Host the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Host::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $searchModel app\models\ContactSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Админка';
$this->params['breadcrumbs'][] = ['label' => 'Админка', 'url' => ['/admin']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="admin-default-index">
<h1><?= Html::encode($this->title) ?></h1>
<statistic></statistic>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="host-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'domain')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'csv_date')->textInput() ?>
<?= $form->field($model, 'wis_date')->textInput() ?>
<?= $form->field($model, 'wis_status')->textInput() ?>
<?= $form->field($model, 'tix')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\HostSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="host-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'options' => [
'data-pjax' => 1
],
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'domain') ?>
<?= $form->field($model, 'created_at') ?>
<?= $form->field($model, 'csv_date') ?>
<?= $form->field($model, 'wis_date') ?>
<?php // echo $form->field($model, 'wis_status') ?>
<?php // echo $form->field($model, 'tix') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
$this->title = 'Create Host';
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="host-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\jui\DatePicker;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel app\models\HostSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'List of domains';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="host-index">
<h1><?= Html::encode($this->title) ?></h1>
<!--p>
<?= Html::a('Create Host', ['create'], ['class' => 'btn btn-success']) ?>
</p-->
<?php Pjax::begin(); ?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'domain',
'created_at' => [
'attribute' => 'created_at',
'value' => 'created_at',
// 'format' => 'date',
/* 'filter' => DatePicker::widget([
'name' => 'created_at',
'clientOptions' => [
'format' => 'd.mm.yyyy',
'todayHighlight' => true,
]
]),*/
],
'csv_date',
'wis_status' =>
[
'attribute' => 'wis_status',
'filter' => \app\models\Host::getStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getStatus($model->wis_status);
},
],
'wis_date',
'domain_expire',
'tix',
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Actions',
'template' => '{view} {delete}',
]
],
]); ?>
<?php Pjax::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
$this->title = 'Update Host: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="host-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="host-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'domain',
'created_at',
'csv_date',
'wis_date',
'wis_status',
'tix',
],
]) ?>
</div>
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Url;
use app\widgets\Alert;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AdminAsset;
AdminAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div id="app" class="wrap">
<?php
NavBar::begin([
'brandLabel' => Yii::$app->name,
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Logout (' . Yii::$app->user->identity->name . ')', 'url' => ['/auth/logout']],
],
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'homeLink' => [
'label' => 'Главная',
'url' => Url::home()
],
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
<notifications
width="380"
group="admin"
position="bottom right"
classes="flower-style"
:duration="3000"
></notifications>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; <?php echo Yii::$app->name; ?> <?php
$d = date('Y');
echo(($d - 2021) ? '2021 - ' . $d : $d); ?>
</p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
......@@ -4,25 +4,23 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
/* @var $model app\models\Filter */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="host-form">
<div class="filter-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'domain')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'pattern')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'created')->textInput() ?>
<?= $form->field($model, 'csv_date')->textInput() ?>
<?= $form->field($model, 'include')->textInput() ?>
<?= $form->field($model, 'wis_date')->textInput() ?>
<?= $form->field($model, 'status')->textInput() ?>
<?= $form->field($model, 'wis_status')->textInput() ?>
<?= $form->field($model, 'tix')->textInput() ?>
<?= $form->field($model, 'type')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
......
......@@ -4,11 +4,11 @@ use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\HostSearch */
/* @var $model app\models\FilterSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="host-search">
<div class="filter-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
......@@ -20,17 +20,15 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'domain') ?>
<?= $form->field($model, 'pattern') ?>
<?= $form->field($model, 'created_at') ?>
<?= $form->field($model, 'created') ?>
<?= $form->field($model, 'csv_date') ?>
<?= $form->field($model, 'include') ?>
<?= $form->field($model, 'wis_date') ?>
<?= $form->field($model, 'status') ?>
<?php // echo $form->field($model, 'wis_status') ?>
<?php // echo $form->field($model, 'tix') ?>
<?php // echo $form->field($model, 'type') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
......
......@@ -3,13 +3,13 @@
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
/* @var $model app\models\Filter */
$this->title = 'Create Host';
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->title = 'Create Filter';
$this->params['breadcrumbs'][] = ['label' => 'Filters', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="host-create">
<div class="filter-create">
<h1><?= Html::encode($this->title) ?></h1>
......
<?php
use yii\jui\DatePicker;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel app\models\HostSearch */
/* @var $searchModel app\models\FilterSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'List of domains';
$this->title = 'Filters';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="host-index">
<div class="filter-index">
<h1><?= Html::encode($this->title) ?></h1>
<!--p>
<?= Html::a('Create Host', ['create'], ['class' => 'btn btn-success']) ?>
</p-->
<p>
<?= Html::a('Create Filter', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
......@@ -29,38 +28,13 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'],
'id',
'domain',
'created_at' => [
'attribute' => 'created_at',
'value' => 'created_at',
// 'format' => 'date',
/* 'filter' => DatePicker::widget([
'name' => 'created_at',
'clientOptions' => [
'format' => 'd.mm.yyyy',
'todayHighlight' => true,
]
]),*/
'pattern:ntext',
'created',
'include',
'status',
//'type',
],
'csv_date',
'wis_status' =>
[
'attribute' => 'wis_status',
'filter' => \app\models\Host::getStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getStatus($model->wis_status);
},
],
'wis_date',
'domain_expire',
'tix',
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Actions',
'template' => '{view} {delete}',
]
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
......
......@@ -3,14 +3,14 @@
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
/* @var $model app\models\Filter */
$this->title = 'Update Host: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->title = 'Update Filter: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Filters', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="host-update">
<div class="filter-update">
<h1><?= Html::encode($this->title) ?></h1>
......
......@@ -4,14 +4,14 @@ use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\Host */
/* @var $model app\models\Filter */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Hosts', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => 'Filters', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="host-view">
<div class="filter-view">
<h1><?= Html::encode($this->title) ?></h1>
......@@ -30,12 +30,11 @@ $this->params['breadcrumbs'][] = $this->title;
'model' => $model,
'attributes' => [
'id',
'domain',
'created_at',
'csv_date',
'wis_date',
'wis_status',
'tix',
'pattern:ntext',
'created',
'include',
'status',
'type',
],
]) ?>
......
yii 100644 → 100755
File mode changed
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!