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,18 +58,27 @@ 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
|
||||||
|
tags: (cb)->
|
||||||
|
TagsHandler.getAllTags user_id, cb
|
||||||
|
projects: (cb)->
|
||||||
|
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel', cb
|
||||||
|
}, (err, results)->
|
||||||
|
logger.log results:results, user_id:user_id, "rendering project list"
|
||||||
|
viewModel = _buildListViewModel results.projects[0], results.projects[1], results.projects[2], results.tags[0], results.tags[1], results.subscription[0]
|
||||||
|
res.render 'project/list', viewModel
|
||||||
|
timer.done()
|
||||||
|
|
||||||
|
|
||||||
|
_buildListViewModel = (projects, collabertions, readOnlyProjects, tags, tagsGroupedByProject, subscription)->
|
||||||
# TODO: Remove this one month after the ability to start free trials was removed
|
# TODO: Remove this one month after the ability to start free trials was removed
|
||||||
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
||||||
freeTrial =
|
freeTrial =
|
||||||
expired: !!subscription.freeTrial.downgraded
|
expired: !!subscription.freeTrial.downgraded
|
||||||
expiresAt: SubscriptionFormatters.formatDate(subscription.freeTrial.expiresAt)
|
expiresAt: SubscriptionFormatters.formatDate(subscription.freeTrial.expiresAt)
|
||||||
TagsHandler.getAllTags user_id, (err, tags, tagsGroupedByProject)->
|
|
||||||
logger.log user_id: user_id, "project list timer - TagsHandler.getAllTags"
|
|
||||||
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel', (projects, collabertions, readOnlyProjects)->
|
|
||||||
logger.log user_id: user_id, "project list timer - Project.findAllUsersProjects"
|
|
||||||
for project in projects
|
for project in projects
|
||||||
project.accessLevel = "owner"
|
project.accessLevel = "owner"
|
||||||
for project in collabertions
|
for project in collabertions
|
||||||
|
@ -82,15 +91,14 @@ module.exports =
|
||||||
return project
|
return project
|
||||||
tags = _.sortBy tags, (tag)->
|
tags = _.sortBy tags, (tag)->
|
||||||
-tag.project_ids.length
|
-tag.project_ids.length
|
||||||
logger.log projects:projects, collabertions:collabertions, readOnlyProjects:readOnlyProjects, user_id:user_id, "rendering project list"
|
|
||||||
sortedProjects = _.sortBy projects, (project)->
|
sortedProjects = _.sortBy projects, (project)->
|
||||||
return - project.lastUpdated
|
return - project.lastUpdated
|
||||||
res.render 'project/list',
|
|
||||||
|
return {
|
||||||
title:'Your Projects'
|
title:'Your Projects'
|
||||||
priority_title: true
|
priority_title: true
|
||||||
projects: sortedProjects
|
projects: sortedProjects
|
||||||
freeTrial: freeTrial
|
freeTrial: freeTrial
|
||||||
tags:tags
|
tags:tags
|
||||||
projectTabActive: true
|
projectTabActive: true
|
||||||
logger.log user_id: user_id, "project list timer - Finished"
|
}
|
||||||
timer.done()
|
|
|
@ -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