1- import { getDisplayStateFromUserStatus } from '../../../utils.js' ;
2- import type { UmbUserCollectionContext } from '../../user-collection.context.js' ;
3- import type { UmbUserDetailModel } from '../../../types.js' ;
1+ import { getDisplayStateFromUserStatus , TimeFormatOptions } from '../../../utils.js' ;
2+ import { UmbUserKind } from '../../../utils/index.js' ;
43import { UMB_USER_COLLECTION_CONTEXT } from '../../user-collection.context-token.js' ;
54import { UMB_USER_WORKSPACE_PATH } from '../../../paths.js' ;
6- import { UmbUserKind } from '../../../utils/index.js' ;
7- import { css , html , nothing , customElement , state , repeat , ifDefined } from '@umbraco-cms/backoffice/external/lit' ;
8- import { UmbTextStyles } from '@umbraco-cms/backoffice/style' ;
5+ import type { UmbUserCollectionContext } from '../../user-collection.context.js' ;
6+ import type { UmbUserDetailModel } from '../../../types.js' ;
7+ import {
8+ css ,
9+ customElement ,
10+ html ,
11+ ifDefined ,
12+ nothing ,
13+ repeat ,
14+ state ,
15+ when ,
16+ } from '@umbraco-cms/backoffice/external/lit' ;
917import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
18+ import { UmbTextStyles } from '@umbraco-cms/backoffice/style' ;
19+ import { UmbUserGroupCollectionRepository } from '@umbraco-cms/backoffice/user-group' ;
1020import { UserStateModel } from '@umbraco-cms/backoffice/external/backend-api' ;
1121import type { UmbUserGroupDetailModel } from '@umbraco-cms/backoffice/user-group' ;
12- import { UmbUserGroupCollectionRepository } from '@umbraco-cms/backoffice/user-group' ;
1322
1423@customElement ( 'umb-user-grid-collection-view' )
1524export class UmbUserGridCollectionViewElement extends UmbLitElement {
@@ -23,6 +32,7 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
2332 private _loading = false ;
2433
2534 #userGroups: Array < UmbUserGroupDetailModel > = [ ] ;
35+
2636 #collectionContext?: UmbUserCollectionContext ;
2737
2838 // TODO: we need to use the item repository here
@@ -33,11 +43,13 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
3343
3444 this . consumeContext ( UMB_USER_COLLECTION_CONTEXT , ( instance ) => {
3545 this . #collectionContext = instance ;
46+
3647 this . observe (
3748 this . #collectionContext. selection . selection ,
3849 ( selection ) => ( this . _selection = selection ) ,
3950 'umbCollectionSelectionObserver' ,
4051 ) ;
52+
4153 this . observe ( this . #collectionContext. items , ( items ) => ( this . _users = items ) , 'umbCollectionItemsObserver' ) ;
4254 } ) ;
4355
@@ -48,7 +60,9 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
4860 this . _loading = true ;
4961
5062 const { data } = await this . #userGroupCollectionRepository. requestCollection ( ) ;
63+
5164 this . #userGroups = data ?. items ?? [ ] ;
65+
5266 this . _loading = false ;
5367 }
5468
@@ -74,12 +88,10 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
7488 }
7589
7690 #renderUserCard( user : UmbUserDetailModel ) {
77- const href = UMB_USER_WORKSPACE_PATH + '/edit/' + user . unique ;
78-
7991 return html `
8092 <uui- card- user
8193 .name = ${ user . name ?? this . localize . term ( 'general_unnamed' ) }
82- href= ${ href }
94+ href= " ${ UMB_USER_WORKSPACE_PATH } /edit/ ${ user . unique } "
8395 selectable
8496 ?select- only = ${ this . _selection . length > 0 }
8597 ?selected= ${ this . #collectionContext?. selection . isSelected ( user . unique ) }
@@ -90,8 +102,7 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
90102 slot= "avatar"
91103 .name = ${ user . name }
92104 .kind = ${ user . kind }
93- .imgUrls = ${ user . avatarUrls }
94- style= "font- size: 1.6rem;"> </ umb- user- avatar>
105+ .imgUrls = ${ user . avatarUrls } > </ umb- user- avatar>
95106 </ uui- card- user>
96107 ` ;
97108 }
@@ -102,13 +113,11 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
102113 }
103114
104115 const statusLook = user . state ? getDisplayStateFromUserStatus ( user . state ) : undefined ;
105- return html `<uui- tag
106- slot= "tag"
107- size = "s"
108- look= "${ ifDefined ( statusLook ?. look ) } "
109- color = "${ ifDefined ( statusLook ?. color ) } ">
110- <umb- localize key= ${ 'user_' + statusLook ?. key } > </ umb- localize>
111- </ uui- tag> ` ;
116+ return html `
117+ <uui- tag slot= "tag" look = ${ ifDefined ( statusLook ?. look ) } color = ${ ifDefined ( statusLook ?. color ) } >
118+ <umb- localize key= ${ 'user_' + statusLook ?. key } > </ umb- localize>
119+ </ uui- tag>
120+ ` ;
112121 }
113122
114123 #renderUserGroupNames( user : UmbUserDetailModel ) {
@@ -122,17 +131,18 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
122131
123132 #renderUserLoginDate( user : UmbUserDetailModel ) {
124133 if ( user . kind === UmbUserKind . API ) return nothing ;
125-
126- if ( ! user . lastLoginDate ) {
127- return html `<div class= "user-login-time" > ${ `${ user . name } ${ this . localize . term ( 'user_noLogin' ) } ` } </ div> ` ;
128- }
129- const lastLoggedinLocalTime : Date = new Date ( user . lastLoginDate ) ;
130- const formattedTime = lastLoggedinLocalTime . toLocaleTimeString ( [ ] , { hour : '2-digit' , minute : '2-digit' } ) ;
131-
132- return html `<div class= "user-login-time" >
133- <umb- localize key= "user_lastLogin" > </ umb- localize>
134- ${ this . localize . date ( user . lastLoginDate ) } ${ formattedTime }
135- </ div> ` ;
134+ return html `
135+ <div class= "user-login-time" >
136+ ${ when (
137+ user . lastLoginDate ,
138+ ( lastLoginDate ) => html `
139+ <umb- localize key= "user_lastLogin" > Last login </ umb- localize>
140+ <span> ${ this . localize . date ( lastLoginDate , TimeFormatOptions ) } </ span>
141+ ` ,
142+ ( ) => html `<umb- localize key= "user_noLogin" > has not logged in yet </ umb- localize> ` ,
143+ ) }
144+ </ div>
145+ ` ;
136146 }
137147
138148 static override styles = [
@@ -145,26 +155,32 @@ export class UmbUserGridCollectionViewElement extends UmbLitElement {
145155
146156 # user-grid {
147157 display : grid;
148- grid-template-columns : repeat (auto-fill, minmax (250 px , 1fr ));
158+ grid-template-columns : repeat (auto-fill, minmax (280 px , 1fr ));
149159 gap : var (--uui-size-space-4 );
150160 }
151161
152162 uui-card-user {
153163 width : 100% ;
154- height : 180px ;
155164 justify-content : normal;
156165 padding-top : var (--uui-size-space-5 );
166+ flex-direction : column;
167+
168+ umb-user-avatar {
169+ font-size : 1.6rem ;
170+ }
157171 }
158172
159173 .user-login-time {
160- margin-top : auto ;
174+ margin-top : var ( --uui-size-1 ) ;
161175 }
162176 ` ,
163177 ] ;
164178}
165179
166180export default UmbUserGridCollectionViewElement ;
167181
182+ export { UmbUserGridCollectionViewElement as element } ;
183+
168184declare global {
169185 interface HTMLElementTagNameMap {
170186 'umb-user-grid-collection-view' : UmbUserGridCollectionViewElement ;
0 commit comments