mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
made project page load faaaaaaster
This commit is contained in:
parent
88ba45b9dc
commit
c0780f5a67
1 changed files with 81 additions and 73 deletions
|
@ -75,85 +75,93 @@ module.exports =
|
||||||
timer.done()
|
timer.done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
loadEditor: (req, res)->
|
loadEditor: (req, res)->
|
||||||
timer = new metrics.Timer("load-editor")
|
timer = new metrics.Timer("load-editor")
|
||||||
if !Settings.editorIsOpen
|
if !Settings.editorIsOpen
|
||||||
res.render("general/closed", {title:"updating site"})
|
return res.render("general/closed", {title:"updating site"})
|
||||||
else
|
|
||||||
if req.session.user?
|
user_id = if req.session.user? then req.session.user._id else 'openUser'
|
||||||
user_id = req.session.user._id
|
project_id = req.params.Project_id
|
||||||
|
|
||||||
|
async.parallel {
|
||||||
|
project: (cb)->
|
||||||
|
Project.findPopulatedById project_id, cb
|
||||||
|
user: (cb)->
|
||||||
|
User.findById user_id, cb
|
||||||
|
subscription: (cb)->
|
||||||
|
SubscriptionLocator.getUsersSubscription user_id, cb
|
||||||
|
}, (err, results)->
|
||||||
|
if err?
|
||||||
|
return res.send 500
|
||||||
|
project = results.project
|
||||||
|
user = results.user
|
||||||
|
subscription = results.subscription
|
||||||
|
|
||||||
|
if user_id == 'openUser'
|
||||||
|
anonymous = true
|
||||||
|
user = defaultSettingsForAnonymousUser(user_id)
|
||||||
else
|
else
|
||||||
user_id = 'openUser'
|
anonymous = false
|
||||||
project_id = req.params.Project_id
|
|
||||||
Project.findPopulatedById project_id, (err, project)->
|
SecurityManager.userCanAccessProject user, project, (canAccess, privilegeLevel)->
|
||||||
User.findById user_id, (err, user)->
|
if !canAccess
|
||||||
if user_id == 'openUser'
|
return res.send 401
|
||||||
anonymous = true
|
|
||||||
user =
|
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
||||||
id : user_id
|
allowedFreeTrial = !!subscription.freeTrial.allowed || true
|
||||||
ace:
|
|
||||||
mode:'none'
|
res.render 'project/editor',
|
||||||
theme:'textmate'
|
title: project.name
|
||||||
fontSize: '12'
|
priority_title: true
|
||||||
autoComplete: true
|
bodyClasses: ["editor"]
|
||||||
spellCheckLanguage: ""
|
project : project
|
||||||
pdfViewer: ""
|
userObject : JSON.stringify({
|
||||||
subscription:
|
id : user.id
|
||||||
freeTrial:
|
email : user.email
|
||||||
allowed: true
|
first_name : user.first_name
|
||||||
featureSwitches:
|
last_name : user.last_name
|
||||||
dropbox: false
|
referal_id : user.referal_id
|
||||||
trackChanges: false
|
subscription :
|
||||||
else
|
freeTrial: {allowed: allowedFreeTrial}
|
||||||
anonymous = false
|
})
|
||||||
SubscriptionLocator.getUsersSubscription user?._id, (err, subscription)->
|
userSettingsObject: JSON.stringify({
|
||||||
SecurityManager.userCanAccessProject user, project, (canAccess, privilegeLevel)->
|
mode : user.ace.mode
|
||||||
allowedFreeTrial = true
|
theme : user.ace.theme
|
||||||
if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt?
|
project_id : project._id
|
||||||
allowedFreeTrial = !!subscription.freeTrial.allowed
|
fontSize : user.ace.fontSize
|
||||||
if canAccess
|
autoComplete: user.ace.autoComplete
|
||||||
timer.done()
|
spellCheckLanguage: user.ace.spellCheckLanguage
|
||||||
res.render 'project/editor',
|
pdfViewer : user.ace.pdfViewer
|
||||||
title: project.name
|
docPositions: {}
|
||||||
priority_title: true
|
oldHistory: !!user.featureSwitches?.oldHistory
|
||||||
bodyClasses: ["editor"]
|
})
|
||||||
project : project
|
sharelatexObject : JSON.stringify({
|
||||||
#owner : project.owner_ref
|
siteUrl: Settings.siteUrl,
|
||||||
userObject : JSON.stringify({
|
jsPath: res.locals.jsPath
|
||||||
id : user.id
|
})
|
||||||
email : user.email
|
privilegeLevel: privilegeLevel
|
||||||
first_name : user.first_name
|
loadPdfjs: (user.ace.pdfViewer == "pdfjs")
|
||||||
last_name : user.last_name
|
chatUrl: Settings.apis.chat.url
|
||||||
referal_id : user.referal_id
|
anonymous: anonymous
|
||||||
subscription :
|
languages: Settings.languages
|
||||||
freeTrial: {allowed: allowedFreeTrial}
|
timer.done()
|
||||||
})
|
|
||||||
userSettingsObject: JSON.stringify({
|
|
||||||
mode : user.ace.mode
|
|
||||||
theme : user.ace.theme
|
|
||||||
project_id : project._id
|
|
||||||
fontSize : user.ace.fontSize
|
|
||||||
autoComplete: user.ace.autoComplete
|
|
||||||
spellCheckLanguage: user.ace.spellCheckLanguage
|
|
||||||
pdfViewer : user.ace.pdfViewer
|
|
||||||
docPositions: {}
|
|
||||||
oldHistory: !!user.featureSwitches?.oldHistory
|
|
||||||
})
|
|
||||||
sharelatexObject : JSON.stringify({
|
|
||||||
siteUrl: Settings.siteUrl,
|
|
||||||
jsPath: res.locals.jsPath
|
|
||||||
})
|
|
||||||
privilegeLevel: privilegeLevel
|
|
||||||
loadPdfjs: (user.ace.pdfViewer == "pdfjs")
|
|
||||||
chatUrl: Settings.apis.chat.url
|
|
||||||
anonymous: anonymous
|
|
||||||
languages: Settings.languages
|
|
||||||
else
|
|
||||||
res.send 401
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
defaultSettingsForAnonymousUser = ->
|
||||||
|
id : user_id
|
||||||
|
ace:
|
||||||
|
mode:'none'
|
||||||
|
theme:'textmate'
|
||||||
|
fontSize: '12'
|
||||||
|
autoComplete: true
|
||||||
|
spellCheckLanguage: ""
|
||||||
|
pdfViewer: ""
|
||||||
|
subscription:
|
||||||
|
freeTrial:
|
||||||
|
allowed: true
|
||||||
|
featureSwitches:
|
||||||
|
dropbox: false
|
||||||
|
trackChanges: false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue