Implement navigation url service.
parent
2aa95c6e3d
commit
171aaa1f6b
|
@ -57,6 +57,9 @@ modules = [
|
||||||
"taigaBase",
|
"taigaBase",
|
||||||
"taigaResources",
|
"taigaResources",
|
||||||
"taigaLocales",
|
"taigaLocales",
|
||||||
|
"taigaAuth",
|
||||||
|
|
||||||
|
"taigaNavigation",
|
||||||
|
|
||||||
# Specific Modules
|
# Specific Modules
|
||||||
"taigaBacklog",
|
"taigaBacklog",
|
||||||
|
|
|
@ -20,22 +20,28 @@ taiga = @.taiga
|
||||||
class AuthService extends taiga.Service
|
class AuthService extends taiga.Service
|
||||||
@.$inject = ["$rootScope", "$tgStorage", "$tgModel", "$tgHttp"]
|
@.$inject = ["$rootScope", "$tgStorage", "$tgModel", "$tgHttp"]
|
||||||
|
|
||||||
constructor: (@rootScope, @storage, @model, @http) ->
|
constructor: (@rootscope, @storage, @model, @http) ->
|
||||||
super()
|
super()
|
||||||
|
|
||||||
getUser: ->
|
getUser: ->
|
||||||
|
if @rootscope.user
|
||||||
|
return @rootscope.user
|
||||||
|
|
||||||
userData = @storage.get("userInfo")
|
userData = @storage.get("userInfo")
|
||||||
if userData
|
if userData
|
||||||
return @model.make_model("users", userData)
|
user = @model.make_model("users", userData)
|
||||||
|
@rootscope.user = user
|
||||||
|
return user
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
setUser: (user) ->
|
setUser: (user) ->
|
||||||
@rootScope.auth = user
|
@rootscope.auth = user
|
||||||
@rootScope.$broadcast("i18n:change", user.default_language)
|
@rootscope.$broadcast("i18n:change", user.default_language)
|
||||||
@storage.set("userInfo", user.getAttrs())
|
@storage.set("userInfo", user.getAttrs())
|
||||||
|
|
||||||
clear: ->
|
clear: ->
|
||||||
@rootScope.auth = null
|
@rootscope.auth = null
|
||||||
@storage.remove("userInfo")
|
@storage.remove("userInfo")
|
||||||
|
|
||||||
setToken: (token) ->
|
setToken: (token) ->
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||||
|
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||||
|
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: modules/base/navurl.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
taiga = @.taiga
|
||||||
|
trim = @.taiga.trim
|
||||||
|
|
||||||
|
parseNav = (data, scope) ->
|
||||||
|
options = {}
|
||||||
|
|
||||||
|
[name, params] = _.map(data.split(":"), trim)
|
||||||
|
params = _.map(params.split(","), trim)
|
||||||
|
|
||||||
|
for item in params
|
||||||
|
[key, value] = _.map(item.split("="), trim)
|
||||||
|
options[key] = scope.$eval(value)
|
||||||
|
|
||||||
|
return [name, options]
|
||||||
|
|
||||||
|
formatUrl = (url, ctx={}) ->
|
||||||
|
replacer = (match) ->
|
||||||
|
match = trim(match, ":")
|
||||||
|
return ctx[match] or "undefined"
|
||||||
|
return url.replace(/(:\w+)/g, replacer)
|
||||||
|
|
||||||
|
|
||||||
|
class NavigationUrlsService extends taiga.Service
|
||||||
|
constructor: ->
|
||||||
|
@.urls = {}
|
||||||
|
|
||||||
|
update: (urls) ->
|
||||||
|
@.urls = _.merge({}, @.urls, urls or {})
|
||||||
|
|
||||||
|
resolve: (name) ->
|
||||||
|
return @.urls[name]
|
||||||
|
|
||||||
|
|
||||||
|
NavigationUrlsDirective = ($navurls, $auth) ->
|
||||||
|
# Example:
|
||||||
|
# link(tg-nav="project-backlog:project='sss',")
|
||||||
|
|
||||||
|
link = ($scope, $el, $attrs) ->
|
||||||
|
[name, options] = parseNav($attrs.tgNav, $scope)
|
||||||
|
|
||||||
|
user = $auth.getUser()
|
||||||
|
options.user = user.username if user
|
||||||
|
|
||||||
|
url = $navurls.resolve(name)
|
||||||
|
fullUrl = formatUrl(url, options)
|
||||||
|
|
||||||
|
$el.attr("href", fullUrl)
|
||||||
|
|
||||||
|
return {link: link}
|
||||||
|
|
||||||
|
|
||||||
|
module = angular.module("taigaBase")
|
||||||
|
module.service("$tgNavUrls", NavigationUrlsService)
|
||||||
|
module.directive("tgNav", ["$tgNavUrls", "$tgAuth", NavigationUrlsDirective])
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||||
|
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||||
|
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: modules/navigation.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
# Simple module that uses navurls service and register
|
||||||
|
# navigation urls for taiga.
|
||||||
|
|
||||||
|
urls = {
|
||||||
|
"home": "/",
|
||||||
|
"profile": "/:user",
|
||||||
|
"project": "/:user/:project",
|
||||||
|
"project-backlog": "/:user/:project/backlog",
|
||||||
|
"project-taskboard": "/:user/:project/taskboard/:sprint",
|
||||||
|
}
|
||||||
|
|
||||||
|
init = ($log, $navurls) ->
|
||||||
|
$log.debug "Initialize navigation urls"
|
||||||
|
$navurls.update(urls)
|
||||||
|
|
||||||
|
module = angular.module("taigaNavigation", ["taigaBase"])
|
||||||
|
module.run(["$log", "$tgNavUrls", init])
|
|
@ -21,10 +21,14 @@
|
||||||
|
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ResourcesService extends taiga.Service
|
class ResourcesService extends taiga.Service
|
||||||
|
|
||||||
initUrls = (urls) ->
|
|
||||||
urls.update({
|
urls = {
|
||||||
"auth": "/api/v1/auth"
|
"auth": "/api/v1/auth"
|
||||||
"auth-register": "/api/v1/auth/register"
|
"auth-register": "/api/v1/auth/register"
|
||||||
"permissions": "/api/v1/permissions"
|
"permissions": "/api/v1/permissions"
|
||||||
|
@ -80,7 +84,12 @@ initUrls = (urls) ->
|
||||||
"issues/attachments": "/api/v1/issues/attachments"
|
"issues/attachments": "/api/v1/issues/attachments"
|
||||||
"tasks/attachments": "/api/v1/tasks/attachments"
|
"tasks/attachments": "/api/v1/tasks/attachments"
|
||||||
"wiki/attachments": "/api/v1/wiki/attachments"
|
"wiki/attachments": "/api/v1/wiki/attachments"
|
||||||
})
|
}
|
||||||
|
|
||||||
|
# Initialize api urls service
|
||||||
|
initUrls = ($log, $urls) ->
|
||||||
|
$log.debug "Initialize api urls"
|
||||||
|
$urls.update(urls)
|
||||||
|
|
||||||
# Initialize resources service populating it with methods
|
# Initialize resources service populating it with methods
|
||||||
# defined in separated files.
|
# defined in separated files.
|
||||||
|
@ -95,7 +104,7 @@ module = angular.module("taigaResources", ["taigaBase"])
|
||||||
module.service("$tgResources", ResourcesService)
|
module.service("$tgResources", ResourcesService)
|
||||||
|
|
||||||
# Module entry point
|
# Module entry point
|
||||||
module.run(["$tgUrls", initUrls])
|
module.run(["$log", "$tgUrls", initUrls])
|
||||||
module.run([
|
module.run([
|
||||||
"$log",
|
"$log",
|
||||||
"$tgResources",
|
"$tgResources",
|
||||||
|
|
|
@ -40,6 +40,11 @@ mixOf = (base, mixins...) ->
|
||||||
Mixed
|
Mixed
|
||||||
|
|
||||||
|
|
||||||
|
trim = (data, char) ->
|
||||||
|
return _.str.trim(data, char)
|
||||||
|
|
||||||
|
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
taiga.bindOnce = bindOnce
|
taiga.bindOnce = bindOnce
|
||||||
taiga.mixOf = mixOf
|
taiga.mixOf = mixOf
|
||||||
|
taiga.trim = trim
|
||||||
|
|
|
@ -32,7 +32,8 @@ section.sprints
|
||||||
span(tg-bo-ref="us.ref")
|
span(tg-bo-ref="us.ref")
|
||||||
span(tg-bo-html="us.subject")
|
span(tg-bo-html="us.subject")
|
||||||
div.column-points.width-1(tg-bo-html="us.total_points")
|
div.column-points.width-1(tg-bo-html="us.total_points")
|
||||||
a.button.button-gray(href="", title="Current Sprint Taskboard")
|
a.button.button-gray(href="", tg-nav="project-taskboard:project=projectId,sprint=sprint.id",
|
||||||
|
title="Current Sprint Taskboard")
|
||||||
span Sprint Taskboard
|
span Sprint Taskboard
|
||||||
|
|
||||||
// If is current sprint
|
// If is current sprint
|
||||||
|
|
Loading…
Reference in New Issue