From cd7068c18a99fe49bb6d282f05856be39e953997 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 11 Jun 2014 19:33:33 +0200 Subject: [PATCH] Load main data for render backlog. --- app/coffee/modules/backlog.coffee | 37 ++++++++---- .../modules/resources/repository.coffee | 19 ++++++- app/coffee/modules/resources/resources.coffee | 50 ++++++++++++++++ app/partials/backlog.jade | 57 ++++++++++--------- app/partials/views/modules/backlog-table.jade | 3 - 5 files changed, 125 insertions(+), 41 deletions(-) create mode 100644 app/coffee/modules/resources/resources.coffee diff --git a/app/coffee/modules/backlog.coffee b/app/coffee/modules/backlog.coffee index 7bea08ce..b97733e9 100644 --- a/app/coffee/modules/backlog.coffee +++ b/app/coffee/modules/backlog.coffee @@ -18,27 +18,44 @@ taiga = @.taiga class BacklogController extends taiga.TaigaController - constructor: (@repo) -> - console.log "foo" + constructor: (@scope, @repo, @params, @rs) -> + # Resolve project slug + promise = @repo.resolve({pslug: @params.pslug}).then (data) => + console.log "resolve", data.project + @scope.projectId = data.project + return @rs.getProject(@scope.projectId) - getMilestones: -> - projectId = 1 - return @repo.queryMany("milestones", {project:projectId}).then (milestones) -> - console.log milestones - return milestones + # Load project + promise = promise.then (project) => + @scope.project = project + console.log project + return @rs.getMilestones(@scope.projectId) + + # Load milestones + promise = promise.then (milestones) => + @scope.milestones = milestones + return @rs.getBacklog(@scope.projectId) + + # Load unassigned userstories + promise = promise.then (userstories) => + @scope.userstories = userstories + + # Obviously fail condition + promise.then null, => + console.log "FAIL" BacklogDirective = ($compile) -> - controller: ["$tgRepo", BacklogController] + controller: ["$scope", "$tgRepo", "$routeParams", "$tgResources", BacklogController] link: (scope, element, attrs, ctrl) -> - ctrl.getMilestones().then => - console.log "kaka" BacklogTableDirective = ($compile, $templateCache) -> require: "^tgBacklog" link: (scope, element, attrs, ctrl) -> content = $templateCache.get("backlog-row.html") + scope.$watch "userstories", (userstories) => + console.log "ready to render", userstories module = angular.module("taiga") diff --git a/app/coffee/modules/resources/repository.coffee b/app/coffee/modules/resources/repository.coffee index cb9f93b4..ac689683 100644 --- a/app/coffee/modules/resources/repository.coffee +++ b/app/coffee/modules/resources/repository.coffee @@ -108,7 +108,14 @@ class RepositoryService extends taiga.TaigaService url = "#{url}/#{id}" if id return @http.get(url, params).then (data) => - return @model.make_model(name, data) + return @model.make_model(name, data.data) + + queryOneRaw: (name, id, params) -> + url = @urls.resolve(name) + url = "#{url}/#{id}" if id + + return @http.get(url, params).then (data) => + return data.data queryPaginated: (name, params) -> url = @urls.resolve(name) @@ -121,5 +128,15 @@ class RepositoryService extends taiga.TaigaService result.paginatedBy = parseInt(headers["x-paginated-by"], 10) return result + resolve: (options) -> + params = {} + params.project = options.pslug if options.pslug? + params.us = options.usref if options.usref? + params.task = options.taskref if options.taskref? + params.issue = options.issueref if options.issueref? + params.milestone = options.mlref if options.mlref? + return @.queryOneRaw("resolver", null, params) + + module = angular.module("taigaResources") module.service("$tgRepo", RepositoryService) diff --git a/app/coffee/modules/resources/resources.coffee b/app/coffee/modules/resources/resources.coffee new file mode 100644 index 00000000..7a1a0cdd --- /dev/null +++ b/app/coffee/modules/resources/resources.coffee @@ -0,0 +1,50 @@ +# 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 . + +taiga = @.taiga + +class ResourcesService extends taiga.TaigaService + @.$inject = ["$q", "$tgRepo", "$tgUrls", "$tgModel"] + + constructor: (@q, @repo, @urls, @model) -> + super() + + ############################################################################# + # Common + ############################################################################# + + getProject: (projectId) -> + return @repo.queryOne("projects", projectId) + + ############################################################################# + # Backlog + ############################################################################# + + getMilestones: (projectId) -> + return @repo.queryMany("milestones", {project:projectId}).then (milestones) => + for m in milestones + uses = m.user_stories + uses = _.map(uses, (u) => @model.make_model("userstories", u)) + m._attrs.user_stories = uses + return milestones + + getBacklog: (projectId) -> + params = {"project": projectId, "milestone": "null"} + return @repo.queryMany("userstories", params) + +module = angular.module("taigaResources") +module.service("$tgResources", ResourcesService) diff --git a/app/partials/backlog.jade b/app/partials/backlog.jade index 21487f80..f2a641de 100644 --- a/app/partials/backlog.jade +++ b/app/partials/backlog.jade @@ -4,31 +4,34 @@ block head title Taiga Project management web application with scrum in mind! block content - div(tg-backlog) - sidebar.menu-secondary.extrabar.filters-bar - include views/modules/filters - section.main.backlog - include views/components/mainTitle - include views/components/summary - include views/modules/burndown - div.backlog-menu - a.trans-button(href="", title="Move to Current Sprint") - span.icon.icon-move - span.text Move to current Sprint - a.trans-button(href="", title="Show Filters") - span.icon.icon-filter - span.text Show Filters - a.trans-button(href="", title="Show Tags") - span.icon.icon-tag - span.text Show Tags - include views/components/addnewus - include views/modules/backlog-table - sidebar.menu-secondary.sidebar - include views/modules/sprints - div.lightbox.lightbox_add-new-us - include views/modules/lightbox_add-new-us - div.lightbox.lightbox_add-bulk - include views/modules/lightbox_add-bulk - div.lightbox.lightbox_add-sprint - include views/modules/lightbox_add-sprint + sidebar.menu-secondary.extrabar.filters-bar + include views/modules/filters + section.main.backlog(tg-backlog) + include views/components/mainTitle + include views/components/summary + include views/modules/burndown + div.backlog-menu + a.trans-button(href="", title="Move to Current Sprint") + span.icon.icon-move + span.text Move to current Sprint + a.trans-button(href="", title="Show Filters") + span.icon.icon-filter + span.text Show Filters + a.trans-button(href="", title="Show Tags") + span.icon.icon-tag + span.text Show Tags + include views/components/addnewus + include views/modules/backlog-table + sidebar.menu-secondary.sidebar + include views/modules/sprints + div.lightbox.lightbox_add-new-us + include views/modules/lightbox_add-new-us + div.lightbox.lightbox_add-bulk + include views/modules/lightbox_add-bulk + div.lightbox.lightbox_add-sprint + include views/modules/lightbox_add-sprint + + // Preloading angular templates parts + script(type="text/ng-template" id="backlog-row.html") + include views/components/backlog-row diff --git a/app/partials/views/modules/backlog-table.jade b/app/partials/views/modules/backlog-table.jade index a3a12cbf..75381651 100644 --- a/app/partials/views/modules/backlog-table.jade +++ b/app/partials/views/modules/backlog-table.jade @@ -67,6 +67,3 @@ section.backlog-table(tg-backlog-table) a(href="", title="Status 3") Status 3 hr.doom-line -// Preloading angular templates parts -script(type="text/ng-template" id="backlog-row.html") - include ../components/backlog-row