add broadcasts

This commit is contained in:
Sven Fuchs 2012-10-18 03:53:19 +02:00
parent 03595db5fa
commit 90fb2c3b78
16 changed files with 866 additions and 811 deletions

View File

@ -1,8 +1,38 @@
Travis.FlashController = Ember.ArrayController.extend Travis.FlashController = Ember.ArrayController.extend
broadcastBinding: 'Travis.app.currentUser.broadcasts'
init: -> init: ->
@_super.apply this, arguments @_super.apply this, arguments
@set('content', Ember.A()) @set('content', Ember.A())
pushObjects: (objects) -> broadcasts: (->
Ember.run.later(this, (-> @removeObjects(objects)), 10000) Travis.Broadcast.find() if Travis.app.get('currentUser')
@_super(objects) ).property('Travis.app.currentUser')
broadcastsObserver: (->
if broadcasts = @get('broadcasts')
broadcasts.forEach (msg) => @pushObject(msg.toObject()) unless @isSeenBroadcast(msg)
).observes('broadcasts.length')
loadFlashes: (msgs) ->
for msg in msgs
type = Ember.keys(msg)[0]
msg = { type: type, message: msg[type] }
@pushObject(msg)
Ember.run.later(this, (-> @removeObject(msg)), 15000)
close: (msg) ->
@storeSeenBroadcast(msg) if msg.type == 'broadcast'
@removeObject(msg)
isSeenBroadcast: (msg) ->
msg.get('id') in @seenBroadcasts()
seenBroadcasts: ->
seen = localStorage.getItem('travis.seen_broadcasts')
if seen then JSON.parse(seen) else []
storeSeenBroadcast: (msg) ->
seen = @seenBroadcasts()
seen.push(msg.id)
localStorage.setItem('travis.seen_broadcasts', JSON.stringify(seen))

View File

@ -1,6 +1,7 @@
require 'models/extensions' require 'models/extensions'
require 'models/account' require 'models/account'
require 'models/artifact' require 'models/artifact'
require 'models/broadcast'
require 'models/branch' require 'models/branch'
require 'models/build' require 'models/build'
require 'models/commit' require 'models/commit'

View File

@ -0,0 +1,11 @@
require 'travis/model'
@Travis.Broadcast = Travis.Model.extend
message: DS.attr('string')
toObject: ->
{ type: 'broadcast', id: @get('id'), message: @get('message') }
@Travis.Broadcast.reopenClass
# TODO fix or monkey-patch the adapter's url and key lookup/generation crap
# url: 'users/broadcasts'

View File

@ -3,6 +3,7 @@ require 'models'
@Travis.RestAdapter = DS.RESTAdapter.extend @Travis.RestAdapter = DS.RESTAdapter.extend
mappings: mappings:
broadcasts: Travis.Broadcast
repositories: Travis.Repo repositories: Travis.Repo
repository: Travis.Repo repository: Travis.Repo
repos: Travis.Repo repos: Travis.Repo

View File

@ -1,6 +1,6 @@
{{#each flash in controller}} {{#each flash in controller}}
{{#view Travis.FlashItemView flashBinding="flash"}} {{#view Travis.FlashItemView flashBinding="flash"}}
<p>{{view.message}}</p> <p>{{{flash.message}}}</p>
<a class="close" {{action close target="view"}}></a> <a class="close" {{action close target="view"}}></a>
{{/view}} {{/view}}
{{/each}} {{/each}}

View File

@ -3,8 +3,9 @@
templateName: 'application' templateName: 'application'
classNames: ['application'] classNames: ['application']
popup: (event) -> # popup: (event) ->
console.log event # console.log event
localeDidChange: (-> localeDidChange: (->
if locale = Travis.app.get('auth.user.locale') if locale = Travis.app.get('auth.user.locale')
Travis.setLocale(locale) Travis.setLocale(locale)

View File

@ -6,15 +6,7 @@
FlashItemView: Travis.View.extend FlashItemView: Travis.View.extend
tagName: 'li' tagName: 'li'
classNameBindings: ['type'] classNameBindings: ['flash.type']
type: (->
@get('flash') && Ember.keys(@get('flash'))[0]
).property('flash')
message: (->
@get('flash') && @get('flash')[@get('type')]
).property('flash')
close: (event) -> close: (event) ->
@get('controller').removeObject(@get('flash')) @get('controller').close(@get('flash'))

View File

@ -30,7 +30,7 @@ jQuery.support.cors = true
success = options.success || (->) success = options.success || (->)
options.success = (data) => options.success = (data) =>
Travis.app.router.flashController.pushObjects(data.flash) if Travis.app?.router && data.flash Travis.app.router.flashController.loadFlashes(data.flash) if Travis.app?.router && data.flash
delete data.flash delete data.flash
success.call(this, data) success.call(this, data)

View File

@ -103,6 +103,11 @@ $color-bg-list-info: $yellow-light-2
$color-text-list-info: $slate-yellow-1 $color-text-list-info: $slate-yellow-1
$color-shadow-list-info: $slate-yellow-2 $color-shadow-list-info: $slate-yellow-2
$color-bg-flash-success: #ebfcc2
$color-bg-flash-notice: lightGoldenrodYellow
$color-bg-flash-error: #f5d7d3
$color-bg-flash-broadcast: #efefef
#colors #colors
.black .black

View File

@ -11,14 +11,20 @@
@include box-shadow(transparent 0 0 0 0, $color-border-normal 0 1px 6px 0, transparent 0 0 0 0, transparent 0 0 0 0) @include box-shadow(transparent 0 0 0 0, $color-border-normal 0 1px 6px 0, transparent 0 0 0 0, transparent 0 0 0 0)
border-bottom: 1px solid $color-border-light border-bottom: 1px solid $color-border-light
a
text-decoration: underline
.success .success
background-color: #ebfcc2 background-color: $color-bg-flash-success
.notice .notice
background-color: lightGoldenrodYellow background-color: $color-bg-flash-notice
.error .error
background-color: #f5d7d3 background-color: $color-bg-flash-error
.broadcast
background-color: $color-bg-flash-broadcast
p p
margin: 0 margin: 0

View File

@ -94,8 +94,8 @@ class Travis::Web::App
end end
def set_config(string) def set_config(string)
string.gsub! %r(<meta (rel|name)="(travis\.[^"]*)" (href|value)="([^"]*)"[^>]*>) do string.gsub! %r(<meta (rel|name)="travis\.([^"]*)" (href|value)="([^"]*)"[^>]*>) do
%(<meta #{$1}="#{$2}" #{$3}="#{options[$2.to_sym] || $4}">) %(<meta #{$1}="travis.#{$2}" #{$3}="#{options[$2.to_sym] || $4}">)
end end
string.gsub! %r{(src|href)="(\/?)((styles|scripts)\/[^"]*)"} do string.gsub! %r{(src|href)="(\/?)((styles|scripts)\/[^"]*)"} do
@ -113,4 +113,4 @@ class Travis::Web::App
builder.run router builder.run router
builder builder
end end
end end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
6d938637 63abb082

View File

@ -4,5 +4,5 @@ cd "$(dirname "$0")/.."
[ $RACK_ENV ] || RACK_ENV=development [ $RACK_ENV ] || RACK_ENV=development
cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn -p $PORT -c ./config/unicorn.rb" cmd="ruby -I lib -S bundle exec ruby -I lib -S unicorn -p $PORT -c ./config/unicorn.rb"
[[ $RACK_ENV == "development" ]] && exec rerun "$cmd -o 127.0.0.1" [[ $RACK_ENV == "development" ]] && exec rerun "$cmd -o 127.0.0.1" -p '{lib,public}/**/*'
exec $cmd exec $cmd