Class: TeamsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/teams_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#createObject

POST /courses/1/teams POST /courses/1/teams.xml



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'app/controllers/teams_controller.rb', line 182

def create
  if has_permissions_or_redirect(:staff, root_path)
    params[:team][:members_override] = params[:persons]
    @team = Team.new(params[:team])

    @team.course_id = params[:course_id]
    @course = Course.find(params[:course_id])

    update_course_faculty_label

    respond_to do |format|
      if @team.save
        flash[:notice] = 'Team was successfully created.'
        format.html { redirect_to(course_teams_path(@team.course_id)) }
        format.xml { render :xml => @team, :status => :created, :location => @team }
      else
        @faculty = @course.faculty
        format.html { render :action => "new" }
        format.xml { render :xml => @team.errors, :status => :unprocessable_entity }
      end
    end
  end
end

#destroyObject

DELETE /courses/1/teams/1 DELETE /courses/1/teams/1.xml



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'app/controllers/teams_controller.rb', line 233

def destroy
  if !current_user.is_admin?
    flash[:error] = I18n.t(:no_permission)
    redirect_to(teams_url) and return
  end

  @team = Team.find(params[:id])
  course = @team.course
  @team.destroy

  respond_to do |format|
    format.html { redirect_to(course_teams_path(course)) }
    format.xml { head :ok }
  end
end

#editObject

GET /courses/1/teams/1/edit



171
172
173
174
175
176
177
178
# File 'app/controllers/teams_controller.rb', line 171

def edit
  @team = Team.find(params[:id])
  @course = Course.find(params[:course_id])
  if has_permissions_or_redirect(:staff, course_team_path(@course, @team))
    @team.course_id = params[:course_id]
    @faculty = @course.faculty
  end
end

#export_to_csvObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/teams_controller.rb', line 99

def export_to_csv
  if has_permissions_or_redirect(:staff, root_path)

    @course = Course.find(params[:course_id])
    @teams = Team.where(:course_id => params[:course_id]).order("id").all unless params[:course_id].empty?

    report = CSV.generate do |title|
      title << ['Team Name', 'Team Member', 'Past Teams', "Part Time", "Local/Near/Remote", "State", "Company Name"]
      @teams.each do |team|
        team.members.each do |user|
          part_time = user.is_part_time ? "PT" : "FT"
          title << [team.name, user.human_name, user.formatted(user.past_teams), part_time, user.local_near_remote, user.work_state, user.organization_name]
        end
      end
    end
    send_data(report, :type => 'text/csv;charset=iso-8859-1;', :filename => "past_teams_for_#{@course.display_course_name}.csv",
              :disposition => 'attachment', :encoding => 'utf8')
  end
end

#indexObject

GET /courses/1/teams GET /courses/1/teams.xml



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/teams_controller.rb', line 9

def index
  @show_teams_for_many_courses = false
  @machine_name = ""
  @teams = Team.where(:course_id => params[:course_id]).order("id").all unless params[:course_id].empty?
  @course = Course.find(params[:course_id])

  @show_section = false
  @teams.each do |team|
    @show_section = true unless (team.section.nil? || team.section.empty?)
  end

  respond_to do |format|
    format.html { render :partial => "twiki_index", :locals => {:teams => @teams, :show_new_teams_link => true, :show_photo_view_link => true, :show_student_photos => false, :show_course => false} } # index.html.erb
    format.xml { render :xml => @teams }
  end
end

#index_allObject

GET /teams GET /teams.xml



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/teams_controller.rb', line 122

def index_all
  @show_teams_for_many_courses = true
  @show_create_course = false
  @show_section = false
  @machine_name = ""

  #If possible, we would prefer to do an order by in sql to sort latest semester alphabetical by course name.
  @teams = Team.order("course_id DESC").all
  #    @teams = @teams.sort_by {|team| team.course.year + team.course.semester + team.course.name }.reverse

  respond_to do |format|
    format.html { render :partial => "twiki_index", :locals => {:teams => @teams, :show_new_teams_link => false, :show_photo_view_link => false, :show_student_photos => false, :show_course => false} } # index.html.erb
    format.xml { render :xml => @teams }
  end
end

#index_photosObject



77
78
79
80
81
82
83
84
85
# File 'app/controllers/teams_controller.rb', line 77

def index_photos
  @teams = Team.where(:course_id => params[:course_id]).order("id").all unless params[:course_id].empty?
  @course = Course.find(params[:course_id])

  respond_to do |format|
    format.html { render :html => @teams, :layout => "simple" } # index.html.erb
    format.xml { render :xml => @teams }
  end
end

#newObject

GET /courses/1/teams/new GET /courses/1/teams/new.xml



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/controllers/teams_controller.rb', line 153

def new
  if has_permissions_or_redirect(:staff, root_path)
    @team = Team.new()
    @team.course_id = params[:course_id]
    @course = Course.find(params[:course_id])
    @faculty = @course.faculty
    (1..5).each do
      @team.members << User.new
    end

    respond_to do |format|
      format.html # new.html.erb
      format.xml { render :xml => @team }
    end
  end
end

#past_teams_listObject



87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/teams_controller.rb', line 87

def past_teams_list
  if has_permissions_or_redirect(:staff, root_path)
    @teams = Team.where(:course_id => params[:course_id]).order("id").all unless params[:course_id].empty?
    @course = Course.find(params[:course_id])

    respond_to do |format|
      format.html { render :html => @teams, :layout => "cmu_sv" } # index.html.erb
      format.xml { render :xml => @teams }
    end
  end
end

#peer_evaluationObject

GET /courses/1/teams/1/peer_evaluation



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'app/controllers/teams_controller.rb', line 250

def peer_evaluation
  @course = Course.find(params[:course_id])
  @team = Team.find(params[:id])

  @emails = []
  @first_names = []
  @full_names = []
  @ids = []
  @team.members.each do |user|
    @emails << user.email
    @first_names << user.first_name
    @full_names << user.human_name
    @ids << user.id
  end

  if (@team.peer_evaluation_first_email.nil?)
    @team.peer_evaluation_first_email = Date.today()
  end
  if (@team.peer_evaluation_second_email.nil?)
    @team.peer_evaluation_second_email = Date.today()
  end

  respond_to do |format|
    format.html # show.html.erb
    format.xml { render :xml => @team }
  end
end

#peer_evaluation_updateObject



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'app/controllers/teams_controller.rb', line 278

def peer_evaluation_update
  @team = Team.find(params[:id])

  @team.peer_evaluation_first_email = params[:team][:peer_evaluation_first_email]
  @team.peer_evaluation_second_email = params[:team][:peer_evaluation_second_email]

  if @team.save
    flash[:notice] = 'Dates saved'
  else
    flash[:error] = 'Dates not saved'
  end
  redirect_to(peer_evaluation_path(@team.course, @team.id))
end

#showObject

GET /courses/1/teams/1 GET /courses/1/teams/1.xml



141
142
143
144
145
146
147
148
149
# File 'app/controllers/teams_controller.rb', line 141

def show
  @course = Course.find(params[:course_id])
  @team = Team.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml { render :xml => @team }
  end
end

#twiki_indexObject

generate the team table for a course on a page hosted on the twiki server



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/teams_controller.rb', line 54

def twiki_index
  @show_teams_for_many_courses = false
  @machine_name = "http://whiteboard.sv.cmu.edu"

  url = get_twiki_http_referer()
  @course = Course.where(:twiki_url => url).first

  @show_create_course = false
  if (@course.nil?)
    @show_create_course = true
    render :partial => "twiki_index", :layout => false, :locals => {:teams => @teams, :show_new_teams_link => true, :show_photo_view_link => true, :show_student_photos => false, :show_course => false}
    return
  end
  @teams = Team.where(:course_id => @course.id).order("id").all unless @course.nil?

  @show_section = false
  @teams.each do |team|
    @show_section = true unless (team.section.nil? || team.section.empty?)
  end

  render :partial => "twiki_index", :layout => false, :locals => {:teams => @teams, :show_new_teams_link => true, :show_photo_view_link => true, :show_student_photos => false, :show_course => false}
end

#twiki_newObject

Create a new team from a team table page hosted on the twiki server



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/teams_controller.rb', line 27

def twiki_new
  if has_permissions_or_redirect(:staff, root_path)
    # Example url:
    # http://info.sv.cmu.edu/twiki/bin/view/Fall2008/Foundations/StudentTeams
    # http://info.sv.cmu.edu/twiki/bin/view/Fall2009/Foundations/WebHome
    url = get_twiki_http_referer()
    @course = Course.where(:twiki_url => url).first
    if (@course.nil?)
      parts = url.split('/')
      @course = Course.new()
      @course.twiki_url = url
      @course.name = parts[parts.length - 2]
      match = parts[parts.length - 3].match /(\D+)(\d+)/
      @course.semester = match[1] unless (match.nil? || match[1].nil?)
      @course.year = match[2] unless (match.nil? || match[2].nil?)

      if !@course.save()
        flash[:error] = 'Course could not be created.'
      end
    else
      #error
    end
    redirect_to url
  end
end

#updateObject

PUT /courses/1/teams/1 PUT /courses/1/teams/1.xml



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'app/controllers/teams_controller.rb', line 208

def update
  params[:team][:members_override] = params[:persons]
  @team = Team.find(params[:id])
  @course = @team.course
  if has_permissions_or_redirect(:staff, course_team_path(@course, @team))

    update_course_faculty_label

    respond_to do |format|
      @team.attributes = params[:team]
      if @team.save(params[:team])
        flash[:notice] = 'Team was successfully updated.'
        format.html { redirect_to(course_teams_path(@team.course)) }
        format.xml { head :ok }
      else
        @faculty = @course.faculty
        format.html { render :action => "edit" }
        format.xml { render :xml => @team.errors, :status => :unprocessable_entity }
      end
    end
  end
end

#update_course_faculty_labelObject



293
294
295
296
297
298
299
300
# File 'app/controllers/teams_controller.rb', line 293

def update_course_faculty_label
  @course = Course.find(params[:course_id])
  if @course.primary_faculty_label != params[:primary_faculty_label] || @course.secondary_faculty_label != params[:seconday_faculty_label] then
    @course.primary_faculty_label = params[:primary_faculty_label]
    @course.secondary_faculty_label = params[:secondary_faculty_label]
    @course.save
  end
end