Browse Source

Allow dragging into the root folder

James Allen 12 năm trước cách đây
mục cha
commit
a13ee00e91

+ 6 - 2
services/web/app/views/project/editor/file-tree.jade

@@ -39,8 +39,12 @@ aside#file-tree(ng-controller="FileTreeController")
 			)
 			)
 				i.fa.fa-trash-o
 				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(
 			file-entity(
 				entity="entity",
 				entity="entity",
 				ng-repeat="entity in rootFolder.children | orderBy:[orderByFoldersFirst, 'name']"
 				ng-repeat="entity in rootFolder.children | orderBy:[orderByFoldersFirst, 'name']"

+ 7 - 3
services/web/public/coffee/app/ide/file-tree/FileTreeManager.coffee

@@ -5,6 +5,7 @@ define [
 	"ide/file-tree/controllers/FileTreeController"
 	"ide/file-tree/controllers/FileTreeController"
 	"ide/file-tree/controllers/FileTreeEntityController"
 	"ide/file-tree/controllers/FileTreeEntityController"
 	"ide/file-tree/controllers/FileTreeFolderController"
 	"ide/file-tree/controllers/FileTreeFolderController"
+	"ide/file-tree/controllers/FileTreeRootFolderController"
 ], () ->
 ], () ->
 	class FileTreeManager
 	class FileTreeManager
 		constructor: (@ide, @$scope) ->
 		constructor: (@ide, @$scope) ->
@@ -59,6 +60,7 @@ define [
 			@ide.socket.on "reciveEntityMove", (entity_id, folder_id) =>
 			@ide.socket.on "reciveEntityMove", (entity_id, folder_id) =>
 				entity = @findEntityById(entity_id)
 				entity = @findEntityById(entity_id)
 				folder = @findEntityById(folder_id)
 				folder = @findEntityById(folder_id)
+				console.log "Got recive ENTITY", entity_id, folder_id, entity, folder
 				@$scope.$apply () =>
 				@$scope.$apply () =>
 					@_moveEntityInScope(entity, folder)
 					@_moveEntityInScope(entity, folder)
 
 
@@ -69,6 +71,8 @@ define [
 			entity.selected = true
 			entity.selected = true
 
 
 		findEntityById: (id, options = {}) ->
 		findEntityById: (id, options = {}) ->
+			return @$scope.rootFolder if @$scope.rootFolder.id == id
+
 			entity = @_findEntityByIdInFolder @$scope.rootFolder, id
 			entity = @_findEntityByIdInFolder @$scope.rootFolder, id
 			return entity if entity?
 			return entity if entity?
 
 
@@ -250,7 +254,7 @@ define [
 				_csrf: window.csrfToken
 				_csrf: window.csrfToken
 			}
 			}
 
 
-		_deleteEntityFromScope: (entity) ->
+		_deleteEntityFromScope: (entity, options = { moveToDeleted: true }) ->
 			parent_folder = null
 			parent_folder = null
 			@forEachEntity (possible_entity, folder) ->
 			@forEachEntity (possible_entity, folder) ->
 				if possible_entity == entity
 				if possible_entity == entity
@@ -261,11 +265,11 @@ define [
 				if index > -1
 				if index > -1
 					parent_folder.children.splice(index, 1)
 					parent_folder.children.splice(index, 1)
 
 
-			if entity.type == "doc"
+			if entity.type == "doc" and options.moveToDeleted
 				entity.deleted = true
 				entity.deleted = true
 				@$scope.deletedDocs.push entity
 				@$scope.deletedDocs.push entity
 
 
 		_moveEntityInScope: (entity, parent_folder) ->
 		_moveEntityInScope: (entity, parent_folder) ->
 			return if entity in parent_folder.children
 			return if entity in parent_folder.children
-			@_deleteEntityFromScope(entity)
+			@_deleteEntityFromScope(entity, moveToDeleted: false)
 			parent_folder.children.push(entity)
 			parent_folder.children.push(entity)

+ 13 - 0
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)
+	]

+ 1 - 0
services/web/public/coffee/app/ide/file-tree/directives/droppable.coffee

@@ -7,6 +7,7 @@ define [
 				onDropCallback: "="
 				onDropCallback: "="
 			}
 			}
 			link: (scope, element, attrs) ->
 			link: (scope, element, attrs) ->
+				console.log "DROPPABLE", element, scope.onDropCallback
 				element.droppable
 				element.droppable
 					greedy: true
 					greedy: true
 					hoverClass: "droppable-hover"
 					hoverClass: "droppable-hover"