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
29653d2b
Commit
29653d2b
authored
May 05, 2017
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and add column alias tests
parent
2361e2dd
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
50 deletions
+61
-50
public/app/core/utils/file_export.ts
+1
-1
public/app/plugins/panel/table/module.html
+1
-1
public/app/plugins/panel/table/module.ts
+5
-20
public/app/plugins/panel/table/renderer.ts
+36
-25
public/app/plugins/panel/table/specs/renderer_specs.ts
+16
-2
public/app/plugins/panel/table/transformers.ts
+2
-1
No files found.
public/app/core/utils/file_export.ts
View file @
29653d2b
...
@@ -53,7 +53,7 @@ export function exportTableDataToCsv(table) {
...
@@ -53,7 +53,7 @@ export function exportTableDataToCsv(table) {
var
text
=
'sep=;
\
n'
;
var
text
=
'sep=;
\
n'
;
// add header
// add header
_
.
each
(
table
.
columns
,
function
(
column
)
{
_
.
each
(
table
.
columns
,
function
(
column
)
{
text
+=
column
.
text
+
';'
;
text
+=
(
column
.
title
||
column
.
text
)
+
';'
;
});
});
text
+=
'
\
n'
;
text
+=
'
\
n'
;
// process data
// process data
...
...
public/app/plugins/panel/table/module.html
View file @
29653d2b
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<tr>
<tr>
<th
ng-repeat=
"col in ctrl.table.columns"
ng-hide=
"col.hidden"
>
<th
ng-repeat=
"col in ctrl.table.columns"
ng-hide=
"col.hidden"
>
<div
class=
"table-panel-table-header-inner pointer"
ng-click=
"ctrl.toggleColumnSort(col, $index)"
>
<div
class=
"table-panel-table-header-inner pointer"
ng-click=
"ctrl.toggleColumnSort(col, $index)"
>
{{col.title
|| col.text
}}
{{col.title}}
<span
class=
"table-panel-table-header-controls"
ng-if=
"col.sort"
>
<span
class=
"table-panel-table-header-controls"
ng-if=
"col.sort"
>
<i
class=
"fa fa-caret-down"
ng-show=
"col.desc"
></i>
<i
class=
"fa fa-caret-down"
ng-show=
"col.desc"
></i>
<i
class=
"fa fa-caret-up"
ng-hide=
"col.desc"
></i>
<i
class=
"fa fa-caret-up"
ng-hide=
"col.desc"
></i>
...
...
public/app/plugins/panel/table/module.ts
View file @
29653d2b
...
@@ -17,6 +17,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -17,6 +17,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
pageIndex
:
number
;
pageIndex
:
number
;
dataRaw
:
any
;
dataRaw
:
any
;
table
:
any
;
table
:
any
;
renderer
:
any
;
panelDefaults
=
{
panelDefaults
=
{
targets
:
[{}],
targets
:
[{}],
...
@@ -122,22 +123,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -122,22 +123,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
this
.
table
=
transformDataToTable
(
this
.
dataRaw
,
this
.
panel
);
this
.
table
=
transformDataToTable
(
this
.
dataRaw
,
this
.
panel
);
this
.
table
.
sort
(
this
.
panel
.
sort
);
this
.
table
.
sort
(
this
.
panel
.
sort
);
for
(
let
colIndex
=
0
;
colIndex
<
this
.
table
.
columns
.
length
;
colIndex
++
)
{
this
.
renderer
=
new
TableRenderer
(
this
.
panel
,
this
.
table
,
this
.
dashboard
.
isTimezoneUtc
(),
this
.
$sanitize
);
let
column
=
this
.
table
.
columns
[
colIndex
];
for
(
let
i
=
0
;
i
<
this
.
panel
.
styles
.
length
;
i
++
)
{
let
style
=
this
.
panel
.
styles
[
i
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
const
matches
=
column
.
text
.
match
(
regex
);
if
(
matches
)
{
column
.
style
=
style
;
if
(
style
.
alias
)
{
column
.
title
=
column
.
text
.
replace
(
regex
,
style
.
alias
);
}
break
;
}
}
}
return
super
.
render
(
this
.
table
);
return
super
.
render
(
this
.
table
);
}
}
...
@@ -162,8 +148,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -162,8 +148,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
}
}
exportCsv
()
{
exportCsv
()
{
var
renderer
=
new
TableRenderer
(
this
.
panel
,
this
.
table
,
this
.
dashboard
.
isTimezoneUtc
(),
this
.
$sanitize
);
FileExport
.
exportTableDataToCsv
(
this
.
renderer
.
render_values
());
FileExport
.
exportTableDataToCsv
(
renderer
.
render_values
());
}
}
link
(
scope
,
elem
,
attrs
,
ctrl
)
{
link
(
scope
,
elem
,
attrs
,
ctrl
)
{
...
@@ -183,9 +168,9 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -183,9 +168,9 @@ class TablePanelCtrl extends MetricsPanelCtrl {
}
}
function
appendTableRows
(
tbodyElem
)
{
function
appendTableRows
(
tbodyElem
)
{
var
renderer
=
new
TableRenderer
(
panel
,
data
,
ctrl
.
dashboard
.
isTimezoneUtc
(),
ctrl
.
$sanitize
);
ctrl
.
renderer
.
setTable
(
data
);
tbodyElem
.
empty
();
tbodyElem
.
empty
();
tbodyElem
.
html
(
renderer
.
render
(
ctrl
.
pageIndex
));
tbodyElem
.
html
(
ctrl
.
renderer
.
render
(
ctrl
.
pageIndex
));
}
}
function
switchPage
(
e
)
{
function
switchPage
(
e
)
{
...
...
public/app/plugins/panel/table/renderer.ts
View file @
29653d2b
...
@@ -5,12 +5,44 @@ import moment from 'moment';
...
@@ -5,12 +5,44 @@ import moment from 'moment';
import
kbn
from
'app/core/utils/kbn'
;
import
kbn
from
'app/core/utils/kbn'
;
export
class
TableRenderer
{
export
class
TableRenderer
{
formaters
:
any
[];
format
t
ers
:
any
[];
colorState
:
any
;
colorState
:
any
;
constructor
(
private
panel
,
private
table
,
private
isUtc
,
private
sanitize
)
{
constructor
(
private
panel
,
private
table
,
private
isUtc
,
private
sanitize
)
{
this
.
formaters
=
[];
this
.
initColumns
();
}
setTable
(
table
)
{
this
.
table
=
table
;
this
.
initColumns
();
}
initColumns
()
{
this
.
formatters
=
[];
this
.
colorState
=
{};
this
.
colorState
=
{};
for
(
let
colIndex
=
0
;
colIndex
<
this
.
table
.
columns
.
length
;
colIndex
++
)
{
let
column
=
this
.
table
.
columns
[
colIndex
];
column
.
title
=
column
.
text
;
for
(
let
i
=
0
;
i
<
this
.
panel
.
styles
.
length
;
i
++
)
{
let
style
=
this
.
panel
.
styles
[
i
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
if
(
column
.
text
.
match
(
regex
))
{
column
.
style
=
style
;
if
(
style
.
alias
)
{
column
.
title
=
column
.
text
.
replace
(
regex
,
style
.
alias
);
}
break
;
}
}
this
.
formatters
[
colIndex
]
=
this
.
createColumnFormatter
(
column
);
}
}
}
getColorForValue
(
value
,
style
)
{
getColorForValue
(
value
,
style
)
{
...
@@ -92,28 +124,7 @@ export class TableRenderer {
...
@@ -92,28 +124,7 @@ export class TableRenderer {
}
}
formatColumnValue
(
colIndex
,
value
)
{
formatColumnValue
(
colIndex
,
value
)
{
if
(
!
this
.
formaters
[
colIndex
])
{
return
this
.
formatters
[
colIndex
]
?
this
.
formatters
[
colIndex
](
value
)
:
value
;
let
column
=
this
.
table
.
columns
[
colIndex
];
if
(
!
column
.
style
)
{
for
(
let
i
=
0
;
i
<
this
.
panel
.
styles
.
length
;
i
++
)
{
let
style
=
this
.
panel
.
styles
[
i
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
const
matches
=
column
.
text
.
match
(
regex
);
if
(
matches
)
{
column
.
style
=
style
;
if
(
style
.
alias
)
{
column
.
title
=
column
.
text
.
replace
(
regex
,
style
.
alias
);
}
break
;
}
}
}
this
.
formaters
[
colIndex
]
=
this
.
createColumnFormatter
(
column
);
}
return
this
.
formaters
[
colIndex
](
value
);
}
}
renderCell
(
columnIndex
,
value
,
addWidthHack
=
false
)
{
renderCell
(
columnIndex
,
value
,
addWidthHack
=
false
)
{
...
@@ -132,7 +143,7 @@ export class TableRenderer {
...
@@ -132,7 +143,7 @@ export class TableRenderer {
// this hack adds header content to cell (not visible)
// this hack adds header content to cell (not visible)
var
widthHack
=
''
;
var
widthHack
=
''
;
if
(
addWidthHack
)
{
if
(
addWidthHack
)
{
widthHack
=
'<div class="table-panel-width-hack">'
+
this
.
table
.
columns
[
columnIndex
].
t
ext
+
'</div>'
;
widthHack
=
'<div class="table-panel-width-hack">'
+
this
.
table
.
columns
[
columnIndex
].
t
itle
+
'</div>'
;
}
}
if
(
value
===
undefined
)
{
if
(
value
===
undefined
)
{
...
...
public/app/plugins/panel/table/specs/renderer_specs.ts
View file @
29653d2b
...
@@ -22,13 +22,15 @@ describe('when rendering table', () => {
...
@@ -22,13 +22,15 @@ describe('when rendering table', () => {
{
{
pattern
:
'Time'
,
pattern
:
'Time'
,
type
:
'date'
,
type
:
'date'
,
format
:
'LLL'
format
:
'LLL'
,
alias
:
'Timestamp'
},
},
{
{
pattern
:
'
Value
'
,
pattern
:
'
/(Val)ue/
'
,
type
:
'number'
,
type
:
'number'
,
unit
:
'ms'
,
unit
:
'ms'
,
decimals
:
3
,
decimals
:
3
,
alias
:
'$1'
},
},
{
{
pattern
:
'Colored'
,
pattern
:
'Colored'
,
...
@@ -132,6 +134,18 @@ describe('when rendering table', () => {
...
@@ -132,6 +134,18 @@ describe('when rendering table', () => {
var
html
=
renderer
.
renderCell
(
6
,
'text <a href="http://google.com">link</a>'
);
var
html
=
renderer
.
renderCell
(
6
,
'text <a href="http://google.com">link</a>'
);
expect
(
html
).
to
.
be
(
'<td>sanitized</td>'
);
expect
(
html
).
to
.
be
(
'<td>sanitized</td>'
);
});
});
it
(
'Time column title should be Timestamp'
,
()
=>
{
expect
(
table
.
columns
[
0
].
title
).
to
.
be
(
'Timestamp'
);
});
it
(
'Value column title should be Val'
,
()
=>
{
expect
(
table
.
columns
[
1
].
title
).
to
.
be
(
'Val'
);
});
it
(
'Colored column title should be Colored'
,
()
=>
{
expect
(
table
.
columns
[
2
].
title
).
to
.
be
(
'Colored'
);
});
});
});
});
});
...
...
public/app/plugins/panel/table/transformers.ts
View file @
29653d2b
...
@@ -229,7 +229,7 @@ function transformDataToTable(data, panel) {
...
@@ -229,7 +229,7 @@ function transformDataToTable(data, panel) {
var
transformer
=
transformers
[
panel
.
transform
];
var
transformer
=
transformers
[
panel
.
transform
];
if
(
!
transformer
)
{
if
(
!
transformer
)
{
throw
{
message
:
'Transformer '
+
panel
.
transform
er
+
' not found'
};
throw
{
message
:
'Transformer '
+
panel
.
transform
+
' not found'
};
}
}
if
(
panel
.
filterNull
)
{
if
(
panel
.
filterNull
)
{
...
@@ -239,6 +239,7 @@ function transformDataToTable(data, panel) {
...
@@ -239,6 +239,7 @@ function transformDataToTable(data, panel) {
}
}
transformer
.
transform
(
copyData
,
panel
,
model
);
transformer
.
transform
(
copyData
,
panel
,
model
);
return
model
;
return
model
;
}
}
...
...
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