1
1
import type { ManifestDashboardApp } from '../dashboard-app.extension.js' ;
2
2
import { UMB_DASHBOARD_APP_PICKER_MODAL } from '../app/picker/picker-modal.token.js' ;
3
- import type { UmbDashboardAppDetailModel } from '../app/types.js' ;
4
3
import { UmbTextStyles } from '@umbraco-cms/backoffice/style' ;
5
4
import { css , html , customElement , nothing , ifDefined , state , repeat } from '@umbraco-cms/backoffice/external/lit' ;
6
5
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
7
- import type { UmbExtensionElementInitializer } from '@umbraco-cms/backoffice/extension-api' ;
6
+ import {
7
+ UmbExtensionsElementInitializer ,
8
+ type UmbExtensionElementInitializer ,
9
+ } from '@umbraco-cms/backoffice/extension-api' ;
8
10
import { umbOpenModal } from '@umbraco-cms/backoffice/modal' ;
11
+ import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry' ;
9
12
10
13
@customElement ( 'umb-dashboard' )
11
14
export class UmbDashboardElement extends UmbLitElement {
@@ -17,17 +20,49 @@ export class UmbDashboardElement extends UmbLitElement {
17
20
[ 'large' , 'large' ] ,
18
21
] ) ;
19
22
23
+ #extensionsController?: UmbExtensionsElementInitializer < UmbExtensionManifest , 'dashboardApp' , ManifestDashboardApp > ;
24
+
20
25
@state ( )
21
- _apps : Array < UmbDashboardAppDetailModel > = [ ] ;
26
+ _appElements : Array < any > = [ ] ;
22
27
23
- // TODO: this is just a temp value. We need to look up the item data.
24
28
@state ( )
25
29
_appUniques : Array < string > = [ ] ;
26
30
27
31
constructor ( ) {
28
32
super ( ) ;
29
33
}
30
34
35
+ #observeDashboardApps( ) : void {
36
+ this . #extensionsController?. destroy ( ) ;
37
+ this . #extensionsController = new UmbExtensionsElementInitializer <
38
+ UmbExtensionManifest ,
39
+ 'dashboardApp' ,
40
+ ManifestDashboardApp
41
+ > (
42
+ this ,
43
+ umbExtensionsRegistry ,
44
+ 'dashboardApp' ,
45
+ ( manifest ) => this . _appUniques . includes ( manifest . alias ) ,
46
+ ( extensionControllers ) => {
47
+ this . _appElements = extensionControllers . map ( ( controller ) => {
48
+ if ( controller . component && controller . manifest ) {
49
+ const size = this . #sizeMap. get ( controller . manifest . meta ?. size ) ?? this . #defaultSize;
50
+ const headline = controller . manifest ?. meta ?. headline
51
+ ? this . localize . string ( controller . manifest ?. meta ?. headline )
52
+ : undefined ;
53
+
54
+ return html `<uui- box part= "umb-dashboard-app-${ size } " headline = ${ ifDefined ( headline ) }
55
+ > ${ controller . component } </ uui- box
56
+ > ` ;
57
+ } else {
58
+ return html `<uui- box part= "umb-dashboard-app-${ this . #defaultSize} " > Not Found </ uui- box> ` ;
59
+ }
60
+ } ) ;
61
+ } ,
62
+ undefined , // We can leave the alias to undefined, as we destroy this our selfs.
63
+ ) ;
64
+ }
65
+
31
66
async #openAppPicker( ) {
32
67
const value = await umbOpenModal ( this , UMB_DASHBOARD_APP_PICKER_MODAL , {
33
68
data : {
@@ -39,22 +74,22 @@ export class UmbDashboardElement extends UmbLitElement {
39
74
} ) . catch ( ( ) => undefined ) ;
40
75
41
76
if ( value ) {
42
- //this._apps = value.selection;
43
77
this . _appUniques = value . selection . filter ( ( item ) => item !== null ) as Array < string > ;
78
+ this . #observeDashboardApps( ) ;
44
79
}
45
80
}
46
81
47
82
override render ( ) {
48
83
return html `
49
84
<section id= "content" >
50
85
<uui- butto n look= "placeholder" @click = ${ this . #openAppPicker} > Add </ uui- butto n>
51
- ${ repeat (
52
- this . _appUniques ,
53
- ( unique ) => unique ,
54
- ( unique ) => {
55
- return html ` ${ unique } ` ;
56
- } ,
57
- ) }
86
+ <div class = "grid-container" >
87
+ ${ repeat (
88
+ this . _appElements ,
89
+ ( element ) => element ,
90
+ ( element ) => element ,
91
+ ) }
92
+ < / div >
58
93
<umb- extension- slot
59
94
type= "dashboardApp"
60
95
.renderMethod = ${ this . #extensionSlotRenderMethod}
@@ -83,7 +118,6 @@ export class UmbDashboardElement extends UmbLitElement {
83
118
.grid-container {
84
119
display : grid;
85
120
grid-template-columns : repeat (4 , 1fr );
86
- grid-template-rows : repeat (100 , 225px );
87
121
margin : calc (var (--uui-size-space-3 ) * -1 );
88
122
}
89
123
0 commit comments