Skip to content

Commit

Permalink
create edit seals page (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
saracamilo authored Jan 8, 2025
1 parent febad32 commit 25d2282
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 17 deletions.
5 changes: 5 additions & 0 deletions config/routes/admin/seal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
22 changes: 12 additions & 10 deletions cypress/e2e/admin/seal/seal-create.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]', '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');
});
});
57 changes: 57 additions & 0 deletions cypress/e2e/admin/seal/seal-edit.cy.js
Original file line number Diff line number Diff line change
@@ -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('[email protected]', '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/');
});
});
51 changes: 45 additions & 6 deletions src/Controller/Web/Admin/SealAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand All @@ -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'),
];
Expand All @@ -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, [
Expand All @@ -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(),
],
]);
}
}
}
67 changes: 67 additions & 0 deletions templates/_admin/seal/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% extends "_layouts/blank.html.twig" %}

{% block title %}{{ 'edit_seals' | trans }}{% endblock %}

{% block content %}
<section class="d-flex">
{% include "_components/side-bar.html.twig" %}
<div class="management-content w-100 p-4">
<div class="row">
<div class="col-md-8 offset-md-2">
<div class="card card-body">
<h2>{{ 'edit_seals' | trans }}</h2>
<form method="POST">
<div class="mb-3">
<label for="name" class="form-label">{{ 'seals_name' | trans }}</label>
<input
type="text"
id="name"
name="name"
class="form-control"
value="{{ seal.name }}"
required
>
</div>
<div class="mb-3 form-check">
<input
type="checkbox"
id="active"
name="active"
class="form-check-input"
{{ seal.active ? 'checked' : '' }}
>
<label for="active" class="form-check-label">Ativo</label>
</div>
<div class="mb-3">
<label for="description" class="form-label">{{ 'seals_description' | trans }}</label>
<textarea
id="description"
name="description"
class="form-control"
rows="3"
maxlength="500"
required
>{{ seal.description }}</textarea>
</div>
<button type="submit" class="btn btn-primary">
{{ 'save' | trans }}
</button>
<a href="{{ path('admin_seal_list') }}" class="btn btn-secondary">
{{ 'cancel' | trans }}
</a>
</form>
{% if errors is defined and errors|length > 0 %}
<div class="alert alert-danger mt-3">
<ul>
{% for error in errors %}
<li>{{ error.message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</section>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/_admin/seal/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<td>{{ seal.active ? 'view.seal.status.active'|trans : 'view.seal.status.inactive'|trans }}</td>
<td>{{ seal.createdAt|date('d/m/Y H:i') }}</td>
<td>
<a href="#" class="btn btn-outline-warning btn-sm">{{ 'edit'|trans }}</a>
<a href="{{ path('admin_seal_edit', {'id': seal.id}) }}" class="btn btn-outline-warning btn-sm">{{ 'edit'|trans }}</a>
<button data-cy="remove-{{ loop.index }}" data-bs-toggle="modal" data-bs-target="#modalRemoveConfirm" onclick="confirmRemove(this)" data-href="{{ path('admin_seal_remove', {id: seal.id}) }}" class="btn btn-outline-danger btn-sm">{{ 'delete'|trans }}</button>
</td>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions translations/messages.es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions translations/messages.pt-br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions var/translations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'>;
Expand Down Expand Up @@ -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'>;
Expand Down Expand Up @@ -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'>;
Expand Down
Loading

0 comments on commit 25d2282

Please sign in to comment.