Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Added editor side support for Exporting Files
Browse files Browse the repository at this point in the history
Signed-off-by: Kamidi Preetham <kamidi@live.com>
  • Loading branch information
Kamidi Preetham committed Jul 8, 2016
1 parent 40d5d85 commit 92490f7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,45 @@
}
};

var saveFile = (function () {
var a = document.createElement('a');
document.body.appendChild(a);
a.style = 'display: none';
return function (blob, file_name) {
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = file_name;
a.click();
setTimeout( function() {
window.URL.revokeObjectURL(url);
}, 100);
};
}());

$scope.exportFile = function () {
var file = filePath;
if (file) {
if (isLeaf) {
$http.get('/api/file/download',
{ params: { "file": file },
responseType: "arraybuffer"
}).success( function (data, status, headers, config) {
var f = headers('Content-Disposition').match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
var file_name = String(f).split('=').pop().slice(1, -1);
var mime_type = headers('Content-Type');
var blob = new Blob([data], { type: String(mime_type) });
saveFile(blob, file_name);
}).error( function (data, status, headers, config) {
alert('Error: Unable to Download File');
});
} else {
alert('Error: Cannot Download Folder');
}
} else {
alert('Please select File first!');
}
};

$scope.remove = function () {
if (filePath) {
var file_name = filePath.split("/").pop();
Expand Down Expand Up @@ -1100,6 +1139,9 @@
case "file.importfile":
$scope.importFile();
break;
case "file.exportfile":
$scope.exportFile();
break;
case "file.remove":
$scope.remove();
break;
Expand Down
5 changes: 5 additions & 0 deletions server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
<md-button ng-click="ctrl.menuAction('file.importfile', $event)">
Import File
</md-button>
</md-menu-item>
<md-menu-item>
<md-button ng-click="ctrl.menuAction('file.exportfile', $event)">
Export File
</md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
Expand Down

0 comments on commit 92490f7

Please sign in to comment.