Custom top lists length

This commit is contained in:
aunefyren 2022-10-15 22:07:15 +02:00
parent ff83892999
commit 65e866955b
7 changed files with 47 additions and 22 deletions

View file

@ -8,6 +8,7 @@
"stats_outro_subtitle":"Goodbye.",
"stats_order_by_plays":true,
"stats_order_by_duration":true,
"stats_top_list_length": 10,
"get_user_movie_stats":true,
"get_user_movie_stats_title":"Movies!",
"get_user_movie_stats_subtitle":"You watched {movie_count} movies. That's a lot of movies!",

View file

@ -10,7 +10,7 @@ import (
"github.com/google/uuid"
)
var wrapperr_version_parameter = "v3.0.3"
var wrapperr_version_parameter = "v3.0.4"
var config_path, _ = filepath.Abs("./config/config.json")
var default_config_path, _ = filepath.Abs("./config_default.json")
@ -123,6 +123,7 @@ func CreateConfigFile() error {
config.TautulliConfig.TautulliGrouping = true
config.CreateShareLinks = true
config.WinterTheme = true
config.WrapperrCustomize.StatsTopListLength = 10
config.WrapperrCustomize.StatsOrderByDuration = true
config.WrapperrCustomize.StatsOrderByPlays = true
config.WrapperrCustomize.GetUserMovieStats = true
@ -227,6 +228,10 @@ func GetConfig() (*WrapperrConfig, error) {
config.TautulliConfig.TautulliPort = config_default.TautulliConfig.TautulliPort
}
if config.WrapperrCustomize.StatsTopListLength < 0 {
config.WrapperrCustomize.StatsTopListLength = config_default.WrapperrCustomize.StatsTopListLength
}
if config.WrapperrCustomize.WrapperrFrontPageTitle == "" {
config.WrapperrCustomize.WrapperrFrontPageTitle = config_default.WrapperrCustomize.WrapperrFrontPageTitle
}

View file

@ -78,6 +78,7 @@ type WrapperrCustomize struct {
StatsOutroSubtitle string `json:"stats_outro_subtitle"`
StatsOrderByPlays bool `json:"stats_order_by_plays"`
StatsOrderByDuration bool `json:"stats_order_by_duration"`
StatsTopListLength int `json:"stats_top_list_length"`
GetUserMovieStats bool `json:"get_user_movie_stats"`
GetUserMovieStatsTitle string `json:"get_user_movie_stats_title"`
GetUserMovieStatsSubtitle string `json:"get_user_movie_stats_subtitle"`

View file

@ -368,7 +368,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
end_loop_date := time.Unix(int64(config.WrappedEnd), 0)
start_loop_date := time.Unix(int64(config.WrappedStart), 0)
top_list_limit := 10
top_list_limit := config.WrapperrCustomize.StatsTopListLength
var wrapperr_user_movie []TautulliEntry
var wrapperr_user_episode []TautulliEntry
@ -695,7 +695,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_movie, "Duration")
count := 0
for _, entry := range wrapperr_user_movie {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMovies.Data.MoviesDuration = append(wrapperr_reply.User.UserMovies.Data.MoviesDuration, entry)
@ -706,7 +706,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_movie, "Plays")
count = 0
for _, entry := range wrapperr_user_movie {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMovies.Data.MoviesPlays = append(wrapperr_reply.User.UserMovies.Data.MoviesPlays, entry)
@ -756,7 +756,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_show, "Duration")
count := 0
for _, entry := range wrapperr_user_show {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserShows.Data.ShowsDuration = append(wrapperr_reply.User.UserShows.Data.ShowsDuration, entry)
@ -767,7 +767,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_show, "Plays")
count = 0
for _, entry := range wrapperr_user_show {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserShows.Data.ShowsPlays = append(wrapperr_reply.User.UserShows.Data.ShowsPlays, entry)
@ -808,7 +808,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_track, "Duration")
count := 0
for _, entry := range wrapperr_user_track {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.TracksDuration = append(wrapperr_reply.User.UserMusic.Data.TracksDuration, entry)
@ -819,7 +819,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_track, "Plays")
count = 0
for _, entry := range wrapperr_user_track {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.TracksPlays = append(wrapperr_reply.User.UserMusic.Data.TracksPlays, entry)
@ -830,7 +830,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_album, "Duration")
count = 0
for _, entry := range wrapperr_user_album {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.AlbumsDuration = append(wrapperr_reply.User.UserMusic.Data.AlbumsDuration, entry)
@ -841,7 +841,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_album, "Plays")
count = 0
for _, entry := range wrapperr_user_album {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.AlbumsPlays = append(wrapperr_reply.User.UserMusic.Data.AlbumsPlays, entry)
@ -852,7 +852,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_artist, "Duration")
count = 0
for _, entry := range wrapperr_user_artist {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.ArtistsDuration = append(wrapperr_reply.User.UserMusic.Data.ArtistsDuration, entry)
@ -863,7 +863,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_user_artist, "Plays")
count = 0
for _, entry := range wrapperr_user_artist {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.User.UserMusic.Data.ArtistsPlays = append(wrapperr_reply.User.UserMusic.Data.ArtistsPlays, entry)
@ -909,7 +909,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_movie, "Duration")
count := 0
for _, entry := range wrapperr_year_movie {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearMovies.Data.MoviesDuration = append(wrapperr_reply.YearStats.YearMovies.Data.MoviesDuration, entry)
@ -920,7 +920,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_movie, "Plays")
count = 0
for _, entry := range wrapperr_year_movie {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearMovies.Data.MoviesPlays = append(wrapperr_reply.YearStats.YearMovies.Data.MoviesPlays, entry)
@ -953,7 +953,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_show, "Duration")
count := 0
for _, entry := range wrapperr_year_show {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearShows.Data.ShowsDuration = append(wrapperr_reply.YearStats.YearShows.Data.ShowsDuration, entry)
@ -964,7 +964,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_show, "Plays")
count = 0
for _, entry := range wrapperr_year_show {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearShows.Data.ShowsPlays = append(wrapperr_reply.YearStats.YearShows.Data.ShowsPlays, entry)
@ -997,7 +997,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_artist, "Duration")
count := 0
for _, entry := range wrapperr_year_artist {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearMusic.Data.ArtistsDuration = append(wrapperr_reply.YearStats.YearMusic.Data.ArtistsDuration, entry)
@ -1008,7 +1008,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_artist, "Plays")
count = 0
for _, entry := range wrapperr_year_artist {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearMusic.Data.ArtistsPlays = append(wrapperr_reply.YearStats.YearMusic.Data.ArtistsPlays, entry)
@ -1046,7 +1046,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_user, "Duration")
count := 0
for _, entry := range wrapperr_year_user {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearUsers.Data.UsersDuration = append(wrapperr_reply.YearStats.YearUsers.Data.UsersDuration, entry)
@ -1057,7 +1057,7 @@ func WrapperrLoopData(user_id int, config *WrapperrConfig, wrapperr_data []Wrapp
sortutil.DescByField(wrapperr_year_user, "Plays")
count = 0
for _, entry := range wrapperr_year_user {
if count >= top_list_limit {
if count >= top_list_limit && top_list_limit != 0 {
break
}
wrapperr_reply.YearStats.YearUsers.Data.UsersPlays = append(wrapperr_reply.YearStats.YearUsers.Data.UsersPlays, entry)

View file

@ -825,6 +825,15 @@ function set_wrapperr_customization() {
html += '<hr>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="stats_top_list_length" title="Use 0 for no limit.">Maximum length of top lists:<br>';
html += '<input type="number" class="form-control" id="stats_top_list_length" value="' + stats_top_list_length + '" autocomplete="off" placeholder="" required /><br>';
html += '</div>';
html += '<div class="form-group newline">';
html += '<hr>';
html += '</div>';
html += '<div class="form-group">';
html += '<label for="wrapperr_front_page_title" title="Introduction title that is shown on top of the front page.">Introduction title for the front page:<br>';
html += '<textarea cols="40" rows="5" class="form-control" style="overflow-x: hidden;resize:vertical;min-height: 5em;" id="wrapperr_front_page_title" name="wrapperr_front_page_title" value="" autocomplete="off"></textarea></label>';
@ -1561,6 +1570,7 @@ function set_wrapperr_customization() {
document.getElementById("stats_intro_subtitle").value = stats_intro_subtitle;
document.getElementById("stats_outro_title").value = stats_outro_title;
document.getElementById("stats_outro_subtitle").value = stats_outro_subtitle;
document.getElementById("stats_top_list_length").value = stats_top_list_length;
document.getElementById("get_user_movie_stats_title").value = get_user_movie_stats_title;
document.getElementById("get_user_movie_stats_subtitle").value = get_user_movie_stats_subtitle;
@ -1646,6 +1656,7 @@ function set_wrapperr_customization_call() {
stats_outro_subtitle = document.getElementById('stats_outro_subtitle').value;
stats_order_by_plays = document.getElementById('stats_order_by_plays').checked;
stats_order_by_duration = document.getElementById('stats_order_by_duration').checked;
stats_top_list_length = parseInt(document.getElementById("stats_top_list_length").value);
get_user_movie_stats = document.getElementById('get_user_movie_stats').checked;
get_user_movie_stats_title = document.getElementById('get_user_movie_stats_title').value;
@ -1754,6 +1765,7 @@ function set_wrapperr_customization_call() {
"stats_outro_subtitle" : stats_outro_subtitle,
"stats_order_by_plays" : stats_order_by_plays,
"stats_order_by_duration" : stats_order_by_duration,
"stats_top_list_length" : stats_top_list_length,
"get_user_movie_stats" : get_user_movie_stats,
"get_user_movie_stats_title" : get_user_movie_stats_title,
"get_user_movie_stats_subtitle" : get_user_movie_stats_subtitle,
@ -1846,6 +1858,9 @@ function set_wrapperr_customization_call() {
var wrapperr_customization_data = JSON.stringify(wrapperr_customization_form);
// Debug line
// console.log(wrapperr_customization_data);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
@ -2397,6 +2412,7 @@ function get_config(cookie) {
stats_intro_subtitle = result.data.wrapperr_customize.stats_intro_subtitle;
stats_outro_title = result.data.wrapperr_customize.stats_outro_title;
stats_outro_subtitle = result.data.wrapperr_customize.stats_outro_subtitle;
stats_top_list_length = result.data.wrapperr_customize.stats_top_list_length;
get_user_movie_stats = result.data.wrapperr_customize.get_user_movie_stats;
get_user_movie_stats_title = result.data.wrapperr_customize.get_user_movie_stats_title;

View file

@ -75,6 +75,8 @@ var stats_outro_title = '';
var stats_outro_subtitle = '';
var stats_order_by_plays = '';
var stats_order_by_duration = '';
var stats_top_list_length = 0;
var client_id = '';
var wrapperr_root = '';
var winter_theme = false;

View file

@ -717,7 +717,7 @@ function top_list(array, title, music, show, year, div_id) {
html += "<div class='stats'>";
html += "<div class='status-title'>" + title + "</div>";
html += "<div class='stats-list'>";
for(i = 0; (i < array.length && i < 10); i++) {
for(i = 0; (i < array.length); i++) {
html += "<div class='item'>";
html += "<div class='number'>";
html += i+1 + ". ";
@ -769,7 +769,7 @@ function top_list_names(array, title, div_id) {
html += "<div class='stats'>";
html += "<div class='status-title'>" + title + "</div>";
html += "<div class='stats-list'>";
for(i = 0; i < 10 && i < array.length; i++) {
for(i = 0; i < array.length; i++) {
if(i == 0) {
html += "<div class='item gold'>";
} else if(i == 1) {