aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/sort.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/routes/ui/sort.rs')
-rw-r--r--server/src/routes/ui/sort.rs51
1 files changed, 45 insertions, 6 deletions
diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs
index 4db8f3d..3748a44 100644
--- a/server/src/routes/ui/sort.rs
+++ b/server/src/routes/ui/sort.rs
@@ -1,4 +1,4 @@
-use jellycommon::{NodeKind, NodePublic};
+use jellycommon::{helpers::SortAnyway, NodeKind, NodePublic, Rating};
use rocket::{
http::uri::fmt::{Query, UriDisplay},
FromForm, FromFormField, UriDisplayQuery,
@@ -12,10 +12,32 @@ pub struct NodeFilterSort {
}
#[rustfmt::skip]
-#[derive(FromFormField, UriDisplayQuery, Clone, Copy, PartialEq, Eq)]
+#[derive(FromFormField, UriDisplayQuery, Clone, PartialEq, Eq)]
enum SortProperty {
#[field(value = "release_date")] ReleaseDate,
#[field(value = "title")] Title,
+ #[field(value = "rating_rt")] RatingRottenTomatoes,
+ #[field(value = "rating_mc")] RatingMetacritic,
+ #[field(value = "rating_imdb")] RatingImdb,
+ #[field(value = "rating_yt_views")] RatingYoutubeViews,
+ #[field(value = "rating_yt_likes")] RatingYoutubeLikes,
+ #[field(value = "rating_yt_followers")] RatingYoutubeFollowers,
+}
+
+impl SortProperty {
+ const ALL: &[(SortProperty, &'static str)] = {
+ use SortProperty::*;
+ &[
+ (Title, "Title"),
+ (ReleaseDate, "Release Date"),
+ (RatingImdb, "IMDb Rating"),
+ (RatingMetacritic, "Metacritic Rating"),
+ (RatingRottenTomatoes, "Rotten Tomatoes"),
+ (RatingYoutubeFollowers, "Youtube Subscribers"),
+ (RatingYoutubeLikes, "Youtube Likes"),
+ (RatingYoutubeViews, "Youtube Views"),
+ ]
+ };
}
#[rustfmt::skip]
@@ -33,10 +55,28 @@ pub fn filter_and_sort_nodes(f: &NodeFilterSort, nodes: &mut Vec<(String, NodePu
}
o
});
- if let Some(sort_prop) = f.sort_by {
+ if let Some(sort_prop) = &f.sort_by {
match sort_prop {
SortProperty::ReleaseDate => nodes.sort_by_key(|(_, _n)| 0), // TODO
SortProperty::Title => nodes.sort_by(|(_, a), (_, b)| a.title.cmp(&b.title)),
+ SortProperty::RatingRottenTomatoes => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::RottenTomatoes).unwrap_or(&0.))
+ }),
+ SortProperty::RatingMetacritic => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::Metacritic).unwrap_or(&0.))
+ }),
+ SortProperty::RatingImdb => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::Imdb).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeViews => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeViews).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeLikes => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeLikes).unwrap_or(&0.))
+ }),
+ SortProperty::RatingYoutubeFollowers => nodes.sort_by_cached_key(|(_, n)| {
+ SortAnyway(*n.ratings.get(&Rating::YoutubeFollowers).unwrap_or(&0.))
+ }),
}
}
match f.sort_order.unwrap_or(SortOrder::Ascending) {
@@ -59,9 +99,8 @@ markup::define! {
}
fieldset.sortby {
legend { "Sort By" }
- @use SortProperty::*;
- @for (value, label) in [(Title, "Title"), (ReleaseDate, "Release Date")] {
- label { input[type="radio", name="sort_by", value=value, checked=Some(value)==f.sort_by]; @label } br;
+ @for (value, label) in SortProperty::ALL {
+ label { input[type="radio", name="sort_by", value=value, checked=Some(value)==f.sort_by.as_ref()]; @label } br;
}
}
fieldset.sortorder {