Skip to content
Browse files

Show messages

  • Loading branch information...
1 parent 24e4b9c commit 0cf5d3119a1cac2da4f69d0d5832a0bb7360d03f @Vanuan Vanuan committed Jul 9, 2014
View
3 chat/app/assets/javascripts/application.js
@@ -15,4 +15,7 @@
//= require lib/underscore
//= require lib/backbone
//= require lib/marionette
+//= require_tree ./modules/config
+//= require ./modules/chat/chat_app
+//= require ./modules/entities/message
//= require_tree ./modules/chat
View
10 chat/app/assets/javascripts/modules/chat/apps/footer/footer_app.js.coffee
@@ -1,10 +0,0 @@
-Chat.module "FooterApp", (FooterApp, App, Backbone, Marionette, $, _) ->
-
- API =
- showFooter: ->
- FooterApp.Show.Controller.showFooter()
-
- FooterApp.on "start", ->
- API.showFooter()
-
-
View
10 chat/app/assets/javascripts/modules/chat/apps/footer/show/show_controller.js.coffee
@@ -1,10 +0,0 @@
-@Chat.module "FooterApp.Show", (Show, App, Backbone, Marionette, $, _) ->
- Show.Controller =
-
- showFooter: ->
- footerView = @getFooterView()
- App.footerRegion.show footerView
-
- getFooterView: ->
- new Show.Footer
-
View
5 chat/app/assets/javascripts/modules/chat/apps/footer/show/show_view.js.coffee
@@ -1,5 +0,0 @@
-Chat.module "FooterApp.Show", (Show, App, Backbone, Marionette, $, _) ->
-
- class Show.Footer extends Marionette.ItemView
- template: "footer/show/templates/show_footer"
- tagName: "li"
View
0 chat/app/assets/javascripts/modules/chat/apps/footer/templates/show.js.eco
No changes.
View
26 chat/app/assets/javascripts/modules/chat/chat_app.js.coffee
@@ -1,18 +1,20 @@
@Chat = do (Backbone, Marionette) ->
- @startWithParent = false
- App = new Marionette.Application
+ @startWithParent = false
+ App = new Marionette.Application
- App.addRegions
- headerRegion: "#header-region"
- mainRegion: "#main-region"
- footerRegion: "#footer-region"
+ App.addRegions
+ headerRegion: "#header-region"
+ mainRegion: "#main-region"
+ inputRegion: "#input-region"
- App.addInitializer ->
- App.module("FooterApp").start()
+ App.addInitializer ->
+ App.execute "input:show"
+ App.execute "messages:show"
- App.on "initialize:after", ->
- if Backbone.history
- Backbone.history.start()
+ App.on "initialize:after", ->
+ if Backbone.history
+ Backbone.history.start()
+
+ App
- App
View
53 chat/app/assets/javascripts/modules/chat/chat_cv.js.coffee
@@ -0,0 +1,53 @@
+@Chat.module "SendMessageApp", (SendMessageApp, App, Backbone, Marionette, $, _) ->
+
+ API =
+ showInput: ->
+ SendMessageApp.Controller.showInput()
+
+ App.commands.setHandler "input:show", ->
+ API.showInput()
+
+ SendMessageApp.Controller =
+
+ showInput: ->
+ inputView = @getInputView()
+ App.inputRegion.show inputView
+
+ getInputView: ->
+ new SendMessageApp.Input
+
+ class SendMessageApp.Input extends Marionette.ItemView
+ template: "chat/templates/show_input"
+ tagName: "form"
+
+
+
+
+
+@Chat.module "ShowMessagesApp", (ShowMessagesApp, App, Backbone, Marionette, $, _) ->
+
+ API =
+ showMessages: ->
+ ShowMessagesApp.Controller.showMessages()
+
+ App.commands.setHandler "messages:show", ->
+ API.showMessages()
+
+
+ ShowMessagesApp.Controller =
+
+ showMessages: ->
+ App.request "chat:messages", (messages) =>
+ mainView = @getMainView(messages)
+ App.mainRegion.show mainView
+
+ getMainView: (messages) ->
+ new ShowMessagesApp.Main
+ collection: messages
+
+
+ class ShowMessagesApp.Message extends Marionette.ItemView
+ template: "chat/templates/message"
+
+ class ShowMessagesApp.Main extends Marionette.CollectionView
+ childView: ShowMessagesApp.Message
View
5 chat/app/assets/javascripts/modules/chat/config/marionette/renderer.js.coffee
@@ -1,5 +0,0 @@
-Backbone.Marionette.Renderer.render = (template, data) ->
- path = JST["chat/apps/" + template]
- unless path
- throw "Template #{template} not found"
- path(data)
View
2 chat/app/assets/javascripts/modules/chat/templates/message.jst.eco
@@ -0,0 +1,2 @@
+<%= @created_at %>
+<%= @body %>
View
2 chat/app/assets/javascripts/modules/chat/templates/show_input.jst.eco
@@ -0,0 +1,2 @@
+<input type="text" />
+<button>Submit</button>
View
18 chat/app/assets/javascripts/modules/entities/message.js.coffee
@@ -0,0 +1,18 @@
+@Chat.module "Entities", (Entities, App, Backbone, Marionette, $, _) ->
+
+ class Entities.Message extends Backbone.Model
+
+ class Entities.MessagesCollection extends Backbone.Collection
+ model: Entities.Message
+ url: "messages"
+
+ API =
+ getMessages: (callback) ->
+ messages = new Entities.MessagesCollection
+ messages.fetch
+ success: ->
+ callback(messages)
+
+
+ App.reqres.setHandler "chat:messages", (callback) ->
+ API.getMessages callback
View
2 chat/app/assets/stylesheets/application.css.scss
@@ -13,3 +13,5 @@
*= require_tree .
*= require_self
*/
+@import "bootstrap";
+
View
7 chat/app/controllers/messages_controller.rb
@@ -0,0 +1,7 @@
+class MessagesController < ApplicationController
+ respond_to :json
+
+ def index
+ @messages = Message.all
+ end
+end
View
2 chat/app/models/message.rb
@@ -0,0 +1,2 @@
+class Message < ActiveRecord::Base
+end
View
4 chat/app/views/application/index.html.erb
@@ -1,9 +1,9 @@
<div id="header-region"></div>
<div id="main-region"></div>
-<div id="footer-region"></div>
+<div id="input-region"></div>
<%= javascript_tag do %>
$(function(){
- Chat.start();
+ Chat.start();
});
<% end %>
View
3 chat/app/views/messages/index.json.rabl
@@ -0,0 +1,3 @@
+collection @messages
+
+attributes :id, :body, :created_at, :updated_at
View
55 chat/config/routes.rb
@@ -3,63 +3,10 @@
get 'sasha/Index'
resources :users
+ resources :messages
get 'admin' => 'admin#index'
get 'chat' => 'chat#index'
root to: 'application#index'
- # The priority is based upon order of creation: first created -> highest priority.
- # See how all your routes lay out with "rake routes".
-
- # You can have the root of your site routed with "root"
- # root 'welcome#index'
-
- # Example of regular route:
- # get 'products/:id' => 'catalog#view'
-
- # Example of named route that can be invoked with purchase_url(id: product.id)
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
- # Example resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Example resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Example resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Example resource route with more complex sub-resources:
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', on: :collection
- # end
- # end
-
- # Example resource route with concerns:
- # concern :toggleable do
- # post 'toggle'
- # end
- # resources :posts, concerns: :toggleable
- # resources :photos, concerns: :toggleable
-
- # Example resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
end
View
9 chat/db/migrate/20140709135917_create_messages.rb
@@ -0,0 +1,9 @@
+class CreateMessages < ActiveRecord::Migration
+ def change
+ create_table :messages do |t|
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
View
8 chat/db/schema.rb
@@ -11,7 +11,13 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20140707141905) do
+ActiveRecord::Schema.define(version: 20140709135917) do
+
+ create_table "messages", force: true do |t|
+ t.text "body"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "users", force: true do |t|
t.string "login"
View
7 chat/test/fixtures/messages.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ body: MyText
+
+two:
+ body: MyText
View
7 chat/test/models/message_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class MessageTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 0cf5d31

Please sign in to comment.
Something went wrong with that request. Please try again.