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)
|
||||
|
||||
flushUsersProjectToDropbox: (user_id, callback)->
|
||||
Project.findAllUsersProjects user_id, '_id', (projects = [], collabertions = [], readOnlyProjects = [])->
|
||||
Project.findAllUsersProjects user_id, '_id', (err, projects = [], collabertions = [], readOnlyProjects = [])->
|
||||
projectList = []
|
||||
projectList = projectList.concat(projects)
|
||||
projectList = projectList.concat(collabertions)
|
||||
|
|
|
@ -58,18 +58,27 @@ module.exports =
|
|||
projectListPage: (req, res, next)->
|
||||
timer = new metrics.Timer("project-list")
|
||||
user_id = req.session.user._id
|
||||
SubscriptionLocator.getUsersSubscription user_id, (err, subscription)->
|
||||
logger.log user_id: user_id, "project list timer - Subscription.getUsersSubscription"
|
||||
return next(error) if error?
|
||||
async.parallel {
|
||||
subscription: (cb)->
|
||||
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
|
||||
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
||||
freeTrial =
|
||||
expired: !!subscription.freeTrial.downgraded
|
||||
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
|
||||
project.accessLevel = "owner"
|
||||
for project in collabertions
|
||||
|
@ -82,15 +91,14 @@ module.exports =
|
|||
return project
|
||||
tags = _.sortBy tags, (tag)->
|
||||
-tag.project_ids.length
|
||||
logger.log projects:projects, collabertions:collabertions, readOnlyProjects:readOnlyProjects, user_id:user_id, "rendering project list"
|
||||
sortedProjects = _.sortBy projects, (project)->
|
||||
return - project.lastUpdated
|
||||
res.render 'project/list',
|
||||
|
||||
return {
|
||||
title:'Your Projects'
|
||||
priority_title: true
|
||||
projects: sortedProjects
|
||||
freeTrial: freeTrial
|
||||
tags:tags
|
||||
projectTabActive: true
|
||||
logger.log user_id: user_id, "project list timer - Finished"
|
||||
timer.done()
|
||||
}
|
|
@ -114,7 +114,7 @@ module.exports =
|
|||
async.waterfall jobs, 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)
|
||||
projectName = projectName.toLowerCase()
|
||||
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 {collaberator_refs:user_id}, requiredFields, (err, collabertions)=>
|
||||
this.find {readOnly_refs:user_id}, requiredFields, (err, readOnlyProjects)=>
|
||||
callback(projects, collabertions, readOnlyProjects)
|
||||
callback(err, projects, collabertions, readOnlyProjects)
|
||||
|
||||
sanitizeTypeOfElement = (elementType)->
|
||||
lastChar = elementType.slice -1
|
||||
|
|
|
@ -73,7 +73,7 @@ describe 'third party data store', ->
|
|||
user_id = "123u9oijllkj"
|
||||
projectList = [{_id:"123lk"}, {_id:"12ji3ojio"}, {_id:"2jiojdoi"}]
|
||||
collabProjectList = [{_id:"213ds"}]
|
||||
@projectModel.findAllUsersProjects.callsArgWith(2, projectList, collabProjectList)
|
||||
@projectModel.findAllUsersProjects.callsArgWith(2, null, projectList, collabProjectList)
|
||||
@handler.flushUsersProjectToDropbox user_id, =>
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[0]._id).should.equal true
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[1]._id).should.equal true
|
||||
|
|
|
@ -102,7 +102,7 @@ describe "ProjectController", ->
|
|||
@readOnly = [{lastUpdated:3, _id:3}]
|
||||
@SubscriptionLocator.getUsersSubscription.callsArgWith(1, null, {})
|
||||
@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)->
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ describe 'project model', ->
|
|||
user_id = "123jojoidns"
|
||||
stubbedProject = {name:"findThis"}
|
||||
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)->
|
||||
project.should.equal stubbedProject
|
||||
done()
|
||||
|
@ -236,7 +236,7 @@ describe 'project model', ->
|
|||
user_id = "123jojoidns"
|
||||
stubbedProject = {name:"findThis"}
|
||||
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)->
|
||||
project.should.equal stubbedProject
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue