From 4f6f85a88c19d9a4004505358bf3829f6346517f Mon Sep 17 00:00:00 2001 From: Patrick Sun Date: Tue, 30 Mar 2021 07:43:55 +1100 Subject: [PATCH] person profile, CRUD is finished. --- .../client-profile.component.ts | 2 +- src/app/main-menu-items.ts | 4 +- .../message-box/message-box.component.html | 4 +- src/app/models/api-v1-login-response.ts | 2 +- src/app/models/people.model.ts | 20 ++ src/app/models/user-extra.model.ts | 10 + .../admin-profile/admin-profile.component.ts | 1 - .../broker-profile.component.html | 14 +- .../broker-profile.component.ts | 23 +- .../change-password.component.ts | 2 +- .../people-profile.component.html | 37 +++- .../people-profile.component.scss | 42 ++++ .../people-profile.component.ts | 55 +++-- src/app/profile/profile.component.html | 70 +++++- src/app/profile/profile.component.scss | 30 +++ src/app/profile/profile.component.ts | 207 ++++++++++++++---- .../user-profile/user-profile.component.html | 4 +- .../user-profile/user-profile.component.ts | 37 ++-- src/app/service/auth.service.ts | 2 + src/app/service/people.service.ts | 26 ++- 20 files changed, 457 insertions(+), 135 deletions(-) diff --git a/src/app/client-profile/client-profile.component.ts b/src/app/client-profile/client-profile.component.ts index e460fdf..ab88a26 100644 --- a/src/app/client-profile/client-profile.component.ts +++ b/src/app/client-profile/client-profile.component.ts @@ -36,7 +36,7 @@ export class ClientProfileComponent implements OnInit { if (! brokerForm.touched || brokerForm.form.pristine) { return; } - this.ps.saveUser(this.User).subscribe( () => { + this.ps.savePeople(this.User).subscribe( () => { this.showDialog('updated successfully '); brokerForm.form.markAsPristine(); }, err => { diff --git a/src/app/main-menu-items.ts b/src/app/main-menu-items.ts index 2328f9f..51d2393 100644 --- a/src/app/main-menu-items.ts +++ b/src/app/main-menu-items.ts @@ -42,10 +42,8 @@ export const mainMenuItems: any[] = [ text: 'People', icon: 'user', items: [ - { text: 'Add ', icon: 'plus', url: './#people-add' }, + { text: 'Add ', icon: 'plus', url: './#profile/start-new-people' }, { text: 'List All', fa: faIdCard , url: './#list-all-people'}, - { text: '--', separator: 'true' }, - { text: 'Admin', icon: 'email', url: './#send-to-all-people'}, ] }, ]; diff --git a/src/app/message-box/message-box.component.html b/src/app/message-box/message-box.component.html index eed56b4..ea140f7 100644 --- a/src/app/message-box/message-box.component.html +++ b/src/app/message-box/message-box.component.html @@ -1,5 +1,7 @@ -

{{ Message }}

+

+ {{ Message }} +

diff --git a/src/app/models/api-v1-login-response.ts b/src/app/models/api-v1-login-response.ts index b3854a7..fca6fa9 100644 --- a/src/app/models/api-v1-login-response.ts +++ b/src/app/models/api-v1-login-response.ts @@ -30,7 +30,7 @@ export class ApiV1LoginResponse { } public hasValidSession(): boolean { - if (this.session === undefined || this.session === '') { + if (this.session === undefined || this.session === '' || this.session === null) { return false; }else{ return true; diff --git a/src/app/models/people.model.ts b/src/app/models/people.model.ts index 3195fd7..e707ae2 100644 --- a/src/app/models/people.model.ts +++ b/src/app/models/people.model.ts @@ -23,6 +23,26 @@ export class PeopleModel{ public static EmptyNew(): PeopleModel { return new PeopleModel('', '', '', '', '', '', '' ); } + + public Copy(ppl: PeopleModel): void { + this.Id = ppl.Id; + this.First = ppl.First; + this.Last = ppl.Last; + this.Middle = ppl.Middle; + this.Title = ppl.Title; + this.Display = ppl.Display; + this.Nick = ppl.Nick; + } + + public Clear(): void { + this.Id = ''; + this.First = ''; + this.Last = ''; + this.Middle = ''; + this.Title = ''; + this.Display = ''; + this.Nick = ''; + } } diff --git a/src/app/models/user-extra.model.ts b/src/app/models/user-extra.model.ts index b1183cd..6e58a92 100644 --- a/src/app/models/user-extra.model.ts +++ b/src/app/models/user-extra.model.ts @@ -23,5 +23,15 @@ export class UserExtraModel { rt.Role = ''; return rt; } + + public Clear(): void { + this.BSB = ''; + this.ACC = ''; + this.License = ''; + this.Organization = ''; + this.Enabled = false; + this.Login = ''; + this.Role = ''; + } } diff --git a/src/app/profile/admin-profile/admin-profile.component.ts b/src/app/profile/admin-profile/admin-profile.component.ts index 5733e61..e24d59c 100644 --- a/src/app/profile/admin-profile/admin-profile.component.ts +++ b/src/app/profile/admin-profile/admin-profile.component.ts @@ -6,7 +6,6 @@ import {Component, Input, OnInit} from '@angular/core'; styleUrls: ['./admin-profile.component.scss'] }) export class AdminProfileComponent implements OnInit { - @Input() public PeopleId = '0'; constructor() { } diff --git a/src/app/profile/broker-profile/broker-profile.component.html b/src/app/profile/broker-profile/broker-profile.component.html index 5b5bc10..3b1f419 100644 --- a/src/app/profile/broker-profile/broker-profile.component.html +++ b/src/app/profile/broker-profile/broker-profile.component.html @@ -1,5 +1,5 @@ -
Broker Related : {{broker.Display }}
- +
Broker : {{People.Display }}
+
@@ -7,7 +7,7 @@
- license is required, key in unknown if have one @@ -15,7 +15,7 @@ - BSB required for accepting payment @@ -23,7 +23,7 @@ - ACC is required for accepting payment @@ -31,8 +31,8 @@ - Organization is required, (only changed by admin) diff --git a/src/app/profile/broker-profile/broker-profile.component.ts b/src/app/profile/broker-profile/broker-profile.component.ts index 6559693..50b1c93 100644 --- a/src/app/profile/broker-profile/broker-profile.component.ts +++ b/src/app/profile/broker-profile/broker-profile.component.ts @@ -1,10 +1,11 @@ import {Component, Input, OnInit, ViewChild} from '@angular/core'; import {AuthService} from '../../service/auth.service'; -import {FormControl, FormGroup, NgForm} from '@angular/forms'; -import {FileInfo, FileRestrictions, FileSelectComponent, SelectEvent} from '@progress/kendo-angular-upload'; +import {NgForm} from '@angular/forms'; import {PeopleService} from '../../service/people.service'; import {BrokerModel} from '../../models/broker.model'; import {MessageBoxComponent} from '../../message-box/message-box.component'; +import {UserExtraModel} from '../../models/user-extra.model'; +import {PeopleModel} from '../../models/people.model'; @@ -14,28 +15,24 @@ import {MessageBoxComponent} from '../../message-box/message-box.component'; styleUrls: ['./broker-profile.component.scss'] }) export class BrokerProfileComponent implements OnInit { - @Input() public PeopleId = ''; - @Input() public broker: BrokerModel = BrokerModel.EmptyNew(); + @Input() public UserExtra: UserExtraModel = UserExtraModel.EmptyNew(); + @Input() public People: PeopleModel = PeopleModel.EmptyNew(); @ViewChild('messageBox', {static: true})msgBox: MessageBoxComponent; - public showAdmin = false; + public isAdmin = false; constructor( private auth: AuthService, private ps: PeopleService) { } ngOnInit(): void { - this.showAdmin = this.auth.isAdmin(); - - if (this.auth.isAdmin() ) { - // edit someone else - }else { - this.broker = BrokerModel.getFromUserAndExtra(this.auth.loggedIn.User, this.auth.loggedIn.UserExtra); - } + this.isAdmin = this.auth.isAdmin(); } public save(brokerForm: NgForm): void{ if (! brokerForm.touched || brokerForm.form.pristine) { + this.msgBox.Show('Save successfully done'); return; } - this.ps.saveBroker(this.broker).subscribe( () => { + const broker = BrokerModel.getFromUserAndExtra(this.People, this.UserExtra); + this.ps.saveBroker(broker).subscribe( () => { this.msgBox.Show('updated successfully '); brokerForm.form.markAsPristine(); }, err => { diff --git a/src/app/profile/change-password/change-password.component.ts b/src/app/profile/change-password/change-password.component.ts index 22d2f68..fda4c18 100644 --- a/src/app/profile/change-password/change-password.component.ts +++ b/src/app/profile/change-password/change-password.component.ts @@ -57,7 +57,7 @@ export class ChangePasswordComponent implements OnInit { public canChangePassword(): boolean { if ( this.auth.isCurrentUser(this.PeopleId) ) { - return this.auth.isBroker() || this.auth.isAdmin(); + return this.auth.isUser() || this.auth.isBroker() || this.auth.isAdmin(); }else{ return this.auth.isAdmin() ; } diff --git a/src/app/profile/people-profile/people-profile.component.html b/src/app/profile/people-profile/people-profile.component.html index 45c075c..1bfa60c 100644 --- a/src/app/profile/people-profile/people-profile.component.html +++ b/src/app/profile/people-profile/people-profile.component.html @@ -2,19 +2,39 @@
  Personal Information
-
+
+
+
+
+ + + + +
+
+
+ + + +
-
-
+
+
@@ -28,7 +48,7 @@ + > First name is required
@@ -36,15 +56,16 @@ + > Last Name is required
- + Display name cannot empty
diff --git a/src/app/profile/people-profile/people-profile.component.scss b/src/app/profile/people-profile/people-profile.component.scss index 564f891..2143705 100644 --- a/src/app/profile/people-profile/people-profile.component.scss +++ b/src/app/profile/people-profile/people-profile.component.scss @@ -27,3 +27,45 @@ div.vertical-spacer { height:1px; margin-bottom: 30px; } + +.k-loading-panel { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; + z-index: 100; +} +.k-loading-panel-mask { + width: 100%; + height: 100%; + position: absolute; + top: 0; + left: 0; + background-color: #000000; + opacity: 0.8; + border-radius: 10px; +} +.k-loading-panel-wrapper { + position: relative; + z-index: 2; +} + +.k-loading-panel-text { + margin-top: 20px; + text-align: center; + color: #ffffff; +} + +.k-button.add-new-people { + padding: 30px; + border-radius: 50px; + box-shadow: 1px 1px 10px white; +} + +div.dropzone-wrapper.k-cursor-pointer :hover { + box-shadow: rgb(239 239 239 / 25%) 0px 30px 60px -12px inset, rgb(4 4 4 / 30%) 0px 18px 36px -18px inset; +} diff --git a/src/app/profile/people-profile/people-profile.component.ts b/src/app/profile/people-profile/people-profile.component.ts index e1b1e0b..1eaf264 100644 --- a/src/app/profile/people-profile/people-profile.component.ts +++ b/src/app/profile/people-profile/people-profile.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, Input, OnInit, ViewChild, EventEmitter, Output} from '@angular/core'; import {MessageBoxComponent} from '../../message-box/message-box.component'; import {FileInfo, FileRestrictions, FileSelectComponent, SelectEvent} from '@progress/kendo-angular-upload'; import {AuthService} from '../../service/auth.service'; @@ -12,8 +12,9 @@ import {PeopleModel} from '../../models/people.model'; styleUrls: ['./people-profile.component.scss'] }) export class PeopleProfileComponent implements OnInit { - @Input() PeopleId = ''; @Input() public People: PeopleModel = PeopleModel.EmptyNew(); + @Output() public newPeople = new EventEmitter(); + public avatarUrl = 'url(https://via.placeholder.com/128)' ; public myRestrictions: FileRestrictions = { allowedExtensions: ['.jpg', '.png', '.jpeg'], @@ -25,27 +26,12 @@ export class PeopleProfileComponent implements OnInit { constructor(private auth: AuthService, private ps: PeopleService) { } ngOnInit(): void { - if (this.auth.isAdmin() && !this.auth.isCurrentUser(this.PeopleId)) { - // edit someone else - if ( this.People.Id === '' && this.PeopleId !== '') {// we need to load user by ourself - this.ps.getPeopleById(this.PeopleId).subscribe( - ppl => { - this.People = new PeopleModel( - ppl.Id, - ppl.First, - ppl.Last, - ppl.Middle, - ppl.Title, - ppl.Display, - ppl.Nick - ); - } - ); - } + if (this.auth.isAdmin() && !this.auth.isCurrentUser(this.People.Id)) { + // }else{ this.People = this.auth.loggedIn.User; } - this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.PeopleId) + ')'; + this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.People.Id) + ')'; } onDialogClose(status: string): void { @@ -61,7 +47,7 @@ export class PeopleProfileComponent implements OnInit { reader.onloadend = () => { const str = reader.result as string; - this.ps.updateAvatar(str, this.PeopleId).subscribe( resp => { + this.ps.updateAvatar(str, this.People.Id).subscribe( resp => { this.avatarUrl = 'url(' + str + ' )'; }, err => { this.msgBox.Show('Failed to Update Avatar: ' + err.toString()); @@ -84,7 +70,7 @@ export class PeopleProfileComponent implements OnInit { this.msgBox.Show('Nothing has been changed'); return; } - this.ps.saveUser(this.People).subscribe( () => { + this.ps.savePeople(this.People).subscribe( () => { this.msgBox.Show('Updated successfully '); if ( this.auth.loggedIn.User.Id === this.People.Id ) { this.auth.UpdatePeopleInfo(this.People); @@ -94,4 +80,29 @@ export class PeopleProfileComponent implements OnInit { this.msgBox.Show('Failed to Update: ' + err.toString()); }); } + + public createPeople(): void{ + this.ps.createPeople(this.People).subscribe( + ppl => { + this.People.Copy(ppl); + this.newPeople.emit(this.People); + this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.People.Id) + ')'; + } + ); + } + + public PeopleChanged(ppl: PeopleModel): void { + console.log(this); + this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.People.Id) + ')'; + } + + public startSelectAvatar(): void { + const element: NodeListOf = document.getElementsByName('selectAvatar'); + element.forEach( v => { + if ( v.tagName.toLowerCase() === 'input') { + v.click(); + } + }); + + } } diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html index 6001020..1407c6b 100644 --- a/src/app/profile/profile.component.html +++ b/src/app/profile/profile.component.html @@ -4,17 +4,69 @@
- -

- -

- -

- -

- +
+
+
admin options
+ + + + + + +
+ + +
+
+ + +
+
admin options
+ + + + +
+ + + + + +
+
+ +
+

+ + +
+
+   Remove this person +
+ + You confirm to delete EVERY-thing related to this person + +
+ +
+ +
+ + diff --git a/src/app/profile/profile.component.scss b/src/app/profile/profile.component.scss index 1176235..6f30c1c 100644 --- a/src/app/profile/profile.component.scss +++ b/src/app/profile/profile.component.scss @@ -23,3 +23,33 @@ div.vertical-spacer { height:1px; margin-bottom: 30px; } + +div.admin-panel { + position:relative; + height: 100px; + text-align: center; + margin-top: 10px; + margin-bottom: 20px; + padding-top: 50px; + box-shadow: rgb(0 0 0 / 2%) 0px 1px 3px 0px, rgb(175 175 175 / 15%) 0px 0px 0px 1px +} + +div.admin-panel.dangerous { + margin-top: 30px; + border-radius: 0px 0px 50px 50px; + background-color: #ffeeee; +} + +span.spacer{ + display: inline-block; + width: 30px; +} + +div.admin-label{ + position: absolute; + left: 0px; + top: 0px; + background-color: #dadada4a; + width: 100%; + box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px; +} diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts index b896dac..48b3eed 100644 --- a/src/app/profile/profile.component.ts +++ b/src/app/profile/profile.component.ts @@ -9,6 +9,8 @@ import {ActivatedRoute} from '@angular/router'; import {BrokerModel} from '../models/broker.model'; import {PeopleModel} from '../models/people.model'; import {UserExtraModel} from '../models/user-extra.model'; +import {MessageBoxComponent} from '../message-box/message-box.component'; +import {setTime} from '@progress/kendo-angular-dateinputs/dist/es2015/util'; @Component({ selector: 'app-profile', @@ -20,12 +22,30 @@ export class ProfileComponent implements OnInit { @ViewChild('peopleProfile', {static: true}) pp: PeopleProfileComponent; @ViewChild('userProfile', {static: true}) up: UserProfileComponent; @ViewChild('brokerProfile', {static: true}) bp: BrokerProfileComponent; + @ViewChild('messagebox', {static: true}) msgBox: MessageBoxComponent; - public role = 'unknown'; + public role = 'unknown'; // the role user to be edited. public UserExtra: UserExtraModel = UserExtraModel.EmptyNew(); public People: PeopleModel = PeopleModel.EmptyNew(); - public broker: BrokerModel = BrokerModel.EmptyNew(); + // different section + public showUser = false; + public showBroker = false; + public showAdmin = false; + public showPassword = false; + + // admin specific + public showAdminTool = false; + public editOtherPeople = false; + public enableUserAdd = false; + public enableUserDel = false; + public enableBrokerAdd = false; + public enableBrokerDel = false; + + // delete entire people + public warnDelete = false; + public deleteHeight = 25; + // public isValidPeople = true; public isValidBroker = true; @@ -37,30 +57,36 @@ export class ProfileComponent implements OnInit { this.PeopleId = id; } - if (this.auth.isAdmin() && this.PeopleId !== '' && !this.auth.isCurrentUser(this.PeopleId)) { // admin editing someone else - this.loadOtherPeople(); - this.loadOtherPeopleExtra(); - + if (this.auth.isAdmin() && this.PeopleId !== '' ){ + if (this.PeopleId === 'start-new-people' ){ + return; + }else if (this.PeopleId !== '' && !this.auth.isCurrentUser(this.PeopleId)) { // admin editing someone else + this.loadOtherPeople(); + } }else { // edit himself this.role = this.auth.loggedIn.role; this.PeopleId = this.auth.loggedIn.User.Id; + this.People = this.auth.loggedIn.User; + this.UserExtra = this.auth.loggedIn.UserExtra; } + this.updateShowHide(); } - private loadOtherPeople(): void{ + private loadOtherPeople(): void { this.isValidPeople = false; this.ps.getPeopleById(this.PeopleId).subscribe( ppl => { this.isValidPeople = ppl.Id === this.PeopleId; - this.People = new PeopleModel( - ppl.Id, - ppl.First, - ppl.Last, - ppl.Middle, - ppl.Title, - ppl.Display, - ppl.Nick - ); + if (this.isValidPeople) { + console.log(this); + this.People.Copy(ppl); + this.pp.PeopleChanged(this.People); + this.loadOtherPeopleExtra(); + } + this.updateShowHide(); + }, err => { + console.log(this); + this.msgBox.Show('Failed to load User Information'); } ); } @@ -69,57 +95,148 @@ export class ProfileComponent implements OnInit { this.isValidBroker = false; this.ps.getPeopleExtraById(this.PeopleId).subscribe( resp => { - this.isValidBroker = resp.License !== ''; - this.UserExtra = new UserExtraModel(resp); - this.role = this.UserExtra.Role; - if (this.role === 'broker') { - this.broker = BrokerModel.getFromUserAndExtra(this.People, this.UserExtra); - } + this.setUserExtra(resp); + this.updateShowHide(); } ); } - public showPeople(): boolean { - return this.isValidPeople; // always true + private setUserExtra(resp: UserExtraModel): void { + this.isValidBroker = resp.License !== ''; + this.UserExtra.BSB = resp.BSB; + this.UserExtra.ACC = resp.ACC; + this.UserExtra.License = resp.License; + this.UserExtra.Organization = resp.Organization; + this.UserExtra.Enabled = resp.Enabled; + this.UserExtra.Login = resp.Login; + this.UserExtra.Role = resp.Role; + this.role = this.UserExtra.Role; } - public showUser(): boolean { - return this.isUser() || this.isBroker() || this.isAdmin(); - } + private updateShowHide(): void { + this.resetShowHide(); + + this.editOtherPeople = ! this.auth.isCurrentUser(this.PeopleId); + if ( this.editOtherPeople ) { + this.showAdminTool = this.isAdmin() && this.People.Id !== '' ; + if ( this.showAdminTool ){ + this.enableUserAdd = ! ['user', 'broker', 'admin'].includes(this.role); + this.enableUserDel = this.role === 'user'; + this.enableBrokerAdd = this.role === 'user'; + this.enableBrokerDel = this.role === 'broker'; + } - public showBroker(): boolean { - return this.isBroker() && ! this.isAdmin(); + this.showUser = ['user', 'broker', 'admin'].includes(this.role); + this.showBroker = ['broker'].includes(this.role); + this.showAdmin = ['admin'].includes(this.role); + this.showPassword = true; + + }else{ + this.showAdminTool = false; + this.showUser = ['user', 'broker', 'admin'].includes(this.role); + this.showBroker = ['broker'].includes(this.role); + this.showAdmin = ['admin'].includes(this.role); + this.showPassword = ['user', 'broker', 'admin'].includes(this.role);; + } + console.log( 'check pass', this); } - public showAdmin(): boolean { - return this.isAdmin(); + private resetShowHide(): void { + // different section + this.showUser = false; + this.showBroker = false; + this.showAdmin = false; + this.showPassword = false; + + // admin specific + this.showAdminTool = false; + this.editOtherPeople = false; + this.enableUserAdd = false; + this.enableUserDel = false; + this.enableBrokerAdd = false; + this.enableBrokerDel = false; } - public showPassword(): boolean { - return this.isUser() || this.isBroker() || this.isAdmin(); + public onNewPeopleCreated(ppl: PeopleModel): void { + console.log(this.People); + this.updateShowHide(); } + // the user who performs this edit action public isAdmin(): boolean { - if ( this.auth.isCurrentUser(this.PeopleId) ){ return this.auth.isAdmin(); - }else{ - return this.role === 'admin'; - } } + // the user who performs this edit action public isBroker(): boolean { - if ( this.auth.isCurrentUser(this.PeopleId) ) { return this.auth.isBroker(); - }else{ - return this.role === 'broker'; - } } + // the user who performs this edit action public isUser(): boolean { - if ( this.auth.isCurrentUser(this.PeopleId) ) { return this.auth.isUser(); - }else{ - return this.role === 'user'; - } + } + + public deletePeople(): void { + + this.ps.deletePeople(this.People.Id).subscribe( + resp => { + if ( resp === this.People.Id ) { // successfully deleted + this.msgBox.Show('User and all of his/her related loans payment has been deleted !!'); + this.People.Clear(); + this.UserExtra.Clear(); + this.role = 'unknown'; + console.log(this); + this.updateShowHide(); + } + }, err => { + this.msgBox.Show('"Error Delete People'); + } + ); + } + + public upgradePeopleToUser(): void{ + this.ps.upgradePeopleToUser(this.People.Id).subscribe( + resp => { + this.setUserExtra(resp); + this.updateShowHide(); + } + ); + } + + public downgradeToPeople(): void{ + this.ps.downgradeUserToPeople(this.People.Id).subscribe( + resp => { + this.setUserExtra(resp); + this.updateShowHide(); + } + ); + } + + public upgradeUserToBroker(): void{ + this.ps.upgradeUserToBroker(this.People.Id).subscribe( + resp => { + this.setUserExtra(resp); + this.updateShowHide(); + } + ); + } + + public downgradeToUser(): void{ + this.ps.downgradeBrokerToUser(this.People.Id).subscribe( + resp => { + this.setUserExtra(resp); + this.updateShowHide(); + } + ); + } + + public onWarnDelete(status: boolean): void { + + if (status) { + this.deleteHeight = 100; + }else{ + this.deleteHeight = 30; + } } } diff --git a/src/app/profile/user-profile/user-profile.component.html b/src/app/profile/user-profile/user-profile.component.html index 1cac9f7..49c6f04 100644 --- a/src/app/profile/user-profile/user-profile.component.html +++ b/src/app/profile/user-profile/user-profile.component.html @@ -11,7 +11,7 @@ [size]="'medium'" > - + Login is required Login is used by someone else @@ -28,7 +28,7 @@
-
+
diff --git a/src/app/profile/user-profile/user-profile.component.ts b/src/app/profile/user-profile/user-profile.component.ts index b21abd6..2c031de 100644 --- a/src/app/profile/user-profile/user-profile.component.ts +++ b/src/app/profile/user-profile/user-profile.component.ts @@ -4,9 +4,9 @@ import {FormControl, FormGroup, NgForm, Validators} from '@angular/forms'; import {AuthService} from '../../service/auth.service'; import {HttpClient} from '@angular/common/http'; import {MessageBoxComponent} from '../../message-box/message-box.component'; -import {BrokerModel} from '../../models/broker.model'; import {PeopleService} from '../../service/people.service'; import {asyncValidatorLoginAvailable} from '../../validator/unique.login.validator'; +import {PeopleModel} from '../../models/people.model'; @Component({ selector: 'app-user-profile', @@ -14,7 +14,7 @@ import {asyncValidatorLoginAvailable} from '../../validator/unique.login.validat styleUrls: ['./user-profile.component.scss'] }) export class UserProfileComponent implements OnInit { - @Input() public PeopleId = ''; + @Input() public People: PeopleModel = PeopleModel.EmptyNew(); @Input() public UserExtra: UserExtraModel = UserExtraModel.EmptyNew(); @ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent; @@ -28,24 +28,15 @@ export class UserProfileComponent implements OnInit { ngOnInit(): void { this.showAdmin = this.auth.isAdmin(); - this.isCurrentUser = this.auth.isCurrentUser(this.PeopleId); + this.isCurrentUser = this.auth.isCurrentUser(this.People.Id); - if (this.auth.isAdmin() && !this.auth.isCurrentUser(this.PeopleId)) { + if (this.auth.isAdmin() && !this.auth.isCurrentUser(this.People.Id)) { // edit other people, - if ( this.PeopleId !== '' && this.UserExtra.Login === '' ){ // we need to load by ourself - this.ps.getPeopleExtraById(this.PeopleId).subscribe( - resp => { - this.UserExtra = new UserExtraModel(resp); - this.UserForm.get('Login').setValue(this.UserExtra.Login); - this.UserForm.get('Enabled').setValue(this.UserExtra.Enabled); - } - ); - } }else{ - this.PeopleId = this.auth.loggedIn.User.Id; + this.People.Id = this.auth.loggedIn.User.Id; this.UserExtra = this.auth.loggedIn.UserExtra; } - + console.log(this); this.UserForm = new FormGroup({ Login: new FormControl({value: this.UserExtra.Login, disabled: ! this.showAdmin }, [Validators.required, Validators.email], @@ -55,10 +46,15 @@ export class UserProfileComponent implements OnInit { } public save(): void { - const expected = this.UserForm.get('Login').value; - this.http.post(this.auth.getUrl('user/' + this.PeopleId), this.UserExtra).subscribe( + const ex = new UserExtraModel(this.UserExtra); + ex.Login = this.UserForm.get('Login').value; + ex.Enabled = this.UserForm.get('Enabled').value; + + this.http.post(this.auth.getUrl('user/' + this.People.Id), ex).subscribe( resp => { - if ( resp === expected ) { + if ( resp.Login === ex.Login && resp.Enabled === ex.Enabled) { + this.UserExtra.Login = resp.Login; + this.UserExtra.Enabled = resp.Enabled; this.msgBox.Show('Successfully Changed'); }else{ this.msgBox.Show('Login not Changed: ' + resp ); @@ -77,8 +73,9 @@ export class UserProfileComponent implements OnInit { return this.UserExtra !== undefined && this.UserExtra.Login !== undefined; } - public onChangeLogin(): void { - console.log(this); + + public showSubmit(): boolean { + return this.UserForm.get('Login').status !== 'PENDING' && this.currentUserIsAdmin(); } } diff --git a/src/app/service/auth.service.ts b/src/app/service/auth.service.ts index 2ae63b1..d70ce3b 100644 --- a/src/app/service/auth.service.ts +++ b/src/app/service/auth.service.ts @@ -80,6 +80,8 @@ export class AuthService { if (responseData.UserExtra !== undefined ) { this.loggedIn.UserExtra = new UserExtraModel(responseData.UserExtra); + }else{ + this.loggedIn.UserExtra = UserExtraModel.EmptyNew(); } }else{ this.loggedIn.User = PeopleModel.EmptyNew(); diff --git a/src/app/service/people.service.ts b/src/app/service/people.service.ts index e365084..0649218 100644 --- a/src/app/service/people.service.ts +++ b/src/app/service/people.service.ts @@ -45,7 +45,31 @@ export class PeopleService { return this.http.post(this.auth.getUrl('broker/' + broker.Id), broker); } - public saveUser(people: PeopleModel): Observable{ + public savePeople(people: PeopleModel): Observable{ return this.http.post(this.auth.getUrl('people/' + people.Id), people); } + + public createPeople(people: PeopleModel): Observable { + return this.http.put(this.auth.getUrl('people/' + people.Id), people); + } + + public deletePeople(id: string): Observable { + return this.http.delete(this.auth.getUrl('people/' + id)); + } + + public upgradePeopleToUser(id: string ): Observable { + return this.http.put(this.auth.getUrl('user/' + id), {}); + } + + public downgradeUserToPeople(id: string ): Observable { + return this.http.delete(this.auth.getUrl('user/' + id), {}); + } + + public upgradeUserToBroker(id: string ): Observable { + return this.http.put(this.auth.getUrl('broker/' + id), {}); + } + public downgradeBrokerToUser(id: string ): Observable { + return this.http.delete(this.auth.getUrl('broker/' + id), {}); + } + }