Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
469013a3
Commit
469013a3
authored
Oct 02, 2018
by
Zach Perkins
Browse files
Integrated the new search helper with the view
parent
f54c072f
Changes
3
Hide whitespace changes
Inline
Side-by-side
schedules/app/controllers/search_controller.rb
View file @
469013a3
class
SearchController
<
ApplicationController
def
index
puts
SearchHelper
::
GenericItem
.
fetchall
(
"cs 110"
)
@courses
=
[]
# @courses = Course.fetch(params).select do |course|
# course.course_sections.count.positive?
# end
@results
=
SearchHelper
::
GenericItem
.
fetchall
(
params
[
:query
])
end
def
update
...
...
schedules/app/helpers/search_helper.rb
View file @
469013a3
module
SearchHelper
class
GenericItem
attr_reader
:data
attr_reader
:type
def
initialize
(
type
,
data
)
@type
=
type
@data
=
data
end
def
self
.
fetchall
(
query_string
)
def
self
.
fetchall
(
query_string
,
sort_mode
=
:auto
)
models
=
[]
models
+=
fetch_instructors
query_string
models
+=
fetch_courses
query_string
...
...
@@ -38,12 +41,18 @@ module SearchHelper
s
=
a
[
0
]
next
unless
!
subj
.
nil?
&&
get_count
(
Course
.
from_course_number
(
base_query
,
s
)).
positive?
base_query
=
Course
.
from_course_number
(
base_query
,
s
)
.
order
(
"courses.course_number ASC"
)
return
base_query
.
all
end
base_query
=
Course
.
from_title
(
base_query
,
query_string
.
gsub
(
/ +/
,
" "
).
strip
)
.
order
(
"section_count DESC"
)
stripped_query_string
=
query_string
.
gsub
(
/ +/
,
" "
).
strip
# There's more to parse
if
stripped_query_string
.
length
.
positive?
base_query
=
Course
.
from_title
(
base_query
,
stripped_query_string
)
.
order
(
"section_count DESC"
)
else
base_query
=
base_query
.
order
(
"courses.course_number ASC"
)
end
base_query
.
all
end
...
...
@@ -53,7 +62,7 @@ module SearchHelper
def
self
.
build_list
(
models
)
list
=
[]
models
.
each
do
|
model
|
list
.
push
(
GenericItem
.
new
(
model
.
class
.
name
.
underscore
,
model
))
list
.
push
(
GenericItem
.
new
(
model
.
class
.
name
.
underscore
.
to_sym
,
model
))
end
list
...
...
schedules/app/views/search/index.html.erb
View file @
469013a3
<%
if
@courses
.
any?
%>
<%=
render
partial:
'shared/course'
,
collection:
@courses
%>
<%
if
@results
.
any?
%>
<%
@results
.
each
do
|
result
|
%>
<%
if
result
.
type
==
:course
%>
<%=
render
partial:
'shared/course'
,
object:
result
.
data
%>
<%
elsif
result
.
type
==
:instructor
%>
<%=
render
partial:
'shared/instructor'
,
object:
result
.
data
%>
<%
end
%>
<%
end
%>
<%
else
%>
<h1>
Sorry, we couldn't find anything matching your search.
</h1>
<p>
Please try again!
</p>
<h1>
Sorry, we couldn't find anything matching your search.
</h1>
<p>
Please try again!
</p>
<%
end
%>
<!-- Export Modal -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment