Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: mark-d-holmberg/sed
base: f13fa905c3
...
head fork: mark-d-holmberg/sed
compare: 8afaac7d3c
  • 7 commits
  • 27 files changed
  • 0 commit comments
  • 1 contributor
Showing with 234 additions and 111 deletions.
  1. +3 −0  app/assets/javascripts/pages.js.coffee
  2. +3 −0  app/assets/javascripts/users.js.coffee
  3. +1 −1  app/assets/stylesheets/application.css.scss
  4. +1 −1  app/assets/stylesheets/sass_custom.css.scss
  5. +30 −6 app/assets/stylesheets/surveys.css.scss
  6. +1 −1  app/controllers/pages_controller.rb
  7. +27 −12 app/controllers/surveys_controller.rb
  8. +3 −0  app/controllers/take_surveys_controller.rb
  9. +8 −0 app/helpers/surveys_helper.rb
  10. +4 −1 app/models/ability.rb
  11. +2 −1  app/models/question.rb
  12. +9 −0 app/models/response.rb
  13. +19 −1 app/models/survey.rb
  14. +1 −1  app/views/layouts/professors/_professor.html.erb
  15. +11 −1 app/views/layouts/students/_student.html.erb
  16. +8 −6 app/views/shared/user_search/_list_simple.html.erb
  17. +2 −2 app/views/shared/user_search/_listing.html.erb
  18. +18 −7 app/views/surveys/_form.html.erb
  19. +3 −1 app/views/surveys/_question_fields.html.erb
  20. +0 −8 app/views/surveys/index.html.erb
  21. +34 −32 app/views/surveys/report.html.erb
  22. +1 −0  app/views/surveys/report.js.erb
  23. +27 −25 app/views/surveys/show.html.erb
  24. +1 −1  app/views/users/new.js.erb
  25. +6 −0 db/migrate/20120408214556_add_anonymous_to_question.rb
  26. +6 −0 db/migrate/20120409005348_add_anonymous_to_survey.rb
  27. +5 −3 db/schema.rb
3  app/assets/javascripts/pages.js.coffee
View
@@ -9,6 +9,9 @@ jQuery ->
$.ajax
url: "users/" + id + "/",
dataType: "script",
+ $('#user-list-content .pagination a').live 'click', (event) ->
+ $.getScript(this.href);
+ return false;
jQuery ->
$("section#user_flyout").click (event) ->
$("div#user_flyout_menu").show("slide", { direction: "left" }, 1000);
3  app/assets/javascripts/users.js.coffee
View
@@ -12,3 +12,6 @@ jQuery ->
$.get($('#user_search_full').attr('action'),
$('#user_search_full').serialize(), null, 'script')
false
+ $("a.remote").click (event) ->
+ $.getScript(this.href)
+ false
2  app/assets/stylesheets/application.css.scss
View
@@ -17,7 +17,7 @@
* {
margin: 0 auto;
padding: 0em;
- text-align: justify;
+ text-align: left;
font-family: "Arial", "Helvetica", "Sans-Serif";
z-index: -1;
}
2  app/assets/stylesheets/sass_custom.css.scss
View
@@ -51,7 +51,7 @@ $header_3_color: #000000;
$flash_error_alert_bg_color: #fbe3e4;
$flash_error_alert_color: #8a1f11;
$flash_error_alert_border_color: #fbc2c4;
-$flash_notice_bg_color: #99CC00;
+$flash_notice_bg_color: #fff6bf;
$flash_notice_color: #514721;
$flash_notice_border_color: #ffd324;
$flash_success_bg_color: #FFFF66;
36 app/assets/stylesheets/surveys.css.scss
View
@@ -26,17 +26,17 @@ table {
&#show_survey {
th, td {
padding: 2em;
+ margin-left: 2em;
}
- }
-}
-nav {
- &#user_sort_links {
- ul {
+ ul, ol {
+ margin-left: 2em;
li {
- padding: 0.2em 0.2em 0.2em 0.2em;
+ padding: 0.2em;
}
}
}
+}
+nav {
&#survey_links_nav {
@include rounded-corners(10px);
border: 1px solid darken($nav_color_bg, 10%);
@@ -46,3 +46,27 @@ nav {
padding-top: 0.4em;
}
}
+p {
+ &.add_answer {
+ margin-top: 1em;
+ margin-bottom: 1em;
+ }
+ textarea {
+ margin-top: 1em;
+ margin-bottom: 0.2em;
+ }
+}
+div {
+ &.field, &.fields {
+ margin: 0.3em;
+ }
+ &.anonymous {
+ margin-top: 1em;
+ }
+ &#survey_report_result {
+ padding: 0.5em;
+ border: 1px solid black;
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+}
2  app/controllers/pages_controller.rb
View
@@ -2,7 +2,7 @@ class PagesController < ApplicationController
before_filter :authorize, :only => [:home]
def home
@students = User.search(params[:search], params[:page], 20).order("name ASC")
- authorize! :list, :students
+ @surveys = Survey.published
respond_to do |format|
format.html # pages.html.erb
format.js
39 app/controllers/surveys_controller.rb
View
@@ -1,17 +1,15 @@
class SurveysController < ApplicationController
-#before_filter :authorize
+ require 'csv'
load_and_authorize_resource
+
def index
-#@surveys = Survey.all
end
def show
-#@survey = Survey.find(params[:id])
end
#SPEC: 2.2.2: Adding a new Survey(form)
def new
-#@survey = Survey.new
3.times do
question = @survey.questions.build
4.times { question.answers.build }
@@ -20,10 +18,6 @@ def new
#SPEC: 2.2.5: Create a new Survey(form)
def create
-#@survey = Survey.new(params[:survey])
- if params[:available_at_pretty]
- flash.alert = "available at pretty found"
- end
if @survey.save
redirect_to @survey, :notice => "Successfully created survey."
else
@@ -33,14 +27,12 @@ def create
#SPEC: 2.2.4: Edit an existing Survey(form)
def edit
-#@survey = Survey.find(params[:id])
end
#SPEC: 2.2.7: Update the DB with the new Survey(form)
def update
-#@survey = Survey.find(params[:id])
if @survey.update_attributes(params[:survey])
- redirect_to @survey, :notice => "Successfully updated survey."
+ redirect_to @survey
else
render :action => 'edit'
end
@@ -49,7 +41,6 @@ def update
#SPEC: 2.2.3: Removing an existing Survey(form)
#SPEC: 2.2.9: Destroy an existing Survey(form)
def destroy
-#@survey = Survey.find(params[:id])
@survey.destroy
redirect_to surveys_url, :notice => "Successfully destroyed survey."
end
@@ -57,5 +48,29 @@ def destroy
#SPEC: 7.2.1: View the Report on a specified survey
def report
@survey = Survey.find(params[:id])
+ respond_to do |format|
+ format.html
+ format.csv do
+ csv_string = CSV.generate do |csv|
+ @survey.questions.each do |question|
+ # header row
+ csv << ["question", "question_id"]
+
+ # data rows
+ csv << [question.content, question.id]
+ question.answers.each do |answer|
+ # header row
+ csv << ["answer", "answer_id", "responses_total"]
+ # data rows
+ csv << [answer.content, answer.id, Response.answers_total_count(answer.id)]
+ end
+ end
+ end
+ # send it to the browser
+ send_data csv_string,
+ :type => 'text/csv; charset=iso-8859-1; header=present',
+ :disposition => "attachment; filename=report.csv"
+ end
+ end
end
end
3  app/controllers/take_surveys_controller.rb
View
@@ -4,6 +4,9 @@ class TakeSurveysController < ApplicationController
def new
@survey = Survey.find(params[:id]) if params[:id]
authorize! :take, :survey
+ respond_to do |format|
+ format.html
+ end
end
#SPEC: 7.1.1.2: Adding Create action
8 app/helpers/surveys_helper.rb
View
@@ -11,4 +11,12 @@ def date_pretty_mst(date)
def date_time_pretty_mst(date)
"#{date.localtime.strftime("%d %B %Y at %I:%M:%S %p")} MST"
end
+
+ def answers_total_count(answer_id)
+ @count = Response.answers_total_count(answer_id)
+ end
+
+ def who_answered_me(answer_id)
+ @who = Response.who_answered_me(answer_id).join(", ")
+ end
end
5 app/models/ability.rb
View
@@ -11,9 +11,12 @@ def initialize(user)
can :edit_password, User, :id => user.id
can :update_password, User, :id => user.id
can :index, Response, :user_id => user.id
+ can :take, :survey
+ can :create, :survey
+ can :show, :survey
cannot :assign_roles, User
cannot :destroy, User
- can :list, :students
+ cannot :list, :students
elsif user.role? :advisor
can [:read, :show, :edit, :update], User, :id => user.id, :roles_mask => user.roles_mask
cannot :destroy, User, :id => user.id, :roles_mask => user.roles_mask
3  app/models/question.rb
View
@@ -7,10 +7,11 @@
# content :text
# created_at :datetime not null
# updated_at :datetime not null
+# anonymous :boolean(1) default(FALSE)
#
class Question < ActiveRecord::Base
- attr_accessible :content, :answers_attributes
+ attr_accessible :content, :answers_attributes, :anonymous
belongs_to :survey
has_many :answers, :dependent => :destroy
9 app/models/response.rb
View
@@ -23,4 +23,13 @@ class Response < ActiveRecord::Base
# (something of the form validates_uniquness of
# http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000086
validates_uniqueness_of :question_id, :scope => [:user_id], :message => "You have already answered that question!"
+
+ private
+ def self.who_answered_me(answer_id_in)
+ Response.where(:answer_id => answer_id_in).map(&:user).map(&:name)
+ end
+
+ def self.answers_total_count(answer_id_in)
+ where(:answer_id => answer_id_in).count
+ end
end
20 app/models/survey.rb
View
@@ -8,10 +8,12 @@
# updated_at :datetime not null
# published :boolean(1) default(FALSE)
# available_at :datetime
+# anonymous :boolean(1) default(FALSE)
#
class Survey < ActiveRecord::Base
- attr_accessible :name, :published, :available_at, :questions_attributes
+ after_save :check_anonymous
+ attr_accessible :name, :published, :available_at, :questions_attributes, :anonymous
has_many :questions, :dependent => :destroy
accepts_nested_attributes_for :questions,
:reject_if => lambda { |q| q[:content].blank? },
@@ -28,4 +30,20 @@ class Survey < ActiveRecord::Base
def my_questions
self.questions.map(&:id)
end
+
+ def my_anonymous_questions
+ questions.where(:anonymous => true)
+ end
+
+ def my_public_questions
+ questions.where(:anonymous => false)
+ end
+
+ def check_anonymous
+ if anonymous == true
+ questions.each { |question| question.update_attributes(:anonymous => true) }
+ else
+ questions.each { |question| question.update_attributes(:anonymous => false) }
+ end
+ end
end
2  app/views/layouts/professors/_professor.html.erb
View
@@ -1 +1 @@
-professors
+<%= render "shared/user_search/listing" %>
12 app/views/layouts/students/_student.html.erb
View
@@ -1,3 +1,13 @@
<section>
- student
+ <% @surveys.each do |survey| %>
+ <div class="field">
+ <%= survey.name %>
+ <% unless survey_completed?(current_user, survey) %>
+ <%= link_to "Take", new_take_surveys_path(survey.id) %>
+ <% else %>
+ Completed.
+ <% end %>
+ <%= link_to "Show", take_survey_path(survey.id) %>
+ </div>
+ <% end %>
</section>
14 app/views/shared/user_search/_list_simple.html.erb
View
@@ -1,9 +1,11 @@
-<%= will_paginate @students, :previous_label => "<<", :next_label => ">>" %>
-<%= content_tag(:ol, :id => "selectable") do %>
- <% @students.each do |student| %>
- <%= content_tag(:li, :class => "ui-widget-content") do %>
- <%= student.name %>
- <%= hidden_field_tag :user_id, student.id %>
+<% if can? :list, :students %>
+ <%= will_paginate @students, :previous_label => "<<", :next_label => ">>" %>
+ <%= content_tag(:ol, :id => "selectable") do %>
+ <% @students.each do |student| %>
+ <%= content_tag(:li, :class => "ui-widget-content") do %>
+ <%= student.name %>
+ <%= hidden_field_tag :user_id, student.id %>
+ <% end %>
<% end %>
<% end %>
<% end %>
4 app/views/shared/user_search/_listing.html.erb
View
@@ -12,8 +12,8 @@
<section id="user_flyout">
<div id="user_flyout_menu">
<ul>
- <li>New</li>
- <li>Search</li>
+ <li><%= link_to new_user_path, :remote =>true, :class => :remote do %>New<% end %></li>
+ <li><%= link_to "Search", user_search_path %></li>
<li class="hide"><<</li>
</ul>
</div>
25 app/views/surveys/_form.html.erb
View
@@ -2,22 +2,32 @@
<%= render "shared/error_messages", :target => @survey %>
<div class="field">
<%= f.label :name %><br />
- <%= f.text_field :name %><br />
+ <%= f.text_field :name %>
</div>
+
<div class="field">
- <%= f.label :publish %><br />
+ <%= f.label :publish, "Publish?" %>
Yes <%= f.radio_button :published, true %>
- No <%= f.radio_button :published, false %><br />
+ No <%= f.radio_button :published, false %>
</div>
+
<div class="field">
- <%= f.label :available_at, "Available On" %>
+ <%= f.label :available_at, "Available On" %><br />
<%= f.datetime_select :available_at, :ampm => true %>
</div>
+
+ <div class="field anonymous">
+ Make Survey Anonymous?<br />
+ Yes: <%= f.radio_button :anonymous, true %>
+ No: <%= f.radio_button :anonymous, false %>
+ </div>
+
<div class="field">
- <%= f.fields_for :questions do |builder| %>
- <%= render 'question_fields', :f => builder %>
- <% end %>
+ <%= f.fields_for :questions do |builder| %>
+ <%= render 'question_fields', :f => builder %>
+ <% end %>
</div>
+
<div class="actions">
<p>
<% #SPEC: 2.2.10 : Adding a new questions to a Survey(form) %>
@@ -25,4 +35,5 @@
</p>
<%= f.submit "Submit" %>
</div>
+
<% end %>
4 app/views/surveys/_question_fields.html.erb
View
@@ -4,11 +4,13 @@
<%= f.label :content, "Question" %>
<%= link_to_remove_fields "remove", f %><br />
<%= f.text_area :content, :rows => 3 %><br />
+ <%= label_tag :allow_free_response, "Allow Free Response?" %>
+ <%= check_box_tag :allow_free_response, false %>
</p>
<%= f.fields_for :answers do |builder| %>
<%= render 'answer_fields', :f => builder %>
<% end %>
- <p>
+ <p class="add_answer">
<%= link_to_add_fields "Add Answer", f, :answers %>
</p>
</div>
8 app/views/surveys/index.html.erb
View
@@ -6,9 +6,6 @@
<table>
<tr>
<th>Name <em>(Click to Show)</em></th>
- <% if can? :list_published, Survey %>
- <th>Published?</th>
- <% end %>
<% if can? :take, :survey %>
<th>Take</th>
<% end %>
@@ -26,11 +23,6 @@
<%= link_to survey.name, survey %>
</td>
<% end %>
- <% if can? :list_published, Survey %>
- <td>
- <%= survey.published %>
- </td>
- <% end %>
<% if can? :take, :survey %>
<td>
<% unless survey_completed?(current_user, survey) %>
66 app/views/surveys/report.html.erb
View
@@ -13,37 +13,39 @@
<%= render 'surveys/links' %>
<div class="center">
-<section id="survey_partial">
-<%= markdown "## Report" %>
+ <section id="survey_partial">
+ <%= markdown "## Report" %>
-<table id="survey-report">
- <tr>
- <th>Report for Survey <%= @survey.name %></th>
- <tr>
- <tr>
- <th>Question</th>
- <th>Question ID</th>
- <th>Answer</th>
- <th>Answer ID</th>
- <th>Reponses Total</th>
- </tr>
- <% # make a new row for every question %>
- <% @survey.questions.each do |question| %>
- <tr>
- <td><%= question.content.inspect %></td>
- <td><%= question.id %></td>
- <% # make a new row for every questions answer %>
- <% question.answers.each do |answer| %>
- <tr>
- <td></td>
- <td></td>
- <td><%= answer.content.inspect %></td>
- <td><%= answer.id %></td>
- <td><%= Response.where(:answer_id => answer.id).count %></td>
- </tr>
- <% end %>
- </tr>
- <% end %>
-</table>
-</section>
+ <table id="survey-report">
+ <tr>
+ <th>Report for Survey <%= @survey.name %></th>
+ <th><%= link_to "Export", report_survey_path(:format => :csv) %></th>
+ <tr>
+ <tr>
+ <th>Question</th>
+ <th>Question ID</th>
+ <th>Answer</th>
+ <th>Answer ID</th>
+ <th>Reponses Total</th>
+ </tr>
+ <% # make a new row for every question %>
+ <% @survey.questions.each do |question| %>
+ <tr>
+ <td><%= question.content.inspect %></td>
+ <td><%= question.id %></td>
+ <% # make a new row for every questions answer %>
+ <% question.answers.each do |answer| %>
+ <tr>
+ <td></td>
+ <td></td>
+ <td><%= answer.content.inspect %></td>
+ <td><%= answer.id %></td>
+ <td><%= link_to report_survey_path(params[:id], :answer_id => answer.id), :remote => true do %><%= answers_total_count(answer.id) %><% end %></td>
+ </tr>
+ <% end %>
+ </tr>
+ <% end %>
+ </table>
+ <div id="survey_report_result">Nothing Yet.</div>
+ </section>
</div>
1  app/views/surveys/report.js.erb
View
@@ -0,0 +1 @@
+$("div#survey_report_result").html("The following users responded with this answer: <%= escape_javascript( who_answered_me params[:answer_id]) %>");
52 app/views/surveys/show.html.erb
View
@@ -14,30 +14,32 @@
<%= render 'surveys/links' %>
<div class="center">
-<section id="survey_partial">
-
-<%= markdown "##Showing Survey: #{@survey.name.inspect}" %>
-
-<table id="show_survey">
- <tr><td>
- <ol>
- <% @survey.questions.each do |question| %>
- <%= content_tag(:li, label_tag(:question, question.content.inspect)) %>
- <ol>
- <% question.answers.each do |answer| %>
- <%= content_tag_for(:li, answer) do %>
- <%= label_tag :answer, answer.content.inspect %>
+ <section id="survey_partial">
+ <%= markdown "##Showing Survey: #{@survey.name.inspect}" %>
+ <table id="show_survey">
+ <tr>
+ <td>
+ <ol>
+ <% @survey.questions.each do |question| %>
+ <%= content_tag(:li, label_tag(:question, question.content.inspect)) %>
+ <ol>
+ <% question.answers.each do |answer| %>
+ <%= content_tag_for(:li, answer) do %>
+ <%= label_tag :answer, answer.content.inspect %>
+ <% end %>
+ <% end %>
+ </ol>
+ <br />
<% end %>
- <% end %>
- </ol>
- <br />
- <% end %>
- </ol>
- </td></tr>
- <tr>
- <td><%= markdown "**Published?: #{@survey.published}**" %>
- <%= markdown "**Available On: #{date_time_pretty_mst(@survey.available_at)}**" %></td>
- </tr>
-</table>
-</section>
+ </ol>
+ </td>
+ </tr>
+
+ <tr>
+ <td><%= markdown "**Published?: #{@survey.published}**" %></td>
+ <td><%= markdown "**Available On: #{@survey.available_at}**" %></td>
+ <td><%= markdown "**Anonymous?: #{@survey.anonymous}**" %></td>
+ </tr>
+ </table>
+ </section>
</div>
2  app/views/users/new.js.erb
View
@@ -1 +1 @@
-$("#result").html('<%= escape_javascript(render('users/new_remote')) %>');
+$("div#result").html('<%= escape_javascript(render('users/new_remote')) %>');
6 db/migrate/20120408214556_add_anonymous_to_question.rb
View
@@ -0,0 +1,6 @@
+class AddAnonymousToQuestion < ActiveRecord::Migration
+ def change
+ add_column :questions, :anonymous, :boolean, :default => false
+
+ end
+end
6 db/migrate/20120409005348_add_anonymous_to_survey.rb
View
@@ -0,0 +1,6 @@
+class AddAnonymousToSurvey < ActiveRecord::Migration
+ def change
+ add_column :surveys, :anonymous, :boolean, :default => false
+
+ end
+end
8 db/schema.rb
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120327222949) do
+ActiveRecord::Schema.define(:version => 20120409005348) do
create_table "answers", :force => true do |t|
t.integer "question_id"
@@ -23,8 +23,9 @@
create_table "questions", :force => true do |t|
t.integer "survey_id"
t.text "content"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.boolean "anonymous", :default => false
end
create_table "responses", :force => true do |t|
@@ -46,6 +47,7 @@
t.datetime "updated_at", :null => false
t.boolean "published", :default => false
t.datetime "available_at"
+ t.boolean "anonymous", :default => false
end
create_table "users", :force => true do |t|

No commit comments for this range

Something went wrong with that request. Please try again.