mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
refactored project list, and updated sig for findAllUsersProjects to include err
This commit is contained in:
parent
0c921d9188
commit
a6bd916fbf
7 changed files with 51 additions and 43 deletions
|
@ -58,7 +58,7 @@ module.exports =
|
||||||
callback(err)
|
callback(err)
|
||||||
|
|
||||||
flushUsersProjectToDropbox: (user_id, callback)->
|
flushUsersProjectToDropbox: (user_id, callback)->
|
||||||
Project.findAllUsersProjects user_id, '_id', (projects = [], collabertions = [], readOnlyProjects = [])->
|
Project.findAllUsersProjects user_id, '_id', (err, projects = [], collabertions = [], readOnlyProjects = [])->
|
||||||
projectList = []
|
projectList = []
|
||||||
projectList = projectList.concat(projects)
|
projectList = projectList.concat(projects)
|
||||||
projectList = projectList.concat(collabertions)
|
projectList = projectList.concat(collabertions)
|
||||||
|
|
|
@ -58,39 +58,47 @@ module.exports =
|
||||||
projectListPage: (req, res, next)->
|
projectListPage: (req, res, next)->
|
||||||
timer = new metrics.Timer("project-list")
|
timer = new metrics.Timer("project-list")
|
||||||
user_id = req.session.user._id
|
user_id = req.session.user._id
|
||||||
SubscriptionLocator.getUsersSubscription user_id, (err, subscription)->
|
async.parallel {
|
||||||
logger.log user_id: user_id, "project list timer - Subscription.getUsersSubscription"
|
subscription: (cb)->
|
||||||
return next(error) if error?
|
SubscriptionLocator.getUsersSubscription user_id, cb
|
||||||
# TODO: Remove this one month after the ability to start free trials was removed
|
tags: (cb)->
|
||||||
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
TagsHandler.getAllTags user_id, cb
|
||||||
freeTrial =
|
projects: (cb)->
|
||||||
expired: !!subscription.freeTrial.downgraded
|
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel', cb
|
||||||
expiresAt: SubscriptionFormatters.formatDate(subscription.freeTrial.expiresAt)
|
}, (err, results)->
|
||||||
TagsHandler.getAllTags user_id, (err, tags, tagsGroupedByProject)->
|
logger.log results:results, user_id:user_id, "rendering project list"
|
||||||
logger.log user_id: user_id, "project list timer - TagsHandler.getAllTags"
|
viewModel = _buildListViewModel results.projects[0], results.projects[1], results.projects[2], results.tags[0], results.tags[1], results.subscription[0]
|
||||||
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel', (projects, collabertions, readOnlyProjects)->
|
res.render 'project/list', viewModel
|
||||||
logger.log user_id: user_id, "project list timer - Project.findAllUsersProjects"
|
timer.done()
|
||||||
for project in projects
|
|
||||||
project.accessLevel = "owner"
|
|
||||||
for project in collabertions
|
_buildListViewModel = (projects, collabertions, readOnlyProjects, tags, tagsGroupedByProject, subscription)->
|
||||||
project.accessLevel = "readWrite"
|
# TODO: Remove this one month after the ability to start free trials was removed
|
||||||
for project in readOnlyProjects
|
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
||||||
project.accessLevel = "readOnly"
|
freeTrial =
|
||||||
projects = projects.concat(collabertions).concat(readOnlyProjects)
|
expired: !!subscription.freeTrial.downgraded
|
||||||
projects = projects.map (project)->
|
expiresAt: SubscriptionFormatters.formatDate(subscription.freeTrial.expiresAt)
|
||||||
project.tags = tagsGroupedByProject[project._id] || []
|
|
||||||
return project
|
for project in projects
|
||||||
tags = _.sortBy tags, (tag)->
|
project.accessLevel = "owner"
|
||||||
-tag.project_ids.length
|
for project in collabertions
|
||||||
logger.log projects:projects, collabertions:collabertions, readOnlyProjects:readOnlyProjects, user_id:user_id, "rendering project list"
|
project.accessLevel = "readWrite"
|
||||||
sortedProjects = _.sortBy projects, (project)->
|
for project in readOnlyProjects
|
||||||
return - project.lastUpdated
|
project.accessLevel = "readOnly"
|
||||||
res.render 'project/list',
|
projects = projects.concat(collabertions).concat(readOnlyProjects)
|
||||||
title:'Your Projects'
|
projects = projects.map (project)->
|
||||||
priority_title: true
|
project.tags = tagsGroupedByProject[project._id] || []
|
||||||
projects: sortedProjects
|
return project
|
||||||
freeTrial: freeTrial
|
tags = _.sortBy tags, (tag)->
|
||||||
tags:tags
|
-tag.project_ids.length
|
||||||
projectTabActive: true
|
sortedProjects = _.sortBy projects, (project)->
|
||||||
logger.log user_id: user_id, "project list timer - Finished"
|
return - project.lastUpdated
|
||||||
timer.done()
|
|
||||||
|
return {
|
||||||
|
title:'Your Projects'
|
||||||
|
priority_title: true
|
||||||
|
projects: sortedProjects
|
||||||
|
freeTrial: freeTrial
|
||||||
|
tags:tags
|
||||||
|
projectTabActive: true
|
||||||
|
}
|
|
@ -114,7 +114,7 @@ module.exports =
|
||||||
async.waterfall jobs, callback
|
async.waterfall jobs, callback
|
||||||
|
|
||||||
findUsersProjectByName: (user_id, projectName, callback)->
|
findUsersProjectByName: (user_id, projectName, callback)->
|
||||||
Project.findAllUsersProjects user_id, 'name', (projects, collabertions=[])->
|
Project.findAllUsersProjects user_id, 'name', (err, projects, collabertions=[])->
|
||||||
projects = projects.concat(collabertions)
|
projects = projects.concat(collabertions)
|
||||||
projectName = projectName.toLowerCase()
|
projectName = projectName.toLowerCase()
|
||||||
project = _.find projects, (project)->
|
project = _.find projects, (project)->
|
||||||
|
|
|
@ -56,7 +56,7 @@ ProjectSchema.statics.findAllUsersProjects = (user_id, requiredFields, callback)
|
||||||
this.find {owner_ref:user_id}, requiredFields, (err, projects)=>
|
this.find {owner_ref:user_id}, requiredFields, (err, projects)=>
|
||||||
this.find {collaberator_refs:user_id}, requiredFields, (err, collabertions)=>
|
this.find {collaberator_refs:user_id}, requiredFields, (err, collabertions)=>
|
||||||
this.find {readOnly_refs:user_id}, requiredFields, (err, readOnlyProjects)=>
|
this.find {readOnly_refs:user_id}, requiredFields, (err, readOnlyProjects)=>
|
||||||
callback(projects, collabertions, readOnlyProjects)
|
callback(err, projects, collabertions, readOnlyProjects)
|
||||||
|
|
||||||
sanitizeTypeOfElement = (elementType)->
|
sanitizeTypeOfElement = (elementType)->
|
||||||
lastChar = elementType.slice -1
|
lastChar = elementType.slice -1
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe 'third party data store', ->
|
||||||
user_id = "123u9oijllkj"
|
user_id = "123u9oijllkj"
|
||||||
projectList = [{_id:"123lk"}, {_id:"12ji3ojio"}, {_id:"2jiojdoi"}]
|
projectList = [{_id:"123lk"}, {_id:"12ji3ojio"}, {_id:"2jiojdoi"}]
|
||||||
collabProjectList = [{_id:"213ds"}]
|
collabProjectList = [{_id:"213ds"}]
|
||||||
@projectModel.findAllUsersProjects.callsArgWith(2, projectList, collabProjectList)
|
@projectModel.findAllUsersProjects.callsArgWith(2, null, projectList, collabProjectList)
|
||||||
@handler.flushUsersProjectToDropbox user_id, =>
|
@handler.flushUsersProjectToDropbox user_id, =>
|
||||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[0]._id).should.equal true
|
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[0]._id).should.equal true
|
||||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[1]._id).should.equal true
|
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[1]._id).should.equal true
|
||||||
|
|
|
@ -102,7 +102,7 @@ describe "ProjectController", ->
|
||||||
@readOnly = [{lastUpdated:3, _id:3}]
|
@readOnly = [{lastUpdated:3, _id:3}]
|
||||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
||||||
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})
|
||||||
@ProjectModel.findAllUsersProjects.callsArgWith(2, @projects, @collabertions, @readOnly)
|
@ProjectModel.findAllUsersProjects.callsArgWith(2, null, @projects, @collabertions, @readOnly)
|
||||||
|
|
||||||
it "should render the project/list page", (done)->
|
it "should render the project/list page", (done)->
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ describe 'project model', ->
|
||||||
user_id = "123jojoidns"
|
user_id = "123jojoidns"
|
||||||
stubbedProject = {name:"findThis"}
|
stubbedProject = {name:"findThis"}
|
||||||
projects = [{name:"notThis"}, {name:"wellll"}, stubbedProject, {name:"Noooo"}]
|
projects = [{name:"notThis"}, {name:"wellll"}, stubbedProject, {name:"Noooo"}]
|
||||||
Project.findAllUsersProjects = sinon.stub().callsArgWith(2, projects)
|
Project.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects)
|
||||||
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
||||||
project.should.equal stubbedProject
|
project.should.equal stubbedProject
|
||||||
done()
|
done()
|
||||||
|
@ -236,7 +236,7 @@ describe 'project model', ->
|
||||||
user_id = "123jojoidns"
|
user_id = "123jojoidns"
|
||||||
stubbedProject = {name:"findThis"}
|
stubbedProject = {name:"findThis"}
|
||||||
projects = [{name:"notThis"}, {name:"wellll"}, {name:"Noooo"}]
|
projects = [{name:"notThis"}, {name:"wellll"}, {name:"Noooo"}]
|
||||||
Project.findAllUsersProjects = sinon.stub().callsArgWith(2, projects, [stubbedProject])
|
Project.findAllUsersProjects = sinon.stub().callsArgWith(2, null, projects, [stubbedProject])
|
||||||
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
@locator.findUsersProjectByName user_id, stubbedProject.name.toLowerCase(), (err, project)->
|
||||||
project.should.equal stubbedProject
|
project.should.equal stubbedProject
|
||||||
done()
|
done()
|
||||||
|
|
Loading…
Reference in a new issue