From b1d59452ef4f1d03e0a51c3513417bb3d1a21df1 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 6 Nov 2017 22:21:43 +0000 Subject: [PATCH] !wip integrated with the layer#cake repo. Just need to do the UI --- src/Ombi.Api.Github/GithubApi.cs | 10 ++++++---- src/Ombi.Api.Github/IGithubApi.cs | 5 +++-- src/Ombi.Api.Github/Models/CakeThemes.cs | 5 ----- .../Settings/Models/CustomizationSettings.cs | 14 ++++++++++---- src/Ombi/ClientApp/app/interfaces/ISettings.ts | 7 +++++++ .../ClientApp/app/services/settings.service.ts | 5 +++++ .../customization/customization.component.ts | 5 +++-- src/Ombi/Controllers/SettingsController.cs | 5 +++-- src/Ombi/Models/PresetThemeViewModel.cs | 1 + src/Ombi/package-lock.json | 5 ----- 10 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/Ombi.Api.Github/GithubApi.cs b/src/Ombi.Api.Github/GithubApi.cs index b241836a0..824e8ce1f 100644 --- a/src/Ombi.Api.Github/GithubApi.cs +++ b/src/Ombi.Api.Github/GithubApi.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Ombi.Api.Github.Models; @@ -15,11 +16,12 @@ namespace Ombi.Api.Github private readonly IApi _api; private const string BaseUrl = "https://api.github.com/"; - public async Task GetCakeThemes() + public async Task> GetCakeThemes() { - var request = new Request("repos/leram84/layer.Cake/contents/Themes", BaseUrl, HttpMethod.Get); - - return await _api.Request(request); + var request = new Request("repos/leram84/layer.Cake/contents/ombi/themes", BaseUrl, HttpMethod.Get); + request.AddHeader("Accept", "application/vnd.github.v3+json"); + request.AddHeader("User-Agent", "Ombi"); + return await _api.Request>(request); } } } diff --git a/src/Ombi.Api.Github/IGithubApi.cs b/src/Ombi.Api.Github/IGithubApi.cs index cc3a4b366..1cca37f02 100644 --- a/src/Ombi.Api.Github/IGithubApi.cs +++ b/src/Ombi.Api.Github/IGithubApi.cs @@ -1,10 +1,11 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Ombi.Api.Github.Models; namespace Ombi.Api.Github { public interface IGithubApi { - Task GetCakeThemes(); + 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 index 889dce603..f5a3e8e28 100644 --- a/src/Ombi.Api.Github/Models/CakeThemes.cs +++ b/src/Ombi.Api.Github/Models/CakeThemes.cs @@ -1,10 +1,5 @@ namespace Ombi.Api.Github.Models { - public class CakeThemesContainer - { - public CakeThemes[] Themes { get; set; } - } - public class CakeThemes { public string name { get; set; } diff --git a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs index fa8935c10..20c4ae447 100644 --- a/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs +++ b/src/Ombi.Settings/Settings/Models/CustomizationSettings.cs @@ -1,4 +1,6 @@ -using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; +using Ombi.Helpers; namespace Ombi.Settings.Settings.Models { @@ -7,9 +9,14 @@ namespace Ombi.Settings.Settings.Models public string ApplicationName { get; set; } public string ApplicationUrl { get; set; } public string CustomCssLink { get; set; } + public string Logo { get; set; } + + public string PresetThemeName { get; set; } + public string PresetThemeContent { get; set; } + + [NotMapped] + public bool HasPresetTheme => PresetThemeName.HasValue() || PresetThemeContent.HasValue(); - //public string PresetTheme { get; set; } - public void AddToUrl(string part) { if (string.IsNullOrEmpty(ApplicationUrl)) @@ -27,6 +34,5 @@ namespace Ombi.Settings.Settings.Models } ApplicationUrl = ApplicationUrl + part; } - public string Logo { get; set; } } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/app/interfaces/ISettings.ts index ada0d9cab..544e2fda5 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISettings.ts @@ -96,6 +96,13 @@ export interface ICustomizationSettings extends ISettings { customCssLink: string; } +export interface IThemes { + fullName: string; + displayName: string; + version: string; + url: string; +} + export interface IAuthenticationSettings extends ISettings { allowExternalUsersToAuthenticate: boolean; diff --git a/src/Ombi/ClientApp/app/services/settings.service.ts b/src/Ombi/ClientApp/app/services/settings.service.ts index 02400805d..2bfc5bb3a 100644 --- a/src/Ombi/ClientApp/app/services/settings.service.ts +++ b/src/Ombi/ClientApp/app/services/settings.service.ts @@ -23,6 +23,7 @@ import { ISlackNotificationSettings, ISonarrSettings, ITelegramNotifcationSettings, + IThemes, IUpdateSettings, IUserManagementSettings, } from "../interfaces"; @@ -122,6 +123,10 @@ export class SettingsService extends ServiceAuthHelpers { .map(this.extractData).catch(this.handleError); } + public getThemes(): Observable { + return this.httpAuth.get(`${this.url}/themes`).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.ts b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts index 8871725cd..c3dca3e3b 100644 --- a/src/Ombi/ClientApp/app/settings/customization/customization.component.ts +++ b/src/Ombi/ClientApp/app/settings/customization/customization.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from "@angular/core"; -import { ICustomizationSettings } from "../../interfaces"; +import { ICustomizationSettings, IThemes } from "../../interfaces"; import { NotificationService } from "../../services"; import { SettingsService } from "../../services"; @@ -10,12 +10,13 @@ import { SettingsService } from "../../services"; export class CustomizationComponent implements OnInit { public settings: ICustomizationSettings; + public themes: IThemes[]; 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); } public save() { diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index b8dbd0273..6743e28e9 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -225,7 +225,7 @@ namespace Ombi.Controllers public async Task> GetThemes() { var themes = await _githubApi.GetCakeThemes(); - var cssThemes = themes.Themes.Where(x => x.name.Contains(".css", CompareOptions.IgnoreCase) + var cssThemes = themes.Where(x => x.name.Contains(".css", CompareOptions.IgnoreCase) && x.type.Equals("file", StringComparison.CurrentCultureIgnoreCase)); // 001-theBlur-leram84-1.0.css @@ -238,7 +238,8 @@ 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 }); } diff --git a/src/Ombi/Models/PresetThemeViewModel.cs b/src/Ombi/Models/PresetThemeViewModel.cs index 1405572bc..cd97e231a 100644 --- a/src/Ombi/Models/PresetThemeViewModel.cs +++ b/src/Ombi/Models/PresetThemeViewModel.cs @@ -5,5 +5,6 @@ public string FullName { get; set; } public string DisplayName { get; set; } public string Version { get; set; } + public string Url { get; set; } } } \ No newline at end of file diff --git a/src/Ombi/package-lock.json b/src/Ombi/package-lock.json index 55f943530..6dfce6952 100644 --- a/src/Ombi/package-lock.json +++ b/src/Ombi/package-lock.json @@ -3679,11 +3679,6 @@ "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.4.tgz", "integrity": "sha1-ggzdWIuGj/sZGoCVBtbJyPISsbA=" }, - "intro.js-mit": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/intro.js-mit/-/intro.js-mit-3.0.0.tgz", - "integrity": "sha1-vMQHKQrn4FT68+uImVumyTfZRVA=" - }, "invert-kv": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz",