diff --git a/config/routes/admin/seal.yaml b/config/routes/admin/seal.yaml index 4c0ee18c..02f6d436 100644 --- a/config/routes/admin/seal.yaml +++ b/config/routes/admin/seal.yaml @@ -17,3 +17,8 @@ remove: path: /{id}/remove controller: App\Controller\Web\Admin\SealAdminController::remove methods: ['GET'] + +edit: + path: /{id}/editar + controller: App\Controller\Web\Admin\SealAdminController::edit + methods: ['GET', 'POST'] \ No newline at end of file diff --git a/cypress/e2e/admin/seal/seal-create.cy.js b/cypress/e2e/admin/seal/seal-create.cy.js index b284d565..8fbf80d1 100644 --- a/cypress/e2e/admin/seal/seal-create.cy.js +++ b/cypress/e2e/admin/seal/seal-create.cy.js @@ -3,34 +3,36 @@ describe('Teste de navegação e validação da página de Selos', () => { cy.visit('/'); cy.contains('Entrar').click(); - cy.url().should('include', '/login'); - cy.login('saracamilo@example.com', 'Aurora@2024'); - cy.url().should('include', '/'); - cy.contains('Sara Jenifer Camilo').should('be.visible'); + cy.contains('Sara Jenifer Camilo').click(); - cy.contains('Minhas Oportunidades', { timeout: 10000 }).should('be.visible').click(); + cy.contains('Minhas Oportunidades', { timeout: 10000 }) + .should('be.visible') + .click(); cy.url({ timeout: 10000 }).should('include', '/painel/oportunidades'); cy.scrollTo('bottom'); - cy.contains('Selos', { timeout: 10000 }).should('be.visible').click(); + cy.contains('Selos', { timeout: 10000 }) + .should('be.visible') + .click(); cy.url({ timeout: 10000 }).should('include', '/painel/selos/'); cy.get('table', { timeout: 10000 }).should('be.visible'); - cy.contains('Criar', { timeout: 10000 }).should('be.visible').click(); + + cy.contains('Criar', { timeout: 10000 }) + .should('be.visible') + .click(); cy.url({ timeout: 10000 }).should('include', '/painel/selos/adicionar'); - // Garante que a validação existe cy.get('button').contains('Salvar').should('be.visible').click(); cy.get('input:invalid').should('have.length', 1); cy.get('textarea:invalid').should('have.length', 1); - // Garante que a criação funciona cy.get('input[name="name"]').type('Selo de qualidade'); cy.get('textarea[name="description"]').type('Descrição do selo'); cy.get('button').contains('Salvar').should('be.visible').click(); + cy.url({ timeout: 10000 }).should('include', '/painel/selos/'); - cy.contains('Selo de qualidade').should('be.visible'); }); }); diff --git a/cypress/e2e/admin/seal/seal-edit.cy.js b/cypress/e2e/admin/seal/seal-edit.cy.js new file mode 100644 index 00000000..fa694c73 --- /dev/null +++ b/cypress/e2e/admin/seal/seal-edit.cy.js @@ -0,0 +1,57 @@ +describe('Teste de navegação, validação e edição da página de Selos', () => { + beforeEach(() => { + cy.visit('/'); + cy.contains('Entrar').click(); + cy.url().should('include', '/login'); + cy.login('saracamilo@example.com', 'Aurora@2024'); + cy.url().should('include', '/'); + cy.contains('Sara Jenifer Camilo').should('be.visible').click(); + cy.contains('Minhas Oportunidades').should('be.visible').click(); + cy.url().should('include', '/painel/oportunidades'); + cy.scrollTo('bottom'); + cy.contains('Selos').should('be.visible').click(); + cy.url().should('include', '/painel/selos/'); + cy.contains('Editar').first().click(); + cy.url().should('include', '/editar'); + + cy.get('form').invoke('attr', 'novalidate', true); + }); + + it('Verifica e edita os campos do formulário de selos', () => { + cy.get('input[name="active"]') + .should('exist') + .should('have.attr', 'type', 'checkbox') + .should('be.checked'); + + cy.get('input[name="name"]').clear().type('Selo Teste Atualizado'); + + cy.get('textarea[name="description"]') + .clear() + .type('Selo que destaca eventos com impacto em comunidades locais.'); + + cy.contains('Salvar').click(); + cy.url().should('include', '/painel/selos/'); + cy.contains('Selo Teste Atualizado').should('be.visible'); + cy.contains('Selo Teste Atualizado').parent().contains('Editar').click(); + cy.get('input[name="name"]').should('have.value', 'Selo Teste Atualizado'); + cy.get('textarea[name="description"]').should( + 'have.value', + 'Selo que destaca eventos com impacto em comunidades locais.' + ); + cy.get('input[name="active"]').should('be.checked'); + }); + + it('Verifica os botões Salvar e Cancelar', () => { + cy.contains('Salvar') + .should('exist') + .should('have.attr', 'type', 'submit') + + cy.contains('Cancelar') + .should('exist') + .should('have.attr', 'href', '/painel/selos/') + .should('be.visible'); + + cy.contains('Cancelar').click(); + cy.url().should('include', '/painel/selos/'); + }); +}); diff --git a/src/Controller/Web/Admin/SealAdminController.php b/src/Controller/Web/Admin/SealAdminController.php index 56a0f29c..21929194 100644 --- a/src/Controller/Web/Admin/SealAdminController.php +++ b/src/Controller/Web/Admin/SealAdminController.php @@ -8,7 +8,6 @@ use App\Service\Interface\SealServiceInterface; use DateTime; use Exception; -use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Uid\Uuid; @@ -18,11 +17,11 @@ class SealAdminController extends AbstractAdminController { public const VIEW_ADD = 'seal/add.html.twig'; + public const VIEW_EDIT = 'seal/edit.html.twig'; public function __construct( private SealServiceInterface $sealService, - private readonly TranslatorInterface $translator, - private Security $security, + private readonly TranslatorInterface $translator ) { } @@ -38,7 +37,7 @@ public function list(): Response public function getOne(int $id): Response { $seal = [ - 'name' => 'Selo '.$id, + 'name' => 'Selo'.$id, 'status' => 'Ativo', 'createdAt' => new DateTime('2023-12-01 10:00:00'), ]; @@ -58,9 +57,8 @@ public function add(Request $request, ValidatorInterface $validator): Response $this->sealService->create([ 'id' => Uuid::v4(), 'name' => $request->get('name'), + 'active' => null === $request->get('active') ? false : true, 'description' => $request->get('description'), - 'active' => true, - 'createdBy' => $this->security->getUser()->getAgents()->getValues()[0]->getId(), ]); } catch (ValidatorException $exception) { return $this->render(self::VIEW_ADD, [ @@ -87,4 +85,45 @@ public function remove(?Uuid $id): Response return $this->redirectToRoute('admin_seal_list'); } + + public function edit(string $id, Request $request, ValidatorInterface $validator): Response + { + try { + $seal = $this->sealService->get(Uuid::fromString($id)); + } catch (Exception $exception) { + $this->addFlash('error', $exception->getMessage()); + + return $this->redirectToRoute('admin_seal_list'); + } + + if (Request::METHOD_POST !== $request->getMethod()) { + return $this->render(self::VIEW_EDIT, [ + 'seal' => $seal, + ]); + } + + try { + $this->sealService->update(Uuid::fromString($id), [ + 'name' => $request->get('name'), + 'active' => null === $request->get('active') ? false : true, + 'description' => $request->get('description'), + ]); + + $this->addFlash('success', $this->translator->trans('view.seal.message.updated')); + + return $this->redirectToRoute('admin_seal_list'); + } catch (ValidatorException $exception) { + return $this->render(self::VIEW_EDIT, [ + 'seal' => $seal, + 'errors' => $exception->getConstraintViolationList(), + ]); + } catch (Exception $exception) { + return $this->render(self::VIEW_EDIT, [ + 'seal' => $seal, + 'errors' => [ + $exception->getMessage(), + ], + ]); + } + } } diff --git a/templates/_admin/seal/edit.html.twig b/templates/_admin/seal/edit.html.twig new file mode 100644 index 00000000..a0c755aa --- /dev/null +++ b/templates/_admin/seal/edit.html.twig @@ -0,0 +1,67 @@ +{% extends "_layouts/blank.html.twig" %} + +{% block title %}{{ 'edit_seals' | trans }}{% endblock %} + +{% block content %} +
+ {% include "_components/side-bar.html.twig" %} +
+
+
+
+

{{ 'edit_seals' | trans }}

+
+
+ + +
+
+ + +
+
+ + +
+ + + {{ 'cancel' | trans }} + +
+ {% if errors is defined and errors|length > 0 %} +
+
    + {% for error in errors %} +
  • {{ error.message }}
  • + {% endfor %} +
+
+ {% endif %} +
+
+
+
+
+{% endblock %} diff --git a/templates/_admin/seal/list.html.twig b/templates/_admin/seal/list.html.twig index bf28a4e9..3055aea2 100644 --- a/templates/_admin/seal/list.html.twig +++ b/templates/_admin/seal/list.html.twig @@ -44,7 +44,7 @@ {{ seal.active ? 'view.seal.status.active'|trans : 'view.seal.status.inactive'|trans }} {{ seal.createdAt|date('d/m/Y H:i') }} - {{ 'edit'|trans }} + {{ 'edit'|trans }} diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 7d887114..00488219 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -80,6 +80,7 @@ downloadable-files: Downloadable Files edit: Edit edit_faq: Edit FAQ +edit_seals: Edit Seals email: Email entity_banner: Entity Banner entity: Entity @@ -267,6 +268,8 @@ save: Save share: Share save_share: Save and Share seals: Seals +seals_name: Seal name +seals_description: Seal Description search: Search select: Select send: Send @@ -513,6 +516,7 @@ view: expired: expired seal message: deleted: The seal has been deleted + updated: The seal has been updated status: active: Active inactive: Inactive diff --git a/translations/messages.es.yaml b/translations/messages.es.yaml index 7bde910b..cd1d12ce 100644 --- a/translations/messages.es.yaml +++ b/translations/messages.es.yaml @@ -80,6 +80,7 @@ downloadable-files: Archivos Descargables edit: Editar edit_faq: Editar preguntas frecuentes +edit_seals: Editar sellos email: Correo Electrónico entity_banner: Banner de la Entidad entity: Entidad @@ -266,6 +267,8 @@ save: Guardar share: Compartir save_share: Guardar y Compartir seals: Sellos +seals_name: Nombre del sello +seals_description: Descripción del sello search: Buscar select: Seleccionar send: Enviar @@ -518,6 +521,7 @@ view: expired: sello vencido message: deleted: El sello ha sido eliminado + updated: La insignia ha sido actualizada status: active: Activo inactive: Inactivo diff --git a/translations/messages.pt-br.yaml b/translations/messages.pt-br.yaml index ffcdd364..921500dc 100644 --- a/translations/messages.pt-br.yaml +++ b/translations/messages.pt-br.yaml @@ -80,6 +80,7 @@ downloadable-files: Arquivos para download edit: Editar edit_faq: Editar FAQ +edit_seals: Editar Selos email: Email entity_banner: Banner da Entidade entity: Entidade @@ -267,6 +268,8 @@ save_share: Salvar e Compartilhar share: Compartilhar short_presentation: Apresentação Curta seals: Selos +seals_name: Nome do Selo +seals_description: Descrição do Selo search: Buscar select_bank: Selecione o banco select_education: Selecione a sua Escolaridade @@ -601,6 +604,7 @@ view: expired: selo expirado message: deleted: O selo foi excluído + updated: O selo foi atualizado status: active: Ativo inactive: Inativo diff --git a/var/translations/index.d.ts b/var/translations/index.d.ts index e96a427c..5216b9ce 100644 --- a/var/translations/index.d.ts +++ b/var/translations/index.d.ts @@ -212,6 +212,7 @@ export declare const DOES_NOT_EXPIRE: Message<{ 'messages': { parameters: NoPara export declare const DOWNLOADABLE_FILES: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const EDIT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const EDIT_FAQ: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; +export declare const EDIT_SEALS: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const EMAIL: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const ENTITY_BANNER: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const ENTITY: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; @@ -384,6 +385,8 @@ export declare const SAVE: Message<{ 'messages': { parameters: NoParametersType export declare const SHARE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const SAVE_SHARE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const SEALS: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; +export declare const SEALS_NAME: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; +export declare const SEALS_DESCRIPTION: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const SEARCH: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const SELECT: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const SEND: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; @@ -575,6 +578,7 @@ export declare const VIEW_SEAL_CREATOR: Message<{ 'messages': { parameters: NoPa export declare const VIEW_SEAL_DATE_OF_RECEIPT_OF_THE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const VIEW_SEAL_EXPIRED: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const VIEW_SEAL_MESSAGE_DELETED: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; +export declare const VIEW_SEAL_MESSAGE_UPDATED: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const VIEW_SEAL_STATUS_ACTIVE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const VIEW_SEAL_STATUS_INACTIVE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; export declare const VIEW_SEAL_SEAL_PICTURE: Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'pt-br'|'es'>; diff --git a/var/translations/index.js b/var/translations/index.js index 5e92a4e1..3f919b84 100644 --- a/var/translations/index.js +++ b/var/translations/index.js @@ -210,6 +210,7 @@ export const DOES_NOT_EXPIRE = {"id":"does_not_expire","translations":{"messages export const DOWNLOADABLE_FILES = {"id":"downloadable-files","translations":{"messages":{"en":"Downloadable Files","pt-br":"Arquivos para download","es":"Archivos Descargables"}}}; export const EDIT = {"id":"edit","translations":{"messages":{"en":"Edit","pt-br":"Editar","es":"Editar"}}}; export const EDIT_FAQ = {"id":"edit_faq","translations":{"messages":{"en":"Edit FAQ","pt-br":"Editar FAQ","es":"Editar preguntas frecuentes"}}}; +export const EDIT_SEALS = {"id":"edit_seals","translations":{"messages":{"en":"Edit Seals","pt-br":"Editar Selos","es":"Editar sellos"}}}; export const EMAIL = {"id":"email","translations":{"messages":{"en":"Email","pt-br":"Email","es":"Correo Electr\u00f3nico"}}}; export const ENTITY_BANNER = {"id":"entity_banner","translations":{"messages":{"en":"Entity Banner","pt-br":"Banner da Entidade","es":"Banner de la Entidad"}}}; export const ENTITY = {"id":"entity","translations":{"messages":{"en":"Entity","pt-br":"Entidade","es":"Entidad"}}}; @@ -382,6 +383,8 @@ export const SAVE = {"id":"save","translations":{"messages":{"en":"Save","pt-br" export const SHARE = {"id":"share","translations":{"messages":{"en":"Share","pt-br":"Compartilhar","es":"Compartir"}}}; export const SAVE_SHARE = {"id":"save_share","translations":{"messages":{"en":"Save and Share","pt-br":"Salvar e Compartilhar","es":"Guardar y Compartir"}}}; export const SEALS = {"id":"seals","translations":{"messages":{"en":"Seals","pt-br":"Selos","es":"Sellos"}}}; +export const SEALS_NAME = {"id":"seals_name","translations":{"messages":{"en":"Seal name","pt-br":"Nome do Selo","es":"Nombre del sello"}}}; +export const SEALS_DESCRIPTION = {"id":"seals_description","translations":{"messages":{"en":"Seal Description","pt-br":"Descri\u00e7\u00e3o do Selo","es":"Descripci\u00f3n del sello"}}}; export const SEARCH = {"id":"search","translations":{"messages":{"en":"Search","pt-br":"Buscar","es":"Buscar"}}}; export const SELECT = {"id":"select","translations":{"messages":{"en":"Select","pt-br":"Selecione","es":"Seleccionar"}}}; export const SEND = {"id":"send","translations":{"messages":{"en":"Send","pt-br":"Enviar","es":"Enviar"}}}; @@ -573,6 +576,7 @@ export const VIEW_SEAL_CREATOR = {"id":"view.seal.creator","translations":{"mess export const VIEW_SEAL_DATE_OF_RECEIPT_OF_THE = {"id":"view.seal.date_of_receipt_of_the","translations":{"messages":{"en":"Date of receipt of the seal","pt-br":"Data de recebimento do selo","es":"Fecha de recepci\u00f3n del sello"}}}; export const VIEW_SEAL_EXPIRED = {"id":"view.seal.expired","translations":{"messages":{"en":"expired seal","pt-br":"selo expirado","es":"sello vencido"}}}; export const VIEW_SEAL_MESSAGE_DELETED = {"id":"view.seal.message.deleted","translations":{"messages":{"en":"The seal has been deleted","pt-br":"O selo foi exclu\u00eddo","es":"El sello ha sido eliminado"}}}; +export const VIEW_SEAL_MESSAGE_UPDATED = {"id":"view.seal.message.updated","translations":{"messages":{"en":"The seal has been updated","pt-br":"O selo foi atualizado","es":"La insignia ha sido actualizada"}}}; export const VIEW_SEAL_STATUS_ACTIVE = {"id":"view.seal.status.active","translations":{"messages":{"en":"Active","pt-br":"Ativo","es":"Activo"}}}; export const VIEW_SEAL_STATUS_INACTIVE = {"id":"view.seal.status.inactive","translations":{"messages":{"en":"Inactive","pt-br":"Inativo","es":"Inactivo"}}}; export const VIEW_SEAL_SEAL_PICTURE = {"id":"view.seal.seal-picture","translations":{"messages":{"en":"Seal Picture","pt-br":"Foto do Selo","es":"Foto del Sello"}}};