Skip to content

Commit

Permalink
Merge pull request #144 from rapidpro/render_urns_on_fwds
Browse files Browse the repository at this point in the history
Render URNs on forwards in Sent messages folder
  • Loading branch information
rowanseymour committed Aug 31, 2016
2 parents 1a37f3c + 6c3428a commit 465d568
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
35 changes: 35 additions & 0 deletions karma/test-directives.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,41 @@ describe('directives:', () ->
)
)

#=======================================================================
# Tests for URN
#=======================================================================
describe('cpUrn', () ->
it('formats a URN as a link', () ->
$scope = $rootScope.$new()
$scope.urn = 'tel:+11234567890'

el = $compile('<cp-urn urn="urn" />')($scope)[0]
$rootScope.$digest()

link = el.querySelector('a')
expect(link.href).toEqual('tel:+11234567890')
expect(link.textContent).toEqual('+11234567890')

$scope.urn = 'twitter:bobby'

el = $compile('<cp-urn urn="urn" />')($scope)[0]
$rootScope.$digest()

link = el.querySelector('a')
expect(link.href).toEqual('https://twitter.com/bobby')
expect(link.textContent).toEqual('bobby')

$scope.urn = 'mailto:jim@unicef.org'

el = $compile('<cp-urn urn="urn" />')($scope)[0]
$rootScope.$digest()

link = el.querySelector('a')
expect(link.href).toEqual('mailto:jim@unicef.org')
expect(link.textContent).toEqual('jim@unicef.org')
)
)

#=======================================================================
# Tests for cpAlert
#=======================================================================
Expand Down
32 changes: 26 additions & 6 deletions static/coffee/directives.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ directives.directive('cpAlerts', -> {
})


#=====================================================================
#----------------------------------------------------------------------------
# Pod directive
#=====================================================================
#----------------------------------------------------------------------------
directives.directive('cpPod', -> {
templateUrl: -> '/sitestatic/templates/pod.html'
})

#=====================================================================
# Tooltip directive
# Shows 'displayText' with a tooltip at 'position' containing 'tooltipText'
#=====================================================================
#----------------------------------------------------------------------------
# Date formatter
#----------------------------------------------------------------------------
directives.directive('cpDate', () ->
return {
restrict: 'E',
Expand All @@ -89,3 +88,24 @@ directives.directive('cpDate', () ->
$scope.tooltipPosition = "top-right";
}
)

#----------------------------------------------------------------------------
# URN as link renderer
#----------------------------------------------------------------------------
directives.directive('cpUrn', () ->
return {
restrict: 'E',
scope: {urn: '='},
template: '<a href="[[ link ]]">[[ path ]]</a>',
controller: ['$scope', ($scope) ->
parts = $scope.urn.split(':')
$scope.scheme = parts[0]
$scope.path = parts[1]

if $scope.scheme == 'twitter'
$scope.link = 'https://twitter.com/' + $scope.path
else
$scope.link = $scope.urn
]
}
)
5 changes: 2 additions & 3 deletions templates/cases/inbox_outgoing.haml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
%span{ ng-if:"item.contact" }
%a{ ng-click:"activateContact(item.contact)", style:"white-space: nowrap;" }><
<cp-contact contact="item.contact" fields="fields">
%span{ ng-if:"item.urns.length" }
<ng-pluralize count="item.urns.length" when="{'one': '1 recipient', 'other': '{} recipients'}">
</ng-pluralize>
%span{ ng-if:"item.urn" }
<cp-urn urn="item.urn" />

.message-text
%span.label-container{ ng-if:"item.case" }
Expand Down

0 comments on commit 465d568

Please sign in to comment.