rename profile-timeline to user-timeline
parent
280a209008
commit
b6d04a70b7
|
@ -392,9 +392,11 @@ modules = [
|
|||
"taigaPlugins",
|
||||
"taigaIntegrations",
|
||||
"taigaComponents",
|
||||
# new modules
|
||||
"taigaProfile",
|
||||
"taigaHome",
|
||||
"taigaPage",
|
||||
"taigaUserTimeline",
|
||||
|
||||
# template cache
|
||||
"templates",
|
||||
|
|
|
@ -195,7 +195,6 @@ module.run([
|
|||
"$tgWebhooksResourcesProvider",
|
||||
"$tgWebhookLogsResourcesProvider",
|
||||
"$tgLocalesResourcesProvider",
|
||||
"$tgTimelineResourcesProvider",
|
||||
"$tgUsersResourcesProvider",
|
||||
initResources
|
||||
])
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
###
|
||||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino Garcia <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 David Barragán Merino <bameda@dbarragan.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# 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])
|
|
@ -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)
|
|
@ -1,9 +0,0 @@
|
|||
ProfileTimelineDirective = ->
|
||||
return {
|
||||
templateUrl: "profile/profile-timeline/profile-timeline.html",
|
||||
controller: "ProfileTimeline",
|
||||
controllerAs: "vm",
|
||||
scope: {}
|
||||
}
|
||||
|
||||
angular.module("taigaProfile").directive("tgProfileTimeline", ProfileTimelineDirective)
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -1,7 +1,7 @@
|
|||
describe "profileTimelineAttachmentDirective", () ->
|
||||
describe "userTimelineAttachmentDirective", () ->
|
||||
element = scope = compile = provide = null
|
||||
mockTgTemplate = null
|
||||
template = "<div tg-profile-timeline-attachment='attachment'></div>"
|
||||
template = "<div tg-user-timeline-attachment='attachment'></div>"
|
||||
|
||||
_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("<div id='image'></div>")
|
||||
|
||||
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("<div id='file'></div>")
|
||||
|
||||
elm = createDirective()
|
|
@ -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)
|
|
@ -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", () ->
|
|
@ -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)
|
|
@ -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", () ->
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
@ -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")
|
|
@ -0,0 +1 @@
|
|||
angular.module("taigaUserTimeline", [])
|
|
@ -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)
|
|
@ -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
|
||||
|
|
@ -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)
|
|
@ -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")
|
|
@ -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)
|
|
@ -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()
|
||||
|
Loading…
Reference in New Issue