diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 28e9f57b..4107d7be 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -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) diff --git a/app/coffee/modules/nav.coffee b/app/coffee/modules/nav.coffee deleted file mode 100644 index a9ebffc3..00000000 --- a/app/coffee/modules/nav.coffee +++ /dev/null @@ -1,145 +0,0 @@ -### -# Copyright (C) 2014 Andrey Antukh -# Copyright (C) 2014 Jesús Espino Garcia -# Copyright (C) 2014 David Barragán Merino -# -# 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 . -# -# 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(""" - - """) - - # 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]) diff --git a/app/modules/components/project-menu/project-menu.controller.coffee b/app/modules/components/project-menu/project-menu.controller.coffee index 441b0a7c..f64167c3 100644 --- a/app/modules/components/project-menu/project-menu.controller.coffee +++ b/app/modules/components/project-menu/project-menu.controller.coffee @@ -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" diff --git a/app/modules/components/project-menu/project-menu.controller.spec.coffee b/app/modules/components/project-menu/project-menu.controller.spec.coffee index 11c81c89..89f1f650 100644 --- a/app/modules/components/project-menu/project-menu.controller.spec.coffee +++ b/app/modules/components/project-menu/project-menu.controller.spec.coffee @@ -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") diff --git a/app/modules/home/working-on/working-on.controller.spec.coffee b/app/modules/home/working-on/working-on.controller.spec.coffee index e2dcc9ea..7d19a00e 100644 --- a/app/modules/home/working-on/working-on.controller.spec.coffee +++ b/app/modules/home/working-on/working-on.controller.spec.coffee @@ -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'}, diff --git a/app/modules/services/project.service.coffee b/app/modules/services/project.service.coffee index e1edf0f8..fcb67493 100644 --- a/app/modules/services/project.service.coffee +++ b/app/modules/services/project.service.coffee @@ -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: () -> diff --git a/app/modules/services/project.service.spec.coffee b/app/modules/services/project.service.spec.coffee index 4b42cc4a..25016848 100644 --- a/app/modules/services/project.service.spec.coffee +++ b/app/modules/services/project.service.spec.coffee @@ -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)