From 27ee78b409b5d53d45f76a7a8a6ec970793dc3ce Mon Sep 17 00:00:00 2001 From: Jon Lambson Date: Fri, 22 Sep 2017 16:17:42 -0600 Subject: [PATCH] new design, but not sure --- index.html | 3 ++ js/app.js | 2 +- js/controllers/website-controller.js | 56 +++++++++++++++++----- js/lib/ez-file-tree/ez-file-tree.min.js | 1 + js/lib/ez-file-tree/ez-object2array.min.js | 1 + templates/website.html | 20 ++------ 6 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 js/lib/ez-file-tree/ez-file-tree.min.js create mode 100644 js/lib/ez-file-tree/ez-object2array.min.js diff --git a/index.html b/index.html index bc837ed..4cc5675 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,9 @@ + + + diff --git a/js/app.js b/js/app.js index a3dd002..f94c66d 100644 --- a/js/app.js +++ b/js/app.js @@ -1,4 +1,4 @@ -var app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule', 'angucomplete-alt']); +var app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule', 'angucomplete-alt', 'ez.fileTree']); app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function ($stateProvider, $urlRouterProvider, localStorageServiceProvider) { diff --git a/js/controllers/website-controller.js b/js/controllers/website-controller.js index 3f09e1f..d99a060 100644 --- a/js/controllers/website-controller.js +++ b/js/controllers/website-controller.js @@ -339,6 +339,7 @@ app.controller('websiteCtrl', [ vm.Sites.contents = function (r) { vm.showListFiles = true; var pkg = Auth.oauth3.pkg('www@daplie.com'); + return pkg.contents({ hostname: r.domain , domain: r.domain @@ -347,17 +348,8 @@ app.controller('websiteCtrl', [ //, sub: r.sub , path: r.newPath }).then(function (result) { - vm.directories = []; - vm.files = []; - window.alert(JSON.stringify(result.data)); - result.data.forEach(function(dir) { - if (dir.directory) { - debugger; - console.log('asdfasdfasdf'); - vm.things = []; - vm.things.push(dir.name); - } - }); + // window.alert(JSON.stringify(result.data)); + vm.folderStructure = result; }); }; vm.Shares = {}; @@ -494,5 +486,43 @@ app.controller('websiteCtrl', [ return matches; }; - -}]); +}]) +.filter('stringify', function() { + function getSerialize (fn, decycle) { + var seen = [], keys = []; + decycle = decycle || function(key, value) { + return '[Parent REFERENCE]: ' + value.id; + }; + return function(key, value) { + var ret = value; + if (typeof value === 'object' && value) { + if (seen.indexOf(value) !== -1) + ret = decycle(key, value); + else { + seen.push(value); + keys.push(key); + } + } + if (fn) ret = fn(key, ret); + return ret; + }; + } + function getPath (value, seen, keys) { + var index = seen.indexOf(value); + var path = [ keys[index] ]; + for (index--; index >= 0; index--) { + if (seen[index][ path[0] ] === value) { + value = seen[index]; + path.unshift(keys[index]); + } + } + return '~' + path.join('.'); + } + function stringify(obj, fn, spaces, decycle) { + return JSON.stringify(obj, getSerialize(fn, decycle), spaces); + } + stringify.getSerialize = getSerialize; + return function(ob) { + return stringify(ob, undefined, 2); + }; +}); diff --git a/js/lib/ez-file-tree/ez-file-tree.min.js b/js/lib/ez-file-tree/ez-file-tree.min.js new file mode 100644 index 0000000..b98a4dd --- /dev/null +++ b/js/lib/ez-file-tree/ez-file-tree.min.js @@ -0,0 +1 @@ +!function(angular){"use strict";angular.module("ez.fileTree",["ez.object2array"]).constant("EzFileTreeConfig",{enableChecking:!1,enableFolderSelection:!0,enableFileSelection:!0,multiSelect:!1,recursiveSelect:!1,recursiveUnselect:!0,icons:{chevronRight:"fa fa-chevron-right",chevronDown:"fa fa-chevron-down",folder:"fa fa-folder",openFolder:"fa fa-folder-open",file:"fa fa-file"},childrenField:"children",idField:"id",isFolder:function(file){return"folder"===file.type},preSelect:!1,ancestorField:"ancestors",showRoot:!1,movingFolder:null}).directive("ezFileTree",["$compile","$timeout","$parse","EzFileTreeConfig",function($compile,$timeout,$parse,EzFileTreeConfig){return{restrict:"EA",replace:!0,scope:{tree:"=ezFileTree",getChildren:"=?",config:"=?config"},templateUrl:"ez-file-tree-container.html",compile:function(element,attrs){var config=angular.extend({},EzFileTreeConfig);for(var key in EzFileTreeConfig)"undefined"!=typeof attrs[key]&&(config[key]=$parse(attrs[key])());return function(scope){scope.data={showTree:!1};var init=function(){scope.config=angular.extend(config,scope.config),scope.disableSelect=!1;var cachedSelectedFile=angular.extend({},scope.tree._selectedFile);if(delete scope.tree._selectedFile,scope.config.showRoot){var wrappedTree={};wrappedTree[scope.config.idField]="root",wrappedTree.name="root",wrappedTree[scope.config.childrenField]={},wrappedTree[scope.config.childrenField][scope.tree[scope.config.idField]]=$.extend(!0,{},scope.tree),wrappedTree[scope.config.childrenField][scope.tree[scope.config.idField]]._open=!0,wrappedTree[scope.config.childrenField][scope.tree[scope.config.idField]].type="folder",scope.tree=wrappedTree}scope.config.multiSelect?scope.tree._selectedFiles={}:scope.tree._selectedFile=null,scope.tree._activeFiles={},scope.tree[scope.config.childrenField]&&(setParentOnChildren(scope.tree,!0),scope.config.preSelect?scope.findAndSelectFile(cachedSelectedFile):scope.data.showTree=!0)};scope.folderFindAndSelect=function(folder,file,ancestors){if(ancestors.length>1)scope.recursiveFindAndSelect(folder,file,ancestors.slice(1));else for(var k in folder[scope.config.childrenField]){var innerFolder=folder[scope.config.childrenField][k];if(k===file.id)return select(innerFolder),void(scope.data.showTree=!0)}},scope.recursiveFindAndSelect=function(parentFolder,file,ancestors){var folder=parentFolder[scope.config.childrenField][ancestors[0][scope.config.idField]];folder._open?scope.folderFindAndSelect(folder,file,ancestors):scope.toggle(null,folder,function(updatedFolder){scope.folderFindAndSelect(updatedFolder,file,ancestors)})},scope.findAndSelectFile=function(file){for(var k in scope.tree[scope.config.childrenField]){var rootFolder=scope.tree[scope.config.childrenField][k];if(scope.config.ancestorField in file){var ancestors=file[scope.config.ancestorField];if(0===ancestors.length){if(k===file.id)return select(rootFolder),void(scope.data.showTree=!0)}else scope.recursiveFindAndSelect(scope.tree,file,ancestors)}}};var setParentOnChildren=function(file,recursive){for(var k in file[scope.config.childrenField])file[scope.config.childrenField][k]._parent=file,recursive&&file[scope.config.childrenField][k][scope.config.childrenField]&&setParentOnChildren(file[scope.config.childrenField][k],!0)},hasChildrenSelected=function(file){var selected=!1;for(var key in file[scope.config.childrenField]){if(file[scope.config.childrenField][key]._selected){selected=!0;break}if(file[scope.config.childrenField].files&&hasChildrenSelected(file[scope.config.childrenField])){selected=!0;break}}return selected},activate=function(file){file._active=!0,scope.tree._activeFiles[file[scope.config.idField]]=file,file._parent&&activate(file._parent)},deactivate=function(file){var active=!1;file[scope.config.childrenField]&&hasChildrenSelected(file)&&(active=!0),active||delete scope.tree._activeFiles[file[scope.config.idField]],file._active=active,active===!1&&void 0!==file._parent&&deactivate(file._parent)},selectChildren=function(folder){for(var key in folder[scope.config.childrenField])folder[scope.config.childrenField][key]._selected=!0,folder[scope.config.childrenField][key]._active=!0,scope.config.isFolder(folder[scope.config.childrenField][key])&&selectChildren(folder[scope.config.childrenField][key])},select=function(file){scope.$emit("ez-file-tree.select",file),(scope.config.enableFolderSelection||!scope.config.isFolder(file))&&(scope.config.enableFileSelection||scope.config.isFolder(file))&&(scope.config.movingFolder&&scope.config.movingFolder.length&&file[scope.config.idField]===scope.config.movingFolder||(scope.config.multiSelect?scope.tree._selectedFiles[file[scope.config.idField]]=file:(scope.tree._selectedFile=file,unselectAll(scope.tree[scope.config.childrenField])),file._selected=!0,activate(file),scope.config.recursiveSelect&&scope.config.isFolder(file)&&selectChildren(file)))},unselect=function(file){if(file._selected=!1,scope.$emit("ez-file-tree.unselect",file),scope.config.multiSelect?delete scope.tree._selectedFiles[file[scope.config.idField]]:scope.tree._selectedFile=null,deactivate(file),scope.config.recursiveUnselect&&scope.config.isFolder(file))for(var key in file[scope.config.childrenField])unselect(file[scope.config.childrenField][key])},unselectAll=function(files){for(var key in files)"undefined"!=typeof files[key][scope.config.childrenField]&&unselectAll(files[key][scope.config.childrenField]),files[key]._selected=!1,scope.$emit("ez-file-tree.unselect",files[key])};scope.toggle=function(e,file,callback){if(scope.config.isFolder(file)&&(!scope.config.movingFolder||!scope.config.movingFolder.length||file[scope.config.idField]!==scope.config.movingFolder)&&(e&&(scope.disableSelect=!0,$timeout(function(){scope.disableSelect=!1},500)),file._open=!file._open,!file[scope.config.childrenField]||file[scope.config.childrenField]&&!file[scope.config.childrenField].length)){if("undefined"==typeof scope.getChildren)throw new Error("You must add a getChildren method to the directive scope or hard code a children field on your folder objects.");scope.getChildren(file).then(function(children){for(var key in children)children[key]._parent=file,scope.config.multiSelect?"undefined"!=typeof scope.tree._selectedFiles[children[key][scope.config.idField]]&&(children[key]._selected=!0):scope.tree._selectedFile&&scope.tree._selectedFile[scope.config.idField]===children[key][scope.config.idField]&&(children[key]._selected=!0);file[scope.config.childrenField]=children,callback&&callback(file)})}},scope.showCheckbox=function(file){return!scope.config.enableChecking||scope.config.isFolder(file)&&!config.enableFolderSelection?!1:!0},scope.select=function(e,file){e.preventDefault(),$timeout(function(){scope.disableSelect!==!0&&(scope.disableSelect=!1,file._selected?unselect(file):select(file))},200)},init()}}}}])}(angular); diff --git a/js/lib/ez-file-tree/ez-object2array.min.js b/js/lib/ez-file-tree/ez-object2array.min.js new file mode 100644 index 0000000..4e4ec39 --- /dev/null +++ b/js/lib/ez-file-tree/ez-object2array.min.js @@ -0,0 +1 @@ +angular.module("ez.object2array",[]).filter("object2array",[function(){return function(a){if("[object Array]"===Object.prototype.toString.call(a))return a;var b=[];for(var c in a)b.push(a[c]);return b}}]); diff --git a/templates/website.html b/templates/website.html index a6d422a..5f74ec9 100644 --- a/templates/website.html +++ b/templates/website.html @@ -180,22 +180,12 @@
-

Directories

-
    -
  • {{ directory }}
  • -
-

Files

-
    -
  • {{ file }}
  • -
+
+
+
{{ vm.folderStructure | stringify }}
+
+
- - - - - - -