Fixing redirection when creating project

stable
Alejandro Alonso 2014-08-14 10:36:03 +02:00
parent 266d89a567
commit e21e23e5e4
4 changed files with 33 additions and 35 deletions

View File

@ -420,3 +420,27 @@ AppTitle = () ->
return {set: set} return {set: set}
module.factory("$appTitle", AppTitle) module.factory("$appTitle", AppTitle)
#############################################################################
## Get the appropiate section url for a project
## according to his enabled features and user permisions
#############################################################################
ProjectUrl = ($navurls) ->
get = (project) ->
if project.is_backlog_activated and project.my_permissions.indexOf("view_us")>-1
url = $navurls.resolve("project-backlog")
else if project.is_kanban_activated and project.my_permissions.indexOf("view_us")>-1
url = $navurls.resolve("project-kanban")
else if project.is_wiki_activated and project.my_permissions.indexOf("view_wiki_pages")>-1
url = $navurls.resolve("project-wiki")
else if project.is_issues_activated and project.my_permissions.indexOf("view_issues")>-1
url = $navurls.resolve("project-issues")
else
url = $navurls.resolve("project")
return $navurls.formatUrl(url, {'project': project.slug})
return {get: get}
module.factory("$projectUrl", ["$tgNavUrls", ProjectUrl])

View File

@ -29,9 +29,9 @@ module = angular.module("taigaNavMenu", [])
## Projects Navigation ## Projects Navigation
############################################################################# #############################################################################
class ProjectsNavigationController extends taiga.Controller class ProjectsNavigationController extends taiga.Controller
@.$inject = ["$scope", "$rootScope", "$tgResources", "$tgNavUrls"] @.$inject = ["$scope", "$rootScope", "$tgResources", "$tgNavUrls", "$projectUrl"]
constructor: (@scope, @rootscope, @rs, @navurls) -> constructor: (@scope, @rootscope, @rs, @navurls, @projectUrl) ->
promise = @.loadInitialData() promise = @.loadInitialData()
promise.then null, -> promise.then null, ->
console.log "FAIL" console.log "FAIL"
@ -48,18 +48,7 @@ class ProjectsNavigationController extends taiga.Controller
loadInitialData: -> loadInitialData: ->
return @rs.projects.list().then (projects) => return @rs.projects.list().then (projects) =>
for project in projects for project in projects
if project.is_backlog_activated and project.my_permissions.indexOf("view_us")>-1 project.url = @projectUrl.get(project)
url = @navurls.resolve("project-backlog")
else if project.is_kanban_activated and project.my_permissions.indexOf("view_us")>-1
url = @navurls.resolve("project-kanban")
else if project.is_wiki_activated and project.my_permissions.indexOf("view_wiki_pages")>-1
url = @navurls.resolve("project-wiki")
else if project.is_issues_activated and project.my_permissions.indexOf("view_issues")>-1
url = @navurls.resolve("project-issues")
else
url = @navurls.resolve("project")
project.url = @navurls.formatUrl(url, {'project': project.slug})
@scope.projects = projects @scope.projects = projects
@scope.filteredProjects = projects @scope.filteredProjects = projects

View File

@ -3,7 +3,7 @@ bindOnce = @.taiga.bindOnce
module = angular.module("taigaProject") module = angular.module("taigaProject")
CreateProject = ($rootscope, $repo, $confirm, $location, $navurls, $rs, lightboxService) -> CreateProject = ($rootscope, $repo, $confirm, $location, $navurls, $rs, $projectUrl, lightboxService) ->
link = ($scope, $el, attrs) -> link = ($scope, $el, attrs) ->
$scope.data = {} $scope.data = {}
$scope.templates = [] $scope.templates = []
@ -11,13 +11,8 @@ CreateProject = ($rootscope, $repo, $confirm, $location, $navurls, $rs, lightbox
onSuccessSubmit = (response) -> onSuccessSubmit = (response) ->
lightboxService.close($el) lightboxService.close($el)
$confirm.notify("success", "Success") #TODO: i18n $confirm.notify("success", "Success") #TODO: i18n
$location.url($projectUrl.get(response))
url = $navurls.resolve('project')
fullUrl = $navurls.formatUrl(url, {'project': response.slug})
$location.url(fullUrl)
$rootscope.$broadcast("projects:reload") $rootscope.$broadcast("projects:reload")
onErrorSubmit = (response) -> onErrorSubmit = (response) ->
@ -54,6 +49,7 @@ module.directive("tgLbCreateProject", [
"$location", "$location",
"$tgNavUrls", "$tgNavUrls",
"$tgResources", "$tgResources",
"$projectUrl",
"lightboxService", "lightboxService",
CreateProject CreateProject
]) ])

View File

@ -3,9 +3,9 @@ module = angular.module("taigaProject")
class ProjectsController extends taiga.Controller class ProjectsController extends taiga.Controller
@.$inject = ["$scope", "$tgResources", "$rootScope", "$tgNavUrls", "$tgAuth", "$location", "$appTitle"] @.$inject = ["$scope", "$tgResources", "$rootScope", "$tgNavUrls", "$tgAuth", "$location", "$appTitle", "$projectUrl"]
constructor: (@scope, @rs, @rootscope, @navurls, $auth, $location, appTitle) -> constructor: (@scope, @rs, @rootscope, @navurls, $auth, $location, appTitle, @projectUrl) ->
appTitle.set("Projects") appTitle.set("Projects")
if !$auth.isAuthenticated() if !$auth.isAuthenticated()
@ -19,18 +19,7 @@ class ProjectsController extends taiga.Controller
return @rs.projects.list().then (projects) => return @rs.projects.list().then (projects) =>
@.projects = {'recents': projects.slice(0, 8), 'all': projects.slice(8)} @.projects = {'recents': projects.slice(0, 8), 'all': projects.slice(8)}
for project in projects for project in projects
if project.is_backlog_activated and project.my_permissions.indexOf("view_us")>-1 project.url = @projectUrl.get(project)
url = @navurls.resolve("project-backlog")
else if project.is_kanban_activated and project.my_permissions.indexOf("view_us")>-1
url = @navurls.resolve("project-kanban")
else if project.is_wiki_activated and project.my_permissions.indexOf("view_wiki_pages")>-1
url = @navurls.resolve("project-wiki")
else if project.is_issues_activated and project.my_permissions.indexOf("view_issues")>-1
url = @navurls.resolve("project-issues")
else
url = @navurls.resolve("project")
project.url = @navurls.formatUrl(url, {'project': project.slug})
newProject: -> newProject: ->
@rootscope.$broadcast("projects:create") @rootscope.$broadcast("projects:create")