diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index f5f1dc07..a096450e 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -50,18 +50,24 @@ configure.$inject = ["$routeProvider", "$locationProvider", "$httpProvider"] init.$inject = ["$log", "$rootScope"] modules = [ - "ngRoute", - "ngAnimate", - + # Main Modules "taigaConfig", + "taigaBase", "taigaResources", + + # Specific Modules "taigaBacklog", # Vendor modules + "ngRoute", + "ngAnimate", "pasvaz.bindonce", ] +# Default Value for taiga local config module. angular.module("taigaLocalConfig", []).value("localconfig", {}) + +# Main module definition module = angular.module("taiga", modules) module.config(configure) module.run(init) diff --git a/app/coffee/base.coffee b/app/coffee/classes.coffee similarity index 100% rename from app/coffee/base.coffee rename to app/coffee/classes.coffee diff --git a/app/coffee/modules/backlog.coffee b/app/coffee/modules/backlog.coffee index a7d04a7f..a9196e60 100644 --- a/app/coffee/modules/backlog.coffee +++ b/app/coffee/modules/backlog.coffee @@ -1,3 +1,4 @@ +### # Copyright (C) 2014 Andrey Antukh # Copyright (C) 2014 Jesús Espino Garcia # Copyright (C) 2014 David Barragán Merino @@ -14,23 +15,27 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +# +# File: modules/backlog.coffee +### taiga = @.taiga class BacklogController extends taiga.TaigaController constructor: (@scope, @repo, @params, @rs, @q) -> promise = @.loadInitialData() + # Obviously fail condition promise.then null, => console.log "FAIL" loadSprints: -> - return @rs.getSprints(@scope.projectId).then (sprints) => + return @rs.sprints.list(@scope.projectId).then (sprints) => @scope.sprints = sprints return sprints loadUserstories: -> - return @rs.getUnassignedUserstories(@scope.projectId).then (userstories) => + return @rs.userstories.listUnassigned(@scope.projectId).then (userstories) => @scope.userstories = userstories return userstories @@ -45,7 +50,7 @@ class BacklogController extends taiga.TaigaController promise = @repo.resolve({pslug: @params.pslug}).then (data) => console.log "resolve", data.project @scope.projectId = data.project - return @rs.getProject(@scope.projectId) + return @rs.projects.get(@scope.projectId) # Load project promise = promise.then (project) => diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee new file mode 100644 index 00000000..79c289ce --- /dev/null +++ b/app/coffee/modules/base.coffee @@ -0,0 +1 @@ +module = angular.module("taigaBase", []) diff --git a/app/coffee/modules/resources/http.coffee b/app/coffee/modules/base/http.coffee similarity index 98% rename from app/coffee/modules/resources/http.coffee rename to app/coffee/modules/base/http.coffee index 45d05c71..868f7116 100644 --- a/app/coffee/modules/resources/http.coffee +++ b/app/coffee/modules/base/http.coffee @@ -66,5 +66,5 @@ class HttpService extends taiga.TaigaService return @.request(options) -module = angular.module("taigaResources") +module = angular.module("taigaBase") module.service("$tgHttp", HttpService) diff --git a/app/coffee/modules/resources/model.coffee b/app/coffee/modules/base/model.coffee similarity index 98% rename from app/coffee/modules/resources/model.coffee rename to app/coffee/modules/base/model.coffee index 6bdb9b60..9229918f 100644 --- a/app/coffee/modules/resources/model.coffee +++ b/app/coffee/modules/base/model.coffee @@ -139,5 +139,5 @@ provider = ($q, $http, $gmUrls, $gmStorage) -> return service -module = angular.module("taigaResources") +module = angular.module("taigaBase") module.factory("$tgModel", ["$q", "$http", "$tgUrls", "$tgStorage", provider]) diff --git a/app/coffee/modules/resources/repository.coffee b/app/coffee/modules/base/repository.coffee similarity index 99% rename from app/coffee/modules/resources/repository.coffee rename to app/coffee/modules/base/repository.coffee index ac689683..d062a78c 100644 --- a/app/coffee/modules/resources/repository.coffee +++ b/app/coffee/modules/base/repository.coffee @@ -138,5 +138,5 @@ class RepositoryService extends taiga.TaigaService return @.queryOneRaw("resolver", null, params) -module = angular.module("taigaResources") +module = angular.module("taigaBase") module.service("$tgRepo", RepositoryService) diff --git a/app/coffee/modules/resources/storage.coffee b/app/coffee/modules/base/storage.coffee similarity index 97% rename from app/coffee/modules/resources/storage.coffee rename to app/coffee/modules/base/storage.coffee index cfdfeada..3a9a3785 100644 --- a/app/coffee/modules/resources/storage.coffee +++ b/app/coffee/modules/base/storage.coffee @@ -48,5 +48,5 @@ class StorageService extends taiga.TaigaService localStorage.clear() -module = angular.module("taigaResources") +module = angular.module("taigaBase") module.service("$tgStorage", StorageService) diff --git a/app/coffee/modules/resources/urls.coffee b/app/coffee/modules/base/urls.coffee similarity index 97% rename from app/coffee/modules/resources/urls.coffee rename to app/coffee/modules/base/urls.coffee index cdafe076..01922fb9 100644 --- a/app/coffee/modules/resources/urls.coffee +++ b/app/coffee/modules/base/urls.coffee @@ -41,5 +41,5 @@ class UrlsService return format("%s://%s%s", [@.scheme, @.host, url]) -module = angular.module("taigaResources") +module = angular.module("taigaBase") module.service('$tgUrls', UrlsService) diff --git a/app/coffee/modules/resources.coffee b/app/coffee/modules/resources.coffee index e0e2c69a..715bb828 100644 --- a/app/coffee/modules/resources.coffee +++ b/app/coffee/modules/resources.coffee @@ -18,40 +18,8 @@ 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) - - getProjects: -> - return @repo.queryMany("projects") - - ############################################################################# - # Backlog - ############################################################################# - - getSprints: (projectId) -> - params = {"project": projectId} - return @repo.queryMany("milestones", params).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 - - getUnassignedUserstories: (projectId) -> - params = {"project": projectId, "milestone": "null"} - return @repo.queryMany("userstories", params) - - -init = (urls) -> +initUrls = (urls) -> urls.update({ "auth": "/api/v1/auth" "auth-register": "/api/v1/auth/register" @@ -110,6 +78,25 @@ init = (urls) -> "wiki/attachments": "/api/v1/wiki/attachments" }) -module = angular.module("taigaResources", []) +# Initialize resources service populating it with methods +# defined in separated files. +initResources = ($log, $rs) -> + $log.debug "Initialize resources" + providers = _.toArray(arguments).slice(2) + + for provider in providers + provider($rs) + +module = angular.module("taigaResources", ["taigaBase"]) module.service("$tgResources", ResourcesService) -module.run(["$tgUrls", init]) + +# Module entry point +module.run(["$tgUrls", initUrls]) +module.run([ + "$log", + "$tgResources", + "$tgProjectsResourcesProvider", + "$tgSprintsResourcesProvider", + "$tgUserstoriesResourcesProvider", + initResources +]) diff --git a/app/coffee/modules/resources/projects.coffee b/app/coffee/modules/resources/projects.coffee new file mode 100644 index 00000000..9ae30981 --- /dev/null +++ b/app/coffee/modules/resources/projects.coffee @@ -0,0 +1,40 @@ +### +# 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/resources/projects.coffee +### + + +taiga = @.taiga + +resourceProvider = ($repo) -> + service = {} + + service.get = (id) -> + return $repo.queryOne("projects", id) + + service.list = -> + return $repo.queryMany("projects") + + return (instance) -> + instance.projects = service + + +module = angular.module("taigaResources") +module.factory("$tgProjectsResourcesProvider", ["$tgRepo", resourceProvider]) + diff --git a/app/coffee/modules/resources/sprints.coffee b/app/coffee/modules/resources/sprints.coffee new file mode 100644 index 00000000..1c3721e6 --- /dev/null +++ b/app/coffee/modules/resources/sprints.coffee @@ -0,0 +1,40 @@ +### +# 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/resources/sprints.coffee +### + +taiga = @.taiga + +resourceProvider = ($repo, $model) -> + service = {} + + service.list = (projectId) -> + params = {"project": projectId} + return $repo.queryMany("milestones", params).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 + + return (instance) -> + instance.sprints = service + +module = angular.module("taigaResources") +module.factory("$tgSprintsResourcesProvider", ["$tgRepo", "$tgModel", resourceProvider]) diff --git a/app/coffee/modules/resources/userstories.coffee b/app/coffee/modules/resources/userstories.coffee new file mode 100644 index 00000000..9f1ca2f5 --- /dev/null +++ b/app/coffee/modules/resources/userstories.coffee @@ -0,0 +1,35 @@ +### +# 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/resources/userstories.coffee +### + +taiga = @.taiga + +resourceProvider = ($repo) -> + service = {} + + service.listUnassigned = (projectId) -> + params = {"project": projectId, "milestone": "null"} + return $repo.queryMany("userstories", params) + + return (instance) -> + instance.userstories = service + +module = angular.module("taigaResources") +module.factory("$tgUserstoriesResourcesProvider", ["$tgRepo", resourceProvider]) diff --git a/gulpfile.coffee b/gulpfile.coffee index d6c8f7a3..1de56485 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -36,7 +36,7 @@ paths = { "config/main.coffee", "app/coffee/*.coffee", "app/coffee/modules/*.coffee", - "app/coffee/modules/resources/init.coffee", + "app/coffee/modules/base/*.coffee", "app/coffee/modules/resources/*.coffee", "app/coffee/**/*.coffee"] }