diff --git a/app/locales/locale-en.json b/app/locales/locale-en.json index d90335a4..1eb40fda 100644 --- a/app/locales/locale-en.json +++ b/app/locales/locale-en.json @@ -542,7 +542,11 @@ "ACTIVITY_TAB": "Activity Tab", "PROJECTS_TAB": "Projects Tab", "CONTACTS_TAB": "Contacts Tab", - "FAVORITES_TAB": "Favorites Tab" + "FAVORITES_TAB": "Favorites Tab", + "CONTACTS_EMPTY": "{{username}} doesn't have contacts yet", + "CURRENT_USER_CONTACTS_EMPTY": "You don't have contacts yet", + "CURRENT_USER_CONTACTS_EMPTY_EXPLAIN": "The people with whom you work at Taiga will be your contacts automatically", + "PROJECTS_EMPTY": "{{username}} doesn't' have projects yet" }, "PROFILE_SIDEBAR": { "TITLE": "Your profile", diff --git a/app/modules/profile/profile-contacts/profile-contacts.controller.coffee b/app/modules/profile/profile-contacts/profile-contacts.controller.coffee index bc852e0d..cae24b1c 100644 --- a/app/modules/profile/profile-contacts/profile-contacts.controller.coffee +++ b/app/modules/profile/profile-contacts/profile-contacts.controller.coffee @@ -1,12 +1,20 @@ class ProfileContactsController @.$inject = [ - "tgUserService" + "tgUserService", + "tgCurrentUserService" ] - constructor: (@userService) -> + constructor: (@userService, @currentUserService) -> loadContacts: () -> - @userService.getContacts(@.userId) + @.currentUser = @currentUserService.getUser() + + @.isCurrentUser = false + + if @.currentUser.get("id") == @.user.get("id") + @.isCurrentUser = true + + @userService.getContacts(@.user.get("id")) .then (contacts) => @.contacts = contacts diff --git a/app/modules/profile/profile-contacts/profile-contacts.controller.spec.coffee b/app/modules/profile/profile-contacts/profile-contacts.controller.spec.coffee index ba05bd41..cf72cda4 100644 --- a/app/modules/profile/profile-contacts/profile-contacts.controller.spec.coffee +++ b/app/modules/profile/profile-contacts/profile-contacts.controller.spec.coffee @@ -11,10 +11,18 @@ describe "ProfileContacts", -> provide.value "tgUserService", mocks.userServices + _mockCurrentUserService = () -> + mocks.currentUserService = { + getUser: sinon.stub() + } + + provide.value "tgCurrentUserService", mocks.currentUserService + _mocks = () -> module ($provide) -> provide = $provide _mockUserService() + _mockCurrentUserService() return null @@ -28,22 +36,51 @@ describe "ProfileContacts", -> _mocks() _inject() - it "load projects with contacts attached", (done) -> - userId = 2 + it "load current user contacts", (done) -> + user = Immutable.fromJS({id: 2}) + contacts = [ {id: 1}, {id: 2}, {id: 3} ] - mocks.userServices.getContacts.withArgs(userId).promise().resolve(contacts) + mocks.currentUserService.getUser.returns(user) + + mocks.userServices.getContacts.withArgs(user.get("id")).promise().resolve(contacts) $scope = $rootScope.$new() ctrl = $controller("ProfileContacts", $scope, { - userId: userId + user: user }) ctrl.loadContacts().then () -> expect(ctrl.contacts).to.be.equal(contacts) + expect(ctrl.isCurrentUser).to.be.true + done() + + it "load user contacts", (done) -> + user = Immutable.fromJS({id: 2}) + user2 = Immutable.fromJS({id: 3}) + + contacts = [ + {id: 1}, + {id: 2}, + {id: 3} + ] + + mocks.currentUserService.getUser.returns(user2) + + mocks.userServices.getContacts.withArgs(user.get("id")).promise().resolve(contacts) + + $scope = $rootScope.$new() + + ctrl = $controller("ProfileContacts", $scope, { + user: user + }) + + ctrl.loadContacts().then () -> + expect(ctrl.contacts).to.be.equal(contacts) + expect(ctrl.isCurrentUser).to.be.false done() diff --git a/app/modules/profile/profile-contacts/profile-contacts.directive.coffee b/app/modules/profile/profile-contacts/profile-contacts.directive.coffee index f3398bd2..994a275b 100644 --- a/app/modules/profile/profile-contacts/profile-contacts.directive.coffee +++ b/app/modules/profile/profile-contacts/profile-contacts.directive.coffee @@ -5,7 +5,7 @@ ProfileContactsDirective = () -> return { templateUrl: "profile/profile-contacts/profile-contacts.html", scope: { - userId: "=userid" + user: "=" }, controllerAs: "vm", controller: "ProfileContacts", diff --git a/app/modules/profile/profile-contacts/profile-contacts.jade b/app/modules/profile/profile-contacts/profile-contacts.jade index eda0a675..265c26d7 100644 --- a/app/modules/profile/profile-contacts/profile-contacts.jade +++ b/app/modules/profile/profile-contacts/profile-contacts.jade @@ -1,7 +1,17 @@ section.profile-contacts - div(ng-if="!vm.contacts.size") + div(ng-if="vm.contacts === undefined") div.spin img(src="/svg/spinner-circle.svg", alt="Loading...") + + div.empty-tab(ng-if="vm.contacts && !vm.contacts.size") + include ../../../svg/hide.svg + + div(ng-if="!vm.isCurrentUser") + p(translate="USER.PROFILE.CONTACTS_EMPTY", translate-values="{username: vm.user.get('full_name_display')}") + div(ng-if="vm.isCurrentUser") + p(translate="USER.PROFILE.CURRENT_USER_CONTACTS_EMPTY") + p(translate="USER.PROFILE.CURRENT_USER_CONTACTS_EMPTY_EXPLAIN") + // nav.profile-contact-filters // a.active(href="", title="No Filter") all // a(href="", title="Only show your team") team diff --git a/app/modules/profile/profile-projects/profile-projects.controller.coffee b/app/modules/profile/profile-projects/profile-projects.controller.coffee index 7f15ebc7..cadcc2a1 100644 --- a/app/modules/profile/profile-projects/profile-projects.controller.coffee +++ b/app/modules/profile/profile-projects/profile-projects.controller.coffee @@ -7,9 +7,9 @@ class ProfileProjectsController constructor: (@projectsService, @userService) -> loadProjects: () -> - @projectsService.getProjectsByUserId(@.userId) + @projectsService.getProjectsByUserId(@.user.get("id")) .then (projects) => - return @userService.attachUserContactsToProjects(@.userId, projects) + return @userService.attachUserContactsToProjects(@.user.get("id"), projects) .then (projects) => @.projects = projects diff --git a/app/modules/profile/profile-projects/profile-projects.controller.spec.coffee b/app/modules/profile/profile-projects/profile-projects.controller.spec.coffee index 2461a1b3..a090567f 100644 --- a/app/modules/profile/profile-projects/profile-projects.controller.spec.coffee +++ b/app/modules/profile/profile-projects/profile-projects.controller.spec.coffee @@ -47,7 +47,7 @@ describe "ProfileProjects", -> _inject() it "load projects with contacts attached", (done) -> - userId = 2 + user = Immutable.fromJS({id: 2}) projects = [ {id: 1}, {id: 2}, @@ -60,13 +60,13 @@ describe "ProfileProjects", -> {id: 3, contacts: "fake"} ] - mocks.projectsService.getProjectsByUserId.withArgs(userId).promise().resolve(projects) - mocks.userService.attachUserContactsToProjects.withArgs(userId, projects).returns(projectsWithContacts) + mocks.projectsService.getProjectsByUserId.withArgs(user.get("id")).promise().resolve(projects) + mocks.userService.attachUserContactsToProjects.withArgs(user.get("id"), projects).returns(projectsWithContacts) $scope = $rootScope.$new() ctrl = $controller("ProfileProjects", $scope, { - userId: userId + user: user }) ctrl.loadProjects().then () -> diff --git a/app/modules/profile/profile-projects/profile-projects.directive.coffee b/app/modules/profile/profile-projects/profile-projects.directive.coffee index 6a2666a7..57e50153 100644 --- a/app/modules/profile/profile-projects/profile-projects.directive.coffee +++ b/app/modules/profile/profile-projects/profile-projects.directive.coffee @@ -5,7 +5,7 @@ ProfileProjectsDirective = () -> return { templateUrl: "profile/profile-projects/profile-projects.html", scope: { - userId: "=userid" + user: "=" }, link: link bindToController: true, diff --git a/app/modules/profile/profile-projects/profile-projects.jade b/app/modules/profile/profile-projects/profile-projects.jade index d3f38bcd..4b5a8bd5 100644 --- a/app/modules/profile/profile-projects/profile-projects.jade +++ b/app/modules/profile/profile-projects/profile-projects.jade @@ -1,8 +1,13 @@ section.profile-projects - div(ng-if="!vm.projects.size") + div(ng-if="vm.projects === undefined") div.spin img(src="/svg/spinner-circle.svg", alt="Loading...") + div.empty-tab(ng-if="vm.projects && !vm.projects.size") + include ../../../svg/hide.svg + + p(translate="USER.PROFILE.PROJECTS_EMPTY", translate-values="{username: vm.user.get('full_name_display')}") + div.project-list-single(tg-repeat="project in vm.projects") div.project-list-single-left diff --git a/app/modules/profile/profile.jade b/app/modules/profile/profile.jade index 9996b8b6..afb1e8f4 100644 --- a/app/modules/profile/profile.jade +++ b/app/modules/profile/profile.jade @@ -4,13 +4,13 @@ div.profile.centered(ng-if="vm.user") div.main div.timeline-wrapper(tg-profile-tabs) div(tg-profile-tab="activity", tab-title="{{'USER.PROFILE.ACTIVITY_TAB' | translate}}", tab-icon="icon-timeline", tab-active) - div(tg-user-timeline, userId="vm.user.get('id')") + div(tg-user-timeline, user="vm.user") div(tab-disabled="{{vm.isCurrentUser}}", tg-profile-tab="projects", tab-title="{{'USER.PROFILE.PROJECTS_TAB' | translate}}", tab-icon="icon-project") - div(tg-profile-projects, userId="vm.user.get('id')") + div(tg-profile-projects, user="vm.user") div(tg-profile-tab="contacts", tab-title="{{'USER.PROFILE.CONTACTS_TAB' | translate}}", tab-icon="icon-team") - div(tg-profile-contacts, userId="vm.user.get('id')") + div(tg-profile-contacts, user="vm.user") // div(tg-profile-tab="favorites", tab-title="{{'USER.PROFILE.FAVORITES_TAB' | translate}}", tab-icon="icon-star-fill") // include includes/profile-favorites diff --git a/app/modules/profile/profile.scss b/app/modules/profile/profile.scss index 90544bee..c2f9b20d 100644 --- a/app/modules/profile/profile.scss +++ b/app/modules/profile/profile.scss @@ -40,4 +40,16 @@ flex-shrink: 0; width: 150px; } + .empty-tab { + padding: 5vh; + text-align: center; + svg { + margin: 2rem auto; + max-width: 160px; + text-align: center; + } + p { + font-size: .9rem; + } + } } diff --git a/app/modules/projects/project/project.jade b/app/modules/projects/project/project.jade index d95248cd..e99fb1ec 100644 --- a/app/modules/projects/project/project.jade +++ b/app/modules/projects/project/project.jade @@ -14,7 +14,7 @@ div.wrapper div.project-data section.timeline(ng-if="vm.project") - div(tg-user-timeline, projectId="vm.project.get('id')", userId="vm.user.get('id')") + div(tg-user-timeline, projectId="vm.project.get('id')") section.involved-data h2.title {{"PROJECT.SECTION.TEAM" | translate}} ul.involved-team diff --git a/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee index 2606a3fa..6e28d4ee 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee @@ -43,7 +43,7 @@ class UserTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, ta @._timelineLoaded(newTimelineList) else @userTimelineService - .getTimeline(@.userId, @.page) + .getTimeline(@.user.get("id"), @.page) .then (newTimelineList) => @._timelineLoaded(newTimelineList) diff --git a/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee index 6c5ec00e..3db1dea3 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee @@ -3,7 +3,7 @@ describe "UserTimelineController", -> mocks = {} - mockUser = {id: 3} + mockUser = Immutable.fromJS({id: 3}) _mockUserTimeline = () -> mocks.userTimelineService = { @@ -49,12 +49,12 @@ describe "UserTimelineController", -> it "the scrollDisabled variable must be true during the timeline load", () -> myCtrl = controller "UserTimeline" - myCtrl.userId = mockUser.id + myCtrl.user = mockUser thenStub = sinon.stub() mocks.userTimelineService.getTimeline = sinon.stub() - .withArgs(mockUser.id, myCtrl.page) + .withArgs(mockUser.get("id"), myCtrl.page) .returns({ then: thenStub }) @@ -73,12 +73,12 @@ describe "UserTimelineController", -> emptyTimelineList = Immutable.fromJS([]) myCtrl = controller "UserTimeline" - myCtrl.userId = mockUser.id + myCtrl.user = mockUser thenStub = sinon.stub() mocks.userTimelineService.getTimeline = sinon.stub() - .withArgs(mockUser.id, myCtrl.page) + .withArgs(mockUser.get("id"), myCtrl.page) .returns({ then: thenStub }) @@ -95,12 +95,12 @@ describe "UserTimelineController", -> it "pagiantion increase one every call to loadTimeline", () -> myCtrl = controller "UserTimeline" - myCtrl.userId = mockUser.id + myCtrl.user = mockUser thenStub = sinon.stub() mocks.userTimelineService.getTimeline = sinon.stub() - .withArgs(mockUser.id, myCtrl.page) + .withArgs(mockUser.get("id"), myCtrl.page) .returns({ then: thenStub }) @@ -115,12 +115,12 @@ describe "UserTimelineController", -> it "timeline items", () -> myCtrl = controller "UserTimeline" - myCtrl.userId = mockUser.id + myCtrl.user = mockUser thenStub = sinon.stub() mocks.userTimelineService.getTimeline = sinon.stub() - .withArgs(mockUser.id, myCtrl.page) + .withArgs(mockUser.get("id"), myCtrl.page) .returns({ then: thenStub }) @@ -133,7 +133,7 @@ describe "UserTimelineController", -> it "project timeline items", () -> myCtrl = controller "UserTimeline" - myCtrl.userId = mockUser.id + myCtrl.user = mockUser myCtrl.projectId = 4 thenStub = sinon.stub() diff --git a/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee b/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee index 9c15161e..45fd46d1 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee @@ -5,7 +5,7 @@ UserTimelineDirective = -> controllerAs: "vm", scope: { projectId: "=projectid", - userId: "=userid" + user: "=" }, bindToController: true }