From 2886f6e6fa2f81bb2595b4228a7f6368448d71f2 Mon Sep 17 00:00:00 2001 From: TidusJar Date: Tue, 18 Sep 2018 13:05:41 +0100 Subject: [PATCH] Consolodated the usermanagement stuff, still a !wip but it's a start --- .../usermanagement-add.component.html | 79 --------- .../usermanagement-add.component.ts | 70 -------- .../usermanagement-edit.component.html | 70 -------- .../usermanagement-user.component.html | 154 ++++++++++++++++++ ...nt.ts => usermanagement-user.component.ts} | 92 +++++++++-- .../usermanagement.component.html | 4 +- .../usermanagement/usermanagement.module.ts | 4 +- 7 files changed, 235 insertions(+), 238 deletions(-) delete mode 100644 src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.html delete mode 100644 src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.ts delete mode 100644 src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.html create mode 100644 src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.html rename src/Ombi/ClientApp/app/usermanagement/{usermanagement-edit.component.ts => usermanagement-user.component.ts} (51%) diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.html b/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.html deleted file mode 100644 index 683bd5620..000000000 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.html +++ /dev/null @@ -1,79 +0,0 @@ - -

Create User

- - - -
-
- - -
-
\ No newline at end of file diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.ts b/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.ts deleted file mode 100644 index 36b187e79..000000000 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement-add.component.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { Component, OnInit } from "@angular/core"; -import { Router } from "@angular/router"; - -import { ICheckbox, IUser, UserType } from "../interfaces"; -import { IdentityService, NotificationService } from "../services"; - -@Component({ - templateUrl: "./usermanagement-add.component.html", -}) -export class UserManagementAddComponent implements OnInit { - public user: IUser; - public availableClaims: ICheckbox[]; - public confirmPass: ""; - - constructor(private identityService: IdentityService, - private notificationSerivce: NotificationService, - private router: Router) { } - - public ngOnInit() { - this.identityService.getAllAvailableClaims().subscribe(x => this.availableClaims = x); - this.user = { - alias: "", - claims: [], - emailAddress: "", - id: "", - password: "", - userName: "", - userType: UserType.LocalUser, - checked: false, - hasLoggedIn: false, - lastLoggedIn: new Date(), - episodeRequestLimit: 0, - movieRequestLimit: 0, - userAccessToken: "", - }; - } - - public create() { - this.user.claims = this.availableClaims; - - if (this.user.password) { - if (this.user.password !== this.confirmPass) { - this.notificationSerivce.error("Passwords do not match"); - return; - } - } - const hasClaims = this.availableClaims.some((item) => { - if (item.enabled) { return true; } - - return false; - }); - - if (!hasClaims) { - this.notificationSerivce.error("Please assign a role"); - return; - } - - this.identityService.createUser(this.user).subscribe(x => { - if (x.successful) { - this.notificationSerivce.success(`The user ${this.user.userName} has been created successfully`); - this.router.navigate(["usermanagement"]); - } else { - x.errors.forEach((val) => { - this.notificationSerivce.error(val); - }); - } - }); - } - -} diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.html b/src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.html deleted file mode 100644 index 95a70cab0..000000000 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.html +++ /dev/null @@ -1,70 +0,0 @@ -
-
-

User: {{user.userName}}

- - - - - - -
- - - - -
-
-
\ No newline at end of file diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.html b/src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.html new file mode 100644 index 000000000..0dcb24cb4 --- /dev/null +++ b/src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.html @@ -0,0 +1,154 @@ +
+

Create User

+ + + +
+
+ + +
+
+
+ +
+ +
+
+

User: {{user.userName}}

+ + + + + + +
+ + + + +
+
+
+
\ No newline at end of file diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.ts b/src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.ts similarity index 51% rename from src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.ts rename to src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.ts index a83ef5a97..bca4f1058 100644 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement-edit.component.ts +++ b/src/Ombi/ClientApp/app/usermanagement/usermanagement-user.component.ts @@ -1,32 +1,92 @@ -import { Component } from "@angular/core"; -import { Router } from "@angular/router"; +import { Component, OnInit } from "@angular/core"; +import { ActivatedRoute, Router } from "@angular/router"; + +import { ICheckbox, IUser, UserType } from "../interfaces"; +import { IdentityService, NotificationService } from "../services"; + import { ConfirmationService } from "primeng/primeng"; -import { ActivatedRoute } from "@angular/router"; -import { IUser } from "../interfaces"; -import { IdentityService } from "../services"; -import { NotificationService } from "../services"; - @Component({ - templateUrl: "./usermanagement-edit.component.html", + templateUrl: "./usermanagement-user.component.html", }) -export class UserManagementEditComponent { +export class UserManagementUserComponent implements OnInit { + public user: IUser; public userId: string; + public availableClaims: ICheckbox[]; + public confirmPass: ""; + + public edit: boolean; constructor(private identityService: IdentityService, - private route: ActivatedRoute, private notificationService: NotificationService, private router: Router, + private route: ActivatedRoute, private confirmationService: ConfirmationService) { - this.route.params + this.route.params .subscribe((params: any) => { - this.userId = params.id; - - this.identityService.getUserById(this.userId).subscribe(x => { - this.user = x; - }); + if(params.id) { + this.userId = params.id; + this.edit = true; + this.identityService.getUserById(this.userId).subscribe(x => { + this.user = x; + }); + } }); + + } + + public ngOnInit() { + this.identityService.getAllAvailableClaims().subscribe(x => this.availableClaims = x); + if(!this.edit) { + this.user = { + alias: "", + claims: [], + emailAddress: "", + id: "", + password: "", + userName: "", + userType: UserType.LocalUser, + checked: false, + hasLoggedIn: false, + lastLoggedIn: new Date(), + episodeRequestLimit: 0, + movieRequestLimit: 0, + userAccessToken: "", + }; + } + } + + public create() { + this.user.claims = this.availableClaims; + + if (this.user.password) { + if (this.user.password !== this.confirmPass) { + this.notificationService.error("Passwords do not match"); + return; + } + } + const hasClaims = this.availableClaims.some((item) => { + if (item.enabled) { return true; } + + return false; + }); + + if (!hasClaims) { + this.notificationService.error("Please assign a role"); + return; + } + + this.identityService.createUser(this.user).subscribe(x => { + if (x.successful) { + this.notificationService.success(`The user ${this.user.userName} has been created successfully`); + this.router.navigate(["usermanagement"]); + } else { + x.errors.forEach((val) => { + this.notificationService.error(val); + }); + } + }); } public delete() { diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.html b/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.html index 519db023f..de78f64f8 100644 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.html +++ b/src/Ombi/ClientApp/app/usermanagement/usermanagement.component.html @@ -2,7 +2,7 @@ - +
@@ -94,7 +94,7 @@ Emby User - Details/Edit + Details/Edit diff --git a/src/Ombi/ClientApp/app/usermanagement/usermanagement.module.ts b/src/Ombi/ClientApp/app/usermanagement/usermanagement.module.ts index cf25446f5..7ff799729 100644 --- a/src/Ombi/ClientApp/app/usermanagement/usermanagement.module.ts +++ b/src/Ombi/ClientApp/app/usermanagement/usermanagement.module.ts @@ -10,6 +10,7 @@ import { UpdateDetailsComponent } from "./updatedetails.component"; import { UserManagementAddComponent } from "./usermanagement-add.component"; import { UserManagementEditComponent } from "./usermanagement-edit.component"; import { UserManagementComponent } from "./usermanagement.component"; +import { UserManagementUserComponent } from "./usermanagement-user.component"; import { PipeModule } from "../pipes/pipe.module"; import { IdentityService, PlexService } from "../services"; @@ -22,7 +23,7 @@ import { AddPlexUserComponent } from "./addplexuser.component"; const routes: Routes = [ { path: "", component: UserManagementComponent, canActivate: [AuthGuard] }, { path: "add", component: UserManagementAddComponent, canActivate: [AuthGuard] }, - { path: "edit/:id", component: UserManagementEditComponent, canActivate: [AuthGuard] }, + { path: "user", component: UserManagementUserComponent, canActivate: [AuthGuard] }, { path: "updatedetails", component: UpdateDetailsComponent, canActivate: [AuthGuard] }, ]; @@ -46,6 +47,7 @@ const routes: Routes = [ UserManagementEditComponent, UpdateDetailsComponent, AddPlexUserComponent, + UserManagementUserComponent, ], entryComponents:[ AddPlexUserComponent,