@@ -3,13 +3,15 @@ import startCase from 'lodash-es/startCase';
33import { CommonModule } from '@angular/common' ;
44import {
55 Component ,
6+ Injector ,
67 TemplateRef ,
78 booleanAttribute ,
89 computed ,
910 inject ,
1011 input ,
1112 model ,
1213 output ,
14+ runInInjectionContext ,
1315} from '@angular/core' ;
1416import { ReactiveFormsModule } from '@angular/forms' ;
1517import { MatButtonModule } from '@angular/material/button' ;
@@ -20,6 +22,7 @@ import {
2022 ActionsModule ,
2123 Column ,
2224 DialogResponseStatus ,
25+ MenuItem ,
2326 PagedObservableResource ,
2427 SelectFieldModule ,
2528 TableModule ,
@@ -51,52 +54,14 @@ import {
5154export class DomainObjectsTableComponent {
5255 private sidenavInfoService = inject ( SidenavInfoService ) ;
5356 private domainObjectService = inject ( DomainObjectService ) ;
57+ private injector = inject ( Injector ) ;
5458
5559 selectedTypeChange = output < keyof ReflessDomainObject > ( ) ;
5660 resource = input < PagedObservableResource < LimitedVersionedObject , unknown > > ( ) ;
5761 filter = model < string > ( '' ) ;
5862 tableInputsContent = input < TemplateRef < unknown > > ( ) ;
5963 externalFilter = input ( false , { transform : booleanAttribute } ) ;
60- menu = input < Column < LimitedVersionedObject > > (
61- createMenuColumn ( ( d ) => ( {
62- items : [
63- {
64- label : 'Details' ,
65- click : ( ) => {
66- this . sidenavInfoService . toggle ( DomainObjectCardComponent , {
67- ref : d . ref ,
68- version : d . info . version ,
69- } ) ;
70- } ,
71- } ,
72- {
73- label : 'History' ,
74- click : ( ) => {
75- this . domainObjectService . history ( d . ref ) ;
76- } ,
77- } ,
78- {
79- label : 'Edit' ,
80- click : ( ) => {
81- this . domainObjectService . edit ( d . ref ) . next ( ( res ) => {
82- if ( res . status === DialogResponseStatus . Success ) {
83- this . resource ( ) . reload ( ) ;
84- }
85- } ) ;
86- } ,
87- } ,
88- {
89- label : 'Delete' ,
90- click : ( ) => {
91- this . domainObjectService . delete ( d . ref ) . next ( ( ) => {
92- this . resource ( ) . reload ( ) ;
93- } ) ;
94- } ,
95- } ,
96- ] ,
97- } ) ) ,
98- ) ;
99-
64+ menu = input < ( d : LimitedVersionedObject ) => MenuItem [ ] > ( ) ;
10065 columns = computed < Column < LimitedVersionedObject > [ ] > ( ( ) => [
10166 { field : 'id' , cell : ( d ) => ( { value : getReferenceId ( d . ref ) } ) } ,
10267 {
@@ -126,6 +91,46 @@ export class DomainObjectsTableComponent {
12691 description : d . info . changed_by ?. email ,
12792 } ) ,
12893 } ,
129- this . menu ( ) ,
94+ runInInjectionContext ( this . injector , ( ) =>
95+ createMenuColumn ( ( d ) => ( {
96+ items : this . menu ( )
97+ ? this . menu ( ) ( d )
98+ : [
99+ {
100+ label : 'Details' ,
101+ click : ( ) => {
102+ this . sidenavInfoService . toggle ( DomainObjectCardComponent , {
103+ ref : d . ref ,
104+ version : d . info . version ,
105+ } ) ;
106+ } ,
107+ } ,
108+ {
109+ label : 'History' ,
110+ click : ( ) => {
111+ this . domainObjectService . history ( d . ref ) ;
112+ } ,
113+ } ,
114+ {
115+ label : 'Edit' ,
116+ click : ( ) => {
117+ this . domainObjectService . edit ( d . ref ) . next ( ( res ) => {
118+ if ( res . status === DialogResponseStatus . Success ) {
119+ this . resource ( ) . reload ( ) ;
120+ }
121+ } ) ;
122+ } ,
123+ } ,
124+ {
125+ label : 'Delete' ,
126+ click : ( ) => {
127+ this . domainObjectService . delete ( d . ref ) . next ( ( ) => {
128+ this . resource ( ) . reload ( ) ;
129+ } ) ;
130+ } ,
131+ } ,
132+ ] ,
133+ } ) ) ,
134+ ) ,
130135 ] ) ;
131136}
0 commit comments