mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Settings for Ombi
This commit is contained in:
parent
8e04061e4e
commit
831c65f563
11 changed files with 188 additions and 8 deletions
7
Ombi/Ombi.Core/Settings/ISettingsResolver.cs
Normal file
7
Ombi/Ombi.Core/Settings/ISettingsResolver.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Ombi.Core.Settings
|
||||||
|
{
|
||||||
|
public interface ISettingsResolver
|
||||||
|
{
|
||||||
|
ISettingsService<T> Resolve<T>();
|
||||||
|
}
|
||||||
|
}
|
12
Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs
Normal file
12
Ombi/Ombi.Core/Settings/Models/OmbiSettings.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
21
Ombi/Ombi.Core/Settings/SettingsResolver.cs
Normal file
21
Ombi/Ombi.Core/Settings/SettingsResolver.cs
Normal file
|
@ -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<IRequestRepository, RequestJsonRepository>();
|
||||||
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
|
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
|
||||||
services.AddTransient<IUserRepository, UserRepository>();
|
services.AddTransient<IUserRepository, UserRepository>();
|
||||||
|
services.AddTransient<ISettingsResolver, SettingsResolver>();
|
||||||
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>));
|
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>));
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
37
Ombi/Ombi/Controllers/SettingsController.cs
Normal file
37
Ombi/Ombi/Controllers/SettingsController.cs
Normal file
|
@ -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\auth\IUserLogin.ts" />
|
||||||
<Content Include="wwwroot\app\login\login.component.html" />
|
<Content Include="wwwroot\app\login\login.component.html" />
|
||||||
<Content Include="wwwroot\app\login\login.component.ts" />
|
<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.html" />
|
||||||
<Content Include="wwwroot\app\settings\settingsmenu.component.js" />
|
<Content Include="wwwroot\app\settings\settingsmenu.component.js" />
|
||||||
<Content Include="wwwroot\app\settings\settingsmenu.component.js.map" />
|
<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 { SearchService } from './services/search.service';
|
||||||
import { RequestService } from './services/request.service';
|
import { RequestService } from './services/request.service';
|
||||||
import { NotificationService } from './services/notification.service';
|
import { NotificationService } from './services/notification.service';
|
||||||
|
import { SettingsService } from './services/settings.service';
|
||||||
import { AuthService } from './auth/auth.service';
|
import { AuthService } from './auth/auth.service';
|
||||||
import { AuthGuard } from './auth/auth.guard';
|
import { AuthGuard } from './auth/auth.guard';
|
||||||
import { AuthModule } from './auth/auth.module';
|
import { AuthModule } from './auth/auth.module';
|
||||||
|
@ -66,6 +67,7 @@ const routes: Routes = [
|
||||||
NotificationService,
|
NotificationService,
|
||||||
AuthService,
|
AuthService,
|
||||||
AuthGuard,
|
AuthGuard,
|
||||||
|
SettingsService
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
|
23
Ombi/Ombi/wwwroot/app/services/settings.service.ts
Normal file
23
Ombi/Ombi/wwwroot/app/services/settings.service.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts
Normal file
11
Ombi/Ombi/wwwroot/app/settings/interfaces/ISettings.ts
Normal file
|
@ -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>
|
<div class="col-sm-8 col-sm-push-1">
|
||||||
Settings
|
<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({
|
@Component({
|
||||||
selector: 'ombi',
|
selector: 'ombi',
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
templateUrl: './ombi.component.html',
|
templateUrl: './ombi.component.html',
|
||||||
})
|
})
|
||||||
export class OmbiComponent {
|
export class OmbiComponent implements OnInit {
|
||||||
|
|
||||||
enabled:boolean;
|
constructor(private settingsService: SettingsService) { }
|
||||||
host:string;
|
|
||||||
|
settings: IOmbiSettings;
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.settingsService.getOmbi().subscribe(x => this.settings = x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
refreshApiKey() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue