Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
36ef1865
Commit
36ef1865
authored
Nov 29, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repeat row: expose scopedVars to row panels
parent
dd9c727e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
45 deletions
+93
-45
public/app/features/dashboard/dashboard_model.ts
+76
-45
public/app/features/dashboard/specs/repeat.jest.ts
+17
-0
No files found.
public/app/features/dashboard/dashboard_model.ts
View file @
36ef1865
...
@@ -274,7 +274,6 @@ export class DashboardModel {
...
@@ -274,7 +274,6 @@ export class DashboardModel {
this
.
sortPanelsByGridPos
();
this
.
sortPanelsByGridPos
();
this
.
events
.
emit
(
'repeats-processed'
);
this
.
events
.
emit
(
'repeats-processed'
);
console
.
log
(
this
.
panels
);
}
}
getPanelRepeatClone
(
sourcePanel
,
valueIndex
,
sourcePanelIndex
)
{
getPanelRepeatClone
(
sourcePanel
,
valueIndex
,
sourcePanelIndex
)
{
...
@@ -286,25 +285,42 @@ export class DashboardModel {
...
@@ -286,25 +285,42 @@ export class DashboardModel {
let
clone
=
new
PanelModel
(
sourcePanel
.
getSaveModel
());
let
clone
=
new
PanelModel
(
sourcePanel
.
getSaveModel
());
clone
.
id
=
this
.
getNextPanelId
();
clone
.
id
=
this
.
getNextPanelId
();
if
(
sourcePanel
.
type
===
'row'
)
{
// insert after source panel + value index
// for row clones we need to figure out panels under row to clone and where to insert clone
this
.
panels
.
splice
(
sourcePanelIndex
+
valueIndex
,
0
,
clone
);
let
rowPanels
,
insertPos
;
if
(
sourcePanel
.
collapsed
)
{
clone
.
repeatIteration
=
this
.
iteration
;
rowPanels
=
sourcePanel
.
panels
;
clone
.
repeatPanelId
=
sourcePanel
.
id
;
clone
.
panels
=
_
.
cloneDeep
(
rowPanels
);
clone
.
repeat
=
null
;
// insert copied row after preceding row
return
clone
;
insertPos
=
sourcePanelIndex
+
valueIndex
;
}
}
else
{
rowPanels
=
this
.
getRowPanels
(
sourcePanelIndex
);
getRowRepeatClone
(
sourcePanel
,
valueIndex
,
sourcePanelIndex
)
{
clone
.
panels
=
_
.
map
(
rowPanels
,
panel
=>
panel
.
getSaveModel
());
// if first clone return source
// insert copied row after preceding row's panels
if
(
valueIndex
===
0
)
{
insertPos
=
sourcePanelIndex
+
((
rowPanels
.
length
+
1
)
*
valueIndex
);
if
(
!
sourcePanel
.
collapsed
)
{
let
rowPanels
=
this
.
getRowPanels
(
sourcePanelIndex
);
sourcePanel
.
panels
=
rowPanels
;
}
}
this
.
panels
.
splice
(
insertPos
,
0
,
clone
);
return
sourcePanel
;
}
let
clone
=
new
PanelModel
(
sourcePanel
.
getSaveModel
());
clone
.
id
=
this
.
getNextPanelId
();
// for row clones we need to figure out panels under row to clone and where to insert clone
let
rowPanels
,
insertPos
;
if
(
sourcePanel
.
collapsed
)
{
rowPanels
=
_
.
cloneDeep
(
sourcePanel
.
panels
);
clone
.
panels
=
rowPanels
;
// insert copied row after preceding row
insertPos
=
sourcePanelIndex
+
valueIndex
;
}
else
{
}
else
{
// insert after source panel + value index
rowPanels
=
this
.
getRowPanels
(
sourcePanelIndex
);
this
.
panels
.
splice
(
sourcePanelIndex
+
valueIndex
,
0
,
clone
);
clone
.
panels
=
_
.
map
(
rowPanels
,
panel
=>
panel
.
getSaveModel
());
// insert copied row after preceding row's panels
insertPos
=
sourcePanelIndex
+
((
rowPanels
.
length
+
1
)
*
valueIndex
);
}
}
this
.
panels
.
splice
(
insertPos
,
0
,
clone
);
clone
.
repeatIteration
=
this
.
iteration
;
clone
.
repeatIteration
=
this
.
iteration
;
clone
.
repeatPanelId
=
sourcePanel
.
id
;
clone
.
repeatPanelId
=
sourcePanel
.
id
;
...
@@ -334,32 +350,43 @@ export class DashboardModel {
...
@@ -334,32 +350,43 @@ export class DashboardModel {
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
let
option
=
selected
[
index
];
let
option
=
selected
[
index
];
let
copy
=
this
.
getPanelRepeatClone
(
panel
,
index
,
panelIndex
)
;
let
copy
;
copy
.
scopedVars
=
{};
if
(
panel
.
type
===
'row'
)
{
copy
.
scopedVars
[
variable
.
name
]
=
option
;
copy
=
this
.
getRowRepeatClone
(
panel
,
index
,
panelIndex
);
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
copy
.
type
===
'row'
)
{
let
rowHeight
=
this
.
getRowHeight
(
copy
);
let
rowHeight
=
this
.
getRowHeight
(
copy
);
if
(
rowHeight
)
{
// if (rowHeight) {
let
panelsBelowIndex
;
let
panelsBelowIndex
;
let
rowPanels
=
copy
.
panels
;
let
rowPanels
=
copy
.
panels
||
[];
// insert after 'row' panel
// insert after 'row' panel
let
insertPos
=
panelIndex
+
((
rowPanels
.
length
+
1
)
*
index
)
+
1
;
let
insertPos
=
panelIndex
+
((
rowPanels
.
length
+
1
)
*
index
)
+
1
;
if
(
copy
.
collapsed
)
{
if
(
copy
.
collapsed
)
{
copy
.
gridPos
.
y
+=
index
;
copy
.
gridPos
.
y
+=
index
;
yPos
+=
index
;
yPos
+=
index
;
panelsBelowIndex
=
panelIndex
+
index
+
1
;
panelsBelowIndex
=
panelIndex
+
index
+
1
;
_
.
each
(
copy
.
panels
,
(
panel
,
i
)
=>
{
_
.
each
(
copy
.
panels
,
(
panel
,
i
)
=>
{
panel
.
scopedVars
=
{};
panel
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
index
>
0
)
{
panel
.
id
=
this
.
getNextPanelId
();
panel
.
id
=
this
.
getNextPanelId
();
panel
.
repeatIteration
=
this
.
iteration
;
panel
.
repeatIteration
=
this
.
iteration
;
panel
.
repeatPanelId
=
rowPanels
[
i
].
id
;
panel
.
repeatPanelId
=
rowPanels
[
i
].
id
;
panel
.
repeat
=
null
;
panel
.
repeat
=
null
;
copy
.
panels
[
i
]
=
panel
;
copy
.
panels
[
i
]
=
panel
;
});
}
}
else
{
});
_
.
each
(
rowPanels
,
(
rowPanel
,
i
)
=>
{
}
else
{
_
.
each
(
rowPanels
,
(
rowPanel
,
i
)
=>
{
rowPanel
.
scopedVars
=
{};
rowPanel
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
index
>
0
)
{
let
cloneRowPanel
=
new
PanelModel
(
rowPanel
);
let
cloneRowPanel
=
new
PanelModel
(
rowPanel
);
cloneRowPanel
.
id
=
this
.
getNextPanelId
();
cloneRowPanel
.
id
=
this
.
getNextPanelId
();
cloneRowPanel
.
repeatIteration
=
this
.
iteration
;
cloneRowPanel
.
repeatIteration
=
this
.
iteration
;
...
@@ -367,19 +394,23 @@ export class DashboardModel {
...
@@ -367,19 +394,23 @@ export class DashboardModel {
cloneRowPanel
.
repeat
=
null
;
cloneRowPanel
.
repeat
=
null
;
cloneRowPanel
.
gridPos
.
y
+=
rowHeight
*
index
;
cloneRowPanel
.
gridPos
.
y
+=
rowHeight
*
index
;
this
.
panels
.
splice
(
insertPos
+
i
,
0
,
cloneRowPanel
);
this
.
panels
.
splice
(
insertPos
+
i
,
0
,
cloneRowPanel
);
});
}
copy
.
panels
=
[];
});
copy
.
gridPos
.
y
+=
rowHeight
*
index
;
copy
.
panels
=
[];
yPos
+=
rowHeight
;
copy
.
gridPos
.
y
+=
rowHeight
*
index
;
panelsBelowIndex
=
insertPos
+
rowPanels
.
length
;
yPos
+=
rowHeight
;
}
panelsBelowIndex
=
insertPos
+
rowPanels
.
length
;
}
// Update gridPos for panels below
// Update gridPos for panels below
for
(
let
i
=
panelsBelowIndex
;
i
<
this
.
panels
.
length
;
i
++
)
{
for
(
let
i
=
panelsBelowIndex
;
i
<
this
.
panels
.
length
;
i
++
)
{
this
.
panels
[
i
].
gridPos
.
y
+=
yPos
;
this
.
panels
[
i
].
gridPos
.
y
+=
yPos
;
}
}
}
}
else
{
}
else
{
copy
=
this
.
getPanelRepeatClone
(
panel
,
index
,
panelIndex
);
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
copy
.
gridPos
.
y
=
yPos
;
copy
.
gridPos
.
y
=
yPos
;
yPos
+=
copy
.
gridPos
.
h
;
yPos
+=
copy
.
gridPos
.
h
;
...
...
public/app/features/dashboard/specs/repeat.jest.ts
View file @
36ef1865
...
@@ -187,6 +187,23 @@ describe('given dashboard with row repeat', function() {
...
@@ -187,6 +187,23 @@ describe('given dashboard with row repeat', function() {
]);
]);
});
});
it
(
'should set scopedVars for each panel'
,
function
()
{
dashboardJSON
.
templating
.
list
[
0
].
options
[
2
].
selected
=
true
;
dashboard
=
new
DashboardModel
(
dashboardJSON
);
dashboard
.
processRepeats
();
const
scopedVars
=
_
.
compact
(
_
.
map
(
dashboard
.
panels
,
(
panel
)
=>
{
if
(
panel
.
scopedVars
)
{
return
panel
.
scopedVars
.
apps
.
value
;
}
}));
expect
(
scopedVars
).
toEqual
([
'se1'
,
'se1'
,
'se1'
,
'se2'
,
'se2'
,
'se2'
,
'se3'
,
'se3'
,
'se3'
,
]);
});
it
(
'should repeat only row if it is collapsed'
,
function
()
{
it
(
'should repeat only row if it is collapsed'
,
function
()
{
dashboardJSON
.
panels
=
[
dashboardJSON
.
panels
=
[
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment