aboutsummaryrefslogtreecommitdiffstats
path: root/app/views/general/search.rhtml
blob: 735ceda86bb8f0920214886942d82813fc0254f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<% @show_tips = @xapian_requests.nil? || (@total_hits == 0) %>

<% @include_request_link_in_authority_listing = true %>

<%= render :partial => 'localised_datepicker'  %>

<% if @query.nil? %>
    <% @title = _("Search Freedom of Information requests, public authorities and users") %>
<% elsif @total_hits == 0 %>
    <% @title = _('There were no requests matching your query.') %>
<% else %>
    <% @title = _("Results page {{page_number}}", :page_number => @page.to_s) %>
<% end%>

<div id="header_left">
  <% if @query.nil? %>
    <h1>Search</h1>
  <% else %>
     <h1>Search results</h1> 
  <% end%>

  <% if @advanced %>
    <div id="advanced-search">
      <p><%= _('To use the advanced search, combine phrases and labels as described in the search tips below.') %></p>
      <% form_tag(advanced_search_url, :method => "get") do %>
         <p>
           <%= text_field_tag :query, @query, { :size => 60 } %>
           <%= hidden_field_tag 'sortby', @inputted_sortby %>
           <% if @bodies %>
               <%= hidden_field_tag 'bodies', 1 %>
           <% end %>
           <%= submit_tag _("Search") %>
               &nbsp;&nbsp;<%= link_to _('Simple search'), search_redirect_path %>
         </p>
      <% end %>
    </div>
  <% else %>
    <% form_tag(request.url, {:method => "get", :id => "search_form"}) do %>
      <p>
        <%= text_field_tag 'query', params[:query], { :size => 40 } %>
        <%= hidden_field_tag 'sortby', @inputted_sortby %>
        <% if @bodies %>
          <%= hidden_field_tag 'bodies', 1 %>
        <% end %>
        <%= submit_tag _("Search") %>
        <%= link_to(_("Advanced search"), advanced_search_url) %>
      </p>

      <div id="common-subfilters">
        <div id="variety-filter">
          <h3 class="title"><%= _("Showing") %></h3>
          <% labels = [
            ["requests", _("requests")],
            ["users", _("users")],
            ["bodies", _("authorities")],
            ["all", _("everything")]]%>
          <% for variety, label in labels %>
            <% if @variety_postfix != variety %>
              <% if variety != "users" %>
              <%=  link_to label, search_url([params[:query], @common_query], variety, @sort_postfix)  %>
              <% else %>
              <%=  link_to label, search_url(params[:query], variety, @sort_postfix) %>
              <% end %>
            <% else %>
              <%= label %>
            <% end %>
            <%= "|" unless variety == labels.last[0]%>
          <% end %>
        </div>

        <% if false %>
          <%-# Commented out for now as tags are of limited use when users can't see them.  This will change in the future! -%>
          <% if @variety_postfix != "users" %>
            <div>
              <%= label_tag(:query, _("Tags (separated by a space):")) %><%= text_field_tag(:tags, params[:tags], { :size => 20 }) %>
              <% for tag in InfoRequest.get_tags %>
                <%= tag.name_and_value %>
              <% end %>
            </div>
          <% end %>
        <% end %>
      </div>

      <% if @variety_postfix == "requests" %>
        <div id="requests-subfilters">
          <div>
             <h3 class="title"><%= _("Restrict to") %></h3>
             <% [["successful", _("successful requests")],
                ["unsuccessful", _("unsuccessful requests")],
                ["awaiting", _("unresolved requests")],
                ["internal_review", _("internal reviews")]].each_with_index do |item, index|
               status, title = item %>

               <%= check_box_tag "latest_status[]", status, params[:latest_status].nil? ? false : params[:latest_status].include?(status), :id => "latest_status_#{index}" %>
               <%= label_tag("latest_status_#{index}", title) %> <br/>
            <% end %>
          </div>

          <div>
            <h3 class="title"><%= _("Search in") %></h3>
            <% [["sent", _("messages from users")], 
              ["response", _("messages from authorities")],
              ["comment", _("comments")]].each_with_index do |item, index|
              variety, title = item %>

              <%= check_box_tag "request_variety[]", variety, params[:request_variety].nil? ? true : params[:request_variety].include?(variety), :id => "request_variety_#{index}" %>
              <%= label_tag("request_variety_#{index}", title) %> <br/>
            <% end %>
          </div>

          <div id="date_range">
            <label class="form_label title" for="query">Made between</label>
            <%= text_field_tag(:request_date_after, params[:request_date_after], {:class => "use-datepicker", :size => 10}) %>
            <label class="form_label" for="query">&nbsp;and</label>
            <%= text_field_tag(:request_date_before, params[:request_date_before], {:class => "use-datepicker", :size => 10}) %>
          </div>
        </div>  
      <% end %>
      
      <div>
        <%= submit_tag("Filter") if @variety_postfix == "requests"%>
      </div>
    <% end # Search form%>
    
  <% end # if @advanced %>

  <% if !@query.nil? %>
    <p id="search_controls">
      <%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_url(@query, @variety_postfix, 'relevant') %>
      |
      <%=link_to_unless @sortby == 'newest', _("Newest results first"), search_url(@query, @variety_postfix, 'newest') %>
      <% if @sortby == 'described' %>
      | <%= _('Recently described results first') %>
      <% end %>
    </p>
  <% end %>
</div>  <!-- header left -->

<% if @track_thing  && (@xapian_bodies_hits > 0 || @xapian_users_hits > 0 || @total_hits == 0)%>
  <div id="header_right">
    <h2>Track this search</h2>
    <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => false, :location => 'main' } %>
  </div>
<% end %>

<div style="clear:both;"></div>

<% if @total_hits == 0 %>
    <h2><%=@title %></h2>
<% end %>

<% if not @query.nil? %>
    <div class="results_section">
      <% if @xapian_bodies_hits > 0 %>
        <% if @xapian_bodies_hits == 1 && @page == 1 %>
          <h2 class="publicbody_results"><%= _('One public authority found') %></h2>
        <% else %>
          <h2 class="publicbody_results"><%= _('Public authorities {{start_count}} to {{end_count}} of {{total_count}}', :start_count => ((@page-1)*@bodies_per_page+1).to_s, :end_count => [@page*@bodies_per_page, @xapian_bodies.matches_estimated].min.to_s, :total_count => @xapian_bodies.matches_estimated.to_s) %></h2>
        <% end %>

        <div class="results_block">
          <% for result in @xapian_bodies.results %>
            <%= render :partial => 'public_body/body_listing_single', :locals => { :public_body => result[:model] }  %>
          <% end %>
        </div>

        <%= will_paginate WillPaginate::Collection.new(@page, @bodies_per_page, @xapian_bodies.matches_estimated) %>
      <% elsif @bodies && !@query.nil? && @xapian_bodies.results.size == 0 && @page == 1 %>
        <h2 class="publicbody_results"><%= _('No public authorities found') %></h2>
        <% if @spelling_correction %>
          <p id="did_you_mean"><%= _('Did you mean: {{correction}}', :correction => search_link(@spelling_correction, @postfix)) %></p>
        <% end %>
        <p><%= _('<a href="%s">Browse all</a> or <a href="%s">ask us to add one</a>.') % [list_public_bodies_default, help_requesting_path + '#missing_body'] %></p>
      <% end %>
    </div>

    <div class="results_section">
      <% if @xapian_users_hits > 0 %>
        <% if @xapian_users_hits == 1 && @page == 1 %>
            <h2 class="person_results"><%= _("One person found") %></h2>
        <% else %>
            <h2 class="person_results"><%= _("People {{start_count}} to {{end_count}} of {{total_count}}", :start_count => ((@page-1)*@users_per_page+1).to_s, :end_count =>  [@page*@users_per_page, @xapian_users.matches_estimated].min.to_s, :total_count =>  @xapian_users.matches_estimated.to_s) %></h2>
        <% end %>

        <div class="results_block">
          <% for result in @xapian_users.results %>
            <%= render :partial => 'user/user_listing_single', :locals => { :display_user => result[:model] } %>
          <% end %>
        </div>
      <% end %>
    </div>

    <div class="results_section">
      <% if @xapian_requests_hits > 0 %>
        <% if @xapian_requests_hits == 1 && @page == 1 %>
            <h2 class="foi_results"><%= _("One FOI request found") %></h2>
        <% else %>
            <h2 class="foi_results"><%= _("FOI requests {{start_count}} to {{end_count}} of {{total_count}}", :start_count => ((@page-1)*@requests_per_page+1).to_s, :end_count => [@page*@requests_per_page, @xapian_requests.matches_estimated].min.to_s, :total_count =>  @xapian_requests.matches_estimated.to_s) %></h2>
        <% end %>

        <div class="results_block">
          <% for result in @xapian_requests.results %>
            <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
          <% end %>
        </div>

        <%= will_paginate WillPaginate::Collection.new(@page, @requests_per_page, @xapian_requests.matches_estimated) %>
      <% end %>
    </div>
<% end %>

<% if @advanced %>
  <%= render :partial => 'general/advanced_search_tips' %>
<% end %>