Improve resource loading on backlog.

stable
Andrey Antukh 2014-09-04 10:55:58 +02:00
parent dbce8d722a
commit 9709039edc
1 changed files with 26 additions and 32 deletions

View File

@ -56,12 +56,17 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () => # On Success
promise.then =>
@appTitle.set("Backlog - " + @scope.project.name) @appTitle.set("Backlog - " + @scope.project.name)
tgLoader.pageLoaded() tgLoader.pageLoaded()
promise.then null, => # On Error
console.log "FAIL" promise.then null, (xhr) =>
if xhr and xhr.status == 404
@location.path("/not-found")
@location.replace()
return @q.reject(xhr)
@scope.$on("usform:bulk:success", @.loadUserstories) @scope.$on("usform:bulk:success", @.loadUserstories)
@scope.$on("sprintform:create:success", @.loadSprints) @scope.$on("sprintform:create:success", @.loadSprints)
@ -109,8 +114,8 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
@scope.filtersQ = "" @scope.filtersQ = ""
_.forEach [selectedTags, selectedStatuses], (filterGrp) => _.each [selectedTags, selectedStatuses], (filterGrp) =>
_.forEach filterGrp, (item) => _.each filterGrp, (item) =>
filters = @scope.filters[item.type] filters = @scope.filters[item.type]
filter = _.find(filters, {id: taiga.toString(item.id)}) filter = _.find(filters, {id: taiga.toString(item.id)})
filter.selected = false filter.selected = false
@ -119,32 +124,25 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
@.loadUserstories() @.loadUserstories()
# @.filterVisibleUserstories()
# @rootscope.$broadcast("filters:loaded", @scope.filters)
loadUserstories: -> loadUserstories: ->
@scope.urlFilters = @.getUrlFilters() @scope.httpParams = @.getUrlFilters()
@scope.httpParams = {}
for name, values of @scope.urlFilters
@scope.httpParams[name] = values
@rs.userstories.storeQueryParams(@scope.projectId, @scope.httpParams) @rs.userstories.storeQueryParams(@scope.projectId, @scope.httpParams)
@.refreshTagsColors().then => promise = @.refreshTagsColors().then =>
@rs.userstories.listUnassigned(@scope.projectId, @scope.httpParams).then (userstories) => return @rs.userstories.listUnassigned(@scope.projectId, @scope.httpParams)
@scope.userstories = userstories
@.generateFilters() return promise.then (userstories) =>
@.filterVisibleUserstories() @scope.userstories = userstories
@.generateFilters()
@.filterVisibleUserstories()
@rootscope.$broadcast("filters:loaded", @scope.filters) @rootscope.$broadcast("filters:loaded", @scope.filters)
# The broadcast must be executed when the DOM has been fully reloaded. # The broadcast must be executed when the DOM has been fully reloaded.
# We can't assure when this exactly happens so we need a defer # We can't assure when this exactly happens so we need a defer
scopeDefer @scope, => scopeDefer @scope, =>
@scope.$broadcast("userstories:loaded") @scope.$broadcast("userstories:loaded")
return userstories return userstories
loadBacklog: -> loadBacklog: ->
return @q.all([ return @q.all([
@ -169,13 +167,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
@scope.projectId = data.project @scope.projectId = data.project
return data return data
promise.then null, => return promise.then(=> @loadProject())
@location.path("/not-found") .then(=> @q.all([@.loadUsersAndRoles(),
@location.replace() @.loadBacklog()]))
return promise.then(=> @.loadProject())
.then(=> @.loadUsersAndRoles())
.then(=> @.loadBacklog())
filterVisibleUserstories: -> filterVisibleUserstories: ->
@scope.visibleUserstories = [] @scope.visibleUserstories = []