Implement navigation url service.

stable
Andrey Antukh 2014-06-18 19:02:17 +02:00
parent 2aa95c6e3d
commit 171aaa1f6b
8 changed files with 203 additions and 63 deletions

View File

@ -57,6 +57,9 @@ modules = [
"taigaBase", "taigaBase",
"taigaResources", "taigaResources",
"taigaLocales", "taigaLocales",
"taigaAuth",
"taigaNavigation",
# Specific Modules # Specific Modules
"taigaBacklog", "taigaBacklog",

View File

@ -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) ->

View File

@ -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])

View File

@ -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])

View File

@ -21,66 +21,75 @@
taiga = @.taiga taiga = @.taiga
class ResourcesService extends taiga.Service class ResourcesService extends taiga.Service
initUrls = (urls) ->
urls.update({
"auth": "/api/v1/auth"
"auth-register": "/api/v1/auth/register"
"permissions": "/api/v1/permissions"
"roles": "/api/v1/roles"
"projects": "/api/v1/projects"
"memberships": "/api/v1/memberships"
"milestones": "/api/v1/milestones"
"userstories": "/api/v1/userstories"
"bulk-create-us": "/api/v1/userstories/bulk_create"
"bulk-update-us-order": "/api/v1/userstories/bulk_update_order"
"userstories-restore": "/api/v1/userstories/%s/restore"
"tasks": "/api/v1/tasks"
"bulk-create-tasks": "/api/v1/tasks/bulk_create"
"tasks-restore": "/api/v1/tasks/%s/restore"
"issues": "/api/v1/issues"
"issues-restore": "/api/v1/issues/%s/restore"
"wiki": "/api/v1/wiki"
"wiki-restore": "/api/v1/wiki/%s/restore"
"choices/userstory-statuses": "/api/v1/userstory-statuses"
"choices/userstory-statuses/bulk-update-order": "/api/v1/userstory-statuses/bulk_update_order"
"choices/points": "/api/v1/points"
"choices/points/bulk-update-order": "/api/v1/points/bulk_update_order"
"choices/task-statuses": "/api/v1/task-statuses"
"choices/task-statuses/bulk-update-order": "/api/v1/task-statuses/bulk_update_order"
"choices/issue-statuses": "/api/v1/issue-statuses"
"choices/issue-statuses/bulk-update-order": "/api/v1/issue-statuses/bulk_update_order"
"choices/issue-types": "/api/v1/issue-types"
"choices/issue-types/bulk-update-order": "/api/v1/issue-types/bulk_update_order"
"choices/priorities": "/api/v1/priorities"
"choices/priorities/bulk-update-order": "/api/v1/priorities/bulk_update_order"
"choices/severities": "/api/v1/severities"
"choices/severities/bulk-update-order": "/api/v1/severities/bulk_update_order"
"search": "/api/v1/search"
"sites": "/api/v1/sites"
"project-templates": "/api/v1/project-templates"
"site-members": "/api/v1/site-members"
"site-projects": "/api/v1/site-projects"
"users": "/api/v1/users"
"users-password-recovery": "/api/v1/users/password_recovery"
"users-change-password-from-recovery": "/api/v1/users/change_password_from_recovery"
"users-change-password": "/api/v1/users/change_password"
"resolver": "/api/v1/resolver"
"wiki-attachment": "/media/attachment-files/%s/wikipage/%s"
# History urls = {
"history/userstory": "/api/v1/history/userstory" "auth": "/api/v1/auth"
"history/issue": "/api/v1/history/issue" "auth-register": "/api/v1/auth/register"
"history/task": "/api/v1/history/task" "permissions": "/api/v1/permissions"
"history/wiki": "/api/v1/history/wiki" "roles": "/api/v1/roles"
"projects": "/api/v1/projects"
"memberships": "/api/v1/memberships"
"milestones": "/api/v1/milestones"
"userstories": "/api/v1/userstories"
"bulk-create-us": "/api/v1/userstories/bulk_create"
"bulk-update-us-order": "/api/v1/userstories/bulk_update_order"
"userstories-restore": "/api/v1/userstories/%s/restore"
"tasks": "/api/v1/tasks"
"bulk-create-tasks": "/api/v1/tasks/bulk_create"
"tasks-restore": "/api/v1/tasks/%s/restore"
"issues": "/api/v1/issues"
"issues-restore": "/api/v1/issues/%s/restore"
"wiki": "/api/v1/wiki"
"wiki-restore": "/api/v1/wiki/%s/restore"
"choices/userstory-statuses": "/api/v1/userstory-statuses"
"choices/userstory-statuses/bulk-update-order": "/api/v1/userstory-statuses/bulk_update_order"
"choices/points": "/api/v1/points"
"choices/points/bulk-update-order": "/api/v1/points/bulk_update_order"
"choices/task-statuses": "/api/v1/task-statuses"
"choices/task-statuses/bulk-update-order": "/api/v1/task-statuses/bulk_update_order"
"choices/issue-statuses": "/api/v1/issue-statuses"
"choices/issue-statuses/bulk-update-order": "/api/v1/issue-statuses/bulk_update_order"
"choices/issue-types": "/api/v1/issue-types"
"choices/issue-types/bulk-update-order": "/api/v1/issue-types/bulk_update_order"
"choices/priorities": "/api/v1/priorities"
"choices/priorities/bulk-update-order": "/api/v1/priorities/bulk_update_order"
"choices/severities": "/api/v1/severities"
"choices/severities/bulk-update-order": "/api/v1/severities/bulk_update_order"
"search": "/api/v1/search"
"sites": "/api/v1/sites"
"project-templates": "/api/v1/project-templates"
"site-members": "/api/v1/site-members"
"site-projects": "/api/v1/site-projects"
"users": "/api/v1/users"
"users-password-recovery": "/api/v1/users/password_recovery"
"users-change-password-from-recovery": "/api/v1/users/change_password_from_recovery"
"users-change-password": "/api/v1/users/change_password"
"resolver": "/api/v1/resolver"
"wiki-attachment": "/media/attachment-files/%s/wikipage/%s"
# Attachments # History
"userstories/attachments": "/api/v1/userstories/attachments" "history/userstory": "/api/v1/history/userstory"
"issues/attachments": "/api/v1/issues/attachments" "history/issue": "/api/v1/history/issue"
"tasks/attachments": "/api/v1/tasks/attachments" "history/task": "/api/v1/history/task"
"wiki/attachments": "/api/v1/wiki/attachments" "history/wiki": "/api/v1/history/wiki"
})
# Attachments
"userstories/attachments": "/api/v1/userstories/attachments"
"issues/attachments": "/api/v1/issues/attachments"
"tasks/attachments": "/api/v1/tasks/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",

View File

@ -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

View File

@ -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