From 521f7c3ea0c7d7d23110bad9abc8b8d052835ff7 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 31 May 2017 22:47:11 +0100 Subject: [PATCH] Massive amount of rework on the plex settings page. It's pretty decent now! #865 --- .../Controllers/External/PlexController.cs | 21 ++ .../External/PlexRequestTokenViewModel.cs | 11 ++ src/Ombi/wwwroot/app/interfaces/IPlex.ts | 28 ++- .../app/services/applications/plex.service.ts | 8 +- .../app/settings/emby/emby.component.html | 2 +- .../app/settings/plex/plex.component.html | 180 +++++++++++------- .../app/settings/plex/plex.component.ts | 61 +++++- 7 files changed, 222 insertions(+), 89 deletions(-) create mode 100644 src/Ombi/Models/External/PlexRequestTokenViewModel.cs diff --git a/src/Ombi/Controllers/External/PlexController.cs b/src/Ombi/Controllers/External/PlexController.cs index de797416f..f81b83fa2 100644 --- a/src/Ombi/Controllers/External/PlexController.cs +++ b/src/Ombi/Controllers/External/PlexController.cs @@ -9,6 +9,7 @@ using Ombi.Api.Plex.Models; using Ombi.Attributes; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; +using Ombi.Models.External; namespace Ombi.Controllers.External { @@ -82,6 +83,26 @@ PlexAuthToken = result.user.authentication_token, return libs; } + [HttpPost("servers")] + public async Task GetServers([FromBody] UserRequest u) + { + try + { + var signIn = await PlexApi.SignIn(u); + var servers = await PlexApi.GetServer(signIn?.user?.authentication_token); + + return new PlexServersViewModel { Servers = servers, Success = true }; + } + catch (Exception e) + { + return new PlexServersViewModel + { + Success = false, + Message = e.Message + }; + } + } + } } diff --git a/src/Ombi/Models/External/PlexRequestTokenViewModel.cs b/src/Ombi/Models/External/PlexRequestTokenViewModel.cs new file mode 100644 index 000000000..060642a13 --- /dev/null +++ b/src/Ombi/Models/External/PlexRequestTokenViewModel.cs @@ -0,0 +1,11 @@ +using Ombi.Api.Plex.Models.Server; + +namespace Ombi.Models.External +{ + public class PlexServersViewModel + { + public bool Success { get; set; } + public string Message { get; set; } + public PlexServer Servers { get; set; } + } +} diff --git a/src/Ombi/wwwroot/app/interfaces/IPlex.ts b/src/Ombi/wwwroot/app/interfaces/IPlex.ts index 0e3b317a1..b92b02f05 100644 --- a/src/Ombi/wwwroot/app/interfaces/IPlex.ts +++ b/src/Ombi/wwwroot/app/interfaces/IPlex.ts @@ -1,5 +1,4 @@ - -export interface IPlexAuthentication { +export interface IPlexAuthentication { user: IPlexUser } @@ -12,14 +11,35 @@ export interface IPlexUser { } export interface IPlexLibraries { - mediaContainer:IMediaContainer; + mediaContainer: IMediaContainer; } export interface IMediaContainer { - directory:IDirectory[]; + directory: IDirectory[]; } export interface IDirectory { key: string, title: string, } + +export interface IPlexServerViewModel { + success: boolean, + message: string, + servers: IPlexServerResponse; +} + +export interface IPlexServerResponse { + accessToken: string, + address: string, + createdAt: string, + home: string, + host: string, + localAddresses: string, + machineIdentifier: string, + name: string, + owned: string, + ownerId: string, + port: string, + scheme: string, +} \ No newline at end of file diff --git a/src/Ombi/wwwroot/app/services/applications/plex.service.ts b/src/Ombi/wwwroot/app/services/applications/plex.service.ts index 3753ab200..2dea5f3f6 100644 --- a/src/Ombi/wwwroot/app/services/applications/plex.service.ts +++ b/src/Ombi/wwwroot/app/services/applications/plex.service.ts @@ -6,7 +6,7 @@ import { Observable } from 'rxjs/Rx'; import { ServiceAuthHelpers } from '../service.helpers'; -import { IPlexAuthentication, IPlexLibraries } from '../../interfaces/IPlex'; +import { IPlexAuthentication, IPlexLibraries, IPlexServerViewModel } from '../../interfaces/IPlex'; import { IPlexServer } from '../../interfaces/ISettings'; @@ -17,7 +17,11 @@ export class PlexService extends ServiceAuthHelpers { } logIn(login: string, password: string): Observable { - return this.regularHttp.post(`${this.url}`, JSON.stringify({ login: login, password:password}), { headers: this.headers }).map(this.extractData); + return this.regularHttp.post(`${this.url}`, JSON.stringify({ login: login, password: password }), { headers: this.headers }).map(this.extractData); + } + + getServers(login: string, password: string): Observable { + return this.http.post(`${this.url}servers`, JSON.stringify({ login: login, password: password }), { headers: this.headers }).map(this.extractData); } getLibraries(plexSettings: IPlexServer): Observable { diff --git a/src/Ombi/wwwroot/app/settings/emby/emby.component.html b/src/Ombi/wwwroot/app/settings/emby/emby.component.html index f6f795cb0..d65c72d67 100644 --- a/src/Ombi/wwwroot/app/settings/emby/emby.component.html +++ b/src/Ombi/wwwroot/app/settings/emby/emby.component.html @@ -6,7 +6,7 @@
- +
diff --git a/src/Ombi/wwwroot/app/settings/plex/plex.component.html b/src/Ombi/wwwroot/app/settings/plex/plex.component.html index 565bd311f..76f84eccf 100644 --- a/src/Ombi/wwwroot/app/settings/plex/plex.component.html +++ b/src/Ombi/wwwroot/app/settings/plex/plex.component.html @@ -4,103 +4,137 @@
Plex Configuration -
+
+ + +
+ + +
- +
-
+
- +
-
-
-
+
+
+
-
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
- - -
-
- -
-
- - - - - -
- - If enabled then we will lookup all episodes on your Plex server and store them in the local database. This will stop episode requests that already exist on Plex (that might not be in Sonarr). - Please be aware that this is a very resource intensive process and while the Plex Episode Cacher job is running the application may appear slow (Depending on the size of your Plex library). - -
- - -
- -
- -
-
- -
- -
- -
-
+
+
-
+
+
-
- +
+ +
+
+
+
+
+ + + +
+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+ + + + + +
+ + If enabled then we will lookup all episodes on your Plex server and store them in the local database. This will stop episode requests that already exist on Plex (that might not be in Sonarr). + Please be aware that this is a very resource intensive process and while the Plex Episode Cacher job is running the application may appear slow (Depending on the size of your Plex library). + +
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + + +
+
+ Note: if nothing is selected, we will monitor all libraries
@@ -128,12 +162,12 @@
-
+
- - - + + +
diff --git a/src/Ombi/wwwroot/app/settings/plex/plex.component.ts b/src/Ombi/wwwroot/app/settings/plex/plex.component.ts index af9b5e226..71bc459f8 100644 --- a/src/Ombi/wwwroot/app/settings/plex/plex.component.ts +++ b/src/Ombi/wwwroot/app/settings/plex/plex.component.ts @@ -1,6 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Subject } from 'rxjs/Subject'; +import "rxjs/add/operator/takeUntil"; -import { IPlexSettings, IPlexLibraries, IPlexServer } from '../../interfaces/ISettings' +import { IPlexSettings, IPlexLibraries, IPlexServer } from '../../interfaces/ISettings'; +import { IPlexServerResponse, IPlexServerViewModel } from '../../interfaces/IPlex' import { SettingsService } from '../../services/settings.service'; @@ -12,13 +15,18 @@ import { NotificationService } from "../../services/notification.service"; moduleId: module.id, templateUrl: './plex.component.html', }) -export class PlexComponent implements OnInit { +export class PlexComponent implements OnInit, OnDestroy { constructor(private settingsService: SettingsService, private notificationService: NotificationService, private plexService: PlexService) { } settings: IPlexSettings; + loadedServers: IPlexServerViewModel; // This comes from the api call for the user to select a server + private subscriptions = new Subject(); username: string; password: string; + advanced = false; + serversButton = false; + ngOnInit(): void { this.settingsService.getPlex().subscribe(x => { @@ -27,8 +35,30 @@ export class PlexComponent implements OnInit { ); } - requestToken() { - // TODO Plex Service + requestServers(server: IPlexServer): void { + this.plexService.getServers(this.username, this.password) + .takeUntil(this.subscriptions) + .subscribe(x => { + if (x.success) { + this.loadedServers = x; + this.serversButton = true; + this.notificationService.success("Loaded", "Found the servers! Please select one!") + } else { + this.notificationService.warning("Error When Requesting Plex Servers", x.message); + } + }); + } + + selectServer(selectedServer: IPlexServerResponse, server : IPlexServer) + { + server.ip = selectedServer.localAddresses.split(',')[0]; + server.name = selectedServer.name; + server.machineIdentifier = selectedServer.machineIdentifier; + server.plexAuthToken = selectedServer.accessToken; + server.port = parseInt(selectedServer.port); + server.ssl = selectedServer.scheme === "http" ? false : true; + + this.notificationService.success("Success", `Selected ${server.name}!`) } testPlex() { @@ -36,9 +66,12 @@ export class PlexComponent implements OnInit { } addTab() { - //this.settings.servers.push({ name: "New*", id: Math.floor(Math.random() * (99999 - 0 + 1) + 1) }); - - this.notificationService.warning("Disabled", "This feature is currently disabled"); + if (this.settings.servers == null) { + this.settings.servers = []; + this.settings.servers.push({ name: "New*", id: Math.floor(Math.random() * (99999 - 0 + 1) + 1) }); + } else { + this.notificationService.warning("Disabled", "Support for multiple servers is not available yet"); + } } removeServer(server: IPlexServer) { @@ -50,7 +83,12 @@ export class PlexComponent implements OnInit { //} } - loadLibraries(server:IPlexServer) { + loadLibraries(server: IPlexServer) { + if (server.ip == null) + { + this.notificationService.error("Not Configured", "Plex is not yet configured correctly") + return; + } this.plexService.getLibraries(server).subscribe(x => { server.plexSelectedLibraries = []; @@ -77,4 +115,9 @@ export class PlexComponent implements OnInit { } }); } + + ngOnDestroy(): void { + this.subscriptions.next(); + this.subscriptions.complete(); + } } \ No newline at end of file