Settings for Ombi

pull/1389/head
Jamie.Rees 7 years ago
parent 8e04061e4e
commit 831c65f563

@ -0,0 +1,7 @@
namespace Ombi.Core.Settings
{
public interface ISettingsResolver
{
ISettingsService<T> Resolve<T>();
}
}

@ -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; }
}
}

@ -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<T> Resolve<T>()
{
var service = (ISettingsService<T>)_services.GetService(typeof(ISettingsService<T>));
return service;;
}
}
}

@ -51,6 +51,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<IRequestRepository, RequestJsonRepository>();
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<ISettingsResolver, SettingsResolver>();
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>));
return services;
}

@ -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> OmbiSettings()
{
var settings = SettingsResolver.Resolve<OmbiSettings>();
return await settings.GetSettingsAsync();
}
[HttpPost("ombi")]
public async Task<bool> OmbiSettings([FromBody]OmbiSettings ombi)
{
var settings = SettingsResolver.Resolve<OmbiSettings>();
return await settings.SaveSettingsAsync(ombi);
}
}
}

@ -16,6 +16,15 @@
<Content Include="wwwroot\app\auth\IUserLogin.ts" />
<Content Include="wwwroot\app\login\login.component.html" />
<Content Include="wwwroot\app\login\login.component.ts" />
<Content Include="wwwroot\app\services\setting.service.js" />
<Content Include="wwwroot\app\services\setting.service.js.map" />
<Content Include="wwwroot\app\services\setting.service.ts">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="wwwroot\app\services\settings.service.js" />
<Content Include="wwwroot\app\services\settings.service.js.map" />
<Content Include="wwwroot\app\services\settings.service.ts" />
<Content Include="wwwroot\app\settings\interfaces\ISettings.ts" />
<Content Include="wwwroot\app\settings\settingsmenu.component.html" />
<Content Include="wwwroot\app\settings\settingsmenu.component.js" />
<Content Include="wwwroot\app\settings\settingsmenu.component.js.map" />

@ -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]
})

@ -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<IOmbiSettings> {
return this.http.get(this.url).map(this.extractData);
}
saveOmbi(settings: IOmbiSettings): Observable<boolean> {
return this.http.post(`${this.url}/Ombi/`, JSON.stringify(settings), { headers: this.headers }).map(this.extractData);
}
}

@ -0,0 +1,11 @@
export interface ISettings {
id:number
}
export interface IOmbiSettings extends ISettings {
port: number,
//baseUrl:string,
collectAnalyticData: boolean,
wizard: boolean,
apiKey:string
}

@ -1,7 +1,50 @@
<settings-menu></settings-menu>
Settings
<div class="col-sm-8 col-sm-push-1">
<fieldset>
<legend>Ombi Configuration</legend>
<div class="form-group">
<label for="portNumber" class="control-label">Port</label>
<div>
<input type="text" [(ngModel="settings.port" )] class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="{{settings.port}}">
</div>
</div>
<small class="control-label">You will have to restart after changing the port.</small>
<!--<div class="form-group">
<label for="BaseUrl" class="control-label">Base Url @Html.ToolTip("This will make Ombi run with a base url, usually used in reverse proxy scenarios")</label>
Enabled: <p-inputSwitch [(ngModel)]="enabled"></p-inputSwitch>
<div>
<input type="text" class="form-control form-control-custom " id="BaseUrl" name="BaseUrl" placeholder="Base Url" value="@Model.BaseUrl">
HostName:<input type="text" pInputText [(ngModel)]="host" />
</div>
</div>
<small class="control-label">You will have to restart after changing the base url.</small>-->
<div class="form-group">
<label for="ApiKey" class="control-label">Api Key</label>
<div class="input-group">
<input [(ngModel="settings.apiKey" )]] type="text" [readonly]="true" class="form-control form-control-custom" id="ApiKey" name="ApiKey" value="{{settings.apiKey}}">
<div class="input-group-addon">
<div (click)="refreshApiKey()" id="refreshKey" class="fa fa-refresh" title="Reset API Key"></div>
</div>
<div class="input-group-addon">
<div class="fa fa-clipboard" data-clipboard-action="copy"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="CollectAnalyticData" name="CollectAnalyticData" [(ngModel="settings.collectAnalyticData" )]] ng-checked="settings.collectAnalyticData">
<label for="CollectAnalyticData">Allow us to collect anonymous analytical data e.g. browser used</label>
</div>
</div>
<div class="form-group">
<div>
<button type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div>
</div>
</fieldset>
</div>

@ -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() {
}
}
Loading…
Cancel
Save