From dd857d4629fe3ed28f209098cd1d7702d49742bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 14 Jan 2014 15:51:34 +0100 Subject: [PATCH] [add] flash message and undo remove --- app/app.php | 3 ++ app/controllers/front.php | 17 +++++++ app/views/_alerts.twig | 13 ++++++ app/views/layout.twig | 1 + src/Poche/Api/EntryApi.php | 4 ++ src/Poche/Repository/EntryRepository.php | 8 ++++ web/assets/css/style.css | 56 ++++++++++++++++++++++++ 7 files changed, 102 insertions(+) create mode 100644 app/views/_alerts.twig diff --git a/app/app.php b/app/app.php index 95b0550..3f6d5da 100644 --- a/app/app.php +++ b/app/app.php @@ -5,6 +5,7 @@ use Poche\Api\ContentFullTextRssApi; use Poche\Repository\EntryRepository; use Symfony\Component\Translation\Loader\PoFileLoader; +use Silex\Provider\SessionServiceProvider; $app = new Silex\Application(); @@ -38,6 +39,8 @@ $app->register(new Silex\Provider\TranslationServiceProvider(), array( 'locale_fallbacks' => array('en'), )); +$app->register(new SessionServiceProvider()); + $app['translator'] = $app->share($app->extend('translator', function($translator, $app) { $translator->addLoader('po', new PoFileLoader()); diff --git a/app/controllers/front.php b/app/controllers/front.php index 4958735..1eb7af9 100644 --- a/app/controllers/front.php +++ b/app/controllers/front.php @@ -62,6 +62,13 @@ $front->get('/unstar/{id}', function (Request $request, $id) use ($app) { $front->get('/remove/{id}', function (Request $request, $id) use ($app) { $entry = $app['entry_api']->remove($id); + $app['session']->getFlashBag()->add( + 'info', + array( + 'title' => 'success', + 'message' => 'entry #' . $id . ' removed. undo', + ) + ); $referer = $request->headers->get('referer'); @@ -69,6 +76,16 @@ $front->get('/remove/{id}', function (Request $request, $id) use ($app) { }) ->bind('remove_entry'); +$front->get('/restore/{id}', function (Request $request, $id) use ($app) { + + $entry = $app['entry_api']->restore($id); + + $referer = $request->headers->get('referer'); + + return $app->redirect($referer); +}) +->bind('restore_entry'); + $front->match('/add', function (Request $request) use ($app) { $data = array('url'); diff --git a/app/views/_alerts.twig b/app/views/_alerts.twig new file mode 100644 index 0000000..094d2e0 --- /dev/null +++ b/app/views/_alerts.twig @@ -0,0 +1,13 @@ +{% spaceless %} +{% set alertTypeAvaillable = [ 'info', 'success', 'warning', 'error'] %} +{% if app.session.flashBag is defined %} + {%- for alertType in alertTypeAvaillable %} + {%- for alert in app.session.flashBag.get(alertType) %} +
+ {% if alert.title %}

{{ alert.title|trans }}

{% endif %} + {{ alert.message|trans|raw }} +
+ {%- endfor %} + {%- endfor %} +{% endif %} +{% endspaceless %} \ No newline at end of file diff --git a/app/views/layout.twig b/app/views/layout.twig index af10365..b04a27d 100644 --- a/app/views/layout.twig +++ b/app/views/layout.twig @@ -19,6 +19,7 @@
{% include "_menu.twig" %} + {% include '_alerts.twig' %} {% block content %}{% endblock %}
diff --git a/src/Poche/Api/EntryApi.php b/src/Poche/Api/EntryApi.php index ab98092..5931757 100644 --- a/src/Poche/Api/EntryApi.php +++ b/src/Poche/Api/EntryApi.php @@ -43,6 +43,10 @@ class EntryApi return $this->entryRepository->remove($id); } + public function restore($id) { + return $this->entryRepository->restore($id); + } + public function createEntryFromUrl($url) { //TODO: Fetch all what we need, fill the title, content … diff --git a/src/Poche/Repository/EntryRepository.php b/src/Poche/Repository/EntryRepository.php index e6e5362..13fc5c1 100644 --- a/src/Poche/Repository/EntryRepository.php +++ b/src/Poche/Repository/EntryRepository.php @@ -80,5 +80,13 @@ class EntryRepository return $count; } + //TODO don't hardcode the user ;) + public function restore($id, $userId = 1) { + $sql = "UPDATE entries SET status = 'unread' where id = ? AND user_id = ?"; + $count = $this->db->executeUpdate($sql, array($id, $userId)); + + return $count; + } + } diff --git a/web/assets/css/style.css b/web/assets/css/style.css index fb38152..ef93a22 100644 --- a/web/assets/css/style.css +++ b/web/assets/css/style.css @@ -36,4 +36,60 @@ footer { .reading-time { font-size: 0.8em; +} + +.alert { + padding: 8px 35px 8px 14px; + margin-bottom: 20px; + color: #c09853; + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); + background-color: #fcf8e3; + border: 1px solid #fbeed5; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; +} + +.alert h4 { + margin: 0; +} + +.alert .close { + position: relative; + top: -2px; + right: -21px; + line-height: 20px; +} + +.alert-success { + color: #468847; + background-color: #dff0d8; + border-color: #d6e9c6; +} + +.alert-danger, +.alert-error { + color: #b94a48; + background-color: #f2dede; + border-color: #eed3d7; +} + +.alert-info { + color: #3a87ad; + background-color: #d9edf7; + border-color: #bce8f1; +} + +.alert-block { + padding-top: 14px; + padding-bottom: 14px; +} + +.alert-block > p, +.alert-block > ul { + margin-bottom: 0; +} + +.alert-block p + p { + margin-top: 5px; } \ No newline at end of file