diff --git a/.gitignore b/.gitignore index cbaf822..faf4245 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ target/ bower_components/ static/* !static/.keep +!static/images diff --git a/app.py b/app.py index de93762..ea6d0a9 100644 --- a/app.py +++ b/app.py @@ -15,45 +15,61 @@ env.load_path = [ os.path.join(os.path.dirname(__file__), 'bower_components'), ] -bower_files = [ +bower_js = [ 'jquery/dist/jquery.min.js', - # 'angularjs/angular.min.js', + 'bootstrap/dist/js/bootstrap.min.js', + 'underscore/underscore-min.js', ] -receiver_js_files = glob.glob(os.path.join( - os.path.dirname(__file__), 'coffee', 'receiver', '*.coffee')) -sender_js_files = glob.glob(os.path.join( - os.path.dirname(__file__), 'coffee', 'sender', '*.coffee')) -receiver_css_files = glob.glob(os.path.join( - os.path.dirname(__file__), 'sass', 'receiver', '*.scss')) -sender_css_files = glob.glob(os.path.join( - os.path.dirname(__file__), 'sass', 'sender', '*.scss')) +bower_css = [ + 'bootstrap/dist/css/bootstrap.min.css', + 'bootstrap/dist/css/bootstrap-theme.min.css', +] -receiver_js_files = map(lambda x: x[x.find(os.path.sep)+1:], receiver_js_files) -sender_js_files = map(lambda x: x[x.find(os.path.sep)+1:], sender_js_files) -receiver_css_files = map(lambda x: x[x.find(os.path.sep)+1:], receiver_css_files) -sender_css_files = map(lambda x: x[x.find(os.path.sep)+1:], sender_css_files) +receiver_js_files = [os.path.join(dirpath, f) + for dirpath, dirnames, files in os.walk(os.path.join('coffee', 'receiver')) + for f in files if f.endswith('.coffee')] +sender_js_files = [os.path.join(dirpath, f) + for dirpath, dirnames, files in os.walk(os.path.join('coffee', 'sender')) + for f in files if f.endswith('.coffee')] +receiver_css_files = [os.path.join(dirpath, f) + for dirpath, dirnames, files in os.walk(os.path.join('sass', 'receiver')) + for f in files if f.endswith('.scss')] +sender_css_files = [os.path.join(dirpath, f) + for dirpath, dirnames, files in os.walk(os.path.join('sass', 'sender')) + for f in files if f.endswith('.scss')] -receiver_js_bundle = bower_files + \ +receiver_js_files = map( + lambda x: x[x.find(os.path.sep) + 1:], receiver_js_files) +sender_js_files = map(lambda x: x[x.find(os.path.sep) + 1:], sender_js_files) +receiver_css_files = map( + lambda x: x[x.find(os.path.sep) + 1:], receiver_css_files) +sender_css_files = map(lambda x: x[x.find(os.path.sep) + 1:], sender_css_files) + +receiver_js_bundle = bower_js + \ [assets.Bundle(*receiver_js_files, filters='coffeescript', output='receiver.js')] -sender_js_bundle = bower_files + \ +sender_js_bundle = bower_js + \ [assets.Bundle(*sender_js_files, filters='coffeescript', output='sender.js')] +receiver_css_bundle = bower_css + \ + [assets.Bundle(*receiver_css_files, filters='scss', + output='receiver.css')] +sender_css_bundle = bower_css + \ + [assets.Bundle(*sender_css_files, filters='scss', + output='sender.css')] bundles = { 'receiver_js': assets.Bundle(*receiver_js_bundle), 'sender_js': assets.Bundle(*sender_js_bundle), - 'receiver_css': assets.Bundle(*receiver_css_files, - filters='scss', - output='receiver.css'), - 'sender_css': assets.Bundle(*sender_css_files, - filters='scss', - output='sender.css'), + 'receiver_css': assets.Bundle(*receiver_css_bundle), + 'sender_css': assets.Bundle(*sender_css_bundle), } env.register(bundles) +print receiver_js_files + @app.route("/") def index(): diff --git a/coffee/receiver/cast.coffee b/coffee/receiver/cast.coffee index 4b2711d..7d9445b 100644 --- a/coffee/receiver/cast.coffee +++ b/coffee/receiver/cast.coffee @@ -9,6 +9,7 @@ window.addEventListener 'load', -> cast.receiver.logger.setLevelValue 0 window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance() console.log 'Starting Receiver Manager' + window.stateHandler = new StateHandler(new RootState()) # handler for the 'ready' event castReceiverManager.onReady = (event) -> @@ -43,16 +44,12 @@ window.addEventListener 'load', -> # display the message from the sender displayText JSON.stringify(data) - if 'spinWheel' of data - spinWheel(data.spinWheel) + stateHandler.sendMessage(data) + # inform all senders on the CastMessageBus of the incoming message event # sender message listener will be invoked window.messageBus.send event.senderId, event.data - window.spinWheel = (velocity) -> - console.debug 'spinWheel', {wheelSpinning, wheelStopped} - wheel.spin(velocity) - # initialize the CastReceiverManager with an application status message window.castReceiverManager.start statusText: 'Application is starting' console.log 'Receiver Manager started' diff --git a/coffee/receiver/state.coffee b/coffee/receiver/state.coffee new file mode 100644 index 0000000..35c83d1 --- /dev/null +++ b/coffee/receiver/state.coffee @@ -0,0 +1,169 @@ +class StateHandler + constructor: (@current) -> + @initialState = @current + + sendMessage: (message) -> + @current.onMessage(message) + + resetState: -> + @current = @initialState + + setState: (@current) -> + +class StateDefinition + constructor: ({@handler = window.stateHandler} = {}) -> + + onMessage: (message) -> + @handler.resetState() + +class RootState extends StateDefinition + onMessage: (message) -> + if 'spinWheel' of message and not wheelSpinning + wheel.spin(message.spinWheel) + @setMarker(message.spinWheel) + + setMarker: (velocity) -> + y = Math.abs(velocity) / 15 * 100 + $('#marker').css bottom: (y / 2) + 'vh' + style = if 15 > y + 'blue' + else if 15 < y < 50 + 'green' + else if 50 < y < 80 + 'yellow' + else + 'red' + $('#marker-line').removeClass 'blue green yellow red' + $('#marker-line').addClass style + + setTimeout -> + $('#marker-line').removeClass 'blue green yellow red' + $('#marker-line').addClass 'blue' + $('#marker').css bottom: '0vh' + , 4000 + +class DialogState extends StateDefinition + id: null + constructor: ({@content, @size = 'md', @classes, @data} = {}) -> + throw Error "Must provide id in prototype" unless @id? + displayText JSON.stringify {@content, @size, @classes} + super + modal = document.createElement('div') + modal.className = 'modal fade in' + modal.id = @id + modal.setAttribute 'role', 'dialog' + modalDialog = document.createElement('div') + modalDialog.className = "modal-dialog modal-#{@size} #{@classes}" + modalContent = document.createElement('div') + modalContent.className = 'modal-content' + modal.setAttribute 'role', 'document' + modalContent.innerHTML = "

#{@_getContent()}

" + + modalDialog.appendChild(modalContent) + modal.appendChild(modalDialog) + document.body.appendChild(modal) + + @modal = $("##{@id}") + + @modal.modal('show') + + _getContent: -> + @content + + _refreshContent: -> + @modal.find('.modal-content').html @_getContent() + + onMessage: -> + @_closeModal() + super + + _closeModal: -> + @modal.modal('hide') + setTimeout => + @modal.remove() + , 1000 + +class DrinkState extends DialogState + id: 'drink-modal' + +class YouTubeState extends DialogState + id: 'youtube-modal' + constructor: -> + super + @playing = no + + _getContent: -> + """ +