diff --git a/app/coffee/modules/controllerMixins.coffee b/app/coffee/modules/controllerMixins.coffee index 6769d222..2af688a5 100644 --- a/app/coffee/modules/controllerMixins.coffee +++ b/app/coffee/modules/controllerMixins.coffee @@ -41,5 +41,42 @@ class PageMixin .value() return results + +# This mixin requires @location and @scope + +class FiltersMixin + selectFilter: (name, value, load=false) -> + params = @location.search() + if params[name] != undefined and name != "page" + existing = _.map(params[name].split(","), trim) + existing.push(value) + + value = joinStr(",", _.uniq(existing)) + + location = if load then @location else @location.noreload(@scope) + location.search(name, value) + + unselectFilter: (name, value, load=false) -> + params = @location.search() + + if params[name] is undefined + return + + if value is undefined or value is null + delete params[name] + + parsedValues = _.map(params[name].split(","), trim) + newValues = _.reject(parsedValues, (x) -> x == toString(value)) + + if _.isEmpty(newValues) + value = null + else + value = joinStr(",", _.uniq(newValues)) + + location = if load then @location else @location.noreload(@scope) + location.search(name, value) + + taiga = @.taiga taiga.PageMixin = PageMixin +taiga.FiltersMixin = FiltersMixin diff --git a/app/coffee/modules/issues/list.coffee b/app/coffee/modules/issues/list.coffee index a315cfa7..56b106f6 100644 --- a/app/coffee/modules/issues/list.coffee +++ b/app/coffee/modules/issues/list.coffee @@ -34,7 +34,7 @@ module = angular.module("taigaIssues") ## Issues Controller ############################################################################# -class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin) +class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.FiltersMixin) @.$inject = [ "$scope", "$rootScope", @@ -62,49 +62,12 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin) loadProject: -> return @rs.projects.get(@scope.projectId).then (project) => @scope.project = project - # @scope.points = _.sortBy(project.points, "order") - # @scope.issueStatusList = _.sortBy(project.issue_statuses, "order") - # @scope.severityList = _.sortBy(project.severities, "order") - # @scope.priorityList = _.sortBy(project.priorities, "order") - @scope.issueStatusById = groupBy(project.issue_statuses, (x) -> x.id) @scope.severityById = groupBy(project.severities, (x) -> x.id) @scope.priorityById = groupBy(project.priorities, (x) -> x.id) @scope.membersById = groupBy(project.memberships, (x) -> x.id) - console.log @scope.membersById return project - selectFilter: (name, value, load=false) -> - params = @location.search() - if params[name] != undefined - existing = _.map(params[name].split(","), trim) - existing.push(value) - - value = joinStr(",", _.uniq(existing)) - - location = if load then @location else @location.noreload() - location.search(name, value) - - unselectFilter: (name, value, load=false) -> - params = @location.search() - - if params[name] is undefined - return - - if value is undefined - delete params[name] - - parsedValues = _.map(params[name].split(","), trim) - newValues = _.reject(parsedValues, (x) -> x == toString(value)) - - if _.isEmpty(newValues) - value = null - else - value = joinStr(",", _.uniq(newValues)) - - location = if load then @location else @location.noreload() - location.search(name, value) - getFilters: -> filters = _.pick(@location.search(), "page", "tags", "status", "type") filters.page = 1 if not filters.page @@ -235,29 +198,35 @@ IssuesDirective = ($log, $location) -> event.preventDefault() $scope.$apply -> - $scope.page += 1 - $location.noreload($scope).search("page", $scope.page) + $ctrl.selectFilter("page", $scope.page + 1) $ctrl.loadIssues() $el.on "click", ".issues-paginator a.previous", (event) -> event.preventDefault() $scope.$apply -> - $scope.page -= 1 - $location.noreload($scope).search("page", $scope.page) + $ctrl.selectFilter("page", $scope.page - 1) $ctrl.loadIssues() + + ######################### + ## Issues Filters + ######################### + + linkFilters = ($scope, $el, $attrs, $ctrl) -> + $log.debug "IssuesDirective:linkFilters" + ######################### ## Issues Link ######################### link = ($scope, $el, $attrs) -> $ctrl = $el.controller() + linkFilters($scope, $el, $attrs, $ctrl) linkPagination($scope, $el, $attrs, $ctrl) return {link:link} - IssueStatusDirective = -> link = ($scope, $el, $attrs) -> issue = $scope.$eval($attrs.tgIssueStatus) diff --git a/app/partials/issues.jade b/app/partials/issues.jade index 0285460b..d331c85b 100644 --- a/app/partials/issues.jade +++ b/app/partials/issues.jade @@ -6,7 +6,9 @@ block head block content div.wrapper(tg-issues, ng-controller="IssuesController as ctrl", ng-init="section='issues'") - sidebar.menu-secondary.sidebar + sidebar.menu-secondary.sidebar.filters-container + // TODO: maybe everything related to this section + // should be done in one unique include? header h1 Filters include views/modules/search-in