Skip to content

Commit 720f6e3

Browse files
committed
moved settings feature logic in its own module
Signed-off-by: MarioRadu <magda_marior@yahoo.com>
1 parent fad6b3c commit 720f6e3

File tree

7 files changed

+19
-36
lines changed

7 files changed

+19
-36
lines changed

src/Admin/src/Handler/Admin/GetAdminListHandler.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Admin\App\Common\ServerRequestAwareTrait;
1111
use Admin\App\Pagination;
1212
use Admin\Setting\Entity\Setting;
13-
use Admin\Setting\Service\SettingService;
1413
use Dot\DependencyInjection\Attribute\Inject;
1514
use Laminas\Authentication\AuthenticationServiceInterface;
1615
use Laminas\Diactoros\Response\HtmlResponse;
@@ -30,15 +29,13 @@ class GetAdminListHandler implements RequestHandlerInterface
3029
TemplateRendererInterface::class,
3130
AuthenticationServiceInterface::class,
3231
AdminForm::class,
33-
SettingService::class,
3432
)]
3533
public function __construct(
3634
protected AdminServiceInterface $adminService,
3735
protected RouterInterface $router,
3836
protected TemplateRendererInterface $template,
3937
protected AuthenticationServiceInterface $authenticationService,
4038
protected AdminForm $form,
41-
protected SettingService $settingService,
4239
) {
4340
}
4441

@@ -61,21 +58,13 @@ public function handle(ServerRequestInterface $request): ResponseInterface
6158
$params['order'],
6259
);
6360

64-
$settings = $this->settingService->findOneBy([
65-
'admin' => $this->adminService->getAdminRepository()->findOneBy([
66-
'identity' => $this->authenticationService->getIdentity()->getIdentity(),
67-
]),
68-
'identifier' => Setting::IDENTIFIER_TABLE_ADMIN_LIST_SELECTED_COLUMNS,
69-
]);
70-
7161
$this->form->setAttribute('action', $this->router->generateUri('admin::admin-create'));
7262

7363
return new HtmlResponse(
7464
$this->template->render('admin::list', [
7565
'params' => $params,
7666
'admins' => $result['rows'],
7767
'statuses' => Admin::STATUSES,
78-
'settings' => $settings?->getValue() ?? [],
7968
'identifier' => Setting::IDENTIFIER_TABLE_ADMIN_LIST_SELECTED_COLUMNS,
8069
'form' => $this->form->prepare(),
8170
'pagination' => new Pagination($result['total'], $result['offset'], $result['limit']),

src/Admin/src/Handler/Admin/GetAdminLoginListHandler.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Admin\App\Common\ServerRequestAwareTrait;
1010
use Admin\App\Pagination;
1111
use Admin\Setting\Entity\Setting;
12-
use Admin\Setting\Service\SettingService;
1312
use Dot\DependencyInjection\Attribute\Inject;
1413
use Laminas\Authentication\AuthenticationServiceInterface;
1514
use Laminas\Diactoros\Response\HtmlResponse;
@@ -26,13 +25,11 @@ class GetAdminLoginListHandler implements RequestHandlerInterface
2625
AdminServiceInterface::class,
2726
TemplateRendererInterface::class,
2827
AuthenticationServiceInterface::class,
29-
SettingService::class,
3028
)]
3129
public function __construct(
3230
protected AdminServiceInterface $adminService,
3331
protected TemplateRendererInterface $template,
3432
protected AuthenticationServiceInterface $authenticationService,
35-
protected SettingService $settingService,
3633
) {
3734
}
3835

@@ -58,18 +55,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
5855
]
5956
);
6057

61-
$settings = $this->settingService->findOneBy([
62-
'admin' => $this->adminService->getAdminRepository()->findOneBy([
63-
'identity' => $this->authenticationService->getIdentity()->getIdentity(),
64-
]),
65-
'identifier' => Setting::IDENTIFIER_TABLE_ADMIN_LIST_LOGINS_SELECTED_COLUMNS,
66-
]);
67-
6858
return new HtmlResponse(
6959
$this->template->render('admin::list-logins', [
7060
'params' => $params,
7161
'logins' => $logins['rows'],
72-
'settings' => $settings?->getValue() ?? [],
7362
'statuses' => [AdminLogin::LOGIN_FAIL, AdminLogin::LOGIN_SUCCESS],
7463
'identities' => $this->adminService->getAdminLoginIdentities(),
7564
'identifier' => Setting::IDENTIFIER_TABLE_ADMIN_LIST_LOGINS_SELECTED_COLUMNS,

src/Admin/templates/admin/list-logins.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
<script>
184184
const tableId = '#admin-logins-table';
185185
const storeSettingsUrl = '{{ path('setting::setting-store', {identifier: identifier}) }}';
186-
const columnsSettings = JSON.parse('{{ settings|json_encode()|raw }}');
186+
const getSettingsUrl = '{{ path('setting::setting-view', {identifier: identifier}) }}';
187187
</script>
188188
<script src="{{ asset('js/table_settings.js') }}" defer></script>
189189
{% endblock %}

src/Admin/templates/admin/list.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
<script>
138138
const tableId = '#admin-table';
139139
const storeSettingsUrl = '{{ path('setting::setting-store', {identifier: identifier}) }}';
140-
const columnsSettings = JSON.parse('{{ settings|json_encode()|raw }}');
140+
const getSettingsUrl = '{{ path('setting::setting-view', {identifier: identifier}) }}';
141141
</script>
142142
<script src="{{ asset('js/table_settings.js') }}" defer></script>
143143
<script src="{{ asset('js/admin.js') }}" defer></script>

src/App/assets/js/components/_table_settings.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ $(function() {
44
return;
55
}
66

7-
if (! columnsSettings) {
8-
console.error("Invalid or no column settings provided.")
7+
if (! getSettingsUrl) {
8+
console.error("Invalid or no getSettingsUrl provided.")
99
return;
1010
}
1111

@@ -14,12 +14,19 @@ $(function() {
1414
return;
1515
}
1616

17+
const getSettings = () => {
18+
return fetch(getSettingsUrl, {
19+
method: 'GET',
20+
});
21+
};
22+
1723
const hideColumns = (tableId, visibleColumns) => {
1824
const table = $(tableId);
1925
if (visibleColumns.length === 0) {
2026
table.show();
2127
return;
2228
}
29+
2330
$('.table-column').each((_, element) => {
2431
const column = $(element).data('column');
2532
toggleColumnVisibility(column, visibleColumns.includes(column));
@@ -92,9 +99,6 @@ $(function() {
9299
}
93100
}
94101

95-
populateColumnSelector('#column-selector', columnsSettings);
96-
hideColumns(tableId, columnsSettings);
97-
98102
$(document).on('change', '.toggle-column-checkbox', function () {
99103
const table = $(tableId);
100104
if (! table) {
@@ -124,4 +128,12 @@ $(function() {
124128
$(document).on('click', '.ui-checkbox', function (e) {
125129
$(e.currentTarget).prop('checked', !$(e.currentTarget).prop('checked'));
126130
});
131+
132+
getSettings()
133+
.then((response) => response.json())
134+
.then(settings => {
135+
populateColumnSelector('#column-selector', settings.data.value);
136+
hideColumns(tableId, settings.data.value);
137+
})
138+
.catch(error => console.error('Error: ', error));
127139
});

test/Unit/Admin/Handler/Admin/GetAdminListHandlerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function testListAdminWillReturnHtmlResponse(): void
3131
$template = $this->createMock(TemplateRendererInterface::class);
3232
$authenticationService = $this->createMock(AuthenticationServiceInterface::class);
3333
$form = $this->createMock(AdminForm::class);
34-
$settingService = $this->createMock(SettingService::class);
3534
$adminRepository = $this->createMock(AdminRepository::class);
3635

37-
$settingService->method('findOneBy')->willReturn(null);
3836
$adminRepository->method('findOneBy')->willReturn($this->createMock(Admin::class));
3937
$adminService->method('getAdmins')->willReturn([
4038
'rows' => [],
@@ -56,7 +54,6 @@ public function testListAdminWillReturnHtmlResponse(): void
5654
$template,
5755
$authenticationService,
5856
$form,
59-
$settingService,
6057
);
6158

6259
$response = $handler->handle($this->createMock(ServerRequestInterface::class));

test/Unit/Admin/Handler/Admin/GetAdminLoginListHandlerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Admin\Admin\Handler\Admin\GetAdminLoginListHandler;
1111
use Admin\Admin\Repository\AdminRepository;
1212
use Admin\Admin\Service\AdminServiceInterface;
13-
use Admin\Setting\Service\SettingService;
1413
use AdminTest\Unit\UnitTest;
1514
use Fig\Http\Message\StatusCodeInterface;
1615
use Laminas\Authentication\AuthenticationServiceInterface;
@@ -29,10 +28,8 @@ public function testListAdminWillReturnHtmlResponse(): void
2928
$template = $this->createMock(TemplateRendererInterface::class);
3029
$authenticationService = $this->createMock(AuthenticationServiceInterface::class);
3130
$form = $this->createMock(AdminForm::class);
32-
$settingService = $this->createMock(SettingService::class);
3331
$adminRepository = $this->createMock(AdminRepository::class);
3432

35-
$settingService->method('findOneBy')->willReturn(null);
3633
$adminRepository->method('findOneBy')->willReturn($this->createMock(Admin::class));
3734
$adminService->method('getAdminLogins')->willReturn([
3835
'rows' => [],
@@ -52,7 +49,6 @@ public function testListAdminWillReturnHtmlResponse(): void
5249
$adminService,
5350
$template,
5451
$authenticationService,
55-
$settingService,
5652
);
5753

5854
$response = $handler->handle($this->createMock(ServerRequestInterface::class));

0 commit comments

Comments
 (0)