-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #39.
- Loading branch information
Showing
6 changed files
with
267 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Stats views. | ||
use rocket::{get, response::Redirect}; | ||
use rocket_contrib::templates::Template; | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
auth, | ||
data::{self, LocationOrderBy}, | ||
models::{LocationWithCount, User}, | ||
}; | ||
|
||
// Contexts | ||
|
||
#[derive(Serialize)] | ||
struct StatsContext { | ||
user: User, | ||
launch_locations: Vec<LocationWithCount>, | ||
landing_locations: Vec<LocationWithCount>, | ||
} | ||
|
||
// Views | ||
|
||
#[get("/stats")] | ||
pub(crate) fn stats(db: data::Database, user: auth::AuthUser) -> Template { | ||
let user = user.into_inner(); | ||
|
||
// Get all locations | ||
let launch_locations = data::get_locations_with_stats_for_user(&db, &user, LocationOrderBy::Launches, 10); | ||
let landing_locations = | ||
data::get_locations_with_stats_for_user(&db, &user, LocationOrderBy::Landings, 10); | ||
|
||
// Render template | ||
let context = StatsContext { | ||
user, | ||
launch_locations, | ||
landing_locations, | ||
}; | ||
Template::render("stats", &context) | ||
} | ||
|
||
#[get("/stats", rank = 2)] | ||
pub(crate) fn stats_nologin() -> Redirect { | ||
Redirect::to("/auth/login") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends 'base' %} | ||
|
||
{% import 'macros' as macros %} | ||
|
||
{% block content %} | ||
<h2 class="title is-2">Stats</h2> | ||
|
||
<section> | ||
<div class="columns"> | ||
<div class="column"> | ||
<h3 class="title is-4">Top Launch Sites</h3> | ||
<ul> | ||
{% for location in launch_locations %}<li>{{ macros::flag(country_code=location.country) }} {{ location.name }} ({{ location.count }})</li>{% endfor %} | ||
</ul> | ||
</div> | ||
<div class="column"> | ||
<h3 class="title is-4">Top Landing Sites</h3> | ||
<ul> | ||
{% for location in landing_locations %}<li>{{ macros::flag(country_code=location.country) }} {{ location.name }} ({{ location.count }})</li>{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
</section> | ||
{% endblock %} |