Improve resource loading on wiki.

stable
Andrey Antukh 2014-09-04 13:13:01 +02:00
parent 18e5216c7f
commit 4f71ed2e04
1 changed files with 34 additions and 32 deletions

View File

@ -51,18 +51,22 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin, taig
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @filter, @log, @appTitle, constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @filter, @log, @appTitle,
@navUrls) -> @navUrls) ->
@.attachmentsUrlName = "wiki/attachments" @.attachmentsUrlName = "wiki/attachments"
@scope.projectSlug = @params.pslug @scope.projectSlug = @params.pslug
@scope.wikiSlug = @params.slug @scope.wikiSlug = @params.slug
@scope.sectionName = "Wiki" @scope.sectionName = "Wiki"
promise = @.loadInitialData() promise = @.loadInitialData()
# On Success
promise.then () => promise.then () =>
@appTitle.set("Wiki - " + @scope.project.name) @appTitle.set("Wiki - " + @scope.project.name)
promise.then null, -> # On Error
console.log "FAIL" #TODO promise.then null, (xhr) =>
if xhr and xhr.status == 404
@location.path("/not-found")
@location.replace()
return @q.reject(xhr)
loadProject: -> loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) => return @rs.projects.get(@scope.projectId).then (project) =>
@ -71,52 +75,50 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin, taig
@scope.membersById = groupBy(project.memberships, (x) -> x.user) @scope.membersById = groupBy(project.memberships, (x) -> x.user)
return project return project
loadWikiSlug: ->
params = {
pslug: @params.pslug
wikipage: @params.slug
}
promise = @repo.resolve(params).then (data) =>
@scope.wikiId = data.wikipage
@scope.projectId = data.project
return data
promise.then null, =>
ctx = {
project: @params.pslug
slug: @params.slug
}
@location.path(@navUrls.resolve("project-wiki-page-edit", ctx))
loadWiki: -> loadWiki: ->
if @scope.wikiId if @scope.wikiId
return @rs.wiki.get(@scope.wikiId).then (wiki) => return @rs.wiki.get(@scope.wikiId).then (wiki) =>
@scope.wiki = wiki @scope.wiki = wiki
else return wiki
return @scope.wiki = {
content: "" @scope.wiki = {content: ""}
} return @scope.wiki
loadWikiLinks: -> loadWikiLinks: ->
return @rs.wiki.listLinks(@scope.projectId).then (wikiLinks) => return @rs.wiki.listLinks(@scope.projectId).then (wikiLinks) =>
@scope.wikiLinks = wikiLinks @scope.wikiLinks = wikiLinks
loadInitialData: -> loadInitialData: ->
params = {
pslug: @params.pslug
wikipage: @params.slug
}
# Resolve project slug # Resolve project slug
promise = @repo.resolve({pslug: @params.pslug}).then (data) => promise = @repo.resolve({pslug: @params.pslug}).then (data) =>
@scope.projectId = data.project @scope.projectId = data.project
return data return data
promise.then null, => # Resolve wiki slug
@location.path("/not-found") # This should be done in two steps because is not same thing
@location.replace() # not found response for project and not found for wiki page
# and they should be hendled separately.
promise = promise.then =>
prom = @repo.resolve({wikipage: @params.slug, pslug: @params.pslug})
prom = prom.then (data) =>
@scope.wikiId = data.wikipage
return prom.then null, (xhr) =>
ctx = {project: @params.pslug, slug: @params.slug}
@location.path(@navUrls.resolve("project-wiki-page-edit", ctx))
return @q.reject()
return promise.then(=> @.loadProject()) return promise.then(=> @.loadProject())
.then(=> @.loadUsersAndRoles()) .then(=> @q.all([@.loadUsersAndRoles(),
.then(=> @.loadWikiLinks()) @.loadWikiLinks(),
.then(=> @.loadWikiSlug()) @.loadWiki(),
.then(=> @.loadWiki()) @.loadAttachments(@scope.wikiId)]))
.then(=> @.loadAttachments(@scope.wikiId))
edit: -> edit: ->
ctx = { ctx = {