fix project navigation active section
parent
9175d453fb
commit
07ed833e02
|
@ -510,8 +510,7 @@ init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $na
|
|||
if !$auth.isAuthenticated()
|
||||
$location.path($navUrls.resolve("login"))
|
||||
|
||||
if next.section
|
||||
projectService.setSection(next.section)
|
||||
projectService.setSection(next.section)
|
||||
|
||||
if next.params.pslug
|
||||
projectService.setProject(next.params.pslug)
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
###
|
||||
# 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/nav.coffee
|
||||
###
|
||||
|
||||
taiga = @.taiga
|
||||
groupBy = @.taiga.groupBy
|
||||
bindOnce = @.taiga.bindOnce
|
||||
timeout = @.taiga.timeout
|
||||
|
||||
module = angular.module("taigaNavMenu", [])
|
||||
|
||||
|
||||
#############################################################################
|
||||
## Project
|
||||
#############################################################################
|
||||
|
||||
ProjectMenuDirective = ($log, $compile, $auth, $rootscope, $tgAuth, $location, $navUrls, $config, $template) ->
|
||||
menuEntriesTemplate = $template.get("project/project-menu.html", true)
|
||||
|
||||
mainTemplate = _.template("""
|
||||
<div class="menu-container"></div>
|
||||
""")
|
||||
|
||||
# If the last page was kanban or backlog and
|
||||
# the new one is the task detail or the us details
|
||||
# this method preserve the last section name.
|
||||
getSectionName = ($el, sectionName, project) ->
|
||||
oldSectionName = $el.find("a.active").parent().attr("id")?.replace("nav-", "")
|
||||
|
||||
if sectionName == "backlog-kanban"
|
||||
if oldSectionName in ["backlog", "kanban"]
|
||||
sectionName = oldSectionName
|
||||
else if project.is_backlog_activated && !project.is_kanban_activated
|
||||
sectionName = "backlog"
|
||||
else if !project.is_backlog_activated && project.is_kanban_activated
|
||||
sectionName = "kanban"
|
||||
|
||||
return sectionName
|
||||
|
||||
renderMainMenu = ($el) ->
|
||||
html = mainTemplate({})
|
||||
$el.html(html)
|
||||
|
||||
# WARNING: this code has traces of slighty hacky parts
|
||||
# This rerenders and compiles the navigation when ng-view
|
||||
# content loaded signal is raised using inner scope.
|
||||
renderMenuEntries = ($el, targetScope, project={}) ->
|
||||
container = $el.find(".menu-container")
|
||||
sectionName = getSectionName($el, targetScope.section, project)
|
||||
|
||||
ctx = {
|
||||
user: $auth.getUser(),
|
||||
project: project,
|
||||
feedbackEnabled: $config.get("feedbackEnabled")
|
||||
}
|
||||
dom = $compile(menuEntriesTemplate(ctx))(targetScope)
|
||||
|
||||
dom.find("a.active").removeClass("active")
|
||||
dom.find("#nav-#{sectionName} > a").addClass("active")
|
||||
|
||||
container.replaceWith(dom)
|
||||
|
||||
videoConferenceUrl = (project) ->
|
||||
urlFixer = (url) -> return url
|
||||
|
||||
if project.videoconferences == "appear-in"
|
||||
baseUrl = "https://appear.in/"
|
||||
else if project.videoconferences == "talky"
|
||||
baseUrl = "https://talky.io/"
|
||||
else if project.videoconferences == "jitsi"
|
||||
baseUrl = "https://meet.jit.si/"
|
||||
urlFixer = (url) -> return url.replace(/ /g, "").replace(/-/g, "")
|
||||
else
|
||||
return ""
|
||||
|
||||
if project.videoconferences_salt
|
||||
url = "#{project.slug}-#{project.videoconferences_salt}"
|
||||
else
|
||||
url = "#{project.slug}"
|
||||
|
||||
url = urlFixer(url)
|
||||
|
||||
return baseUrl + url
|
||||
|
||||
|
||||
link = ($scope, $el, $attrs, $ctrl) ->
|
||||
renderMainMenu($el)
|
||||
project = null
|
||||
|
||||
# $el.on "click", ".logo", (event) ->
|
||||
# event.preventDefault()
|
||||
# target = angular.element(event.currentTarget)
|
||||
# $rootscope.$broadcast("nav:projects-list:open")
|
||||
|
||||
$el.on "click", ".user-settings .avatar", (event) ->
|
||||
event.preventDefault()
|
||||
$el.find(".user-settings .popover").popover().open()
|
||||
|
||||
$el.on "click", ".logout", (event) ->
|
||||
event.preventDefault()
|
||||
$auth.logout()
|
||||
$scope.$apply ->
|
||||
$location.path($navUrls.resolve("login"))
|
||||
|
||||
$el.on "click", "#nav-search > a", (event) ->
|
||||
event.preventDefault()
|
||||
$rootscope.$broadcast("search-box:show", project)
|
||||
|
||||
$el.on "click", ".feedback", (event) ->
|
||||
event.preventDefault()
|
||||
$rootscope.$broadcast("feedback:show")
|
||||
|
||||
$scope.$on "projects:loaded", (listener) ->
|
||||
$el.addClass("hidden")
|
||||
listener.stopPropagation()
|
||||
|
||||
$scope.$on "project:loaded", (ctx, newProject) ->
|
||||
project = newProject
|
||||
if $el.hasClass("hidden")
|
||||
$el.removeClass("hidden")
|
||||
|
||||
project.videoconferenceUrl = videoConferenceUrl(project)
|
||||
renderMenuEntries($el, ctx.targetScope, project)
|
||||
|
||||
return {link: link}
|
||||
|
||||
module.directive("tgProjectMenu", ["$log", "$compile", "$tgAuth", "$rootScope", "$tgAuth", "$tgLocation",
|
||||
"$tgNavUrls", "$tgConfig", "$tgTemplate", ProjectMenuDirective])
|
|
@ -59,7 +59,7 @@ class ProjectMenuController
|
|||
indexKanban = sectionsBreadcrumb.lastIndexOf("kanban")
|
||||
|
||||
if indexBacklog != -1 || indexKanban != -1
|
||||
if indexBacklog > indexKanban
|
||||
if indexKanban == -1 || indexBacklog < indexKanban
|
||||
oldSectionName = "backlog"
|
||||
else
|
||||
oldSectionName = "kanban"
|
||||
|
|
|
@ -212,7 +212,7 @@ describe "ProjectMenu", ->
|
|||
|
||||
mocks.projectService.project = project
|
||||
mocks.projectService.section = "backlog-kanban"
|
||||
mocks.projectService.sectionsBreadcrumb = Immutable.List.of("kanban", "backlog", "oo")
|
||||
mocks.projectService.sectionsBreadcrumb = Immutable.List.of("oo", "backlog", "kanban")
|
||||
|
||||
ctrl = $controller("ProjectMenu")
|
||||
|
||||
|
@ -225,7 +225,21 @@ describe "ProjectMenu", ->
|
|||
|
||||
mocks.projectService.project = project
|
||||
mocks.projectService.section = "backlog-kanban"
|
||||
mocks.projectService.sectionsBreadcrumb = Immutable.List.of("backlog", "kanban", "oo")
|
||||
mocks.projectService.sectionsBreadcrumb = Immutable.List.of("kanban", "oo", "backlog")
|
||||
|
||||
ctrl = $controller("ProjectMenu")
|
||||
|
||||
ctrl.show()
|
||||
|
||||
expect(ctrl.active).to.be.equal("backlog")
|
||||
|
||||
|
||||
it "backlog-kanban when kanban is not in the breadcrumb", () ->
|
||||
project = Immutable.fromJS({})
|
||||
|
||||
mocks.projectService.project = project
|
||||
mocks.projectService.section = "backlog-kanban"
|
||||
mocks.projectService.sectionsBreadcrumb = Immutable.List.of("oo", "backlog")
|
||||
|
||||
ctrl = $controller("ProjectMenu")
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ describe "WorkingOn", ->
|
|||
ctrl = $controller("WorkingOn")
|
||||
|
||||
ctrl.getWorkInProgress(userId).then () ->
|
||||
console.log ctrl.assignedTo.toJS()
|
||||
expect(ctrl.assignedTo.toJS()).to.be.eql([
|
||||
{id: 6, modified_date: '2015-01-06'},
|
||||
{id: 4, modified_date: '2015-01-05'},
|
||||
|
|
|
@ -16,11 +16,16 @@ class ProjectService
|
|||
|
||||
setSection: (section) ->
|
||||
@._section = section
|
||||
@._sectionsBreadcrumb = @._sectionsBreadcrumb.unshift(@._section)
|
||||
|
||||
if section
|
||||
@._sectionsBreadcrumb = @._sectionsBreadcrumb.push(@._section)
|
||||
else
|
||||
@._sectionsBreadcrumb = Immutable.List()
|
||||
|
||||
setProject: (pslug) ->
|
||||
if @._pslug != pslug
|
||||
@._pslug = pslug
|
||||
|
||||
@.fetchProject()
|
||||
|
||||
fetchProject: () ->
|
||||
|
|
|
@ -41,7 +41,7 @@ describe "tgProjectService", ->
|
|||
expect(projectService.sectionsBreadcrumb.toJS()).to.be.eql(breadcrumb)
|
||||
|
||||
section = "fakeSection222"
|
||||
breadcrumb = ["fakeSection222","fakeSection"]
|
||||
breadcrumb = ["fakeSection", "fakeSection222"]
|
||||
projectService.setSection(section)
|
||||
|
||||
expect(projectService.sectionsBreadcrumb.toJS()).to.be.eql(breadcrumb)
|
||||
|
|
Loading…
Reference in New Issue