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
b1691f1c
Commit
b1691f1c
authored
Apr 27, 2017
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for column aliases in table panel
parent
24e37778
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
27 deletions
+73
-27
public/app/plugins/panel/table/editor.html
+22
-4
public/app/plugins/panel/table/editor.ts
+1
-0
public/app/plugins/panel/table/module.html
+1
-1
public/app/plugins/panel/table/module.ts
+21
-0
public/app/plugins/panel/table/renderer.ts
+28
-22
No files found.
public/app/plugins/panel/table/editor.html
View file @
b1691f1c
...
@@ -67,11 +67,10 @@
...
@@ -67,11 +67,10 @@
<select
class=
"gf-form-input"
ng-model=
"style.type"
ng-options=
"c.value as c.text for c in editor.columnTypes"
ng-change=
"editor.render()"
></select>
<select
class=
"gf-form-input"
ng-model=
"style.type"
ng-options=
"c.value as c.text for c in editor.columnTypes"
ng-change=
"editor.render()"
></select>
</div>
</div>
</div>
</div>
<div
class=
"gf-form"
ng-if=
"style.type
=== 'date
'"
>
<div
class=
"gf-form"
ng-if=
"style.type
!== 'hidden
'"
>
<label
class=
"gf-form-label"
>
Format
</label>
<label
class=
"gf-form-label"
>
Title
</label>
<
metric-segment-model
property=
"style.dateFormat"
options=
"editor.dateFormats"
on-change=
"editor.render()"
custom=
"true"
></metric-segment-model
>
<
input
type=
"text"
class=
"gf-form-input"
ng-model=
"style.alias"
ng-change=
"editor.render()"
ng-model-onblur
>
</div>
</div>
<gf-form-switch
class=
"gf-form"
label-class=
"width-8"
ng-if=
"style.type === 'string'"
label=
"Sanitize HTML"
checked=
"style.sanitize"
change=
"editor.render()"
></gf-form-switch>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
</div>
</div>
...
@@ -84,6 +83,25 @@
...
@@ -84,6 +83,25 @@
</div>
</div>
</div>
</div>
<div
class=
"gf-form-inline"
ng-if=
"style.type === 'date'"
>
<div
class=
"gf-form offset-width-8"
>
<label
class=
"gf-form-label width-8"
>
Format
</label>
</div>
<div
class=
"gf-form"
>
<metric-segment-model
property=
"style.dateFormat"
options=
"editor.dateFormats"
on-change=
"editor.render()"
custom=
"true"
></metric-segment-model>
</div>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
</div>
</div>
<div
class=
"gf-form-inline"
ng-if=
"style.type === 'string'"
>
<gf-form-switch
class=
"gf-form offset-width-8"
label-class=
"width-8"
ng-if=
"style.type === 'string'"
label=
"Sanitize HTML"
checked=
"style.sanitize"
change=
"editor.render()"
></gf-form-switch>
<div
class=
"gf-form gf-form--grow"
>
<div
class=
"gf-form-label gf-form-label--grow"
></div>
</div>
</div>
<div
class=
"gf-form-inline"
ng-if=
"style.type === 'number'"
>
<div
class=
"gf-form-inline"
ng-if=
"style.type === 'number'"
>
<div
class=
"gf-form offset-width-8"
>
<div
class=
"gf-form offset-width-8"
>
<label
class=
"gf-form-label width-8"
>
Unit
</label>
<label
class=
"gf-form-label width-8"
>
Unit
</label>
...
...
public/app/plugins/panel/table/editor.ts
View file @
b1691f1c
...
@@ -107,6 +107,7 @@ export class TablePanelEditorCtrl {
...
@@ -107,6 +107,7 @@ export class TablePanelEditorCtrl {
var
columnStyleDefaults
=
{
var
columnStyleDefaults
=
{
unit
:
'short'
,
unit
:
'short'
,
type
:
'number'
,
type
:
'number'
,
alias
:
''
,
decimals
:
2
,
decimals
:
2
,
colors
:
[
"rgba(245, 54, 54, 0.9)"
,
"rgba(237, 129, 40, 0.89)"
,
"rgba(50, 172, 45, 0.97)"
],
colors
:
[
"rgba(245, 54, 54, 0.9)"
,
"rgba(237, 129, 40, 0.89)"
,
"rgba(50, 172, 45, 0.97)"
],
colorMode
:
null
,
colorMode
:
null
,
...
...
public/app/plugins/panel/table/module.html
View file @
b1691f1c
...
@@ -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.text}}
{{col.t
itle || col.t
ext}}
<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 @
b1691f1c
...
@@ -9,6 +9,7 @@ import {MetricsPanelCtrl} from 'app/plugins/sdk';
...
@@ -9,6 +9,7 @@ import {MetricsPanelCtrl} from 'app/plugins/sdk';
import
{
transformDataToTable
}
from
'./transformers'
;
import
{
transformDataToTable
}
from
'./transformers'
;
import
{
tablePanelEditor
}
from
'./editor'
;
import
{
tablePanelEditor
}
from
'./editor'
;
import
{
TableRenderer
}
from
'./renderer'
;
import
{
TableRenderer
}
from
'./renderer'
;
import
kbn
from
'app/core/utils/kbn'
;
class
TablePanelCtrl
extends
MetricsPanelCtrl
{
class
TablePanelCtrl
extends
MetricsPanelCtrl
{
static
templateUrl
=
'module.html'
;
static
templateUrl
=
'module.html'
;
...
@@ -26,11 +27,13 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -26,11 +27,13 @@ class TablePanelCtrl extends MetricsPanelCtrl {
{
{
type
:
'date'
,
type
:
'date'
,
pattern
:
'Time'
,
pattern
:
'Time'
,
alias
:
'Time'
,
dateFormat
:
'YYYY-MM-DD HH:mm:ss'
,
dateFormat
:
'YYYY-MM-DD HH:mm:ss'
,
},
},
{
{
unit
:
'short'
,
unit
:
'short'
,
type
:
'number'
,
type
:
'number'
,
alias
:
''
,
decimals
:
2
,
decimals
:
2
,
colors
:
[
"rgba(245, 54, 54, 0.9)"
,
"rgba(237, 129, 40, 0.89)"
,
"rgba(50, 172, 45, 0.97)"
],
colors
:
[
"rgba(245, 54, 54, 0.9)"
,
"rgba(237, 129, 40, 0.89)"
,
"rgba(50, 172, 45, 0.97)"
],
colorMode
:
null
,
colorMode
:
null
,
...
@@ -118,6 +121,24 @@ class TablePanelCtrl extends MetricsPanelCtrl {
...
@@ -118,6 +121,24 @@ class TablePanelCtrl extends MetricsPanelCtrl {
render
()
{
render
()
{
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
++
)
{
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
);
}
}
...
...
public/app/plugins/panel/table/renderer.ts
View file @
b1691f1c
...
@@ -24,7 +24,7 @@ export class TableRenderer {
...
@@ -24,7 +24,7 @@ export class TableRenderer {
return
_
.
first
(
style
.
colors
);
return
_
.
first
(
style
.
colors
);
}
}
defaultCellFormater
(
v
,
style
)
{
defaultCellFormat
t
er
(
v
,
style
)
{
if
(
v
===
null
||
v
===
void
0
||
v
===
undefined
)
{
if
(
v
===
null
||
v
===
void
0
||
v
===
undefined
)
{
return
''
;
return
''
;
}
}
...
@@ -40,18 +40,18 @@ export class TableRenderer {
...
@@ -40,18 +40,18 @@ export class TableRenderer {
}
}
}
}
createColumnFormat
er
(
style
,
column
)
{
createColumnFormat
ter
(
column
)
{
if
(
!
style
)
{
if
(
!
column
.
style
)
{
return
this
.
defaultCellFormater
;
return
this
.
defaultCellFormat
t
er
;
}
}
if
(
style
.
type
===
'hidden'
)
{
if
(
column
.
style
.
type
===
'hidden'
)
{
return
v
=>
{
return
v
=>
{
return
undefined
;
return
undefined
;
};
};
}
}
if
(
style
.
type
===
'date'
)
{
if
(
column
.
style
.
type
===
'date'
)
{
return
v
=>
{
return
v
=>
{
if
(
v
===
undefined
||
v
===
null
)
{
if
(
v
===
undefined
||
v
===
null
)
{
return
'-'
;
return
'-'
;
...
@@ -62,12 +62,12 @@ export class TableRenderer {
...
@@ -62,12 +62,12 @@ export class TableRenderer {
if
(
this
.
isUtc
)
{
if
(
this
.
isUtc
)
{
date
=
date
.
utc
();
date
=
date
.
utc
();
}
}
return
date
.
format
(
style
.
dateFormat
);
return
date
.
format
(
column
.
style
.
dateFormat
);
};
};
}
}
if
(
style
.
type
===
'number'
)
{
if
(
column
.
style
.
type
===
'number'
)
{
let
valueFormat
er
=
kbn
.
valueFormats
[
column
.
unit
||
style
.
unit
];
let
valueFormat
ter
=
kbn
.
valueFormats
[
column
.
unit
||
column
.
style
.
unit
];
return
v
=>
{
return
v
=>
{
if
(
v
===
null
||
v
===
void
0
)
{
if
(
v
===
null
||
v
===
void
0
)
{
...
@@ -75,38 +75,44 @@ export class TableRenderer {
...
@@ -75,38 +75,44 @@ export class TableRenderer {
}
}
if
(
_
.
isString
(
v
))
{
if
(
_
.
isString
(
v
))
{
return
this
.
defaultCellFormat
er
(
v
,
style
);
return
this
.
defaultCellFormat
ter
(
v
,
column
.
style
);
}
}
if
(
style
.
colorMode
)
{
if
(
column
.
style
.
colorMode
)
{
this
.
colorState
[
style
.
colorMode
]
=
this
.
getColorForValue
(
v
,
style
);
this
.
colorState
[
column
.
style
.
colorMode
]
=
this
.
getColorForValue
(
v
,
column
.
style
);
}
}
return
valueFormat
er
(
v
,
style
.
decimals
,
null
);
return
valueFormat
ter
(
v
,
column
.
style
.
decimals
,
null
);
};
};
}
}
return
(
value
)
=>
{
return
(
value
)
=>
{
return
this
.
defaultCellFormat
er
(
value
,
style
);
return
this
.
defaultCellFormat
ter
(
value
,
column
.
style
);
};
};
}
}
formatColumnValue
(
colIndex
,
value
)
{
formatColumnValue
(
colIndex
,
value
)
{
if
(
this
.
formaters
[
colIndex
])
{
if
(
!
this
.
formaters
[
colIndex
])
{
return
this
.
formaters
[
colIndex
](
value
);
let
column
=
this
.
table
.
columns
[
colIndex
];
}
if
(
!
column
.
style
)
{
for
(
let
i
=
0
;
i
<
this
.
panel
.
styles
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
this
.
panel
.
styles
.
length
;
i
++
)
{
let
style
=
this
.
panel
.
styles
[
i
];
let
style
=
this
.
panel
.
styles
[
i
];
let
column
=
this
.
table
.
columns
[
colIndex
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
if
(
column
.
text
.
match
(
regex
))
{
const
matches
=
column
.
text
.
match
(
regex
);
this
.
formaters
[
colIndex
]
=
this
.
createColumnFormater
(
style
,
column
);
if
(
matches
)
{
return
this
.
formaters
[
colIndex
](
value
);
column
.
style
=
style
;
if
(
style
.
alias
)
{
column
.
title
=
column
.
text
.
replace
(
regex
,
style
.
alias
);
}
}
break
;
}
}
}
this
.
formaters
[
colIndex
]
=
this
.
createColumnFormatter
(
column
);
}
}
this
.
formaters
[
colIndex
]
=
this
.
defaultCellFormater
;
return
this
.
formaters
[
colIndex
](
value
);
return
this
.
formaters
[
colIndex
](
value
);
}
}
...
...
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