Keep root doc list in sync with file tree updates

This commit is contained in:
James Allen 2014-07-31 12:37:37 +01:00
parent 42c63dd5a2
commit f886f19429

View file

@ -23,49 +23,55 @@ define [
_bindToSocketEvents: () -> _bindToSocketEvents: () ->
@ide.socket.on "reciveNewDoc", (parent_folder_id, doc) => @ide.socket.on "reciveNewDoc", (parent_folder_id, doc) =>
parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder
@$scope.$apply () -> @$scope.$apply () =>
parent_folder.children.push { parent_folder.children.push {
name: doc.name name: doc.name
id: doc._id id: doc._id
type: "doc" type: "doc"
} }
@recalculateDocList()
@ide.socket.on "reciveNewFile", (parent_folder_id, file) => @ide.socket.on "reciveNewFile", (parent_folder_id, file) =>
parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder
@$scope.$apply () -> @$scope.$apply () =>
parent_folder.children.push { parent_folder.children.push {
name: file.name name: file.name
id: file._id id: file._id
type: "file" type: "file"
} }
@recalculateDocList()
@ide.socket.on "reciveNewFolder", (parent_folder_id, folder) => @ide.socket.on "reciveNewFolder", (parent_folder_id, folder) =>
parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder
@$scope.$apply () -> @$scope.$apply () =>
parent_folder.children.push { parent_folder.children.push {
name: folder.name name: folder.name
id: folder._id id: folder._id
type: "folder" type: "folder"
children: [] children: []
} }
@recalculateDocList()
@ide.socket.on "reciveEntityRename", (entity_id, name) => @ide.socket.on "reciveEntityRename", (entity_id, name) =>
entity = @findEntityById(entity_id) entity = @findEntityById(entity_id)
return if !entity? return if !entity?
@$scope.$apply () -> @$scope.$apply () =>
entity.name = name entity.name = name
@recalculateDocList()
@ide.socket.on "removeEntity", (entity_id) => @ide.socket.on "removeEntity", (entity_id) =>
entity = @findEntityById(entity_id) entity = @findEntityById(entity_id)
return if !entity? return if !entity?
@$scope.$apply () => @$scope.$apply () =>
@_deleteEntityFromScope entity @_deleteEntityFromScope entity
@recalculateDocList()
@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)
@$scope.$apply () => @$scope.$apply () =>
@_moveEntityInScope(entity, folder) @_moveEntityInScope(entity, folder)
@recalculateDocList()
selectEntity: (entity) -> selectEntity: (entity) ->
@selected_entity_id = entity.id # For reselecting after a reconnect @selected_entity_id = entity.id # For reselecting after a reconnect