diff --git a/files/config.go b/files/config.go index 928e0b8..a46409c 100644 --- a/files/config.go +++ b/files/config.go @@ -136,6 +136,8 @@ func CreateConfigFile() error { config.CreateShareLinks = true config.WinterTheme = true config.BasicAuth = false + config.WrappedDynamic = false + config.WrappedDynamicDays = 0 config.WrapperrCustomize.StatsTopListLength = 10 config.WrapperrCustomize.ObfuscateOtherUsers = true config.WrapperrCustomize.StatsOrderByDuration = true diff --git a/models/config.go b/models/config.go index 24d7f12..4b305f7 100644 --- a/models/config.go +++ b/models/config.go @@ -1,24 +1,26 @@ package models type WrapperrConfig struct { - TautulliConfig []TautulliConfig `json:"tautulli_config"` - WrapperrCustomize WrapperrCustomize `json:"wrapperr_customize"` - WrapperrVersion string `json:"wrapperr_version"` - Timezone string `json:"timezone"` - ApplicationName string `json:"application_name"` - ApplicationURL string `json:"application_url"` - UseCache bool `json:"use_cache"` - UseLogs bool `json:"use_logs"` - ClientKey string `json:"client_key"` - WrapperrRoot string `json:"wrapperr_root"` - PrivateKey string `json:"private_key"` - CreateShareLinks bool `json:"create_share_links"` - WrappedStart int `json:"wrapped_start"` - WrappedEnd int `json:"wrapped_end"` - WrapperrPort int `json:"wrapperr_port"` - PlexAuth bool `json:"plex_auth"` - BasicAuth bool `json:"basic_auth"` - WinterTheme bool `json:"winter_theme"` + TautulliConfig []TautulliConfig `json:"tautulli_config"` + WrapperrCustomize WrapperrCustomize `json:"wrapperr_customize"` + WrapperrVersion string `json:"wrapperr_version"` + Timezone string `json:"timezone"` + ApplicationName string `json:"application_name"` + ApplicationURL string `json:"application_url"` + UseCache bool `json:"use_cache"` + UseLogs bool `json:"use_logs"` + ClientKey string `json:"client_key"` + WrapperrRoot string `json:"wrapperr_root"` + PrivateKey string `json:"private_key"` + CreateShareLinks bool `json:"create_share_links"` + WrappedStart int `json:"wrapped_start"` + WrappedEnd int `json:"wrapped_end"` + WrappedDynamic bool `json:"wrapped_dynamic"` + WrappedDynamicDays int `json:"wrapped_dynamic_days"` + WrapperrPort int `json:"wrapperr_port"` + PlexAuth bool `json:"plex_auth"` + BasicAuth bool `json:"basic_auth"` + WinterTheme bool `json:"winter_theme"` } type WrapperrConfigLegacy struct { @@ -47,17 +49,19 @@ type SetWrapperrConfig struct { TautulliConfig []TautulliConfig `json:"tautulli_config"` WrapperrCustomize WrapperrCustomize `json:"wrapperr_customize"` WrapperrData struct { - UseCache bool `json:"use_cache"` - UseLogs bool `json:"use_logs"` - PlexAuth bool `json:"plex_auth"` - BasicAuth bool `json:"basic_auth"` - WrapperrRoot string `json:"wrapperr_root"` - CreateShareLinks bool `json:"create_share_links"` - Timezone string `json:"timezone"` - ApplicationName string `json:"application_name"` - ApplicationURL string `json:"application_url"` - WrappedStart int `json:"wrapped_start"` - WrappedEnd int `json:"wrapped_end"` - WinterTheme bool `json:"winter_theme"` + UseCache bool `json:"use_cache"` + UseLogs bool `json:"use_logs"` + PlexAuth bool `json:"plex_auth"` + BasicAuth bool `json:"basic_auth"` + WrapperrRoot string `json:"wrapperr_root"` + CreateShareLinks bool `json:"create_share_links"` + Timezone string `json:"timezone"` + ApplicationName string `json:"application_name"` + ApplicationURL string `json:"application_url"` + WrappedStart int `json:"wrapped_start"` + WrappedEnd int `json:"wrapped_end"` + WinterTheme bool `json:"winter_theme"` + WrappedDynamic bool `json:"wrapped_dynamic"` + WrappedDynamicDays int `json:"wrapped_dynamic_days"` } `json:"wrapperr_data"` } diff --git a/modules/statistics.go b/modules/statistics.go index a61a25e..5c045c5 100644 --- a/modules/statistics.go +++ b/modules/statistics.go @@ -36,6 +36,12 @@ func GetWrapperStatistics(user_name string, user_friendlyname string, user_id in log.Println("Cache stage completed for " + user_name + ".") + // Change wrapped start & end dates if dynamic setting is configured + if config.WrappedDynamic { + config.WrappedEnd = int(time.Now().Unix()) + config.WrappedStart = int(time.Now().AddDate(0, 0, -config.WrappedDynamicDays).Unix()) + } + // Download/refresh data-set from Tautulli wrapperr_data, wrapperr_data_complete, err := WrapperrDownloadDays(user_id, wrapperr_data, cacheLimit, config) if err != nil { diff --git a/routes/admin.go b/routes/admin.go index ae25cd8..49bcb35 100644 --- a/routes/admin.go +++ b/routes/admin.go @@ -117,6 +117,8 @@ func ApiSetConfig(context *gin.Context) { config.ApplicationURL = config_payload.WrapperrData.ApplicationURL config.WrappedEnd = config_payload.WrapperrData.WrappedEnd config.WrappedStart = config_payload.WrapperrData.WrappedStart + config.WrappedDynamic = config_payload.WrapperrData.WrappedDynamic + config.WrappedDynamicDays = config_payload.WrapperrData.WrappedDynamicDays config.WinterTheme = config_payload.WrapperrData.WinterTheme err = files.SaveConfig(config) diff --git a/web/assets/css/admin.css b/web/assets/css/admin.css index 5a676b6..ae48972 100644 --- a/web/assets/css/admin.css +++ b/web/assets/css/admin.css @@ -518,4 +518,12 @@ a { align-content: center; justify-content: center; align-items: center; +} + +.dynamic-enabled, .static-enabled { + display: flex; +} + +.dynamic-disabled, .static-disabled { + display: none; } \ No newline at end of file diff --git a/web/html/settings.html b/web/html/settings.html index 9c483cd..b952db5 100644 --- a/web/html/settings.html +++ b/web/html/settings.html @@ -81,6 +81,8 @@ var application_url_str = ''; var wrapped_start = ''; var wrapped_end = ''; +var wrapped_dynamic = false; +var wrapped_dynamic_days = 0; var create_share_links = ''; var obfuscate_other_users = false; diff --git a/web/js/adminFunctions.js b/web/js/adminFunctions.js index 82ae60b..7891598 100644 --- a/web/js/adminFunctions.js +++ b/web/js/adminFunctions.js @@ -164,6 +164,9 @@ function get_config(cookie) { wrapped_end = new Date(0); wrapped_end.setUTCSeconds(result.data.wrapped_end); + wrapped_dynamic = result.data.wrapped_dynamic + wrapped_dynamic_days = result.data.wrapped_dynamic_days + stats_order_by_plays = result.data.wrapperr_customize.stats_order_by_plays; stats_order_by_duration = result.data.wrapperr_customize.stats_order_by_duration; diff --git a/web/js/settings.js b/web/js/settings.js index efab2b8..c41cff9 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -25,6 +25,20 @@ function loadAdminPage() { html += '
!
The more unique days in the wrapped period, the more Tautulli API calls. It is recommended to enable "Cache results for later use" to prevent long load times.
'; html += ''; + html += '
'; + html += ''; html += '
'; + html += ''; + + html += '
'; + + html += '
'; + html += ''; + html += '
'; + + html += '
'; + html += '
'; html += '
'; html += '
'; @@ -153,6 +178,10 @@ function loadAdminPage() { document.getElementById("setup").innerHTML = html; getTimezones(); + + if(wrapped_dynamic) { + toggleWrappedPeriod(); + } } function set_wrapperr_settings_call() { @@ -175,6 +204,8 @@ function set_wrapperr_settings_call() { timezone = document.getElementById('timezone').value; clear_cache = document.getElementById('clear_cache').checked; winter_theme = document.getElementById('winter_theme').checked; + wrapped_dynamic = document.getElementById('wrapped_dynamic').checked; + wrapped_dynamic_days = document.getElementById('wrapped_dynamic_days').value; if(wrapperr_root_original !== wrapperr_root) { if(!confirm("You have changed the Wrapperr root/base URL. Wrapperr will attempt to restart and the interface to access this webpage will change. If you are using an URL base you must use a trailing '/' at the end of your new URL.")){ @@ -228,25 +259,27 @@ function set_wrapperr_settings_call() { } wrapperr_settings_form = { - "clear_cache" : clear_cache, - "data_type" : "wrapperr_data", - "tautulli_config" : [], - "wrapperr_customize" : {}, - "wrapperr_data" : { - "use_cache" : use_cache, - "use_logs" : use_logs, - "plex_auth" : plex_auth, - "basic_auth" : basic_auth, - "wrapperr_root" : wrapperr_root, - "create_share_links" : create_share_links, - "timezone" : timezone, - "application_name" : application_name_str, - "application_url" : application_url_str, - "wrapped_start" : Math.round(wrapped_start.getTime() / 1000), - "wrapped_end" : Math.round(wrapped_end.getTime() / 1000), - "winter_theme" : winter_theme - } - }; + "clear_cache" : clear_cache, + "data_type" : "wrapperr_data", + "tautulli_config" : [], + "wrapperr_customize" : {}, + "wrapperr_data" : { + "use_cache" : use_cache, + "use_logs" : use_logs, + "plex_auth" : plex_auth, + "basic_auth" : basic_auth, + "wrapperr_root" : wrapperr_root, + "create_share_links" : create_share_links, + "timezone" : timezone, + "application_name" : application_name_str, + "application_url" : application_url_str, + "wrapped_start" : Math.round(wrapped_start.getTime() / 1000), + "wrapped_end" : Math.round(wrapped_end.getTime() / 1000), + "wrapped_dynamic" : wrapped_dynamic, + "wrapped_dynamic_days" : parseInt(wrapped_dynamic_days), + "winter_theme" : winter_theme + } + }; var wrapperr_settings_data = JSON.stringify(wrapperr_settings_form); @@ -320,4 +353,29 @@ function placeTimezones(timezoneArray) { option.name = item; dataList.appendChild(option); }); +} + +function toggleWrappedPeriod() { + wrapped_dynamic = document.getElementById("wrapped-dynamic") + wrapped_static = document.getElementById("wrapped-static") + + if(wrapped_dynamic.classList.contains("dynamic-enabled")) { + wrapped_dynamic.classList.remove("dynamic-enabled") + wrapped_dynamic.classList.add("dynamic-disabled") + } else if(wrapped_dynamic.classList.contains("dynamic-disabled")) { + wrapped_dynamic.classList.add("dynamic-enabled") + wrapped_dynamic.classList.remove("dynamic-disabled") + } else { + wrapped_dynamic.classList.add("dynamic-disabled") + } + + if(wrapped_static.classList.contains("static-enabled")) { + wrapped_static.classList.remove("static-enabled") + wrapped_static.classList.add("static-disabled") + } else if(wrapped_static.classList.contains("static-disabled")) { + wrapped_static.classList.add("static-enabled") + wrapped_static.classList.remove("static-disabled") + } else { + wrapped_static.classList.add("static-enabled") + } } \ No newline at end of file