Skip to content

Commit

Permalink
Merge pull request #508 from alaashafaee/C1_Assuty_223_advanced_searc…
Browse files Browse the repository at this point in the history
…h_1.23

Pull Request: C1_Assuty_223_Advanced_Simple_Search_1.23
  • Loading branch information
MohabGhanim committed May 16, 2014
2 parents 270da02 + a7e1f36 commit f2070dc
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 47 deletions.
4 changes: 3 additions & 1 deletion tutor/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ gem 'json_builder', '3.1.0'
# whenever gem for scheduling tasks
gem 'whenever', :require => false

#pagination
gem 'will_paginate', '~> 3.0.5'

group :development, :test do
gem 'rspec-rails', '~> 3.0.0.beta'
end

14 changes: 13 additions & 1 deletion tutor/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui-1.10.4
//= require_tree .
//= require bootstrap
//= require jquery.tokeninput
//= require utilities
//= require utilities

// [Simple Search auto-complete - Story 1.23]
// autocomplete for the search bar
// Parameters: search term
// Returns: Array with the matched results
// Author: Ahmed Elassuty
$(function(){
$('#search_field').autocomplete({
source: $('#search_field').data("autocomplete-source")
});
});
41 changes: 36 additions & 5 deletions tutor/app/controllers/utilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,35 @@ class UtilitiesController < ApplicationController
# Author: Ahmed Elassuty
def simple_search
@lecturers = Lecturer.simple_search(params[:search])
.paginate(:page => params[:page], :per_page => 3)
@students = Student.simple_search(params[:search])
.paginate(:page => params[:page], :per_page => 3)
@teaching_assisstants = TeachingAssistant.simple_search(params[:search])
.paginate(:page => params[:page], :per_page => 3)
@courses = Course.simple_search(params[:search])
.paginate(:page => params[:page], :per_page => 3)
@objects = @courses
if @lecturers.count > @students.count
if @lecturers.count > @teaching_assisstants.count
if @lecturers.count > @courses.count
@objects = @lecturers
end
else
if @teaching_assisstants.count > @courses.count
@objects = @teaching_assistants
end
end
else
if @students.count > @teaching_assisstants.count
if @students.count > @courses.count
@objects = @students
end
else
if @teaching_assisstants.count > @courses.count
@objects = @teaching_assisstants
end
end
end
respond_to do |format|
format.js
format.html
Expand Down Expand Up @@ -52,11 +78,16 @@ def advanced_search
# Returns: A hashes with search results according to the keyword
# Author: Ahmed Elassuty
def auto_complete
@objects = Lecturer.simple_search(params[:q]).take(1)
respond_to do |format|
format.json {render :template => 'utilities/auto_complete',
:formats => [], :handlers => [:json_builder], :layout=>false}
end
objects = Lecturer.simple_search(params[:term]).take(2)
auto_complete = []
auto_complete = auto_complete.concat(objects.map(&:name)) unless objects.nil?
objects = Student.simple_search(params[:term]).take(2)
auto_complete = auto_complete.concat(objects.map(&:name)) unless objects.nil?
objects = TeachingAssistant.simple_search(params[:term]).take(2)
auto_complete = auto_complete.concat(objects.map(&:name)) unless objects.nil?
objects = Course.simple_search(params[:term]).take(2)
auto_complete = auto_complete.concat(objects.map(&:name)) unless objects.nil?
render json: auto_complete
end

end
5 changes: 3 additions & 2 deletions tutor/app/views/layouts/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# Author: Ahmed Elassuty
-->
<%= form_tag utilities_simple_search_path, :method => 'get',
remote: controller?("utilities","simple_search"), class: "navbar-form navbar-left" do %>
remote: controller?("utilities","simple_search"), class: "navbar-form navbar-left" do %>
<div class="input-group" style="width:350px">
<%= text_field_tag :search, params[:search], class: "form-control col-lg-8",
placeholder: "Search for Users and Courses" %>
placeholder: "Search for Users and Courses", id: "search_field",
data: { autocomplete_source: utilities_auto_complete_path } %>
<span class="input-group-btn">
<%= link_to "Try Advanced", utilities_advanced_search_path,
class: "btn btn-default col-lg-12" %>
Expand Down
32 changes: 10 additions & 22 deletions tutor/app/views/utilities/_result_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
<% if openable %>
<% open = "in" %>
<% openarrow = "glyphicon-chevron-down" %>
<% else %>
<% open = "" %>
<% openarrow = "glyphicon-chevron-right" %>
<% end %>
<% if objects.present? %>
<div class="panel panel-default">
<div class="panel-title list-group-item list-group-item-info">
<a class="icon glyphicon <%= openarrow %>"
href="#<%= objects.first.class.name.pluralize.to_s %>"
data-toggle="collapse" data-parent="#accordion"
style="margin-right:1%;text-decoration: none;">
</a>
<a class="panel-title" align="center">
<%= objects.first.class.name.pluralize.to_s %>
</a>
<span class="badge">
<%= objects.count %>
</span>
<div class="panel-title list-group-item list-group-item-info"
data-parent="#accordion"
href="<%= objects.first.class.name.pluralize.to_s %>">
<div align="center">
<a class="panel-title">
<%= objects.first.class.name.pluralize.to_s %>
</a>
</div>
</div>
<div id="<%= objects.first.class.name.pluralize.to_s %>"
class="panel-collapse collapse <%= open %>">
<div id="<%= objects.first.class.name.pluralize.to_s %>">
<ul class="list-group">
<% objects.each do |object| %>
<li class="list-group-item" data-toggle="tooltip"
Expand All @@ -36,4 +24,4 @@
</ul>
</div>
</div>
<%end%>
<% end %>
16 changes: 7 additions & 9 deletions tutor/app/views/utilities/_simple_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
<p>No Result match</p>
</div>
<% else %>
<% openable = true %>
<% if @lecturers.present? %>
<div class="panel-group list-group" id="accordion">
<%= render "result_form", objects: @lecturers, openable: openable %>
<% openable = false %>
<%= render "result_form", objects: @lecturers %>
</div>
<% end %>
<% if @students.present? %>
<div class="panel-group list-group" id="accordion">
<%= render "result_form", objects: @students, openable: openable %>
<% openable = false %>
<%= render "result_form", objects: @students %>
</div>
<% end %>
<% if @teaching_assisstants.present? %>
<div class="panel-group list-group" id="accordion">
<%= render "result_form", objects: @teaching_assisstants, openable: openable %>
<% openable = false %>
<%= render "result_form", objects: @teaching_assisstants %>
</div>
<% end %>
<% if @courses.present? %>
<div class="panel-group list-group" id="accordion">
<%= render "result_form", objects: @courses, openable: openable %>
<% openable = false %>
<%= render "result_form", objects: @courses %>
</div>
<% end %>
<% end %>
<div class="pagination pull-right">
<%= will_paginate (@objects) %>
</div>
</div>
</div>
</div>
12 changes: 9 additions & 3 deletions tutor/app/views/utilities/advanced_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<legend>Advanced Search Form</legend>
<div class="page-header">
<h3>
<span class="glyphicon glyphicon-search"></span>
Advanced Search Form
</h3>
</div>
<br/>
<hr/>
<div id="advanced_search_form">
<%= render "advanced_search" %>
</div>
<div id="advanced_search_result">
</div>
<div id="advanced_search_result"></div>
4 changes: 0 additions & 4 deletions tutor/app/views/utilities/auto_complete.json_builder

This file was deleted.

3 changes: 3 additions & 0 deletions tutor/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Initialize the Rails application.
Tutor::Application.initialize!

#paginate
require 'will_paginate'

0 comments on commit f2070dc

Please sign in to comment.