Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add search

  • Loading branch information...
commit ec0908723c1fccf05a217883ed66ad6af7a02ceb 1 parent 9210adb
Travis Dunn authored
3,223 app/assets/stylesheets/bootstrap.css
View
1,805 additions, 1,418 deletions not shown
18 app/controllers/search_controller.rb
View
@@ -0,0 +1,18 @@
+class SearchController < ApplicationController
+
+ def index
+ @query = params[:query]
+
+ if current_user.admin?
+ @web_accounts = WebAccount.where(:title => Regexp.new(@query))
+ @generic_accounts = GenericAccount.where(:title => Regexp.new(@query))
+ @licenses = SoftwareLicense.where(:title => Regexp.new(@query))
+ @notes = Note.where(:title => Regexp.new(@query))
+ else
+ @web_accounts = WebAccount.any_of({ :group_ids.in => current_user.group_ids }, { :group_ids => [] }).where(:title => Regexp.new(@query))
+ @generic_accounts = GenericAccount.any_of({ :group_ids.in => current_user.group_ids }, { :group_ids => [] }).where(:title => Regexp.new(@query))
+ @licenses = SoftwareLicense.any_of({ :group_ids.in => current_user.group_ids }, { :group_ids => [] }).where(:title => Regexp.new(@query))
+ @notes = Note.any_of({ :group_ids.in => current_user.group_ids }, { :group_ids => [] }).where(:title => Regexp.new(@query))
+ end
+ end
+end
3  app/views/layouts/application.html.erb
View
@@ -39,6 +39,9 @@
<li <%= active_class_if(software_licenses_path) %> ><%= link_to 'Licenses', software_licenses_path %></li>
<li <%= active_class_if(notes_path) %> ><%= link_to 'Notes', notes_path %></li>
</ul>
+ <form class="navbar-search pull-right" action="<%= search_path %>">
+ <input type="text" name="query" class="search-query" placeholder="Search">
+ </form>
</div>
</div>
105 app/views/search/index.html.erb
View
@@ -0,0 +1,105 @@
+<div class="page-header">
+ <h3>
+ Results for &ldquo;<%= @query %>&rdquo;
+ </h3>
+</div>
+
+<% unless @web_accounts.empty? %>
+<h4>Web Accounts</h4>
+<div class="web-accounts">
+ <table class='table table-striped table-bordered table-condensed'>
+ <thead>
+ <tr>
+ <th>Title</th>
+ <th>Username</th>
+ <th>Last Modified</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @web_accounts.each do |account| %>
+ <tr>
+ <td><%= account.title %></td>
+ <td><%= account.username %></td>
+ <td><%= fmt_datetime(account.updated_at) %></td>
+ <td><%= link_to 'View', accounts_web_account_path(account) %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+</div>
+<% end %>
+
+<% unless @generic_accounts.empty? %>
+<h4>Generic Accounts</h4>
+<div class="generic-accounts">
+ <table class='table table-striped table-bordered table-condensed'>
+ <thead>
+ <tr>
+ <th>Title</th>
+ <th>Username</th>
+ <th>Last Modified</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @generic_accounts.each do |account| %>
+ <tr>
+ <td><%= account.title %></td>
+ <td><%= account.username %></td>
+ <td><%= fmt_datetime(account.updated_at) %></td>
+ <td><%= link_to 'View', accounts_generic_account_path(account) %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+</div>
+<% end %>
+
+<% unless @licenses.empty? %>
+<h4>Software Licenses</h4>
+<div class="licenses">
+ <table class='table table-striped table-bordered table-condensed'>
+ <thead>
+ <tr>
+ <th class='title'>Title</th>
+ <th>Last Modified</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @licenses.each do |license| %>
+ <tr>
+ <td><%= license.title %></td>
+ <td><%= fmt_datetime(license.updated_at) %></td>
+ <td><%= link_to 'View', software_license_path(license) %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+</div>
+<% end %>
+
+<% unless @notes.empty? %>
+<h4>Notes</h4>
+<div class="notes">
+ <table class='table table-striped table-bordered table-condensed'>
+ <thead>
+ <tr>
+ <th class='title'>Title</th>
+ <th>Last Modified</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @notes.each do |note| %>
+ <tr>
+ <td><%= note.title %></td>
+ <td><%= fmt_datetime(note.updated_at) %></td>
+ <td><%= link_to 'View', note_path(note) %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+</div>
+<% end %>
4 config/routes.rb
View
@@ -3,6 +3,8 @@
get 'login', :to => 'sessions#new', :as => 'login'
get 'logout', :to => 'sessions#destroy', :as => 'logout'
+ get 'search', :to => 'search#index'
+
resources :sessions
resources :users
@@ -23,5 +25,5 @@
resources :groups, :except => [ :show ]
end
- root :to => 'notes#index'
+ root :to => 'accounts/web_accounts#index'
end
7 test/controllers/search_controller_test.rb
View
@@ -0,0 +1,7 @@
+require "minitest_helper"
+
+describe SearchController do
+ # it "must be a real test" do
+ # flunk "Need real tests"
+ # end
+end
9 test/helpers/admin/groups_helper_test.rb
View
@@ -1,9 +0,0 @@
-require "minitest_helper"
-
-describe Admin::GroupsHelper do
-
- it "must be a real test" do
- flunk "Need real tests"
- end
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.