8
8
import { MatTableDataSource } from '@angular/material/table' ;
9
9
10
10
import { ApiService } from '../../services/api.service' ;
11
- import { ListViewer } from '../../models/views' ;
11
+ import { IFrameMode , ListViewer } from '../../models/views' ;
12
12
import { HttpParams , HttpErrorResponse } from '@angular/common/http' ;
13
13
import { MatDialog , MatDialogRef } from '@angular/material/dialog' ;
14
14
import { MatPaginator , PageEvent } from '@angular/material/paginator' ;
@@ -17,6 +17,7 @@ import { IframeModalComponent } from '../iframe-modal/iframe-modal.component';
17
17
import { CustomEncoder } from '../../custom-encode' ;
18
18
import { SearchDialogComponent } from '../../containers/search-dialog/search-dialog.component' ;
19
19
import { ListingDialogComponent } from '../../containers/listing-dialog/listing-dialog.component' ;
20
+ import { ActivatedRoute , Router } from '@angular/router' ;
20
21
21
22
@Component ( {
22
23
selector : 'ng-crud-listing' ,
@@ -52,7 +53,10 @@ export class ListingComponent implements OnInit, AfterViewInit {
52
53
private viewContainerRef : ViewContainerRef ,
53
54
private dialog : MatDialog ,
54
55
private resolver : ComponentFactoryResolver ,
55
- private listingDialogRef : MatDialogRef < ListingDialogComponent > ) { }
56
+ private listingDialogRef : MatDialogRef < ListingDialogComponent > ,
57
+ private router : Router ,
58
+ private activeRoute : ActivatedRoute
59
+ ) { }
56
60
57
61
ngOnInit ( ) {
58
62
if ( this . viewConfig . pagination . enabled ) {
@@ -177,8 +181,8 @@ export class ListingComponent implements OnInit, AfterViewInit {
177
181
this . searchParams = this . searchParams . append ( 'sort[]' , this . viewConfig . metadata . sortBy ) ;
178
182
}
179
183
const foreignKeyMultipleFields = this . viewConfig . metadata . fields . filter ( f => f . keyOnSearch ) . map ( f => f . name ) ;
180
- if ( defaultFilter && defaultFilter . length > 0 ) {
181
- defaultFilter . forEach ( f => {
184
+ if ( defaultFilter && defaultFilter . length > 0 ) {
185
+ defaultFilter . forEach ( f => {
182
186
this . defaultFilters [ f . filter ] = f . value ;
183
187
if ( f . value && f . value !== '' ) {
184
188
if ( f . value . id ) {
@@ -214,17 +218,34 @@ export class ListingComponent implements OnInit, AfterViewInit {
214
218
}
215
219
}
216
220
221
+ openEditView ( id : number ) : void {
222
+ if ( this . viewConfig . iframeMode === IFrameMode . POP_UP ) {
223
+ const src = `${ this . viewConfig . external_link . link } ` + `${ id } /?` + `${ this . viewConfig . external_link . params . join ( '&' ) } ` ;
224
+ this . dialog . open ( IframeModalComponent , {
225
+ height : '95vh' ,
226
+ width : '100vw' ,
227
+ data : {
228
+ 'src' : `${ src } ` ,
229
+ 'title' : this . viewConfig ?. title ,
230
+ 'color' : 'grey'
231
+ }
232
+ } ) ;
233
+ } else {
234
+ this . router . navigate ( [ id ] , { relativeTo : this . activeRoute } ) ;
235
+ }
236
+ }
237
+
217
238
fetch ( ) {
218
239
this . api . fetch ( this . viewConfig . metadata . api , this . searchParams ) . subscribe ( res => {
219
240
let newItems = [ ] ;
220
241
if ( this . viewConfig . pagination . enabled ) {
221
- const keys = this . viewConfig . search . search_key ;
222
- let value = res . results ? res . results [ keys [ 0 ] ] : res [ keys [ 0 ] ] ;
223
- for ( let i = 1 ; i < keys . length ; i ++ ) {
224
- value = value [ keys [ i ] ] ;
225
- }
226
- newItems = value ;
227
- this . resultsCount = res . count ;
242
+ const keys = this . viewConfig . search . search_key ;
243
+ let value = res . results ? res . results [ keys [ 0 ] ] : res [ keys [ 0 ] ] ;
244
+ for ( let i = 1 ; i < keys . length ; i ++ ) {
245
+ value = value [ keys [ i ] ] ;
246
+ }
247
+ newItems = value ;
248
+ this . resultsCount = res . count ;
228
249
} else {
229
250
newItems = res ;
230
251
this . resultsCount = newItems . length ;
@@ -249,7 +270,7 @@ export class ListingComponent implements OnInit, AfterViewInit {
249
270
}
250
271
251
272
addCustomElementColumnsToTemplate ( ) : void {
252
- const customElementField = this . viewConfig . metadata . fields . find ( f => f . type === 'custom_element' ) ;
273
+ const customElementField = this . viewConfig . metadata . fields . find ( f => f . type === 'custom_element' ) ;
253
274
this . customElement ?. changes . subscribe ( element => {
254
275
element . forEach ( ( item , index ) => {
255
276
this . viewContainerRef . clear ( ) ;
0 commit comments