Selaa lähdekoodia

profile consolidated.

tags/2.037
Patrick Sun 4 vuotta sitten
vanhempi
commit
9f2acb0781
12 muutettua tiedostoa jossa 149 lisäystä ja 29 poistoa
  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 Näytä tiedosto

{path : 'list-all-people', component: LenderUploadsComponent, canActivate: [AuthGuard] }, {path : 'list-all-people', component: LenderUploadsComponent, canActivate: [AuthGuard] },
{path : 'people-add', component: PeopleAddComponent, canActivate: [AuthGuard] }, {path : 'people-add', component: PeopleAddComponent, canActivate: [AuthGuard] },
{path : 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, {path : 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
{path : 'profile/:id', component: ProfileComponent, canActivate: [AuthGuard] },
{path : 'e403', component: E403Component, }, {path : 'e403', component: E403Component, },
]; ];



+ 2
- 0
src/app/models/user-extra.model.ts Näytä tiedosto

public Organization: string; public Organization: string;
public Enabled: boolean; public Enabled: boolean;
public Login: string; public Login: string;
public Role?: string;


constructor(payload: Partial<UserExtraModel>) { constructor(payload: Partial<UserExtraModel>) {
Object.assign(this, payload); Object.assign(this, payload);
rt.Organization = ''; rt.Organization = '';
rt.Enabled = false; rt.Enabled = false;
rt.Login = ''; rt.Login = '';
rt.Role = '';
return rt; return rt;
} }
} }

+ 8
- 2
src/app/profile/broker-profile/broker-profile.component.ts Näytä tiedosto

}) })
export class BrokerProfileComponent implements OnInit { export class BrokerProfileComponent implements OnInit {
@Input() public PeopleId = ''; @Input() public PeopleId = '';
@Input() public showAdmin: false;
@Input() public broker: BrokerModel = BrokerModel.EmptyNew(); @Input() public broker: BrokerModel = BrokerModel.EmptyNew();
@ViewChild('messageBox', {static: true})msgBox: MessageBoxComponent; @ViewChild('messageBox', {static: true})msgBox: MessageBoxComponent;
public showAdmin = false;


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


ngOnInit(): void { 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{ public save(brokerForm: NgForm): void{

+ 1
- 1
src/app/profile/change-password/change-password.component.html Näytä tiedosto



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

+ 10
- 2
src/app/profile/change-password/change-password.component.ts Näytä tiedosto

@ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent; @ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent;


public changePassword = false; public changePassword = false;
public isAdmin = false;


public ChangePassForm: FormGroup = new FormGroup({ public ChangePassForm: FormGroup = new FormGroup({
OldPassword: new FormControl(), OldPassword: new FormControl(),
constructor(private auth: AuthService, private ps: PeopleService) { } constructor(private auth: AuthService, private ps: PeopleService) { }


ngOnInit(): void { ngOnInit(): void {
if (this.auth.isAdmin() && this.PeopleId !== '' && !this.auth.isCurrentUser(this.PeopleId)) {
this.isAdmin = this.auth.isAdmin();
}
} }
public hidePass(): void{ public hidePass(): void{
if ( this.changePassword ) { if ( this.changePassword ) {
} }


public savePassword(): void{ public savePassword(): void{
this.ps.savePassword('0', this.ChangePassForm.value).subscribe(
this.ps.savePassword(this.PeopleId, this.ChangePassForm.value).subscribe(
() => { () => {
this.changePassword = false; this.changePassword = false;
this.msgBox.Show('Password Changed'); this.msgBox.Show('Password Changed');
} }


public canChangePassword(): boolean { 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 Näytä tiedosto

}) })
export class PeopleProfileComponent implements OnInit { export class PeopleProfileComponent implements OnInit {
@Input() PeopleId = ''; @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 = { public myRestrictions: FileRestrictions = {
allowedExtensions: ['.jpg', '.png', '.jpeg'], allowedExtensions: ['.jpg', '.png', '.jpeg'],
maxFileSize: 2194304 maxFileSize: 2194304
constructor(private auth: AuthService, private ps: PeopleService) { } constructor(private auth: AuthService, private ps: PeopleService) { }


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



+ 3
- 3
src/app/profile/profile.component.html Näytä tiedosto

<div class="container settings"> <div class="container settings">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-sm-12"> <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> <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> <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> <div *ngIf="showAdmin()" class="vertical-spacer"><hr></div>
<app-admin-profile #adminProfile *ngIf="showAdmin()" [PeopleId]="PeopleId" ></app-admin-profile> <app-admin-profile #adminProfile *ngIf="showAdmin()" [PeopleId]="PeopleId" ></app-admin-profile>
<div *ngIf="showPassword()" class="vertical-spacer" ><hr></div> <div *ngIf="showPassword()" class="vertical-spacer" ><hr></div>

+ 72
- 10
src/app/profile/profile.component.ts Näytä tiedosto

import {PeopleProfileComponent} from './people-profile/people-profile.component'; import {PeopleProfileComponent} from './people-profile/people-profile.component';
import {BrokerProfileComponent} from './broker-profile/broker-profile.component'; import {BrokerProfileComponent} from './broker-profile/broker-profile.component';
import {UserProfileComponent} from './user-profile/user-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({ @Component({
selector: 'app-profile', selector: 'app-profile',
@ViewChild('userProfile', {static: true}) up: UserProfileComponent; @ViewChild('userProfile', {static: true}) up: UserProfileComponent;
@ViewChild('brokerProfile', {static: true}) bp: BrokerProfileComponent; @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 { 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 { public showPeople(): boolean {
return true; // always true
return this.isValidPeople; // always true
} }


public showUser(): boolean { public showUser(): boolean {
} }


public isAdmin(): boolean { 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 { 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 { 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 Näytä tiedosto

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

+ 21
- 6
src/app/profile/user-profile/user-profile.component.ts Näytä tiedosto

import {AuthService} from '../../service/auth.service'; import {AuthService} from '../../service/auth.service';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {MessageBoxComponent} from '../../message-box/message-box.component'; import {MessageBoxComponent} from '../../message-box/message-box.component';
import {BrokerModel} from '../../models/broker.model';
import {PeopleService} from '../../service/people.service';


@Component({ @Component({
selector: 'app-user-profile', selector: 'app-user-profile',
}) })
export class UserProfileComponent implements OnInit { export class UserProfileComponent implements OnInit {
@Input() public PeopleId = ''; @Input() public PeopleId = '';
@Input() public showAdmin: false;

public UserExtra: UserExtraModel = UserExtraModel.EmptyNew();
@Input() public UserExtra: UserExtraModel = UserExtraModel.EmptyNew();
@ViewChild('messageBox', {static: true}) msgBox: MessageBoxComponent; @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 { 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 { public save(userForm: NgForm): void {

+ 4
- 0
src/app/service/auth.service.ts Näytä tiedosto

public isUser(): boolean { public isUser(): boolean {
return this.loggedIn.login === true; 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 Näytä tiedosto

import {BrokerModel} from '../models/broker.model'; import {BrokerModel} from '../models/broker.model';
import {LoanModel} from '../models/loan.model'; import {LoanModel} from '../models/loan.model';
import {ChangePassword} from '../models/change-password.model'; import {ChangePassword} from '../models/change-password.model';
import {UserExtraModel} from '../models/user-extra.model';


@Injectable({providedIn: 'root'}) @Injectable({providedIn: 'root'})
export class PeopleService { export class PeopleService {
public getPeopleById(id: string): Observable<PeopleModel> { public getPeopleById(id: string): Observable<PeopleModel> {
return this.http.get<PeopleModel>(this.auth.getUrl('people/' + id)); 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[]}> { public getPeopleList(filter: string): Observable<{Count: number, List: PeopleModel[]}> {
const params = new HttpParams().set('filter', filter); const params = new HttpParams().set('filter', filter);

Loading…
Peruuta
Tallenna