Merge pull request #9 from taigaio/parallel-loading

Improvements on resource loading.
stable
David Barragán Merino 2014-09-04 14:04:54 +02:00
commit b75dbd4afb
9 changed files with 229 additions and 231 deletions

View File

@ -141,6 +141,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, tgLoade
return promise.then null, (response) -> return promise.then null, (response) ->
if response.status == 0 if response.status == 0
$location.path($navUrls.resolve("error")) $location.path($navUrls.resolve("error"))
$location.replace()
else if response.status == 401 else if response.status == 401
nextPath = $location.path() nextPath = $location.path()
$location.url($navUrls.resolve("login")).search("next=#{nextPath}") $location.url($navUrls.resolve("login")).search("next=#{nextPath}")

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,22 +124,15 @@ 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
return promise.then (userstories) =>
@scope.userstories = userstories
@.generateFilters() @.generateFilters()
@.filterVisibleUserstories() @.filterVisibleUserstories()
@ -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 = []

View File

@ -44,6 +44,7 @@ module.directive("tgMain", ["$rootScope", "$window", TaigaMainDirective])
urls = { urls = {
"home": "/" "home": "/"
"error": "/error"
"login": "/login" "login": "/login"
"forgot-password": "/forgot-password" "forgot-password": "/forgot-password"
"change-password": "/change-password/:token" "change-password": "/change-password/:token"

View File

@ -56,15 +56,20 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () => # On Success
promise.then =>
@appTitle.set(@scope.issue.subject + " - " + @scope.project.name) @appTitle.set(@scope.issue.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) =>
@ -102,7 +107,7 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai
loadHistory: => loadHistory: =>
return @rs.issues.history(@scope.issueId).then (history) => return @rs.issues.history(@scope.issueId).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
@ -124,15 +129,11 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin, tai
@scope.issueId = data.issue @scope.issueId = data.issue
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(=> @.loadIssue()) @.loadIssue(),
.then(=> @.loadAttachments(@scope.issueId)) @.loadAttachments(@scope.issueId),
.then(=> @.loadHistory()) @.loadHistory()]))
block: -> block: ->
@rootscope.$broadcast("block", @scope.issue) @rootscope.$broadcast("block", @scope.issue)

View File

@ -65,12 +65,17 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () => # On Success
promise.then =>
@appTitle.set("Issues - " + @scope.project.name) @appTitle.set("Issues - " + @scope.project.name)
tgLoader.pageLoaded() tgLoader.pageLoaded()
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 "issueform:new:success", => @scope.$on "issueform:new:success", =>
@.loadIssues() @.loadIssues()
@ -109,23 +114,14 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
return filters[name] return filters[name]
loadMyFilters: -> loadMyFilters: ->
deferred = @q.defer() return @rs.issues.getMyFilters(@scope.projectId).then (filters) =>
promise = @rs.issues.getMyFilters(@scope.projectId) return _.map filters, (value, key) =>
promise.then (filters) -> return {id: key, name: key, type: "myFilters", selected: false}
result = _.map filters, (value, key) =>
obj = {
id: key,
name: key,
type: "myFilters"
}
obj.selected = false
return obj
deferred.resolve(result)
return deferred.promise
removeNotExistingFiltersFromUrl: -> removeNotExistingFiltersFromUrl: ->
currentSearch = @location.search() currentSearch = @location.search()
urlfilters = @.getUrlFilters() urlfilters = @.getUrlFilters()
for filterName, filterValue of urlfilters for filterName, filterValue of urlfilters
if filterName == "page" or filterName == "orderBy" or filterName == "q" if filterName == "page" or filterName == "orderBy" or filterName == "q"
continue continue
@ -162,15 +158,22 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
obj.selected = if isSelected(obj.type, obj.id) then true else undefined obj.selected = if isSelected(obj.type, obj.id) then true else undefined
loadFilters: -> loadFilters: ->
deferred = @q.defer()
urlfilters = @.getUrlFilters() urlfilters = @.getUrlFilters()
if urlfilters.q if urlfilters.q
@scope.filtersQ = urlfilters.q @scope.filtersQ = urlfilters.q
@.loadMyFilters().then (myFilters) => # Load My Filters
promise = @.loadMyFilters().then (myFilters) =>
@scope.filters.myFilters = myFilters @scope.filters.myFilters = myFilters
@rs.issues.filtersData(@scope.projectId).then (data) => return myFilters
# Load default filters data
promise = promise.then =>
return @rs.issues.filtersData(@scope.projectId)
# Format filters and set them on scope
return promise.then (data) =>
usersFiltersFormat = (users, type, unknownOption) => usersFiltersFormat = (users, type, unknownOption) =>
reformatedUsers = _.map users, (t) => reformatedUsers = _.map users, (t) =>
return { return {
@ -205,21 +208,17 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
} }
# Build filters data structure # Build filters data structure
@scope.filters.statuses = choicesFiltersFormat data.statuses, "statuses", @scope.issueStatusById @scope.filters.statuses = choicesFiltersFormat(data.statuses, "statuses", @scope.issueStatusById)
@scope.filters.severities = choicesFiltersFormat data.severities, "severities", @scope.severityById @scope.filters.severities = choicesFiltersFormat(data.severities, "severities", @scope.severityById)
@scope.filters.priorities = choicesFiltersFormat data.priorities, "priorities", @scope.priorityById @scope.filters.priorities = choicesFiltersFormat(data.priorities, "priorities", @scope.priorityById)
@scope.filters.assignedTo = usersFiltersFormat data.assigned_to, "assignedTo", "Unassigned" @scope.filters.assignedTo = usersFiltersFormat(data.assigned_to, "assignedTo", "Unassigned")
@scope.filters.createdBy = usersFiltersFormat data.created_by, "createdBy", "Unknown" @scope.filters.createdBy = usersFiltersFormat(data.created_by, "createdBy", "Unknown")
@scope.filters.types = choicesFiltersFormat data.types, "types", @scope.issueTypeById @scope.filters.types = choicesFiltersFormat(data.types, "types", @scope.issueTypeById)
@scope.filters.tags = tagsFilterFormat data.tags @scope.filters.tags = tagsFilterFormat(data.tags)
@.removeNotExistingFiltersFromUrl() @.removeNotExistingFiltersFromUrl()
@.markSelectedFilters(@scope.filters, urlfilters) @.markSelectedFilters(@scope.filters, urlfilters)
@rootscope.$broadcast("filters:loaded", @scope.filters) @rootscope.$broadcast("filters:loaded", @scope.filters)
deferred.resolve()
return deferred.promise
loadIssues: -> loadIssues: ->
@scope.urlFilters = @.getUrlFilters() @scope.urlFilters = @.getUrlFilters()
@ -247,28 +246,22 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
name = "type" name = "type"
@scope.httpParams[name] = values @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.issues = data.models
@scope.page = data.current @scope.page = data.current
@scope.count = data.count @scope.count = data.count
@scope.paginatedBy = data.paginatedBy @scope.paginatedBy = data.paginatedBy
return data return data
return promise
loadInitialData: -> loadInitialData: ->
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, =>
@location.path("/not-found")
@location.replace()
return promise.then(=> @.loadProject()) return promise.then(=> @.loadProject())
.then(=> @.loadUsersAndRoles()) .then(=> @q.all([@.loadUsersAndRoles(),
.then(=> @.loadFilters()) @.loadFilters(),
.then(=> @.loadIssues()) @.loadIssues()]))
saveCurrentFiltersTo: (newFilter) -> saveCurrentFiltersTo: (newFilter) ->
deferred = @q.defer() deferred = @q.defer()

View File

@ -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) -> constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @appTitle, tgLoader) ->
_.bindAll(@) _.bindAll(@)
@scope.sectionName = "Kanban" @scope.sectionName = "Kanban"
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () =>
# On Success
promise.then =>
@appTitle.set("Kanban - " + @scope.project.name) @appTitle.set("Kanban - " + @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:new:success", @.loadUserstories) @scope.$on("usform:new:success", @.loadUserstories)
@scope.$on("usform:bulk: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) -> onAssignedToChanged: (ctx, userid, us) ->
us.assigned_to = userid us.assigned_to = userid
promise = @repo.save(us) promise = @repo.save(us)
promise.then null, -> promise.then null, ->
console.log "FAIL" # TODO console.log "FAIL" # TODO
@ -107,10 +113,8 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
@scope.project.tags_colors = tags_colors @scope.project.tags_colors = tags_colors
loadUserstories: -> loadUserstories: ->
return @.refreshTagsColors().then =>
return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) => return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) =>
@scope.userstories = userstories @scope.userstories = userstories
@scope.usByStatus = _.groupBy(userstories, "status") @scope.usByStatus = _.groupBy(userstories, "status")
for status in @scope.usStatusList for status in @scope.usStatusList
@ -126,6 +130,7 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
loadKanban: -> loadKanban: ->
return @q.all([ return @q.all([
@.refreshTagsColors(),
@.loadProjectStats(), @.loadProjectStats(),
@.loadUserstories() @.loadUserstories()
]) ])
@ -146,13 +151,9 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
@scope.projectId = data.project @scope.projectId = data.project
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(=> @.loadKanban()) @.loadKanban()]))
.then(=> @scope.$broadcast("redraw:wip")) .then(=> @scope.$broadcast("redraw:wip"))
prepareBulkUpdateData: (uses) -> prepareBulkUpdateData: (uses) ->

View File

@ -53,11 +53,16 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then () => # On Success
promise.then =>
@appTitle.set("Taskboard - " + @scope.project.name) @appTitle.set("Taskboard - " + @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)
# TODO: Reload entire taskboard after create/edit tasks seems # TODO: Reload entire taskboard after create/edit tasks seems
# a big overhead. It should be optimized in near future. # 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, -> promise.then null, ->
console.log "FAIL" # TODO 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: -> loadSprintStats: ->
return @rs.sprints.stats(@scope.projectId, @scope.sprintId).then (stats) => return @rs.sprints.stats(@scope.projectId, @scope.sprintId).then (stats) =>
totalPointsSum =_.reduce(_.values(stats.total_points), ((res, n) -> res + n), 0) totalPointsSum =_.reduce(_.values(stats.total_points), ((res, n) -> res + n), 0)
@ -100,7 +119,6 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
return sprint return sprint
loadTasks: -> loadTasks: ->
return @.refreshTagsColors().then =>
return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) => return @rs.tasks.list(@scope.projectId, @scope.sprintId).then (tasks) =>
@scope.tasks = tasks @scope.tasks = tasks
@scope.usTasks = {} @scope.usTasks = {}
@ -117,25 +135,12 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
return tasks 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
loadTaskboard: -> loadTaskboard: ->
return @q.all([ return @q.all([
@.refreshTagsColors(),
@.loadSprintStats(), @.loadSprintStats(),
@.loadSprint() @.loadSprint().then(=> @.loadTasks())
]).then(=> @.loadTasks()) ])
loadInitialData: -> loadInitialData: ->
params = { params = {
@ -148,13 +153,9 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
@scope.sprintId = data.milestone @scope.sprintId = data.milestone
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(=> @.loadTaskboard()) @.loadTaskboard()]))
taskMove: (ctx, task, usId, statusId, order) -> taskMove: (ctx, task, usId, statusId, order) ->
# Remove task from old position # Remove task from old position

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,13 +99,16 @@ 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)

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 = {