diff --git a/src/Ombi.Api.Github/GithubApi.cs b/src/Ombi.Api.Github/GithubApi.cs index 824e8ce1f..f7b3fbcbf 100644 --- a/src/Ombi.Api.Github/GithubApi.cs +++ b/src/Ombi.Api.Github/GithubApi.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Ombi.Api.Github.Models; @@ -23,5 +24,16 @@ namespace Ombi.Api.Github request.AddHeader("User-Agent", "Ombi"); return await _api.Request>(request); } + + public async Task GetThemesRawContent(string url) + { + var sections = url.Split('/'); + var lastPart = sections.Last(); + url = url.Replace(lastPart, string.Empty); + var request = new Request(lastPart, url, HttpMethod.Get); + request.AddHeader("Accept", "application/vnd.github.v3+json"); + request.AddHeader("User-Agent", "Ombi"); + return await _api.RequestContent(request); + } } } diff --git a/src/Ombi.Api.Github/IGithubApi.cs b/src/Ombi.Api.Github/IGithubApi.cs index 1cca37f02..307158b72 100644 --- a/src/Ombi.Api.Github/IGithubApi.cs +++ b/src/Ombi.Api.Github/IGithubApi.cs @@ -7,5 +7,6 @@ namespace Ombi.Api.Github public interface IGithubApi { Task> GetCakeThemes(); + Task GetThemesRawContent(string url); } } \ No newline at end of file diff --git a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs index 20c4ae447..efcc2ebdb 100644 --- a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.ComponentModel.DataAnnotations.Schema; using Newtonsoft.Json; using Ombi.Helpers; @@ -14,6 +15,34 @@ namespace Ombi.Settings.Settings.Models public string PresetThemeName { get; set; } public string PresetThemeContent { get; set; } + [NotMapped] + public string PresetThemeVersionVersion + { + get + { + if (HasPresetTheme) + { + var parts = PresetThemeName.Split('-'); + return parts[3].Replace(".css", string.Empty); + } + return string.Empty; + } + } + + [NotMapped] + public string PresetThemeDisplayName + { + get + { + if (HasPresetTheme) + { + var parts = PresetThemeName.Split('-'); + return parts[1]; + } + return string.Empty; + } + } + [NotMapped] public bool HasPresetTheme => PresetThemeName.HasValue() || PresetThemeContent.HasValue(); diff --git a/src/Ombi/ClientApp/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/app/interfaces/ISettings.ts index 544e2fda5..c95de61df 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISettings.ts @@ -94,6 +94,11 @@ export interface ICustomizationSettings extends ISettings { applicationUrl: string; logo: string; customCssLink: string; + hasPresetTheme: boolean; + presetThemeName: string; + presetThemeContent: string; + presetThemeDisplayName: string; + presetThemeVersion: string; } export interface IThemes { diff --git a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html index 4e6358da4..f9bf90bdd 100644 --- a/src/Ombi/ClientApp/app/landingpage/landingpage.component.html +++ b/src/Ombi/ClientApp/app/landingpage/landingpage.component.html @@ -1,5 +1,5 @@ -
- +
+
diff --git a/src/Ombi/ClientApp/app/login/login.component.html b/src/Ombi/ClientApp/app/login/login.component.html index c07d83e0e..323a9653d 100644 --- a/src/Ombi/ClientApp/app/login/login.component.html +++ b/src/Ombi/ClientApp/app/login/login.component.html @@ -2,9 +2,9 @@ you can substitue the span of reauth email for a input with the email and include the remember me checkbox --> -
+
- +
diff --git a/src/Ombi/ClientApp/app/services/settings.service.ts b/src/Ombi/ClientApp/app/services/settings.service.ts index 2bfc5bb3a..7c54ca92e 100644 --- a/src/Ombi/ClientApp/app/services/settings.service.ts +++ b/src/Ombi/ClientApp/app/services/settings.service.ts @@ -127,6 +127,10 @@ export class SettingsService extends ServiceAuthHelpers { return this.httpAuth.get(`${this.url}/themes`).map(this.extractData).catch(this.handleError); } + public getThemeContent(themeUrl: string): Observable { + return this.httpAuth.get(`${this.url}/themecontent?url=${themeUrl}`).map(this.extractData).catch(this.handleError); + } + public getEmailNotificationSettings(): Observable { return this.httpAuth.get(`${this.url}/notifications/email`).map(this.extractData).catch(this.handleError); } diff --git a/src/Ombi/ClientApp/app/settings/customization/customization.component.html b/src/Ombi/ClientApp/app/settings/customization/customization.component.html index 4b0889a97..b996f1296 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.html +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.html @@ -7,29 +7,33 @@
- +
- +
- +
- +
- +
@@ -42,14 +46,29 @@
-
- -
- -
- + + +
+ +
+ +
+ \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/settings/customization/customization.component.ts b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts index c3dca3e3b..34777d950 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.ts +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts @@ -15,8 +15,18 @@ export class CustomizationComponent implements OnInit { constructor(private settingsService: SettingsService, private notificationService: NotificationService) { } public ngOnInit() { - this.settingsService.getCustomization().subscribe(x => this.settings = x); - this.settingsService.getThemes().subscribe(x => this.themes = x); + this.settingsService.getCustomization().subscribe(x => { + this.settings = x; + this.settingsService.getThemes().subscribe(t => { + this.themes = t; + if(x.hasPresetTheme) { + this.themes.unshift({displayName: x.presetThemeDisplayName, fullName: x.presetThemeName, url: "", version: x.presetThemeVersion}); + } else { + this.themes.unshift({displayName: "Please Select", fullName: "-1", url: "-1", version: ""}); + } + }); + }); + } public save() { @@ -28,4 +38,20 @@ export class CustomizationComponent implements OnInit { } }); } + + public dropDownChange(event: any): void { + const selectedThemeFullName = event.target.value; + const selectedTheme = this.themes.filter((val) => { + return val.fullName === selectedThemeFullName; + }); + + // if(selectedTheme[0].fullName === this.settings.presetThemeName) { + // return; + // } + + this.settings.presetThemeName = selectedThemeFullName; + this.settingsService.getThemeContent(selectedTheme[0].url).subscribe(x => { + this.settings.presetThemeContent = x; + }); + } } diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 6743e28e9..ea76864eb 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -221,12 +221,16 @@ namespace Ombi.Controllers return await Save(settings); } + /// + /// Get's the preset themes available + /// + /// [HttpGet("themes")] public async Task> GetThemes() { var themes = await _githubApi.GetCakeThemes(); - var cssThemes = themes.Where(x => x.name.Contains(".css", CompareOptions.IgnoreCase) - && x.type.Equals("file", StringComparison.CurrentCultureIgnoreCase)); + var cssThemes = themes.Where(x => x.name.Contains(".css", CompareOptions.IgnoreCase) + && x.type.Equals("file", StringComparison.CurrentCultureIgnoreCase)); // 001-theBlur-leram84-1.0.css // Number-Name-Author-Version.css @@ -238,7 +242,7 @@ namespace Ombi.Controllers { DisplayName = parts[1], FullName = theme.name, - Version = parts[3].Replace(".css",string.Empty, StringComparison.CurrentCultureIgnoreCase), + Version = parts[3].Replace(".css", string.Empty, StringComparison.CurrentCultureIgnoreCase), Url = theme.download_url }); } @@ -249,6 +253,19 @@ namespace Ombi.Controllers return model; } + /// + /// Gets the content of the theme available + /// + /// + /// + [HttpGet("themecontent")] + public async Task GetThemeContent([FromQuery]string url) + { + var content = await _githubApi.GetThemesRawContent(url); + + return content; + } + /// /// Gets the Sonarr Settings. /// diff --git a/src/Ombi/Views/Shared/_Layout.cshtml b/src/Ombi/Views/Shared/_Layout.cshtml index d4baf620d..db244d6d5 100644 --- a/src/Ombi/Views/Shared/_Layout.cshtml +++ b/src/Ombi/Views/Shared/_Layout.cshtml @@ -28,6 +28,8 @@ + + @appName @@ -56,7 +58,7 @@ @{ if (!string.IsNullOrEmpty(customization.CustomCssLink)) { - + } }