Refactor resources structure.

stable
Andrey Antukh 2014-06-17 15:17:07 +02:00
parent 25cb1209f9
commit 93d2c041fa
14 changed files with 161 additions and 47 deletions

View File

@ -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)

View File

@ -1,3 +1,4 @@
###
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
@ -14,23 +15,27 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 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) =>

View File

@ -0,0 +1 @@
module = angular.module("taigaBase", [])

View File

@ -66,5 +66,5 @@ class HttpService extends taiga.TaigaService
return @.request(options)
module = angular.module("taigaResources")
module = angular.module("taigaBase")
module.service("$tgHttp", HttpService)

View File

@ -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])

View File

@ -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)

View File

@ -48,5 +48,5 @@ class StorageService extends taiga.TaigaService
localStorage.clear()
module = angular.module("taigaResources")
module = angular.module("taigaBase")
module.service("$tgStorage", StorageService)

View File

@ -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)

View File

@ -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
])

View File

@ -0,0 +1,40 @@
###
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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])

View File

@ -0,0 +1,40 @@
###
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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])

View File

@ -0,0 +1,35 @@
###
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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])

View File

@ -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"]
}