Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
806 additions
and
22 deletions.
There are no files selected for viewing
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,60 @@ | ||
class NotificationsController < ApplicationController | ||
before_filter :authenticate_player!, :load_player | ||
# GET /notifications | ||
# GET /notifications.xml | ||
def index | ||
@notifications = @player.notifications.unread.all | ||
|
||
respond_to do |format| | ||
format.json { render :json => @notifications } | ||
end | ||
end | ||
|
||
# GET /notifications/1 | ||
# GET /notifications/1.xml | ||
def show | ||
@notification = @player.notifications.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.xml { render :xml => @notification } | ||
end | ||
end | ||
|
||
|
||
# PUT /notifications/1 | ||
# PUT /notifications/1.xml | ||
def update | ||
@notification = @player.notifications.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @notification.update_attributes(params[:notification]) | ||
format.html { redirect_to(@notification, :notice => 'Notification was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @notification.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /notifications/1 | ||
# DELETE /notifications/1.xml | ||
def destroy | ||
@notification = @player.notifications.find(params[:id]) | ||
@notification.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(notifications_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
|
||
private | ||
|
||
def load_player | ||
@player = current_player | ||
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,2 @@ | ||
module NotificationsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Notification < ActiveRecord::Base | ||
belongs_to :notification_type | ||
belongs_to :player | ||
|
||
serialize :params | ||
|
||
default_scope includes(:notification_type) | ||
|
||
scope :unread, where(:read => false) | ||
|
||
def type | ||
notification_type.name | ||
end | ||
|
||
def as_json(options = {}) | ||
super(:only => [:id, :created_at, :params, :read], | ||
:methods => [:type]) | ||
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,59 @@ | ||
class NotificationType < ActiveRecord::Base | ||
belongs_to :notification | ||
|
||
scope :named, lambda {|name| where('name = ?', name)} | ||
|
||
|
||
def self.create_all_notification_types | ||
NotificationType.create(:name => "new_player") | ||
NotificationType.create(:name => "new_team") | ||
NotificationType.create(:name => "team_accepted") | ||
NotificationType.create(:name => "new_game") | ||
NotificationType.create(:name => "game_accepted") | ||
NotificationType.create(:name => "new_result") | ||
NotificationType.create(:name => "result_accepted") | ||
end | ||
create_all_notification_types if self.all.blank?; | ||
|
||
|
||
def NotificationType.NEW_PLAYER | ||
{ | ||
:notification_type_id => NotificationType.named("new_player").first.id, | ||
:params => { | ||
:title => "Welcome to Padelotron", | ||
:message => "As your first actions, yo can create a new team, invite friends or check today's games in your area", | ||
:urgent => true | ||
} | ||
} | ||
end | ||
|
||
def NotificationType.NEW_TEAM | ||
{ | ||
:notification_type_id => NotificationType.named("new_team").first.id, | ||
:params => { | ||
:title => "New Team Request", | ||
:message => "You have received an offer to join a team"} | ||
} | ||
end | ||
|
||
def NotificationType.TEAM_ACCEPTED | ||
{ | ||
:notification_type_id => NotificationType.named("team_accepted").first.id, | ||
:params => { | ||
:title => "Team Joined", | ||
:message => "You have joined a new team" | ||
} | ||
} | ||
end | ||
|
||
def NotificationType.NEW_GAME | ||
{ | ||
:notification_type_id => NotificationType.named("new_game").first.id, | ||
:params => { | ||
:title => "Team Joined", | ||
:message => "You have joined a new team" | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= form_for(@notification) do |f| %> | ||
<% if @notification.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@notification.errors.count, "error") %> prohibited this notification from being saved:</h2> | ||
|
||
<ul> | ||
<% @notification.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :player %><br /> | ||
<%= f.text_field :player %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :notification_type %><br /> | ||
<%= f.text_field :notification_type %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :params %><br /> | ||
<%= f.text_area :params %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :read %><br /> | ||
<%= f.check_box :read %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% 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,6 @@ | ||
<h1>Editing notification</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @notification %> | | ||
<%= link_to 'Back', notifications_path %> |
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,29 @@ | ||
<h1>Listing notifications</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Player</th> | ||
<th>Notification type</th> | ||
<th>Params</th> | ||
<th>Read</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @notifications.each do |notification| %> | ||
<tr> | ||
<td><%= notification.player %></td> | ||
<td><%= notification.notification_type %></td> | ||
<td><%= notification.params %></td> | ||
<td><%= notification.read %></td> | ||
<td><%= link_to 'Show', notification %></td> | ||
<td><%= link_to 'Edit', edit_notification_path(notification) %></td> | ||
<td><%= link_to 'Destroy', notification, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Notification', new_notification_path %> |
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 @@ | ||
<h1>New notification</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', notifications_path %> |
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,25 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Player:</b> | ||
<%= @notification.player %> | ||
</p> | ||
|
||
<p> | ||
<b>Notification type:</b> | ||
<%= @notification.notification_type %> | ||
</p> | ||
|
||
<p> | ||
<b>Params:</b> | ||
<%= @notification.params %> | ||
</p> | ||
|
||
<p> | ||
<b>Read:</b> | ||
<%= @notification.read %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_notification_path(@notification) %> | | ||
<%= link_to 'Back', notifications_path %> |
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,13 @@ | ||
class CreateNotificationTypes < ActiveRecord::Migration | ||
def self.up | ||
create_table :notification_types do |t| | ||
t.string :name | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :notification_types | ||
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,16 @@ | ||
class CreateNotifications < ActiveRecord::Migration | ||
def self.up | ||
create_table :notifications do |t| | ||
t.references :player | ||
t.references :notification_type | ||
t.text :params | ||
t.boolean :read, :default => false | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :notifications | ||
end | ||
end |
Oops, something went wrong.