Skip to content

Commit 990cf66

Browse files
rogeriolinoclaude
andcommitted
feat: add per-user behavior override UI and endpoint (#452)
- New UpdateUsuarioBehaviorDto for PUT /usuario/{id}/behavior - DefaultController: inject settings service and usuario metadata repository; expose behavior overrides per user in index(); add updateUsuarioBehavior() endpoint - Template: behavior card with dropdowns for callTicketByService and callTicketOutOfOrder (null = inherit global) - JS: updateUsuarioBehavior() method calling the new PUT endpoint - Translations: add label.yes, label.no, settings.user.behavior, settings.user.call_ticket_by_service, settings.user.call_ticket_out_of_order, settings.user.use_global for en, en_US, es, es_AR, pt_BR, pt_PT Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 366f925 commit 990cf66

10 files changed

Lines changed: 393 additions & 93 deletions

‎src/Controller/DefaultController.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
use Novosga\Repository\ServicoRepositoryInterface;
2323
use Novosga\Repository\ServicoUnidadeRepositoryInterface;
2424
use Novosga\Repository\ServicoUsuarioRepositoryInterface;
25+
use Novosga\Repository\UsuarioMetadataRepositoryInterface;
2526
use Novosga\Repository\UsuarioRepositoryInterface;
27+
use Novosga\Service\ApplicationSettingsServiceInterface;
2628
use Novosga\Service\AtendimentoServiceInterface;
2729
use Novosga\Service\FilaServiceInterface;
2830
use Novosga\Service\ServicoServiceInterface;
2931
use Novosga\Service\UnidadeServiceInterface;
3032
use Novosga\Service\UsuarioServiceInterface;
3133
use Novosga\SettingsBundle\Dto\AddServicosDto;
34+
use Novosga\SettingsBundle\Dto\UpdateUsuarioBehaviorDto;
3235
use Novosga\SettingsBundle\Dto\UpdateUsuarioDto;
3336
use Novosga\SettingsBundle\Dto\UpdateUsuarioServicoDto;
3437
use Novosga\SettingsBundle\Form\ImpressaoType;
@@ -57,9 +60,11 @@ class DefaultController extends AbstractController
5760
{
5861
#[Route("/", name: "index", methods: ['GET'])]
5962
public function index(
63+
ApplicationSettingsServiceInterface $settingsService,
6064
ServicoServiceInterface $servicoService,
6165
UsuarioServiceInterface $usuarioService,
6266
UsuarioRepositoryInterface $usuarioRepository,
67+
UsuarioMetadataRepositoryInterface $usuarioMetadataRepository,
6368
LocalRepositoryInterface $localRepository,
6469
ServicoUsuarioRepositoryInterface $servicoUsuarioRepository,
6570
TranslatorInterface $translator,
@@ -83,6 +88,7 @@ public function index(
8388
$unidade,
8489
$servicosUnidade,
8590
$usuarioService,
91+
$usuarioMetadataRepository,
8692
$servicoUsuarioRepository,
8793
) {
8894
$servicosUsuario = $servicoUsuarioRepository->getAll($usuario, $unidade);
@@ -115,6 +121,13 @@ public function index(
115121
$numeroMeta = $usuarioService->meta($usuario, UsuarioServiceInterface::ATTR_ATENDIMENTO_NUM_LOCAL);
116122
$data['numero'] = $numeroMeta ? (int) $numeroMeta->getValue() : null;
117123

124+
$behaviorMeta = $usuarioMetadataRepository->get($usuario, 'novosga.settings', 'behavior');
125+
$overrides = $behaviorMeta ? $behaviorMeta->getValue() : [];
126+
$data['behavior'] = [
127+
'callTicketByService' => $overrides['callTicketByService'] ?? null,
128+
'callTicketOutOfOrder' => $overrides['callTicketOutOfOrder'] ?? null,
129+
];
130+
118131
return $data;
119132
}, $usuarios);
120133

@@ -129,6 +142,7 @@ public function index(
129142
'locais' => $locais,
130143
'usuarios' => $usuariosArray,
131144
'tiposAtendimento' => $tiposAtendimento,
145+
'globalBehavior' => $settingsService->loadBehaviorSettings(),
132146
'form' => $form,
133147
'inlineForm' => $inlineForm,
134148
'impressaoForm' => $impressaoForm,
@@ -546,6 +560,29 @@ public function updateUsuario(
546560
));
547561
}
548562

563+
#[Route("/usuario/{id}/behavior", name: "update_usuario_behavior", methods: ['PUT'])]
564+
public function updateUsuarioBehavior(
565+
ApplicationSettingsServiceInterface $settingsService,
566+
UsuarioServiceInterface $usuarioService,
567+
#[MapRequestPayload] UpdateUsuarioBehaviorDto $data,
568+
int $id,
569+
): Response {
570+
/** @var UsuarioInterface */
571+
$usuarioAtual = $this->getUser();
572+
$unidade = $usuarioAtual->getLotacao()->getUnidade();
573+
574+
$usuario = $usuarioService->getById($id);
575+
if (!$usuario) {
576+
throw $this->createNotFoundException();
577+
}
578+
579+
$settingsService->saveUserBehaviorSettings($usuario, $data->callTicketByService, $data->callTicketOutOfOrder);
580+
581+
return $this->json(new Envelope(
582+
timezone: $unidade->getDateTimeZone(),
583+
));
584+
}
585+
549586
/** @return array<string,string> */
550587
private function getTiposAtendimento(TranslatorInterface $translator): array
551588
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Novo SGA project.
7+
*
8+
* (c) Rogerio Lino <rogeriolino@gmail.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Novosga\SettingsBundle\Dto;
15+
16+
final readonly class UpdateUsuarioBehaviorDto
17+
{
18+
public function __construct(
19+
public ?bool $callTicketByService,
20+
public ?bool $callTicketOutOfOrder,
21+
) {
22+
}
23+
}

‎src/Resources/public/js/script.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@
263263
}
264264
});
265265
},
266+
267+
updateUsuarioBehavior: function (usuario) {
268+
App.ajax({
269+
url: App.url('/novosga.settings/usuario/') + usuario.id + '/behavior',
270+
type: 'put',
271+
data: {
272+
callTicketByService: usuario.behavior.callTicketByService,
273+
callTicketOutOfOrder: usuario.behavior.callTicketOutOfOrder,
274+
}
275+
});
276+
},
266277
},
267278
mounted() {
268279
this.servicosModal = new bootstrap.Modal(this.$refs.servicosModal);

‎src/Resources/translations/NovosgaSettingsBundle.en.xlf‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,37 @@
8989
<trans-unit id="14">
9090
<source>label.schedule</source>
9191
<target>Scheduling</target>
92-
92+
93+
</trans-unit>
94+
<trans-unit id="15">
95+
<source>label.yes</source>
96+
<target>Yes</target>
97+
98+
</trans-unit>
99+
<trans-unit id="16">
100+
<source>label.no</source>
101+
<target>No</target>
102+
103+
</trans-unit>
104+
<trans-unit id="17">
105+
<source>settings.user.behavior</source>
106+
<target>Behavior</target>
107+
108+
</trans-unit>
109+
<trans-unit id="18">
110+
<source>settings.user.call_ticket_by_service</source>
111+
<target>Call by service</target>
112+
113+
</trans-unit>
114+
<trans-unit id="19">
115+
<source>settings.user.call_ticket_out_of_order</source>
116+
<target>Call out of order</target>
117+
118+
</trans-unit>
119+
<trans-unit id="20">
120+
<source>settings.user.use_global</source>
121+
<target>Global default</target>
122+
93123
</trans-unit>
94124
</body>
95125
</file>

‎src/Resources/translations/NovosgaSettingsBundle.en_US.xlf‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,37 @@
8989
<trans-unit id="14">
9090
<source>label.schedule</source>
9191
<target>Scheduling</target>
92-
92+
93+
</trans-unit>
94+
<trans-unit id="15">
95+
<source>label.yes</source>
96+
<target>Yes</target>
97+
98+
</trans-unit>
99+
<trans-unit id="16">
100+
<source>label.no</source>
101+
<target>No</target>
102+
103+
</trans-unit>
104+
<trans-unit id="17">
105+
<source>settings.user.behavior</source>
106+
<target>Behavior</target>
107+
108+
</trans-unit>
109+
<trans-unit id="18">
110+
<source>settings.user.call_ticket_by_service</source>
111+
<target>Call by service</target>
112+
113+
</trans-unit>
114+
<trans-unit id="19">
115+
<source>settings.user.call_ticket_out_of_order</source>
116+
<target>Call out of order</target>
117+
118+
</trans-unit>
119+
<trans-unit id="20">
120+
<source>settings.user.use_global</source>
121+
<target>Global default</target>
122+
93123
</trans-unit>
94124
</body>
95125
</file>

‎src/Resources/translations/NovosgaSettingsBundle.es.xlf‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,37 @@
8989
<trans-unit id="14">
9090
<source>label.schedule</source>
9191
<target>Programación</target>
92-
92+
93+
</trans-unit>
94+
<trans-unit id="15">
95+
<source>label.yes</source>
96+
<target>Sí</target>
97+
98+
</trans-unit>
99+
<trans-unit id="16">
100+
<source>label.no</source>
101+
<target>No</target>
102+
103+
</trans-unit>
104+
<trans-unit id="17">
105+
<source>settings.user.behavior</source>
106+
<target>Comportamiento</target>
107+
108+
</trans-unit>
109+
<trans-unit id="18">
110+
<source>settings.user.call_ticket_by_service</source>
111+
<target>Llamar por servicio</target>
112+
113+
</trans-unit>
114+
<trans-unit id="19">
115+
<source>settings.user.call_ticket_out_of_order</source>
116+
<target>Llamar fuera de orden</target>
117+
118+
</trans-unit>
119+
<trans-unit id="20">
120+
<source>settings.user.use_global</source>
121+
<target>Predeterminado global</target>
122+
93123
</trans-unit>
94124
</body>
95125
</file>

‎src/Resources/translations/NovosgaSettingsBundle.es_AR.xlf‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,37 @@
8989
<trans-unit id="14">
9090
<source>label.schedule</source>
9191
<target>Agendar</target>
92-
92+
93+
</trans-unit>
94+
<trans-unit id="15">
95+
<source>label.yes</source>
96+
<target>Sí</target>
97+
98+
</trans-unit>
99+
<trans-unit id="16">
100+
<source>label.no</source>
101+
<target>No</target>
102+
103+
</trans-unit>
104+
<trans-unit id="17">
105+
<source>settings.user.behavior</source>
106+
<target>Comportamiento</target>
107+
108+
</trans-unit>
109+
<trans-unit id="18">
110+
<source>settings.user.call_ticket_by_service</source>
111+
<target>Llamar por servicio</target>
112+
113+
</trans-unit>
114+
<trans-unit id="19">
115+
<source>settings.user.call_ticket_out_of_order</source>
116+
<target>Llamar fuera de orden</target>
117+
118+
</trans-unit>
119+
<trans-unit id="20">
120+
<source>settings.user.use_global</source>
121+
<target>Predeterminado global</target>
122+
93123
</trans-unit>
94124
</body>
95125
</file>

‎src/Resources/translations/NovosgaSettingsBundle.pt_BR.xlf‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@
7474
<source>label.schedule</source>
7575
<target>Agendamento</target>
7676
</trans-unit>
77+
<trans-unit id="15">
78+
<source>label.yes</source>
79+
<target>Sim</target>
80+
</trans-unit>
81+
<trans-unit id="16">
82+
<source>label.no</source>
83+
<target>Não</target>
84+
</trans-unit>
85+
<trans-unit id="17">
86+
<source>settings.user.behavior</source>
87+
<target>Comportamento</target>
88+
</trans-unit>
89+
<trans-unit id="18">
90+
<source>settings.user.call_ticket_by_service</source>
91+
<target>Chamar por serviço</target>
92+
</trans-unit>
93+
<trans-unit id="19">
94+
<source>settings.user.call_ticket_out_of_order</source>
95+
<target>Chamar fora de ordem</target>
96+
</trans-unit>
97+
<trans-unit id="20">
98+
<source>settings.user.use_global</source>
99+
<target>Padrão global</target>
100+
</trans-unit>
77101
</body>
78102
</file>
79103
</xliff>

‎src/Resources/translations/NovosgaSettingsBundle.pt_PT.xlf‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,37 @@
8484
</trans-unit>
8585
<trans-unit id="14">
8686
<source>label.schedule</source>
87-
87+
88+
</trans-unit>
89+
<trans-unit id="15">
90+
<source>label.yes</source>
91+
<target>Sim</target>
92+
93+
</trans-unit>
94+
<trans-unit id="16">
95+
<source>label.no</source>
96+
<target>Não</target>
97+
98+
</trans-unit>
99+
<trans-unit id="17">
100+
<source>settings.user.behavior</source>
101+
<target>Comportamento</target>
102+
103+
</trans-unit>
104+
<trans-unit id="18">
105+
<source>settings.user.call_ticket_by_service</source>
106+
<target>Chamar por serviço</target>
107+
108+
</trans-unit>
109+
<trans-unit id="19">
110+
<source>settings.user.call_ticket_out_of_order</source>
111+
<target>Chamar fora de ordem</target>
112+
113+
</trans-unit>
114+
<trans-unit id="20">
115+
<source>settings.user.use_global</source>
116+
<target>Padrão global</target>
117+
88118
</trans-unit>
89119
</body>
90120
</file>

0 commit comments

Comments
 (0)