@@ -11,19 +11,40 @@ export class DashboardExporter {
11
11
constructor ( private datasourceSrv ) {
12
12
}
13
13
14
- makeExportable ( dash ) {
14
+ makeExportable ( dashboard ) {
15
15
var dynSrv = new DynamicDashboardSrv ( ) ;
16
- dynSrv . init ( dash , { variables : dash . templating . list } ) ;
16
+
17
+ // clean up repeated rows and panels,
18
+ // this is done on the live real dashboard instance, not on a clone
19
+ // so we need to undo this
20
+ // this is pretty hacky and needs to be changed
21
+ dynSrv . init ( dashboard ) ;
17
22
dynSrv . process ( { cleanUpOnly : true } ) ;
18
23
19
- dash . id = null ;
24
+ var saveModel = dashboard . getSaveModelClone ( ) ;
25
+ saveModel . id = null ;
26
+
27
+ // undo repeat cleanup
28
+ dynSrv . process ( ) ;
20
29
21
30
var inputs = [ ] ;
22
31
var requires = { } ;
23
32
var datasources = { } ;
24
33
var promises = [ ] ;
34
+ var variableLookup : any = { } ;
35
+
36
+ for ( let variable of saveModel . templating . list ) {
37
+ variableLookup [ variable . name ] = variable ;
38
+ }
25
39
26
40
var templateizeDatasourceUsage = obj => {
41
+ // ignore data source properties that contain a variable
42
+ if ( obj . datasource && obj . datasource . indexOf ( '$' ) === 0 ) {
43
+ if ( variableLookup [ obj . datasource . substring ( 1 ) ] ) {
44
+ return ;
45
+ }
46
+ }
47
+
27
48
promises . push ( this . datasourceSrv . get ( obj . datasource ) . then ( ds => {
28
49
if ( ds . meta . builtIn ) {
29
50
return ;
@@ -50,7 +71,7 @@ export class DashboardExporter {
50
71
} ;
51
72
52
73
// check up panel data sources
53
- for ( let row of dash . rows ) {
74
+ for ( let row of saveModel . rows ) {
54
75
for ( let panel of row . panels ) {
55
76
if ( panel . datasource !== undefined ) {
56
77
templateizeDatasourceUsage ( panel ) ;
@@ -77,7 +98,7 @@ export class DashboardExporter {
77
98
}
78
99
79
100
// templatize template vars
80
- for ( let variable of dash . templating . list ) {
101
+ for ( let variable of saveModel . templating . list ) {
81
102
if ( variable . type === 'query' ) {
82
103
templateizeDatasourceUsage ( variable ) ;
83
104
variable . options = [ ] ;
@@ -87,7 +108,7 @@ export class DashboardExporter {
87
108
}
88
109
89
110
// templatize annotations vars
90
- for ( let annotationDef of dash . annotations . list ) {
111
+ for ( let annotationDef of saveModel . annotations . list ) {
91
112
templateizeDatasourceUsage ( annotationDef ) ;
92
113
}
93
114
@@ -105,7 +126,7 @@ export class DashboardExporter {
105
126
} ) ;
106
127
107
128
// templatize constants
108
- for ( let variable of dash . templating . list ) {
129
+ for ( let variable of saveModel . templating . list ) {
109
130
if ( variable . type === 'constant' ) {
110
131
var refName = 'VAR_' + variable . name . replace ( ' ' , '_' ) . toUpperCase ( ) ;
111
132
inputs . push ( {
@@ -133,7 +154,7 @@ export class DashboardExporter {
133
154
newObj [ "__inputs" ] = inputs ;
134
155
newObj [ "__requires" ] = requires ;
135
156
136
- _ . defaults ( newObj , dash ) ;
157
+ _ . defaults ( newObj , saveModel ) ;
137
158
138
159
return newObj ;
139
160
} ) . catch ( err => {
0 commit comments