Browse Source

Priorités des développements

Gestion de la priorité des développements suivant chaque établissement. Chaque producteur peut définir une priorité (basse, normale, haute) pour chaque développement.
prodstable
keun 7 years ago
parent
commit
68e9bb11a2
9 changed files with 199 additions and 19 deletions
  1. +36
    -2
      backend/controllers/DeveloppementController.php
  2. +57
    -12
      backend/views/developpement/index.php
  3. BIN
      backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc
  4. +19
    -0
      backend/web/css/screen.css
  5. +22
    -0
      backend/web/sass/screen.scss
  6. +9
    -0
      common/models/Developpement.php
  7. +38
    -4
      common/models/DeveloppementPriorite.php
  8. +1
    -1
      console/migrations/m171226_200642_tables_developpement.php
  9. +17
    -0
      console/migrations/m171227_090138_champs_priorite_developpement.php

+ 36
- 2
backend/controllers/DeveloppementController.php View File

use Yii; use Yii;
use common\models\User; use common\models\User;
use common\models\Developpement; use common\models\Developpement;
use common\models\DeveloppementPriorite;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
*/ */
public function actionIndex() { public function actionIndex() {
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => Developpement::find(),
'query' => Developpement::find()->with(['developpementPriorite','developpementPrioriteCurrentEtablissement']),
]); ]);


return $this->render('index', [ return $this->render('index', [
return $this->redirect(['index']); return $this->redirect(['index']);
} }


public function actionPriorite($id_developpement, $priorite = null) {
$developpement_priorite = DeveloppementPriorite::find()
->where(['id_developpement' => $id_developpement, 'id_etablissement' => Yii::$app->user->identity->id_etablissement])
->one() ;
if(in_array($priorite,
[DeveloppementPriorite::PRIORITE_HAUTE,
DeveloppementPriorite::PRIORITE_NORMALE,
DeveloppementPriorite::PRIORITE_BASSE])) {
if($developpement_priorite) {
$developpement_priorite->priorite = $priorite ;
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
}
else {
$developpement_priorite = new DeveloppementPriorite ;
$developpement_priorite->id_developpement = $id_developpement ;
$developpement_priorite->priorite = $priorite ;
$developpement_priorite->id_etablissement = Yii::$app->user->identity->id_etablissement ;
}
$developpement_priorite->save() ;
}
else {
if($developpement_priorite) {
$developpement_priorite->delete() ;
}
}
$this->redirect(['index']) ;
}
/** /**
* Finds the Developpement model based on its primary key value. * Finds the Developpement model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }
} }

+ 57
- 12
backend/views/developpement/index.php View File

use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\models\Developpement; use common\models\Developpement;
use common\models\DeveloppementPriorite;
use common\models\User; use common\models\User;


/* @var $this yii\web\View */ /* @var $this yii\web\View */
<?php <?php
$columns = [ $columns = [
['class' => 'yii\grid\SerialColumn'],
[
'header' => '#',
'value' => function($model) {
return '#'.$model->id ;
}
],
[ [
'attribute' => 'type', 'attribute' => 'type',
'header' => 'Type', 'header' => 'Type',
return '' ; return '' ;
}], }],
] ; ] ;
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER) {
$columns[] = [
'header' => 'Priorité',
'format' => 'raw',
'value' => function($model) {

$current_priorite = (isset($model->developpementPrioriteCurrentEtablissement)) ? $model->developpementPrioriteCurrentEtablissement->getStrPriorite() : 'Non' ;
$style_bouton = (isset($model->developpementPrioriteCurrentEtablissement)) ? $model->developpementPrioriteCurrentEtablissement->getClassCssStyleBouton() : 'default' ;
$html = '<div class="btn-group btn-group-priorite">
<button type="button" class="btn btn-priorite btn-sm btn-'.$style_bouton.' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
'.$current_priorite.' <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id]).'">Non</a></li>
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_BASSE]).'">Basse</a></li>
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_NORMALE]).'">Normale</a></li>
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/priorite','id_developpement'=>$model->id, 'priorite' => DeveloppementPriorite::PRIORITE_HAUTE]).'">Haute</a></li>
</ul>
</div><br />' ;
if(isset($model->developpementPriorite) && count($model->developpementPriorite)) {
foreach($model->developpementPriorite as $developpement_priorite) {
if($developpement_priorite->id_etablissement != Yii::$app->user->identity->id_etablissement)
$html .= '<div class="label label-priorite label-sm label-'.$developpement_priorite->getClassCssStyleBouton().'">'.Html::encode($developpement_priorite->etablissement->nom).'</div> ' ;
}
}
return $html ;
}
] ;
}
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN) {
if(Yii::$app->user->identity->status == USER::STATUS_ADMIN) {
$columns[] = [ $columns[] = [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'template' => '{update}',
'headerOptions' => ['class' => 'actions'], 'headerOptions' => ['class' => 'actions'],
'buttons' => [ 'buttons' => [
'update' => function ($url, $model) { 'update' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
return '<div class="btn-group">
<a href="'.$url.'" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="'.Yii::$app->urlManager->createUrl(['developpement/delete','id' => $model->id]).'" class=""><span class="glyphicon glyphicon-trash"></span> Supprimer</a></li>
</ul>
</div>' ;
}, },
'delete' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Suprimer', $url, [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}
], ],
] ; ] ;
} }
<?= <?=
GridView::widget([ GridView::widget([
'id' => 'tab-developpements',
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'columns' => $columns 'columns' => $columns
]); ]);

BIN
backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc View File


+ 19
- 0
backend/web/css/screen.css View File

padding: 10px; padding: 10px;
text-align: center; text-align: center;
} }

/* line 1230, ../sass/screen.scss */
.developpement-index #tab-developpements .btn-group-priorite {
width: 100%;
margin-bottom: 5px;
}
/* line 1234, ../sass/screen.scss */
.developpement-index #tab-developpements .btn-group-priorite .btn-priorite {
display: block;
float: none;
width: 100%;
}
/* line 1241, ../sass/screen.scss */
.developpement-index #tab-developpements .label-priorite {
display: block;
width: 100%;
margin-bottom: 2px;
padding: 5px 8px;
}

+ 22
- 0
backend/web/sass/screen.scss View File

padding: 10px ; padding: 10px ;
text-align: center ; text-align: center ;
} }
}

.developpement-index {
#tab-developpements {
.btn-group-priorite {
width: 100% ;
margin-bottom: 5px ;

.btn-priorite {
display: block ;
float: none ;
width: 100% ;
}
}
.label-priorite {
display: block ;
width: 100% ;
margin-bottom: 2px ;
padding: 5px 8px ;
}
}
} }

+ 9
- 0
common/models/Developpement.php View File

namespace common\models; namespace common\models;


use Yii; use Yii;
use common\models\DeveloppementPriorite ;


/** /**
* This is the model class for table "developpement". * This is the model class for table "developpement".
[['objet', 'statut','type'], 'string', 'max' => 255], [['objet', 'statut','type'], 'string', 'max' => 255],
]; ];
} }
public function getDeveloppementPriorite() {
return $this->hasMany(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->with('etablissement') ;
}
public function getDeveloppementPrioriteCurrentEtablissement() {
return $this->hasOne(DeveloppementPriorite::className(), ['id_developpement' => 'id'])->where(['id_etablissement'=>Yii::$app->user->identity->id_etablissement])->with('etablissement') ;
}


/** /**
* @inheritdoc * @inheritdoc

+ 38
- 4
common/models/DeveloppementPriorite.php View File

namespace common\models; namespace common\models;


use Yii; use Yii;
use common\models\Etablissement ;


/** /**
* This is the model class for table "developpement_priorite". * This is the model class for table "developpement_priorite".
*/ */
class DeveloppementPriorite extends \yii\db\ActiveRecord { class DeveloppementPriorite extends \yii\db\ActiveRecord {


const PRIORITE_HAUTE = 'haute' ;
const PRIORITE_NORMALE = 'normale' ;
const PRIORITE_BASSE = 'basse' ;
/** /**
* @inheritdoc * @inheritdoc
*/ */
*/ */
public function rules() { public function rules() {
return [ return [
[['id_user', 'id_developpement'], 'required'],
[['id_user', 'id_developpement'], 'integer'],
[['id_etablissement', 'id_developpement'], 'required'],
[['id_etablissement', 'id_developpement'], 'integer'],
[['priorite'], 'string'],
]; ];
} }
public function getEtablissement() {
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ;
}


/** /**
* @inheritdoc * @inheritdoc
*/ */
public function attributeLabels() { public function attributeLabels() {
return [ return [
'id_user' => 'Id User',
'id_developpement' => 'Id Developpement',
'id_etablissement' => 'Établissement',
'id_developpement' => 'Développement',
'priorite' => 'Priorité'
]; ];
} }
public function getStrPriorite()
{
switch($this->priorite)
{
case self::PRIORITE_BASSE : return 'Basse' ; break ;
case self::PRIORITE_NORMALE : return 'Normale' ; break ;
case self::PRIORITE_HAUTE : return 'Haute' ; break ;
default: return 'Non définie' ; break ;
}
}
public function getClassCssStyleBouton() {
$style_bouton = 'default' ;
if($this->priorite == DeveloppementPriorite::PRIORITE_BASSE)
$style_bouton = 'info' ;
elseif($this->priorite == DeveloppementPriorite::PRIORITE_NORMALE)
$style_bouton = 'warning' ;
elseif($this->priorite == DeveloppementPriorite::PRIORITE_HAUTE)
$style_bouton = 'danger' ;
return $style_bouton ;
}


} }

+ 1
- 1
console/migrations/m171226_200642_tables_developpement.php View File

]); ]);


$this->createTable('developpement_priorite', [ $this->createTable('developpement_priorite', [
'id_user' => Schema::TYPE_INTEGER . ' NOT NULL',
'id_etablissement' => Schema::TYPE_INTEGER . ' NOT NULL',
'id_developpement' => Schema::TYPE_INTEGER . ' NOT NULL', 'id_developpement' => Schema::TYPE_INTEGER . ' NOT NULL',
'PRIMARY KEY (`id_user`, `id_developpement`)' 'PRIMARY KEY (`id_user`, `id_developpement`)'
]); ]);

+ 17
- 0
console/migrations/m171227_090138_champs_priorite_developpement.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;
use common\models\DeveloppementPriorite ;

class m171227_090138_champs_priorite_developpement extends Migration {

public function up() {
$this->addColumn('developpement_priorite','priorite',Schema::TYPE_STRING.' DEFAULT \''.DeveloppementPriorite::PRIORITE_NORMALE.'\'');
}

public function down() {
$this->dropColumn('developpement_priorite','priorite');
}
}

Loading…
Cancel
Save