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
e1433ebb
Commit
e1433ebb
authored
Nov 05, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(tablepanel) more refactoring
parent
1b83742e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
78 deletions
+76
-78
public/app/panels/table/module.ts
+3
-68
public/app/panels/table/renderer.ts
+60
-3
public/app/panels/table/specs/renderer_specs.ts
+13
-6
public/app/plugins/datasource/influxdb/partials/config.html
+0
-1
No files found.
public/app/panels/table/module.ts
View file @
e1433ebb
...
...
@@ -7,6 +7,7 @@ import kbn = require('app/core/utils/kbn');
import
moment
=
require
(
'moment'
);
import
{
TablePanelCtrl
}
from
'./controller'
;
import
{
TableRenderer
}
from
'./renderer'
;
import
{
tablePanelEditor
}
from
'./editor'
;
export
function
tablePanel
()
{
...
...
@@ -29,76 +30,10 @@ export function tablePanel() {
return
(
panelHeight
-
40
)
+
'px'
;
}
function
createColumnFormater
(
style
)
{
return
function
(
v
)
{
if
(
v
===
null
||
v
===
void
0
)
{
return
'-'
;
}
if
(
_
.
isString
(
v
)
||
!
style
)
{
return
v
;
}
if
(
style
.
type
===
'date'
)
{
if
(
_
.
isArray
(
v
))
{
v
=
v
[
0
];
}
var
date
=
moment
(
v
);
return
date
.
format
(
style
.
dateFormat
);
}
if
(
_
.
isNumber
(
v
)
&&
style
.
type
===
'number'
)
{
let
valueFormater
=
kbn
.
valueFormats
[
style
.
unit
];
return
valueFormater
(
v
,
style
.
decimals
);
}
if
(
_
.
isArray
(
v
))
{
v
=
v
.
join
(
', '
);
}
return
v
;
};
}
function
formatColumnValue
(
colIndex
,
value
)
{
if
(
formaters
[
colIndex
])
{
return
formaters
[
colIndex
](
value
);
}
for
(
let
i
=
0
;
i
<
panel
.
columns
.
length
;
i
++
)
{
let
style
=
panel
.
columns
[
i
];
let
column
=
data
.
columns
[
colIndex
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
if
(
column
.
text
.
match
(
regex
))
{
formaters
[
colIndex
]
=
createColumnFormater
(
style
);
return
formaters
[
colIndex
](
value
);
}
}
formaters
[
colIndex
]
=
function
(
v
)
{
return
v
;
};
return
formaters
[
colIndex
](
value
);
}
function
appendTableRows
(
tbodyElem
)
{
let
rowElements
=
$
(
document
.
createDocumentFragment
());
let
rowEnd
=
Math
.
min
(
panel
.
pageSize
,
data
.
rows
.
length
);
let
rowStart
=
0
;
// reset formater cache
formaters
=
[];
for
(
var
y
=
rowStart
;
y
<
rowEnd
;
y
++
)
{
let
row
=
data
.
rows
[
y
];
let
rowElem
=
$
(
'<tr></tr>'
);
for
(
var
i
=
0
;
i
<
data
.
columns
.
length
;
i
++
)
{
var
colValue
=
formatColumnValue
(
i
,
row
[
i
]);
let
colElem
=
$
(
'<td> '
+
colValue
+
'</td>'
);
rowElem
.
append
(
colElem
);
}
rowElements
.
append
(
rowElem
);
}
var
renderer
=
new
TableRenderer
(
panel
,
data
,
scope
.
dashboard
.
timezone
);
tbodyElem
.
empty
();
tbodyElem
.
append
(
rowElements
);
tbodyElem
.
html
(
renderer
.
render
(
0
)
);
}
function
appendPaginationControls
(
footerElem
)
{
...
...
public/app/panels/table/renderer.ts
View file @
e1433ebb
///<reference path="../../headers/common.d.ts" />
import
_
=
require
(
'lodash'
);
import
kbn
=
require
(
'app/core/utils/kbn'
);
import
moment
=
require
(
'moment'
);
export
class
TableRenderer
{
constructor
(
private
panel
,
private
table
)
{
formaters
:
any
[];
constructor
(
private
panel
,
private
table
,
private
timezone
)
{
this
.
formaters
=
[];
}
formatColumnValue
(
columnIndex
,
value
)
{
return
"value"
;
createColumnFormater
(
style
)
{
return
(
v
)
=>
{
if
(
v
===
null
||
v
===
void
0
)
{
return
'-'
;
}
if
(
_
.
isString
(
v
)
||
!
style
)
{
return
v
;
}
if
(
style
.
type
===
'date'
)
{
if
(
_
.
isArray
(
v
))
{
v
=
v
[
0
];
}
var
date
=
moment
(
v
);
if
(
this
.
timezone
===
'utc'
)
{
date
=
date
.
utc
();
}
return
date
.
format
(
style
.
dateFormat
);
}
if
(
_
.
isNumber
(
v
)
&&
style
.
type
===
'number'
)
{
let
valueFormater
=
kbn
.
valueFormats
[
style
.
unit
];
return
valueFormater
(
v
,
style
.
decimals
);
}
if
(
_
.
isArray
(
v
))
{
v
=
v
.
join
(
', '
);
}
return
v
;
};
}
formatColumnValue
(
colIndex
,
value
)
{
if
(
this
.
formaters
[
colIndex
])
{
return
this
.
formaters
[
colIndex
](
value
);
}
for
(
let
i
=
0
;
i
<
this
.
panel
.
columns
.
length
;
i
++
)
{
let
style
=
this
.
panel
.
columns
[
i
];
let
column
=
this
.
table
.
columns
[
colIndex
];
var
regex
=
kbn
.
stringToJsRegex
(
style
.
pattern
);
if
(
column
.
text
.
match
(
regex
))
{
this
.
formaters
[
colIndex
]
=
this
.
createColumnFormater
(
style
);
return
this
.
formaters
[
colIndex
](
value
);
}
}
this
.
formaters
[
colIndex
]
=
function
(
v
)
{
return
v
;
};
return
this
.
formaters
[
colIndex
](
value
);
}
renderCell
(
columnIndex
,
value
)
{
...
...
public/app/panels/table/specs/renderer_specs.ts
View file @
e1433ebb
...
...
@@ -7,16 +7,23 @@ describe('when rendering table', () => {
describe
(
'given 2 columns'
,
()
=>
{
var
table
=
new
TableModel
();
table
.
columns
=
[{
text
:
'Time'
},
{
text
:
'Value'
}];
table
.
rows
.
push
([
1446733230253
,
12.4
]);
table
.
rows
.
push
([
1446733231253
,
10.4
]);
var
panel
=
{
pageSize
:
10
pageSize
:
10
,
columns
:
[
{
pattern
:
'Time'
,
type
:
'date'
,
format
:
'LLL'
}
]
};
it
(
'render should return html'
,
()
=>
{
var
html
=
new
TableRenderer
(
panel
,
table
).
render
(
0
);
expect
(
html
).
to
.
be
(
'<tr><td>value</td></tr>'
);
var
renderer
=
new
TableRenderer
(
panel
,
table
,
'utc'
);
it
(
'time column should be formated'
,
()
=>
{
var
html
=
renderer
.
renderCell
(
0
,
1388556366666
);
expect
(
html
).
to
.
be
(
'<td>2014-01-01T06:06:06+00:00</td>'
);
});
});
...
...
public/app/plugins/datasource/influxdb/partials/config.html
View file @
e1433ebb
<div
ng-include=
"httpConfigPartialSrc"
></div>
<br>
...
...
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