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
ba65b89b
Commit
ba65b89b
authored
Jan 21, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(csv export): extract csv export into a new file
parent
3d353c7d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
36 deletions
+80
-36
public/app/core/utils/file_export.ts
+75
-0
public/app/core/utils/kbn.js
+0
-32
public/app/plugins/panel/graph/module.js
+3
-2
public/app/plugins/panel/table/controller.ts
+2
-2
No files found.
public/app/core/utils/file_export.ts
0 → 100644
View file @
ba65b89b
///<reference path="../../headers/common.d.ts" />
import
_
from
'lodash'
;
declare
var
window
:
any
;
export
function
exportSeriesListToCsv
(
seriesList
)
{
var
text
=
'Series;Time;Value
\
n'
;
_
.
each
(
seriesList
,
function
(
series
)
{
_
.
each
(
series
.
datapoints
,
function
(
dp
)
{
text
+=
series
.
alias
+
';'
+
new
Date
(
dp
[
1
]).
toISOString
()
+
';'
+
dp
[
0
]
+
'
\
n'
;
});
});
saveSaveBlob
(
text
,
'grafana_data_export.csv'
);
};
export
function
exportTableDataToCsv
(
table
)
{
var
text
=
''
;
// add header
_
.
each
(
table
.
columns
,
function
(
column
)
{
text
+=
column
.
text
+
';'
;
});
text
+=
'
\
n'
;
// process data
_
.
each
(
table
.
rows
,
function
(
row
)
{
_
.
each
(
row
,
function
(
value
)
{
text
+=
value
+
';'
;
});
text
+=
'
\
n'
;
});
saveSaveBlob
(
text
,
'grafana_data_export.csv'
);
};
export
function
saveSaveBlob
(
payload
,
fname
)
{
var
blob
=
new
Blob
([
payload
],
{
type
:
"text/csv;charset=utf-8"
});
window
.
saveAs
(
blob
,
fname
);
};
/*
export default function flatten(target, opts): any {
opts = opts || {};
var delimiter = opts.delimiter || '.';
var maxDepth = opts.maxDepth || 3;
var currentDepth = 1;
var output = {};
function step(object, prev) {
Object.keys(object).forEach(function(key) {
var value = object[key];
var isarray = opts.safe && Array.isArray(value);
var type = Object.prototype.toString.call(value);
var isobject = type === "[object Object]";
var newKey = prev ? prev + delimiter + key : key;
if (!opts.maxDepth) {
maxDepth = currentDepth + 1;
}
if (!isarray && isobject && Object.keys(value).length && currentDepth < maxDepth) {
++currentDepth;
return step(value, newKey);
}
output[newKey] = value;
});
}
step(target, null);
return output;
}
*/
\ No newline at end of file
public/app/core/utils/kbn.js
View file @
ba65b89b
...
@@ -179,38 +179,6 @@ function($, _) {
...
@@ -179,38 +179,6 @@ function($, _) {
.
replace
(
/ +/g
,
'-'
);
.
replace
(
/ +/g
,
'-'
);
};
};
kbn
.
exportSeriesListToCsv
=
function
(
seriesList
)
{
var
text
=
'Series;Time;Value
\
n'
;
_
.
each
(
seriesList
,
function
(
series
)
{
_
.
each
(
series
.
datapoints
,
function
(
dp
)
{
text
+=
series
.
alias
+
';'
+
new
Date
(
dp
[
1
]).
toISOString
()
+
';'
+
dp
[
0
]
+
'
\
n'
;
});
});
kbn
.
saveSaveBlob
(
text
,
'grafana_data_export.csv'
);
};
kbn
.
exportTableDataToCsv
=
function
(
table
)
{
var
text
=
''
;
// add header
_
.
each
(
table
.
columns
,
function
(
column
)
{
text
+=
column
.
text
+
';'
;
});
text
+=
'
\
n'
;
// process data
_
.
each
(
table
.
rows
,
function
(
row
)
{
_
.
each
(
row
,
function
(
value
)
{
text
+=
value
+
';'
;
});
text
+=
'
\
n'
;
});
kbn
.
saveSaveBlob
(
text
,
'grafana_data_export.csv'
);
};
kbn
.
saveSaveBlob
=
function
(
payload
,
fname
)
{
var
blob
=
new
Blob
([
payload
],
{
type
:
"text/csv;charset=utf-8"
});
window
.
saveAs
(
blob
,
fname
);
};
kbn
.
stringToJsRegex
=
function
(
str
)
{
kbn
.
stringToJsRegex
=
function
(
str
)
{
if
(
str
[
0
]
!==
'/'
)
{
if
(
str
[
0
]
!==
'/'
)
{
return
new
RegExp
(
'^'
+
str
+
'$'
);
return
new
RegExp
(
'^'
+
str
+
'$'
);
...
...
public/app/plugins/panel/graph/module.js
View file @
ba65b89b
...
@@ -3,13 +3,14 @@ define([
...
@@ -3,13 +3,14 @@ define([
'lodash'
,
'lodash'
,
'moment'
,
'moment'
,
'app/core/utils/kbn'
,
'app/core/utils/kbn'
,
'app/core/utils/file_export'
,
'app/core/time_series'
,
'app/core/time_series'
,
'app/features/panel/panel_meta'
,
'app/features/panel/panel_meta'
,
'./seriesOverridesCtrl'
,
'./seriesOverridesCtrl'
,
'./graph'
,
'./graph'
,
'./legend'
,
'./legend'
,
],
],
function
(
angular
,
_
,
moment
,
kbn
,
TimeSeries
,
PanelMeta
)
{
function
(
angular
,
_
,
moment
,
kbn
,
fileExport
,
TimeSeries
,
PanelMeta
)
{
'use strict'
;
'use strict'
;
/** @ngInject */
/** @ngInject */
...
@@ -282,7 +283,7 @@ function (angular, _, moment, kbn, TimeSeries, PanelMeta) {
...
@@ -282,7 +283,7 @@ function (angular, _, moment, kbn, TimeSeries, PanelMeta) {
};
};
$scope
.
exportCsv
=
function
()
{
$scope
.
exportCsv
=
function
()
{
kbn
.
exportSeriesListToCsv
(
$scope
.
seriesList
);
fileExport
.
exportSeriesListToCsv
(
$scope
.
seriesList
);
};
};
panelSrv
.
init
(
$scope
);
panelSrv
.
init
(
$scope
);
...
...
public/app/plugins/panel/table/controller.ts
View file @
ba65b89b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import
angular
from
'angular'
;
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
kbn
from
'app/core/utils/kbn
'
;
import
*
as
FileExport
from
'app/core/utils/file_export
'
;
import
PanelMeta
from
'app/features/panel/panel_meta2'
;
import
PanelMeta
from
'app/features/panel/panel_meta2'
;
import
{
transformDataToTable
}
from
'./transformers'
;
import
{
transformDataToTable
}
from
'./transformers'
;
...
@@ -128,7 +128,7 @@ export class TablePanelCtrl {
...
@@ -128,7 +128,7 @@ export class TablePanelCtrl {
};
};
$scope
.
exportCsv
=
function
()
{
$scope
.
exportCsv
=
function
()
{
kbn
.
exportTableDataToCsv
(
$scope
.
table
);
FileExport
.
exportTableDataToCsv
(
$scope
.
table
);
};
};
$scope
.
init
();
$scope
.
init
();
...
...
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