Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: msorokovsky/lohika_ror_lab
base: d6bd8ebce1
...
head fork: msorokovsky/lohika_ror_lab
compare: 0cf5d3119a
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 08, 2014
@Vanuan Vanuan Chat main window 24e4b9c
Commits on Jul 09, 2014
@Vanuan Vanuan Show messages 0cf5d31
View
5 chat/app/assets/javascripts/application.js
@@ -15,4 +15,7 @@
//= require lib/underscore
//= require lib/backbone
//= require lib/marionette
-//= require modules/app
+//= require_tree ./modules/config
+//= require ./modules/chat/chat_app
+//= require ./modules/entities/message
+//= require_tree ./modules/chat
View
0  chat/app/assets/javascripts/modules/app.js.coffee
No changes.
View
20 chat/app/assets/javascripts/modules/chat/chat_app.js.coffee
@@ -0,0 +1,20 @@
+@Chat = do (Backbone, Marionette) ->
+
+ @startWithParent = false
+ App = new Marionette.Application
+
+ App.addRegions
+ headerRegion: "#header-region"
+ mainRegion: "#main-region"
+ inputRegion: "#input-region"
+
+ App.addInitializer ->
+ App.execute "input:show"
+ App.execute "messages:show"
+
+ App.on "initialize:after", ->
+ if Backbone.history
+ Backbone.history.start()
+
+ 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
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
1  chat/app/controllers/application_controller.rb
@@ -4,6 +4,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
-
end
end
View
2  chat/app/controllers/chat_controller.rb
@@ -0,0 +1,2 @@
+class ChatController < ApplicationController
+end
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
8 chat/app/views/application/index.html.erb
@@ -1,5 +1,9 @@
+<div id="header-region"></div>
+<div id="main-region"></div>
+<div id="input-region"></div>
+
<%= javascript_tag do %>
$(function(){
- Chat.start();
+ Chat.start();
});
-<% end %>
+<% end %>
View
3  chat/app/views/messages/index.json.rabl
@@ -0,0 +1,3 @@
+collection @messages
+
+attributes :id, :body, :created_at, :updated_at
View
56 chat/config/routes.rb
@@ -3,62 +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

No commit comments for this range

Something went wrong with that request. Please try again.