From f886f19429d533c9237909ac26874e7645c870d2 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 31 Jul 2014 12:37:37 +0100 Subject: [PATCH] Keep root doc list in sync with file tree updates --- .../coffee/ide/file-tree/FileTreeManager.coffee | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee b/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee index 167efa3005..547749cc89 100644 --- a/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee +++ b/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee @@ -23,49 +23,55 @@ define [ _bindToSocketEvents: () -> @ide.socket.on "reciveNewDoc", (parent_folder_id, doc) => parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder - @$scope.$apply () -> + @$scope.$apply () => parent_folder.children.push { name: doc.name id: doc._id type: "doc" } + @recalculateDocList() @ide.socket.on "reciveNewFile", (parent_folder_id, file) => parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder - @$scope.$apply () -> + @$scope.$apply () => parent_folder.children.push { name: file.name id: file._id type: "file" } - + @recalculateDocList() + @ide.socket.on "reciveNewFolder", (parent_folder_id, folder) => parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder - @$scope.$apply () -> + @$scope.$apply () => parent_folder.children.push { name: folder.name id: folder._id type: "folder" children: [] } + @recalculateDocList() @ide.socket.on "reciveEntityRename", (entity_id, name) => entity = @findEntityById(entity_id) return if !entity? - @$scope.$apply () -> + @$scope.$apply () => entity.name = name + @recalculateDocList() @ide.socket.on "removeEntity", (entity_id) => entity = @findEntityById(entity_id) return if !entity? @$scope.$apply () => @_deleteEntityFromScope entity + @recalculateDocList() @ide.socket.on "reciveEntityMove", (entity_id, folder_id) => entity = @findEntityById(entity_id) folder = @findEntityById(folder_id) @$scope.$apply () => @_moveEntityInScope(entity, folder) + @recalculateDocList() selectEntity: (entity) -> @selected_entity_id = entity.id # For reselecting after a reconnect