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
9590f485
Commit
9590f485
authored
Apr 28, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More optimizations and unit tests for panel repeats, this time reuse rows, #1888
parent
32fe723d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
42 deletions
+64
-42
public/app/features/dashboard/dynamicDashboardSrv.js
+36
-41
public/test/specs/dynamicDashboardSrv-specs.js
+28
-1
No files found.
public/app/features/dashboard/dynamicDashboardSrv.js
View file @
9590f485
...
...
@@ -26,21 +26,6 @@ function (angular, _) {
this
.
handleRowRepeats
(
dashboard
);
};
this
.
removeLinkedPanels
=
function
(
dashboard
)
{
var
i
,
j
,
row
,
panel
;
for
(
i
=
0
;
i
<
dashboard
.
rows
.
length
;
i
++
)
{
row
=
dashboard
.
rows
[
i
];
for
(
j
=
0
;
j
<
row
.
panels
.
length
;
j
++
)
{
panel
=
row
.
panels
[
j
];
if
(
panel
.
linked
)
{
row
.
panels
=
_
.
without
(
row
.
panels
,
panel
);
j
=
j
-
1
;
}
delete
panel
.
scopedVars
;
}
}
};
this
.
handlePanelRepeats
=
function
(
dashboard
)
{
var
i
,
j
,
row
,
panel
;
for
(
i
=
0
;
i
<
dashboard
.
rows
.
length
;
i
++
)
{
...
...
@@ -59,26 +44,51 @@ function (angular, _) {
}
};
this
.
removeLinkedRow
s
=
function
(
dashboard
)
{
this
.
handleRowRepeat
s
=
function
(
dashboard
)
{
var
i
,
row
;
for
(
i
=
0
;
i
<
dashboard
.
rows
.
length
;
i
++
)
{
row
=
dashboard
.
rows
[
i
];
if
(
row
.
linked
)
{
if
(
row
.
repeat
)
{
this
.
repeatRow
(
row
,
dashboard
);
}
// clean up old left overs
else
if
(
row
.
repeatRowId
&&
row
.
repeatIteration
!==
this
.
iteration
)
{
dashboard
.
rows
.
splice
(
i
,
1
);
i
=
i
-
1
;
}
}
};
this
.
handleRowRepeats
=
function
(
dashboard
)
{
this
.
removeLinkedRows
(
dashboard
);
var
i
,
row
;
for
(
i
=
0
;
i
<
dashboard
.
rows
.
length
;
i
++
)
{
row
=
dashboard
.
rows
[
i
];
if
(
row
.
repeat
)
{
this
.
repeatRow
(
row
,
dashboard
);
this
.
getRowClone
=
function
(
sourceRow
,
index
)
{
if
(
index
===
0
)
{
return
sourceRow
;
}
var
i
,
panel
,
row
;
var
sourceRowId
=
_
.
indexOf
(
this
.
dashboard
.
rows
,
sourceRow
)
+
1
;
// look for row to reuse
for
(
i
=
0
;
i
<
this
.
dashboard
.
rows
.
length
;
i
++
)
{
row
=
this
.
dashboard
.
rows
[
i
];
if
(
row
.
repeatRowId
===
sourceRowId
&&
row
.
repeatIteration
!==
this
.
iteration
)
{
row
.
repeatIteration
=
this
.
iteration
;
return
row
;
}
}
var
copy
=
angular
.
copy
(
sourceRow
);
copy
.
repeat
=
null
;
copy
.
repeatRowId
=
sourceRowId
;
copy
.
repeatIteration
=
this
.
iteration
;
this
.
dashboard
.
rows
.
push
(
copy
);
// set new panel ids
for
(
i
=
0
;
i
<
copy
.
panels
.
length
;
i
++
)
{
panel
=
copy
.
panels
[
i
];
panel
.
id
=
this
.
dashboard
.
getNextPanelId
();
}
return
copy
;
};
this
.
repeatRow
=
function
(
row
,
dashboard
)
{
...
...
@@ -96,21 +106,7 @@ function (angular, _) {
}
_
.
each
(
selected
,
function
(
option
,
index
)
{
if
(
index
>
0
)
{
copy
=
angular
.
copy
(
row
);
copy
.
repeat
=
null
;
copy
.
linked
=
true
;
dashboard
.
rows
.
push
(
copy
);
// set new panel ids
for
(
i
=
0
;
i
<
copy
.
panels
.
length
;
i
++
)
{
panel
=
copy
.
panels
[
i
];
panel
.
id
=
dashboard
.
getNextPanelId
();
}
}
else
{
copy
=
row
;
}
copy
=
self
.
getRowClone
(
row
,
index
);
for
(
i
=
0
;
i
<
copy
.
panels
.
length
;
i
++
)
{
panel
=
copy
.
panels
[
i
];
...
...
@@ -129,8 +125,7 @@ function (angular, _) {
// first try finding an existing clone to use
for
(
var
i
=
0
;
i
<
row
.
panels
.
length
;
i
++
)
{
var
panel
=
row
.
panels
[
i
];
if
(
panel
.
repeatIteration
!==
this
.
iteration
&&
panel
.
repeatPanelId
===
sourcePanel
.
id
)
{
if
(
panel
.
repeatIteration
!==
this
.
iteration
&&
panel
.
repeatPanelId
===
sourcePanel
.
id
)
{
panel
.
repeatIteration
=
this
.
iteration
;
return
panel
;
}
...
...
public/test/specs/dynamicDashboardSrv-specs.js
View file @
9590f485
...
...
@@ -133,6 +133,33 @@ define([
expect
(
ctx
.
rows
[
0
].
panels
[
0
].
scopedVars
.
servers
.
value
).
to
.
be
(
'se1'
);
expect
(
ctx
.
rows
[
1
].
panels
[
0
].
scopedVars
.
servers
.
value
).
to
.
be
(
'se2'
);
});
});
describe
(
'After a second iteration'
,
function
()
{
var
repeatedRowAfterFirstIteration
;
beforeEach
(
function
()
{
repeatedRowAfterFirstIteration
=
ctx
.
rows
[
1
];
ctx
.
dynamicDashboardSrv
.
update
(
ctx
.
dash
);
});
it
(
'should still only have 2 rows'
,
function
()
{
expect
(
ctx
.
rows
.
length
).
to
.
be
(
2
);
});
it
(
'should reuse row instance'
,
function
()
{
expect
(
ctx
.
rows
[
1
]).
to
.
be
(
repeatedRowAfterFirstIteration
);
});
});
describe
(
'After a second iteration and selected values reduced'
,
function
()
{
beforeEach
(
function
()
{
ctx
.
dash
.
templating
.
list
[
0
].
options
[
1
].
selected
=
false
;
ctx
.
dynamicDashboardSrv
.
update
(
ctx
.
dash
);
});
it
(
'should remove repeated second row'
,
function
()
{
expect
(
ctx
.
rows
.
length
).
to
.
be
(
1
);
});
});
});
});
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