From 410d507606500605f81de6798f4a314f09c01c36 Mon Sep 17 00:00:00 2001 From: rnadkarni Date: Sat, 2 Nov 2013 16:33:35 -0700 Subject: [PATCH 1/3] First commit --- test | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test diff --git a/test b/test new file mode 100644 index 00000000..e69de29b From b1ecc5acfbfc95fbabe51f617c1294d52750a33a Mon Sep 17 00:00:00 2001 From: rnadkarni Date: Sat, 2 Nov 2013 16:34:28 -0700 Subject: [PATCH 2/3] First commit --- test | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test diff --git a/test b/test deleted file mode 100644 index e69de29b..00000000 From 16ccb561a61820f955a1fc257690640a91955e64 Mon Sep 17 00:00:00 2001 From: rnadkarni Date: Tue, 3 Dec 2013 16:06:39 -0800 Subject: [PATCH 3/3] Re-copied files after re-cloning repo --- app/assets/javascripts/tutor_swap.js.coffee | 3 + app/assets/stylesheets/tutor_swap.css.scss | 3 + app/controllers/.DS_Store | Bin 0 -> 6148 bytes app/controllers/tutor_controller.rb | 2 +- app/controllers/tutor_swap_controller.rb | 121 ++++++++++++++++++ app/helpers/tutor_swap_helper.rb | 2 + app/models/event.rb | 4 +- app/models/tutor_swap.rb | 32 +++++ app/views/people/show.html.erb | 2 +- app/views/slots/_slot.html.erb | 6 + app/views/tutor/schedule.html.erb | 39 +++--- app/views/tutor_swap/new.html.erb | 51 ++++++++ config/routes.rb | 7 + .../20131124004300_create_tutor_swaps.rb | 12 ++ ...9011008_add_orig_tutor_id_to_tutor_swap.rb | 5 + ...29011034_add_new_tutor_id_to_tutor_swap.rb | 5 + ...31129011122_add_swap_date_to_tutor_swap.rb | 5 + ...044108_remove_tutors_id_from_tutor_swap.rb | 9 ++ db/schema.rb | 13 +- .../controllers/tutor_swap_controller_spec.rb | 5 + spec/helpers/tutor_swap_helper_spec.rb | 15 +++ spec/models/tutor_swap_spec.rb | 5 + 22 files changed, 324 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/tutor_swap.js.coffee create mode 100644 app/assets/stylesheets/tutor_swap.css.scss create mode 100644 app/controllers/.DS_Store create mode 100644 app/controllers/tutor_swap_controller.rb create mode 100644 app/helpers/tutor_swap_helper.rb create mode 100644 app/models/tutor_swap.rb create mode 100644 app/views/tutor_swap/new.html.erb create mode 100644 db/migrate/20131124004300_create_tutor_swaps.rb create mode 100644 db/migrate/20131129011008_add_orig_tutor_id_to_tutor_swap.rb create mode 100644 db/migrate/20131129011034_add_new_tutor_id_to_tutor_swap.rb create mode 100644 db/migrate/20131129011122_add_swap_date_to_tutor_swap.rb create mode 100644 db/migrate/20131129044108_remove_tutors_id_from_tutor_swap.rb create mode 100644 spec/controllers/tutor_swap_controller_spec.rb create mode 100644 spec/helpers/tutor_swap_helper_spec.rb create mode 100644 spec/models/tutor_swap_spec.rb diff --git a/app/assets/javascripts/tutor_swap.js.coffee b/app/assets/javascripts/tutor_swap.js.coffee new file mode 100644 index 00000000..76156794 --- /dev/null +++ b/app/assets/javascripts/tutor_swap.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/tutor_swap.css.scss b/app/assets/stylesheets/tutor_swap.css.scss new file mode 100644 index 00000000..1a35b74e --- /dev/null +++ b/app/assets/stylesheets/tutor_swap.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the tutor_swap controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/.DS_Store b/app/controllers/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 false - + def schedule prop = Property.get_or_create @tutoring_enabled = prop.tutoring_enabled diff --git a/app/controllers/tutor_swap_controller.rb b/app/controllers/tutor_swap_controller.rb new file mode 100644 index 00000000..6ff2410d --- /dev/null +++ b/app/controllers/tutor_swap_controller.rb @@ -0,0 +1,121 @@ +class TutorSwapController < ApplicationController + before_filter :require_login # check if user is logged in + before_filter :require_tutor # check if logged-in user is a valid tutor + before_filter :setup, :only => [:new, :create] + + def require_login # check if logged in, otherwise redirect + return if logged_in + redirect_to login_path + end + + def logged_in # return whether or not logged in + @current_user + end + + def require_tutor # check if valid tutor, otherwise redirect + return if valid_tutor + redirect_to tutor_path + end + + def valid_tutor # return whether or not logged-in person is valid tutor + Tutor.find_by_person_id(@current_user.id) != nil + end + + def setup # setup list of slots to display when creating swap + @mytutor = Tutor.find_by_person_id(@current_user.id) + + @myslots = [] + Slot.all.each do |s| + if s.tutors.include?(@mytutor) + @myslots << s + end + end + return true + end + + def new # initialize new TutorSwap + setup + @newswap = TutorSwap.new + end + + def create # instantiate new TutorSwap and save + @mytutor = Tutor.find_by_person_id(@current_user.id) + + @myslots = [] + Slot.all.each do |s| + if s.tutors.include?(@mytutor) + @myslots << s + end + end + + @newswap = TutorSwap.new + + swap_slot = Slot.find_by_id(params[:slot][:slot_id]) # slot that is supposed to be swapped + + # check if submitted name is actually a person + @newswap.orig_tutor_id = @mytutor.id # ASSIGN TutorSwap.orig_tutor_id + first = params[:tutor].split(" ")[0] + last = params[:tutor].split(" ")[1] + flash[:notice] = params[:tutor] + new_tutor_person = Person.find_by_first_name_and_last_name(first, last) + unless new_tutor_person + flash[:notice] = "#{first}|#{last}" + # flash[:notice] = "The person you have specified does not exist" + redirect_to :action => :new + return + end + + # check if specified person is a valid tutor + new_tutor = Tutor.find_by_person_id(new_tutor_person.id) + unless new_tutor + flash[:notice] = "The person you have specified is not a tutor" + redirect_to :action => :new + return + end + + # check if specified person is the same as the submitting person + unless new_tutor != @mytutor + flash[:notice] = "You cannot swap tutoring slots with yourself" + redirect_to :action => :new + return + end + + # check if specified tutor has a conflicting slot, i.e. same time + Slot.all.each do |s| + if s.tutors.include?(new_tutor) + if s.wday == swap_slot.wday && s.hour == swap_slot.hour + flash[:notice] = "Tutor has a conflicting slot" + redirect_to :action => :new + return + end + end + end + + @newswap.new_tutor_id = new_tutor.id # ASSIGN TutorSwap.new_tutor_id + + @newswap.slot_id = params[:slot][:slot_id] # ASSIGN TutorSwap.slot_id + + # reformat inputted date string + date = Date.today + begin + date = Date.strptime(params[:date], "%m/%d/%Y") + rescue ArgumentError + flash[:notice] = "Date is formatted incorrectly" + redirect_to :action => :new + return + end + + @newswap.swap_date = date # ASSIGN TutorSwap.swap_date + + @newswap.save # SAVE TutorSwap + + # finish + flash[:notice] = "Swap submitted!" + redirect_to :action => :new + end + + def to_s + "TutorSwap #{orig_tutor_id} #{new_tutor_id} #{slot_id}" + end + +end diff --git a/app/helpers/tutor_swap_helper.rb b/app/helpers/tutor_swap_helper.rb new file mode 100644 index 00000000..f0e2d90f --- /dev/null +++ b/app/helpers/tutor_swap_helper.rb @@ -0,0 +1,2 @@ +module TutorSwapHelper +end diff --git a/app/models/event.rb b/app/models/event.rb index 1f33ead1..0d534b84 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -94,9 +94,9 @@ def nice_time_range(year = false) def can_view? user if user.nil? - view_permission_group.nil? and Event.current.include? self + view_permission_group.nil? else - (view_permission_group.nil? or user.groups.include? view_permission_group) and Event.current.include? self + view_permission_group.nil? or user.groups.include? view_permission_group end end diff --git a/app/models/tutor_swap.rb b/app/models/tutor_swap.rb new file mode 100644 index 00000000..fa8aca03 --- /dev/null +++ b/app/models/tutor_swap.rb @@ -0,0 +1,32 @@ +class TutorSwap < ActiveRecord::Base + + # === List of columns === + # id : integer + # slot_id : integer + # created_at : datetime + # updated_at : datetime + # orig_tutor_id : integer + # new_tutor_id : integer + # swap_date : date + # ======================= + + has_many :tutors + has_one :slot + + # validates :tutors, :presence => true + # validates :tutors, length: { is: 2 } + # validates :slot, :presence => true + + # validate :check_tutors + + TUTOR_ERROR = "swapping tutors cannot be the same tutor" + + # checks to see if the two tutors are different + def check_tutors(tutors) + my_tutors = self.tutors + if my_tutors[0] == my_tutors[1] then + errors[:tutor] << TUTOR_ERROR + end + end + +end diff --git a/app/views/people/show.html.erb b/app/views/people/show.html.erb index 5f633f6a..0c84c7ab 100644 --- a/app/views/people/show.html.erb +++ b/app/views/people/show.html.erb @@ -54,7 +54,7 @@ <% if @person.rsvps.count > 0 %>

<%= @person.fullname %>'s RSVPs

    - <% @person.rsvps.ordered_desc.each do |rsvp| %> + <% @person.rsvps.ordered_desc.limit(10).each do |rsvp| %> <% if rsvp.event.can_view? @current_user %>
  • <%= link_to "#{rsvp.event.start_date} - #{rsvp.event.name}", rsvp.event %>
  • <% end %> diff --git a/app/views/slots/_slot.html.erb b/app/views/slots/_slot.html.erb index c604ce3a..b0863140 100644 --- a/app/views/slots/_slot.html.erb +++ b/app/views/slots/_slot.html.erb @@ -1,6 +1,12 @@ <% if slot.tutors.any? %> <% slot.tutors.each do |tutor| %> +<% swap = TutorSwap.find_by_orig_tutor_id_and_slot_id(tutor.id, slot.id) %> +<% dates = (Date.today .. (Date.today + 6)) %> +<% if swap && dates.include?(swap.swap_date) %> + <% tutor = Tutor.find_by_id(swap.new_tutor_id) %> +<% end %> +
    -
    - <% courses = CoursePreference.all_courses(tutors.uniq) %> - <% for key in courses.keys %> - <%= key %> - <% for course in courses[key] %> - <% c = "'" + key + course + "'" %> - onmouseover="highlight(<%= c %>)" onmouseout="unhighlight(<%= c %>)" - onclick="return locklight(<%= c %>)"><%= course %> +
    + <% courses = CoursePreference.all_courses(tutors.uniq) %> + <% for key in courses.keys %> + <%= key %> + <% for course in courses[key] %> + <% c = "'" + key + course + "'" %> + onmouseover="highlight(<%= c %>)" onmouseout="unhighlight(<%= c %>)" + onclick="return locklight(<%= c %>)"><%= course %> <%= ', ' unless course == courses[key].last %> - <% end %> -
    - <% end %> -
    + <% end %> +
    + <% end %> +
    -
    = preferred
    -
    = completed
    -
    = in progress
    +
    = preferred
    +
    = completed
    +
    = in progress
    -
    +
    + +
    +
    + <%= button_to "SWAP SLOT", tutor_swap_new_path, :class => "swap", :method => :get %> +
    <%# End tutoring enabled %> <% else %>

    <%= @tutoring_message %>

    -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tutor_swap/new.html.erb b/app/views/tutor_swap/new.html.erb new file mode 100644 index 00000000..4db7f9ae --- /dev/null +++ b/app/views/tutor_swap/new.html.erb @@ -0,0 +1,51 @@ +<% content_for :header do %> + <%= javascript_include_tag "jquery-autocomplete.min" %> + <%= stylesheet_link_tag "jquery-autocomplete" %> +<%- end # header -%> + +

    Swapping Tutoring Slot

    + +
    + + <%= form_for @newswap, url: {action: "create"} do |s| %> + +
    + <%= label_tag "New tutor (e.g. Bobby Tutor):"%> +
    + <%= text_field_tag (l="tutor"), "", :id => l%> + <%= hidden_field_tag (l="tutor_hidden"), params[l], :id => l %> +
    + +
    + +
    + <%= label_tag "Slot:"%> +
    + <%- @myslots.each_with_index do |s, i| -%> +
    + <%= radio_button :slot, :slot_id, s.id%> + <% hour = s.hour % 12 %> + <% if hour == 0 %> + <% hour = 12 %> + <% end %> + <%= label_tag "#{Date.strptime(s.wday.to_s, "%w").strftime("%A")}, #{hour}-#{(hour + 1) % 12} pm"%> +
    + <%- end -%> +
    + +
    + +
    + <%= label_tag "Date (e.g. 07/04/1776):"%> +
    + <%= text_field_tag (l="date"), "", :id => l%> + <%= hidden_field_tag (l="date_hidden"), params[l], :id => l %> +
    + +
    + + <%= s.submit 'SUBMIT SWAP'%> + + <%- end -%> + +
    diff --git a/config/routes.rb b/config/routes.rb index 9cb1d399..b1542a8e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -324,6 +324,13 @@ match "calendar" => "tutor#calendar" end + + # EDIT: route /tutor/swap.html to swap.html.erb in app/views/tutor_swap/ + scope "tutor_swap" do + get "new" => "tutor_swap#new", :as => :tutor_swap_new + post "create" => "tutor_swap#create", :as => :tutor_swap_create + end + # Exams scope "exams" do match '/' => "exams#index", diff --git a/db/migrate/20131124004300_create_tutor_swaps.rb b/db/migrate/20131124004300_create_tutor_swaps.rb new file mode 100644 index 00000000..88db8a26 --- /dev/null +++ b/db/migrate/20131124004300_create_tutor_swaps.rb @@ -0,0 +1,12 @@ +class CreateTutorSwaps < ActiveRecord::Migration + def change + create_table :tutor_swaps do |t| + t.references :tutors + t.references :slot + + t.timestamps + end + add_index :tutor_swaps, :tutors_id + add_index :tutor_swaps, :slot_id + end +end diff --git a/db/migrate/20131129011008_add_orig_tutor_id_to_tutor_swap.rb b/db/migrate/20131129011008_add_orig_tutor_id_to_tutor_swap.rb new file mode 100644 index 00000000..6c2972a5 --- /dev/null +++ b/db/migrate/20131129011008_add_orig_tutor_id_to_tutor_swap.rb @@ -0,0 +1,5 @@ +class AddOrigTutorIdToTutorSwap < ActiveRecord::Migration + def change + add_column :tutor_swaps, :orig_tutor_id, :integer + end +end diff --git a/db/migrate/20131129011034_add_new_tutor_id_to_tutor_swap.rb b/db/migrate/20131129011034_add_new_tutor_id_to_tutor_swap.rb new file mode 100644 index 00000000..1a888291 --- /dev/null +++ b/db/migrate/20131129011034_add_new_tutor_id_to_tutor_swap.rb @@ -0,0 +1,5 @@ +class AddNewTutorIdToTutorSwap < ActiveRecord::Migration + def change + add_column :tutor_swaps, :new_tutor_id, :integer + end +end diff --git a/db/migrate/20131129011122_add_swap_date_to_tutor_swap.rb b/db/migrate/20131129011122_add_swap_date_to_tutor_swap.rb new file mode 100644 index 00000000..c8101dd5 --- /dev/null +++ b/db/migrate/20131129011122_add_swap_date_to_tutor_swap.rb @@ -0,0 +1,5 @@ +class AddSwapDateToTutorSwap < ActiveRecord::Migration + def change + add_column :tutor_swaps, :swap_date, :date + end +end diff --git a/db/migrate/20131129044108_remove_tutors_id_from_tutor_swap.rb b/db/migrate/20131129044108_remove_tutors_id_from_tutor_swap.rb new file mode 100644 index 00000000..106107e0 --- /dev/null +++ b/db/migrate/20131129044108_remove_tutors_id_from_tutor_swap.rb @@ -0,0 +1,9 @@ +class RemoveTutorsIdFromTutorSwap < ActiveRecord::Migration + def up + remove_column :tutor_swaps, :tutors_id + end + + def down + add_column :tutor_swaps, :tutors_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 9faa9f09..51f5df7f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130519233001) do +ActiveRecord::Schema.define(:version => 20131129044108) do create_table "alumnis", :force => true do |t| t.string "grad_semester" @@ -502,6 +502,17 @@ t.integer "keyword", :default => 0 end + create_table "tutor_swaps", :force => true do |t| + t.integer "slot_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "orig_tutor_id" + t.integer "new_tutor_id" + t.date "swap_date" + end + + add_index "tutor_swaps", ["slot_id"], :name => "index_tutor_swaps_on_slot_id" + create_table "tutors", :force => true do |t| t.integer "person_id", :null => false t.string "languages" diff --git a/spec/controllers/tutor_swap_controller_spec.rb b/spec/controllers/tutor_swap_controller_spec.rb new file mode 100644 index 00000000..2a4f21f0 --- /dev/null +++ b/spec/controllers/tutor_swap_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe TutorSwapController do + +end diff --git a/spec/helpers/tutor_swap_helper_spec.rb b/spec/helpers/tutor_swap_helper_spec.rb new file mode 100644 index 00000000..029848e7 --- /dev/null +++ b/spec/helpers/tutor_swap_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TutorSwapHelper. For example: +# +# describe TutorSwapHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe TutorSwapHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/tutor_swap_spec.rb b/spec/models/tutor_swap_spec.rb new file mode 100644 index 00000000..636a8812 --- /dev/null +++ b/spec/models/tutor_swap_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe TutorSwap do + pending "add some examples to (or delete) #{__FILE__}" +end