Fixed navegation.

stable
Andrey Antukh 2014-06-26 17:16:20 +02:00
parent 6548576ad9
commit 3c8fdfb007
4 changed files with 24 additions and 57 deletions

View File

@ -21,6 +21,7 @@
taiga = @.taiga taiga = @.taiga
groupBy = @.taiga.groupBy groupBy = @.taiga.groupBy
bindOnce = @.taiga.bindOnce
module = angular.module("taigaBase", ["taigaLocales"]) module = angular.module("taigaBase", ["taigaLocales"])
@ -29,17 +30,7 @@ module = angular.module("taigaBase", ["taigaLocales"])
## Global Page Directive ## Global Page Directive
############################################################################# #############################################################################
class MainTaigaController extends taiga.Controller MainTaigaDirective = ($log, $compile, $rootscope) ->
@.$inject = ["$scope"]
constructor: (@scope) ->
@scope.mainSection = "backlog"
setSectionName: (name) ->
@scope.mainSection = name
MainTaigaDirective = ($log, $compile) ->
template = _.template(""" template = _.template("""
<h1 class="logo"><a href="" title="Home"><img src="/images/logo.png" alt="Taiga"/></a></h1> <h1 class="logo"><a href="" title="Home"><img src="/images/logo.png" alt="Taiga"/></a></h1>
<ul class="main-nav"> <ul class="main-nav">
@ -49,7 +40,7 @@ MainTaigaDirective = ($log, $compile) ->
</a> </a>
</li> </li>
<li data-name="backlog" tg-nav="project-backlog:project=project.slug"> <li data-name="backlog" tg-nav="project-backlog:project=project.slug">
<a href="" title="Backlog" class="active"> <a href="" title="Backlog" tg-nav="project-backlog:project=project.slug">
<span class="icon icon-backlog"></span> <span class="icon icon-backlog"></span>
<span class="item">Backlog</span> <span class="item">Backlog</span>
</a> </a>
@ -92,52 +83,29 @@ MainTaigaDirective = ($log, $compile) ->
</a> </a>
</div>""") </div>""")
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)
# WARNING: this code has traces of slighty hacky parts # WARNING: this code has traces of slighty hacky parts
# This rerenders and compiles the navigation when ng-view # This rerenders and compiles the navigation when ng-view
# content loaded signal is raised using inner scope. # content loaded signal is raised using inner scope.
$scope.$on "$viewContentLoaded", -> renderMainMenu = ($el, targetScope) ->
body = angular.element("body") container = $el.find(".master > .wrapper")
wScope = body.find(".wrapper").scope() dom = $compile(template({}))(targetScope)
html = template({})
dom = $compile(html)(wScope)
menuDom = $el.find("nav.menu") menuDom = $el.find("nav.menu")
menuDom.empty() menuDom.empty()
menuDom.append(dom) menuDom.append(dom)
return { sectionName = targetScope.section
controller: MainTaigaController menuDom.find("a.active").removeClass("active")
link: link menuDom.find("[data-name=#{sectionName}] > a").addClass("active")
}
SectionMarkerDirective = ($log) ->
link = ($scope, $el, $attrs, $ctrl) -> link = ($scope, $el, $attrs, $ctrl) ->
$ctrl.setSectionName($attrs.tgSectionMarker) $scope.$on "$viewContentLoaded", (ctx) ->
renderMainMenu($el, ctx.targetScope.$$childHead)
return { return {link:link}
require: "^tgMain"
link: link
}
module.directive("tgMain", ["$log", "$compile", MainTaigaDirective]) module.directive("tgMain", ["$log", "$compile", "$rootScope", MainTaigaDirective])
module.directive("tgSectionMarker", ["$log", SectionMarkerDirective])
############################################################################# #############################################################################

View File

@ -85,7 +85,7 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin)
module.controller("IssuesController", IssuesController) module.controller("IssuesController", IssuesController)
############################################################################# #############################################################################
## Issues Controller ## Issues Directive
############################################################################# #############################################################################
paginatorTemplate = """ paginatorTemplate = """
@ -126,7 +126,6 @@ IssuesDirective = ($log, $location) ->
## Issues Pagination ## Issues Pagination
######################### #########################
# Constants
template = _.template(paginatorTemplate) template = _.template(paginatorTemplate)
linkPagination = ($scope, $el, $attrs, $ctrl) -> linkPagination = ($scope, $el, $attrs, $ctrl) ->
@ -197,13 +196,11 @@ IssuesDirective = ($log, $location) ->
$location.noreload($scope).search("page", $scope.page) $location.noreload($scope).search("page", $scope.page)
$ctrl.loadIssues() $ctrl.loadIssues()
######################### #########################
## Issues Link ## Issues Link
######################### #########################
link = ($scope, $el, $attrs) -> link = ($scope, $el, $attrs) ->
console.log "IssuesDirective:link"
$ctrl = $el.controller() $ctrl = $el.controller()
linkPagination($scope, $el, $attrs, $ctrl) linkPagination($scope, $el, $attrs, $ctrl)

View File

@ -4,7 +4,8 @@ block head
title Taiga Project management web application with scrum in mind! title Taiga Project management web application with scrum in mind!
block content block content
div.wrapper(tg-backlog, ng-controller="BacklogController as ctrl") div.wrapper(tg-backlog, ng-controller="BacklogController as ctrl",
ng-init="section='backlog'")
sidebar.menu-secondary.extrabar.filters-bar sidebar.menu-secondary.extrabar.filters-bar
include views/modules/filters include views/modules/filters
section.main.backlog section.main.backlog

View File

@ -4,7 +4,8 @@ block head
title Taiga Project management web application with scrum in mind! title Taiga Project management web application with scrum in mind!
block content block content
div.wrapper(tg-issues, ng-controller="IssuesController as ctrl") div.wrapper(tg-issues, ng-controller="IssuesController as ctrl",
ng-init="section='issues'")
sidebar.menu-secondary.sidebar sidebar.menu-secondary.sidebar
header header
h1 Filters h1 Filters