From 7b04f5f07bc2e88cad86888389831892f12cd202 Mon Sep 17 00:00:00 2001 From: vitam Date: Tue, 25 Jul 2017 23:03:52 +0200 Subject: [PATCH 1/5] group file into folder in select file --- css/modals.css | 4 ++-- index.html | 42 +++++++++++++++++++++++++++++++----------- js/ctrls/modal.js | 17 +++++++++++++++++ 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/css/modals.css b/css/modals.css index 9aedb6a..f5740ae 100644 --- a/css/modals.css +++ b/css/modals.css @@ -34,11 +34,11 @@ width: 80px; } -.selectFiles > div > .control-label { +.selectFiles div .control-label { font-weight: normal; margin-left: 30px; } -.selectFiles > div > .controls { +.selectFiles div .controls { margin-left: 30px; } diff --git a/index.html b/index.html index 18551bc..e7cca56 100644 --- a/index.html +++ b/index.html @@ -1028,6 +1028,36 @@ + + + + @@ -1039,17 +1069,7 @@ diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 3177c3d..7dc8c9c 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -113,6 +113,23 @@ angular var self = this; this.files = _.cloneDeep(files); + var groupFile = function (files) { + var i, j, str, arr, folder = {}, tmp = folder; + for (i = 0; i < files.length; i++) { + str = files[i].relpath; + arr = str.split("/"); + for (j = 0; j < arr.length - 1; j++) { + if (!tmp[arr[j]]) { + tmp[arr[j]] = {}; + } + tmp = tmp[arr[j]]; + } + tmp[arr[arr.length - 1]] = files[i]; + tmp = folder; + } + return folder; + }; + this.groupedFiles = groupFile(this.files); this.inst = $modal.open({ templateUrl: "selectFiles.html", scope: scope, From 8af0a6dbcb5d527d006eff52a41446d85526c15a Mon Sep 17 00:00:00 2001 From: vitam Date: Thu, 27 Jul 2017 12:31:18 +0200 Subject: [PATCH 2/5] group file into folder in select file --- index.html | 44 ++++++++++++++------------ js/ctrls/modal.js | 61 +++++++++++++++++++++++++++++-------- js/directives/fileselect.js | 21 +++++++++++++ js/init.js | 2 +- 4 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 js/directives/fileselect.js diff --git a/index.html b/index.html index e7cca56..8214268 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@ - + @@ -41,6 +41,7 @@ + @@ -1032,30 +1033,33 @@ diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index 7dc8c9c..9f0a7b7 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -113,23 +113,60 @@ angular var self = this; this.files = _.cloneDeep(files); - var groupFile = function (files) { - var i, j, str, arr, folder = {}, tmp = folder; - for (i = 0; i < files.length; i++) { - str = files[i].relpath; - arr = str.split("/"); - for (j = 0; j < arr.length - 1; j++) { - if (!tmp[arr[j]]) { - tmp[arr[j]] = {}; + var groupFiles = function (files) { + var createSubFolder = function () { + var folder = { + dirs : {}, + files : {}, + show : false, + _selected : false, + change : function () { + for (var file in this.files) { + if (this.files.hasOwnProperty(file)) { + this.files[file].selected = this.selected; + } + } + for (var folder in this.dirs) { + if (this.dirs.hasOwnProperty(folder)) { + this.dirs[folder].selected = this.selected; + } + } + console.log(this); } - tmp = tmp[arr[j]]; - } - tmp[arr[arr.length - 1]] = files[i]; + }; + Object.defineProperty(folder, "selected", { + get : function () { + return this._selected; + }, + set : function (newValue) { + this._selected = newValue; + this.change(); + } + }); + Object.defineProperty(folder, "indeterminate", { + get : function () { + return this._selected; + } + }); + return folder; + }; + var folder = createSubFolder(), + tmp; + for (var i = 0; i < files.length; i++) { tmp = folder; + var str = files[i].relpath; + var arr = str.split("/"); + for (var j = 0; j < arr.length - 1; j++) { + if (!tmp.dirs[arr[j]]) { + tmp.dirs[arr[j]] = createSubFolder(); + } + tmp = tmp.dirs[arr[j]]; + } + tmp.files[arr[arr.length - 1]] = files[i]; } return folder; }; - this.groupedFiles = groupFile(this.files); + this.groupedFiles = groupFiles(this.files); this.inst = $modal.open({ templateUrl: "selectFiles.html", scope: scope, diff --git a/js/directives/fileselect.js b/js/directives/fileselect.js new file mode 100644 index 0000000..d0d01c5 --- /dev/null +++ b/js/directives/fileselect.js @@ -0,0 +1,21 @@ +// watches changes in the file upload control (input[file]) and +// puts the files selected in an attribute +angular.module("webui.directives.fileselect", []).directive("indeterminate", function () { + return { + // Restrict the directive so it can only be used as an attribute + restrict : "A", + + link : function link (scope, elem, attr) { + // Whenever the bound value of the attribute changes we update + // the internal 'indeterminate' flag on the attached dom element + var watcher = scope.$watch(attr.indeterminate, function (value) { + elem[0].indeterminate = value; + }); + + // Remove the watcher when the directive is destroyed + scope.$on("$destroy", function () { + watcher(); + }); + } + }; +}); diff --git a/js/init.js b/js/init.js index 72fe0ff..ce964e7 100644 --- a/js/init.js +++ b/js/init.js @@ -4,7 +4,7 @@ var webui = angular.module('webui', [ 'webui.services.modals', 'webui.services.alerts', 'webui.services.settings', 'webui.services.settings.filters', 'webui.filters.bytes','webui.filters.url', - 'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect', + 'webui.directives.chunkbar', 'webui.directives.dgraph', 'webui.directives.fselect', "webui.directives.fileselect", 'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal', 'webui.ctrls.alert', 'webui.ctrls.props', // external deps From 286cc301fe6618c33565d97593ca362ac6d8a725 Mon Sep 17 00:00:00 2001 From: vitam Date: Thu, 27 Jul 2017 22:31:33 +0200 Subject: [PATCH 3/5] change some code for better perfomance, support indeterminate --- index.html | 6 +-- js/ctrls/modal.js | 85 ++++++++++++++++++++----------------- js/directives/fileselect.js | 48 ++++++++++++++++++--- 3 files changed, 92 insertions(+), 47 deletions(-) diff --git a/index.html b/index.html index 8214268..6358a6f 100644 --- a/index.html +++ b/index.html @@ -1031,7 +1031,7 @@ - +