From d59dcfed38eee2b5b2ff804fac70113b397cdb1e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2014 12:12:28 +0200 Subject: [PATCH] Add navegation directive and main controller. --- app/coffee/app.coffee | 5 +- app/coffee/modules/base.coffee | 72 ++++++++++++++++++++++++++++ app/coffee/modules/navigation.coffee | 38 --------------- app/index.jade | 2 +- app/partials/taskboard.jade | 3 +- app/partials/views/modules/nav.jade | 12 ++--- 6 files changed, 83 insertions(+), 49 deletions(-) delete mode 100644 app/coffee/modules/navigation.coffee diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index e902e26b..493d5c1d 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -63,13 +63,12 @@ angular.module("taigaCommon", []) modules = [ # Main Global Modules - "taigaConfig", "taigaBase", + "taigaCommon", + "taigaConfig", "taigaResources", "taigaLocales", "taigaAuth", - "taigaCommon", - "taigaNavigation", # Specific Modules "taigaBacklog", diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index 9c91a272..172daca7 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -19,4 +19,76 @@ # File: modules/base.coffee ### +taiga = @.taiga +groupBy = @.taiga.groupBy + module = angular.module("taigaBase", ["taigaLocales"]) + + +############################################################################# +## Global Page Directive +############################################################################# + +class MainTaigaController extends taiga.Controller + @.$inject = ["$scope"] + + constructor: (@scope) -> + @scope.mainSection = "backlog" + + setSectionName: (name) -> + @scope.mainSection = name + + +MainTaigaDirective = ($log) -> + linkMainNav = ($scope, $el, $attrs, $ctrl) -> + menuEntriesSelector = $el.find("ul.main-nav > li") + menuEntries = _.map(menuEntriesSelector, (x) -> angular.element(x)) + menuEntriesByName = groupBy(menuEntries, (x) -> x.data("name")) + + $scope.$watch "mainSection", (sectionName) -> + $el.find("ul.main-nav a.active").removeClass("active") + + entry = menuEntriesByName[sectionName] + entry.find("> a").addClass("active") + + link = ($scope, $el, $attrs, $ctrl) -> + $log.debug "Taiga main directive initialized." + linkMainNav($scope, $el, $attrs, $ctrl) + + return { + controller: MainTaigaController + link: link + } + + +SectionMarkerDirective = ($log) -> + link = ($scope, $el, $attrs, $ctrl) -> + $ctrl.setSectionName($attrs.tgSectionMarker) + + return { + require: "^tgMain" + link: link + } + + +module.directive("tgMain", ["$log", MainTaigaDirective]) +module.directive("tgSectionMarker", ["$log", SectionMarkerDirective]) + + +############################################################################# +## Navigation +############################################################################# + +urls = { + "home": "/", + "profile": "/:user", + "project": "/project/:project", + "project-backlog": "/project/:project/backlog", + "project-taskboard": "/project/:project/taskboard/:sprint", +} + +init = ($log, $navurls) -> + $log.debug "Initialize navigation urls" + $navurls.update(urls) + +module.run(["$log", "$tgNavUrls", init]) diff --git a/app/coffee/modules/navigation.coffee b/app/coffee/modules/navigation.coffee deleted file mode 100644 index ba3f7d12..00000000 --- a/app/coffee/modules/navigation.coffee +++ /dev/null @@ -1,38 +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/navigation.coffee -### - -# Simple module that uses navurls service and register -# navigation urls for taiga. - -urls = { - "home": "/", - "profile": "/:user", - "project": "/project/:project", - "project-backlog": "/project/:project/backlog", - "project-taskboard": "/project/:project/taskboard/:sprint", -} - -init = ($log, $navurls) -> - $log.debug "Initialize navigation urls" - $navurls.update(urls) - -module = angular.module("taigaNavigation", ["taigaBase"]) -module.run(["$log", "$tgNavUrls", init]) diff --git a/app/index.jade b/app/index.jade index bd28f730..f95e6dda 100644 --- a/app/index.jade +++ b/app/index.jade @@ -8,7 +8,7 @@ html(lang="en", ng-app="taiga") meta(name="keywords", content="Agile, Taiga, Management, Github") meta(name="viewport", content="width=device-width, user-scalable=no") link(rel="stylesheet", href="/styles/main.css") - body + body(tg-main) include partials/views/modules/nav div.master(ng-view="") div.hidden.lightbox.lightbox_confirm-delete diff --git a/app/partials/taskboard.jade b/app/partials/taskboard.jade index 568f302e..7cadcd39 100644 --- a/app/partials/taskboard.jade +++ b/app/partials/taskboard.jade @@ -4,7 +4,8 @@ block head title Taiga Project management web application with scrum in mind! block content - div.wrapper(tg-taskboard, ng-controller="TaskboardController as ctrl") + div.wrapper(tg-taskboard, ng-controller="TaskboardController as ctrl", + tg-section-marker="backlog") section.main.taskboard h1 span(tg-bo-html="project.name") diff --git a/app/partials/views/modules/nav.jade b/app/partials/views/modules/nav.jade index bffc7f62..7b2ad1c5 100644 --- a/app/partials/views/modules/nav.jade +++ b/app/partials/views/modules/nav.jade @@ -3,27 +3,27 @@ nav.menu a(href="", title="Home") img(src="/images/logo.png", alt="Taiga") ul.main-nav - li + li(data-name="search") a(href="", title="Search") span.icon.icon-search span.item Search - li + li(data-name="backlog") a.active(href="", title="Backlog") span.icon.icon-backlog span.item Backlog - li + li(data-name="kanban") a(href="", title="Kanban") span.icon.icon-kanban span.item Kanban - li + li(data-name="issues") a(href="", title="Issues") span.icon.icon-issues span.item Issues - li + li(data-name="wiki") a(href="", title="Wiki") span.icon.icon-wiki span.item Wiki - li + li(data-name"video") a(href="", title="Video") span.icon.icon-video span.item Video