|
|
|
@ -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<void>();
|
|
|
|
|
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(<IPlexServer>{ 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(<IPlexServer>{ 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) {
|
|
|
|
@ -51,6 +84,11 @@ export class PlexComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|