From a13ee00e91ad03ea650b2082e7aeae201480c536 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 3 Jul 2014 11:01:41 +0100 Subject: [PATCH] Allow dragging into the root folder --- .../web/app/views/project/editor/file-tree.jade | 8 ++++++-- .../coffee/app/ide/file-tree/FileTreeManager.coffee | 10 +++++++--- .../controllers/FileTreeRootFolderController.coffee | 13 +++++++++++++ .../app/ide/file-tree/directives/droppable.coffee | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 services/web/public/coffee/app/ide/file-tree/controllers/FileTreeRootFolderController.coffee diff --git a/services/web/app/views/project/editor/file-tree.jade b/services/web/app/views/project/editor/file-tree.jade index a9ceaca2ff..67fa6c5574 100644 --- a/services/web/app/views/project/editor/file-tree.jade +++ b/services/web/app/views/project/editor/file-tree.jade @@ -39,8 +39,12 @@ aside#file-tree(ng-controller="FileTreeController") ) i.fa.fa-trash-o - .file-tree-inner - ul.list-unstyled.file-tree-list + .file-tree-inner(ng-if="rootFolder", ng-controller="FileTreeRootFolderController") + ul.list-unstyled.file-tree-list( + droppable + accept=".entity-name" + on-drop-callback="onDrop" + ) file-entity( entity="entity", ng-repeat="entity in rootFolder.children | orderBy:[orderByFoldersFirst, 'name']" diff --git a/services/web/public/coffee/app/ide/file-tree/FileTreeManager.coffee b/services/web/public/coffee/app/ide/file-tree/FileTreeManager.coffee index 26aeb03853..838f9db1aa 100644 --- a/services/web/public/coffee/app/ide/file-tree/FileTreeManager.coffee +++ b/services/web/public/coffee/app/ide/file-tree/FileTreeManager.coffee @@ -5,6 +5,7 @@ define [ "ide/file-tree/controllers/FileTreeController" "ide/file-tree/controllers/FileTreeEntityController" "ide/file-tree/controllers/FileTreeFolderController" + "ide/file-tree/controllers/FileTreeRootFolderController" ], () -> class FileTreeManager constructor: (@ide, @$scope) -> @@ -59,6 +60,7 @@ define [ @ide.socket.on "reciveEntityMove", (entity_id, folder_id) => entity = @findEntityById(entity_id) folder = @findEntityById(folder_id) + console.log "Got recive ENTITY", entity_id, folder_id, entity, folder @$scope.$apply () => @_moveEntityInScope(entity, folder) @@ -69,6 +71,8 @@ define [ entity.selected = true findEntityById: (id, options = {}) -> + return @$scope.rootFolder if @$scope.rootFolder.id == id + entity = @_findEntityByIdInFolder @$scope.rootFolder, id return entity if entity? @@ -250,7 +254,7 @@ define [ _csrf: window.csrfToken } - _deleteEntityFromScope: (entity) -> + _deleteEntityFromScope: (entity, options = { moveToDeleted: true }) -> parent_folder = null @forEachEntity (possible_entity, folder) -> if possible_entity == entity @@ -261,11 +265,11 @@ define [ if index > -1 parent_folder.children.splice(index, 1) - if entity.type == "doc" + if entity.type == "doc" and options.moveToDeleted entity.deleted = true @$scope.deletedDocs.push entity _moveEntityInScope: (entity, parent_folder) -> return if entity in parent_folder.children - @_deleteEntityFromScope(entity) + @_deleteEntityFromScope(entity, moveToDeleted: false) parent_folder.children.push(entity) diff --git a/services/web/public/coffee/app/ide/file-tree/controllers/FileTreeRootFolderController.coffee b/services/web/public/coffee/app/ide/file-tree/controllers/FileTreeRootFolderController.coffee new file mode 100644 index 0000000000..8e3fe5e8bb --- /dev/null +++ b/services/web/public/coffee/app/ide/file-tree/controllers/FileTreeRootFolderController.coffee @@ -0,0 +1,13 @@ +define [ + "base" +], (App) -> + App.controller "FileTreeRootFolderController", ["$scope", "ide", ($scope, ide) -> + console.log "CREATING FileTreeRootFolderController" + rootFolder = $scope.rootFolder + console.log "ROOT FOLDER", rootFolder + $scope.onDrop = (events, ui) -> + source = $(ui.draggable).scope().entity + console.log "DROPPED INTO ROOT", source, rootFolder + return if !source? + ide.fileTreeManager.moveEntity(source, rootFolder) + ] diff --git a/services/web/public/coffee/app/ide/file-tree/directives/droppable.coffee b/services/web/public/coffee/app/ide/file-tree/directives/droppable.coffee index ba087aa49a..5c3bdefc35 100644 --- a/services/web/public/coffee/app/ide/file-tree/directives/droppable.coffee +++ b/services/web/public/coffee/app/ide/file-tree/directives/droppable.coffee @@ -7,6 +7,7 @@ define [ onDropCallback: "=" } link: (scope, element, attrs) -> + console.log "DROPPABLE", element, scope.onDropCallback element.droppable greedy: true hoverClass: "droppable-hover"