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
3044a74a
Commit
3044a74a
authored
Apr 27, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization and unit tests for panel and row repeat feature, #1888
parent
ca7aa294
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
59 deletions
+107
-59
public/app/features/dashboard/dynamicDashboardSrv.js
+4
-9
public/app/panels/graph/module.js
+1
-0
public/app/partials/dashboard.html
+1
-1
public/test/specs/dynamicDashboardSrv-specs.js
+101
-49
No files found.
public/app/features/dashboard/dynamicDashboardSrv.js
View file @
3044a74a
...
...
@@ -8,8 +8,6 @@ function (angular, _) {
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
service
(
'dynamicDashboardSrv'
,
function
()
{
var
self
=
this
;
this
.
init
=
function
(
dashboard
)
{
this
.
iteration
=
0
;
...
...
@@ -57,7 +55,7 @@ function (angular, _) {
for
(
i
=
0
;
i
<
dashboard
.
rows
.
length
;
i
++
)
{
row
=
dashboard
.
rows
[
i
];
if
(
row
.
linked
)
{
dashboard
.
rows
=
_
.
without
(
dashboard
.
rows
,
row
);
dashboard
.
rows
.
splice
(
i
,
1
);
i
=
i
-
1
;
}
}
...
...
@@ -75,7 +73,6 @@ function (angular, _) {
};
this
.
repeatRow
=
function
(
row
,
dashboard
)
{
console
.
log
(
'repeat row'
);
var
variables
=
dashboard
.
templating
.
list
;
var
variable
=
_
.
findWhere
(
variables
,
{
name
:
row
.
repeat
.
replace
(
'$'
,
''
)});
if
(
!
variable
)
{
...
...
@@ -95,13 +92,13 @@ function (angular, _) {
copy
.
repeat
=
null
;
copy
.
linked
=
true
;
dashboard
.
rows
.
push
(
copy
);
// set new panel ids
for
(
i
=
0
;
i
<
copy
.
panels
.
length
;
i
++
)
{
panel
=
row
.
panels
[
i
];
panel
=
copy
.
panels
[
i
];
panel
.
id
=
dashboard
.
getNextPanelId
();
}
dashboard
.
rows
.
push
(
copy
);
}
else
{
copy
=
row
;
}
...
...
@@ -112,7 +109,6 @@ function (angular, _) {
panel
.
scopedVars
[
variable
.
name
]
=
option
;
}
});
};
this
.
getRepeatPanel
=
function
(
sourcePanel
,
row
)
{
...
...
@@ -155,4 +151,3 @@ function (angular, _) {
});
});
public/app/panels/graph/module.js
View file @
3044a74a
...
...
@@ -24,6 +24,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
});
module
.
controller
(
'GraphCtrl'
,
function
(
$scope
,
$rootScope
,
panelSrv
,
annotationsSrv
,
panelHelper
,
$q
)
{
console
.
log
(
'Graph: init: '
+
$scope
.
panel
.
id
);
$scope
.
panelMeta
=
new
PanelMeta
({
panelName
:
'Graph'
,
...
...
public/app/partials/dashboard.html
View file @
3044a74a
...
...
@@ -79,7 +79,7 @@
</div>
<!-- Panels, draggable needs to be disabled in fullscreen because Firefox bug -->
<div
ng-repeat=
"(name, panel) in row.panels"
class=
"panel"
<div
ng-repeat=
"(name, panel) in row.panels
track by panel.id
"
class=
"panel"
ui-draggable=
"{{!dashboardViewState.fullscreen}}"
drag=
"panel.id"
ui-on-Drop=
"onDrop($data, row, panel)"
drag-handle-class=
"drag-handle"
panel-width
>
...
...
public/test/specs/dynamicDashboardSrv-specs.js
View file @
3044a74a
...
...
@@ -4,62 +4,114 @@ define([
],
function
()
{
'use strict'
;
describe
(
'dynamicDashboardSrv'
,
function
()
{
var
_dynamicDashboardSrv
;
var
_dashboardSrv
;
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
inject
(
function
(
dynamicDashboardSrv
,
dashboardSrv
)
{
_dynamicDashboardSrv
=
dynamicDashboardSrv
;
_dashboardSrv
=
dashboardSrv
;
}));
describe
(
'given dashboard with panel repeat'
,
function
()
{
var
model
;
beforeEach
(
function
()
{
model
=
_dashboardSrv
.
create
({
rows
:
[
{
panels
:
[{
id
:
2
,
repeat
:
'$apps'
}]
}
],
templating
:
{
list
:
[{
name
:
'apps'
,
current
:
{
text
:
'se1, se2'
,
value
:
[
'se1'
,
'se2'
]
},
options
:
[
{
text
:
'se1'
,
value
:
'se1'
,
selected
:
true
},
{
text
:
'se2'
,
value
:
'se2'
,
selected
:
true
},
]
}]
}
},
{});
_dynamicDashboardSrv
.
init
(
model
);
});
function
dynamicDashScenario
(
desc
,
func
)
{
it
(
'should repeat panel one time'
,
function
()
{
expect
(
model
.
rows
[
0
].
panels
.
length
).
to
.
be
(
2
);
});
describe
(
desc
,
function
()
{
var
ctx
=
{};
ctx
.
setup
=
function
(
setupFunc
)
{
beforeEach
(
module
(
'grafana.services'
));
beforeEach
(
inject
(
function
(
dynamicDashboardSrv
,
dashboardSrv
)
{
ctx
.
dynamicDashboardSrv
=
dynamicDashboardSrv
;
ctx
.
dashboardSrv
=
dashboardSrv
;
var
model
=
{
rows
:
[],
templating
:
{
list
:
[]
}
};
setupFunc
(
model
);
ctx
.
dash
=
ctx
.
dashboardSrv
.
create
(
model
);
ctx
.
dynamicDashboardSrv
.
init
(
ctx
.
dash
);
ctx
.
rows
=
ctx
.
dash
.
rows
;
}));
it
(
'should mark panel repeated'
,
function
()
{
expect
(
model
.
rows
[
0
].
panels
[
0
].
linked
).
to
.
be
(
undefined
);
expect
(
model
.
rows
[
0
].
panels
[
0
].
repeat
).
to
.
be
(
'$apps'
);
expect
(
model
.
rows
[
0
].
panels
[
1
].
linked
).
to
.
be
(
true
);
expect
(
model
.
rows
[
0
].
panels
[
1
].
repeat
).
to
.
be
(
null
);
};
func
(
ctx
);
});
}
dynamicDashScenario
(
'given dashboard with panel repeat'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
dash
)
{
dash
.
rows
.
push
({
panels
:
[{
id
:
2
,
repeat
:
'$apps'
}]
});
dash
.
templating
.
list
.
push
({
name
:
'apps'
,
current
:
{
text
:
'se1, se2'
,
value
:
[
'se1'
,
'se2'
]
},
options
:
[
{
text
:
'se1'
,
value
:
'se1'
,
selected
:
true
},
{
text
:
'se2'
,
value
:
'se2'
,
selected
:
true
},
]
});
});
it
(
'should repeat panel one time'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
panels
.
length
).
to
.
be
(
2
);
});
it
(
'should set scopedVars on panels'
,
function
()
{
expect
(
model
.
rows
[
0
].
panels
[
0
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se1'
);
expect
(
model
.
rows
[
0
].
panels
[
1
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se2'
);
it
(
'should mark panel repeated'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
linked
).
to
.
be
(
undefined
);
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
repeat
).
to
.
be
(
'$apps'
);
expect
(
ctx
.
rows
[
0
].
panels
[
1
].
linked
).
to
.
be
(
true
);
expect
(
ctx
.
rows
[
0
].
panels
[
1
].
repeat
).
to
.
be
(
null
);
});
it
(
'should set scopedVars on panels'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se1'
);
expect
(
ctx
.
rows
[
0
].
panels
[
1
].
scopedVars
.
apps
.
value
).
to
.
be
(
'se2'
);
});
});
dynamicDashScenario
(
'given dashboard with row repeat'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
dash
)
{
dash
.
rows
.
push
({
repeat
:
'$servers'
,
panels
:
[{
id
:
2
}]
});
dash
.
templating
.
list
.
push
({
name
:
'servers'
,
current
:
{
text
:
'se1, se2'
,
value
:
[
'se1'
,
'se2'
]
},
options
:
[
{
text
:
'se1'
,
value
:
'se1'
,
selected
:
true
},
{
text
:
'se2'
,
value
:
'se2'
,
selected
:
true
},
]
});
});
it
(
'should repeat row one time'
,
function
()
{
expect
(
ctx
.
rows
.
length
).
to
.
be
(
2
);
});
it
(
'should keep panel ids on first row'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
id
).
to
.
be
(
2
);
});
it
(
'should mark second row as repeated'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
linked
).
to
.
be
(
undefined
);
expect
(
ctx
.
rows
[
0
].
repeat
).
to
.
be
(
'$servers'
);
expect
(
ctx
.
rows
[
1
].
linked
).
to
.
be
(
true
);
expect
(
ctx
.
rows
[
1
].
repeat
).
to
.
be
(
null
);
});
it
(
'should set scopedVars on row panels'
,
function
()
{
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
scopedVars
.
servers
.
value
).
to
.
be
(
'se1'
);
expect
(
ctx
.
rows
[
1
].
panels
[
0
].
scopedVars
.
servers
.
value
).
to
.
be
(
'se2'
);
});
});
});
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