Commit ede9235d authored by Zac Wood's avatar Zac Wood
Browse files

Added Home controller and moved partials to shared folder

parent 9f37f2eb
Pipeline #2943 failed with stage
in 2 minutes and 18 seconds
function search() { // Place all the behaviors and hooks related to the matching controller here.
const searchTable = document.getElementById('scheduleTable'); // All this logic will automatically be available in application.js.
const crn = document.getElementById('search').value;
fetch(`api/search?crn=${crn}`)
.then(section => section.json())
.then(section => addRow(searchTable, section));
}
function addRow(table, section) {
const tr = document.createElement('tr');
const fields = [
section.name,
section.title,
section.crn,
section.instructor,
section.location,
section.days,
[section.start_time, section.end_time].join(' - '),
];
fields.forEach(field => {
const td = document.createElement('td');
const txt = document.createTextNode(field);
td.appendChild(txt);
tr.appendChild(td);
});
table.appendChild(tr);
}
// Place all the styles related to the Home controller here. // Place all the styles related to the home controller here.
// They will automatically be included in application.css. // They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/ // You can use Sass (SCSS) here: http://sass-lang.com/
# Configures the application. # Configures the application.
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session protect_from_forgery with: :null_session
before_action :set_cookies before_action :set_cookies, :set_cart
def set_cart
@cart = cookies[:ids].split(',').map do |crn|
CourseSection.find_by_crn crn
end
end
def set_cookies def set_cookies
cookies[:ids] = "" if cookies[:ids].nil? cookies[:ids] = "" if cookies[:ids].nil?
......
...@@ -3,10 +3,6 @@ class SearchController < ApplicationController ...@@ -3,10 +3,6 @@ class SearchController < ApplicationController
@courses = Course.where(subject: params[:q]).select do |course| @courses = Course.where(subject: params[:q]).select do |course|
course.course_sections.count.positive? course.course_sections.count.positive?
end end
@cart = cookies[:ids].split(',').map do |crn|
CourseSection.find_by_crn crn
end
end end
def update def update
......
<h1>Schedules</h1> <%= render partial: 'shared/navbar' %>
<input type="text" title="search_text" placeholder="Enter CRN..."/> <h1>Home#index</h1>
<button title="search">Search</button> <p>Find me in app/views/home/index.html.erb</p>
<h2>Your classes</h2>
<table>
<tr>
<th>Course</th>
<th>Section Name</th>
<th>CRN</th>
<th>Professor</th>
<th>Location</th>
<th>Days</th>
<th>Times</th>
</tr>
</table>
<button title="export">Export to calender</button>
<div class="card" id="course-<%= course.id %>" onclick="toggleSections(this)" data-course="<%= course.to_json %>">
<div class="card-body">
<div>
<h3 style="float: left"><%= "#{course.subject} #{course.course_number}" %></h3>
<h5 style="float: right"><em><%= course.title %></em>. <%= course.credits %> credits.</h5>
</div>
<div style="clear: both"> </div>
<p class="description"><%= course.description %></p>
<div class="d-block" style="text-align: center">
<i class="fas fa-chevron-down"></i>
</div>
<!-- List of Course Sections -->
<ul class="list-group list-group-flush" id="sections" style="display:none">
<%= render partial: 'section', collection: course.course_sections, locals: { in_cart: false } %>
</ul>
</div>
</div>
<div class="container-fluid">
<div class="row align-left align-sm-center align-md-right" id="navbar">
<div class="col-8 col-sm align-center">
<a href="/search" id="logo">
<i class="fas fa-calendar-alt"></i>
Schedules
</a>
</div>
<div class="col-4 col-sm align-center order-0 order-sm-1" onclick="toggleSchedule()">
<h1 style="margin-top:24px">
<!-- <h2><i class="fas fa-shopping-cart" id="schedule-icon"></i></h2> -->
<span class="fa-layers fa-fw" id="schedule-icon">
<i class="fas fa-shopping-cart"></i>
<span class="fa-layers fa-fw">
<i class="fas fa-circle" data-fa-transform="shrink-3 up-12 right-12" style="color:gray"></i>
<span id="course-counter" class="fa-layers-text fa-inverse" data-fa-transform="shrink-10 up-12 right-12" style="font-weight:600">
<%= @cart.length %>
</span>
</span>
</span>
</h1>
</div>
<div class="col-12 col-sm align-center order-1 order-sm-0">
<form action="/search" class="form-inline">
<div class="form-group">
<div class="input-group">
<input name="q" type="text" class="form-control" placeholder="Search by CRN, course, professor..." aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-secondary" type="button">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<% if in_cart %>
<li id="section-<%= section.crn %>"
class="list-group-item schedule-section-card"
data-crn="<%= section.crn %>"
onclick="removeFromSchedule(this)"
>
<span style="float:left"><b class="subj"><%= "#{section.name}" %></b>: <%= section.title %></span>
<span style="float:right"><i class="fas fa-map-marker-alt"></i> <%= section.location %></span>
<div style="clear: both"></div>
<span style="float:left"><i class="fas fa-chalkboard-teacher"></i> <%= section.instructor.name %></span>
<span style="float:right"><i class="fas fa-clock"></i> <%= "#{section.days}, #{section.start_time}-#{section.end_time}" %></span>
<div style="clear: both"></div>
</li>
<% else %>
<li id="section-<%= section.crn %>"
class="list-group-item section-item <%= "selected" if @cart.include? section %>"
data-crn="<%= section.crn %>"
onclick="addToSchedule(event, this)"
>
<span style="float:left"><b class="subj"><%= "#{section.name}" %></b>: <%= section.title %></span>
<span style="float:right"><i class="fas fa-map-marker-alt"></i> <%= section.location %></span>
<div style="clear: both"></div>
<span style="float:left"><i class="fas fa-chalkboard-teacher"></i> <%= section.instructor.name %></span>
<span style="float:right"><i class="fas fa-clock"></i> <%= "#{section.days}, #{section.start_time}-#{section.end_time}" %></span>
<div style="clear: both"></div>
</li>
<% end %>
<%= render partial: 'navbar' %> <%= render partial: 'shared/navbar' %>
<div class="container-fluid"> <div class="container-fluid">
<!-- The main screen consists of a row with two columns: the search results, and the cart --> <!-- The main screen consists of a row with two columns: the search results, and the cart -->
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<!-- Search result, List of Courses --> <!-- Search result, List of Courses -->
<div class="col-lg-7 col-md-10 mx-auto order-2 order-lg-0" id="search-list"> <div class="col-lg-7 col-md-10 mx-auto order-2 order-lg-0" id="search-list">
<% if @courses.any? %> <% if @courses.any? %>
<%= render partial: 'course', collection: @courses %> <%= render partial: 'shared/course', collection: @courses %>
<% else %> <% else %>
<h1>Sorry, we couldn't find anything matching your search.</h1> <h1>Sorry, we couldn't find anything matching your search.</h1>
<p>Please try again!</p> <p>Please try again!</p>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<h3 class="card-title">Your Schedule</h3> <h3 class="card-title">Your Schedule</h3>
</div> </div>
<ul class="list-group list-group-flush" id="schedule"> <ul class="list-group list-group-flush" id="schedule">
<%= render partial: 'section', collection: @cart, locals: { in_cart: true } %> <%= render partial: 'shared/section', collection: @cart, locals: { in_cart: true } %>
</ul> </ul>
<div class="card-body"> <div class="card-body">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" onclick="setUrlInModal()"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" onclick="setUrlInModal()">
......
...@@ -10,5 +10,6 @@ Rails.application.routes.draw do ...@@ -10,5 +10,6 @@ Rails.application.routes.draw do
end end
apipie # sets up API docs apipie # sets up API docs
get '/', to: redirect('/api') # redirect the root url to API docs
root to: 'home#index'
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment