2018-06-04 21:57:03 +02:00
|
|
|
use rocket::response::{Redirect, Flash};
|
2018-12-06 18:54:16 +01:00
|
|
|
use rocket_i18n::I18n;
|
2018-05-13 15:35:55 +02:00
|
|
|
|
2018-06-23 18:36:11 +02:00
|
|
|
use plume_common::utils;
|
|
|
|
use plume_models::{db_conn::DbConn, notifications::Notification, users::User};
|
2018-07-25 15:33:54 +02:00
|
|
|
use routes::Page;
|
2018-12-06 18:54:16 +01:00
|
|
|
use template_utils::Ructe;
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-07-25 15:33:54 +02:00
|
|
|
#[get("/notifications?<page>")]
|
2018-12-06 18:54:16 +01:00
|
|
|
pub fn paginated_notifications(conn: DbConn, user: User, page: Page, intl: I18n) -> Ructe {
|
|
|
|
render!(notifications::index(
|
|
|
|
&(&*conn, &intl.catalog, Some(user.clone())),
|
|
|
|
Notification::page_for_user(&*conn, &user, page.limits()),
|
|
|
|
page.0,
|
|
|
|
Page::total(Notification::find_for_user(&*conn, &user).len() as i32)
|
|
|
|
))
|
2018-05-13 15:35:55 +02:00
|
|
|
}
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-07-25 15:33:54 +02:00
|
|
|
#[get("/notifications")]
|
2018-12-06 18:54:16 +01:00
|
|
|
pub fn notifications(conn: DbConn, user: User, intl: I18n) -> Ructe {
|
|
|
|
paginated_notifications(conn, user, Page::first(), intl)
|
2018-07-25 15:33:54 +02:00
|
|
|
}
|
|
|
|
|
2018-06-04 21:57:03 +02:00
|
|
|
#[get("/notifications", rank = 2)]
|
2018-12-06 18:54:16 +01:00
|
|
|
pub fn notifications_auth(i18n: I18n) -> Flash<Redirect>{
|
2018-09-08 01:11:27 +02:00
|
|
|
utils::requires_login(
|
2018-12-06 18:54:16 +01:00
|
|
|
i18n!(i18n.catalog, "You need to be logged in order to see your notifications"),
|
2018-11-26 10:21:52 +01:00
|
|
|
uri!(notifications)
|
2018-09-08 01:11:27 +02:00
|
|
|
)
|
2018-06-04 21:57:03 +02:00
|
|
|
}
|