diff --git a/assets/css/radio-station-bulk-remove.css b/assets/css/radio-station-bulk-remove.css new file mode 100644 index 00000000..95366459 --- /dev/null +++ b/assets/css/radio-station-bulk-remove.css @@ -0,0 +1,13 @@ +/* radio station list */ + +.radio-stations-remove { + max-height: 430px; + overflow-y: auto; + box-sizing: border-box; + padding: 0.05em 1em; + background: #F9FCF9; + border: 1px solid #D6EAD0; +} +.radio-stations-remove fieldset { + margin: 0; +} diff --git a/assets/css/radio-table-remove.css b/assets/css/radio-table-remove.css index 9fb7aa8a..f4af4576 100644 --- a/assets/css/radio-table-remove.css +++ b/assets/css/radio-table-remove.css @@ -1,18 +1,3 @@ -/* radio station list */ - -.radio-stations-remove { - max-height: 430px; - overflow-y: auto; - box-sizing: border-box; - padding: 0.05em 1em; - background: #F9FCF9; - border: 1px solid #D6EAD0; -} -.radio-stations-remove fieldset { - margin: 0; -} - - /* radio table warning */ .radio-table-remove-confirm { diff --git a/src/Controller/RadioStationController.php b/src/Controller/RadioStationController.php index 9a3509aa..7677fa4c 100644 --- a/src/Controller/RadioStationController.php +++ b/src/Controller/RadioStationController.php @@ -5,6 +5,7 @@ use App\Entity\RadioStation; use App\Entity\RadioTable; use App\Form\RadioStationEditType; +use App\Form\RadioStationBulkRemoveType; use Doctrine\ORM\EntityManagerInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; @@ -96,4 +97,38 @@ public function copy(RadioStation $radioStation): Response 'template' => $template, ]); } + + /** + * @Route({"pl": "/wykaz/{id}/usun-stacje", "en": "/list/{id}/delete-stations"}, name="radio_station.bulk_remove") + * @IsGranted("IS_AUTHENTICATED_REMEMBERED") + * @IsGranted("RADIO_TABLE_MODIFY", subject="radioTable", statusCode=404) + */ + public function bulkRemove(RadioTable $radioTable, Request $request, EntityManagerInterface $entityManager): Response + { + $form = $this->createForm(RadioStationBulkRemoveType::class, null, ['radio_table' => $radioTable]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $chosenToRemove = $form->getData()['chosenToRemove']; + + if (count($chosenToRemove) > 0) { + foreach ($chosenToRemove as $radioStation) { + $entityManager->remove($radioStation); + } + $entityManager->flush(); + + $this->addFlash('notice', 'radio_station.bulk_remove.notification.bulk_removed'); + + // Form needs to be reloaded to not display removed radio stations. + return $this->redirectToRoute('radio_station.bulk_remove', [ + 'id' => $radioTable->getId(), + ]); + } + } + + return $this->render('radio_station/bulk_remove.html.twig', [ + 'form' => $form->createView(), + 'radio_table' => $radioTable, + ]); + } } diff --git a/src/Controller/RadioTableController.php b/src/Controller/RadioTableController.php index 947b13b2..c87b4900 100644 --- a/src/Controller/RadioTableController.php +++ b/src/Controller/RadioTableController.php @@ -2,17 +2,14 @@ namespace App\Controller; -use App\Entity\RadioStation; use App\Entity\RadioTable; use App\Export\RadioTableExporterProvider; -use App\Form\RadioStationRemoveType; use App\Form\RadioTableCreateType; use App\Form\RadioTableRemoveType; use App\Form\RadioTableSettingsType; use App\Repository\RadioStationRepository; use Doctrine\ORM\EntityManagerInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -125,27 +122,17 @@ public function export(RadioTable $radioTable): Response } /** - * This action handles both radio table removing and radio station removing. - * * @Route({"pl": "/wykaz/{id}/usun", "en": "/list/{id}/delete"}, name="radio_table.remove") - * @ParamConverter("radioStationToRemove", class="stdClass") * @IsGranted("IS_AUTHENTICATED_REMEMBERED") * @IsGranted("RADIO_TABLE_MODIFY", subject="radioTable", statusCode=404) */ - public function remove(RadioTable $radioTable, Request $request, EntityManagerInterface $entityManager, - RadioStation $radioStationToRemove = null): Response + public function remove(RadioTable $radioTable, Request $request, EntityManagerInterface $entityManager): Response { - $form_RadioTable = $this->createForm(RadioTableRemoveType::class); - $form_RadioTable->handleRequest($request); - - $form_RadioStation = $this->createForm(RadioStationRemoveType::class, - $radioStationToRemove ? ['chosenToRemove' => [$radioStationToRemove]] : null, - ['radio_table' => $radioTable] - ); - $form_RadioStation->handleRequest($request); + $form = $this->createForm(RadioTableRemoveType::class); + $form->handleRequest($request); - if ($form_RadioTable->isSubmitted() && $form_RadioTable->isValid()) { - $confirmed = (true === $form_RadioTable->getData()['confirm']); + if ($form->isSubmitted() && $form->isValid()) { + $confirmed = (true === $form->getData()['confirm']); if ($confirmed) { $entityManager->remove($radioTable); @@ -158,29 +145,9 @@ public function remove(RadioTable $radioTable, Request $request, EntityManagerIn $this->addFlash('error', 'radio_table.remove.notification.not_yet'); } } - elseif ($form_RadioStation->isSubmitted() && $form_RadioStation->isValid()) { - $chosenToRemove = $form_RadioStation->getData()['chosenToRemove']; - - if (count($chosenToRemove) > 0) { - foreach ($chosenToRemove as $radioStation) { - $entityManager->remove($radioStation); - } - $entityManager->flush(); - - $this->addFlash('notice', 'radio_station.remove.notification.bulk_removed'); - - // Redirect to after successful radio stations removing. - // * Form needs to be reloaded to not display removed radio stations. - // * URL needs to be changed to avoid 404 error if page was forwarded from RadioStationController. - return $this->redirectToRoute('radio_table.remove', [ - 'id' => $radioTable->getId(), - ]); - } - } return $this->render('radio_table/remove.html.twig', [ - 'form_radio_table' => $form_RadioTable->createView(), - 'form_radio_station' => $form_RadioStation->createView(), + 'form' => $form->createView(), 'radio_table' => $radioTable, ]); } diff --git a/src/Form/RadioStationRemoveType.php b/src/Form/RadioStationBulkRemoveType.php similarity index 94% rename from src/Form/RadioStationRemoveType.php rename to src/Form/RadioStationBulkRemoveType.php index dd8f1ac4..cb4df921 100644 --- a/src/Form/RadioStationRemoveType.php +++ b/src/Form/RadioStationBulkRemoveType.php @@ -12,7 +12,7 @@ use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -class RadioStationRemoveType extends AbstractType +class RadioStationBulkRemoveType extends AbstractType { private $radioStationRepository; @@ -53,7 +53,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setRequired(['radio_table']); $resolver->setAllowedTypes('radio_table', RadioTable::class); $resolver->setDefaults([ - 'label_format' => 'radio_station.remove.form.%name%', + 'label_format' => 'radio_station.bulk_remove.form.%name%', ]); } } diff --git a/templates/radio_station/bulk_remove.html.twig b/templates/radio_station/bulk_remove.html.twig new file mode 100644 index 00000000..7d8dfde9 --- /dev/null +++ b/templates/radio_station/bulk_remove.html.twig @@ -0,0 +1,62 @@ +{% extends 'layout.html.twig' %} + +{% block page_title %}{{ 'radio_station.bulk_remove.title'|trans }}{% endblock %} + +{% block head_closing %} + {{ encore_entry_link_tags('radio-station-bulk-remove') }} +{% endblock %} + +{% block context_menu %} + +{% endblock %} + +{% form_theme form _self %} +{% block _radio_station_bulk_remove_chosenToRemove_entry_label %} + {% set label = '%s (%s %s)'|format(label, frequency|format_number({min_fraction_digit: 2, grouping_used: false}), get_frequency_label(frequency_unit)) %} + {{ block('form_label') }} +{% endblock %} + +{% block page_content %} +
+

+ {{ 'radio_station.bulk_remove.title'|trans }} + + {{ 'radio_station.edit.text.for_radio_table_a11y_subheading'|trans }} + {{ radio_table.name }} + +

+
+ +
+
+

{{ 'radio_station.bulk_remove.heading.remove_radio_station'|trans }}

+ + {% if radio_table.radioStationsCount > 0 %} + {{ form_start(form) }} + +
+ {{ form_row(form.chosenToRemove) }} +
+ + + + {{ form_end(form) }} + {% else %} +

+ {{ 'radio_station.bulk_remove.information.empty_cannot_remove_radio_station'|trans }} +

+ {% endif %} +
+
+{% endblock %} diff --git a/templates/radio_table/remove.html.twig b/templates/radio_table/remove.html.twig index b22ab68a..25007a09 100644 --- a/templates/radio_table/remove.html.twig +++ b/templates/radio_table/remove.html.twig @@ -27,12 +27,6 @@ {% endblock %} -{% form_theme form_radio_station _self %} -{% block _radio_station_remove_chosenToRemove_entry_label %} - {% set label = '%s (%s %s)'|format(label, frequency|format_number({min_fraction_digit: 2, grouping_used: false}), get_frequency_label(frequency_unit)) %} - {{ block('form_label') }} -{% endblock %} - {% block page_content %}

@@ -42,25 +36,6 @@

-
-

{{ 'radio_table.remove.heading.remove_radio_station'|trans }}

- - {% if radio_table.radioStationsCount > 0 %} - {{ form_start(form_radio_station) }} - -
- {{ form_row(form_radio_station.chosenToRemove) }} -
- - - - {{ form_end(form_radio_station) }} - {% else %} -

- {{ 'radio_table.remove.information.empty_cannot_remove_radio_station'|trans }} -

- {% endif %} -

{{ 'radio_table.remove.heading.remove_radio_table'|trans }}

@@ -68,9 +43,9 @@ {{ 'radio_table.remove.information.cannot_be_undone'|trans }}

- {{ form_start(form_radio_table) }} + {{ form_start(form) }} - {{ form_row(form_radio_table.confirm, { + {{ form_row(form.confirm, { label_translation_parameters: { '%name%': radio_table.name }, attr: { 'class': 'radio-table-remove-confirm', @@ -78,9 +53,9 @@ }, }) }} - + - {{ form_end(form_radio_table) }} + {{ form_end(form) }}
{% endblock %} diff --git a/templates/radio_table/settings.html.twig b/templates/radio_table/settings.html.twig index 25b45cc1..6ba9afab 100644 --- a/templates/radio_table/settings.html.twig +++ b/templates/radio_table/settings.html.twig @@ -19,6 +19,11 @@ {{ 'radio_station.add.title'|trans }} +
  • + + {{ 'radio_station.bulk_remove.title'|trans }} + +
  • {{ 'radio_table.remove.title'|trans }} diff --git a/tests/Controller/RadioStationControllerTest.php b/tests/Controller/RadioStationControllerTest.php index 61a1ab6c..eeb7f3ae 100644 --- a/tests/Controller/RadioStationControllerTest.php +++ b/tests/Controller/RadioStationControllerTest.php @@ -58,11 +58,12 @@ public function testCopyRadioStation(): void $this->assertStringContainsString('COPIED_RADIO_STATION_NAME', $content); } - public function testRemoveRadioStation(): void + public function testBulkRemoveRadioStation(): void { - $crawler = $this->client->request('GET', '/wykaz/1/usun-stacje/1'); - $form = $crawler->filter('form[name="radio_station_remove"]')->form(); - $this->client->submit($form); // Radiostation is selected automatically. + $crawler = $this->client->request('GET', '/wykaz/1/usun-stacje'); + $form = $crawler->filter('form[name="radio_station_bulk_remove"]')->form(); + $form['radio_station_bulk_remove[chosenToRemove][1]']->tick(); // Checkbox is chosen by order, not by input value. + $this->client->submit($form); $this->client->request('GET', '/wykaz/1'); $content = $this->client->getResponse()->getContent(); diff --git a/tests/Form/FormsCompilationTest.php b/tests/Form/FormsCompilationTest.php index 3361cb6a..7bc7bcbd 100644 --- a/tests/Form/FormsCompilationTest.php +++ b/tests/Form/FormsCompilationTest.php @@ -6,7 +6,7 @@ use App\Entity\RadioTable; use App\Entity\User; use App\Form\RadioStationEditType; -use App\Form\RadioStationRemoveType; +use App\Form\RadioStationBulkRemoveType; use App\Form\RadioTableCreateType; use App\Form\RadioTableRemoveType; use App\Form\RadioTableSearchType; @@ -40,7 +40,7 @@ public function formTypeAndEntityProvider(): iterable self::ensureKernelShutdown(); yield 'RadioStationEditType' => [RadioStationEditType::class, $radioStation]; - yield 'RadioStationRemoveType' => [RadioStationRemoveType::class, null, ['radio_table' => $radioTable]]; + yield 'RadioStationBulkRemoveType' => [RadioStationBulkRemoveType::class, null, ['radio_table' => $radioTable]]; yield 'RadioTableCreateType' => [RadioTableCreateType::class, $radioTable]; yield 'RadioTableRemoveType' => [RadioTableRemoveType::class]; yield 'RadioTableSearchType' => [RadioTableSearchType::class]; diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 2f8cd0a2..08ef6536 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -118,15 +118,12 @@ radio_table: about_ods: 'ODS — spreadsheet document for LibreOffice and Apache OpenOffice' remove: - title: 'Delete station or list' + title: 'Delete list' action: export: 'Export list' - selected_radio_stations: 'Delete chosen stations' - radio_table: 'Delete list' heading: - remove_radio_station: 'Delete stations' remove_radio_table: 'Delete list' form: @@ -137,7 +134,6 @@ radio_table: not_yet: "Let's try again. Nothing happened." information: - empty_cannot_remove_radio_station: 'This is is empty. There is nothing to delete…' cannot_be_undone: 'Deleted list cannot be restored. Please remember that you can still export your list into HTML, PDF or CSV file and download it to your computer.' text: @@ -202,8 +198,14 @@ radio_station: for_radio_table_a11y_subheading: 'in list' disabled_radio_table_column: 'This column is currently not visible in the list.' - remove: - title: 'Delete station' + bulk_remove: + title: 'Delete more stations' + + action: + bulk_remove: 'Delete chosen stations' + + heading: + remove_radio_station: 'Delete stations' form: chosenToRemove: 'Choose stations to be deleted' @@ -211,6 +213,9 @@ radio_station: notification: bulk_removed: 'Chosen stations have been deleted.' + information: + empty_cannot_remove_radio_station: 'This is is empty. There is nothing to delete…' + user: detail: last_activity_date: 'Last activity date' diff --git a/translations/messages.pl.yaml b/translations/messages.pl.yaml index b9adda2f..91a89d45 100644 --- a/translations/messages.pl.yaml +++ b/translations/messages.pl.yaml @@ -118,15 +118,12 @@ radio_table: about_ods: "ODS — arkusz kalkulacyjny pakietów LibreOffice oraz Apache\u00A0OpenOffice" remove: - title: 'Usuń stacje lub wykaz' + title: 'Usuń wykaz' action: export: 'Eksport wykazu' - selected_radio_stations: 'Usuń zaznaczone stacje' - radio_table: 'Usuń wykaz' heading: - remove_radio_station: 'Usuwanie stacji' remove_radio_table: 'Usuwanie wykazu' form: @@ -137,7 +134,6 @@ radio_table: not_yet: 'Pamiętaj: jeśli jesteś na samym dnie, głowa do góry, może być już tylko lepiej!' information: - empty_cannot_remove_radio_station: 'Ten wykaz jest pusty. Nie ma czego usuwać…' cannot_be_undone: "Usunięcie wykazu jest nieodwracalne. Pamiętaj, że przed usunięciem możesz wyeksportować wykaz do\u00A0pliku HTML, PDF lub CSV, aby pobrać go na komputer." text: @@ -202,8 +198,14 @@ radio_station: for_radio_table_a11y_subheading: 'w wykazie' disabled_radio_table_column: 'Ta kolumna jest niewidoczna w wykazie.' - remove: - title: 'Usuń stację' + bulk_remove: + title: 'Usuń wiele stacji' + + action: + bulk_remove: 'Usuń zaznaczone stacje' + + heading: + remove_radio_station: 'Usuwanie stacji' form: chosenToRemove: 'Wskaż stacje do usunięcia' @@ -211,6 +213,9 @@ radio_station: notification: bulk_removed: 'Wybrane stacje zostały usunięte.' + information: + empty_cannot_remove_radio_station: 'Ten wykaz jest pusty. Nie ma czego usuwać…' + user: detail: last_activity_date: 'Data ostatniej aktywności' diff --git a/webpack.config.js b/webpack.config.js index 28860c4c..b7f99715 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -31,6 +31,7 @@ Encore .addStyleEntry('homepage', './assets/css/homepage.css') .addStyleEntry('user-login-register', './assets/css/user-login-register.css') .addStyleEntry('user-public-profile', './assets/css/user-public-profile.css') + .addStyleEntry('radio-station-bulk-remove', './assets/css/radio-station-bulk-remove.css') .addStyleEntry('all-radio-tables', './assets/css/all-radio-tables.css') .addStyleEntry('static-page', './assets/css/static-page.css') .addStyleEntry('dark-error', './assets/css/dark-error.css')