From 4204a06b7726597dc84fe34b39c53f1534a86140 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 11 Mar 2016 14:48:46 +0100 Subject: Add flashes messages --- .../CoreBundle/Controller/ConfigController.php | 18 ++++++------ .../CoreBundle/Controller/EntryController.php | 26 ++++++++++++----- .../CoreBundle/Controller/TagController.php | 2 +- .../Resources/translations/messages.en.yml | 34 ++++++++++++++++++++++ .../Tests/Controller/ConfigControllerTest.php | 16 +++++----- .../ImportBundle/Controller/PocketController.php | 8 +++-- .../Controller/WallabagV1Controller.php | 9 ++++-- .../Controller/WallabagV2Controller.php | 9 ++++-- .../Tests/Controller/PocketControllerTest.php | 2 +- .../Tests/Controller/WallabagV1ControllerTest.php | 6 ++-- .../Tests/Controller/WallabagV2ControllerTest.php | 4 +-- 11 files changed, 94 insertions(+), 40 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index d24066b3..779be268 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -45,7 +45,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Config saved. Some parameters will be considered after disconnection.' + 'flashes.config.notice.config_saved' ); return $this->redirect($this->generateUrl('config')); @@ -57,9 +57,9 @@ class ConfigController extends Controller if ($pwdForm->isValid()) { if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) { - $message = 'In demonstration mode, you can\'t change password for this user.'; + $message = 'flashes.config.notice.password_not_updated_demo'; } else { - $message = 'Password updated'; + $message = 'flashes.config.notice.password_updated'; $user->setPlainPassword($pwdForm->get('new_password')->getData()); $userManager->updateUser($user, true); @@ -82,7 +82,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Information updated' + 'flashes.config.notice.user_updated' ); return $this->redirect($this->generateUrl('config').'#set3'); @@ -98,7 +98,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'RSS information updated' + 'flashes.config.notice.rss_updated' ); return $this->redirect($this->generateUrl('config').'#set2'); @@ -116,7 +116,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Tagging rules updated' + 'flashes.config.notice.tagging_rules_updated' ); return $this->redirect($this->generateUrl('config').'#set5'); @@ -147,7 +147,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - $this->get('translator')->trans('User "%username%" added', array('%username%' => $newUser->getUsername())) + $this->get('translator')->trans('flashes.config.notice.user_added', array('%username%' => $newUser->getUsername())) ); return $this->redirect($this->generateUrl('config').'#set6'); @@ -192,7 +192,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'RSS token updated' + 'flashes.config.notice.rss_token_updated' ); return $this->redirect($this->generateUrl('config').'#set2'); @@ -219,7 +219,7 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Tagging rule deleted' + 'flashes.config.notice.tagging_rules_deleted' ); return $this->redirect($this->generateUrl('config').'#set5'); diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 0fae3a0f..1a0b80ac 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -55,7 +55,7 @@ class EntryController extends Controller if (false !== $existingEntry) { $this->get('session')->getFlashBag()->add( 'notice', - 'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y') + $this->get('translator')->trans('flashes.entry.notice.entry_already_saved', array('%date%' => $existingEntry->getCreatedAt()->format('d-m-Y'))) ); return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId()))); @@ -64,7 +64,7 @@ class EntryController extends Controller $this->updateEntry($entry); $this->get('session')->getFlashBag()->add( 'notice', - 'Entry saved' + 'flashes.entry.notice.entry_saved' ); return $this->redirect($this->generateUrl('homepage')); @@ -128,7 +128,7 @@ class EntryController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Entry updated' + 'flashes.entry.notice.entry_updated' ); return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); @@ -304,9 +304,9 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $message = 'Entry reloaded'; + $message = 'flashes.entry.notice.entry_reloaded'; if (false === $this->updateEntry($entry)) { - $message = 'Failed to reload entry'; + $message = 'flashes.entry.notice.entry_reload_failed'; } $this->get('session')->getFlashBag()->add( @@ -334,9 +334,14 @@ class EntryController extends Controller $entry->toggleArchive(); $this->getDoctrine()->getManager()->flush(); + $message = 'flashes.entry.notice.entry_unarchived'; + if ($entry->isArchived()) { + $message = 'flashes.entry.notice.entry_archived'; + } + $this->get('session')->getFlashBag()->add( 'notice', - 'Entry '.($entry->isArchived() ? 'archived' : 'unarchived') + $message ); return $this->redirect($request->headers->get('referer')); @@ -359,9 +364,14 @@ class EntryController extends Controller $entry->toggleStar(); $this->getDoctrine()->getManager()->flush(); + $message = 'flashes.entry.notice.entry_unstarred'; + if ($entry->isStarred()) { + $message = 'flashes.entry.notice.entry_starred'; + } + $this->get('session')->getFlashBag()->add( 'notice', - 'Entry '.($entry->isStarred() ? 'starred' : 'unstarred') + $message ); return $this->redirect($request->headers->get('referer')); @@ -394,7 +404,7 @@ class EntryController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Entry deleted' + 'flashes.entry.notice.entry_deleted' ); // don't redirect user to the deleted entry diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 7b34939d..56e5195c 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -43,7 +43,7 @@ class TagController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'Tag added' + 'flashes.tag.notice.tag_added' ); return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 22039de3..c8a1973b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -332,3 +332,37 @@ validator: password_wrong_value: 'Wrong value for your current password' item_per_page_too_high: 'This will certainly kill the app' rss_limit_too_hight: 'This will certainly kill the app' + +flashes: + config: + notice: + config_saved: 'Config saved. Some parameters will be considered after disconnection.' + password_updated: 'Password updated' + password_not_updated_demo: "In demonstration mode, you can't change password for this user." + user_updated: 'Information updated' + rss_updated: 'RSS information updated' + tagging_rules_updated: 'Tagging rules updated' + tagging_rules_deleted: 'Tagging rule deleted' + user_added: 'User "%username%" added' + rss_token_updated: 'RSS token updated' + entry: + notice: + entry_already_saved: 'Entry already saved on %date%' + entry_saved: 'Entry saved' + entry_updated: 'Entry updated' + entry_reloaded: 'Entry reloaded' + entry_reload_failed: 'Failed to reload entry' + entry_archived: 'Entry archived' + entry_unarchived: 'Entry unarchived' + entry_starred: 'Entry starred' + entry_unstarred: 'Entry unstarred' + entry_deleted: 'Entry deleted' + tag: + notice: + tag_added: 'Tag added' + import: + notice: + failed: 'Import failed, please try again.' + failed_on_file: 'Error while processing import. Please verify your import file.' + summary: 'Import summary: %imported% imported, %skipped% already saved.' + diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php index 884e740e..f2d26750 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php @@ -57,7 +57,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('Config saved', $alert[0]); + $this->assertContains('flashes.config.notice.config_saved', $alert[0]); } public function dataForUpdateFailed() @@ -177,7 +177,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('Password updated', $alert[0]); + $this->assertContains('flashes.config.notice.password_updated', $alert[0]); } public function dataForUserFailed() @@ -245,7 +245,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Information updated', $alert[0]); + $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } public function dataForNewUserFailed() @@ -346,7 +346,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('User "wallace" added', $alert[0]); + $this->assertContains('flashes.config.notice.user_added', $alert[0]); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $user = $em @@ -433,7 +433,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('RSS information updated', $alert[0]); + $this->assertContains('flashes.config.notice.rss_updated', $alert[0]); } public function dataForRssFailed() @@ -499,7 +499,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('Tagging rules updated', $alert[0]); + $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); $deleteLink = $crawler->filter('.delete')->last()->link(); @@ -508,7 +508,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); - $this->assertContains('Tagging rule deleted', $alert[0]); + $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]); } public function dataForTaggingRuleFailed() @@ -602,7 +602,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertContains('In demonstration mode, you can\'t change password for this user.', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); + $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $config->set('demo_mode_enabled', 0); $config->set('demo_mode_username', 'wallabag'); diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index 7a35514b..1d804219 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -52,8 +52,9 @@ class PocketController extends Controller */ public function callbackAction() { - $message = 'Import failed, please try again.'; + $message = 'flashes.import.notice.failed'; $pocket = $this->get('wallabag_import.pocket.import'); + $markAsRead = $this->get('session')->get('mark_as_read'); $this->get('session')->remove('mark_as_read'); @@ -69,7 +70,10 @@ class PocketController extends Controller if (true === $pocket->setMarkAsRead($markAsRead)->import()) { $summary = $pocket->getSummary(); - $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; + $message = $this->get('translator')->trans('flashes.import.notice.summary', array( + '%imported%' => $summary['imported'], + '%skipped%' => $summary['skipped'], + )); } $this->get('session')->getFlashBag()->add( diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index 154a0769..1bc9696d 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php @@ -31,11 +31,14 @@ class WallabagV1Controller extends Controller ->setMarkAsRead($markAsRead) ->import(); - $message = 'Import failed, please try again.'; + $message = 'flashes.import.notice.failed'; if (true === $res) { $summary = $wallabag->getSummary(); - $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; + $message = $this->get('translator')->trans('flashes.import.notice.summary', array( + '%imported%' => $summary['imported'], + '%skipped%' => $summary['skipped'], + )); unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); } @@ -49,7 +52,7 @@ class WallabagV1Controller extends Controller } else { $this->get('session')->getFlashBag()->add( 'notice', - 'Error while processing import. Please verify your import file.' + 'flashes.import.notice.failed_on_file' ); } } diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php index 6dcd204a..3e6428a0 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php @@ -31,11 +31,14 @@ class WallabagV2Controller extends Controller ->setMarkAsRead($markAsRead) ->import(); - $message = 'Import failed, please try again.'; + $message = 'flashes.import.notice.failed'; if (true === $res) { $summary = $wallabag->getSummary(); - $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; + $message = $this->get('translator')->trans('flashes.import.notice.summary', array( + '%imported%' => $summary['imported'], + '%skipped%' => $summary['skipped'], + )); unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); } @@ -49,7 +52,7 @@ class WallabagV2Controller extends Controller } else { $this->get('session')->getFlashBag()->add( 'notice', - 'Error while processing import. Please verify your import file.' + 'flashes.import.notice.failed_on_file' ); } } diff --git a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php index c2acd68c..174641fd 100644 --- a/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php +++ b/src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php @@ -37,6 +37,6 @@ class PocketControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertContains('import/pocket', $client->getResponse()->headers->get('location')); - $this->assertEquals('Import failed, please try again.', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); + $this->assertEquals('flashes.import.notice.failed', $client->getContainer()->get('session')->getFlashBag()->peek('notice')[0]); } } diff --git a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php index 6c876b3b..8d353a71 100644 --- a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php +++ b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php @@ -55,7 +55,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertTrue($content->getTags()->contains($tag)); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Import summary', $body[0]); + $this->assertContains('flashes.import.notice.summary', $body[0]); } public function testImportWallabagWithFileAndMarkAllAsRead() @@ -100,7 +100,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertTrue($content2->isArchived()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Import summary', $body[0]); + $this->assertContains('flashes.import.notice.summary', $body[0]); } public function testImportWallabagWithEmptyFile() @@ -124,6 +124,6 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Import failed, please try again', $body[0]); + $this->assertContains('flashes.import.notice.failed', $body[0]); } } diff --git a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php index 58baa836..bcbd6305 100644 --- a/src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php +++ b/src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php @@ -40,7 +40,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Import summary', $body[0]); + $this->assertContains('flashes.import.notice.summary', $body[0]); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -88,6 +88,6 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text'))); - $this->assertContains('Import failed, please try again', $body[0]); + $this->assertContains('flashes.import.notice.failed', $body[0]); } } -- cgit v1.2.3