Changeset 277

Show
Ignore:
Timestamp:
10/14/08 17:01:46 (3 months ago)
Author:
pwh
Message:

Refactored index to allow for further search paramters when narrowing down devices.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/app/controllers/manage_device_controller.rb

    r244 r277  
    3636 
    3737    @partial = "common/device_search" 
    38  
    39     if params[:site_id] && !params[:site_id].blank? && params[:site_id].to_i != 0 
    40       logger.debug "Finding all devices with site_id='#{params[:site_id]}'" 
    41       @devices = Device.find(:all, :conditions => { :site_id => params[:site_id] }) 
    42     else 
    43       logger.debug "Finding all devices" 
     38     
     39    # Pluck out any search criteria we need to use from the search_for parameter 
     40     
     41    if !params[:search_criteria].nil? 
     42      search_criteria = params[:search_criteria] 
     43           
     44      if !search_criteria[:site_id].blank? 
     45        logger.debug "Finding all devices with site_id='#{search_criteria[:site_id]}'" 
     46        @devices = Device.find(:all, :conditions => { :site_id => search_criteria[:site_id] }) 
     47      end 
     48       
     49    end 
     50     
     51    if !@devices 
     52       
     53      logger.debug "No search parameters passed, returning all Devices" 
    4454      @devices = Device.find(:all) 
     55       
    4556    end 
    46  
     57     
    4758    @sites = Site.find(:all) 
    4859 
     
    6980    if @device 
    7081      @l2_interfaces = L2Interface.find(:all, :conditions => ["l2_interfaces.device_id = ?", @device.id.to_s], 
    71                                           :include => ['l3_interfaces']) 
     82        :include => ['l3_interfaces']) 
    7283 
    7384      @subtitle = "Device Management: #{@device.hostname}" 
  • nethorus/app/views/common/_device_search.html.erb

    r242 r277  
    1 <table class="vert"> 
    2  <tr> 
    3   <th>Search Functions</th> 
    4  </tr> 
    5  <tr> 
    6   <td> 
    7    <form method="post"> 
    8     <p>Only devices in <%= select('search_for', 'site_id', @sites.collect { |site| [ site.description, site.id ] } ) %></p> 
    9     <input type="submit" value="Go" /> 
    10     </p> 
    11    </form> 
    12   </td> 
    13  </tr> 
     1<form method="post"> 
     2  <table class="vert"> 
     3    <tr> 
     4      <th>Search Functions</th> 
     5    </tr> 
     6    <tr> 
     7      <td> 
     8        <p>Limit to devices at site <%= select('search_criteria', 'site_id', @sites.collect { |site| [ site.description, site.id ] }, { :include_blank => :true } ) %></p> 
     9        <input type="submit" value="Go" />     
     10     </td> 
     11  </tr> 
    1412</table> 
    15  
     13</form> 
    1614<br /> 
    1715