@ -1,21 +1,31 @@
import { Component , Inject , OnInit } from "@angular/core" ;
import { Component , Inject , OnInit } from '@angular/core' ;
import { UntypedFormBuilder , UntypedFormGroup } from "@angular/forms" ;
import { UntypedFormBuilder , UntypedFormGroup } from '@angular/forms' ;
import { MatDialogRef , MAT_DIALOG_DATA } from "@angular/material/dialog" ;
import { MatDialogRef , MAT_DIALOG_DATA } from '@angular/material/dialog' ;
import { SonarrFacade } from "app/state/sonarr" ;
import { RadarrFacade } from 'app/state/radarr' ;
import { firstValueFrom , Observable } from "rxjs" ;
import { SonarrFacade } from 'app/state/sonarr' ;
import { startWith , map } from "rxjs/operators" ;
import { firstValueFrom , Observable } from 'rxjs' ;
import { ILanguageProfiles , IRadarrProfile , IRadarrRootFolder , ISonarrProfile , ISonarrRootFolder , IUserDropdown , RequestType } from "../../interfaces" ;
import { startWith , map } from 'rxjs/operators' ;
import { IdentityService , RadarrService , SonarrService } from "../../services" ;
import {
ILanguageProfiles ,
IRadarrProfile ,
IRadarrRootFolder ,
ISonarrProfile ,
ISonarrRootFolder ,
IUserDropdown ,
RequestType ,
} from '../../interfaces' ;
import { IdentityService , RadarrService , SonarrService } from '../../services' ;
export interface IAdminRequestDialogData {
export interface IAdminRequestDialogData {
type : RequestType ,
type : RequestType ;
id : number
id : number ;
is4k : boolean | null ;
}
}
@Component ( {
@Component ( {
selector : "admin-request-dialog" ,
selector : 'admin-request-dialog' ,
templateUrl : "admin-request-dialog.component.html" ,
templateUrl : 'admin-request-dialog.component.html' ,
styleUrls : [ "admin-request-dialog.component.scss" ]
styleUrls : [ 'admin-request-dialog.component.scss' ] ,
} )
} )
export class AdminRequestDialogComponent implements OnInit {
export class AdminRequestDialogComponent implements OnInit {
constructor (
constructor (
@ -25,7 +35,8 @@ export class AdminRequestDialogComponent implements OnInit {
private sonarrService : SonarrService ,
private sonarrService : SonarrService ,
private radarrService : RadarrService ,
private radarrService : RadarrService ,
private fb : UntypedFormBuilder ,
private fb : UntypedFormBuilder ,
private sonarrFacade : SonarrFacade
private sonarrFacade : SonarrFacade ,
private radarrFacade : RadarrFacade ,
) { }
) { }
public form : UntypedFormGroup ;
public form : UntypedFormGroup ;
@ -36,6 +47,7 @@ export class AdminRequestDialogComponent implements OnInit {
public userId : string ;
public userId : string ;
public radarrEnabled : boolean ;
public radarrEnabled : boolean ;
public radarr4kEnabled : boolean ;
public sonarrEnabled : boolean ;
public sonarrEnabled : boolean ;
public sonarrProfiles : ISonarrProfile [ ] ;
public sonarrProfiles : ISonarrProfile [ ] ;
@ -45,56 +57,68 @@ export class AdminRequestDialogComponent implements OnInit {
public radarrRootFolders : IRadarrRootFolder [ ] ;
public radarrRootFolders : IRadarrRootFolder [ ] ;
public async ngOnInit() {
public async ngOnInit() {
this . form = this . fb . group ( {
this . form = this . fb . group ( {
username : [ null ] ,
username : [ null ] ,
sonarrPathId : [ null ] ,
sonarrPathId : [ null ] ,
sonarrFolderId : [ null ] ,
sonarrFolderId : [ null ] ,
sonarrLanguageId : [ null ] ,
sonarrLanguageId : [ null ] ,
radarrPathId : [ null ] ,
radarrPathId : [ null ] ,
radarrFolderId : [ null ]
radarrFolderId : [ null ] ,
} )
} ) ;
this . options = await firstValueFrom ( this . identityService . getUsersDropdown ( ) ) ;
this . options = await firstValueFrom ( this . identityService . getUsersDropdown ( ) ) ;
this . filteredOptions = this . form . controls [ 'username' ] . valueChanges . pipe (
this . filteredOptions = this . form . controls [ 'username' ] . valueChanges . pipe (
startWith ( "" ) ,
startWith ( '' ) ,
map ( ( value ) = > this . _filter ( value ) )
map ( ( value ) = > this . _filter ( value ) ) ,
) ;
) ;
if ( this . data . type === RequestType . tvShow ) {
if ( this . data . type === RequestType . tvShow ) {
this . sonarrEnabled = this . sonarrFacade . isEnabled ( ) ;
this . sonarrEnabled = this . sonarrFacade . isEnabled ( ) ;
if ( this . sonarrEnabled ) {
if ( this . sonarrEnabled ) {
console . log ( this . sonarrFacade . version ( ) ) ;
console . log ( this . sonarrFacade . version ( ) ) ;
if ( this . sonarrFacade . version ( ) [ 0 ] === "3" ) {
if ( this . sonarrFacade . version ( ) [ 0 ] === '3' ) {
this . sonarrService . getV3LanguageProfilesWithoutSettings ( ) . subscribe ( ( profiles : ILanguageProfiles [ ] ) = > {
this . sonarrService . getV3LanguageProfilesWithoutSettings ( ) . subscribe ( ( profiles : ILanguageProfiles [ ] ) = > {
this . sonarrLanguageProfiles = profiles ;
this . sonarrLanguageProfiles = profiles ;
} )
} ) ;
}
}
this . sonarrService . getQualityProfilesWithoutSettings ( ) . subscribe ( c = > {
this . sonarrService . getQualityProfilesWithoutSettings ( ) . subscribe ( ( c ) = > {
this . sonarrProfiles = c ;
this . sonarrProfiles = c ;
} ) ;
} ) ;
this . sonarrService . getRootFoldersWithoutSettings ( ) . subscribe ( c = > {
this . sonarrService . getRootFoldersWithoutSettings ( ) . subscribe ( ( c ) = > {
this . sonarrRootFolders = c ;
this . sonarrRootFolders = c ;
} ) ;
} ) ;
}
}
}
}
if ( this . data . type === RequestType . movie ) {
if ( this . data . type === RequestType . movie ) {
this . radarrEnabled = await this . radarrService . isRadarrEnabled ( ) ;
this . radarrEnabled = this . radarrFacade . isEnabled ( ) ;
this . radarr4kEnabled = this . radarrFacade . is4KEnabled ( ) ;
if ( this . data . is4k ? ? false ) {
if ( this . radarr4kEnabled ) {
this . radarrService . getQualityProfiles4kFromSettings ( ) . subscribe ( ( c ) = > {
this . radarrProfiles = c ;
} ) ;
this . radarrService . getRootFolders4kFromSettings ( ) . subscribe ( ( c ) = > {
this . radarrRootFolders = c ;
} ) ;
}
} else {
if ( this . radarrEnabled ) {
if ( this . radarrEnabled ) {
this . radarrService . getQualityProfilesFromSettings ( ) . subscribe ( c = > {
this . radarrService . getQualityProfilesFromSettings ( ) . subscribe ( ( c ) = > {
this . radarrProfiles = c ;
this . radarrProfiles = c ;
} ) ;
} ) ;
this . radarrService . getRootFoldersFromSettings ( ) . subscribe ( c = > {
this . radarrService . getRootFoldersFromSettings ( ) . subscribe ( ( c ) = > {
this . radarrRootFolders = c ;
this . radarrRootFolders = c ;
} ) ;
} ) ;
}
}
}
}
}
}
}
public displayFn ( user : IUserDropdown ) : string {
public displayFn ( user : IUserDropdown ) : string {
const username = user ? . username ? user . username : "" ;
const username = user ? . username ? user . username : '' ;
const email = user ? . email ? ` ( ${ user . email } ) ` : "" ;
const email = user ? . email ? ` ( ${ user . email } ) ` : '' ;
if ( username || email ) {
if ( username || email ) {
return ` ${ username } ${ email } ` ;
return ` ${ username } ${ email } ` ;
}
}
@ -102,23 +126,18 @@ export class AdminRequestDialogComponent implements OnInit {
}
}
private _filter ( value : string | IUserDropdown ) : IUserDropdown [ ] {
private _filter ( value : string | IUserDropdown ) : IUserDropdown [ ] {
const filterValue =
const filterValue = typeof value === 'string' ? value . toLowerCase ( ) : value . username . toLowerCase ( ) ;
typeof value === "string"
? value . toLowerCase ( )
: value . username . toLowerCase ( ) ;
return this . options . filter ( ( option ) = >
return this . options . filter ( ( option ) = > option . username . toLowerCase ( ) . includes ( filterValue ) ) ;
option . username . toLowerCase ( ) . includes ( filterValue )
) ;
}
}
public async submitRequest() {
public async submitRequest() {
const model = this . form . value ;
const model = this . form . value ;
model . radarrQualityOverrideTitle = this . radarrProfiles ? . filter ( x = > x . id == model . radarrPathId ) [ 0 ] ? . name ;
model . radarrQualityOverrideTitle = this . radarrProfiles ? . filter ( ( x ) = > x . id == model . radarrPathId ) [ 0 ] ? . name ;
model . radarrRootFolderTitle = this . radarrRootFolders ? . filter ( x = > x . id == model . radarrFolderId ) [ 0 ] ? . path ;
model . radarrRootFolderTitle = this . radarrRootFolders ? . filter ( ( x ) = > x . id == model . radarrFolderId ) [ 0 ] ? . path ;
model . sonarrRootFolderTitle = this . sonarrRootFolders ? . filter ( x = > x . id == model . sonarrFolderId ) [ 0 ] ? . path ;
model . sonarrRootFolderTitle = this . sonarrRootFolders ? . filter ( ( x ) = > x . id == model . sonarrFolderId ) [ 0 ] ? . path ;
model . sonarrQualityOverrideTitle = this . sonarrProfiles ? . filter ( x = > x . id == model . sonarrPathId ) [ 0 ] ? . name ;
model . sonarrQualityOverrideTitle = this . sonarrProfiles ? . filter ( ( x ) = > x . id == model . sonarrPathId ) [ 0 ] ? . name ;
model . sonarrLanguageProfileTitle = this . sonarrLanguageProfiles ? . filter ( x = > x . id == model . sonarrLanguageId ) [ 0 ] ? . name ;
model . sonarrLanguageProfileTitle = this . sonarrLanguageProfiles ? . filter ( ( x ) = > x . id == model . sonarrLanguageId ) [ 0 ] ? . name ;
this . dialogRef . close ( model ) ;
this . dialogRef . close ( model ) ;
}
}
}
}