Class: SearchController

Inherits:
ApplicationController show all
Defined in:
app/controllers/search_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#content_date_sort, #do_404, #do_410, #do_invalid_page, #get_county_options, #get_location_options, #mobile_detection, #set_analytics_visitor, #set_app_location, #set_default_request_ip_address, #set_locale, #set_request_url_options, #unescape_params

Methods included from ControllerExtensions

#check_openidurl_foruser, #log_user_activity, #validate_datepicker

Methods included from AuthLib

#current_person, #set_current_person

Instance Method Details

- (Object) add



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/search_controller.rb', line 44

def add
  if (!params[:url].nil? and !params[:url].empty?)
    annote = Annotation.new
    result = annote.add(params[:url], current_person)
    
    if result[:success]
      flash[:success] = "#{annote.url} has been added to search."
    else
      flash[:failure] = "Unable to add #{params[:url]} - #{result[:msg]}"
    end
    
  else
    flash[:warning] = "No valid url provided."
  end
  
  redirect_to(:action => :manage, :searchterm => params[:searchterm])
end

- (Object) index



17
18
19
# File 'app/controllers/search_controller.rb', line 17

def index
  @page_title = "Home"
end

- (Object) manage



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/search_controller.rb', line 21

def manage
  @page_title = "Manage Links"
  set_titletag('Manage CSE Links')
  if (!params[:searchterm].nil? and !params[:searchterm].empty?)
    @annotations = Annotation.patternsearch(params[:searchterm]).paginate(:all, :order => :url, :page => params[:page])
    if @annotations.nil? || @annotations.length == 0
      flash.now[:warning] = "No URLs were found that matches your search term."
    end
  else
    @annotations = Annotation.paginate(:all, :order => 'added_at DESC', :page => params[:page])
  end
end

- (Object) manage_activity



34
35
36
37
# File 'app/controllers/search_controller.rb', line 34

def manage_activity
  @page_title = "CSE Link Management Activity"
  @events = AnnotationEvent.paginate(:all, :joins => :person, :order => 'created_at DESC', :page => params[:page])
end

- (Object) manage_event



39
40
41
42
# File 'app/controllers/search_controller.rb', line 39

def manage_event
  @page_title = "CSE Link Management Event"
  @event = AnnotationEvent.find_by_id(params[:id])
end

- (Object) remove



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/search_controller.rb', line 62

def remove
  if (!params[:id].nil? and !params[:id].empty?)
    goner = Annotation.find_by_id(params[:id])
    
    if goner
      result = goner.remove(current_person)
    else
      result = {:success => false, :msg => "URL ID not found"}
    end
    
    if result[:success]
      flash[:success] = "#{goner.url} has been removed from search. "
      flash[:success] << link_to("UNDO", url_for(:action => :add, :url => goner.url, :searchterm => params[:searchterm]), :class => "bigbutton blue")
    else
      if goner
        flash[:failure] = "Unable to remove #{goner.url} - #{result[:msg]}"
      else
        flash[:failure] = "Unable to remove URL - #{result[:msg]}"
      end
    end
  else
    flash[:warning] = "No valid id provided."
  end
  
  redirect_to(:action => :manage, :searchterm => params[:searchterm])
end