diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 748a5b4a..6e83343a 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -392,9 +392,11 @@ modules = [ "taigaPlugins", "taigaIntegrations", "taigaComponents", + # new modules "taigaProfile", "taigaHome", "taigaPage", + "taigaUserTimeline", # template cache "templates", diff --git a/app/coffee/modules/resources.coffee b/app/coffee/modules/resources.coffee index 4631a432..69730a00 100644 --- a/app/coffee/modules/resources.coffee +++ b/app/coffee/modules/resources.coffee @@ -195,7 +195,6 @@ module.run([ "$tgWebhooksResourcesProvider", "$tgWebhookLogsResourcesProvider", "$tgLocalesResourcesProvider", - "$tgTimelineResourcesProvider", "$tgUsersResourcesProvider", initResources ]) diff --git a/app/coffee/modules/resources/timeline.coffee b/app/coffee/modules/resources/timeline.coffee deleted file mode 100644 index 31529120..00000000 --- a/app/coffee/modules/resources/timeline.coffee +++ /dev/null @@ -1,39 +0,0 @@ -### -# 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/timeline.coffee -### - -taiga = @.taiga - -resourceProvider = ($repo) -> - service = {} - - service.profile = (userId, page) -> - params = { - page: page - } - - return $repo.queryOnePaginatedRaw("timeline-profile", userId, params) - - return (instance) -> - instance.timeline = service - - -module = angular.module("taigaResources") -module.factory("$tgTimelineResourcesProvider", ["$tgRepo", resourceProvider]) diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item.directive.coffee b/app/modules/profile/profile-timeline-item/profile-timeline-item.directive.coffee deleted file mode 100644 index d15cf6b9..00000000 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item.directive.coffee +++ /dev/null @@ -1,13 +0,0 @@ -ProfileTimelineItemDirective = () -> - return { - controllerAs: "vm" - controller: "ProfileTimelineItem" - bindToController: true - templateUrl: "profile/profile-timeline-item/profile-timeline-item.html" - scope: { - timeline: "=tgProfileTimelineItem" - } - } - -angular.module("taigaProfile") - .directive("tgProfileTimelineItem", ProfileTimelineItemDirective) diff --git a/app/modules/profile/profile-timeline/profile-timeline.directive.coffee b/app/modules/profile/profile-timeline/profile-timeline.directive.coffee deleted file mode 100644 index ae4ba91d..00000000 --- a/app/modules/profile/profile-timeline/profile-timeline.directive.coffee +++ /dev/null @@ -1,9 +0,0 @@ -ProfileTimelineDirective = -> - return { - templateUrl: "profile/profile-timeline/profile-timeline.html", - controller: "ProfileTimeline", - controllerAs: "vm", - scope: {} - } - -angular.module("taigaProfile").directive("tgProfileTimeline", ProfileTimelineDirective) diff --git a/app/modules/profile/profile-timeline/profile-timeline.service.coffee b/app/modules/profile/profile-timeline/profile-timeline.service.coffee deleted file mode 100644 index b6c99236..00000000 --- a/app/modules/profile/profile-timeline/profile-timeline.service.coffee +++ /dev/null @@ -1,57 +0,0 @@ -taiga = @.taiga - -class ProfileTimelineService extends taiga.Service - @.$inject = ["$tgResources"] - - constructor: (@rs) -> - - _valid_fields: [ - 'status', - 'subject', - 'description', - 'assigned_to', - 'points', - 'severity', - 'priority', - 'type', - 'attachments', - 'milestone', - 'is_blocked', - 'is_iocaine', - 'content_diff', - 'name', - 'estimated_finish', - 'estimated_start' - ] - - _isValidField: (values) -> - return _.some values, (value) => @._valid_fields.indexOf(value) != -1 - - _isValidEvent: (event) -> - return event.split(".").slice(-1)[0] != 'delete' - - _filterValidTimelineItems: (timeline) => - if timeline.data.values_diff - values = Object.keys(timeline.data.values_diff) - - if values && values.length - if !@._isValidField(values) - return false - else if values[0] == 'attachments' && - timeline.data.values_diff.attachments.new.length == 0 - return false - - if !@._isValidEvent(timeline.event_type) - return false - - return true - - getTimeline: (userId, page) -> - return @rs.timeline.profile(userId, page) - .then (result) => - newTimelineList = _.filter result.data, @._filterValidTimelineItems - - return Immutable.fromJS(newTimelineList) - - -angular.module("taigaProjects").service("tgProfileTimelineService", ProfileTimelineService) diff --git a/app/modules/profile/profile.jade b/app/modules/profile/profile.jade index 07059af6..5183265d 100644 --- a/app/modules/profile/profile.jade +++ b/app/modules/profile/profile.jade @@ -4,7 +4,7 @@ div.profile.centered 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-profile-timeline) + div(tg-user-timeline) div(tg-profile-tab="projects", tab-title="{{'USER.PROFILE.PROJECTS_TAB' | translate}}", tab-icon="icon-project") div(tg-profile-projects) diff --git a/app/modules/resources/users-resource.service.coffee b/app/modules/resources/users-resource.service.coffee index 8587e7e1..8badf44f 100644 --- a/app/modules/resources/users-resource.service.coffee +++ b/app/modules/resources/users-resource.service.coffee @@ -37,6 +37,17 @@ Resource = (urlsService, http) -> .then (result) -> return Immutable.fromJS(result.data) + service.getTimeline = (userId, page) -> + params = { + page: page + } + + url = urlsService.resolve("timeline-profile") + url = "#{url}/#{userId}" + + return http.get(url, params).then (result) => + return Immutable.fromJS(result.data) + return () -> return {"users": service} diff --git a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment-image.jade b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment-image.jade similarity index 100% rename from app/modules/profile/profile-timeline-attachment/profile-timeline-attachment-image.jade rename to app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment-image.jade diff --git a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.coffee b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.coffee similarity index 53% rename from app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.coffee rename to app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.coffee index e733a089..10e438a4 100644 --- a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.coffee +++ b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.coffee @@ -1,4 +1,4 @@ -ProfileTimelineAttachmentDirective = (template, $compile) -> +UserTimelineAttachmentDirective = (template, $compile) -> validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"] isImage = (url) -> @@ -11,9 +11,9 @@ ProfileTimelineAttachmentDirective = (template, $compile) -> is_image = isImage(scope.attachment.url) if is_image - templateHtml = template.get("profile/profile-timeline-attachment/profile-timeline-attachment-image.html") + templateHtml = template.get("user-timeline/user-timeline-attachment/user-timeline-attachment-image.html") else - templateHtml = template.get("profile/profile-timeline-attachment/profile-timeline-attachment.html") + templateHtml = template.get("user-timeline/user-timeline-attachment/user-timeline-attachment.html") el.html(templateHtml) $compile(el.contents())(scope) @@ -23,14 +23,14 @@ ProfileTimelineAttachmentDirective = (template, $compile) -> return { link: link scope: { - attachment: "=tgProfileTimelineAttachment" + attachment: "=tgUserTimelineAttachment" } } -ProfileTimelineAttachmentDirective.$inject = [ +UserTimelineAttachmentDirective.$inject = [ "$tgTemplate", "$compile" ] -angular.module("taigaProfile") - .directive("tgProfileTimelineAttachment", ProfileTimelineAttachmentDirective) +angular.module("taigaUserTimeline") + .directive("tgUserTimelineAttachment", UserTimelineAttachmentDirective) diff --git a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.spec.coffee b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.spec.coffee similarity index 76% rename from app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.spec.coffee rename to app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.spec.coffee index c2e24a9d..37a3f927 100644 --- a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.directive.spec.coffee +++ b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.directive.spec.coffee @@ -1,7 +1,7 @@ -describe "profileTimelineAttachmentDirective", () -> +describe "userTimelineAttachmentDirective", () -> element = scope = compile = provide = null mockTgTemplate = null - template = "
" + template = "
" _mockTgTemplate= () -> mockTgTemplate = { @@ -23,7 +23,7 @@ describe "profileTimelineAttachmentDirective", () -> return elm beforeEach -> - module "taigaProfile" + module "taigaUserTimeline" _mocks() @@ -37,7 +37,7 @@ describe "profileTimelineAttachmentDirective", () -> } mockTgTemplate.get - .withArgs("profile/profile-timeline-attachment/profile-timeline-attachment-image.html") + .withArgs("user-timeline/user-timeline-attachment/user-timeline-attachment-image.html") .returns("
") elm = createDirective() @@ -50,7 +50,7 @@ describe "profileTimelineAttachmentDirective", () -> } mockTgTemplate.get - .withArgs("profile/profile-timeline-attachment/profile-timeline-attachment.html") + .withArgs("user-timeline/user-timeline-attachment/user-timeline-attachment.html") .returns("
") elm = createDirective() diff --git a/app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.jade b/app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.jade similarity index 100% rename from app/modules/profile/profile-timeline-attachment/profile-timeline-attachment.jade rename to app/modules/user-timeline/user-timeline-attachment/user-timeline-attachment.jade diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.coffee similarity index 95% rename from app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.coffee index b927fc1b..9de3e72d 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.coffee @@ -1,4 +1,4 @@ -class ProfileTimelineItemTitle +class UserTimelineItemTitle @.$inject = [ "$translate" ] @@ -87,5 +87,5 @@ class ProfileTimelineItemTitle getTitle: (timeline, event, type) -> return @translate.instant(type.key, @._getParams(timeline, event, type)) -angular.module("taigaProfile") - .service("tgProfileTimelineItemTitle", ProfileTimelineItemTitle) +angular.module("taigaUserTimeline") + .service("tgUserTimelineItemTitle", UserTimelineItemTitle) diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.spec.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.spec.coffee similarity index 97% rename from app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.spec.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.spec.coffee index fe9586f8..a28fdcd6 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item-title.service.spec.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item-title.service.spec.coffee @@ -1,4 +1,4 @@ -describe "tgProfileTimelineItemTitle", -> +describe "tgUserTimelineItemTitle", -> mySvc = null mockTranslate = null timeline = event = type = null @@ -20,15 +20,15 @@ describe "tgProfileTimelineItemTitle", -> _mockTranslate() _inject = -> - inject (_tgProfileTimelineItemTitle_) -> - mySvc = _tgProfileTimelineItemTitle_ + inject (_tgUserTimelineItemTitle_) -> + mySvc = _tgUserTimelineItemTitle_ _setup = -> _mocks() _inject() beforeEach -> - module "taigaProfile" + module "taigaUserTimeline" _setup() it "title with username", () -> diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.coffee similarity index 98% rename from app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.coffee index 29987438..ba7f60b3 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.coffee @@ -150,8 +150,8 @@ timelineType = (timeline, event) -> return _.find types, (obj) -> return obj.check(timeline, event, field_name) -class ProfileTimelineType +class UserTimelineType getType: (timeline, event) -> timelineType(timeline, event) -angular.module("taigaProfile") - .service("tgProfileTimelineItemType", ProfileTimelineType) +angular.module("taigaUserTimeline") + .service("tgUserTimelineItemType", UserTimelineType) diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.spec.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.spec.coffee similarity index 74% rename from app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.spec.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.spec.coffee index ecc15084..5198f07c 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item-type.service.spec.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item-type.service.spec.coffee @@ -1,4 +1,4 @@ -describe "tgProfileTimelineItemType", -> +describe "tgUserTimelineItemType", -> mySvc = null _provide = (callback) -> @@ -7,14 +7,14 @@ describe "tgProfileTimelineItemType", -> return null _inject = -> - inject (_tgProfileTimelineItemType_) -> - mySvc = _tgProfileTimelineItemType_ + inject (_tgUserTimelineItemType_) -> + mySvc = _tgUserTimelineItemType_ _setup = -> _inject() beforeEach -> - module "taigaProfile" + module "taigaUserTimeline" _setup() it "get the timeline type", () -> diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item.controller.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee similarity index 70% rename from app/modules/profile/profile-timeline-item/profile-timeline-item.controller.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee index f17bcfeb..8da84bc5 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item.controller.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee @@ -1,21 +1,21 @@ -class ProfileTimelineItemController +class UserTimelineItemController @.$inject = [ "$sce", - "tgProfileTimelineItemType", - "tgProfileTimelineItemTitle" + "tgUserTimelineItemType", + "tgUserTimelineItemTitle" ] - constructor: (@sce, @profileTimelineItemType, @profileTimelineItemTitle) -> + constructor: (@sce, @userTimelineItemType, @userTimelineItemTitle) -> timeline = @.timeline.toJS() event = @.parseEventType(timeline.event_type) - type = @profileTimelineItemType.getType(timeline, event) + type = @userTimelineItemType.getType(timeline, event) @.activity = {} @.activity.user = timeline.data.user @.activity.project = timeline.data.project @.activity.sprint = timeline.data.milestone - @.activity.title = @profileTimelineItemTitle.getTitle(timeline, event, type) + @.activity.title = @userTimelineItemTitle.getTitle(timeline, event, type) @.activity.created_formated = moment(timeline.created).fromNow() @.activity.obj = @.getObject(timeline, event) @@ -41,5 +41,5 @@ class ProfileTimelineItemController if timeline.data[event.obj] return timeline.data[event.obj] -angular.module("taigaProfile") - .controller("ProfileTimelineItem", ProfileTimelineItemController) +angular.module("taigaUserTimeline") + .controller("UserTimelineItem", UserTimelineItemController) diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item.controller.spec.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.spec.coffee similarity index 69% rename from app/modules/profile/profile-timeline-item/profile-timeline-item.controller.spec.coffee rename to app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.spec.coffee index 7b127951..1ef9b7c3 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item.controller.spec.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.spec.coffee @@ -1,12 +1,12 @@ -describe "ProfileTimelineItemController", -> +describe "UserTimelineItemController", -> controller = scope = provide = null timeline = event = null - mockTgProfileTimelineItemType = null - mockTgProfileTimelineItemTitle = null + mockTgUserTimelineItemType = null + mockTgUserTimelineItemTitle = null mockType = null - _mockTgProfileTimelineItemType = () -> - mockTgProfileTimelineItemType = { + _mockTgUserTimelineItemType = () -> + mockTgUserTimelineItemType = { getType: sinon.stub() } @@ -15,24 +15,24 @@ describe "ProfileTimelineItemController", -> member: sinon.stub() } - mockTgProfileTimelineItemType.getType.withArgs(timeline).returns(mockType) + mockTgUserTimelineItemType.getType.withArgs(timeline).returns(mockType) - provide.value "tgProfileTimelineItemType", mockTgProfileTimelineItemType + provide.value "tgUserTimelineItemType", mockTgUserTimelineItemType - _mockTgProfileTimelineItemTitle = () -> - mockTgProfileTimelineItemTitle = { + _mockTgUserTimelineItemTitle = () -> + mockTgUserTimelineItemTitle = { getTitle: sinon.stub() } - mockTgProfileTimelineItemTitle.getTitle.withArgs(timeline, event, mockType).returns("fakeTitle") + mockTgUserTimelineItemTitle.getTitle.withArgs(timeline, event, mockType).returns("fakeTitle") - provide.value "tgProfileTimelineItemTitle", mockTgProfileTimelineItemTitle + provide.value "tgUserTimelineItemTitle", mockTgUserTimelineItemTitle _mocks = () -> module ($provide) -> provide = $provide - _mockTgProfileTimelineItemType() - _mockTgProfileTimelineItemTitle() + _mockTgUserTimelineItemType() + _mockTgUserTimelineItemTitle() return null @@ -61,7 +61,7 @@ describe "ProfileTimelineItemController", -> } beforeEach -> - module "taigaProfile" + module "taigaUserTimeline" _setup() _mocks() @@ -73,7 +73,7 @@ describe "ProfileTimelineItemController", -> timeline = scope.vm.timeline timeline_immutable = Immutable.fromJS(timeline) - myCtrl = controller("ProfileTimelineItem", {$scope: scope}, {timeline: timeline_immutable}) + myCtrl = controller("UserTimelineItem", {$scope: scope}, {timeline: timeline_immutable}) expect(myCtrl.activity.user).to.be.equal(timeline.data.user) expect(myCtrl.activity.project).to.be.equal(timeline.data.project) @@ -97,7 +97,7 @@ describe "ProfileTimelineItemController", -> timeline_immutable = Immutable.fromJS(timeline) - myCtrl = controller("ProfileTimelineItem", {$scope: scope}, {timeline: timeline_immutable}) + myCtrl = controller("UserTimelineItem", {$scope: scope}, {timeline: timeline_immutable}) expect(myCtrl.activity.description).to.be.an('object') # $sce.trustAsHtml expect(myCtrl.activity.member).to.be.equal(member) diff --git a/app/modules/user-timeline/user-timeline-item/user-timeline-item.directive.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item.directive.coffee new file mode 100644 index 00000000..15daf833 --- /dev/null +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item.directive.coffee @@ -0,0 +1,13 @@ +UserTimelineItemDirective = () -> + return { + controllerAs: "vm" + controller: "UserTimelineItem" + bindToController: true + templateUrl: "user-timeline/user-timeline-item/user-timeline-item.html" + scope: { + timeline: "=tgUserTimelineItem" + } + } + +angular.module("taigaUserTimeline") + .directive("tgUserTimelineItem", UserTimelineItemDirective) diff --git a/app/modules/profile/profile-timeline-item/profile-timeline-item.jade b/app/modules/user-timeline/user-timeline-item/user-timeline-item.jade similarity index 94% rename from app/modules/profile/profile-timeline-item/profile-timeline-item.jade rename to app/modules/user-timeline/user-timeline-item/user-timeline-item.jade index 218eaf1e..1d941d60 100644 --- a/app/modules/profile/profile-timeline-item/profile-timeline-item.jade +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item.jade @@ -19,4 +19,4 @@ div.activity-item p {{::vm.activity.member.role.name}} div(ng-repeat="attachment in vm.activity.attachments") - div(tg-profile-timeline-attachment="attachment") + div(tg-user-timeline-attachment="attachment") diff --git a/app/modules/user-timeline/user-timeline.module.coffee b/app/modules/user-timeline/user-timeline.module.coffee new file mode 100644 index 00000000..728a1bbf --- /dev/null +++ b/app/modules/user-timeline/user-timeline.module.coffee @@ -0,0 +1 @@ +angular.module("taigaUserTimeline", []) diff --git a/app/modules/profile/profile-timeline/profile-timeline.controller.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee similarity index 81% rename from app/modules/profile/profile-timeline/profile-timeline.controller.coffee rename to app/modules/user-timeline/user-timeline/user-timeline.controller.coffee index 6b9854da..dffa696d 100644 --- a/app/modules/profile/profile-timeline/profile-timeline.controller.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.coffee @@ -23,13 +23,13 @@ taiga = @.taiga mixOf = @.taiga.mixOf -class ProfileTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.FiltersMixin) +class UserTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.FiltersMixin) @.$inject = [ "$tgAuth", - "tgProfileTimelineService" + "tgUserTimelineService" ] - constructor: (@auth, @profileTimelineService) -> + constructor: (@auth, @userTimelineService) -> @.timelineList = Immutable.List() @.page = 1 @.loadingData = false @@ -39,12 +39,12 @@ class ProfileTimelineController extends mixOf(taiga.Controller, taiga.PageMixin, @.loadingData = true - @profileTimelineService + @userTimelineService .getTimeline(user.id, @.page) .then (newTimelineList) => @.timelineList = @.timelineList.concat(newTimelineList) @.page++ @.loadingData = false -angular.module("taigaProfile") - .controller("ProfileTimeline", ProfileTimelineController) +angular.module("taigaUserTimeline") + .controller("UserTimeline", UserTimelineController) diff --git a/app/modules/profile/profile-timeline/profile-timeline.controller.spec.coffee b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee similarity index 82% rename from app/modules/profile/profile-timeline/profile-timeline.controller.spec.coffee rename to app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee index 954560cb..3979a071 100644 --- a/app/modules/profile/profile-timeline/profile-timeline.controller.spec.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.controller.spec.coffee @@ -1,16 +1,16 @@ -describe "ProfileTimelineController", -> +describe "UserTimelineController", -> myCtrl = scope = $q = provide = null mocks = {} mockUser = {id: 3} - _mockProfileTimeline = () -> - mocks.profileTimelineService = { + _mockUserTimeline = () -> + mocks.userTimelineService = { getTimeline: sinon.stub() } - provide.value "tgProfileTimelineService", mocks.profileTimelineService + provide.value "tgUserTimelineService", mocks.userTimelineService _mockTgAuth = () -> provide.value "$tgAuth", { @@ -21,19 +21,19 @@ describe "ProfileTimelineController", -> _mocks = () -> module ($provide) -> provide = $provide - _mockProfileTimeline() + _mockUserTimeline() _mockTgAuth() return null beforeEach -> - module "taigaProfile" + module "taigaUserTimeline" _mocks() inject ($controller, _$q_) -> $q = _$q_ - myCtrl = $controller "ProfileTimeline" + myCtrl = $controller "UserTimeline" it "timelineList should be an array", () -> expect(myCtrl.timelineList.toJS()).is.an("array") @@ -54,14 +54,12 @@ describe "ProfileTimelineController", -> thenStub = sinon.stub() - profileStub = sinon.stub() + mocks.userTimelineService.getTimeline = sinon.stub() .withArgs(mockUser.id, myCtrl.page) .returns({ then: thenStub }) - mocks.profileTimelineService.getTimeline = profileStub - it "the loadingData variable must be true during the timeline load", () -> expect(myCtrl.loadingData).to.be.false diff --git a/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee b/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee new file mode 100644 index 00000000..dda6e07a --- /dev/null +++ b/app/modules/user-timeline/user-timeline/user-timeline.directive.coffee @@ -0,0 +1,9 @@ +UserTimelineDirective = -> + return { + templateUrl: "user-timeline/user-timeline/user-timeline.html", + controller: "UserTimeline", + controllerAs: "vm", + scope: {} + } + +angular.module("taigaProfile").directive("tgUserTimeline", UserTimelineDirective) diff --git a/app/modules/profile/profile-timeline/profile-timeline.jade b/app/modules/user-timeline/user-timeline/user-timeline.jade similarity index 61% rename from app/modules/profile/profile-timeline/profile-timeline.jade rename to app/modules/user-timeline/user-timeline/user-timeline.jade index 6901f624..4c57d15a 100644 --- a/app/modules/profile/profile-timeline/profile-timeline.jade +++ b/app/modules/user-timeline/user-timeline/user-timeline.jade @@ -1,3 +1,3 @@ section.profile-timeline div(infinite-scroll="vm.loadTimeline()", infinite-scroll-distance="3", infinite-scroll-disabled="vm.loadingData") - div(tg-repeat="timeline in vm.timelineList", tg-profile-timeline-item="timeline") + div(tg-repeat="timeline in vm.timelineList", tg-user-timeline-item="timeline") diff --git a/app/modules/profile/profile-timeline/profile-timeline.scss b/app/modules/user-timeline/user-timeline/user-timeline.scss similarity index 100% rename from app/modules/profile/profile-timeline/profile-timeline.scss rename to app/modules/user-timeline/user-timeline/user-timeline.scss diff --git a/app/modules/user-timeline/user-timeline/user-timeline.service.coffee b/app/modules/user-timeline/user-timeline/user-timeline.service.coffee new file mode 100644 index 00000000..8c4381e0 --- /dev/null +++ b/app/modules/user-timeline/user-timeline/user-timeline.service.coffee @@ -0,0 +1,58 @@ +taiga = @.taiga + +class UserTimelineService extends taiga.Service + @.$inject = ["tgResources"] + + constructor: (@rs) -> + + _valid_fields: [ + 'status', + 'subject', + 'description', + 'assigned_to', + 'points', + 'severity', + 'priority', + 'type', + 'attachments', + 'milestone', + 'is_blocked', + 'is_iocaine', + 'content_diff', + 'name', + 'estimated_finish', + 'estimated_start' + ] + + _isValidField: (values) -> + return _.some values, (value) => @._valid_fields.indexOf(value) != -1 + + _isValidEvent: (event) -> + return event.split(".").slice(-1)[0] != 'delete' + + _filterValidTimelineItems: (timeline) -> + if timeline.get("data") + values = [] + values_diff = timeline.get("data").get("values_diff") + + if values_diff + values = Object.keys(values_diff.toJS()) + + if values && values.length + if !@._isValidField(values) + return false + else if values[0] == 'attachments' && + values_diff.get('attachments').get('new').size == 0 + return false + + if !@._isValidEvent(timeline.get('event_type')) + return false + + return true + + getTimeline: (userId, page) -> + return @rs.users.getTimeline(userId, page) + .then (result) => + return result.filter (timeline) => @._filterValidTimelineItems(timeline) + +angular.module("taigaUserTimeline").service("tgUserTimelineService", UserTimelineService) diff --git a/app/modules/profile/profile-timeline/profile-timeline.service.spec.coffee b/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee similarity index 79% rename from app/modules/profile/profile-timeline/profile-timeline.service.spec.coffee rename to app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee index 03766f40..9cc2f2c9 100644 --- a/app/modules/profile/profile-timeline/profile-timeline.service.spec.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee @@ -1,18 +1,18 @@ -describe "tgProfileTimelineService", -> +describe "tgUserTimelineService", -> provide = null $q = null $rootScope = null - profileTimelineService = null + userTimelineService = null mocks = {} _mockResources = () -> mocks.resources = {} - mocks.resources.timeline = { - profile: sinon.stub() + mocks.resources.users = { + getTimeline: sinon.stub() } - provide.value "$tgResources", mocks.resources + provide.value "tgResources", mocks.resources _mocks = () -> module ($provide) -> @@ -25,20 +25,19 @@ describe "tgProfileTimelineService", -> _mocks() _inject = (callback) -> - inject (_tgProfileTimelineService_, _$q_, _$rootScope_) -> - profileTimelineService = _tgProfileTimelineService_ + inject (_tgUserTimelineService_, _$q_, _$rootScope_) -> + userTimelineService = _tgUserTimelineService_ $q = _$q_ $rootScope = _$rootScope_ callback() if callback beforeEach -> - module "taigaProjects" + module "taigaUserTimeline" _setup() _inject() it "filter invalid timeline items", (done) -> - valid_items = { - data: [ + valid_items = [ { # valid item event_type: "xx.tt.create", data: { @@ -104,26 +103,25 @@ describe "tgProfileTimelineService", -> } } ] - } userId = 3 page = 2 - mocks.resources.timeline.profile = (_userId_, _page_) -> + mocks.resources.users.getTimeline = (_userId_, _page_) -> expect(_userId_).to.be.equal(userId) expect(_page_).to.be.equal(page) return $q (resolve, reject) -> - resolve(valid_items) + resolve(Immutable.fromJS(valid_items)) - profileTimelineService.getTimeline(userId, page) + userTimelineService.getTimeline(userId, page) .then (_items_) -> items = _items_.toJS() expect(items).to.have.length(3) - expect(items[0]).to.be.eql(valid_items.data[0]) - expect(items[1]).to.be.eql(valid_items.data[3]) - expect(items[2]).to.be.eql(valid_items.data[5]) + expect(items[0]).to.be.eql(valid_items[0]) + expect(items[1]).to.be.eql(valid_items[3]) + expect(items[2]).to.be.eql(valid_items[5]) done()