From 9709039edca9af3a9b2a218e288c01bdf58098c7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 10:55:58 +0200 Subject: [PATCH 1/8] Improve resource loading on backlog. --- app/coffee/modules/backlog/main.coffee | 58 ++++++++++++-------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/app/coffee/modules/backlog/main.coffee b/app/coffee/modules/backlog/main.coffee index e6b12d85..9dae7be6 100644 --- a/app/coffee/modules/backlog/main.coffee +++ b/app/coffee/modules/backlog/main.coffee @@ -56,12 +56,17 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F promise = @.loadInitialData() - promise.then () => + # On Success + promise.then => @appTitle.set("Backlog - " + @scope.project.name) tgLoader.pageLoaded() - promise.then null, => - console.log "FAIL" + # On Error + 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("sprintform:create:success", @.loadSprints) @@ -109,8 +114,8 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F @scope.filtersQ = "" - _.forEach [selectedTags, selectedStatuses], (filterGrp) => - _.forEach filterGrp, (item) => + _.each [selectedTags, selectedStatuses], (filterGrp) => + _.each filterGrp, (item) => filters = @scope.filters[item.type] filter = _.find(filters, {id: taiga.toString(item.id)}) filter.selected = false @@ -119,32 +124,25 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F @.loadUserstories() - # @.filterVisibleUserstories() - # @rootscope.$broadcast("filters:loaded", @scope.filters) - loadUserstories: -> - @scope.urlFilters = @.getUrlFilters() - - @scope.httpParams = {} - for name, values of @scope.urlFilters - @scope.httpParams[name] = values - + @scope.httpParams = @.getUrlFilters() @rs.userstories.storeQueryParams(@scope.projectId, @scope.httpParams) - @.refreshTagsColors().then => - @rs.userstories.listUnassigned(@scope.projectId, @scope.httpParams).then (userstories) => - @scope.userstories = userstories + promise = @.refreshTagsColors().then => + return @rs.userstories.listUnassigned(@scope.projectId, @scope.httpParams) - @.generateFilters() - @.filterVisibleUserstories() + return promise.then (userstories) => + @scope.userstories = userstories + @.generateFilters() + @.filterVisibleUserstories() - @rootscope.$broadcast("filters:loaded", @scope.filters) - # 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 - scopeDefer @scope, => - @scope.$broadcast("userstories:loaded") + @rootscope.$broadcast("filters:loaded", @scope.filters) + # 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 + scopeDefer @scope, => + @scope.$broadcast("userstories:loaded") - return userstories + return userstories loadBacklog: -> return @q.all([ @@ -169,13 +167,9 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F @scope.projectId = data.project return data - promise.then null, => - @location.path("/not-found") - @location.replace() - - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadBacklog()) + return promise.then(=> @loadProject()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadBacklog()])) filterVisibleUserstories: -> @scope.visibleUserstories = [] From 7ae59899d96684f95786308ce4a11c7aa2f4c6dd Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 11:11:11 +0200 Subject: [PATCH 2/8] Improve resource loading on taskboard. --- app/coffee/modules/taskboard/main.coffee | 77 ++++++++++++------------ 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/app/coffee/modules/taskboard/main.coffee b/app/coffee/modules/taskboard/main.coffee index 274b6081..06254bb7 100644 --- a/app/coffee/modules/taskboard/main.coffee +++ b/app/coffee/modules/taskboard/main.coffee @@ -53,11 +53,16 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) promise = @.loadInitialData() - promise.then () => + # On Success + promise.then => @appTitle.set("Taskboard - " + @scope.project.name) - promise.then null, -> - console.log "FAIL" #TODO + # On Error + promise.then null, (xhr) => + if xhr and xhr.status == 404 + @location.path("/not-found") + @location.replace() + return @q.reject(xhr) # TODO: Reload entire taskboard after create/edit tasks seems # a big overhead. It should be optimized in near future. @@ -72,6 +77,20 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) promise.then null, -> console.log "FAIL" # TODO + loadProject: -> + return @rs.projects.get(@scope.projectId).then (project) => + @scope.project = project + @scope.$emit('project:loaded', project) + # Not used at this momment + @scope.pointsList = _.sortBy(project.points, "order") + # @scope.roleList = _.sortBy(project.roles, "order") + @scope.pointsById = groupBy(project.points, (e) -> e.id) + @scope.roleById = groupBy(project.roles, (e) -> e.id) + @scope.taskStatusList = _.sortBy(project.task_statuses, "order") + @scope.usStatusList = _.sortBy(project.us_statuses, "order") + @scope.usStatusById = groupBy(project.us_statuses, (e) -> e.id) + return project + loadSprintStats: -> return @rs.sprints.stats(@scope.projectId, @scope.sprintId).then (stats) => totalPointsSum =_.reduce(_.values(stats.total_points), ((res, n) -> res + n), 0) @@ -100,42 +119,28 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) return sprint loadTasks: -> - return @.refreshTagsColors().then => - return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) => - @scope.tasks = tasks - @scope.usTasks = {} + return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) => + @scope.tasks = tasks + @scope.usTasks = {} - # Iterate over all userstories and - # null userstory for unassigned tasks - for us in _.union(@scope.userstories, [{id:null}]) - @scope.usTasks[us.id] = {} - for status in @scope.taskStatusList - @scope.usTasks[us.id][status.id] = [] + # Iterate over all userstories and + # null userstory for unassigned tasks + for us in _.union(@scope.userstories, [{id:null}]) + @scope.usTasks[us.id] = {} + for status in @scope.taskStatusList + @scope.usTasks[us.id][status.id] = [] - for task in @scope.tasks - @scope.usTasks[task.user_story][task.status].push(task) + for task in @scope.tasks + @scope.usTasks[task.user_story][task.status].push(task) - return tasks - - loadProject: -> - return @rs.projects.get(@scope.projectId).then (project) => - @scope.project = project - @scope.$emit('project:loaded', project) - # Not used at this momment - @scope.pointsList = _.sortBy(project.points, "order") - # @scope.roleList = _.sortBy(project.roles, "order") - @scope.pointsById = groupBy(project.points, (e) -> e.id) - @scope.roleById = groupBy(project.roles, (e) -> e.id) - @scope.taskStatusList = _.sortBy(project.task_statuses, "order") - @scope.usStatusList = _.sortBy(project.us_statuses, "order") - @scope.usStatusById = groupBy(project.us_statuses, (e) -> e.id) - return project + return tasks loadTaskboard: -> return @q.all([ + @.refreshTagsColors(), @.loadSprintStats(), - @.loadSprint() - ]).then(=> @.loadTasks()) + @.loadSprint().then(=> @.loadTasks()) + ]) loadInitialData: -> params = { @@ -148,13 +153,9 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin) @scope.sprintId = data.milestone return data - promise.then null, => - @location.path("/not-found") - @location.replace() - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadTaskboard()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadTaskboard()])) taskMove: (ctx, task, usId, statusId, order) -> # Remove task from old position From 10457af1445a64a4d1085f239ebff9c4039a27f8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 11:46:50 +0200 Subject: [PATCH 3/8] Improve resource loading on userstory detail. --- app/coffee/modules/userstories/detail.coffee | 40 +++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/app/coffee/modules/userstories/detail.coffee b/app/coffee/modules/userstories/detail.coffee index 6fa81a3b..7a360d5d 100644 --- a/app/coffee/modules/userstories/detail.coffee +++ b/app/coffee/modules/userstories/detail.coffee @@ -48,21 +48,25 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin, constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @log, @appTitle, @navUrls) -> @.attachmentsUrlName = "userstories/attachments" - @scope.issueRef = @params.issueref @scope.sectionName = "User Story Details" promise = @.loadInitialData() - promise.then () => + # On Success + promise.then => @appTitle.set(@scope.us.subject + " - " + @scope.project.name) - promise.then null, -> - console.log "FAIL" #TODO + # On Error + 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:edit", @loadHistory - @scope.$on "attachment:delete", @loadHistory + @scope.$on("attachment:create", => @loadHistory()) + @scope.$on("attachment:edit", => @loadHistory()) + @scope.$on("attachment:delete", => @loadHistory()) loadProject: -> 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) + return us + loadTasks: -> return @rs.tasks.list(@scope.projectId, null, @scope.usId).then (tasks) => @scope.tasks = tasks + return tasks loadHistory: => return @rs.userstories.history(@scope.usId).then (history) => - _.each history, (historyResult) -> - #If description was modified take only the description_html field + for historyResult in history + # If description was modified take only the description_html field if historyResult.values_diff.description? 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.comments = _.filter(history, (historyEntry) -> historyEntry.comment != "") + return history loadInitialData: -> params = { @@ -129,16 +137,12 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin, @scope.usId = data.us return data - promise.then null, => - @location.path("/not-found") - @location.replace() - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadUs()) - .then(=> @.loadTasks()) - .then(=> @.loadAttachments(@scope.usId)) - .then(=> @.loadHistory()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadUs(), + @.loadTasks(), + @.loadAttachments(@scope.usId), + @.loadHistory()])) block: -> @rootscope.$broadcast("block", @scope.us) From a8f753af55d47a8895b1ce90f2d3923d4414d2bb Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 12:41:57 +0200 Subject: [PATCH 4/8] Improve resource loading on issues detail. --- app/coffee/modules/issues/detail.coffee | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/coffee/modules/issues/detail.coffee b/app/coffee/modules/issues/detail.coffee index 81e4c302..f2f99554 100644 --- a/app/coffee/modules/issues/detail.coffee +++ b/app/coffee/modules/issues/detail.coffee @@ -56,15 +56,20 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai promise = @.loadInitialData() - promise.then () => + # On Success + promise.then => @appTitle.set(@scope.issue.subject + " - " + @scope.project.name) - promise.then null, -> - console.log "FAIL" #TODO + # On Error + 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:edit", @loadHistory - @scope.$on "attachment:delete", @loadHistory + @scope.$on("attachment:create", => @.loadHistory()) + @scope.$on("attachment:edit", => @.loadHistory()) + @scope.$on("attachment:delete", => @.loadHistory()) loadProject: -> return @rs.projects.get(@scope.projectId).then (project) => @@ -102,8 +107,8 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai loadHistory: => return @rs.issues.history(@scope.issueId).then (history) => - _.each history, (historyResult) -> - #If description was modified take only the description_html field + for historyResult in history + # If description was modified take only the description_html field if historyResult.values_diff.description? historyResult.values_diff.description = historyResult.values_diff.description_diff @@ -124,15 +129,11 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai @scope.issueId = data.issue return data - promise.then null, => - @location.path("/not-found") - @location.replace() - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadIssue()) - .then(=> @.loadAttachments(@scope.issueId)) - .then(=> @.loadHistory()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadIssue(), + @.loadAttachments(@scope.issueId), + @.loadHistory()])) block: -> @rootscope.$broadcast("block", @scope.issue) From e6ed0caee017e1465442ab5565a1d8577e370448 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 12:42:26 +0200 Subject: [PATCH 5/8] Improve resource loading on issues list. --- app/coffee/modules/issues/list.coffee | 137 ++++++++++++-------------- 1 file changed, 65 insertions(+), 72 deletions(-) diff --git a/app/coffee/modules/issues/list.coffee b/app/coffee/modules/issues/list.coffee index 14c004ae..1b3dc3c7 100644 --- a/app/coffee/modules/issues/list.coffee +++ b/app/coffee/modules/issues/list.coffee @@ -65,12 +65,17 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi promise = @.loadInitialData() - promise.then () => + # On Success + promise.then => @appTitle.set("Issues - " + @scope.project.name) tgLoader.pageLoaded() - promise.then null, -> - console.log "FAIL" #TODO + # On Error + promise.then null, (xhr) => + if xhr and xhr.status == 404 + @location.path("/not-found") + @location.replace() + return @q.reject(xhr) @scope.$on "issueform:new:success", => @.loadIssues() @@ -109,23 +114,14 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi return filters[name] loadMyFilters: -> - deferred = @q.defer() - promise = @rs.issues.getMyFilters(@scope.projectId) - promise.then (filters) -> - result = _.map filters, (value, key) => - obj = { - id: key, - name: key, - type: "myFilters" - } - obj.selected = false - return obj - deferred.resolve(result) - return deferred.promise + return @rs.issues.getMyFilters(@scope.projectId).then (filters) => + return _.map filters, (value, key) => + return {id: key, name: key, type: "myFilters", selected: false} removeNotExistingFiltersFromUrl: -> currentSearch = @location.search() urlfilters = @.getUrlFilters() + for filterName, filterValue of urlfilters if filterName == "page" or filterName == "orderBy" or filterName == "q" continue @@ -162,64 +158,67 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi obj.selected = if isSelected(obj.type, obj.id) then true else undefined loadFilters: -> - deferred = @q.defer() urlfilters = @.getUrlFilters() if urlfilters.q @scope.filtersQ = urlfilters.q - @.loadMyFilters().then (myFilters) => + # Load My Filters + promise = @.loadMyFilters().then (myFilters) => @scope.filters.myFilters = myFilters - @rs.issues.filtersData(@scope.projectId).then (data) => - usersFiltersFormat = (users, type, unknownOption) => - reformatedUsers = _.map users, (t) => - return { - id: t[0], - count: t[1], - type: type - name: if t[0] then @scope.usersById[t[0]].full_name_display else unknownOption - } - unknownItem = _.remove(reformatedUsers, (u) -> not u.id) - reformatedUsers = _.sortBy(reformatedUsers, (u) -> u.name.toUpperCase()) - if unknownItem.length > 0 - reformatedUsers.unshift(unknownItem[0]) - return reformatedUsers + return myFilters - choicesFiltersFormat = (choices, type, byIdObject) => - _.map choices, (t) -> - return { - id: t[0], - name: byIdObject[t[0]].name, - color: byIdObject[t[0]].color, - count: t[1], - type: type} + # Load default filters data + promise = promise.then => + return @rs.issues.filtersData(@scope.projectId) - tagsFilterFormat = (tags) => - return _.map tags, (t) => - return { - id: t[0], - name: t[0], - color: @scope.project.tags_colors[t[0]], - count: t[1], - type: "tags" - } + # Format filters and set them on scope + return promise.then (data) => + usersFiltersFormat = (users, type, unknownOption) => + reformatedUsers = _.map users, (t) => + return { + id: t[0], + count: t[1], + type: type + name: if t[0] then @scope.usersById[t[0]].full_name_display else unknownOption + } + unknownItem = _.remove(reformatedUsers, (u) -> not u.id) + reformatedUsers = _.sortBy(reformatedUsers, (u) -> u.name.toUpperCase()) + if unknownItem.length > 0 + reformatedUsers.unshift(unknownItem[0]) + return reformatedUsers - # Build filters data structure - @scope.filters.statuses = choicesFiltersFormat data.statuses, "statuses", @scope.issueStatusById - @scope.filters.severities = choicesFiltersFormat data.severities, "severities", @scope.severityById - @scope.filters.priorities = choicesFiltersFormat data.priorities, "priorities", @scope.priorityById - @scope.filters.assignedTo = usersFiltersFormat data.assigned_to, "assignedTo", "Unassigned" - @scope.filters.createdBy = usersFiltersFormat data.created_by, "createdBy", "Unknown" - @scope.filters.types = choicesFiltersFormat data.types, "types", @scope.issueTypeById - @scope.filters.tags = tagsFilterFormat data.tags + choicesFiltersFormat = (choices, type, byIdObject) => + _.map choices, (t) -> + return { + id: t[0], + name: byIdObject[t[0]].name, + color: byIdObject[t[0]].color, + count: t[1], + type: type} - @.removeNotExistingFiltersFromUrl() + tagsFilterFormat = (tags) => + return _.map tags, (t) => + return { + id: t[0], + name: t[0], + color: @scope.project.tags_colors[t[0]], + count: t[1], + type: "tags" + } - @.markSelectedFilters(@scope.filters, urlfilters) + # Build filters data structure + @scope.filters.statuses = choicesFiltersFormat(data.statuses, "statuses", @scope.issueStatusById) + @scope.filters.severities = choicesFiltersFormat(data.severities, "severities", @scope.severityById) + @scope.filters.priorities = choicesFiltersFormat(data.priorities, "priorities", @scope.priorityById) + @scope.filters.assignedTo = usersFiltersFormat(data.assigned_to, "assignedTo", "Unassigned") + @scope.filters.createdBy = usersFiltersFormat(data.created_by, "createdBy", "Unknown") + @scope.filters.types = choicesFiltersFormat(data.types, "types", @scope.issueTypeById) + @scope.filters.tags = tagsFilterFormat(data.tags) - @rootscope.$broadcast("filters:loaded", @scope.filters) - deferred.resolve() - return deferred.promise + @.removeNotExistingFiltersFromUrl() + @.markSelectedFilters(@scope.filters, urlfilters) + @rootscope.$broadcast("filters:loaded", @scope.filters) loadIssues: -> @scope.urlFilters = @.getUrlFilters() @@ -247,28 +246,22 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi name = "type" @scope.httpParams[name] = values - promise = @rs.issues.list(@scope.projectId, @scope.httpParams).then (data) => + return @rs.issues.list(@scope.projectId, @scope.httpParams).then (data) => @scope.issues = data.models @scope.page = data.current @scope.count = data.count @scope.paginatedBy = data.paginatedBy return data - return promise - loadInitialData: -> promise = @repo.resolve({pslug: @params.pslug}).then (data) => @scope.projectId = data.project return data - promise.then null, => - @location.path("/not-found") - @location.replace() - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadFilters()) - .then(=> @.loadIssues()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadFilters(), + @.loadIssues()])) saveCurrentFiltersTo: (newFilter) -> deferred = @q.defer() From 18e5216c7f10d9c24104cadaa55e16ead207da29 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 12:50:23 +0200 Subject: [PATCH 6/8] Improve resource loading on kanban. --- app/coffee/modules/kanban/main.coffee | 47 ++++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/app/coffee/modules/kanban/main.coffee b/app/coffee/modules/kanban/main.coffee index 11173458..48315440 100644 --- a/app/coffee/modules/kanban/main.coffee +++ b/app/coffee/modules/kanban/main.coffee @@ -50,16 +50,21 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @appTitle, tgLoader) -> _.bindAll(@) - @scope.sectionName = "Kanban" promise = @.loadInitialData() - promise.then () => + + # On Success + promise.then => @appTitle.set("Kanban - " + @scope.project.name) tgLoader.pageLoaded() - promise.then null, => - console.log "FAIL" + # On Error + promise.then null, (xhr) => + if xhr and xhr.status == 404 + @location.path("/not-found") + @location.replace() + return @q.reject(xhr) @scope.$on("usform:new:success", @.loadUserstories) @scope.$on("usform:bulk:success", @.loadUserstories) @@ -84,6 +89,7 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi onAssignedToChanged: (ctx, userid, us) -> us.assigned_to = userid + promise = @repo.save(us) promise.then null, -> console.log "FAIL" # TODO @@ -107,25 +113,24 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi @scope.project.tags_colors = tags_colors loadUserstories: -> - return @.refreshTagsColors().then => - return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) => - @scope.userstories = userstories + return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) => + @scope.userstories = userstories + @scope.usByStatus = _.groupBy(userstories, "status") - @scope.usByStatus = _.groupBy(userstories, "status") + for status in @scope.usStatusList + if not @scope.usByStatus[status.id]? + @scope.usByStatus[status.id] = [] - for status in @scope.usStatusList - if not @scope.usByStatus[status.id]? - @scope.usByStatus[status.id] = [] + # 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 + scopeDefer @scope, => + @scope.$broadcast("userstories:loaded") - # 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 - scopeDefer @scope, => - @scope.$broadcast("userstories:loaded") - - return userstories + return userstories loadKanban: -> return @q.all([ + @.refreshTagsColors(), @.loadProjectStats(), @.loadUserstories() ]) @@ -146,13 +151,9 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi @scope.projectId = data.project return data - promise.then null, => - @location.path("/not-found") - @location.replace() - return promise.then(=> @.loadProject()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadKanban()) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadKanban()])) .then(=> @scope.$broadcast("redraw:wip")) prepareBulkUpdateData: (uses) -> From 4f71ed2e0448bec3e5a7efb61616310c849d380d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 13:13:01 +0200 Subject: [PATCH 7/8] Improve resource loading on wiki. --- app/coffee/modules/wiki/main.coffee | 66 +++++++++++++++-------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/app/coffee/modules/wiki/main.coffee b/app/coffee/modules/wiki/main.coffee index 045d0a3d..4698df4e 100644 --- a/app/coffee/modules/wiki/main.coffee +++ b/app/coffee/modules/wiki/main.coffee @@ -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, @navUrls) -> @.attachmentsUrlName = "wiki/attachments" - @scope.projectSlug = @params.pslug @scope.wikiSlug = @params.slug @scope.sectionName = "Wiki" promise = @.loadInitialData() + # On Success promise.then () => @appTitle.set("Wiki - " + @scope.project.name) - promise.then null, -> - console.log "FAIL" #TODO + # On Error + promise.then null, (xhr) => + if xhr and xhr.status == 404 + @location.path("/not-found") + @location.replace() + return @q.reject(xhr) loadProject: -> 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) 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: -> if @scope.wikiId return @rs.wiki.get(@scope.wikiId).then (wiki) => @scope.wiki = wiki - else - return @scope.wiki = { - content: "" - } + return wiki + + @scope.wiki = {content: ""} + return @scope.wiki loadWikiLinks: -> return @rs.wiki.listLinks(@scope.projectId).then (wikiLinks) => @scope.wikiLinks = wikiLinks loadInitialData: -> + params = { + pslug: @params.pslug + wikipage: @params.slug + } + # Resolve project slug promise = @repo.resolve({pslug: @params.pslug}).then (data) => @scope.projectId = data.project return data - promise.then null, => - @location.path("/not-found") - @location.replace() + # Resolve wiki slug + # This should be done in two steps because is not same thing + # 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()) - .then(=> @.loadUsersAndRoles()) - .then(=> @.loadWikiLinks()) - .then(=> @.loadWikiSlug()) - .then(=> @.loadWiki()) - .then(=> @.loadAttachments(@scope.wikiId)) + .then(=> @q.all([@.loadUsersAndRoles(), + @.loadWikiLinks(), + @.loadWiki(), + @.loadAttachments(@scope.wikiId)])) edit: -> ctx = { From f237e97f45b40987c06360697c7fcfff60ddd0a5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 4 Sep 2014 11:43:01 +0200 Subject: [PATCH 8/8] Fix error page url resolution. Now it properly redirects to error page when api service is down. --- app/coffee/app.coffee | 1 + app/coffee/modules/base.coffee | 1 + 2 files changed, 2 insertions(+) diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index f3e3bfbb..7a7fad73 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -141,6 +141,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, tgLoade return promise.then null, (response) -> if response.status == 0 $location.path($navUrls.resolve("error")) + $location.replace() else if response.status == 401 nextPath = $location.path() $location.url($navUrls.resolve("login")).search("next=#{nextPath}") diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index e0e29489..d9c2f9db 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -44,6 +44,7 @@ module.directive("tgMain", ["$rootScope", "$window", TaigaMainDirective]) urls = { "home": "/" + "error": "/error" "login": "/login" "forgot-password": "/forgot-password" "change-password": "/change-password/:token"