From c8f00c4e8a7edef9683c1082daa4e2329e3782cb Mon Sep 17 00:00:00 2001 From: Jamie Date: Mon, 6 Nov 2017 16:30:44 +0000 Subject: [PATCH] !wip work in progress for the theme presets --- src/Ombi.Api.Github/GithubApi.cs | 25 +++++++++++++ src/Ombi.Api.Github/IGithubApi.cs | 10 ++++++ src/Ombi.Api.Github/Models/CakeThemes.cs | 29 +++++++++++++++ src/Ombi.Api.Github/Ombi.Api.Github.csproj | 11 ++++++ src/Ombi.DependencyInjection/IocExtensions.cs | 2 ++ .../Ombi.DependencyInjection.csproj | 1 + .../Settings/Models/CustomizationSettings.cs | 2 ++ src/Ombi.sln | 7 ++++ src/Ombi/Controllers/SettingsController.cs | 36 +++++++++++++++++-- src/Ombi/Models/PresetThemeViewModel.cs | 9 +++++ src/Ombi/Ombi.csproj | 1 + 11 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/Ombi.Api.Github/GithubApi.cs create mode 100644 src/Ombi.Api.Github/IGithubApi.cs create mode 100644 src/Ombi.Api.Github/Models/CakeThemes.cs create mode 100644 src/Ombi.Api.Github/Ombi.Api.Github.csproj create mode 100644 src/Ombi/Models/PresetThemeViewModel.cs diff --git a/src/Ombi.Api.Github/GithubApi.cs b/src/Ombi.Api.Github/GithubApi.cs new file mode 100644 index 000000000..b241836a0 --- /dev/null +++ b/src/Ombi.Api.Github/GithubApi.cs @@ -0,0 +1,25 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Ombi.Api.Github.Models; + +namespace Ombi.Api.Github +{ + public class GithubApi : IGithubApi + { + public GithubApi(IApi api) + { + _api = api; + } + + private readonly IApi _api; + private const string BaseUrl = "https://api.github.com/"; + + public async Task GetCakeThemes() + { + var request = new Request("repos/leram84/layer.Cake/contents/Themes", BaseUrl, HttpMethod.Get); + + return await _api.Request(request); + } + } +} diff --git a/src/Ombi.Api.Github/IGithubApi.cs b/src/Ombi.Api.Github/IGithubApi.cs new file mode 100644 index 000000000..cc3a4b366 --- /dev/null +++ b/src/Ombi.Api.Github/IGithubApi.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Ombi.Api.Github.Models; + +namespace Ombi.Api.Github +{ + public interface IGithubApi + { + Task GetCakeThemes(); + } +} \ No newline at end of file diff --git a/src/Ombi.Api.Github/Models/CakeThemes.cs b/src/Ombi.Api.Github/Models/CakeThemes.cs new file mode 100644 index 000000000..889dce603 --- /dev/null +++ b/src/Ombi.Api.Github/Models/CakeThemes.cs @@ -0,0 +1,29 @@ +namespace Ombi.Api.Github.Models +{ + public class CakeThemesContainer + { + public CakeThemes[] Themes { get; set; } + } + + public class CakeThemes + { + public string name { get; set; } + public string path { get; set; } + public string sha { get; set; } + public int size { get; set; } + public string url { get; set; } + public string html_url { get; set; } + public string git_url { get; set; } + public string download_url { get; set; } + public string type { get; set; } + public _Links _links { get; set; } + } + + public class _Links + { + public string self { get; set; } + public string git { get; set; } + public string html { get; set; } + } + +} \ No newline at end of file diff --git a/src/Ombi.Api.Github/Ombi.Api.Github.csproj b/src/Ombi.Api.Github/Ombi.Api.Github.csproj new file mode 100644 index 000000000..a3651df3c --- /dev/null +++ b/src/Ombi.Api.Github/Ombi.Api.Github.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index ca9db4246..12b53b6c5 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -31,6 +31,7 @@ using Ombi.Api; using Ombi.Api.CouchPotato; using Ombi.Api.DogNzb; using Ombi.Api.FanartTv; +using Ombi.Api.Github; using Ombi.Api.Mattermost; using Ombi.Api.Pushbullet; using Ombi.Api.Pushover; @@ -100,6 +101,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } public static void RegisterStore(this IServiceCollection services) { diff --git a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index dbb660326..e9e99f535 100644 --- a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -20,6 +20,7 @@ + diff --git a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs index 2518bcafa..fa8935c10 100644 --- a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs @@ -8,6 +8,8 @@ namespace Ombi.Settings.Settings.Models public string ApplicationUrl { get; set; } public string CustomCssLink { get; set; } + //public string PresetTheme { get; set; } + public void AddToUrl(string part) { if (string.IsNullOrEmpty(ApplicationUrl)) diff --git a/src/Ombi.sln b/src/Ombi.sln index 2c46992c2..d233b727b 100644 --- a/src/Ombi.sln +++ b/src/Ombi.sln @@ -88,6 +88,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Tests", "Ombi.Tests\Om EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Telegram", "Ombi.Api.Telegram\Ombi.Api.Telegram.csproj", "{CB9DD209-8E09-4E01-983E-C77C89592D36}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Github", "Ombi.Api.Github\Ombi.Api.Github.csproj", "{55866DEE-46D1-4AF7-B1A2-62F6190C8EC7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -226,6 +228,10 @@ Global {CB9DD209-8E09-4E01-983E-C77C89592D36}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB9DD209-8E09-4E01-983E-C77C89592D36}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB9DD209-8E09-4E01-983E-C77C89592D36}.Release|Any CPU.Build.0 = Release|Any CPU + {55866DEE-46D1-4AF7-B1A2-62F6190C8EC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55866DEE-46D1-4AF7-B1A2-62F6190C8EC7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55866DEE-46D1-4AF7-B1A2-62F6190C8EC7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55866DEE-46D1-4AF7-B1A2-62F6190C8EC7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -258,6 +264,7 @@ Global {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E} = {9293CA11-360A-4C20-A674-B9E794431BF5} {C12F5276-352A-43CF-8E33-400E768E9757} = {6F42AB98-9196-44C4-B888-D5E409F415A1} {CB9DD209-8E09-4E01-983E-C77C89592D36} = {9293CA11-360A-4C20-A674-B9E794431BF5} + {55866DEE-46D1-4AF7-B1A2-62F6190C8EC7} = {9293CA11-360A-4C20-A674-B9E794431BF5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {192E9BF8-00B4-45E4-BCCC-4C215725C869} diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 7cfcd4134..b8dbd0273 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -17,13 +18,13 @@ using Ombi.Core.Settings.Models; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.Models; -using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Radarr; using Ombi.Settings.Settings.Models; using Ombi.Settings.Settings.Models.External; using Ombi.Settings.Settings.Models.Notifications; using Ombi.Store.Entities; using Ombi.Store.Repository; +using Ombi.Api.Github; namespace Ombi.Controllers { @@ -45,12 +46,14 @@ namespace Ombi.Controllers /// The embyApi. /// The radarrCacher. /// The memory cache. + /// The memory cache. public SettingsController(ISettingsResolver resolver, IMapper mapper, INotificationTemplatesRepository templateRepo, IEmbyApi embyApi, IRadarrCacher radarrCacher, - IMemoryCache memCache) + IMemoryCache memCache, + IGithubApi githubApi) { SettingsResolver = resolver; Mapper = mapper; @@ -58,6 +61,7 @@ namespace Ombi.Controllers _embyApi = embyApi; _radarrCacher = radarrCacher; _cache = memCache; + _githubApi = githubApi; } private ISettingsResolver SettingsResolver { get; } @@ -66,6 +70,7 @@ namespace Ombi.Controllers private readonly IEmbyApi _embyApi; private readonly IRadarrCacher _radarrCacher; private readonly IMemoryCache _cache; + private readonly IGithubApi _githubApi; /// /// Gets the Ombi settings. @@ -216,6 +221,33 @@ namespace Ombi.Controllers return await Save(settings); } + [HttpGet("themes")] + public async Task> GetThemes() + { + var themes = await _githubApi.GetCakeThemes(); + var cssThemes = themes.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 + var model = new List(); + foreach (var theme in cssThemes) + { + var parts = theme.name.Split("-"); + model.Add(new PresetThemeViewModel + { + DisplayName = parts[1], + FullName = theme.name, + Version = parts[3].Replace(".css",string.Empty, StringComparison.CurrentCultureIgnoreCase) + }); + } + + // Display on UI - Current Theme = theBlur 1.0 + // In dropdown display as "theBlur 1.1" + + return model; + } + /// /// Gets the Sonarr Settings. /// diff --git a/src/Ombi/Models/PresetThemeViewModel.cs b/src/Ombi/Models/PresetThemeViewModel.cs new file mode 100644 index 000000000..1405572bc --- /dev/null +++ b/src/Ombi/Models/PresetThemeViewModel.cs @@ -0,0 +1,9 @@ +namespace Ombi.Models +{ + public class PresetThemeViewModel + { + public string FullName { get; set; } + public string DisplayName { get; set; } + public string Version { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index f2004a413..0188741f5 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -77,6 +77,7 @@ +