Parcourir la source

profile consolidated.

tags/2.037
Patrick Sun il y a 4 ans
Parent
révision
9f2acb0781
12 fichiers modifiés avec 149 ajouts et 29 suppressions
  1. +1
    -0
      src/app/app-routing.module.ts
  2. +2
    -0
      src/app/models/user-extra.model.ts
  3. +8
    -2
      src/app/profile/broker-profile/broker-profile.component.ts
  4. +1
    -1
      src/app/profile/change-password/change-password.component.html
  5. +10
    -2
      src/app/profile/change-password/change-password.component.ts
  6. +22
    -4
      src/app/profile/people-profile/people-profile.component.ts
  7. +3
    -3
      src/app/profile/profile.component.html
  8. +72
    -10
      src/app/profile/profile.component.ts
  9. +1
    -1
      src/app/profile/user-profile/user-profile.component.html
  10. +21
    -6
      src/app/profile/user-profile/user-profile.component.ts
  11. +4
    -0
      src/app/service/auth.service.ts
  12. +4
    -0
      src/app/service/people.service.ts

+ 1
- 0
src/app/app-routing.module.ts Voir le fichier

@@ -52,6 +52,7 @@ const routes: Routes = [
{path : 'list-all-people', component: LenderUploadsComponent, canActivate: [AuthGuard] },
{path : 'people-add', component: PeopleAddComponent, canActivate: [AuthGuard] },
{path : 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
{path : 'profile/:id', component: ProfileComponent, canActivate: [AuthGuard] },
{path : 'e403', component: E403Component, },
];


+ 2
- 0
src/app/models/user-extra.model.ts Voir le fichier

@@ -6,6 +6,7 @@ export class UserExtraModel {
public Organization: string;
public Enabled: boolean;
public Login: string;
public Role?: string;

constructor(payload: Partial<UserExtraModel>) {
Object.assign(this, payload);
@@ -19,6 +20,7 @@ export class UserExtraModel {
rt.Organization = '';
rt.Enabled = false;
rt.Login = '';
rt.Role = '';
return rt;
}
}

+ 8
- 2
src/app/profile/broker-profile/broker-profile.component.ts Voir le fichier

@@ -15,14 +15,20 @@ import {MessageBoxComponent} from '../../message-box/message-box.component';
})
export class BrokerProfileComponent implements OnInit {
@Input() public PeopleId = '';
@Input() public showAdmin: false;
@Input() public broker: BrokerModel = BrokerModel.EmptyNew();
@ViewChild('messageBox', {static: true})msgBox: MessageBoxComponent;
public showAdmin = false;

constructor( private auth: AuthService, private ps: PeopleService) { }

ngOnInit(): void {
this.broker = BrokerModel.getFromUserAndExtra(this.auth.loggedIn.User, this.auth.loggedIn.UserExtra);
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);
}
}

public save(brokerForm: NgForm): void{

+ 1
- 1
src/app/profile/change-password/change-password.component.html Voir le fichier

@@ -5,7 +5,7 @@

<div class="vertical-spacer"></div>
<form *ngIf="changePassword" [formGroup]="ChangePassForm" class="k-form" (submit)="savePassword()">
<kendo-formfield>
<kendo-formfield *ngIf="!isAdmin">
<kendo-label [for]="OldPassword" text="Current Password"></kendo-label>
<input kendoTextBox #OldPassword name="OldPassword" formControlName="OldPassword"
type="password" [minlength]="3" [maxlength]="25" />

+ 10
- 2
src/app/profile/change-password/change-password.component.ts Voir le fichier

@@ -14,6 +14,7 @@ export class ChangePasswordComponent implements OnInit {
@ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent;

public changePassword = false;
public isAdmin = false;

public ChangePassForm: FormGroup = new FormGroup({
OldPassword: new FormControl(),
@@ -23,6 +24,9 @@ export class ChangePasswordComponent implements OnInit {
constructor(private auth: AuthService, private ps: PeopleService) { }

ngOnInit(): void {
if (this.auth.isAdmin() && this.PeopleId !== '' && !this.auth.isCurrentUser(this.PeopleId)) {
this.isAdmin = this.auth.isAdmin();
}
}
public hidePass(): void{
if ( this.changePassword ) {
@@ -31,7 +35,7 @@ export class ChangePasswordComponent implements OnInit {
}

public savePassword(): void{
this.ps.savePassword('0', this.ChangePassForm.value).subscribe(
this.ps.savePassword(this.PeopleId, this.ChangePassForm.value).subscribe(
() => {
this.changePassword = false;
this.msgBox.Show('Password Changed');
@@ -52,6 +56,10 @@ export class ChangePasswordComponent implements OnInit {
}

public canChangePassword(): boolean {
return this.auth.isBroker() || this.auth.isAdmin();
if ( this.auth.isCurrentUser(this.PeopleId) ) {
return this.auth.isBroker() || this.auth.isAdmin();
}else{
return this.auth.isAdmin() ;
}
}
}

+ 22
- 4
src/app/profile/people-profile/people-profile.component.ts Voir le fichier

@@ -13,8 +13,8 @@ import {PeopleModel} from '../../models/people.model';
})
export class PeopleProfileComponent implements OnInit {
@Input() PeopleId = '';
public People: PeopleModel = PeopleModel.EmptyNew();
public avatarUrl = 'url(https://svr2021.lawipac.com:8080/api/v1/avatar/1000)' ;
@Input() public People: PeopleModel = PeopleModel.EmptyNew();
public avatarUrl = 'url(https://via.placeholder.com/128)' ;
public myRestrictions: FileRestrictions = {
allowedExtensions: ['.jpg', '.png', '.jpeg'],
maxFileSize: 2194304
@@ -25,8 +25,26 @@ export class PeopleProfileComponent implements OnInit {
constructor(private auth: AuthService, private ps: PeopleService) { }

ngOnInit(): void {
this.People = this.auth.loggedIn.User;
this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.PeopleId) + ')';
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
);
}
);
}
}else{
this.People = this.auth.loggedIn.User;
}
this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.PeopleId) + ')';
}


+ 3
- 3
src/app/profile/profile.component.html Voir le fichier

@@ -4,11 +4,11 @@
<div class="container settings">
<div class="row justify-content-center">
<div class="col-sm-12">
<app-people-profile #peopleProfile *ngIf="showPeople()" [PeopleId]="PeopleId" ></app-people-profile>
<app-people-profile #peopleProfile *ngIf="showPeople()" [PeopleId]="PeopleId" [People]="People" ></app-people-profile>
<div *ngIf="showUser()" class="vertical-spacer"> <hr></div>
<app-user-profile #userProfile *ngIf="showUser()" [PeopleId]="PeopleId" [showAdmin]="showAdmin()"></app-user-profile>
<app-user-profile #userProfile *ngIf="showUser()" [PeopleId]="PeopleId" [UserExtra]="UserExtra"></app-user-profile>
<div *ngIf="showBroker()" class="vertical-spacer"><hr></div>
<app-broker-profile #brokerProfile *ngIf="showBroker()" [PeopleId]="PeopleId" [showAdmin]="showAdmin()"></app-broker-profile>
<app-broker-profile #brokerProfile *ngIf="showBroker()" [PeopleId]="PeopleId" [broker]="broker"></app-broker-profile>
<div *ngIf="showAdmin()" class="vertical-spacer"><hr></div>
<app-admin-profile #adminProfile *ngIf="showAdmin()" [PeopleId]="PeopleId" ></app-admin-profile>
<div *ngIf="showPassword()" class="vertical-spacer" ><hr></div>

+ 72
- 10
src/app/profile/profile.component.ts Voir le fichier

@@ -5,6 +5,10 @@ import {PeopleService} from '../service/people.service';
import {PeopleProfileComponent} from './people-profile/people-profile.component';
import {BrokerProfileComponent} from './broker-profile/broker-profile.component';
import {UserProfileComponent} from './user-profile/user-profile.component';
import {ActivatedRoute} from '@angular/router';
import {BrokerModel} from '../models/broker.model';
import {PeopleModel} from '../models/people.model';
import {UserExtraModel} from '../models/user-extra.model';

@Component({
selector: 'app-profile',
@@ -17,19 +21,66 @@ export class ProfileComponent implements OnInit {
@ViewChild('userProfile', {static: true}) up: UserProfileComponent;
@ViewChild('brokerProfile', {static: true}) bp: BrokerProfileComponent;

public role = 'client';
public role = 'unknown';
public UserExtra: UserExtraModel = UserExtraModel.EmptyNew();
public People: PeopleModel = PeopleModel.EmptyNew();
public broker: BrokerModel = BrokerModel.EmptyNew();

constructor(private auth: AuthService, private ps: PeopleService) { }
public isValidPeople = true;
public isValidBroker = true;

constructor(private auth: AuthService, private ps: PeopleService, private actRoute: ActivatedRoute) { }

ngOnInit(): void {
this.role = this.auth.loggedIn.role;
this.PeopleId = this.auth.loggedIn.User.Id;
console.log('profile people id', this.PeopleId);
const id = this.actRoute.snapshot.params.id;
if ( id !== undefined && id.length > 10 ) {
this.PeopleId = id;
}

if (this.auth.isAdmin() && this.PeopleId !== '' && !this.auth.isCurrentUser(this.PeopleId)) { // admin editing someone else
this.loadOtherPeople();
this.loadOtherPeopleExtra();

}else { // edit himself
this.role = this.auth.loggedIn.role;
this.PeopleId = this.auth.loggedIn.User.Id;
}
}

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
);
}
);
}

private loadOtherPeopleExtra(): void {
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);
}
}
);
}

public showPeople(): boolean {
return true; // always true
return this.isValidPeople; // always true
}

public showUser(): boolean {
@@ -49,15 +100,26 @@ export class ProfileComponent implements OnInit {
}

public isAdmin(): boolean {
return this.auth.isAdmin();
if ( this.auth.isCurrentUser(this.PeopleId) ){
return this.auth.isAdmin();
}else{
return this.role === 'admin';
}
}

public isBroker(): boolean {
return this.auth.isBroker();
if ( this.auth.isCurrentUser(this.PeopleId) ) {
return this.auth.isBroker();
}else{
return this.role === 'broker';
}
}

public isUser(): boolean {
return this.auth.isUser();
if ( this.auth.isCurrentUser(this.PeopleId) ) {
return this.auth.isUser();
}else{
return this.role === 'user';
}
}

}

+ 1
- 1
src/app/profile/user-profile/user-profile.component.html Voir le fichier

@@ -15,7 +15,7 @@
<kendo-formfield *ngIf="showAdmin ">
<label class="k-label">Allow Login &nbsp;
<input type="checkbox" name="enabled" kendoCheckBox
[(ngModel)]="UserExtra.Enabled" [disabled]="currentUserIsAdmin()"/>
[(ngModel)]="UserExtra.Enabled" [disabled]="isCurrentUser"/>
</label>
</kendo-formfield>
<div class="vertical-spacer"></div>

+ 21
- 6
src/app/profile/user-profile/user-profile.component.ts Voir le fichier

@@ -4,6 +4,8 @@ import {NgForm} 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';

@Component({
selector: 'app-user-profile',
@@ -12,16 +14,29 @@ import {MessageBoxComponent} from '../../message-box/message-box.component';
})
export class UserProfileComponent implements OnInit {
@Input() public PeopleId = '';
@Input() public showAdmin: false;

public UserExtra: UserExtraModel = UserExtraModel.EmptyNew();
@Input() public UserExtra: UserExtraModel = UserExtraModel.EmptyNew();
@ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent;

constructor(private auth: AuthService, private http: HttpClient) { }
public showAdmin = false;
public isCurrentUser = false;
constructor(private auth: AuthService, private http: HttpClient, private ps: PeopleService) { }

ngOnInit(): void {
this.PeopleId = this.auth.loggedIn.User.Id;
this.UserExtra = this.auth.loggedIn.UserExtra;
this.showAdmin = this.auth.isAdmin();
this.isCurrentUser = this.auth.isCurrentUser(this.PeopleId);
if (this.auth.isAdmin() && !this.auth.isCurrentUser(this.PeopleId)) {
// 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);
}
);
}
}else{
this.PeopleId = this.auth.loggedIn.User.Id;
this.UserExtra = this.auth.loggedIn.UserExtra;
}
}

public save(userForm: NgForm): void {

+ 4
- 0
src/app/service/auth.service.ts Voir le fichier

@@ -149,4 +149,8 @@ export class AuthService {
public isUser(): boolean {
return this.loggedIn.login === true;
}

public isCurrentUser(id: string): boolean {
return this.loggedIn.login === true && this.loggedIn.User !== undefined && this.loggedIn.User.Id === id;
}
}

+ 4
- 0
src/app/service/people.service.ts Voir le fichier

@@ -6,6 +6,7 @@ import {PeopleModel} from '../models/people.model';
import {BrokerModel} from '../models/broker.model';
import {LoanModel} from '../models/loan.model';
import {ChangePassword} from '../models/change-password.model';
import {UserExtraModel} from '../models/user-extra.model';

@Injectable({providedIn: 'root'})
export class PeopleService {
@@ -14,6 +15,9 @@ export class PeopleService {
public getPeopleById(id: string): Observable<PeopleModel> {
return this.http.get<PeopleModel>(this.auth.getUrl('people/' + id));
}
public getPeopleExtraById(id: string): Observable<UserExtraModel> {
return this.http.get<UserExtraModel>(this.auth.getUrl('people-extra/' + id));
}

public getPeopleList(filter: string): Observable<{Count: number, List: PeopleModel[]}> {
const params = new HttpParams().set('filter', filter);

Chargement…
Annuler
Enregistrer