1- import sjson from 'secure-json-parse' ;
2- import {
3- AfterLoad ,
4- BeforeInsert ,
5- BeforeUpdate ,
6- Column ,
7- Entity ,
8- JoinColumn ,
9- ManyToOne ,
10- PrimaryGeneratedColumn ,
11- Relation ,
12- } from 'typeorm' ;
13- import { DashboardWidgetTypeEnum } from '../../../enums/dashboard-widget-type.enum.js' ;
1+ import { Column , Entity , JoinColumn , ManyToOne , PrimaryGeneratedColumn , Relation } from 'typeorm' ;
142import { DashboardEntity } from '../dashboard/dashboard.entity.js' ;
153import { SavedDbQueryEntity } from '../saved-db-query/saved-db-query.entity.js' ;
164
@@ -19,18 +7,6 @@ export class DashboardWidgetEntity {
197 @PrimaryGeneratedColumn ( 'uuid' )
208 id : string ;
219
22- @Column ( { type : 'varchar' } )
23- widget_type : DashboardWidgetTypeEnum ;
24-
25- @Column ( { type : 'varchar' , default : null , nullable : true } )
26- chart_type : string | null ;
27-
28- @Column ( { default : null , nullable : true } )
29- name : string | null ;
30-
31- @Column ( { type : 'text' , default : null , nullable : true } )
32- description : string | null ;
33-
3410 @Column ( { type : 'int' , default : 0 } )
3511 position_x : number ;
3612
@@ -43,9 +19,6 @@ export class DashboardWidgetEntity {
4319 @Column ( { type : 'int' , default : 3 } )
4420 height : number ;
4521
46- @Column ( 'json' , { default : null , nullable : true } )
47- widget_options : string | null ;
48-
4922 @Column ( { type : 'uuid' } )
5023 dashboard_id : string ;
5124
@@ -63,40 +36,4 @@ export class DashboardWidgetEntity {
6336 @ManyToOne ( ( ) => SavedDbQueryEntity , { onDelete : 'SET NULL' , nullable : true } )
6437 @JoinColumn ( { name : 'query_id' } )
6538 query : Relation < SavedDbQueryEntity > | null ;
66-
67- @BeforeUpdate ( )
68- stringifyOptionsOnUpdate ( ) : void {
69- try {
70- if ( this . widget_options && typeof this . widget_options === 'object' ) {
71- this . widget_options = JSON . stringify ( this . widget_options ) ;
72- }
73- } catch ( e ) {
74- console . error ( '-> Error widget options stringify ' + e . message ) ;
75- }
76- }
77-
78- @BeforeInsert ( )
79- stringifyOptions ( ) : void {
80- try {
81- if ( this . widget_options && typeof this . widget_options === 'object' ) {
82- this . widget_options = JSON . stringify ( this . widget_options ) ;
83- }
84- } catch ( e ) {
85- console . error ( '-> Error widget options stringify ' + e . message ) ;
86- }
87- }
88-
89- @AfterLoad ( )
90- parseOptions ( ) : void {
91- try {
92- if ( this . widget_options && typeof this . widget_options === 'string' ) {
93- this . widget_options = sjson . parse ( this . widget_options , null , {
94- protoAction : 'remove' ,
95- constructorAction : 'remove' ,
96- } ) ;
97- }
98- } catch ( e ) {
99- console . error ( '-> Error widget options parse ' + e . message ) ;
100- }
101- }
10239}
0 commit comments