JSON file of perf data can be saved from perf tab

test-unit-sauce
Brian Ford 12 years ago
parent 4f92e7ab83
commit 1cb56e6764

@ -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) {

@ -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() {});
}
};
});

@ -16,6 +16,7 @@
<script src="js/services/appContext.js"></script>
<script src="js/services/chromeExtension.js"></script>
<script src="js/services/filesystem.js"></script>
<script src="js/controllers/OptionsCtrl.js"></script>
<script src="js/controllers/PerfCtrl.js"></script>
@ -84,7 +85,8 @@
</div>
</div>
</div>
<button class="btn" ng-click="clearHistogram()">Clear Data</button>
<button class="btn btn-success" ng-click="exportData()">Save Data as JSON</button>
<button class="btn btn-danger" ng-click="clearHistogram()">Clear Data</button>
</div>
</div>