From 8aba67d8207a325357cb76746c6c3252efd46cc3 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 25 Jun 2014 23:08:46 +0200 Subject: [PATCH] Intial controller and directive for issues page including pagination implementation. --- app/coffee/app.coffee | 1 + app/coffee/modules/issues.coffee | 22 ++ app/coffee/modules/issues/list.coffee | 213 +++++++++++++++++++ app/partials/views/modules/issues-table.jade | 28 +-- gulpfile.coffee | 1 + 5 files changed, 251 insertions(+), 14 deletions(-) create mode 100644 app/coffee/modules/issues.coffee create mode 100644 app/coffee/modules/issues/list.coffee diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index faf90fc5..211a615f 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -76,6 +76,7 @@ modules = [ # Specific Modules "taigaBacklog", "taigaTaskboard", + "taigaIssues", # Vendor modules "ngRoute", diff --git a/app/coffee/modules/issues.coffee b/app/coffee/modules/issues.coffee new file mode 100644 index 00000000..c95f3992 --- /dev/null +++ b/app/coffee/modules/issues.coffee @@ -0,0 +1,22 @@ +### +# 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/issues.coffee +### + +module = angular.module("taigaIssues", []) diff --git a/app/coffee/modules/issues/list.coffee b/app/coffee/modules/issues/list.coffee new file mode 100644 index 00000000..3a22b2ed --- /dev/null +++ b/app/coffee/modules/issues/list.coffee @@ -0,0 +1,213 @@ +### +# 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/issues.coffee +### + +taiga = @.taiga +mixOf = @.taiga.mixOf + +module = angular.module("taigaIssues") + +############################################################################# +## Issues Controller +############################################################################# + +class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin) + @.$inject = [ + "$scope", + "$rootScope", + "$tgRepo", + "$tgConfirm", + "$tgResources", + "$routeParams", + "$q" + ] + + constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q) -> + @scope.sprintId = @params.id + @scope.page = @params.page or 1 + + promise = @.loadInitialData() + promise.then null, -> + console.log "FAIL" #TODO + + loadFilters: -> + defered = @q.defer() + defered.resolve() + return defered.promise + + loadProject: -> + return @rs.projects.get(@scope.projectId).then (project) => + @scope.project = project + @scope.points = _.sortBy(project.points, "order") + @scope.taskStatusList = _.sortBy(project.task_statuses, "order") + @scope.usStatusList = _.sortBy(project.us_statuses, "order") + return project + + loadIssues: -> + filters = {page: @scope.page} + promise = @rs.issues.list(@scope.projectId, filters).then (data) => + console.log "loadIssues:", data + @scope.issues = data.models + @scope.page = data.current + @scope.count = data.count + @scope.paginatedBy = data.paginatedBy + return data + + return promise + + loadInitialData: -> + promise = @repo.resolve({pslug: @params.pslug}).then (data) => + @scope.projectId = data.project + return data + + return promise.then(=> @.loadProject()) + .then(=> @.loadUsersAndRoles()) + .then(=> @.loadFilters()) + .then(=> @.loadIssues()) + +module.controller("IssuesController", IssuesController) + +############################################################################# +## Issues Controller +############################################################################# + +paginatorTemplate = """ +
    + <% if (showPrevious) { %> + + <% } %> + + <% _.each(pages, function(item) { %> +
  • + <% if (item.type === "page") { %> + <%= item.num %> + <% } else if (item.type === "page-active") { %> + <%= item.num %> + <% } else { %> + ... + <% } %> +
  • + <% }); %> + + <% if (showNext) { %> + + <% } %> +
+""" + +IssuesDirective = ($log, $location) -> + + ######################### + ## Issues Pagination + ######################### + + # Constants + template = _.template(paginatorTemplate) + + linkPagination = ($scope, $el, $attrs, $ctrl) -> + # Constants + afterCurrent = 5 + beforeCurrent = 5 + atBegin = 2 + atEnd = 2 + + $pagEl = $el.find("section.issues-paginator") + + getNumPages = -> + numPages = $scope.count / $scope.paginatedBy + if parseInt(numPages, 10) < numPages + numPages = parseInt(numPages, 10) + 1 + else + numPages = parseInt(numPages, 10) + + return numPages + + renderPagination = -> + numPages = getNumPages() + + if numPages <= 1 + $pagEl.hide() + return + + pages = [] + options = {} + options.pages = pages + options.showPrevious = ($scope.page > 1) + options.showNext = not ($scope.page == numPages) + + cpage = $scope.page + + for i in [1..numPages] + if i == (cpage + afterCurrent) and numPages > (cpage + afterCurrent + atEnd) + pages.push({classes: "dots", type: "dots"}) + else if i == (cpage - beforeCurrent) and cpage > (atBegin + beforeCurrent) + pages.push({classes: "dots", type: "dots"}) + else if i > (cpage + afterCurrent) and i <= (numPages - atEnd) + else if i < (cpage - beforeCurrent) and i > atBegin + else if i == cpage + pages.push({classes: "active", num: i, type: "page-active"}) + else + pages.push({classes: "page", num: i, type: "page"}) + + $pagEl.html(template(options)) + + $scope.$watch "issues", (value) -> + # Do nothing if value is not logical true + return if not value + + renderPagination() + + $el.on "click", ".issues-paginator a.next", (event) -> + event.preventDefault() + + $scope.$apply -> + $scope.page += 1 + $location.noreload($scope).search("page", $scope.page) + $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.loadIssues() + + + ######################### + ## Issues Link + ######################### + + link = ($scope, $el, $attrs) -> + console.log "IssuesDirective:link" + $ctrl = $el.controller() + linkPagination($scope, $el, $attrs, $ctrl) + + return {link:link} + + +module.directive("tgIssues", ["$log", "$tgLocation", IssuesDirective]) diff --git a/app/partials/views/modules/issues-table.jade b/app/partials/views/modules/issues-table.jade index 1c5da4d4..f7369f58 100644 --- a/app/partials/views/modules/issues-table.jade +++ b/app/partials/views/modules/issues-table.jade @@ -5,17 +5,17 @@ section.issues-table.basic-table div.width-7.subject Subject div.width-2 Status div.width-2 Assigned to - - for (var x = 0; x < 50; x++) - div.row.table-main - div.level-field.width-1 - div.level - div.level-field.width-1 - div.level - div.width-7.subject - | #2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sit amet leo accumsan, commodo neque eu, iaculis nisl. Phasellus fermentum ipsum eget sapien suscipit pretium. - div.width-2 - In progress - div.width-2 - figure.avatar - img(src="http://thecodeplayer.com/u/uifaces/12.jpg", alt="username") - figcaption Pilar \ No newline at end of file + div.row.table-main(ng-repeat="issue in issues track by issue.id") + div.level-field.width-1 + div.level + div.level-field.width-1 + div.level + div.width-7.subject(tg-bo-html="issue.subject") + div.width-2 + In progress + div.width-2 + figure.avatar + img(src="http://thecodeplayer.com/u/uifaces/12.jpg", alt="username") + figcaption Pilar + +section.issues-paginator \ No newline at end of file diff --git a/gulpfile.coffee b/gulpfile.coffee index f02fd1af..8af4c916 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -39,6 +39,7 @@ paths = { "app/coffee/modules/*.coffee", "app/coffee/modules/common/*.coffee", "app/coffee/modules/backlog/*.coffee", + "app/coffee/modules/issues/*.coffee", "app/coffee/modules/locales/*.coffee", "app/coffee/modules/base/*.coffee", "app/coffee/modules/resources/*.coffee"]