users resources
parent
9d551fdd5c
commit
74aa3a5d75
|
@ -356,6 +356,7 @@ modules = [
|
||||||
"taigaBase",
|
"taigaBase",
|
||||||
"taigaCommon",
|
"taigaCommon",
|
||||||
"taigaResources",
|
"taigaResources",
|
||||||
|
"taigaResources2",
|
||||||
"taigaAuth",
|
"taigaAuth",
|
||||||
"taigaEvents",
|
"taigaEvents",
|
||||||
|
|
||||||
|
|
|
@ -146,8 +146,9 @@ urls = {
|
||||||
# locales
|
# locales
|
||||||
"locales": "/locales"
|
"locales": "/locales"
|
||||||
|
|
||||||
# user
|
# users
|
||||||
"contacts": "/users/%s/contacts"
|
"contacts": "/users/%s/contacts"
|
||||||
|
"stats": "/users/%s/stats"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialize api urls service
|
# Initialize api urls service
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
class ProfileContactsController
|
class ProfileContactsController
|
||||||
@.$inject = [
|
@.$inject = [
|
||||||
"tgUserService",
|
"tgResources",
|
||||||
"$tgAuth"
|
"$tgAuth"
|
||||||
]
|
]
|
||||||
|
|
||||||
constructor: (@userService, @auth) ->
|
constructor: (@rs, @auth) ->
|
||||||
|
|
||||||
loadContacts: () ->
|
loadContacts: () ->
|
||||||
userId = @auth.getUser().id
|
userId = @auth.getUser().id
|
||||||
|
|
||||||
@userService.getUserContacts(userId)
|
@rs.users.getContacts(userId)
|
||||||
.then (contacts) =>
|
.then (contacts) =>
|
||||||
@.contacts = contacts
|
@.contacts = contacts
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,14 @@ describe "ProfileContacts", ->
|
||||||
$rootScope = null
|
$rootScope = null
|
||||||
mocks = {}
|
mocks = {}
|
||||||
|
|
||||||
_mockUserService = () ->
|
_mockResources = () ->
|
||||||
mocks.userService = {
|
mocks.resources = {
|
||||||
getUserContacts: sinon.stub()
|
users: {
|
||||||
|
getContacts: sinon.stub()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
provide.value "tgUserService", mocks.userService
|
provide.value "tgResources", mocks.resources
|
||||||
|
|
||||||
_mockAuthService = () ->
|
_mockAuthService = () ->
|
||||||
stub = sinon.stub()
|
stub = sinon.stub()
|
||||||
|
@ -24,7 +26,7 @@ describe "ProfileContacts", ->
|
||||||
_mocks = () ->
|
_mocks = () ->
|
||||||
module ($provide) ->
|
module ($provide) ->
|
||||||
provide = $provide
|
provide = $provide
|
||||||
_mockUserService()
|
_mockResources()
|
||||||
_mockAuthService()
|
_mockAuthService()
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
@ -48,7 +50,7 @@ describe "ProfileContacts", ->
|
||||||
{id: 3}
|
{id: 3}
|
||||||
]
|
]
|
||||||
|
|
||||||
mocks.userService.getUserContacts = (userId) ->
|
mocks.resources.users.getContacts = (userId) ->
|
||||||
expect(userId).to.be.equal(userId)
|
expect(userId).to.be.equal(userId)
|
||||||
|
|
||||||
return $q (resolve, reject) ->
|
return $q (resolve, reject) ->
|
||||||
|
|
|
@ -15,6 +15,5 @@ class ProfileProjectsController
|
||||||
.then (projects) =>
|
.then (projects) =>
|
||||||
@.projects = projects
|
@.projects = projects
|
||||||
|
|
||||||
|
|
||||||
angular.module("taigaProfile")
|
angular.module("taigaProfile")
|
||||||
.controller("ProfileProjects", ProfileProjectsController)
|
.controller("ProfileProjects", ProfileProjectsController)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# File: modules/backlog/main.coffee
|
# File: modules/profile/profile-timeline/profile-timeline.controller.coffee
|
||||||
###
|
###
|
||||||
|
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
services = [
|
||||||
|
"tgProjectsResources"
|
||||||
|
]
|
||||||
|
|
||||||
|
Resources = ($injector) ->
|
||||||
|
for serviceName in services
|
||||||
|
serviceFn = $injector.get(serviceName)
|
||||||
|
|
||||||
|
service = $injector.invoke(serviceFn)
|
||||||
|
|
||||||
|
for serviceProperty in Object.keys(service)
|
||||||
|
if @[serviceProperty]
|
||||||
|
console.warm("repeated resource " + serviceProperty)
|
||||||
|
|
||||||
|
@[serviceProperty] = service[serviceProperty]
|
||||||
|
|
||||||
|
return @
|
||||||
|
|
||||||
|
|
||||||
|
Resources.$inject = ["$injector"]
|
||||||
|
|
||||||
|
angular.module("taigaResources2").service("tgResources", Resources)
|
|
@ -0,0 +1 @@
|
||||||
|
angular.module("taigaResources2", [])
|
|
@ -0,0 +1,46 @@
|
||||||
|
Resource = (urlsService, http) ->
|
||||||
|
service = {}
|
||||||
|
|
||||||
|
service.getStats = (userId) ->
|
||||||
|
url = urlsService.resolve("stats", userId)
|
||||||
|
|
||||||
|
httpOptions = {
|
||||||
|
headers: {
|
||||||
|
"x-disable-pagination": "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.get(url, {}, httpOptions)
|
||||||
|
.then (result) ->
|
||||||
|
return Immutable.fromJS(result.data)
|
||||||
|
|
||||||
|
|
||||||
|
service.getContacts = (userId) ->
|
||||||
|
url = urlsService.resolve("contacts", userId)
|
||||||
|
|
||||||
|
httpOptions = {
|
||||||
|
headers: {
|
||||||
|
"x-disable-pagination": "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return http.get(url, {}, httpOptions)
|
||||||
|
.then (result) ->
|
||||||
|
return Immutable.fromJS(result.data)
|
||||||
|
|
||||||
|
service.getProjects = (userId) ->
|
||||||
|
url = urlsService.resolve("projects")
|
||||||
|
|
||||||
|
params = {"member": userId, "order_by": "memberships__user_order"}
|
||||||
|
|
||||||
|
return http.get(url, params)
|
||||||
|
.then (result) ->
|
||||||
|
return Immutable.fromJS(result.data)
|
||||||
|
|
||||||
|
return () ->
|
||||||
|
return {"users": service}
|
||||||
|
|
||||||
|
Resource.$inject = ["$tgUrls", "$tgHttp"]
|
||||||
|
|
||||||
|
module = angular.module("taigaResources2")
|
||||||
|
module.factory("tgProjectsResources", Resource)
|
|
@ -1,28 +1,28 @@
|
||||||
taiga = @.taiga
|
taiga = @.taiga
|
||||||
|
|
||||||
class UserService extends taiga.Service
|
class UserService extends taiga.Service
|
||||||
@.$inject = ["$tgResources"]
|
@.$inject = ["tgResources"]
|
||||||
|
|
||||||
constructor: (@rs) ->
|
constructor: (@rs) ->
|
||||||
|
|
||||||
getProjects: (userId) ->
|
getProjects: (userId) ->
|
||||||
return @rs.projects.listByMember(userId)
|
return @rs.users.getProjects(userId)
|
||||||
.then (projects) -> return Immutable.fromJS(projects)
|
|
||||||
|
getContacts: (userId) ->
|
||||||
|
return @rs.users.getContacts(userId)
|
||||||
|
|
||||||
attachUserContactsToProjects: (userId, projects) ->
|
attachUserContactsToProjects: (userId, projects) ->
|
||||||
return @.getUserContacts(userId)
|
return @.getContacts(userId)
|
||||||
.then (contacts) ->
|
.then (contacts) ->
|
||||||
projects = projects.map (project) ->
|
projects = projects.map (project) ->
|
||||||
project.contacts = contacts.filter (contact) ->
|
contactsFiltered = contacts.filter (contact) ->
|
||||||
contactId = contact.get("id")
|
contactId = contact.get("id")
|
||||||
return project.members.indexOf(contactId) != -1
|
return project.get('members').indexOf(contactId) != -1
|
||||||
|
|
||||||
|
project = project.set("contacts", contactsFiltered)
|
||||||
|
|
||||||
return project
|
return project
|
||||||
|
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
getUserContacts: (userId) ->
|
|
||||||
return @rs.users.contacts(userId)
|
|
||||||
.then (contacts) -> return Immutable.fromJS(contacts)
|
|
||||||
|
|
||||||
angular.module("taigaCommon").service("tgUserService", UserService)
|
angular.module("taigaCommon").service("tgUserService", UserService)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# pending new resouercees
|
describe "UserService", ->
|
||||||
|
|
||||||
describe.skip "UserService", ->
|
|
||||||
userService = null
|
userService = null
|
||||||
$q = null
|
$q = null
|
||||||
provide = null
|
provide = null
|
||||||
|
@ -9,15 +7,12 @@ describe.skip "UserService", ->
|
||||||
|
|
||||||
_mockResources = () ->
|
_mockResources = () ->
|
||||||
mocks.resources = {}
|
mocks.resources = {}
|
||||||
mocks.resources.projects = {
|
|
||||||
listByMember: sinon.stub()
|
|
||||||
}
|
|
||||||
|
|
||||||
mocks.resources.users = {
|
mocks.resources.users = {
|
||||||
contacts: sinon.stub()
|
getProjects: sinon.stub(),
|
||||||
|
getContacts: sinon.stub()
|
||||||
}
|
}
|
||||||
|
|
||||||
provide.value "$tgResources", mocks.resources
|
provide.value "tgResources", mocks.resources
|
||||||
|
|
||||||
_mocks = () ->
|
_mocks = () ->
|
||||||
module ($provide) ->
|
module ($provide) ->
|
||||||
|
@ -37,7 +32,7 @@ describe.skip "UserService", ->
|
||||||
_mocks()
|
_mocks()
|
||||||
_inject()
|
_inject()
|
||||||
|
|
||||||
it "get user projects", (done) ->
|
it "get user projects", () ->
|
||||||
userId = 2
|
userId = 2
|
||||||
|
|
||||||
projects = [
|
projects = [
|
||||||
|
@ -46,28 +41,17 @@ describe.skip "UserService", ->
|
||||||
{id: 3}
|
{id: 3}
|
||||||
]
|
]
|
||||||
|
|
||||||
mocks.resources.projects.listByMember = (userId) ->
|
mocks.resources.users.getProjects.withArgs(userId).returns(true)
|
||||||
expect(userId).to.be.equal(userId)
|
|
||||||
|
|
||||||
return $q (resolve, reject) ->
|
expect(userService.getProjects(userId)).to.be.true
|
||||||
resolve(projects)
|
|
||||||
|
|
||||||
userService.getProjects(userId).then (_projects_) ->
|
|
||||||
expect(_projects_.toJS()).to.be.eql(projects)
|
|
||||||
done()
|
|
||||||
|
|
||||||
$rootScope.$apply()
|
|
||||||
|
|
||||||
it "attach user contacts to projects", (done) ->
|
it "attach user contacts to projects", (done) ->
|
||||||
userId = 2
|
userId = 2
|
||||||
|
|
||||||
class Project
|
|
||||||
constructor: (@id, @members) ->
|
|
||||||
|
|
||||||
projects = Immutable.fromJS([
|
projects = Immutable.fromJS([
|
||||||
new Project(1, [1, 2, 3]),
|
{id: 1, members: [1, 2, 3]},
|
||||||
new Project(1, [2, 3]),
|
{id: 2, members: [2, 3]},
|
||||||
new Project(1, [1])
|
{id: 3, members: [1]}
|
||||||
])
|
])
|
||||||
|
|
||||||
contacts = Immutable.fromJS([
|
contacts = Immutable.fromJS([
|
||||||
|
@ -76,18 +60,16 @@ describe.skip "UserService", ->
|
||||||
{id: 3, name: "fake3"}
|
{id: 3, name: "fake3"}
|
||||||
])
|
])
|
||||||
|
|
||||||
mocks.resources.users.contacts = (userId) ->
|
mocks.resources.users.getContacts = (userId) ->
|
||||||
expect(userId).to.be.equal(userId)
|
expect(userId).to.be.equal(userId)
|
||||||
|
|
||||||
return $q (resolve, reject) ->
|
return $q (resolve, reject) ->
|
||||||
resolve(contacts)
|
resolve(contacts)
|
||||||
|
|
||||||
userService.attachUserContactsToProjects(userId, projects).then (_projects_) ->
|
userService.attachUserContactsToProjects(userId, projects).then (_projects_) ->
|
||||||
contacts = _projects_.get(0).contacts
|
contacts = _projects_.get(0).get("contacts")
|
||||||
|
|
||||||
console.log _projects_.get(0)
|
expect(contacts.get(0).get("name")).to.be.equal('fake1')
|
||||||
|
|
||||||
expect(contacts[0]).to.be.equal('fake1')
|
|
||||||
done()
|
done()
|
||||||
|
|
||||||
$rootScope.$apply()
|
$rootScope.$apply()
|
||||||
|
@ -101,14 +83,14 @@ describe.skip "UserService", ->
|
||||||
{id: 3}
|
{id: 3}
|
||||||
]
|
]
|
||||||
|
|
||||||
mocks.resources.user.contacts = (userId) ->
|
mocks.resources.users.getContacts = (userId) ->
|
||||||
expect(userId).to.be.equal(userId)
|
expect(userId).to.be.equal(userId)
|
||||||
|
|
||||||
return $q (resolve, reject) ->
|
return $q (resolve, reject) ->
|
||||||
resolve(contacts)
|
resolve(contacts)
|
||||||
|
|
||||||
userService.getUserContacts(userId).then (_contacts_) ->
|
userService.getContacts(userId).then (_contacts_) ->
|
||||||
expect(_contacts_.toJS()).to.be.eql(contacts)
|
expect(_contacts_).to.be.eql(contacts)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
$rootScope.$apply()
|
$rootScope.$apply()
|
||||||
|
|
Loading…
Reference in New Issue