|
|
|
@ -8,13 +8,12 @@ |
|
|
|
// tslint:disable: no-pipe-impure
|
|
|
|
// tslint:disable: directive-class-suffix
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Directive, OnDestroy, Pipe, PipeTransform } from '@angular/core'; |
|
|
|
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core'; |
|
|
|
import { ApiUrlConfig, UserDto, UsersProviderService } from '@app/shared/internal'; |
|
|
|
import { Observable, of, Subscription } from 'rxjs'; |
|
|
|
import { map } from 'rxjs/operators'; |
|
|
|
|
|
|
|
@Directive() |
|
|
|
class UserAsyncPipe implements OnDestroy { |
|
|
|
class UserAsyncPipe { |
|
|
|
private lastUserId: string; |
|
|
|
private lastValue: string | undefined = undefined; |
|
|
|
private subscription: Subscription; |
|
|
|
@ -27,7 +26,7 @@ class UserAsyncPipe implements OnDestroy { |
|
|
|
this.lastValue = loading; |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
public destroy() { |
|
|
|
if (this.subscription) { |
|
|
|
this.subscription.unsubscribe(); |
|
|
|
} |
|
|
|
@ -62,11 +61,15 @@ class UserAsyncPipe implements OnDestroy { |
|
|
|
name: 'sqxUserName', |
|
|
|
pure: false |
|
|
|
}) |
|
|
|
export class UserNamePipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
export class UserNamePipe extends UserAsyncPipe implements OnDestroy, PipeTransform { |
|
|
|
constructor(users: UsersProviderService, changeDetector: ChangeDetectorRef) { |
|
|
|
super('Loading...', users, changeDetector); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
super.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
public transform(userId: string, placeholder = 'Me') { |
|
|
|
return super.transformInternal(userId, users => users.getUser(userId, placeholder).pipe(map(u => u.displayName))); |
|
|
|
} |
|
|
|
@ -76,11 +79,15 @@ export class UserNamePipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
name: 'sqxUserNameRef', |
|
|
|
pure: false |
|
|
|
}) |
|
|
|
export class UserNameRefPipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
export class UserNameRefPipe extends UserAsyncPipe implements OnDestroy, PipeTransform { |
|
|
|
constructor(users: UsersProviderService, changeDetector: ChangeDetectorRef) { |
|
|
|
super('Loading...', users, changeDetector); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
super.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
public transform(userId: string, placeholder: string | null = 'Me') { |
|
|
|
return super.transformInternal(userId, users => { |
|
|
|
const { type, id } = split(userId); |
|
|
|
@ -132,13 +139,17 @@ export class UserIdPicturePipe implements PipeTransform { |
|
|
|
name: 'sqxUserPicture', |
|
|
|
pure: false |
|
|
|
}) |
|
|
|
export class UserPicturePipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
export class UserPicturePipe extends UserAsyncPipe implements OnDestroy, PipeTransform { |
|
|
|
constructor(users: UsersProviderService, changeDetector: ChangeDetectorRef, |
|
|
|
private readonly apiUrl: ApiUrlConfig |
|
|
|
) { |
|
|
|
super('', users, changeDetector); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
super.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
public transform(userId: string) { |
|
|
|
return super.transformInternal(userId, users => users.getUser(userId).pipe(map(u => this.apiUrl.buildUrl(`api/users/${u.id}/picture`)))); |
|
|
|
} |
|
|
|
@ -148,13 +159,17 @@ export class UserPicturePipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
name: 'sqxUserPictureRef', |
|
|
|
pure: false |
|
|
|
}) |
|
|
|
export class UserPictureRefPipe extends UserAsyncPipe implements PipeTransform { |
|
|
|
export class UserPictureRefPipe extends UserAsyncPipe implements OnDestroy, PipeTransform { |
|
|
|
constructor(users: UsersProviderService, changeDetector: ChangeDetectorRef, |
|
|
|
private readonly apiUrl: ApiUrlConfig |
|
|
|
) { |
|
|
|
super('', users, changeDetector); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
super.destroy(); |
|
|
|
} |
|
|
|
|
|
|
|
public transform(userId: string) { |
|
|
|
return super.transformInternal(userId, users => { |
|
|
|
const { type, id } = split(userId); |
|
|
|
|