From 83ef49d7834db88fdf9a33369e2b70f00a5e8090 Mon Sep 17 00:00:00 2001 From: Zac Wood Date: Wed, 24 Oct 2018 16:58:14 -0400 Subject: [PATCH] instructor page updates --- schedules/app/models/semester.rb | 4 +++ schedules/app/views/instructors/show.html.erb | 29 +++++++++++++++---- schedules/app/views/shared/_course.html.erb | 6 ---- schedules/config/routes.rb | 3 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/schedules/app/models/semester.rb b/schedules/app/models/semester.rb index 419e047..cea92f3 100644 --- a/schedules/app/models/semester.rb +++ b/schedules/app/models/semester.rb @@ -8,4 +8,8 @@ class Semester < ApplicationRecord # Ensure necessary fields are present. validates :year, presence: true validates :season, presence: true + + def to_s + return "#{season} #{year}" + end end diff --git a/schedules/app/views/instructors/show.html.erb b/schedules/app/views/instructors/show.html.erb index 678e28f..2606a80 100644 --- a/schedules/app/views/instructors/show.html.erb +++ b/schedules/app/views/instructors/show.html.erb @@ -1,7 +1,24 @@ -

<%= @instructor.name %>

+
+
+

<%= @instructor.name %>

+ <% prev = @instructor.course_sections.reject { |s| s.course.semester == @semester }.map { |s| s.name.split[0..1].join(' ') }.uniq %> -<% if @courses.any? %> - <%= render partial: 'shared/course', collection: @courses, locals: { expanded: true } %> -<% else %> -

<%= @instructor.name %> has not taught any courses...

-<% end %> + <% if prev.count.positive? %> + Previously taught: +
    + <% prev.each do |s| %> +
  • <%= s %>
  • + <% end %> +
+ <% end %> +
+ +
+

<%= @semester.to_s %>

+ <% if @courses.any? %> + <%= render partial: 'shared/course', collection: @courses, locals: { expanded: true } %> + <% else %> +

<%= @instructor.name %> is not teaching any courses this semester...

+ <% end %> +
+
diff --git a/schedules/app/views/shared/_course.html.erb b/schedules/app/views/shared/_course.html.erb index 3b678cc..02122a6 100644 --- a/schedules/app/views/shared/_course.html.erb +++ b/schedules/app/views/shared/_course.html.erb @@ -8,12 +8,6 @@

<%= "#{course.subject} #{course.course_number}" %>

<% end %> - -
<%= course.title %>
diff --git a/schedules/config/routes.rb b/schedules/config/routes.rb index 136f057..0e8765f 100644 --- a/schedules/config/routes.rb +++ b/schedules/config/routes.rb @@ -4,9 +4,10 @@ Rails.application.routes.draw do get 'sessions/update', as: 'update_session' get 'sessions/cart' + resources :courses, only: [:show] resources :instructors, only: [:index, :show] get 'schedule', to: 'schedules#show', as: 'schedule' - + scope :api do # Register /api routes resources :courses, only: [:index, :show] resources :course_sections, only: [:index] -- GitLab