From 3109fe8138e1b611a092a963d6d5ed75b8be0b97 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 23 Jun 2015 16:40:34 -0700 Subject: [PATCH] GUAC-1172: Implement file browsing directive. Track expanded/collapsed state within ManagedFilesystem.File. --- .../app/client/directives/guacFileBrowser.js | 103 ++++++++++++++++++ .../webapp/app/client/styles/file-browser.css | 48 ++++++++ .../app/client/templates/guacFileBrowser.html | 58 ++++++++++ .../app/client/types/ManagedFilesystem.js | 8 ++ guacamole/src/main/webapp/images/file.png | Bin 0 -> 471 bytes .../src/main/webapp/images/folder-closed.png | Bin 0 -> 487 bytes .../src/main/webapp/images/folder-open.png | Bin 0 -> 803 bytes 7 files changed, 217 insertions(+) create mode 100644 guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js create mode 100644 guacamole/src/main/webapp/app/client/styles/file-browser.css create mode 100644 guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html create mode 100644 guacamole/src/main/webapp/images/file.png create mode 100644 guacamole/src/main/webapp/images/folder-closed.png create mode 100644 guacamole/src/main/webapp/images/folder-open.png diff --git a/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js b/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js new file mode 100644 index 000000000..98147f1dd --- /dev/null +++ b/guacamole/src/main/webapp/app/client/directives/guacFileBrowser.js @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * A directive which displays the contents of a filesystem received through the + * Guacamole client. + */ +angular.module('client').directive('guacFileBrowser', [function guacFileBrowser() { + + return { + restrict: 'E', + replace: true, + scope: { + + /** + * The client whose file transfers should be managed by this + * directive. + * + * @type ManagedClient + */ + client : '=', + + /** + * @type ManagedFilesystem + */ + filesystem : '=' + + }, + + templateUrl: 'app/client/templates/guacFileBrowser.html', + controller: ['$scope', '$injector', function guacFileBrowserController($scope, $injector) { + + // Required types + var ManagedFilesystem = $injector.get('ManagedFilesystem'); + + /** + * Returns whether the given file is a normal file. + * + * @param {ManagedFilesystem.File} file + * The file to test. + * + * @returns {Boolean} + * true if the given file is a normal file, false otherwise. + */ + $scope.isNormalFile = function isNormalFile(file) { + return file.type === ManagedFilesystem.File.Type.NORMAL; + }; + + /** + * Returns whether the given file is a directory. + * + * @param {ManagedFilesystem.File} file + * The file to test. + * + * @returns {Boolean} + * true if the given file is a directory, false otherwise. + */ + $scope.isDirectory = function isDirectory(file) { + return file.type === ManagedFilesystem.File.Type.DIRECTORY; + }; + + /** + * Toggles the expanded state of the given file between expanded + * and collapsed, showing or hiding the file's children. This is + * only applicable to directories. + * + * @param {ManagedFilesystem.File} file + * The file to expand or collapse. + */ + $scope.toggleExpanded = function toggleExpanded(file) { + + // Toggle expanded state + file.expanded = !file.expanded; + + // If now expanded, refresh contents + if (file.expanded) + ManagedFilesystem.refresh($scope.filesystem, file); + + }; + + }] + + }; +}]); diff --git a/guacamole/src/main/webapp/app/client/styles/file-browser.css b/guacamole/src/main/webapp/app/client/styles/file-browser.css new file mode 100644 index 000000000..2c6c923fb --- /dev/null +++ b/guacamole/src/main/webapp/app/client/styles/file-browser.css @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 Glyptodon LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* Hide directory contents by default */ + +.file-browser .directory > .children { + padding-left: 1em; + display: none; +} + +/* Show directory contents if expanded */ + +.file-browser .directory.expanded > .children { + display: block; +} + +/* Directory / file icons */ + +.file-browser .normal-file > .caption .icon { + background-image: url('images/file.png'); +} + +.file-browser .directory > .caption .icon { + background-image: url('images/folder-closed.png'); +} + +.file-browser .directory.expanded > .caption .icon { + background-image: url('images/folder-open.png'); +} diff --git a/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html b/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html new file mode 100644 index 000000000..dc5bdf18c --- /dev/null +++ b/guacamole/src/main/webapp/app/client/templates/guacFileBrowser.html @@ -0,0 +1,58 @@ +
+ + + + + +
+
+
+ +
diff --git a/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js b/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js index 2c58d5d74..08be2c4d1 100644 --- a/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js +++ b/guacamole/src/main/webapp/app/client/types/ManagedFilesystem.js @@ -231,6 +231,14 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector' */ this.files = template.files || {}; + /** + * Whether this file is currently expanded, exposing any children + * within. This is only applicable to directories. + * + * @type Boolean + */ + this.expanded = template.expanded || false; + }; /** diff --git a/guacamole/src/main/webapp/images/file.png b/guacamole/src/main/webapp/images/file.png new file mode 100644 index 0000000000000000000000000000000000000000..d45e227d389df5a987b9bfb74ef2d28030fae3f7 GIT binary patch literal 471 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4yp^%RmZ1)t37Vw zyZ-jJyANzx&i*yvX-tg0p3rlXA!d1v^K(u8)0y+qbxsFKC(8)AX{a@9HS=ysVq&ON z5)ozakYBii!QmE%D;vWlR}C|U32IIk85{aJ&h6ZlDaHOk>)Fp6`AsH@E&1oa)W-Ke zu3-33@@DVRdM3NotF(U2v=@CK!gWCIz%qt6j5*X|T(qD3`QG8E*~zE-E8j1kZ~0W; qxcuV!PrKz9_H1zP=RbpW=X#z~JfX=d#Wzp$PyueYc|k literal 0 HcmV?d00001 diff --git a/guacamole/src/main/webapp/images/folder-closed.png b/guacamole/src/main/webapp/images/folder-closed.png new file mode 100644 index 0000000000000000000000000000000000000000..46a918ad5c3e42923b4adcf66762c661e8377547 GIT binary patch literal 487 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4g5tgTLOWf;>%%{TJ9 zNYDGtXv6gW{>*cWHI(`ucP%y-*LuKfk!f@E7I(qXU0<42JSBM8dii-p3+_}j#dCh( zvSIL1n;h2mjp=o6y&8XGcEiVtJEsnu+ozbmS#t5kjyV02{w`gy?gy3&tz&+%{dMO0 z9=Z3P>_et2j8|eBtQux<2e1beGrnTT(sPh?ILo?%dBskKQU+7;1$+yh;ZxLb;FsPX zn|(UbJbxV@iS4)(H|?5kV|6KqF%WF#`^D7jS#q@b&U1ZWq%e58`njxgN@xNAE$+bx literal 0 HcmV?d00001 diff --git a/guacamole/src/main/webapp/images/folder-open.png b/guacamole/src/main/webapp/images/folder-open.png new file mode 100644 index 0000000000000000000000000000000000000000..f04b0be73df6fd516b5b785bf1083093dc092028 GIT binary patch literal 803 zcmV+;1Kj+HP)lMjF#92|%V)oS%716H#fEm>RAWIR<$v9+}|bw~3kz!RXdv9Uq9 zT%NkKc@$s=V0(MpinF}p@D_M(Bajp!*b^X+pA_4Uv_=?)((QJQ3ZQNg%xw?L%gZ;d z#2PCrD+EDc#g|rp48w5Ram);BMKFpY`u#pvS68-NYH=gLL!blnQ{y+V8pkn8DdQ0Y z0p)U;Fbvt<-R1J~az;xY&m$}qIHi;TQmIsAZ*NbMBrz^_CPgsK1#oR!i1qb#+27xv znE>hQ@JHaKj#ATLb90kYsbn-q5CpVZEvnTj0BdV&oSmHklz?A(&%b5{J-_JDY&Iv# zfOHr5oTrcr93LM~WSS^!}Iwm}p{oS&a- z+mD_Eo!^1BU0g+^nUNjt%)015E5(1elj0TD4Og5Y=t=(4aGpv!HC9R&<>Y+T_1!xQd5-1d1~fH%O4X+&g+Yv4T@i}!du h9*@W4@p$eqe*sgclf