Skip to content

Commit d7d07f0

Browse files
paulbertlmmrssa
authored andcommitted
Show child user profile (fixes #2890) (#2894)
1 parent ab5e458 commit d7d07f0

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/app/users/users-profile/users-profile.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<span>{{userDetail.name}}</span>
1010
<mat-icon class="margin-lr-5" *ngIf="userDetail.gender" svgIcon="{{userDetail.gender}}"></mat-icon>
1111
<span class="toolbar-fill"></span>
12-
<button mat-raised-button color="accent" class="margin-lr-3" *ngIf="user.name === urlName || user.isUserAdmin" i18n [routerLink]="['../../update/', urlName]"><mat-icon>mode_edit</mat-icon><span>Edit Profile</span></button>
12+
<button mat-raised-button color="accent" class="margin-lr-3" *ngIf="user.name === urlName || (user.isUserAdmin && editable)" i18n [routerLink]="['../../update/', urlName]"><mat-icon>mode_edit</mat-icon><span>Edit Profile</span></button>
1313
<a mat-raised-button color="accent" class="margin-lr-3" *ngIf="user.name === urlName" i18n [planetChangePassword]="userDetail">Change password</a>
1414
</mat-toolbar>
1515
<div class="view-container">

src/app/users/users-profile/users-profile.component.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class UsersProfileComponent implements OnInit {
2424
imageSrc = '';
2525
urlPrefix = environment.couchAddress + '/' + this.dbName + '/';
2626
urlName = '';
27+
planetCode: string | null = null;
28+
editable = false;
2729

2830
constructor(
2931
private couchService: CouchService,
@@ -34,19 +36,18 @@ export class UsersProfileComponent implements OnInit {
3436

3537
ngOnInit() {
3638
this.user = this.userService.get();
37-
38-
this.route.paramMap.pipe(
39-
switchMap((params: ParamMap) =>
40-
of(params.get('name'))
41-
)
42-
).subscribe((urlName) => {
43-
this.urlName = urlName;
39+
this.route.paramMap.subscribe((params: ParamMap) => {
40+
this.urlName = params.get('name');
41+
this.planetCode = params.get('planet');
4442
this.profileView();
4543
});
4644
}
4745

4846
profileView() {
49-
this.couchService.get(this.dbName + '/org.couchdb.user:' + this.urlName).subscribe((response) => {
47+
const dbName = this.planetCode === null ? this.dbName : 'child_users';
48+
const userId = this.planetCode === null ? 'org.couchdb.user:' + this.urlName : this.urlName + '@' + this.planetCode;
49+
this.editable = userId.indexOf('@') === -1;
50+
this.couchService.get(dbName + '/' + userId).subscribe((response) => {
5051
const { derived_key, iterations, password_scheme, salt, ...userDetail } = response;
5152
this.userDetail = userDetail;
5253
if (response['_attachments']) {

src/app/users/users.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
<mat-header-cell *matHeaderCellDef i18n>Profile Image</mat-header-cell>
6767
<mat-cell *matCellDef="let element">
6868
<div *ngIf="element.imageSrc; else noImage">
69-
<img class="profile-image cursor-pointer" [src]="element.imageSrc" routerLink="profile/{{element.doc.name}}">
69+
<img class="profile-image cursor-pointer" [src]="element.imageSrc" (click)="gotoProfileView(element.doc.name)">
7070
</div>
7171
<ng-template #noImage>
72-
<img class="profile-image cursor-pointer" src="assets/avatar.png" routerLink="profile/{{element.doc.name}}">
72+
<img class="profile-image cursor-pointer" src="assets/avatar.png" (click)="gotoProfileView(element.doc.name)">
7373
</ng-template>
7474
</mat-cell>
7575
</ng-container>
@@ -117,7 +117,7 @@
117117
(click)="setRoles(element.doc, element.doc.isUserAdmin ? element.doc.oldRoles : ['manager'])"
118118
mat-raised-button color="primary" i18n>{+element.doc.isUserAdmin, select, 1 {Demote} 0 {Promote}}</a>
119119
</span>
120-
<a routerLink="profile/{{element.doc.name}}" mat-raised-button color="primary" i18n>
120+
<a (click)="gotoProfileView(element.doc.name)" mat-raised-button color="primary" i18n>
121121
<mat-icon>folder_open</mat-icon>View Profile
122122
</a>
123123
</mat-cell>

src/app/users/users.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class UsersComponent implements OnInit, OnDestroy, AfterViewInit {
3737
allUsers = new MatTableDataSource();
3838
message = '';
3939
searchValue = '';
40-
selectedChild: any;
40+
selectedChild: any = {};
4141
filterType = 'local';
4242
filter: any;
4343
planetType = '';
@@ -307,4 +307,9 @@ export class UsersComponent implements OnInit, OnDestroy, AfterViewInit {
307307
return loginActivities.filter((logItem: any) => logItem.user === user.name).length;
308308
}
309309

310+
gotoProfileView(userName: string) {
311+
const optParams = this.selectedChild.code ? { planet: this.selectedChild.code } : {};
312+
this.router.navigate([ 'profile', userName, optParams ], { relativeTo: this.route });
313+
}
314+
310315
}

0 commit comments

Comments
 (0)