diff --git a/services/web/app/coffee/Features/Project/ProjectEditorHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEditorHandler.coffee index a3d8319424..4e4991a855 100644 --- a/services/web/app/coffee/Features/Project/ProjectEditorHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEditorHandler.coffee @@ -46,12 +46,12 @@ module.exports = ProjectEditorHandler = signUpDate : user.signUpDate buildFolderModelView: (folder) -> - fileRefs = _.filter folder.fileRefs, (file)-> file? + fileRefs = _.filter (folder.fileRefs or []), (file)-> file? _id : folder._id name : folder.name - folders : @buildFolderModelView childFolder for childFolder in folder.folders + folders : @buildFolderModelView childFolder for childFolder in (folder.folders or []) fileRefs : @buildFileModelView file for file in fileRefs - docs : @buildDocModelView doc for doc in folder.docs + docs : @buildDocModelView doc for doc in (folder.docs or []) buildFileModelView: (file) -> _id : file._id diff --git a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee index fff91d2ce3..e039f60ca6 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee @@ -22,7 +22,9 @@ module.exports = ProjectEntityHandler = folders = {} processFolder = (basePath, folder) -> folders[basePath] = folder - processFolder path.join(basePath, childFolder.name), childFolder for childFolder in folder.folders + for childFolder in (folder.folders or []) + if childFolder.name? + processFolder path.join(basePath, childFolder.name), childFolder ProjectGetter.getProjectWithoutDocLines project_id, (err, project) -> return callback(err) if err? @@ -43,11 +45,11 @@ module.exports = ProjectEntityHandler = for docContent in docContentsArray docContents[docContent._id] = docContent - ProjectEntityHandler.getAllFolders project_id, (error, folders) -> + ProjectEntityHandler.getAllFolders project_id, (error, folders = {}) -> return callback(error) if error? docs = {} for folderPath, folder of folders - for doc in folder.docs + for doc in (folder.docs or []) content = docContents[doc._id.toString()] if content? docs[path.join(folderPath, doc.name)] = { @@ -61,11 +63,11 @@ module.exports = ProjectEntityHandler = getAllFiles: (project_id, callback) -> logger.log project_id:project_id, "getting all files for project" - @getAllFolders project_id, (err, folders) -> + @getAllFolders project_id, (err, folders = {}) -> return callback(err) if err? files = {} for folderPath, folder of folders - for file in folder.fileRefs + for file in (folder.fileRefs or []) if file? files[path.join(folderPath, file.name)] = file callback null, files diff --git a/services/web/app/coffee/Features/References/ReferencesHandler.coffee b/services/web/app/coffee/Features/References/ReferencesHandler.coffee index bd31345f87..c033a4999f 100644 --- a/services/web/app/coffee/Features/References/ReferencesHandler.coffee +++ b/services/web/app/coffee/Features/References/ReferencesHandler.coffee @@ -20,13 +20,13 @@ module.exports = ReferencesHandler = ids = [] _process = (folder) -> - folder.docs.forEach (doc) -> + (folder.docs or []).forEach (doc) -> if doc?.name?.match(/^.*\.bib$/) ids.push(doc._id) - folder.folders.forEach (folder) -> + (folder.folders or []).forEach (folder) -> _process(folder) - project.rootFolder.forEach (rootFolder) -> + (project.rootFolder or []).forEach (rootFolder) -> _process(rootFolder) return ids