MOBILE-3947 user: Fix user types on user-avatar
parent
e40a4f13bb
commit
4ebec029ba
|
@ -40,7 +40,7 @@
|
||||||
<ion-item [attr.button]="isSiteClickable(isCurrentSite) ? true : null" (click)="siteClicked($event, site, isCurrentSite)"
|
<ion-item [attr.button]="isSiteClickable(isCurrentSite) ? true : null" (click)="siteClicked($event, site, isCurrentSite)"
|
||||||
[attr.detail]="isSiteClickable(isCurrentSite) ? 'true' : 'false'" [class.item-current]="isCurrentSite">
|
[attr.detail]="isSiteClickable(isCurrentSite) ? 'true' : 'false'" [class.item-current]="isCurrentSite">
|
||||||
|
|
||||||
<core-user-avatar [user]="site" slot="start" [linkProfile]="false" [siteId]="site.id"></core-user-avatar>
|
<core-user-avatar [site]="site" slot="start" [linkProfile]="false" [siteId]="site.id"></core-user-avatar>
|
||||||
|
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{site.fullname}}</p>
|
<p class="item-heading">{{site.fullname}}</p>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core';
|
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core';
|
||||||
|
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSiteBasicInfo, CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { USER_PROFILE_PICTURE_UPDATED, CoreUserBasicData } from '@features/user/services/user';
|
import { USER_PROFILE_PICTURE_UPDATED, CoreUserBasicData } from '@features/user/services/user';
|
||||||
|
@ -22,6 +22,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreNetwork } from '@services/network';
|
import { CoreNetwork } from '@services/network';
|
||||||
import { CoreUserHelper } from '@features/user/services/user-helper';
|
import { CoreUserHelper } from '@features/user/services/user-helper';
|
||||||
import { CoreUrlUtils } from '@services/utils/url';
|
import { CoreUrlUtils } from '@services/utils/url';
|
||||||
|
import { CoreSiteInfo } from '@classes/site';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to display a "user avatar".
|
* Component to display a "user avatar".
|
||||||
|
@ -35,7 +36,8 @@ import { CoreUrlUtils } from '@services/utils/url';
|
||||||
})
|
})
|
||||||
export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
|
export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
|
|
||||||
@Input() user?: CoreUserWithAvatar;
|
@Input() user?: CoreUserWithAvatar; // @todo Fix the accepted type and restrict it a bit.
|
||||||
|
@Input() site?: CoreSiteBasicInfo | CoreSiteInfo; // Site info contains user info.
|
||||||
// The following params will override the ones in user object.
|
// The following params will override the ones in user object.
|
||||||
@Input() profileUrl?: string;
|
@Input() profileUrl?: string;
|
||||||
@Input() linkProfile = true; // Avoid linking to the profile if wanted.
|
@Input() linkProfile = true; // Avoid linking to the profile if wanted.
|
||||||
|
@ -71,8 +73,23 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
async ngOnInit(): Promise<void> {
|
||||||
this.siteId = this.siteId || CoreSites.getCurrentSiteId();
|
this.siteId = this.siteId ?? (this.site && 'id' in this.site
|
||||||
|
? this.site.id
|
||||||
|
: CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
|
if (this.site && !this.user) {
|
||||||
|
this.user = {
|
||||||
|
id: ('userid' in this.site
|
||||||
|
? this.site.userid
|
||||||
|
: this.site.userId)
|
||||||
|
?? (await CoreSites.getSite(this.siteId)).getUserId(),
|
||||||
|
fullname: this.site.fullname ?? '',
|
||||||
|
firstname: this.site.firstname ?? '',
|
||||||
|
lastname: this.site.lastname ?? '',
|
||||||
|
userpictureurl: this.site.userpictureurl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.setFields();
|
this.setFields();
|
||||||
}
|
}
|
||||||
|
@ -189,4 +206,6 @@ export type CoreUserWithAvatar = CoreUserBasicData & {
|
||||||
isonline?: boolean;
|
isonline?: boolean;
|
||||||
courseid?: number;
|
courseid?: number;
|
||||||
lastaccess?: number;
|
lastaccess?: number;
|
||||||
|
firstname?: string; // The first name(s) of the user.
|
||||||
|
lastname?: string; // The family name of the user.
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
</ion-label>
|
</ion-label>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item *ngFor="let site of sites" (click)="siteClicked(site.id)" [detail]="false" button>
|
<ion-item *ngFor="let site of sites" (click)="siteClicked(site.id)" [detail]="false" button>
|
||||||
<core-user-avatar [user]="site" slot="start" [linkProfile]="false"></core-user-avatar>
|
<core-user-avatar [site]="site" slot="start" [linkProfile]="false"></core-user-avatar>
|
||||||
|
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{site.fullname}}</p>
|
<p class="item-heading">{{site.fullname}}</p>
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
<div class="core-login-user">
|
<div class="core-login-user">
|
||||||
<!-- Show user avatar. -->
|
<!-- Show user avatar. -->
|
||||||
<core-user-avatar class="large-avatar" *ngIf="showUserAvatar" [user]="siteInfo" [linkProfile]="false"
|
<core-user-avatar class="large-avatar" *ngIf="showUserAvatar" [site]="siteInfo" [linkProfile]="false"
|
||||||
[siteId]="siteId"></core-user-avatar>
|
[siteId]="siteId"></core-user-avatar>
|
||||||
<p *ngIf="siteInfo?.fullname" class="core-login-fullname">
|
<p *ngIf="siteInfo?.fullname" class="core-login-fullname">
|
||||||
<core-format-text [text]="siteInfo?.fullname" [filter]="false"></core-format-text>
|
<core-format-text [text]="siteInfo?.fullname" [filter]="false"></core-format-text>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<core-user-avatar *ngIf="(alwaysShow || isMainScreen) && siteInfo" [user]="siteInfo" class="core-bar-button-image clickable"
|
<core-user-avatar *ngIf="(alwaysShow || isMainScreen) && siteInfo" [site]="siteInfo" class="core-bar-button-image clickable"
|
||||||
[linkProfile]="false" (ariaButtonClick)="openUserMenu($event)" [userTour]="userTour"
|
[linkProfile]="false" (ariaButtonClick)="openUserMenu($event)" [userTour]="userTour"
|
||||||
[attr.aria-label]="'core.user.useraccount' | translate">
|
[attr.aria-label]="'core.user.useraccount' | translate">
|
||||||
</core-user-avatar>
|
</core-user-avatar>
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
<ion-item button class="core-usermenu-handler ion-text-wrap" *ngIf="siteInfo" lines="full" (click)="openUserProfile($event)"
|
<ion-item button class="core-usermenu-handler ion-text-wrap" *ngIf="siteInfo" lines="full" (click)="openUserProfile($event)"
|
||||||
[detail]="true" [attr.aria-label]="'core.user.profile' | translate">
|
[detail]="true" [attr.aria-label]="'core.user.profile' | translate">
|
||||||
<core-user-avatar [user]="siteInfo" [userId]="siteInfo.userid" [linkProfile]="false" slot="start"></core-user-avatar>
|
<core-user-avatar [site]="siteInfo" [userId]="siteInfo.userid" [linkProfile]="false" slot="start"></core-user-avatar>
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<p class="item-heading">{{ siteInfo.fullname }}</p>
|
<p class="item-heading">{{ siteInfo.fullname }}</p>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
|
|
|
@ -1253,6 +1253,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
const basicInfo: CoreSiteBasicInfo = {
|
const basicInfo: CoreSiteBasicInfo = {
|
||||||
id: site.id,
|
id: site.id,
|
||||||
|
userId: siteInfo?.userid,
|
||||||
siteUrl: site.siteUrl,
|
siteUrl: site.siteUrl,
|
||||||
siteUrlWithoutProtocol: site.siteUrl.replace(/^https?:\/\//, '').toLowerCase(),
|
siteUrlWithoutProtocol: site.siteUrl.replace(/^https?:\/\//, '').toLowerCase(),
|
||||||
fullname: siteInfo?.fullname,
|
fullname: siteInfo?.fullname,
|
||||||
|
@ -2148,6 +2149,7 @@ export type CoreSiteUserTokenResponse = {
|
||||||
*/
|
*/
|
||||||
export type CoreSiteBasicInfo = {
|
export type CoreSiteBasicInfo = {
|
||||||
id: string; // Site ID.
|
id: string; // Site ID.
|
||||||
|
userId?: number; // User ID.
|
||||||
siteUrl: string; // Site URL.
|
siteUrl: string; // Site URL.
|
||||||
siteUrlWithoutProtocol: string; // Site URL without protocol.
|
siteUrlWithoutProtocol: string; // Site URL without protocol.
|
||||||
fullname?: string; // User's full name.
|
fullname?: string; // User's full name.
|
||||||
|
|
Loading…
Reference in New Issue