Add flashes messages

This commit is contained in:
Jeremy Benoist 2016-03-11 14:48:46 +01:00
parent 4f9cf232f8
commit 4204a06b77
11 changed files with 94 additions and 40 deletions

View 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');

View 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

View 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())));

View 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.'

View 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');

View 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(

View 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'
);
}
}

View 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'
);
}
}

View 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]);
}
}

View 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]);
}
}

View 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]);
}
}