 angular.module('fileManager').
-factory 'FileSystemNode', ($q, assert, crypto, DbDoc, CrypTree, session) ->
+factory 'FileSystemNode', ($q, assert, crypto, DbDoc, CrypTree, session, $log) ->
   class FileSystemNode
-    constructor: (doc, parentKey, parentId) ->
-      console.log "new File/Folder", doc, parentKey
+    constructor: (doc, parentKey, parentId = null) ->
+      $log.log "new File/Folder", doc, parentKey
       @_id              = doc._id
       @_rev             = doc._rev
-      @metadata         = doc.metadata || doc.data || {}
+      @metadata         = doc.metadata ? doc.data ? {}
       @content          = doc.content
 
       @dataKeyLink      = doc.dataKeyLink

          else
            @_getParentKey(doc, parentFolder).then (parentKey) =>
              CrypTree.resolveSymLink(linkOrKey, parentKey).then (key) =>
                console.log "dataOrSFKey", key
                if not doc.isFolder
                  # dataKey
                  return key

      @subfolderKey     = doc.subfolderKey
      @dataKey          = doc.dataKey

      @parentId         = parentId ? doc.parentId
      @keyDurty         = doc.keyDurty ? false

      if not @dataKey and parentKey?
        @generateReadCrypTreeKeys(parentKey)
        @generateWriteCrypTreeKeys()

    #
    # Static method
    #
    @_getParent: (doc, parentFolder) ->
      deferred = $q.defer()
