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
8593ca00
Commit
8593ca00
authored
Dec 01, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repeat row: refactor
parent
88760983
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
67 deletions
+79
-67
public/app/features/dashboard/dashboard_model.ts
+79
-67
No files found.
public/app/features/dashboard/dashboard_model.ts
View file @
8593ca00
...
@@ -305,8 +305,6 @@ export class DashboardModel {
...
@@ -305,8 +305,6 @@ export class DashboardModel {
}
}
let
clone
=
new
PanelModel
(
sourcePanel
.
getSaveModel
());
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
// for row clones we need to figure out panels under row to clone and where to insert clone
let
rowPanels
,
insertPos
;
let
rowPanels
,
insertPos
;
if
(
sourcePanel
.
collapsed
)
{
if
(
sourcePanel
.
collapsed
)
{
...
@@ -322,9 +320,7 @@ export class DashboardModel {
...
@@ -322,9 +320,7 @@ export class DashboardModel {
}
}
this
.
panels
.
splice
(
insertPos
,
0
,
clone
);
this
.
panels
.
splice
(
insertPos
,
0
,
clone
);
clone
.
repeatIteration
=
this
.
iteration
;
this
.
updateRepeatedPanelIds
(
clone
);
clone
.
repeatPanelId
=
sourcePanel
.
id
;
clone
.
repeat
=
null
;
return
clone
;
return
clone
;
}
}
...
@@ -337,101 +333,117 @@ export class DashboardModel {
...
@@ -337,101 +333,117 @@ export class DashboardModel {
return
;
return
;
}
}
let
selected
;
if
(
panel
.
type
===
'row'
)
{
if
(
variable
.
current
.
text
===
'All'
)
{
this
.
repeatRow
(
panel
,
panelIndex
,
variable
);
selected
=
variable
.
options
.
slice
(
1
,
variable
.
options
.
length
);
return
;
}
else
{
selected
=
_
.
filter
(
variable
.
options
,
{
selected
:
true
});
}
}
let
selectedOptions
=
this
.
getSelectedVariableOptions
(
variable
);
let
minWidth
=
panel
.
minSpan
||
6
;
let
minWidth
=
panel
.
minSpan
||
6
;
let
xPos
=
0
;
let
xPos
=
0
;
let
yPos
=
panel
.
gridPos
.
y
;
let
yPos
=
panel
.
gridPos
.
y
;
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
selected
Options
.
length
;
index
++
)
{
let
option
=
selected
[
index
];
let
option
=
selected
Options
[
index
];
let
copy
;
let
copy
;
if
(
panel
.
type
===
'row'
)
{
copy
=
this
.
getPanelRepeatClone
(
panel
,
index
,
panelIndex
);
copy
=
this
.
getRowRepeatClone
(
panel
,
index
,
panelIndex
);
copy
.
scopedVars
=
{};
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
copy
.
scopedVars
[
variable
.
name
]
=
option
;
let
rowHeight
=
this
.
getRowHeight
(
copy
);
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
// if (rowHeight) {
copy
.
gridPos
.
y
=
yPos
;
let
panelsBelowIndex
;
yPos
+=
copy
.
gridPos
.
h
;
let
rowPanels
=
copy
.
panels
||
[];
}
else
{
//
insert after 'row' panel
//
set width based on how many are selected
let
insertPos
=
panelIndex
+
((
rowPanels
.
length
+
1
)
*
index
)
+
1
;
// assumed the repeated panels should take up full row width
if
(
copy
.
collapsed
)
{
copy
.
gridPos
.
w
=
Math
.
max
(
GRID_COLUMN_COUNT
/
selectedOptions
.
length
,
minWidth
);
copy
.
gridPos
.
y
+=
index
;
copy
.
gridPos
.
x
=
xPos
;
yPos
+=
index
;
copy
.
gridPos
.
y
=
yPos
;
panelsBelowIndex
=
panelIndex
+
index
+
1
;
xPos
+=
copy
.
gridPos
.
w
;
// handle overflow by pushing down one row
if
(
xPos
+
copy
.
gridPos
.
w
>
GRID_COLUMN_COUNT
)
{
xPos
=
0
;
yPos
+=
copy
.
gridPos
.
h
;
}
}
}
}
_
.
each
(
copy
.
panels
,
(
panel
,
i
)
=>
{
repeatRow
(
panel
:
PanelModel
,
panelIndex
:
number
,
variable
)
{
let
selectedOptions
=
this
.
getSelectedVariableOptions
(
variable
);
let
yPos
=
panel
.
gridPos
.
y
;
function
setScopedVars
(
panel
,
variableOption
)
{
panel
.
scopedVars
=
{};
panel
.
scopedVars
=
{};
panel
.
scopedVars
[
variable
.
name
]
=
option
;
panel
.
scopedVars
[
variable
.
name
]
=
variableOption
;
}
if
(
index
>
0
)
{
for
(
let
optionIndex
=
0
;
optionIndex
<
selectedOptions
.
length
;
optionIndex
++
)
{
panel
.
id
=
this
.
getNextPanelId
();
let
option
=
selectedOptions
[
optionIndex
];
panel
.
repeatIteration
=
this
.
iteration
;
let
rowCopy
=
this
.
getRowRepeatClone
(
panel
,
optionIndex
,
panelIndex
);
panel
.
repeatPanelId
=
rowPanels
[
i
].
id
;
setScopedVars
(
rowCopy
,
option
);
panel
.
repeat
=
null
;
copy
.
panels
[
i
]
=
panel
;
let
rowHeight
=
this
.
getRowHeight
(
rowCopy
);
let
rowPanels
=
rowCopy
.
panels
||
[];
let
panelBelowIndex
;
if
(
panel
.
collapsed
)
{
// For collapsed row just copy its panels and set scoped vars and proper IDs
_
.
each
(
rowPanels
,
(
rowPanel
,
i
)
=>
{
setScopedVars
(
rowPanel
,
option
);
if
(
optionIndex
>
0
)
{
this
.
updateRepeatedPanelIds
(
rowPanel
);
}
}
});
});
rowCopy
.
gridPos
.
y
+=
optionIndex
;
yPos
+=
optionIndex
;
panelBelowIndex
=
panelIndex
+
optionIndex
+
1
;
}
else
{
}
else
{
// insert after 'row' panel
let
insertPos
=
panelIndex
+
((
rowPanels
.
length
+
1
)
*
optionIndex
)
+
1
;
_
.
each
(
rowPanels
,
(
rowPanel
,
i
)
=>
{
_
.
each
(
rowPanels
,
(
rowPanel
,
i
)
=>
{
rowPanel
.
scopedVars
=
{};
setScopedVars
(
rowPanel
,
option
);
rowPanel
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
optionIndex
>
0
)
{
if
(
index
>
0
)
{
let
cloneRowPanel
=
new
PanelModel
(
rowPanel
);
let
cloneRowPanel
=
new
PanelModel
(
rowPanel
);
cloneRowPanel
.
id
=
this
.
getNextPanelId
();
this
.
updateRepeatedPanelIds
(
cloneRowPanel
);
cloneRowPanel
.
repeatIteration
=
this
.
iteration
;
// For exposed row additionally set proper Y grid position and add it to dashboard panels
cloneRowPanel
.
repeatPanelId
=
rowPanel
.
id
;
cloneRowPanel
.
gridPos
.
y
+=
rowHeight
*
optionIndex
;
cloneRowPanel
.
repeat
=
null
;
cloneRowPanel
.
gridPos
.
y
+=
rowHeight
*
index
;
this
.
panels
.
splice
(
insertPos
+
i
,
0
,
cloneRowPanel
);
this
.
panels
.
splice
(
insertPos
+
i
,
0
,
cloneRowPanel
);
}
}
});
});
c
opy
.
panels
=
[];
rowC
opy
.
panels
=
[];
copy
.
gridPos
.
y
+=
rowHeight
*
i
ndex
;
rowCopy
.
gridPos
.
y
+=
rowHeight
*
optionI
ndex
;
yPos
+=
rowHeight
;
yPos
+=
rowHeight
;
panels
BelowIndex
=
insertPos
+
rowPanels
.
length
;
panel
BelowIndex
=
insertPos
+
rowPanels
.
length
;
}
}
// Update gridPos for panels below
// Update gridPos for panels below
for
(
let
i
=
panels
BelowIndex
;
i
<
this
.
panels
.
length
;
i
++
)
{
for
(
let
i
=
panel
BelowIndex
;
i
<
this
.
panels
.
length
;
i
++
)
{
this
.
panels
[
i
].
gridPos
.
y
+=
yPos
;
this
.
panels
[
i
].
gridPos
.
y
+=
yPos
;
}
}
}
else
{
copy
=
this
.
getPanelRepeatClone
(
panel
,
index
,
panelIndex
);
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
copy
.
gridPos
.
y
=
yPos
;
yPos
+=
copy
.
gridPos
.
h
;
}
else
{
// set width based on how many are selected
// assumed the repeated panels should take up full row width
copy
.
gridPos
.
w
=
Math
.
max
(
GRID_COLUMN_COUNT
/
selected
.
length
,
minWidth
);
copy
.
gridPos
.
x
=
xPos
;
copy
.
gridPos
.
y
=
yPos
;
xPos
+=
copy
.
gridPos
.
w
;
// handle overflow by pushing down one row
if
(
xPos
+
copy
.
gridPos
.
w
>
GRID_COLUMN_COUNT
)
{
xPos
=
0
;
yPos
+=
copy
.
gridPos
.
h
;
}
}
}
}
updateRepeatedPanelIds
(
panel
:
PanelModel
)
{
panel
.
repeatPanelId
=
panel
.
id
;
panel
.
id
=
this
.
getNextPanelId
();
panel
.
repeatIteration
=
this
.
iteration
;
panel
.
repeat
=
null
;
return
panel
;
}
}
getSelectedVariableOptions
(
variable
)
{
let
selectedOptions
;
if
(
variable
.
current
.
text
===
'All'
)
{
selectedOptions
=
variable
.
options
.
slice
(
1
,
variable
.
options
.
length
);
}
else
{
selectedOptions
=
_
.
filter
(
variable
.
options
,
{
selected
:
true
});
}
}
return
selectedOptions
;
}
}
getRowHeight
(
rowPanel
:
PanelModel
):
number
{
getRowHeight
(
rowPanel
:
PanelModel
):
number
{
...
...
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