diff --git a/js/controllers/PerfCtrl.js b/js/controllers/PerfCtrl.js
index d28f9e7..c3aea93 100644
--- a/js/controllers/PerfCtrl.js
+++ b/js/controllers/PerfCtrl.js
@@ -6,7 +6,7 @@ panelApp.filter('sortByTime', function () {
};
});
-panelApp.controller('PerfCtrl', function PerfCtrl($scope, appContext) {
+panelApp.controller('PerfCtrl', function PerfCtrl($scope, appContext, filesystem) {
$scope.enable = false;
@@ -17,6 +17,10 @@ panelApp.controller('PerfCtrl', function PerfCtrl($scope, appContext) {
appContext.clearHistogram();
};
+ $scope.exportData = function () {
+ filesystem.exportJSON('file.json', $scope.histogram);
+ };
+
var first = true;
$scope.$watch('enable', function (newVal, oldVal) {
diff --git a/js/services/filesystem.js b/js/services/filesystem.js
new file mode 100644
index 0000000..c04cb0a
--- /dev/null
+++ b/js/services/filesystem.js
@@ -0,0 +1,32 @@
+// Service for exporting as JSON
+panelApp.factory('filesystem', function(chromeExtension) {
+
+ // taken from:
+ // http://html5-demos.appspot.com/static/html5storage/index.html#slide59
+
+ // TODO: error handlers?
+
+ return {
+ exportJSON: function (name, data) {
+ //TODO: file size/limits? 1024*1024
+ window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function (fs) {
+ fs.root.getFile(name + '.json', {create: true}, function (fileEntry) {
+ fileEntry.createWriter(function(fileWriter) {
+
+ var builder = new WebKitBlobBuilder();
+ builder.append(JSON.stringify(data));
+ var blob = builder.getBlob('text/plain');
+
+ fileWriter.onwriteend = function () {
+ // navigate to file, will download
+ //location.href = fileEntry.toURL();
+ window.open(fileEntry.toURL());
+ };
+
+ fileWriter.write(blob);
+ }, function() {});
+ }, function() {});
+ }, function() {});
+ }
+ };
+});
diff --git a/panel.html b/panel.html
index 0240a4e..025bf31 100644
--- a/panel.html
+++ b/panel.html
@@ -16,6 +16,7 @@
+
@@ -84,7 +85,8 @@
-
+
+