Skip to content

Commit

Permalink
Merge pull request #5038 from refine-kenshi/refine-kenshi/feature/sor…
Browse files Browse the repository at this point in the history
…t_admin

管理画面:ソート機能追加(商品一覧・受注一覧・会員一覧)
  • Loading branch information
chihiro-adachi authored Jan 27, 2022
2 parents 9cbd803 + 2e5a796 commit 0e60516
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 36 deletions.
19 changes: 19 additions & 0 deletions html/template/admin/assets/css/bootstrap.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion html/template/admin/assets/css/bootstrap.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/admin/assets/css/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/admin/assets/css/bootstrap.min.css.map

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions html/template/admin/assets/js/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,32 @@ var searchWord = function (searchText, el) {
}
});
};

// 一覧ページのソート機能
$(function() {
if ($('.js-listSort').length < 1) {
return;
}

// 現在のソート状況をボタン表示に反映
const sortkey = $('.js-listSort-key').val();
const target = $('.js-listSort').filter('[data-sortkey="' + sortkey + '"]');
if (target.length === 1) {
target.addClass('listSort-current');
if ($('.js-listSort-type').val() === 'd') {
target.find('.fa').addClass('fa-arrow-down').removeClass('fa-arrow-up');
}
}

// ソート実施
$('.js-listSort').on({
click: function (e) {
const sortkey = $(e.currentTarget).data('sortkey');
const sorttype = ($('.js-listSort-key').val() === sortkey && $('.js-listSort-type').val() !== 'd') ? 'd' : 'a';
$('.js-listSort-key').val(sortkey);
$('.js-listSort-type').val(sorttype);
$('#search_form').submit();
e.preventDefault();
}
});
});
33 changes: 33 additions & 0 deletions html/template/admin/assets/scss/component/_bootstrapOriginal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,36 @@ Styleguide 12.7
*/
.text-ec-gray { color: #999 !important; }
.text-ec-lightGray { color: #ccc !important; }

/*
一覧ソートボタン
一覧ページでのソートボタン用のクラスを定義しています
*/
.js-listSort {
color: $black40;

&:hover {
color: $black40;
}

&.listSort-current {
color: $black85;
}

.fa {
display:inline-block;
width: 1em;
margin-left: 3px;
}

&:hover {
.fa-arrow-up:before {
content: "\f0aa"; // fa-arrow-circle-up
}

.fa-arrow-down:before {
content: "\f0ab"; // fa-arrow-circle-down
}
}
}
22 changes: 16 additions & 6 deletions src/Eccube/Controller/Admin/Order/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,22 @@ public function index(Request $request, $page_no = null, PaginatorInterface $pag
);

$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event);

$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count
);
$sortKey = $searchData['sortkey'];

if (empty($this->orderRepository::COLUMNS[$sortKey]) || $sortKey == 'order_status') {
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count
);
} else {
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count,
['wrap-queries' => true]
);
}

return [
'searchForm' => $searchForm->createView(),
Expand Down
21 changes: 16 additions & 5 deletions src/Eccube/Controller/Admin/Product/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,22 @@ public function index(Request $request, $page_no = null, PaginatorInterface $pag

$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_INDEX_SEARCH, $event);

$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count
);
$sortKey = $searchData['sortkey'];

if (empty($this->productRepository::COLUMNS[$sortKey]) || $sortKey == 'code' || $sortKey == 'status') {
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count
);
} else {
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count,
['wrap-queries' => true]
);
}

return [
'searchForm' => $searchForm->createView(),
Expand Down
10 changes: 10 additions & 0 deletions src/Eccube/Form/Type/Admin/SearchCustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

Expand Down Expand Up @@ -321,6 +322,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'data-toggle' => 'datetimepicker',
],
])
// ソート用
->add('sortkey', HiddenType::class, [
'label' => 'admin.list.sort.key',
'required' => false,
])
->add('sorttype', HiddenType::class, [
'label' => 'admin.list.sort.type',
'required' => false,
])
;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Eccube/Form/Type/Admin/SearchOrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

Expand Down Expand Up @@ -328,6 +329,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'admin.order.purchase_product',
'required' => false,
])
// ソート用
->add('sortkey', HiddenType::class, [
'label' => 'admin.list.sort.key',
'required' => false,
])
->add('sorttype', HiddenType::class, [
'label' => 'admin.list.sort.type',
'required' => false,
]);
;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Eccube/Form/Type/Admin/SearchProductType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

class SearchProductType extends AbstractType
{
Expand Down Expand Up @@ -214,6 +215,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'data-toggle' => 'datetimepicker',
],
])
// ソート用
->add('sortkey', HiddenType::class, [
'label' => 'admin.list.sort.key',
'required' => false,
])
->add('sorttype', HiddenType::class, [
'label' => 'admin.list.sort.type',
'required' => false,
])
;
}

Expand Down
15 changes: 14 additions & 1 deletion src/Eccube/Repository/CustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class CustomerRepository extends AbstractRepository
*/
protected $encoderFactory;

public const COLUMNS = [
'customer_id' => 'c.id'
,'name'=> 'c.name01'
];

/**
* CustomerRepository constructor.
*
Expand Down Expand Up @@ -280,7 +285,15 @@ public function getQueryBuilderBySearchData($searchData)
}

// Order By
$qb->addOrderBy('c.update_date', 'DESC');
if (isset($searchData['sortkey']) && !empty($searchData['sortkey'])) {
$sortOrder = (isset($searchData['sorttype']) && $searchData['sorttype'] == 'a') ? 'ASC' : 'DESC';
$qb->orderBy(self::COLUMNS[$searchData['sortkey']], $sortOrder);
$qb->addOrderBy('c.update_date', 'DESC');
$qb->addOrderBy('c.id', 'DESC');
} else {
$qb->orderBy('c.update_date', 'DESC');
$qb->addOrderBy('c.id', 'DESC');
}

return $this->queries->customize(QueryKey::CUSTOMER_SEARCH, $qb, $searchData);
}
Expand Down
26 changes: 24 additions & 2 deletions src/Eccube/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class OrderRepository extends AbstractRepository
*/
protected $queries;

public const COLUMNS = [
'order' => 'o.name01'
,'orderer'=> 'o.id'
,'shipping_id'=> 's.id'
,'purchase_product' => 'oi.product_name'
,'quantity' => 'oi.quantity'
,'payment_method' => 'o.payment_method'
,'order_status' => 'o.OrderStatus'
,'purchase_price' => 'o.total'
,'shipping_status' => 's.shipping_date'
,'tracking_number' => 's.tracking_number'
,'delivery' => 's.name01'
];

/**
* OrderRepository constructor.
*
Expand Down Expand Up @@ -352,8 +366,16 @@ public function getQueryBuilderBySearchDataForAdmin($searchData)
}

// Order By
$qb->orderBy('o.update_date', 'DESC');
$qb->addorderBy('o.id', 'DESC');
if (isset($searchData['sortkey']) && !empty($searchData['sortkey'])) {
$sortOrder = (isset($searchData['sorttype']) && $searchData['sorttype'] == 'a') ? 'ASC' : 'DESC';

$qb->orderBy(self::COLUMNS[$searchData['sortkey']], $sortOrder);
$qb->addOrderBy('o.update_date', 'DESC');
$qb->addOrderBy('o.id', 'DESC');
} else {
$qb->orderBy('o.update_date', 'DESC');
$qb->addorderBy('o.id', 'DESC');
}

return $this->queries->customize(QueryKey::ORDER_SEARCH_ADMIN, $qb, $searchData);
}
Expand Down
22 changes: 20 additions & 2 deletions src/Eccube/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class ProductRepository extends AbstractRepository
*/
protected $eccubeConfig;

public const COLUMNS = [
'product_id' => 'p.id'
,'name' => 'p.name'
,'product_code' => 'pc.code'
,'stock' => 'pc.stock'
,'status' => 'p.Status'
,'create_date' => 'p.create_date'
,'update_date' => 'p.update_date'
];

/**
* ProductRepository constructor.
*
Expand Down Expand Up @@ -366,8 +376,16 @@ public function getQueryBuilderBySearchDataForAdmin($searchData)
}

// Order By
$qb
->orderBy('p.update_date', 'DESC');
if (isset($searchData['sortkey']) && !empty($searchData['sortkey'])) {
$sortOrder = (isset($searchData['sorttype']) && $searchData['sorttype'] == 'a') ? 'ASC' : 'DESC';

$qb->orderBy(self::COLUMNS[$searchData['sortkey']], $sortOrder);
$qb->addOrderBy('p.update_date', 'DESC');
$qb->addOrderBy('p.id', 'DESC');
} else {
$qb->orderBy('p.update_date', 'DESC');
$qb->addOrderBy('p.id', 'DESC');
}

return $this->queries->customize(QueryKey::PRODUCT_SEARCH_ADMIN, $qb, $searchData);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1786,3 +1786,9 @@ purchase_flow.over_stock: '%name% does not have enough stock.'
#------------------------------------------------------------------------------------

command.composer_require_already_installed.not_supported_plugin: '%name% %plugin_version% does not support EC-CUBE %eccube_version% . Do you want to continue?'

#------------------------------------------------------------------------------------
# ソート機能
#------------------------------------------------------------------------------------
admin.list.sort.key: listSortKey
admin.list.sort.type: listSortType
6 changes: 6 additions & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1786,3 +1786,9 @@ purchase_flow.over_stock: '「%name%」の在庫が足りません。'
#------------------------------------------------------------------------------------

command.composer_require_already_installed.not_supported_plugin: '%name% %plugin_version% は EC-CUBE %eccube_version% には対応していません。続行しますか?'

#------------------------------------------------------------------------------------
# ソート機能
#------------------------------------------------------------------------------------
admin.list.sort.key: listSortKey # 検索条件の表示制御に利用
admin.list.sort.type: listSortType # 検索条件の表示制御に利用
7 changes: 4 additions & 3 deletions src/Eccube/Resource/template/admin/Customer/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ file that was distributed with this source code.
$(this).val($(this).data('value'));
});
});
</script>
{% endblock javascript %}

Expand Down Expand Up @@ -288,6 +287,8 @@ file that was distributed with this source code.
</div>
{% endfor %}
</div>
{{ form_widget(searchForm.sortkey, {'attr': {'class': 'js-listSort-key'}}) }}
{{ form_widget(searchForm.sorttype, {'attr': {'class': 'js-listSort-type'}}) }}
</div>
<div class="c-outsideBlock__contents mb-5">
<button type="submit" class="btn btn-ec-conversion px-5">{{ 'admin.common.search'|trans }}</button>
Expand Down Expand Up @@ -330,8 +331,8 @@ file that was distributed with this source code.
<table class="table">
<thead>
<tr>
<th class="border-top-0 pt-2 pb-3 pl-3 text-nowrap">{{ 'admin.customer.customer_id'|trans }}</th>
<th class="border-top-0 pt-2 pb-3">{{ 'admin.common.name'|trans }}</th>
<th class="border-top-0 pt-2 pb-3 pl-3 text-nowrap">{{ 'admin.customer.customer_id'|trans }}<a href="#" class="js-listSort" data-sortkey="customer_id"><i class="fa fa-arrow-up" aria-hidden="true"></i></a></th>
<th class="border-top-0 pt-2 pb-3">{{ 'admin.common.name'|trans }}<a href="#" class="js-listSort" data-sortkey="name"><i class="fa fa-arrow-up" aria-hidden="true"></i></a></th>
<th class="border-top-0 pt-2 pb-3">{{ 'admin.common.phone_number'|trans }}</th>
<th class="border-top-0 pt-2 pb-3">{{ 'admin.common.mail_address'|trans }}</th>
<th class="border-top-0 pt-2 pb-3">&nbsp;</th>
Expand Down
Loading

0 comments on commit 0e60516

Please sign in to comment.