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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
15 deletions
+67
-15
public/app/core/constants.ts
+1
-0
public/app/features/dashboard/dashboard_model.ts
+21
-7
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 @@
...
@@ -2,5 +2,6 @@
export
const
GRID_CELL_HEIGHT
=
20
;
export
const
GRID_CELL_HEIGHT
=
20
;
export
const
GRID_CELL_VMARGIN
=
10
;
export
const
GRID_CELL_VMARGIN
=
10
;
export
const
GRID_COLUMN_COUNT
=
24
;
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
moment
from
'moment'
;
import
_
from
'lodash'
;
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
{
DEFAULT_ANNOTATION_COLOR
}
from
'app/core/utils/colors'
;
import
{
Emitter
,
contextSrv
}
from
'app/core/core'
;
import
{
Emitter
,
contextSrv
}
from
'app/core/core'
;
import
sortByKeys
from
'app/core/utils/sort_by_keys'
;
import
sortByKeys
from
'app/core/utils/sort_by_keys'
;
...
@@ -283,6 +283,9 @@ export class DashboardModel {
...
@@ -283,6 +283,9 @@ export class DashboardModel {
selected
=
_
.
filter
(
variable
.
options
,
{
selected
:
true
});
selected
=
_
.
filter
(
variable
.
options
,
{
selected
:
true
});
}
}
let
minWidth
=
panel
.
minSpan
||
6
;
let
xIndex
=
0
;
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
selected
.
length
;
index
++
)
{
var
option
=
selected
[
index
];
var
option
=
selected
[
index
];
var
copy
=
this
.
getRepeatClone
(
panel
,
index
);
var
copy
=
this
.
getRepeatClone
(
panel
,
index
);
...
@@ -290,15 +293,26 @@ export class DashboardModel {
...
@@ -290,15 +293,26 @@ export class DashboardModel {
copy
.
scopedVars
=
{};
copy
.
scopedVars
=
{};
copy
.
scopedVars
[
variable
.
name
]
=
option
;
copy
.
scopedVars
[
variable
.
name
]
=
option
;
// souce panel uses original possition
if
(
panel
.
repeatDirection
===
REPEAT_DIR_VERTICAL
)
{
if
(
index
===
0
)
{
if
(
index
===
0
)
{
continue
;
continue
;
}
}
if
(
panel
.
repeatDirection
===
'Y'
)
{
copy
.
gridPos
.
y
=
panel
.
gridPos
.
y
+
panel
.
gridPos
.
h
*
index
;
copy
.
gridPos
.
y
=
panel
.
gridPos
.
y
+
panel
.
gridPos
.
h
*
index
;
}
else
{
}
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
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
import
appEvents
from
'app/core/app_events'
;
...
...
public/app/features/dashboard/panel_model.ts
View file @
70005d3e
...
@@ -21,10 +21,11 @@ export class PanelModel {
...
@@ -21,10 +21,11 @@ export class PanelModel {
title
:
string
;
title
:
string
;
alert
?:
any
;
alert
?:
any
;
scopedVars
?:
any
;
scopedVars
?:
any
;
repeat
?:
any
;
repeat
?:
string
;
repeatIteration
?:
any
;
repeatIteration
?:
number
;
repeatPanelId
?:
any
;
repeatPanelId
?:
number
;
repeatDirection
?:
any
;
repeatDirection
?:
string
;
minSpan
?:
number
;
// non persisted
// non persisted
fullscreen
:
boolean
;
fullscreen
:
boolean
;
...
...
public/app/features/dashboard/specs/dashboard_model_specs.ts
View file @
70005d3e
...
@@ -416,12 +416,12 @@ describe('DashboardModel', function() {
...
@@ -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
;
var
dashboard
;
beforeEach
(
function
()
{
beforeEach
(
function
()
{
dashboard
=
new
DashboardModel
({
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
:
{
templating
:
{
list
:
[{
list
:
[{
name
:
'apps'
,
name
:
'apps'
,
...
@@ -456,6 +456,12 @@ describe('DashboardModel', function() {
...
@@ -456,6 +456,12 @@ describe('DashboardModel', function() {
expect
(
dashboard
.
panels
[
2
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se3'
);
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
()
{
describe
(
'After a second iteration'
,
function
()
{
var
repeatedPanelAfterIteration1
;
var
repeatedPanelAfterIteration1
;
...
@@ -522,4 +528,36 @@ describe('DashboardModel', function() {
...
@@ -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