Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate username #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
06db0cf
Create auto-generate in User model for username
vito-makhatadze Nov 25, 2019
7af7cfc
UserController give access control role also administrator
vito-makhatadze Nov 26, 2019
c1aed66
User create roles change
vito-makhatadze Dec 3, 2019
ac29e05
Date Format Consistency
vito-makhatadze Dec 13, 2019
327b127
Showing created at and Department column under employe index
vito-makhatadze Dec 13, 2019
9bf4b20
Make statuses colorful
vito-makhatadze Dec 13, 2019
3741c50
Workin Day time format
vito-makhatadze Dec 13, 2019
0af6658
show Created at column under Departments
vito-makhatadze Dec 13, 2019
6ff4a3d
Remove index column from everywhere
vito-makhatadze Dec 17, 2019
9eb6cd4
Create different format of requests
vito-makhatadze Dec 17, 2019
824c1d4
Change views
vito-makhatadze Dec 17, 2019
97781b0
Create different formats type of requests
vito-makhatadze Dec 18, 2019
01c764e
Create different formats type of requests
vito-makhatadze Dec 18, 2019
36ae069
Change the colors stripe
vito-makhatadze Dec 23, 2019
18c1a5f
Refactor employ username autofill
vito-makhatadze Dec 23, 2019
94f52cd
Delete unused views
vito-makhatadze Dec 26, 2019
aab31d5
Change Select by {{model}}.tablename
vito-makhatadze Dec 26, 2019
cea972b
Change calendar border and background colors
vito-makhatadze Dec 26, 2019
22066dc
Change status colors
vito-makhatadze Dec 26, 2019
b661802
Allow HR and Admin roles to delete user holiday requests
vito-makhatadze Jan 8, 2020
24d6f7d
Employ colorfull statuses
vito-makhatadze Jan 8, 2020
271c98a
Working day tickbox
vito-makhatadze Jan 8, 2020
d1d95a6
Date format change
vito-makhatadze Jan 8, 2020
bd2ee1f
ID column size same the everywhere
vito-makhatadze Jan 8, 2020
d970f82
change custom request form type by busineess form
vito-makhatadze Jan 8, 2020
58a43f3
change view format
vito-makhatadze Jan 8, 2020
b5953bf
Change Roles checkbox method
vito-makhatadze Jan 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AppAsset extends AssetBundle
'js/bootstrap-tour.min.js',
'js/lobiplugins/bootstrap-datepicker.js',
'js/modal.js',
'js/user-form.js',
];

public $depends = [
Expand Down
8 changes: 6 additions & 2 deletions controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function behaviors()
'rules' => [
[
'allow' => true,
'roles' => [User::ROLE_MANAGER],
'roles' => [User::ROLE_MANAGER, User::ROLE_ADMINISTRATOR],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhatadze ROLE_ADMINISTRATOR contains ROLE_MANAGER.
ROLE_MANAGER means access granted for ROLE_ADMINISTRATOR too.

],
],
],
Expand Down Expand Up @@ -73,6 +73,10 @@ public function actionView($id)
*/
public function actionCreate()
{
//todo pass user specific roles
$userRoles = Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId());
$userRoleName = array_keys($userRoles);

$model = new UserForm();
$model->setScenario('create');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Expand All @@ -81,7 +85,7 @@ public function actionCreate()

return $this->render('create', [
'model' => $model,
'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')
'roles' => ArrayHelper::map(Yii::$app->authManager->getChildRoles($userRoleName[0]), 'name', 'name')
]);
}

Expand Down
2 changes: 1 addition & 1 deletion models/search/BankHolidaySearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function search($params)

// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'bank_holiday.id' => $this->id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhatadze It would be better to use {{Model}}::tableName() instead of hardcoded 'bank_holiday'.

'date' => $this->date,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
Expand Down
15 changes: 11 additions & 4 deletions models/search/DepartmentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class DepartmentSearch extends Department
public function rules()
{
return [
[['id', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'integer'],
[['name'], 'safe'],
[['id', 'updated_at', 'created_by', 'updated_by'], 'integer'],
[['name','created_at'], 'safe'],
[['creator'], 'safe'],

];
}

Expand Down Expand Up @@ -68,13 +69,19 @@ public function search($params)

// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'department.id' => $this->id,
'updated_at' => $this->updated_at,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
]);

if ($this->created_at) {

$query->andFilterWhere([
'FROM_UNIXTIME(department.created_at, "%Y-%m-%d")' => $this->created_at
]);
}

$query->andFilterWhere(['like', 'name', $this->name]);
if ($this->creator) {

Expand Down
25 changes: 16 additions & 9 deletions models/search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserSearch extends User
{
public function attributes()
{
return ['id', 'fullName', 'username', 'email', 'status', 'created_at', 'updated_at', 'logged_at', 'position'];
return ['id', 'fullName', 'department_id', 'username', 'email', 'status', 'created_at', 'updated_at', 'logged_at', 'position'];
}

/**
Expand All @@ -27,10 +27,11 @@ public function attributes()
public function rules()
{
return [
[['id', 'status', 'position'], 'integer'],
[['created_at', 'updated_at', 'logged_at'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['created_at', 'updated_at', 'logged_at'], 'default', 'value' => null],
[['id', 'status', 'position', 'department_id'], 'integer'],
[['updated_at', 'logged_at'], 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true],
[['updated_at', 'logged_at'], 'default', 'value' => null],
[['fullName', 'username', 'auth_key', 'password_hash', 'email'], 'safe'],
[['created_at'], 'string'],
];
}

Expand Down Expand Up @@ -62,21 +63,27 @@ public function search($params)
'desc' => ["CONCAT(up.firstname, ' ', up.lastname)" => SORT_DESC],
];

if (!( $this->load($params) && $this->validate() )) {

if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}


$query->andFilterWhere([
'id' => $this->id,
'up.id' => $this->id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhatadze It would be better to use {{Model}}::tableName() instead of hardcoded 'up'.

'position' => $this->position,
'status' => $this->status,
'department_id' => $this->department_id
]);

if ($this->created_at !== null) {
$query->andFilterWhere(['between', 'created_at', $this->created_at, $this->created_at + 3600 * 24]);
if ($this->created_at) {

$query->andFilterWhere([
'FROM_UNIXTIME(user.created_at, "%Y-%m-%d")' => $this->created_at
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makhatadze It would be better to use User::tableName() instead of hardcoded 'user'.

]);
}

if ($this->updated_at !== null) {
if ($this->updated_at) {
$query->andFilterWhere(['between', 'updated_at', $this->updated_at, $this->updated_at + 3600 * 24]);
}

Expand Down
8 changes: 5 additions & 3 deletions views/bank-holiday/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
[
'attribute' => 'id',
'value' => 'id',
'contentOptions' => ['style' => 'width:80px; '],
],
'date',
'description:ntext',
[
Expand Down
26 changes: 23 additions & 3 deletions views/department/index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use trntv\yii\datetime\DateTimeWidget;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\web\JsExpression;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
Expand All @@ -26,9 +28,11 @@
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
[
'attribute' => 'id',
'value' => 'id',
'contentOptions' => ['style' => 'width:80px; '],
],
'name',
[
'label' => Yii::t('app', 'Created By'),
Expand All @@ -38,6 +42,22 @@
return $model->creator->userProfile->getFullName();
}
],
[
'attribute' => 'created_at',
'value' => function ($model) {
return Yii::$app->formatter->asDate($model->created_at);
},
'label' => 'Created at',
'filter' => DateTimeWidget::widget([
'model' => $searchModel,
'attribute' => 'created_at',
'phpDatetimeFormat' => "yyyy-MM-dd",
'momentDatetimeFormat' => 'YYYY-MM-DD',
'clientEvents' => [
'dp.change' => new JsExpression('(e) => $(e.target).find("input").trigger("change.yiiGridView")')
],
])
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Expand Down
4 changes: 2 additions & 2 deletions views/holiday/_view_types/_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
return $model->getStatusText();
}
],
'start_date',
'start_date:date',
[
'attribute' => 'start_time',
'value' => function ($model) {
/** @var \app\models\Holiday $model */
return $model->getStartTimeText();
}
],
'end_date',
'end_date:date',
[
'attribute' => 'end_time',
'value' => function ($model) {
Expand Down
16 changes: 15 additions & 1 deletion views/request/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'id',
'value' => 'id',
'contentOptions' => ['style' => 'width:80px; '],
],
[
'attribute' => 'employee',
'value' => function ($model) {
Expand All @@ -52,6 +56,16 @@
[
'attribute' => 'status',
'filter' => Holiday::statuses(),
'contentOptions' => function ($model) {
/** @var $model Holiday */
if ($model->getStatusText() == "Accepted") {
return ['style' => 'color: green;'];
} else if ($model->getStatusText() == "Pending") {
return ['style' => 'color: #FFA500;'];
} else {
return ['style' => 'color: red;'];
}
},
'value' => function ($model) {
/** @var $model Holiday */
return $model->getStatusText();
Expand Down
6 changes: 3 additions & 3 deletions views/user/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<?php $form = ActiveForm::begin() ?>
<div class="row">
<div class="col-md-3">
<?php echo $form->field($model, 'firstname') ?>
<?php echo $form->field($model, 'firstname')->textInput(['id' => 'firstname']) ?>

</div>
<div class="col-md-3">
<?php echo $form->field($model, 'lastname') ?>
<?php echo $form->field($model, 'lastname')->textInput(['id' => 'lastname']) ?>
</div>
</div>

Expand All @@ -43,7 +43,7 @@

<div class="row">
<div class="col-md-3">
<?php echo $form->field($model, 'username') ?>
<?php echo $form->field($model, 'username')->textInput(['id' => 'username']) ?>

</div>
<div class="col-md-3">
Expand Down
2 changes: 2 additions & 0 deletions views/user/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
'roles' => $roles
]) ?>

<?php $this->registerJsFile('@web/js/user-form.js') ?>

</div>
46 changes: 43 additions & 3 deletions views/user/index.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

use app\grid\EnumColumn;
use app\models\Holiday;
use app\models\User;
use trntv\yii\datetime\DateTimeWidget;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\web\JsExpression;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
Expand Down Expand Up @@ -31,26 +34,63 @@
'class' => 'grid-view table-responsive'
],
'columns' => [
'id',
[
'attribute' => 'id',
'value' => 'id',
'contentOptions' => ['style' => 'width:80px; '],
],
[
'attribute' => 'fullName',
'value' => 'userProfile.fullName'
],
'username',
'email:email',
[
'attribute' => 'position',
'filter' => User::positions(),
'value' => function($model){
'value' => function ($model) {
return User::positions()[$model->position];
}
],

[
'attribute' => 'department_id',
'filter' => \app\models\Department::getDropdown(),
'value' => function ($model) {
return $model->department->name;
}
],
[
'class' => EnumColumn::class,
'attribute' => 'status',
'contentOptions' => function ($model) {
// user status 1 == not active, 2 == active, 3 === deleted
if ($model->status == 1) {
return ['style' => 'color: #FFA500;'];
} else if ($model->status == 2) {
return ['style' => 'color: green;'];
} else {
return ['style' => 'color: red;'];
}
},
'enum' => User::statuses(),
'filter' => User::statuses()
],
[
'attribute' => 'created_at',
'value' => function ($model) {
return Yii::$app->formatter->asDate($model->created_at);
},
'label' => 'Created at',
'filter' => DateTimeWidget::widget([
'model' => $searchModel,
'attribute' => 'created_at',
'phpDatetimeFormat' => "yyyy-MM-dd",
'momentDatetimeFormat' => 'YYYY-MM-DD',
'clientEvents' => [
'dp.change' => new JsExpression('(e) => $(e.target).find("input").trigger("change.yiiGridView")')
],
])
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} {delete}',
Expand Down
15 changes: 12 additions & 3 deletions views/working-day/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
'weekday',
// 'week_index',
'is_working_day:boolean',
'start_at',
'end_at',
[
'attribute' => 'start_at',
'value' => function ($model) {
return Yii::$app->formatter->asTime($model->start_at, 'H:mm');
}
],
[
'attribute' => 'end_at',
'value' => function ($model) {
return Yii::$app->formatter->asTime($model->end_at, 'H:mm');
}
],

[
'class' => 'yii\grid\ActionColumn',
Expand Down
Loading