make seen broadcasts work with localstorage
This commit is contained in:
parent
558f6e64c0
commit
9fa7e408cd
|
@ -17,23 +17,6 @@ Controller = Ember.Controller.extend
|
|||
"#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=48&d=mm"
|
||||
).property('user.gravatarId')
|
||||
|
||||
unseenBroadcasts: (->
|
||||
@get('broadcasts').filter (broadcast) ->
|
||||
!broadcast.get('isSeen')
|
||||
).property('broadcasts.[]', 'broadcasts.length')
|
||||
|
||||
v2broadcasts: (->
|
||||
broadcasts = Ember.ArrayProxy.create(content: [])
|
||||
|
||||
if @get('currentUser.id')
|
||||
@get('store').find('broadcast').then (result) ->
|
||||
broadcasts.pushObjects(result.toArray())
|
||||
|
||||
console.log(broadcasts)
|
||||
|
||||
broadcasts
|
||||
).property('currentUser.id')
|
||||
|
||||
broadcasts: (->
|
||||
|
||||
if @get('auth.signedIn')
|
||||
|
@ -47,14 +30,21 @@ Controller = Ember.Controller.extend
|
|||
options.type = 'GET'
|
||||
options.headers = { Authorization: "token #{@auth.token()}" }
|
||||
|
||||
seenBroadcasts = Travis.storage.getItem('travis.seen_broadcasts')
|
||||
seenBroadcasts = JSON.parse(seenBroadcasts) if seenBroadcasts
|
||||
|
||||
$.ajax("#{apiEndpoint}/v3/broadcasts", options).then (response) ->
|
||||
array = response.broadcasts.filter((broadcast) ->
|
||||
broadcast unless broadcast.expired
|
||||
).map( (broadcast) ->
|
||||
Ember.Object.create(broadcast)
|
||||
).reverse()
|
||||
|
||||
broadcasts.set('lastBroadcastStatus', array[0].category)
|
||||
if response.broadcasts.length
|
||||
array = response.broadcasts.filter((broadcast) ->
|
||||
unless broadcast.expired
|
||||
if seenBroadcasts.indexOf(broadcast.id.toString()) == -1
|
||||
broadcast
|
||||
).map( (broadcast) ->
|
||||
Ember.Object.create(broadcast)
|
||||
).reverse()
|
||||
|
||||
if array.length
|
||||
broadcasts.set('lastBroadcastStatus', array[0].category)
|
||||
broadcasts.set('content', array)
|
||||
broadcasts.set('isLoading', false)
|
||||
|
||||
|
@ -69,6 +59,17 @@ Controller = Ember.Controller.extend
|
|||
toggleBroadcasts: ->
|
||||
@toggleProperty('showBroadcasts')
|
||||
return false
|
||||
|
||||
markBroadcastAsSeen: (broadcast) ->
|
||||
id = broadcast.get('id').toString()
|
||||
seenBroadcasts = Travis.storage.getItem('travis.seen_broadcasts')
|
||||
if seenBroadcasts
|
||||
seenBroadcasts = JSON.parse(seenBroadcasts)
|
||||
else
|
||||
seenBroadcasts = []
|
||||
seenBroadcasts.push(id)
|
||||
Travis.storage.setItem('travis.seen_broadcasts', JSON.stringify(seenBroadcasts))
|
||||
return false
|
||||
}
|
||||
|
||||
showCta: (->
|
||||
|
|
|
@ -54,6 +54,15 @@
|
|||
height: auto
|
||||
transform: translateY(0) scale(1)
|
||||
|
||||
.icon-close
|
||||
display: inline-block
|
||||
width: 1.2em
|
||||
height: 1.2em
|
||||
float: right
|
||||
background:
|
||||
image: inline-image('line-icons/icon-failed.svg')
|
||||
repeat: no-repeat
|
||||
|
||||
@media #{$medium-up}
|
||||
position: absolute
|
||||
top: 3.3em
|
||||
|
|
|
@ -11,13 +11,13 @@
|
|||
</div>
|
||||
<ul class="broadcasts {{if showBroadcasts 'is-open'}}">
|
||||
{{#each broadcasts.content as |broadcast|}}
|
||||
<li><p><span class="broadcast-status {{broadcast.category}}" title="Transmitted on {{broadcast.updated_at}}"></span> {{{broadcast.message}}}</p></li>
|
||||
<li><p><span class="broadcast-status {{broadcast.category}}" title="Transmitted on {{broadcast.updated_at}}"></span> {{{broadcast.message}}} <a {{action 'markBroadcastAsSeen' broadcast}} class="icon-close"></a></p></li>
|
||||
{{else}}
|
||||
<li><p>There are no broadcasts transmitted</p></li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
||||
{{v2broadcasts}}
|
||||
|
||||
<nav id="navigation" class="navigation {{if is-open 'is-open'}}">
|
||||
<ul>
|
||||
<li><a href="http://blog.travis-ci.com" class="navigation-anchor">Blog</a></li>
|
||||
|
|
Loading…
Reference in New Issue
Block a user