2014-10-31 06:34:18 -04:00
|
|
|
_ = require("underscore")
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
module.exports = ProjectEditorHandler =
|
2016-08-01 12:05:37 -04:00
|
|
|
buildProjectModelView: (project, members, invites) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
result =
|
|
|
|
_id : project._id
|
|
|
|
name : project.name
|
|
|
|
rootDoc_id : project.rootDoc_id
|
|
|
|
rootFolder : [@buildFolderModelView project.rootFolder[0]]
|
|
|
|
publicAccesLevel : project.publicAccesLevel
|
|
|
|
dropboxEnabled : !!project.existsInDropbox
|
|
|
|
compiler : project.compiler
|
|
|
|
description: project.description
|
|
|
|
spellCheckLanguage: project.spellCheckLanguage
|
|
|
|
deletedByExternalDataSource : project.deletedByExternalDataSource || false
|
2014-06-05 08:11:39 -04:00
|
|
|
deletedDocs: project.deletedDocs
|
2016-03-07 10:25:10 -05:00
|
|
|
members: []
|
2016-08-15 10:22:23 -04:00
|
|
|
invites: invites
|
|
|
|
|
|
|
|
if !result.invites?
|
|
|
|
result.invites = []
|
2016-08-01 12:05:37 -04:00
|
|
|
|
2016-08-04 11:47:48 -04:00
|
|
|
{owner, ownerFeatures, members} = @buildOwnerAndMembersViews(members)
|
|
|
|
result.owner = owner
|
|
|
|
result.members = members
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2016-08-04 11:47:48 -04:00
|
|
|
result.features = _.defaults(ownerFeatures or {}, {
|
2016-03-15 10:44:06 -04:00
|
|
|
collaborators: -1 # Infinite
|
|
|
|
versioning: false
|
|
|
|
dropbox:false
|
|
|
|
compileTimeout: 60
|
|
|
|
compileGroup:"standard"
|
|
|
|
templates: false
|
|
|
|
references: false
|
|
|
|
})
|
2014-10-20 07:21:40 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
return result
|
|
|
|
|
2016-08-04 11:47:48 -04:00
|
|
|
buildOwnerAndMembersViews: (members) ->
|
|
|
|
owner = null
|
|
|
|
ownerFeatures = null
|
|
|
|
filteredMembers = []
|
|
|
|
for member in members
|
|
|
|
if member.privilegeLevel == "owner"
|
|
|
|
ownerFeatures = member.user.features
|
|
|
|
owner = @buildUserModelView member.user, "owner"
|
|
|
|
else
|
|
|
|
filteredMembers.push @buildUserModelView member.user, member.privilegeLevel
|
|
|
|
{owner: owner, ownerFeatures: ownerFeatures, members: filteredMembers}
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
buildUserModelView: (user, privileges) ->
|
|
|
|
_id : user._id
|
|
|
|
first_name : user.first_name
|
|
|
|
last_name : user.last_name
|
|
|
|
email : user.email
|
|
|
|
privileges : privileges
|
|
|
|
signUpDate : user.signUpDate
|
|
|
|
|
|
|
|
buildFolderModelView: (folder) ->
|
2016-03-23 06:54:36 -04:00
|
|
|
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
|
2014-02-12 05:23:40 -05:00
|
|
|
_id : folder._id
|
|
|
|
name : folder.name
|
2016-03-23 06:54:36 -04:00
|
|
|
folders : @buildFolderModelView childFolder for childFolder in (folder.folders or [])
|
2014-10-31 06:34:18 -04:00
|
|
|
fileRefs : @buildFileModelView file for file in fileRefs
|
2016-03-23 06:54:36 -04:00
|
|
|
docs : @buildDocModelView doc for doc in (folder.docs or [])
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
buildFileModelView: (file) ->
|
|
|
|
_id : file._id
|
|
|
|
name : file.name
|
|
|
|
|
|
|
|
buildDocModelView: (doc) ->
|
|
|
|
_id : doc._id
|
|
|
|
name : doc.name
|