Improve resource loading on userstory detail.

stable
Andrey Antukh 2014-09-04 11:46:50 +02:00
parent 7ae59899d9
commit 10457af144
1 changed files with 22 additions and 18 deletions

View File

@ -48,21 +48,25 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @log, @appTitle, @navUrls) -> constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @log, @appTitle, @navUrls) ->
@.attachmentsUrlName = "userstories/attachments" @.attachmentsUrlName = "userstories/attachments"
@scope.issueRef = @params.issueref @scope.issueRef = @params.issueref
@scope.sectionName = "User Story Details" @scope.sectionName = "User Story Details"
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () => # On Success
promise.then =>
@appTitle.set(@scope.us.subject + " - " + @scope.project.name) @appTitle.set(@scope.us.subject + " - " + @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)
@scope.$on "attachment:create", @loadHistory @scope.$on("attachment:create", => @loadHistory())
@scope.$on "attachment:edit", @loadHistory @scope.$on("attachment:edit", => @loadHistory())
@scope.$on "attachment:delete", @loadHistory @scope.$on("attachment:delete", => @loadHistory())
loadProject: -> loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) => return @rs.projects.get(@scope.projectId).then (project) =>
@ -95,14 +99,17 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
} }
@scope.nextUrl = @navUrls.resolve("project-userstories-detail", ctx) @scope.nextUrl = @navUrls.resolve("project-userstories-detail", ctx)
return us
loadTasks: -> loadTasks: ->
return @rs.tasks.list(@scope.projectId, null, @scope.usId).then (tasks) => return @rs.tasks.list(@scope.projectId, null, @scope.usId).then (tasks) =>
@scope.tasks = tasks @scope.tasks = tasks
return tasks
loadHistory: => loadHistory: =>
return @rs.userstories.history(@scope.usId).then (history) => return @rs.userstories.history(@scope.usId).then (history) =>
_.each history, (historyResult) -> for historyResult in history
#If description was modified take only the description_html field # If description was modified take only the description_html field
if historyResult.values_diff.description? if historyResult.values_diff.description?
historyResult.values_diff.description = historyResult.values_diff.description_diff historyResult.values_diff.description = historyResult.values_diff.description_diff
@ -117,6 +124,7 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
@scope.history = history @scope.history = history
@scope.comments = _.filter(history, (historyEntry) -> historyEntry.comment != "") @scope.comments = _.filter(history, (historyEntry) -> historyEntry.comment != "")
return history
loadInitialData: -> loadInitialData: ->
params = { params = {
@ -129,16 +137,12 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin,
@scope.usId = data.us @scope.usId = data.us
return data return data
promise.then null, =>
@location.path("/not-found")
@location.replace()
return promise.then(=> @.loadProject()) return promise.then(=> @.loadProject())
.then(=> @.loadUsersAndRoles()) .then(=> @q.all([@.loadUsersAndRoles(),
.then(=> @.loadUs()) @.loadUs(),
.then(=> @.loadTasks()) @.loadTasks(),
.then(=> @.loadAttachments(@scope.usId)) @.loadAttachments(@scope.usId),
.then(=> @.loadHistory()) @.loadHistory()]))
block: -> block: ->
@rootscope.$broadcast("block", @scope.us) @rootscope.$broadcast("block", @scope.us)