@@ -67,38 +67,53 @@ export class DashboardComponent
6767 extends SafeUnsubscribeComponent
6868 implements OnInit , OnDestroy
6969{
70+ /** Change step event ( in workflow ) */
71+ @Output ( ) changeStep : EventEmitter < number > = new EventEmitter ( ) ;
72+ /** Widget grid reference */
73+ @ViewChild ( SafeWidgetGridComponent )
74+ widgetGridComponent ! : SafeWidgetGridComponent ;
75+ /** Is dashboard in fullscreen mode */
7076 public isFullScreen = false ;
71- // === DATA ===
77+ /** Dashboard id */
7278 public id = '' ;
79+ /** Application id */
7380 public applicationId ?: string ;
81+ /** Is dashboard loading */
7482 public loading = true ;
75- public tiles : any [ ] = [ ] ;
83+ /** List of widgets */
84+ public widgets : any [ ] = [ ] ;
85+ /** Current dashboard */
7686 public dashboard ?: Dashboard ;
87+ /** Show dashboard filter */
7788 public showFilter ! : boolean ;
78-
79- // === GRID ===
80- private generatedTiles = 0 ;
81-
82- // === DASHBOARD NAME EDITION ===
89+ /** User can update dashboard */
8390 public canUpdate = false ;
91+ /** Dashboard name edition is active */
8492 public formActive = false ;
85-
86- // === STEP CHANGE FOR WORKFLOW ===
87- @Output ( ) changeStep : EventEmitter < number > = new EventEmitter ( ) ;
88-
89- // === DUP APP SELECTION ===
93+ /** Show application menu */
9094 public showAppMenu = false ;
95+ /** List of available applications */
9196 public applications : Application [ ] = [ ] ;
92-
93- @ViewChild ( SafeWidgetGridComponent )
94- widgetGridComponent ! : SafeWidgetGridComponent ;
95-
96- // === CONTEXT ===
97+ /** Contextual reference data elements */
9798 public refDataElements : any [ ] = [ ] ;
99+ /** Contextual records query */
98100 public recordsQuery ! : QueryRef < GetResourceRecordsQueryResponse > ;
101+ /** Contextual template id */
99102 public contextId = new FormControl < string | number | null > ( null ) ;
103+ /** Field of contextual reference data */
100104 public refDataValueField = '' ;
105+ /** Contextual record */
101106 public contextRecord : Record | null = null ;
107+ /** Configured dashboard quick actions */
108+ public buttonActions : ButtonActionT [ ] = [ ] ;
109+
110+ /** @returns get newest widget id from existing ids */
111+ get newestId ( ) : number {
112+ const widgets = this . widgets ?. slice ( ) || [ ] ;
113+ return widgets . length === 0
114+ ? 0
115+ : Math . max ( ...widgets . map ( ( x : any ) => x . id ) ) + 1 ;
116+ }
102117
103118 /** @returns type of context element */
104119 get contextType ( ) {
@@ -109,10 +124,6 @@ export class DashboardComponent
109124 }
110125 }
111126
112- // === BUTTON ACTIONS ===
113- public buttonActions : ButtonActionT [ ] = [ ] ;
114-
115- // === ROUTE ===
116127 /** @returns is dashboard a step or a page */
117128 get isStep ( ) : boolean {
118129 return this . router . url . includes ( '/workflow/' ) ;
@@ -136,7 +147,6 @@ export class DashboardComponent
136147 * @param refDataService Shared reference data service
137148 * @param renderer Angular renderer
138149 * @param elementRef Angular element ref
139- * @param translate Translate service
140150 * @param layoutService Shared layout service
141151 */
142152 constructor (
@@ -155,7 +165,6 @@ export class DashboardComponent
155165 private refDataService : SafeReferenceDataService ,
156166 private renderer : Renderer2 ,
157167 private elementRef : ElementRef ,
158- private translate : TranslateService ,
159168 private layoutService : SafeLayoutService
160169 ) {
161170 super ( ) ;
@@ -308,13 +317,9 @@ export class DashboardComponent
308317 : this . dashboard ?. step ?. canUpdate ) || false ;
309318
310319 this . dashboardService . openDashboard ( this . dashboard ) ;
311- this . tiles = this . dashboard . structure
320+ this . widgets = this . dashboard . structure
312321 ? [ ...this . dashboard . structure . filter ( ( x : any ) => x !== null ) ]
313322 : [ ] ;
314- this . generatedTiles =
315- this . tiles . length === 0
316- ? 0
317- : Math . max ( ...this . tiles . map ( ( x ) => x && x ?. id ) ) + 1 ;
318323 this . applicationId = this . dashboard . page
319324 ? this . dashboard . page . application ?. id
320325 : this . dashboard . step
@@ -391,14 +396,13 @@ export class DashboardComponent
391396 * @param e add event
392397 */
393398 onAdd ( e : any ) : void {
394- const tile = JSON . parse ( JSON . stringify ( e ) ) ;
395- tile . id = this . generatedTiles ;
396- this . generatedTiles += 1 ;
397- this . tiles = [ ...this . tiles , tile ] ;
399+ const widget = JSON . parse ( JSON . stringify ( e ) ) ;
400+ widget . id = this . newestId ;
401+ this . widgets = [ ...this . widgets , widget ] ;
398402 this . autoSaveChanges ( ) ;
399403 // scroll to the element once it is created
400404 setTimeout ( ( ) => {
401- const el = document . getElementById ( `widget-${ tile . id } ` ) ;
405+ const el = document . getElementById ( `widget-${ widget . id } ` ) ;
402406 el ?. scrollIntoView ( { behavior : 'smooth' } ) ;
403407 } ) ;
404408 }
@@ -410,17 +414,17 @@ export class DashboardComponent
410414 */
411415 onEditTile ( e : any ) : void {
412416 // make sure that we save the default layout.
413- const index = this . tiles . findIndex ( ( v : any ) => v . id === e . id ) ;
414- const options = this . tiles [ index ] ?. settings ?. defaultLayout
417+ const index = this . widgets . findIndex ( ( v : any ) => v . id === e . id ) ;
418+ const options = this . widgets [ index ] ?. settings ?. defaultLayout
415419 ? {
416420 ...e . options ,
417- defaultLayout : this . tiles [ index ] . settings . defaultLayout ,
421+ defaultLayout : this . widgets [ index ] . settings . defaultLayout ,
418422 }
419423 : e . options ;
420424 if ( options ) {
421425 switch ( e . type ) {
422426 case 'display' : {
423- this . tiles = this . tiles . map ( ( x ) => {
427+ this . widgets = this . widgets . map ( ( x ) => {
424428 if ( x . id === e . id ) {
425429 x . defaultCols = options . cols ;
426430 x . defaultRows = options . rows ;
@@ -431,7 +435,7 @@ export class DashboardComponent
431435 break ;
432436 }
433437 case 'data' : {
434- this . tiles = this . tiles . map ( ( x ) => {
438+ this . widgets = this . widgets . map ( ( x ) => {
435439 if ( x . id === e . id ) {
436440 x = { ...x , settings : options } ;
437441 }
@@ -453,7 +457,7 @@ export class DashboardComponent
453457 * @param e delete event
454458 */
455459 onDeleteTile ( e : any ) : void {
456- this . tiles = this . tiles . filter ( ( x ) => x . id !== e . id ) ;
460+ this . widgets = this . widgets . filter ( ( x ) => x . id !== e . id ) ;
457461 this . autoSaveChanges ( ) ;
458462 }
459463
@@ -480,10 +484,10 @@ export class DashboardComponent
480484 */
481485 onMove ( e : any ) : void {
482486 // Duplicates array, some times the arrays is write protected
483- this . tiles = this . tiles . slice ( ) ;
484- [ this . tiles [ e . oldIndex ] , this . tiles [ e . newIndex ] ] = [
485- this . tiles [ e . newIndex ] ,
486- this . tiles [ e . oldIndex ] ,
487+ this . widgets = this . widgets . slice ( ) ;
488+ [ this . widgets [ e . oldIndex ] , this . widgets [ e . newIndex ] ] = [
489+ this . widgets [ e . newIndex ] ,
490+ this . widgets [ e . oldIndex ] ,
487491 ] ;
488492 this . autoSaveChanges ( ) ;
489493 }
@@ -495,7 +499,7 @@ export class DashboardComponent
495499 mutation : EDIT_DASHBOARD ,
496500 variables : {
497501 id : this . id ,
498- structure : this . tiles ,
502+ structure : this . widgets ,
499503 } ,
500504 } )
501505 . subscribe ( {
@@ -523,7 +527,7 @@ export class DashboardComponent
523527 ) ;
524528 this . dashboardService . openDashboard ( {
525529 ...this . dashboard ,
526- structure : this . tiles ,
530+ structure : this . widgets ,
527531 } ) ;
528532 }
529533 } ,
0 commit comments