Ver código fonte

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

feature/souke
Guillaume Bourgeois 1 ano atrás
pai
commit
38abe2f6ec
13 arquivos alterados com 165 adições e 9 exclusões
  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 Ver arquivo

@@ -171,4 +171,20 @@ class ProducerController extends BackendController

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 Ver arquivo

@@ -36,6 +36,8 @@
* termes.
*/

use common\components\PageSizer;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use yii\helpers\Html;
use yii\grid\GridView;
use common\logic\User\User\Wrapper\UserManager;
@@ -43,6 +45,8 @@ use common\logic\Order\Order\Model\Order;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\User\Model\User;

$producerManager = ProducerManager::getInstance();

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

+ 12
- 7
backend/web/css/screen.css Ver arquivo

@@ -1827,37 +1827,42 @@ body.skin-black .content-wrapper .submenu {
body.skin-black .main-footer a {
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 {
background: none;
background-color: white;
}
/* line 316, ../sass/_adminlte.scss */
/* line 321, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo {
text-align: center;
font-family: 'highvoltageregular';
}
/* line 320, ../sass/_adminlte.scss */
/* line 325, ../sass/_adminlte.scss */
body.login-page .login-box .login-logo img {
width: 50px;
}
/* line 325, ../sass/_adminlte.scss */
/* line 330, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary {
background-color: #F39C12;
border-color: #F39C12;
padding: 5px 10px;
}
/* line 330, ../sass/_adminlte.scss */
/* line 335, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body .btn-primary:active {
background-color: #f4a62a;
border-color: #F39C12;
}
/* line 336, ../sass/_adminlte.scss */
/* line 341, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a {
color: #F39C12;
}
/* line 338, ../sass/_adminlte.scss */
/* line 343, ../sass/_adminlte.scss */
body.login-page .login-box .login-box-body a:hover {
color: #f4a62a;
}

+ 8
- 0
backend/web/js/backend.js Ver arquivo

@@ -51,6 +51,7 @@ $(document).ready(function () {
opendistrib_menu_treeview();
opendistrib_select2();
opendistrib_dropdown_producers();
opendistrib_gridview_pagesize();
});

var UrlManager = {
@@ -63,6 +64,13 @@ var UrlManager = {
}
};

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


function opendistrib_dropdown_producers() {

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

+ 5
- 0
backend/web/sass/_adminlte.scss Ver arquivo

@@ -307,6 +307,11 @@ body.skin-black {
color: $color1 ;
}
}

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

body.login-page {

+ 34
- 0
common/components/PageSizer.php Ver arquivo

@@ -0,0 +1,34 @@
<?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 Ver arquivo

@@ -66,6 +66,9 @@ return [
'parameterBag' => [
'class' => 'common\components\ParameterBag'
],
'pageSizer' => [
'class' => 'common\components\PageSizer'
],
'assetManager' => [
'linkAssets' => YII_ENV == "dev" ? 'true' : false,
],

+ 45
- 0
common/logic/Producer/Producer/Service/ProducerPageSizer.php Ver arquivo

@@ -0,0 +1,45 @@
<?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 Ver arquivo

@@ -2,6 +2,7 @@

namespace common\logic\Producer\Producer\Service;

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

+ 2
- 0
common/logic/Producer/Producer/Wrapper/ProducerContainer.php Ver arquivo

@@ -7,6 +7,7 @@ use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\DolibarrProducerUtils;
use common\logic\Producer\Producer\Service\ProducerBuilder;
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\ProducerUtils;

@@ -20,6 +21,7 @@ class ProducerContainer extends AbstractContainer
ProducerRepository::class,
ProducerBuilder::class,
ProducerUtils::class,
ProducerPageSizer::class,
DolibarrProducerUtils::class,
];
}

+ 2
- 0
common/logic/Producer/Producer/Wrapper/ProducerManager.php Ver arquivo

@@ -7,6 +7,7 @@ use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\Producer\Producer\Service\DolibarrProducerUtils;
use common\logic\Producer\Producer\Service\ProducerBuilder;
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\ProducerUtils;

@@ -16,6 +17,7 @@ use common\logic\Producer\Producer\Service\ProducerUtils;
* @mixin ProducerRepository
* @mixin ProducerBuilder
* @mixin ProducerUtils
* @mixin ProducerPageSizer
* @mixin DolibarrProducerUtils
*/
class ProducerManager extends AbstractManager

+ 6
- 2
common/logic/User/User/Model/UserSearch.php Ver arquivo

@@ -40,6 +40,7 @@ namespace common\logic\User\User\Model;

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

@@ -62,6 +63,9 @@ class UserSearch extends User

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

$query = User::find()
->select(
'`user`.id, '
@@ -88,7 +92,7 @@ class UserSearch extends User
. '`user`.type, '
. '(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([
'query' => $query,
@@ -97,7 +101,7 @@ class UserSearch extends User
'defaultOrder' => ['created_at' => SORT_DESC]
],
'pagination' => [
'pageSize' => 20,
'pageSize' => $producerManager->getConfig('option_pagesize_user', $producer),
],
]);


+ 26
- 0
console/migrations/m231005_072832_add_column_producer_option_pagesize_user.php Ver arquivo

@@ -0,0 +1,26 @@
<?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');
}
}

Carregando…
Cancelar
Salvar