forked from project-rhex/patient-data-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added notifications and event support
- Loading branch information
Ganley
committed
Mar 1, 2012
1 parent
72a5cbc
commit d504e0a
Showing
27 changed files
with
433 additions
and
78 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
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,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/ |
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,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/ |
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,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 |
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,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
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 | ||
|
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 :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 %> |
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>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 %> |
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>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 %> |
Oops, something went wrong.