From 831c65f563e6505130fc70a015f472c4351f27a2 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Wed, 12 Apr 2017 15:30:45 +0100 Subject: [PATCH] Settings for Ombi --- Ombi/Ombi.Core/Settings/ISettingsResolver.cs | 7 +++ .../Ombi.Core/Settings/Models/OmbiSettings.cs | 12 +++++ Ombi/Ombi.Core/Settings/SettingsResolver.cs | 21 ++++++++ .../Ombi.DependencyInjection/IocExtensions.cs | 1 + Ombi/Ombi/Controllers/SettingsController.cs | 37 ++++++++++++++ Ombi/Ombi/Ombi.csproj | 9 ++++ Ombi/Ombi/wwwroot/app/app.module.ts | 2 + .../wwwroot/app/services/settings.service.ts | 23 +++++++++ .../app/settings/interfaces/ISettings.ts | 11 ++++ .../app/settings/ombi/ombi.component.html | 51 +++++++++++++++++-- .../app/settings/ombi/ombi.component.ts | 22 ++++++-- 11 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 Ombi/Ombi.Core/Settings/ISettingsResolver.cs create mode 100644 Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs create mode 100644 Ombi/Ombi.Core/Settings/SettingsResolver.cs create mode 100644 Ombi/Ombi/Controllers/SettingsController.cs create mode 100644 Ombi/Ombi/wwwroot/app/services/settings.service.ts create mode 100644 Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts diff --git a/Ombi/Ombi.Core/Settings/ISettingsResolver.cs b/Ombi/Ombi.Core/Settings/ISettingsResolver.cs new file mode 100644 index 000000000..6c21878ae --- /dev/null +++ b/Ombi/Ombi.Core/Settings/ISettingsResolver.cs @@ -0,0 +1,7 @@ +namespace Ombi.Core.Settings +{ + public interface ISettingsResolver + { + ISettingsService Resolve(); + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs b/Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs new file mode 100644 index 000000000..6294a43a4 --- /dev/null +++ b/Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs @@ -0,0 +1,12 @@ +namespace Ombi.Core.Settings.Models +{ + public class OmbiSettings : Settings + { + public int Port { get; set; } + //public string BaseUrl { get; set; } + public bool CollectAnalyticData { get; set; } + public bool Wizard { get; set; } + + public string ApiKey { get; set; } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.Core/Settings/SettingsResolver.cs b/Ombi/Ombi.Core/Settings/SettingsResolver.cs new file mode 100644 index 000000000..33c7cf2c2 --- /dev/null +++ b/Ombi/Ombi.Core/Settings/SettingsResolver.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.Extensions.DependencyInjection; + +namespace Ombi.Core.Settings +{ + public class SettingsResolver : ISettingsResolver + { + public SettingsResolver(IServiceProvider services) + { + _services = services; + } + + private readonly IServiceProvider _services; + + public ISettingsService Resolve() + { + var service = (ISettingsService)_services.GetService(typeof(ISettingsService)); + return service;; + } + } +} \ No newline at end of file diff --git a/Ombi/Ombi.DependencyInjection/IocExtensions.cs b/Ombi/Ombi.DependencyInjection/IocExtensions.cs index 6ccaca0f8..57fae18d5 100644 --- a/Ombi/Ombi.DependencyInjection/IocExtensions.cs +++ b/Ombi/Ombi.DependencyInjection/IocExtensions.cs @@ -51,6 +51,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>)); return services; } diff --git a/Ombi/Ombi/Controllers/SettingsController.cs b/Ombi/Ombi/Controllers/SettingsController.cs new file mode 100644 index 000000000..db83c15b6 --- /dev/null +++ b/Ombi/Ombi/Controllers/SettingsController.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models; + +namespace Ombi.Controllers +{ + [Authorize(Roles = "Admin")] + public class SettingsController : BaseV1ApiController + { + public SettingsController(ISettingsResolver resolver) + { + SettingsResolver = resolver; + } + + private ISettingsResolver SettingsResolver { get; } + + [HttpGet("ombi")] + public async Task OmbiSettings() + { + var settings = SettingsResolver.Resolve(); + + return await settings.GetSettingsAsync(); + } + + [HttpPost("ombi")] + public async Task OmbiSettings([FromBody]OmbiSettings ombi) + { + var settings = SettingsResolver.Resolve(); + + return await settings.SaveSettingsAsync(ombi); + } + + + } +} diff --git a/Ombi/Ombi/Ombi.csproj b/Ombi/Ombi/Ombi.csproj index b8336f669..784ae0f46 100644 --- a/Ombi/Ombi/Ombi.csproj +++ b/Ombi/Ombi/Ombi.csproj @@ -16,6 +16,15 @@ + + + + PreserveNewest + + + + + diff --git a/Ombi/Ombi/wwwroot/app/app.module.ts b/Ombi/Ombi/wwwroot/app/app.module.ts index 1e9835bda..18ea25e3a 100644 --- a/Ombi/Ombi/wwwroot/app/app.module.ts +++ b/Ombi/Ombi/wwwroot/app/app.module.ts @@ -19,6 +19,7 @@ import { PageNotFoundComponent } from './errors/not-found.component'; import { SearchService } from './services/search.service'; import { RequestService } from './services/request.service'; import { NotificationService } from './services/notification.service'; +import { SettingsService } from './services/settings.service'; import { AuthService } from './auth/auth.service'; import { AuthGuard } from './auth/auth.guard'; import { AuthModule } from './auth/auth.module'; @@ -66,6 +67,7 @@ const routes: Routes = [ NotificationService, AuthService, AuthGuard, + SettingsService ], bootstrap: [AppComponent] }) diff --git a/Ombi/Ombi/wwwroot/app/services/settings.service.ts b/Ombi/Ombi/wwwroot/app/services/settings.service.ts new file mode 100644 index 000000000..0f353315e --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/services/settings.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { AuthHttp } from 'angular2-jwt'; +import { Observable } from 'rxjs/Rx'; + +import { ServiceAuthHelpers } from './service.helpers'; +import { IOmbiSettings } from '../settings/interfaces/ISettings'; + + +@Injectable() +export class SettingsService extends ServiceAuthHelpers { + constructor(http: AuthHttp) { + super(http, '/api/v1/Settings/'); + } + + getOmbi(): Observable { + return this.http.get(this.url).map(this.extractData); + } + + saveOmbi(settings: IOmbiSettings): Observable { + return this.http.post(`${this.url}/Ombi/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData); + } + +} \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts b/Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts new file mode 100644 index 000000000..5bb3deeac --- /dev/null +++ b/Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts @@ -0,0 +1,11 @@ +export interface ISettings { + id:number +} + +export interface IOmbiSettings extends ISettings { + port: number, +//baseUrl:string, + collectAnalyticData: boolean, + wizard: boolean, + apiKey:string +} \ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.html b/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.html index a71b39d11..6750530dd 100644 --- a/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.html +++ b/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.html @@ -1,7 +1,50 @@ - -Settings +
+
+ Ombi Configuration +
+ +
+ +
+
+ You will have to restart after changing the port. + + +
+ +
+ + +
+
+
+ +
+
+
+
+
+ +
+
+ + +
+
+ +
+
+ +
+
+
+
\ No newline at end of file diff --git a/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.ts b/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.ts index 7805b9ebe..d1aba3a99 100644 --- a/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.ts +++ b/Ombi/Ombi/wwwroot/app/settings/ombi/ombi.component.ts @@ -1,11 +1,25 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; + +import { IOmbiSettings } from '../interfaces/ISettings' +import { SettingsService } from '../../services/settings.service'; + @Component({ selector: 'ombi', moduleId: module.id, templateUrl: './ombi.component.html', }) -export class OmbiComponent { +export class OmbiComponent implements OnInit { + + constructor(private settingsService: SettingsService) { } + + settings: IOmbiSettings; + + ngOnInit(): void { + this.settingsService.getOmbi().subscribe(x => this.settings = x); + } + - enabled:boolean; - host:string; + refreshApiKey() { + + } } \ No newline at end of file