Browse Source

[Administration] Utilisateurs > liste : configuration du nombre d'utilisateurs affichés par page #1301

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
38abe2f6ec
13 changed files with 165 additions and 9 deletions
  1. +16
    -0
      backend/controllers/ProducerController.php
  2. +5
    -0
      backend/views/user/index.php
  3. +12
    -7
      backend/web/css/screen.css
  4. +8
    -0
      backend/web/js/backend.js
  5. +5
    -0
      backend/web/sass/_adminlte.scss
  6. +34
    -0
      common/components/PageSizer.php
  7. +3
    -0
      common/config/main.php
  8. +45
    -0
      common/logic/Producer/Producer/Service/ProducerPageSizer.php
  9. +1
    -0
      common/logic/Producer/Producer/Service/ProducerSolver.php
  10. +2
    -0
      common/logic/Producer/Producer/Wrapper/ProducerContainer.php
  11. +2
    -0
      common/logic/Producer/Producer/Wrapper/ProducerManager.php
  12. +6
    -2
      common/logic/User/User/Model/UserSearch.php
  13. +26
    -0
      console/migrations/m231005_072832_add_column_producer_option_pagesize_user.php

+ 16
- 0
backend/controllers/ProducerController.php View File



return $this->redirect(\Yii::$app->request->referrer); return $this->redirect(\Yii::$app->request->referrer);
} }

public function actionPagesize()
{
$producerManager = $this->getProducerManager();
$producerCurrent = $this->getProducerCurrent();
$request = Yii::$app->request;

$entity = $request->post('entity');
$pageSize = $request->post('pagesize');

$producerManager->updatePagesize($producerCurrent, $entity, $pageSize);

$referer = strtok(Yii::$app->request->referrer, "?");
return $this->redirect($referer);
}

} }

+ 5
- 0
backend/views/user/index.php View File

* termes. * termes.
*/ */


use common\components\PageSizer;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\logic\User\User\Wrapper\UserManager; use common\logic\User\User\Wrapper\UserManager;
use common\logic\User\UserProducer\Model\UserProducer; use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\User\Model\User; use common\logic\User\User\Model\User;


$producerManager = ProducerManager::getInstance();

$this->setTitle('Utilisateurs'); $this->setTitle('Utilisateurs');
$this->addBreadcrumb($this->getTitle()); $this->addBreadcrumb($this->getTitle());
$this->addButton(['label' => 'Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span>', 'url' => 'user/create', 'class' => 'btn btn-primary']); $this->addButton(['label' => 'Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span>', 'url' => 'user/create', 'class' => 'btn btn-primary']);
<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'summary' => $producerManager->getPageSizeSummary($producer, 'user', 'Utilisateurs'),
'columns' => [ 'columns' => [
[ [
'attribute' => 'username', 'attribute' => 'username',

+ 12
- 7
backend/web/css/screen.css View File

body.skin-black .main-footer a { body.skin-black .main-footer a {
color: #F39C12; color: #F39C12;
} }
/* line 311, ../sass/_adminlte.scss */
body.skin-black .gridview-pagesize {
float: right;
margin-bottom: 8px;
}


/* line 312, ../sass/_adminlte.scss */
/* line 317, ../sass/_adminlte.scss */
body.login-page { body.login-page {
background: none; background: none;
background-color: white; background-color: white;
} }
/* line 316, ../sass/_adminlte.scss */
/* line 321, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo { body.login-page .login-box .login-logo {
text-align: center; text-align: center;
font-family: 'highvoltageregular'; font-family: 'highvoltageregular';
} }
/* line 320, ../sass/_adminlte.scss */
/* line 325, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo img { body.login-page .login-box .login-logo img {
width: 50px; width: 50px;
} }
/* line 325, ../sass/_adminlte.scss */
/* line 330, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary { body.login-page .login-box .login-box-body .btn-primary {
background-color: #F39C12; background-color: #F39C12;
border-color: #F39C12; border-color: #F39C12;
padding: 5px 10px; padding: 5px 10px;
} }
/* line 330, ../sass/_adminlte.scss */
/* line 335, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary:active { body.login-page .login-box .login-box-body .btn-primary:active {
background-color: #f4a62a; background-color: #f4a62a;
border-color: #F39C12; border-color: #F39C12;
} }
/* line 336, ../sass/_adminlte.scss */
/* line 341, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a { body.login-page .login-box .login-box-body a {
color: #F39C12; color: #F39C12;
} }
/* line 338, ../sass/_adminlte.scss */
/* line 343, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a:hover { body.login-page .login-box .login-box-body a:hover {
color: #f4a62a; color: #f4a62a;
} }

+ 8
- 0
backend/web/js/backend.js View File

opendistrib_menu_treeview(); opendistrib_menu_treeview();
opendistrib_select2(); opendistrib_select2();
opendistrib_dropdown_producers(); opendistrib_dropdown_producers();
opendistrib_gridview_pagesize();
}); });


var UrlManager = { var UrlManager = {
} }
}; };


function opendistrib_gridview_pagesize() {
$('.gridview-pagesize select').change(function() {
$(this).parent().parent().submit();
});
}


function opendistrib_dropdown_producers() { function opendistrib_dropdown_producers() {


$('.producer-menu .dropdown-toggle').click(function() { $('.producer-menu .dropdown-toggle').click(function() {

+ 5
- 0
backend/web/sass/_adminlte.scss View File

color: $color1 ; color: $color1 ;
} }
} }

.gridview-pagesize {
float: right;
margin-bottom: 8px;
}
} }


body.login-page { body.login-page {

+ 34
- 0
common/components/PageSizer.php View File

<?php

namespace common\components;

use yii\helpers\Html;

class PageSizer
{
const DEFAULT_PAGE_SIZE = 25;
public static array $pageSizeOptions = [25, 50, 75, 100];

public function getForm(string $entity, string $labelEntity, int $pageSize, array $action = ['producer/pagesize'])
{
return '<form class="form-inline gridview-pagesize" method="post" action="'.\Yii::$app->urlManager->createUrl($action).'"><div class="form-group"><label class="control-label">'.$labelEntity.' par page : </label> '.
Html::hiddenInput('entity', $entity).
Html::dropDownList(
'pagesize',
$pageSize,
$this->getPageSizeOptions(),
array('class'=>'form-control')).'</div></form></div>';
}

public function getPageSizeOptions(): array
{
$pageSizeOptionsArray = [];

foreach(self::$pageSizeOptions as $pageSize) {
$pageSizeOptionsArray[$pageSize] = $pageSize;
}

return $pageSizeOptionsArray;
}

}

+ 3
- 0
common/config/main.php View File

'parameterBag' => [ 'parameterBag' => [
'class' => 'common\components\ParameterBag' 'class' => 'common\components\ParameterBag'
], ],
'pageSizer' => [
'class' => 'common\components\PageSizer'
],
'assetManager' => [ 'assetManager' => [
'linkAssets' => YII_ENV == "dev" ? 'true' : false, 'linkAssets' => YII_ENV == "dev" ? 'true' : false,
], ],

+ 45
- 0
common/logic/Producer/Producer/Service/ProducerPageSizer.php View File

<?php

namespace common\logic\Producer\Producer\Service;

use common\components\PageSizer;
use common\logic\AbstractUtils;
use common\logic\Producer\Producer\Model\Producer;

class ProducerPageSizer extends AbstractUtils
{
protected ProducerSolver $producerSolver;
protected ProducerBuilder $producerBuilder;

public function loadDependencies(): void
{
$this->producerSolver = $this->loadService(ProducerSolver::class);
$this->producerBuilder = $this->loadService(ProducerBuilder::class);
}

public function getPageSizeConfigName(string $entity)
{
return 'option_pagesize_'.$entity;
}

public function getPageSize(Producer $producer, string $entity)
{
$pageSizeConfig = $this->getPageSizeConfigName($entity);
return $this->producerSolver->getConfig($pageSizeConfig, $producer) ?: PageSizer::DEFAULT_PAGE_SIZE ;
}

public function getPageSizeSummary(Producer $producer, string $entity, string $labelEntity)
{
return \Yii::$app->pageSizer->getForm($entity, $labelEntity, $this->getPageSize($producer, $entity));
}

public function updatePagesize(Producer $producer, string $entity, int $pageSize)
{
$field = $this->getPageSizeConfigName($entity);

if(isset($producer->$field)) {
$producer->$field = $pageSize;
$this->producerBuilder->update($producer);
}
}
}

+ 1
- 0
common/logic/Producer/Producer/Service/ProducerSolver.php View File



namespace common\logic\Producer\Producer\Service; namespace common\logic\Producer\Producer\Service;


use common\components\PageSizer;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\AbstractService; use common\logic\AbstractService;
use common\logic\Producer\Producer\Model\Producer; use common\logic\Producer\Producer\Model\Producer;

+ 2
- 0
common/logic/Producer/Producer/Wrapper/ProducerContainer.php View File

use common\logic\Producer\Producer\Service\DolibarrProducerUtils; use common\logic\Producer\Producer\Service\DolibarrProducerUtils;
use common\logic\Producer\Producer\Service\ProducerBuilder; use common\logic\Producer\Producer\Service\ProducerBuilder;
use common\logic\Producer\Producer\Service\ProducerDefinition; use common\logic\Producer\Producer\Service\ProducerDefinition;
use common\logic\Producer\Producer\Service\ProducerPageSizer;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Producer\Producer\Service\ProducerUtils; use common\logic\Producer\Producer\Service\ProducerUtils;


ProducerRepository::class, ProducerRepository::class,
ProducerBuilder::class, ProducerBuilder::class,
ProducerUtils::class, ProducerUtils::class,
ProducerPageSizer::class,
DolibarrProducerUtils::class, DolibarrProducerUtils::class,
]; ];
} }

+ 2
- 0
common/logic/Producer/Producer/Wrapper/ProducerManager.php View File

use common\logic\Producer\Producer\Service\DolibarrProducerUtils; use common\logic\Producer\Producer\Service\DolibarrProducerUtils;
use common\logic\Producer\Producer\Service\ProducerBuilder; use common\logic\Producer\Producer\Service\ProducerBuilder;
use common\logic\Producer\Producer\Service\ProducerDefinition; use common\logic\Producer\Producer\Service\ProducerDefinition;
use common\logic\Producer\Producer\Service\ProducerPageSizer;
use common\logic\Producer\Producer\Service\ProducerSolver; use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Producer\Producer\Service\ProducerUtils; use common\logic\Producer\Producer\Service\ProducerUtils;


* @mixin ProducerRepository * @mixin ProducerRepository
* @mixin ProducerBuilder * @mixin ProducerBuilder
* @mixin ProducerUtils * @mixin ProducerUtils
* @mixin ProducerPageSizer
* @mixin DolibarrProducerUtils * @mixin DolibarrProducerUtils
*/ */
class ProducerManager extends AbstractManager class ProducerManager extends AbstractManager

+ 6
- 2
common/logic/User/User/Model/UserSearch.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\logic\PointSale\PointSale\Model\PointSale; use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\User\Repository\UserRepository; use common\logic\User\User\Repository\UserRepository;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;




public function search($params = []) public function search($params = [])
{ {
$producerManager = ProducerManager::getInstance();
$producer = GlobalParam::getCurrentProducer();

$query = User::find() $query = User::find()
->select( ->select(
'`user`.id, ' '`user`.id, '
. '`user`.type, ' . '`user`.type, '
. '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders'); . '(SELECT COUNT(*) FROM `order` WHERE `user`.id = `order`.id_user) AS count_orders');


$query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.id_producer = :id_producer AND user_producer.active = 1', [':id_producer' => GlobalParam::getCurrentProducerId()]);
$query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.id_producer = :id_producer AND user_producer.active = 1', [':id_producer' => $producer->id]);


$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
'defaultOrder' => ['created_at' => SORT_DESC] 'defaultOrder' => ['created_at' => SORT_DESC]
], ],
'pagination' => [ 'pagination' => [
'pageSize' => 20,
'pageSize' => $producerManager->getConfig('option_pagesize_user', $producer),
], ],
]); ]);



+ 26
- 0
console/migrations/m231005_072832_add_column_producer_option_pagesize_user.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m231005_072832_add_column_producer_option_pagesize_user
*/
class m231005_072832_add_column_producer_option_pagesize_user extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'option_pagesize_user', Schema::TYPE_INTEGER);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'option_pagesize_user');
}
}

Loading…
Cancel
Save