diff --git a/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee index 08a57487..c1e9cde6 100644 --- a/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee +++ b/app/modules/user-timeline/user-timeline-item/user-timeline-item.controller.coffee @@ -6,6 +6,7 @@ class UserTimelineItemController constructor: (@userTimelineItemType, @userTimelineItemTitle) -> timeline = @.timeline.toJS() + event = @.parseEventType(timeline.event_type) type = @userTimelineItemType.getType(timeline, event) diff --git a/app/modules/user-timeline/user-timeline/user-timeline.service.coffee b/app/modules/user-timeline/user-timeline/user-timeline.service.coffee index 2672c735..93841005 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.service.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.service.coffee @@ -5,6 +5,48 @@ class UserTimelineService extends taiga.Service constructor: (@rs) -> + _invalid: [ + {# Items with only invalid fields + check: (timeline) -> + values_diff = timeline.get("data").get("values_diff") + + if values_diff + values = Object.keys(values_diff.toJS()) + + if values && values.length + if _.every(values, (value) => @._valid_fields.indexOf(value) == -1) + return true + else if values[0] == 'attachments' && + values_diff.get('attachments').get('new').size == 0 + return true + + return false + }, + {# Deleted + check: (timeline) -> + event = timeline.get('event_type').split(".") + return event[2] == 'delete' + }, + {# Project change + check: (timeline) -> + event = timeline.get('event_type').split(".") + return event[1] == 'project' && event[2] == 'change' + }, + {# Comment deleted + check: (timeline) -> + return !!timeline.get("data").get("comment_deleted") + }, + {# Task milestone + check: (timeline) -> + event = timeline.get('event_type').split(".") + + if event[1] == "task" && event[2] == "change" + return timeline.get("data").get("values_diff").get("milestone") + + return false + } + ] + _valid_fields: [ 'status', 'subject', @@ -24,50 +66,26 @@ class UserTimelineService extends taiga.Service 'estimated_start' ] - _isValidField: (values) -> - return _.some values, (value) => @._valid_fields.indexOf(value) != -1 - - _isValidEvent: (event) -> - event = event.split(".") - - return event[2] != 'delete' && !(event[1] == 'project' && event[2] == 'change') - - _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 timeline.get("data").get("comment_deleted") - return false - - if !@._isValidEvent(timeline.get('event_type')) - return false - - return true + _isInValidTimeline: (timeline) -> + return _.some @._invalid, (invalid) => + return invalid.check.call(this, timeline) getProfileTimeline: (userId, page) -> return @rs.users.getProfileTimeline(userId, page) .then (result) => - return result.filter (timeline) => @._filterValidTimelineItems(timeline) + return result.filterNot (timeline) => + return @._isInValidTimeline(timeline) getUserTimeline: (userId, page) -> return @rs.users.getUserTimeline(userId, page) .then (result) => - return result.filter (timeline) => @._filterValidTimelineItems(timeline) + return result.filterNot (timeline) => + return @._isInValidTimeline(timeline) getProjectTimeline: (projectId, page) -> return @rs.projects.getTimeline(projectId, page) .then (result) => - return result.filter (timeline) => @._filterValidTimelineItems(timeline) + return result.filterNot (timeline) => + return @._isInValidTimeline(timeline) angular.module("taigaUserTimeline").service("tgUserTimelineService", UserTimelineService) diff --git a/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee b/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee index 97cb18bd..528ddbac 100644 --- a/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee +++ b/app/modules/user-timeline/user-timeline/user-timeline.service.spec.coffee @@ -122,6 +122,22 @@ describe "tgUserTimelineService", -> "subject": "xx" } } + }, + { # valid item + event_type: "xx.task.change", + data: { + values_diff: { + "name": "xx" + } + } + }, + { # invalid item + event_type: "xx.task.change", + data: { + values_diff: { + "milestone": "xx" + } + } } ] @@ -140,10 +156,11 @@ describe "tgUserTimelineService", -> .then (_items_) -> items = _items_.toJS() - expect(items).to.have.length(3) + expect(items).to.have.length(4) 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]) + expect(items[3]).to.be.eql(valid_items[9]) done() @@ -164,10 +181,11 @@ describe "tgUserTimelineService", -> .then (_items_) -> items = _items_.toJS() - expect(items).to.have.length(3) + expect(items).to.have.length(4) 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]) + expect(items[3]).to.be.eql(valid_items[9]) done() @@ -188,11 +206,11 @@ describe "tgUserTimelineService", -> .then (_items_) -> items = _items_.toJS() - expect(items).to.have.length(3) + expect(items).to.have.length(4) 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]) - + expect(items[3]).to.be.eql(valid_items[9]) done() $rootScope.$apply()