Skip to content

Commit

Permalink
Retrieve meetings information and campus. Display it in the sections …
Browse files Browse the repository at this point in the history
…table.
  • Loading branch information
CraigJZ committed Dec 6, 2022
1 parent 9c4e6e9 commit 9df3b8d
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/assets/javascripts/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ $(document).ready(function() {
},
{ responsivePriority: 3, targets: [
5,
9,
12
11,
14
]

},
{ responsivePriority: 4, targets: [
6,
7,
8,
10,
11,
12,
13,
14
15,
16
]
}
],
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/sections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def level_label(level)
def truthiness_indicator(value)
tag.i class: 'fa-solid fa-circle-check fa-large fa-xl' if value
end

def day_and_time(section)
"#{section.days} #{section.formatted_time(section.start_time)}-#{section.formatted_time(section.end_time)}"
end
end
31 changes: 30 additions & 1 deletion app/models/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,33 @@ def self.mark_for_deletion
Section.in_term(term).update_all(delete_at: Time.now.next_month)
end
end
end

def formatted_time(time)
time.to_datetime.strftime("%-I:%M%p") if time
end

def campus_label
case campus_code
when 'KOR'
'Mason Korea Campus'
when 'AR'
'Arlington Campus'
when 'FX'
'Fairfax Campus'
when 'FR'
'Front Royal'
when 'SA'
'Study Abroad'
when 'NE', 'MOL'
'Mason Online'
when 'OC', 'OCB'
'Off Campus'
when 'LC'
'Loudon Campus'
when 'PW'
'Science and Technology Campus'
else
campus_code
end
end
end
2 changes: 2 additions & 0 deletions app/views/sections/_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<td><%= section.credits %></td>
<td><%= level_label(section.level) %></td>
<td><%= section.modality_description %></td>
<td><%= day_and_time(section) %></td>
<td><%= section.campus_label %></td>
<td><%= section.instructor_names %></td>
<td><%= section.status %></td>
<td><%= section.enrollment_limit %><%= yesterday_arrow(section, 'enrollment_limit') %></td>
Expand Down
2 changes: 2 additions & 0 deletions app/views/sections/_section_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<th>Credits</th>
<th>Level</th>
<th>Modality</th>
<th>Meeting</th>
<th>Campus</th>
<th>Instructor(s)</th>
<th>Status</th>
<th>Enrollment Limit</th>
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20221206162054_add_meeting_data_to_sections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddMeetingDataToSections < ActiveRecord::Migration[7.0]
def change
add_column :sections, :days, :string
add_column :sections, :start_time, :string
add_column :sections, :end_time, :string
add_column :sections, :campus_code, :string
end
end
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_08_20_203515) do
ActiveRecord::Schema[7.0].define(version: 2022_12_06_162054) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down Expand Up @@ -73,6 +73,10 @@
t.string "print_flag"
t.string "instructor_name"
t.string "second_instructor_name"
t.string "days"
t.string "start_time"
t.string "end_time"
t.string "campus_code"
end

create_table "settings", force: :cascade do |t|
Expand Down
12 changes: 11 additions & 1 deletion lib/tasks/get_marketing_info.rake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ namespace :marketing_info do
section = Section.unscoped.where(section_id: chssweb_section['crn'].to_i, term: term).first
puts "#{chssweb_section['id']} - #{section.present?}"
if section.present?
section.assign_attributes(chssweb_title: chssweb_section['title'], image_present: chssweb_section['has_image?'], description_present: chssweb_section['has_description?'], youtube_present: chssweb_section['has_youtube?'], instructor_name: chssweb_section['instructor_name'], second_instructor_name: chssweb_section['second_instructor_name'])
section.assign_attributes(
chssweb_title: chssweb_section['title'],
image_present: chssweb_section['has_image?'],
description_present: chssweb_section['has_description?'],
youtube_present: chssweb_section['has_youtube?'],
instructor_name: chssweb_section['instructor_name'],
second_instructor_name: chssweb_section['second_instructor_name'],
days: chssweb_section['days'],
start_time: chssweb_section['start_time'],
end_time: chssweb_section['end_time'],
campus_code: chssweb_section['campus_code'])
section.second_instructor_name = nil if section.instructor_name == section.second_instructor_name
#### if any of the marketing info has changed, update it
section.save if section.changed?
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/sections_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'test_helper'

class SectionHelperTest < ActionView::TestCase
include SectionsHelper

setup do
@section = sections(:one)
end

test "combines section day and time into a string for display" do
@section.update(days: "TR", start_time: "10:30", end_time: "13:20")
assert_equal day_and_time(@section), "#{@section.days} #{@section.formatted_time(@section.start_time)}-#{@section.formatted_time(@section.end_time)}"
end
end
15 changes: 15 additions & 0 deletions test/models/section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,19 @@ class SectionTest < ActiveSupport::TestCase
assert_not_nil @section_four.reload.delete_at
assert_not_nil @section_five.reload.delete_at
end

test 'translates 24-hour time string into formatted 12-hour time' do
@section.update(start_time: "16:30")
assert_equal @section.formatted_time(@section.start_time), "4:30PM"
end

test 'returns the label for a known campus code' do
@section.update(campus_code: 'LC')
assert_equal @section.campus_label, 'Loudon Campus'
end

test 'returns the campus code for an known campus code' do
@section.update(campus_code: 'ABC')
assert_equal @section.campus_label, 'ABC'
end
end

0 comments on commit 9df3b8d

Please sign in to comment.