-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lists channels and activities on the index page
Signed-off-by: Akash Manohar J <[email protected]>
- Loading branch information
Showing
21 changed files
with
167 additions
and
6 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
app/assets/javascripts/ember/controllers/activities_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Kandan.ActivitiesController = Ember.ResourceController.create({ | ||
resourceType: Kandan.Activity | ||
|
||
_resourceUrl: ()-> | ||
"/channels/#{@get('channel').get('id')}/activities" | ||
}) |
9 changes: 8 additions & 1 deletion
9
app/assets/javascripts/ember/controllers/channels_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
Kandan.ChannelsController = Ember.ResourceController.create | ||
Kandan.ChannelsController = Ember.ResourceController.create({ | ||
resourceType: Kandan.Channel | ||
|
||
|
||
# load: (json)-> | ||
# console.log "activity loads..." | ||
# console.log json | ||
# @_super(json) | ||
}) |
2 changes: 2 additions & 0 deletions
2
app/assets/javascripts/ember/controllers/users_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Kandan.UsersController = Ember.ResourceController.create | ||
resourceType: Kandan.User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Kandan.Activity = Ember.Resource.extend | ||
resourceName: 'activity' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Kandan.Channel extends Ember.Resource | ||
Kandan.Channel = Ember.Resource.extend | ||
resourceUrl: '/channels' | ||
resourceName: 'channel' |
4 changes: 4 additions & 0 deletions
4
app/assets/javascripts/ember/templates/activities/list_activities.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
List activitiy boxes for channels here | ||
{{#each channels}} | ||
{{view Kandan.ListChannelActivitiesView channelBinding="this"}} | ||
{{/each}} |
4 changes: 4 additions & 0 deletions
4
app/assets/javascripts/ember/templates/activities/list_channel_activities.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CHANNEL: {{channel.name}} | ||
{{#each channel.activities}} | ||
{{view Kandan.ShowActivityView activityBinding="this"}} | ||
{{/each}} |
1 change: 1 addition & 0 deletions
1
app/assets/javascripts/ember/templates/activities/show.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
USER:{{activity.user.id}} {{activity.id}} - {{activity.content}} |
4 changes: 4 additions & 0 deletions
4
app/assets/javascripts/ember/views/activities/list_activities.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Kandan.ListActivitiesView = Ember.View.extend({ | ||
templateName: 'ember/templates/activities/list_activities' | ||
channelsBinding: 'Kandan.ChannelsController' | ||
}) |
7 changes: 7 additions & 0 deletions
7
app/assets/javascripts/ember/views/activities/list_channel_activities.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Kandan.ListChannelActivitiesView = Ember.View.extend({ | ||
templateName: 'ember/templates/activities/list_channel_activities' | ||
channelBinding: 'Kandan.ChannelsController' | ||
activitiesBinding: 'Kandan.ActivitiesController' | ||
# userBinding: 'Kandan.UsersController' | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Kandan.ShowActivityView = Ember.View.extend({ | ||
templateName: 'ember/templates/activities/show' | ||
className: ['activity'] | ||
tagName: 'div' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class ActivitiesController < ApplicationController | ||
before_filter :authenticate_user! | ||
|
||
def index | ||
@activities = Channel.find(params[:channel_id]).activities.includes(:user).all | ||
respond_to do |format| | ||
format.json { render :json => @activities, :include => :user } | ||
end | ||
end | ||
|
||
def create | ||
@activity = Channel.find(params[:channel_id]).activities.build(params[:activity]) | ||
if @activity.save | ||
respond_to do |format| | ||
format.json { render :json => @activity, :status => :created } | ||
end | ||
else | ||
respond_to do |format| | ||
format.json { render :json => @activity.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def show | ||
@activity = Activity.find params[:id] | ||
respond_to do |format| | ||
format.json { render :json => @activity } | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class ChannelsController < ApplicationController | ||
before_filter :authenticate_user! | ||
|
||
def index | ||
@channels = Channel.includes(:activities => :user).all | ||
respond_to do |format| | ||
format.json do | ||
render :json => @channels, :include => {:activities => {:include=>:user}} | ||
end | ||
end | ||
end | ||
|
||
def create | ||
@channel = Channel.new(params[:channel]) | ||
if @channel.save | ||
respond_to do |format| | ||
format.json { render :json => @channel, :status => :created } | ||
end | ||
else | ||
respond_to do |format| | ||
format.json { render :json => @channel.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def show | ||
@channel = Channel.find params[:id] | ||
respond_to do |format| | ||
format.json { render :json => @channel } | ||
end | ||
end | ||
|
||
def update | ||
@channel = Channel.find(params[:id]) | ||
if @channel.update_attributes(params[:channel]) | ||
respond_to do |format| | ||
format.json { render :json => @channel, :status => :ok } | ||
end | ||
else | ||
respond_to do |format| | ||
format.json { render :json => @channel.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@channel = Channel.find params[:id] | ||
@channel.destroy if not @channel.id == 1 | ||
respond_to do |format| | ||
format.json { render :json => nil, :status => :ok} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class ActivityObserver < ActiveRecord::Observer | ||
|
||
def after_save(activity) | ||
Kandan::Config.broadcaster.broadcast(activity.attributes) | ||
faye_channel = "/channels/#{activity.channel.to_param}/messages" | ||
Kandan::Config.broadcaster.broadcast(faye_channel, activity.attributes) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "spec_helper" | ||
|
||
describe ChannelsController do | ||
describe "GET index" do | ||
it "should return list of channels in JSON" do | ||
get :index | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Factory.define do | ||
factory :channel do |f| | ||
f.name "Test Channel" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe ActivityObserver do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |