diff --git a/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js b/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js index 98147f1dd..9e5e047cc 100644 --- a/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js +++ b/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js @@ -97,6 +97,17 @@ angular.module('client').directive('guacFileBrowser', [function guacFileBrowser( }; + /** + * Initiates a download of the given file. The progress of the + * download can be observed through guacFileTransferManager. + * + * @param {ManagedFilesystem.File} file + * The file to download. + */ + $scope.downloadFile = function downloadFile(file) { + ManagedFilesystem.downloadFile($scope.client, $scope.filesystem, file.streamName); + }; + }] }; diff --git a/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html b/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html index dc5bdf18c..1c3a84567 100644 --- a/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html +++ b/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html @@ -25,7 +25,7 @@
-
+
{{file.name}}
diff --git a/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js b/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js index 08be2c4d1..265721afb 100644 --- a/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js +++ b/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js @@ -27,6 +27,10 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector', function defineManagedFilesystem($rootScope, $injector) { + // Required types + var ManagedFileDownload = $injector.get('ManagedFileDownload'); + var ManagedFileUpload = $injector.get('ManagedFileUpload'); + /** * Object which serves as a surrogate interface, encapsulating a Guacamole * filesystem object while it is active, allowing it to be detached and @@ -182,6 +186,36 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector' }; + /** + * Downloads the given file from the server using the given Guacamole + * client and filesystem. The file transfer can be monitored through the + * corresponding entry in the downloads array of the given ManagedClient. + * + * @param {ManagedClient} managedClient + * The ManagedClient from which the file is to be downloaded. + * + * @param {ManagedFilesystem} managedFilesystem + * The ManagedFilesystem from which the file is to be downloaded. Any + * path information provided must be relative to this filesystem. + * + * @param {String} path + * The full, absolute path of the file to download. + */ + ManagedFilesystem.downloadFile = function downloadFile(managedClient, managedFilesystem, path) { + + // Request download + managedFilesystem.object.requestInputStream(path, function downloadStreamReceived(stream, mimetype) { + + // Parse filename from string + var filename = path.match(/(.*[\\/])?(.*)/)[2]; + + // Start and track download + managedClient.downloads.push(ManagedFileDownload.getInstance(stream, mimetype, filename)); + + }); + + }; + /** * A file within a ManagedFilesystem. Each ManagedFilesystem.File provides * sufficient information for retrieval or replacement of the file's