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 +++++----- 5 files changed, 70 insertions(+), 26 deletions(-) (limited to 'src/Wallabag/CoreBundle') 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'); -- cgit v1.2.3