mirror of https://github.com/Ombi-app/Ombi
parent
61a2a59879
commit
8aba799681
@ -0,0 +1,59 @@
|
|||||||
|
<div class="modal-header">
|
||||||
|
<h3>Add A Friend!</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>You can invite a user to share your Plex Library here. The invited user will be asked to confirm friendship.</p>
|
||||||
|
|
||||||
|
|
||||||
|
<div *ngIf="plexServers">
|
||||||
|
<form novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)" style="padding-top:5%;">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username" class="control-label">Username/Email</label>
|
||||||
|
|
||||||
|
<input type="text" class="form-control form-control-custom " id="username" name="username" p formControlName="username" [ngClass]="{'form-error': form.get('username').hasError('required')}">
|
||||||
|
<small *ngIf="form.get('username').hasError('required')" class="error-text">The Username/Email is required</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="select" class="control-label">Select a Server</label>
|
||||||
|
<div id="profiles">
|
||||||
|
<select formControlName="selectedServer" (change)="selected()" class="form-control form-control-custom" id="select" [ngClass]="{'form-error': form.get('selectedServer').hasError('required')}">
|
||||||
|
<option *ngFor="let server of plexServers" value="{{server.machineId}}">{{server.serverName}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<small *ngIf="form.get('selectedServer').hasError('required')" class="error-text">You need to select a server!</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="plexLibs" class="form-group">
|
||||||
|
<label for="select" class="control-label">Libraries to share</label>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<input type="checkbox" id="selectAll" formControlName="allLibsSelected">
|
||||||
|
<label for="selectAll">All</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div *ngIf="!form.value.allLibsSelected">
|
||||||
|
<div *ngFor="let lib of plexLibs.mediaContainer.directory">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<input type="checkbox" id="{{lib.key}}" value={{lib.key}} (change)="checkedLib($event.target.checked, $event.target.value)">
|
||||||
|
<label for="{{lib.key}}">{{lib.title}}</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="submit" class="btn btn-primary-outline" (click)="onSubmit(form)" [disabled]="form.invalid">Add</button>
|
||||||
|
<button type="button" class="btn btn-danger-outline" (click)="activeModal.close('Close click')">Close</button>
|
||||||
|
</div>
|
@ -1,25 +1,84 @@
|
|||||||
import { Component, Input } from "@angular/core";
|
import { Component, Input, OnInit } from "@angular/core";
|
||||||
|
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||||
|
|
||||||
|
import { NotificationService, PlexService } from "../services";
|
||||||
|
|
||||||
|
import { IPlexLibraries, IPlexServersAdd } from "../interfaces";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "ngbd-modal-content",
|
selector: "ngbd-modal-content",
|
||||||
template: `
|
templateUrl: "./addplexuser.component.html",
|
||||||
<div class="modal-header">
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<p>Hello, {{name}}!</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-danger-outline" (click)="activeModal.close('Close click')">Close</button>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
})
|
})
|
||||||
export class AddPlexUserComponent {
|
export class AddPlexUserComponent implements OnInit {
|
||||||
|
|
||||||
@Input() public name: string;
|
@Input() public name: string;
|
||||||
|
|
||||||
|
public plexServers: IPlexServersAdd[];
|
||||||
|
public plexLibs: IPlexLibraries;
|
||||||
|
|
||||||
|
public libsSelected: number[] = [];
|
||||||
|
|
||||||
|
public form: FormGroup;
|
||||||
|
|
||||||
|
constructor(public activeModal: NgbActiveModal,
|
||||||
|
private plexService: PlexService,
|
||||||
|
private notificationService: NotificationService,
|
||||||
|
private fb: FormBuilder) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ngOnInit(): void {
|
||||||
|
this.form = this.fb.group({
|
||||||
|
selectedServer: [null, Validators.required],
|
||||||
|
allLibsSelected: [true],
|
||||||
|
username:[null, Validators.required],
|
||||||
|
});
|
||||||
|
this.getServers();
|
||||||
|
}
|
||||||
|
|
||||||
constructor(public activeModal: NgbActiveModal) {
|
public getServers() {
|
||||||
console.log("called");
|
this.plexService.getServersFromSettings().subscribe(x => {
|
||||||
|
if (x.success) {
|
||||||
|
this.plexServers = x.servers;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getPlexLibs(machineId: string) {
|
||||||
|
this.plexService.getLibrariesFromSettings(machineId).subscribe(x => {
|
||||||
|
if (x.successful) {
|
||||||
|
this.plexLibs = x.data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public selected() {
|
||||||
|
this.getPlexLibs(this.form.value.selectedServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public checkedLib(checked: boolean, value: number) {
|
||||||
|
if(checked) {
|
||||||
|
this.libsSelected.push(value);
|
||||||
|
} else {
|
||||||
|
this.libsSelected = this.libsSelected.filter(v => v !== value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public onSubmit(form: FormGroup) {
|
||||||
|
debugger;
|
||||||
|
if (form.invalid) {
|
||||||
|
this.notificationService.error("Please check your entered values");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const libs = form.value.allLibsSelected ? this.plexLibs.mediaContainer.directory.map(x => +x.key) : this.libsSelected;
|
||||||
|
|
||||||
|
this.plexService.addUserToServer({ username: form.value.username, machineIdentifier: form.value.selectedServer, libsSelected: libs }).subscribe(x => {
|
||||||
|
if (x.success) {
|
||||||
|
this.notificationService.success("User added to Plex");
|
||||||
|
} else {
|
||||||
|
this.notificationService.error(x.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue