]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add flashes messages
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 11 Mar 2016 13:48:46 +0000 (14:48 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 20 Mar 2016 20:12:22 +0000 (21:12 +0100)
src/Wallabag/CoreBundle/Controller/ConfigController.php
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Controller/TagController.php
src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
src/Wallabag/ImportBundle/Controller/PocketController.php
src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
src/Wallabag/ImportBundle/Tests/Controller/PocketControllerTest.php
src/Wallabag/ImportBundle/Tests/Controller/WallabagV1ControllerTest.php
src/Wallabag/ImportBundle/Tests/Controller/WallabagV2ControllerTest.php

index d24066b3fc1d671dc0501e400c007e284f5ef742..779be2689897a3344a279f4b667acbc03b0cffbe 100644 (file)
@@ -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');
index 0fae3a0ff1d49687749a6cb802de2d5686a151cf..1a0b80ac589fd8eed9b3c363274640d7c5316171 100644 (file)
@@ -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
index 7b34939d2495847074fbf270f436ff6849d4580e..56e5195c1fc0075af5d9896416a5c9f5e5965ee3 100644 (file)
@@ -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())));
index 22039de32947dfcac22eed0e3b851f9b08a4d007..c8a1973b4bd9baf381afb2e23b7241566959ba46 100644 (file)
@@ -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.'
+
index 884e740eed790ec21ae2a3367678d65f32d7e956..f2d267503fbfc5c2d55f50f0ec257a49b993c449 100644 (file)
@@ -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');
index 7a35514baf7803584f0ba08aea509b6c80545352..1d80421923cac43ed008f2ff8317e2a583598271 100644 (file)
@@ -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(
index 154a0769b0ac4688008e4f012b08499f28d28dda..1bc9696d5b90bbdfb42dfeab056dbc7e9c8b4673 100644 (file)
@@ -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'
                 );
             }
         }
index 6dcd204a7240a6d15f0fc84f035c4a254e663869..3e6428a049903c72c094be73df5341feb970565a 100644 (file)
@@ -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'
                 );
             }
         }
index c2acd68c324d7f8406fc46037cdf76a1462404b6..174641fd5be758a74c007661e756225fd8997f8c 100644 (file)
@@ -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]);
     }
 }
index 6c876b3b419eeea6a2e7e2da60b815af4905aac0..8d353a711e88ac0f3d6ef1f22efbb5cbd17ff8fc 100644 (file)
@@ -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]);
     }
 }
index 58baa8360cb3af0af413c0f2cdc4a5fc6415af46..bcbd6305774632b9cb0e5e1587a3965ea01f9841 100644 (file)
@@ -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]);
     }
 }