Skip to content

Commit

Permalink
added notifications and event support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganley committed Mar 1, 2012
1 parent 72a5cbc commit d504e0a
Show file tree
Hide file tree
Showing 27 changed files with 433 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gem 'devise_oauth2_providable', :git => 'https://github.com/rdingwell/devise_oau
gem 'omniauth'
gem 'omniauth-openid'
gem 'kaminari'

gem "symbolize", :require => "symbolize/mongoid"

group :assets do
gem 'sass-rails', " ~> 3.2.3"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
symbolize (4.2.0)
systemu (2.4.2)
term-ansicolor (1.0.7)
therubyracer (0.9.10)
Expand Down Expand Up @@ -274,6 +275,7 @@ DEPENDENCIES
rails (= 3.2.2.rc1)
ruby-openid!
sass-rails (~> 3.2.3)
symbolize
therubyracer
thin
turn
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/notifications.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/notifications.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the notifications controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
83 changes: 83 additions & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class NotificationsController < ApplicationController
# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.all( conditions: { user: /#{@current_user.email}/i } ).to_a

respond_to do |format|
format.html # index.html.erb
format.json { render json: @notifications }
end
end

# GET /notifications/1
# GET /notifications/1.json
def show
@notification = Notification.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @notification }
end
end

# GET /notifications/new
# GET /notifications/new.json
def new
@notification = Notification.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @notification }
end
end

# GET /notifications/1/edit
def edit
@notification = Notification.find(params[:id])
end

# POST /notifications
# POST /notifications.json
def create
@notification = Notification.new(params[:notification])

respond_to do |format|
if @notification.save
format.html { redirect_to @notification, notice: 'Notification was successfully created.' }
format.json { render json: @notification, status: :created, location: @notification }
else
format.html { render action: "new" }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end

# PUT /notifications/1
# PUT /notifications/1.json
def update
@notification = Notification.find(params[:id])

respond_to do |format|
if @notification.update_attributes(params[:notification])
format.html { redirect_to @notification, notice: 'Notification was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @notification.errors, status: :unprocessable_entity }
end
end
end

# DELETE /notifications/1
# DELETE /notifications/1.json
def destroy
@notification = Notification.find(params[:id])
@notification.destroy

respond_to do |format|
format.html { redirect_to notifications_url }
format.json { head :no_content }
end
end
end
5 changes: 3 additions & 2 deletions app/controllers/notify_configs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class NotifyConfigsController < ApplicationController
# GET /notify_configs
# GET /notify_configs.json
def index
@notify_configs = NotifyConfig.all

puts ".." + @current_user.email + ".."
@notify_configs = NotifyConfig.all( conditions: { user: /#{@current_user.email}/i } ).to_a

respond_to do |format|
format.html # index.html.erb
format.json { render json: @notify_configs }
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module NotificationsHelper
end
27 changes: 27 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Notification
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Symbolize


# email or username etc
field :user, :type => String

# RECORD_UPDATE | CONSULT_REQUEST | CONSULT_COMPLETE
symbolize :action, :in => {
record_update: "Record Update",
consult_request: "Consult Request",
consult_complete: "Consult Complete" }, :scopes => true



field :record_id, :type => String

# UNREAD | READ | DONE
# DONE - user is done with this notification and thus can be cleaned out (deleted)
symbolize :status, :in => {
unread: "Unread",
read: "Read",
done: "Done" }, :scopes => true
end

91 changes: 38 additions & 53 deletions app/models/notify_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,54 @@

class NotifyConfig
include Mongoid::Document
include Mongoid::Symbolize

# email or username etc
field :user, :type => String

# INSTANT | DAILY | WEEKLY
field :interval, :type => String

symbolize :interval, :in => {
instant: "Instant",
daily: "Daily",
weekly: "Weekly"}, :default => :instant, :scopes => true

# RECORD_UPDATE | CONSULT_REQUEST | CONSULT_COMPLETE
field :action, :type => String
symbolize :action, :in => {
record_update: "Record Update",
consult_request: "Consult Request",
consult_complete: "Consult Complete" }, :scopes => true

# one or more of these
# default WEB | EMAIL | TEXT | DIRECT_EMAIL
field :alert_flags, :type => String
end



class NotifyEnum
def NotifyEnum.add_item(key,value)
@hash ||= {}
@hash[key]=value
end

def NotifyEnum.const_missing(key)
@hash[key]
end

def NotifyEnum.each
@hash.each {|key,value| yield(key,value)}
end

def NotifyEnum.items
key_array = []
@hash.each { |key,value|
key_array << key
}
key_array
end

end


class NotifyInterval < NotifyEnum

NotifyInterval.add_item :INSTANT, 1
NotifyInterval.add_item :DAILY , 2
NotifyInterval.add_item :WEEKLY , 3
end


class NotifyAction < NotifyEnum

NotifyAction.add_item :RECORD_UPDATE , 1
NotifyAction.add_item :CONSULT_REQUEST , 2
NotifyAction.add_item :CONSULT_COMPLETE, 3
end

## TODO - note the best implementation of this, good for now
symbolize :alert_out1, :in => {
web: "Web",
email: "Email",
text: "Text",
direct_email: "Direct Email",
none: "None"}, :default => :web, :scopes => true

symbolize :alert_out2, :in => {
web: "Web",
email: "Email",
text: "Text",
direct_email: "Direct Email",
none: "None"}, :default => :none, :scopes => true

symbolize :alert_out3, :in => {
web: "Web",
email: "Email",
text: "Text",
direct_email: "Direct Email",
none: "None"}, :default => :none, :scopes => true

symbolize :alert_out4, :in => {
web: "Web",
email: "Email",
text: "Text",
direct_email: "Direct Email",
none: "None"}, :default => :none, :scopes => true

class AlertFlag < NotifyEnum

AlertFlag.add_item :WEB , 0x1
AlertFlag.add_item :EMAIL , 0x2
AlertFlag.add_item :TEXT , 0x4
AlertFlag.add_item :DIRECT_EMAIL, 0x8
end

4 changes: 2 additions & 2 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<div id="page_header">
<% unless current_user.nil? || current_user.username.nil? %>
<a href="/users/sign_out">Logout</a>
<a href="#">Settings</a>
<a href="/settings">Settings</a>
<a href="/audit_logs">Audit Log</a>
<a href="#">Alerts [1]</a>
<a href="/notifications">Alerts</a>
<% end %>
<span id="logo">REST<span id="sublogo"><B>+</B> Pilot</span></span>
<% unless current_user.nil? || current_user.username.nil? %>
Expand Down
33 changes: 33 additions & 0 deletions app/views/notifications/_form.html.erb
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 :user %>
<%= f.text_field :user, :value => @current_user.email %>
</div>
<div class="field">
<%= f.label :action %>
<%= f.select :action, Notification.get_action_values, :prompt =>'Select...' %><br>
</div>
<div class="field">
<%= f.label :record_id %>
<%= f.text_field :record_id %>
</div>
<div class="field">
<%= f.label :status %>
<%= f.select :status, Notification.get_status_values, :prompt =>'Select...' %><br>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/notifications/edit.html.erb
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 %>
29 changes: 29 additions & 0 deletions app/views/notifications/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h1>Listing notifications</h1>

<table>
<tr>
<th>User</th>
<th>Action</th>
<th>Record</th>
<th>Status</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @notifications.each do |notification| %>
<tr>
<td><%= notification.user %></td>
<td><%= notification.action %></td>
<td><%= notification.record_id %></td>
<td><%= notification.status %></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 %>
5 changes: 5 additions & 0 deletions app/views/notifications/new.html.erb
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 %>
25 changes: 25 additions & 0 deletions app/views/notifications/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p id="notice"><%= notice %></p>

<p>
<b>User:</b>
<%= @notification.user %>
</p>

<p>
<b>Action:</b>
<%= @notification.action %>
</p>

<p>
<b>Record:</b>
<%= @notification.record_id %>
</p>

<p>
<b>Status:</b>
<%= @notification.status %>
</p>


<%= link_to 'Edit', edit_notification_path(@notification) %> |
<%= link_to 'Back', notifications_path %>
Loading

0 comments on commit d504e0a

Please sign in to comment.