Skip to content
Browse files

list

  • Loading branch information...
1 parent b0fae73 commit 1091c406005398f1e98cbb3cc39f6bb1f58f23ce Sébastien Gruhier committed
View
23 app/assets/stylesheets/application.css.less
@@ -11,5 +11,26 @@
#map img {
max-width: none;
}
+
body,p,div, table, label, input, select, textarea ,button {font-family: 'Open Sans', sans-serif;}
-h1,h2,h3,h4,h5 {font-family: 'Convergence', sans-serif;}
+h1,h2,h3,h4,h5 {font-family: 'Convergence', sans-serif;}
+
+.form-horizontal .help-block {
+ font-style: italic;
+ margin-top: -5px;
+ color: #888;
+}
+
+.centered {
+ text-align:center
+}
+
+h2 {
+ margin-top: 20px;
+ text-align: center;
+}
+
+.label-info {
+ margin-bottom: 3px;
+ line-height: 11px
+}
View
3 app/assets/stylesheets/medications.css.scss
@@ -1,3 +0,0 @@
-// Place all the styles related to the Medications controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -1,56 +0,0 @@
-body {
- background-color: #fff;
- color: #333;
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px; }
-
-p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px; }
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px; }
-
-a {
- color: #000;
- &:visited {
- color: #666; }
- &:hover {
- color: #fff;
- background-color: #000; } }
-
-div {
- &.field, &.actions {
- margin-bottom: 10px; } }
-
-#notice {
- color: green; }
-
-.field_with_errors {
- padding: 2px;
- background-color: red;
- display: table; }
-
-#error_explanation {
- width: 450px;
- border: 2px solid red;
- padding: 7px;
- padding-bottom: 0;
- margin-bottom: 20px;
- background-color: #f0f0f0;
- h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- margin-bottom: 0px;
- background-color: #c00;
- color: #fff; }
- ul li {
- font-size: 12px;
- list-style: square; } }
View
114 app/assets/stylesheets/searchform.css
@@ -0,0 +1,114 @@
+/* search form
+-------------------------------------- */
+.searchform {
+ display: block;
+ position: relative;
+
+ zoom: 1; /* ie7 hack for display:inline-block */
+ *display: inline;
+ border: solid 1px #d2d2d2;
+ padding: 3px 5px;
+ margin-top: 25px;
+
+ -webkit-border-radius: 2em;
+ -moz-border-radius: 2em;
+ border-radius: 2em;
+
+ -webkit-box-shadow: 0 1px 0px rgba(0,0,0,.1);
+ -moz-box-shadow: 0 1px 0px rgba(0,0,0,.1);
+ box-shadow: 0 1px 0px rgba(0,0,0,.1);
+
+ background: #f1f1f1;
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
+ background: -moz-linear-gradient(top, #fff, #ededed);
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed'); /* ie7 */
+ -ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed'); /* ie8 */
+}
+.searchform input {
+ font: normal 12px/100% Arial, Helvetica, sans-serif;
+ margin-bottom: 0px;
+}
+.searchform .searchfield {
+ background: #fff;
+ padding: 6px 6px 6px 8px;
+ width: 202px;
+
+ border: solid 1px #bcbbbb;
+ outline: none;
+
+ -webkit-border-radius: 2em;
+ -moz-border-radius: 2em;
+ border-radius: 2em;
+
+ -moz-box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
+ -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
+ box-shadow: inset 0 1px 2px rgba(0,0,0,.2);
+}
+.searchform .searchbutton {
+ color: #fff;
+ border: solid 1px #494949;
+ font-size: 11px;
+ height: 27px;
+ width: 27px;
+ text-shadow: 0 1px 1px rgba(0,0,0,.6);
+
+ -webkit-border-radius: 2em;
+ -moz-border-radius: 2em;
+ border-radius: 2em;
+
+ background: #5f5f5f;
+ background: -webkit-gradient(linear, left top, left bottom, from(#9e9e9e), to(#454545));
+ background: -moz-linear-gradient(top, #9e9e9e, #454545);
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#9e9e9e', endColorstr='#454545'); /* ie7 */
+ -ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#9e9e9e', endColorstr='#454545'); /* ie8 */
+
+ position: absolute;
+ top: 4px;
+ right: 6px;
+}
+.searchform .search-query {
+ width: 94%;
+ padding: 5px 0 5px 10px;
+}
+
+@media (max-width: 320px) {
+ .searchform .search-query {
+ width: 95%;
+ }
+ .searchform {
+ width: 100%;
+ }
+}
+
+@media (max-width: 480px) {
+ .searchform .search-query {
+ width: 96%;
+ }
+ h2 {
+ font-size: 20px;
+ }
+
+
+}
+
+@media (max-width: 767px) {
+ .searchform .search-query {
+ width: 96%;
+ }
+ .searchform {
+ width: 100%;
+ }
+ h2 {
+ font-size: 20px;
+ }
+}
+
+@media (min-width: 768px) {
+ .searchform {
+ width: 727px;
+ margin:25px auto 10px auto;
+ }
+ .searchform .search-query {
+ width: 717px;
+ }
+}
View
17 app/controllers/medications_controller.rb
@@ -1,17 +1,23 @@
class MedicationsController < ApplicationController
+ before_filter :authenticate, :only => :list
+
# GET /medications
# GET /medications.json
def index
- @medications = Medication.page(params[:page]).per(10)
-
respond_to do |format|
format.html # index.html.erb
format.json { render json: @medications }
end
end
+ def list
+ @medications = Medication.page(params[:page]).per(10)
+ end
+
+
# GET /medications/search
def elastic_search
+ @search = params[:q]
@medications = Medication.elastic_search params
@facets = @medications.facets['secondary_effects']["terms"]
@@ -101,4 +107,11 @@ def destroy
format.json { head :ok }
end
end
+
+private
+ def authenticate
+ authenticate_or_request_with_http_basic("Documents Realm") do |username, password|
+ username == "admin" && password == "top_secret"
+ end
+ end
end
View
2 app/views/layouts/application.html.erb
@@ -3,7 +3,7 @@
<head>
<title>BBPHealth</title>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Convergence|Open+Sans">
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
View
16 app/views/medications/_list.html.erb
@@ -3,7 +3,9 @@
<th>Name</th>
<th>Generic name</th>
<th>Secondary effects</th>
- <th></th>
+ <% if admin_mode %>
+ <th></th>
+ <% end %>
</tr>
<% @medications.each do |medication| %>
@@ -15,11 +17,13 @@
<span class="label label-info"><%= tag %></span>
<% end %>
</td>
- <td>
- <%= link_to 'Show', medication_path(medication.slug) %> |
- <%= link_to 'Edit', edit_medication_path(medication.slug) %> |
- <%= link_to 'Destroy', medication_path(medication.slug), confirm: 'Are you sure?', method: :delete %>
- </td>
+ <% if admin_mode %>
+ <td>
+ <%= link_to 'Show', medication_path(medication.slug) %> |
+ <%= link_to 'Edit', edit_medication_path(medication.slug) %> |
+ <%= link_to 'Destroy', medication_path(medication.slug), confirm: 'Are you sure?', method: :delete %>
+ </td>
+ <% end %>
</tr>
<% end %>
</table>
View
6 app/views/medications/elastic_search.html.erb
@@ -1,6 +1,6 @@
-<h1>Elastic Search results medications</h1>
+<h2>Search results for "<%= @search %>"</h2>
-<%= render 'list' %>
+<%= render 'list', admin_mode: false %>
<%= render 'elastic_search_facets' %>
<br />
-<%= link_to 'New Medication', new_medication_path, :class=>"btn" %>
+<%= link_to 'Or add a new medication', new_medication_path, :class=>"link" %>
View
22 app/views/medications/index.html.erb
@@ -1,18 +1,10 @@
-<h1>Listing medications</h1>
+<h2>Search for medications</h2>
-<%= form_tag ("/medications/elastic_search"), :method => 'get', :class => 'form-horizontal' do %>
- <div class="control-group">
- <label class="control-label" for="input01"> <%= label_tag :elastic_query %></label>
- <div class="controls">
- <%= text_field_tag :q, params[:q], :class => "input-xlarge" %>
- <%= submit_tag :search, :class => 'btn btn-success' %>
- </div>
- </div>
+<%= form_tag ("/medications/elastic_search"), :method => 'get', :class => 'searchform' do %>
+ <%= text_field_tag :q, params[:q], :class => "input-medium search-query" %>
+ <%= submit_tag :search, :class => 'searchbutton', :value => "Go" %>
<% end %>
-
-
-<%= render 'list' %>
-
<br />
-
-<%= link_to 'New Medication', new_medication_path, :class=>"btn" %>
+<div class="centered">
+ <%= link_to 'or add a new medication', new_medication_path, :class=>"link" %>
+<div>
View
2 app/views/medications/list.html.erb
@@ -0,0 +1,2 @@
+<h1>Medication listing</h1>
+<%= render 'list' %>
View
5 config/routes.rb
@@ -2,7 +2,10 @@
match "medications/elastic_search" => "medications#elastic_search"
resources :medications do
- collection { get :search }
+ collection do
+ get :search
+ get :list
+ end
end
root :to => "medications#index"
View
19 spec/controllers/medications_controller_spec.rb
@@ -36,7 +36,7 @@ def valid_attributes
it "assigns all medications as @medications" do
medication = Medication.create! valid_attributes
get :index
- assigns(:medications).should eq([medication])
+ response.should be_success
end
end
@@ -159,4 +159,21 @@ def valid_attributes
end
end
+ describe "GET list" do
+ it "assigns all medications as @medications if authenticated" do
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("admin", "top_secret")
+
+ medication = Medication.create! valid_attributes
+ get :list
+ response.should be_success
+ assigns(:medications).should eq([medication])
+ end
+
+ it "doen't assign all medications as @medications if not authenticated" do
+ get :list
+ response.should_not be_success
+ end
+ end
+
+
end

0 comments on commit 1091c40

Please sign in to comment.
Something went wrong with that request. Please try again.