users resources
parent
9d551fdd5c
commit
74aa3a5d75
|
@ -356,6 +356,7 @@ modules = [
|
|||
"taigaBase",
|
||||
"taigaCommon",
|
||||
"taigaResources",
|
||||
"taigaResources2",
|
||||
"taigaAuth",
|
||||
"taigaEvents",
|
||||
|
||||
|
|
|
@ -146,8 +146,9 @@ urls = {
|
|||
# locales
|
||||
"locales": "/locales"
|
||||
|
||||
# user
|
||||
# users
|
||||
"contacts": "/users/%s/contacts"
|
||||
"stats": "/users/%s/stats"
|
||||
}
|
||||
|
||||
# Initialize api urls service
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
class ProfileContactsController
|
||||
@.$inject = [
|
||||
"tgUserService",
|
||||
"tgResources",
|
||||
"$tgAuth"
|
||||
]
|
||||
|
||||
constructor: (@userService, @auth) ->
|
||||
constructor: (@rs, @auth) ->
|
||||
|
||||
loadContacts: () ->
|
||||
userId = @auth.getUser().id
|
||||
|
||||
@userService.getUserContacts(userId)
|
||||
@rs.users.getContacts(userId)
|
||||
.then (contacts) =>
|
||||
@.contacts = contacts
|
||||
|
||||
|
|
|
@ -5,12 +5,14 @@ describe "ProfileContacts", ->
|
|||
$rootScope = null
|
||||
mocks = {}
|
||||
|
||||
_mockUserService = () ->
|
||||
mocks.userService = {
|
||||
getUserContacts: sinon.stub()
|
||||
_mockResources = () ->
|
||||
mocks.resources = {
|
||||
users: {
|
||||
getContacts: sinon.stub()
|
||||
}
|
||||
}
|
||||
|
||||
provide.value "tgUserService", mocks.userService
|
||||
provide.value "tgResources", mocks.resources
|
||||
|
||||
_mockAuthService = () ->
|
||||
stub = sinon.stub()
|
||||
|
@ -24,7 +26,7 @@ describe "ProfileContacts", ->
|
|||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockUserService()
|
||||
_mockResources()
|
||||
_mockAuthService()
|
||||
|
||||
return null
|
||||
|
@ -48,7 +50,7 @@ describe "ProfileContacts", ->
|
|||
{id: 3}
|
||||
]
|
||||
|
||||
mocks.userService.getUserContacts = (userId) ->
|
||||
mocks.resources.users.getContacts = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
|
|
|
@ -15,6 +15,5 @@ class ProfileProjectsController
|
|||
.then (projects) =>
|
||||
@.projects = projects
|
||||
|
||||
|
||||
angular.module("taigaProfile")
|
||||
.controller("ProfileProjects", ProfileProjectsController)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# 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/main.coffee
|
||||
# File: modules/profile/profile-timeline/profile-timeline.controller.coffee
|
||||
###
|
||||
|
||||
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
|
||||
|
||||
class UserService extends taiga.Service
|
||||
@.$inject = ["$tgResources"]
|
||||
@.$inject = ["tgResources"]
|
||||
|
||||
constructor: (@rs) ->
|
||||
|
||||
getProjects: (userId) ->
|
||||
return @rs.projects.listByMember(userId)
|
||||
.then (projects) -> return Immutable.fromJS(projects)
|
||||
return @rs.users.getProjects(userId)
|
||||
|
||||
getContacts: (userId) ->
|
||||
return @rs.users.getContacts(userId)
|
||||
|
||||
attachUserContactsToProjects: (userId, projects) ->
|
||||
return @.getUserContacts(userId)
|
||||
return @.getContacts(userId)
|
||||
.then (contacts) ->
|
||||
projects = projects.map (project) ->
|
||||
project.contacts = contacts.filter (contact) ->
|
||||
contactsFiltered = contacts.filter (contact) ->
|
||||
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 projects
|
||||
|
||||
getUserContacts: (userId) ->
|
||||
return @rs.users.contacts(userId)
|
||||
.then (contacts) -> return Immutable.fromJS(contacts)
|
||||
|
||||
angular.module("taigaCommon").service("tgUserService", UserService)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
# pending new resouercees
|
||||
|
||||
describe.skip "UserService", ->
|
||||
describe "UserService", ->
|
||||
userService = null
|
||||
$q = null
|
||||
provide = null
|
||||
|
@ -9,15 +7,12 @@ describe.skip "UserService", ->
|
|||
|
||||
_mockResources = () ->
|
||||
mocks.resources = {}
|
||||
mocks.resources.projects = {
|
||||
listByMember: sinon.stub()
|
||||
}
|
||||
|
||||
mocks.resources.users = {
|
||||
contacts: sinon.stub()
|
||||
getProjects: sinon.stub(),
|
||||
getContacts: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgResources", mocks.resources
|
||||
provide.value "tgResources", mocks.resources
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
|
@ -37,7 +32,7 @@ describe.skip "UserService", ->
|
|||
_mocks()
|
||||
_inject()
|
||||
|
||||
it "get user projects", (done) ->
|
||||
it "get user projects", () ->
|
||||
userId = 2
|
||||
|
||||
projects = [
|
||||
|
@ -46,28 +41,17 @@ describe.skip "UserService", ->
|
|||
{id: 3}
|
||||
]
|
||||
|
||||
mocks.resources.projects.listByMember = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
mocks.resources.users.getProjects.withArgs(userId).returns(true)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
resolve(projects)
|
||||
|
||||
userService.getProjects(userId).then (_projects_) ->
|
||||
expect(_projects_.toJS()).to.be.eql(projects)
|
||||
done()
|
||||
|
||||
$rootScope.$apply()
|
||||
expect(userService.getProjects(userId)).to.be.true
|
||||
|
||||
it "attach user contacts to projects", (done) ->
|
||||
userId = 2
|
||||
|
||||
class Project
|
||||
constructor: (@id, @members) ->
|
||||
|
||||
projects = Immutable.fromJS([
|
||||
new Project(1, [1, 2, 3]),
|
||||
new Project(1, [2, 3]),
|
||||
new Project(1, [1])
|
||||
{id: 1, members: [1, 2, 3]},
|
||||
{id: 2, members: [2, 3]},
|
||||
{id: 3, members: [1]}
|
||||
])
|
||||
|
||||
contacts = Immutable.fromJS([
|
||||
|
@ -76,18 +60,16 @@ describe.skip "UserService", ->
|
|||
{id: 3, name: "fake3"}
|
||||
])
|
||||
|
||||
mocks.resources.users.contacts = (userId) ->
|
||||
mocks.resources.users.getContacts = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
resolve(contacts)
|
||||
|
||||
userService.attachUserContactsToProjects(userId, projects).then (_projects_) ->
|
||||
contacts = _projects_.get(0).contacts
|
||||
contacts = _projects_.get(0).get("contacts")
|
||||
|
||||
console.log _projects_.get(0)
|
||||
|
||||
expect(contacts[0]).to.be.equal('fake1')
|
||||
expect(contacts.get(0).get("name")).to.be.equal('fake1')
|
||||
done()
|
||||
|
||||
$rootScope.$apply()
|
||||
|
@ -101,14 +83,14 @@ describe.skip "UserService", ->
|
|||
{id: 3}
|
||||
]
|
||||
|
||||
mocks.resources.user.contacts = (userId) ->
|
||||
mocks.resources.users.getContacts = (userId) ->
|
||||
expect(userId).to.be.equal(userId)
|
||||
|
||||
return $q (resolve, reject) ->
|
||||
resolve(contacts)
|
||||
|
||||
userService.getUserContacts(userId).then (_contacts_) ->
|
||||
expect(_contacts_.toJS()).to.be.eql(contacts)
|
||||
userService.getContacts(userId).then (_contacts_) ->
|
||||
expect(_contacts_).to.be.eql(contacts)
|
||||
done()
|
||||
|
||||
$rootScope.$apply()
|
||||
|
|
Loading…
Reference in New Issue