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
70005d3e
Commit
70005d3e
authored
Oct 13, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
grid: repeat refactoring and unit tests
parent
e5a6cb62
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
12 deletions
+64
-12
public/app/core/constants.ts
+1
-0
public/app/features/dashboard/dashboard_model.ts
+18
-4
public/app/features/dashboard/folder_modal/folder.ts
+0
-2
public/app/features/dashboard/panel_model.ts
+5
-4
public/app/features/dashboard/specs/dashboard_model_specs.ts
+40
-2
No files found.
public/app/core/constants.ts
View file @
70005d3e
...
...
@@ -2,5 +2,6 @@
export
const
GRID_CELL_HEIGHT
=
20
;
export
const
GRID_CELL_VMARGIN
=
10
;
export
const
GRID_COLUMN_COUNT
=
24
;
export
const
REPEAT_DIR_VERTICAL
=
'v'
;
public/app/features/dashboard/dashboard_model.ts
View file @
70005d3e
import
moment
from
'moment'
;
import
_
from
'lodash'
;
import
{
GRID_COLUMN_COUNT
,
GRID_CELL_HEIGHT
}
from
'app/core/constants'
;
import
{
GRID_COLUMN_COUNT
,
GRID_CELL_HEIGHT
,
REPEAT_DIR_VERTICAL
}
from
'app/core/constants'
;
import
{
DEFAULT_ANNOTATION_COLOR
}
from
'app/core/utils/colors'
;
import
{
Emitter
,
contextSrv
}
from
'app/core/core'
;
import
sortByKeys
from
'app/core/utils/sort_by_keys'
;
...
...
@@ -283,6 +283,9 @@ export class DashboardModel {
selected
=
_
.
filter
(
variable
.
options
,
{
selected
:
true
});
}
let
minWidth
=
panel
.
minSpan
||
6
;
let
xIndex
=
0
;
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
var
option
=
selected
[
index
];
var
copy
=
this
.
getRepeatClone
(
panel
,
index
);
...
...
@@ -290,15 +293,26 @@ export class DashboardModel {
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
// souce panel uses original possition
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
if
(
index
===
0
)
{
continue
;
}
if
(
panel
.
repeatDirection
===
'Y'
)
{
copy
.
gridPos
.
y
=
panel
.
gridPos
.
y
+
panel
.
gridPos
.
h
*
index
;
}
else
{
copy
.
gridPos
.
x
=
panel
.
gridPos
.
x
+
panel
.
gridPos
.
w
*
index
;
// 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
=
copy
.
gridPos
.
w
*
xIndex
;
// handle overflow by pushing down one row
if
(
copy
.
gridPos
.
x
+
copy
.
gridPos
.
w
>
GRID_COLUMN_COUNT
)
{
copy
.
gridPos
.
x
=
0
;
xIndex
=
0
;
}
else
{
xIndex
+=
1
;
}
}
}
}
...
...
public/app/features/dashboard/folder_modal/folder.ts
View file @
70005d3e
///<reference path="../../../headers/common.d.ts" />
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
...
...
public/app/features/dashboard/panel_model.ts
View file @
70005d3e
...
...
@@ -21,10 +21,11 @@ export class PanelModel {
title
:
string
;
alert
?:
any
;
scopedVars
?:
any
;
repeat
?:
any
;
repeatIteration
?:
any
;
repeatPanelId
?:
any
;
repeatDirection
?:
any
;
repeat
?:
string
;
repeatIteration
?:
number
;
repeatPanelId
?:
number
;
repeatDirection
?:
string
;
minSpan
?:
number
;
// non persisted
fullscreen
:
boolean
;
...
...
public/app/features/dashboard/specs/dashboard_model_specs.ts
View file @
70005d3e
...
...
@@ -416,12 +416,12 @@ describe('DashboardModel', function() {
});
});
describe
(
'given dashboard with panel repeat'
,
function
(
ctx
)
{
describe
(
'given dashboard with panel repeat
in horizontal direction
'
,
function
(
ctx
)
{
var
dashboard
;
beforeEach
(
function
()
{
dashboard
=
new
DashboardModel
({
panels
:
[{
id
:
2
,
repeat
:
'apps'
}],
panels
:
[{
id
:
2
,
repeat
:
'apps'
,
repeatDirection
:
'h'
,
gridPos
:
{
x
:
0
,
y
:
0
,
h
:
2
,
w
:
24
}
}],
templating
:
{
list
:
[{
name
:
'apps'
,
...
...
@@ -456,6 +456,12 @@ describe('DashboardModel', function() {
expect
(
dashboard
.
panels
[
2
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se3'
);
});
it
(
'should place on first row and adjust width so all fit'
,
function
()
{
expect
(
dashboard
.
panels
[
0
].
gridPos
).
to
.
eql
({
x
:
0
,
y
:
0
,
h
:
2
,
w
:
8
});
expect
(
dashboard
.
panels
[
1
].
gridPos
).
to
.
eql
({
x
:
8
,
y
:
0
,
h
:
2
,
w
:
8
});
expect
(
dashboard
.
panels
[
2
].
gridPos
).
to
.
eql
({
x
:
16
,
y
:
0
,
h
:
2
,
w
:
8
});
});
describe
(
'After a second iteration'
,
function
()
{
var
repeatedPanelAfterIteration1
;
...
...
@@ -522,4 +528,36 @@ describe('DashboardModel', function() {
});
describe
(
'given dashboard with panel repeat in vertical direction'
,
function
(
ctx
)
{
var
dashboard
;
beforeEach
(
function
()
{
dashboard
=
new
DashboardModel
({
panels
:
[{
id
:
2
,
repeat
:
'apps'
,
repeatDirection
:
'v'
,
gridPos
:
{
x
:
5
,
y
:
0
,
h
:
2
,
w
:
8
}}],
templating
:
{
list
:
[{
name
:
'apps'
,
current
:
{
text
:
'se1, se2, se3'
,
value
:
[
'se1'
,
'se2'
,
'se3'
]
},
options
:
[
{
text
:
'se1'
,
value
:
'se1'
,
selected
:
true
},
{
text
:
'se2'
,
value
:
'se2'
,
selected
:
true
},
{
text
:
'se3'
,
value
:
'se3'
,
selected
:
true
},
{
text
:
'se4'
,
value
:
'se4'
,
selected
:
false
}
]
}]
}
});
dashboard
.
processRepeats
();
});
it
(
'should place on items on top of each other and keep witdh'
,
function
()
{
expect
(
dashboard
.
panels
[
0
].
gridPos
).
to
.
eql
({
x
:
5
,
y
:
0
,
h
:
2
,
w
:
8
});
expect
(
dashboard
.
panels
[
1
].
gridPos
).
to
.
eql
({
x
:
5
,
y
:
2
,
h
:
2
,
w
:
8
});
expect
(
dashboard
.
panels
[
2
].
gridPos
).
to
.
eql
({
x
:
5
,
y
:
4
,
h
:
2
,
w
:
8
});
});
});
});
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