1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-15 13:45:04 -05:00

[add] flash message and undo remove

This commit is contained in:
Nicolas Lœuillet 2014-01-14 15:51:34 +01:00
parent 6fee53233e
commit dd857d4629
7 changed files with 102 additions and 0 deletions

View File

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

View File

@ -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. <a href="'.$app['url_generator']->generate('restore_entry', array('id' => $id)).'">undo</a>',
)
);
$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');

13
app/views/_alerts.twig Normal file
View File

@ -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) %}
<div class="alert alert-{{ alertType }}" >
{% if alert.title %}<h4 class="alert-heading">{{ alert.title|trans }}</h4>{% endif %}
{{ alert.message|trans|raw }}
</div>
{%- endfor %}
{%- endfor %}
{% endif %}
{% endspaceless %}

View File

@ -19,6 +19,7 @@
<div id="main">
<div id="content" class="w600p center">
{% include "_menu.twig" %}
{% include '_alerts.twig' %}
{% block content %}{% endblock %}
</div>
</div>

View File

@ -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 …

View File

@ -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;
}
}

View File

@ -37,3 +37,59 @@ 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;
}