From 384033bfe655dbf0d845777b88256a7ab12cf223 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Fri, 20 Jan 2017 11:47:52 -0500 Subject: [PATCH 1/2] Added Index Route to Show Result Oysters - set up index route to show osyters of a specific result - set up index view, controller method, and route - commented out debug console --- Pearlception/Gemfile | 2 + Pearlception/Gemfile.lock | 2 + .../app/assets/javascripts/application.js | 2 + .../app/assets/javascripts/oysters.coffee | 3 + .../app/assets/javascripts/oysters.js | 3 + .../app/assets/stylesheets/application.css | 2 + .../app/assets/stylesheets/oysters.scss | 3 + .../app/controllers/oysters_controller.rb | 10 ++ Pearlception/app/helpers/oysters_helper.rb | 2 + Pearlception/app/models/oyster.rb | 1 + .../app/views/dashboard/index.html.erb | 4 + Pearlception/app/views/oysters/index.html.erb | 128 ++++++++++++++++++ Pearlception/app/views/oysters/show.html.erb | 1 + Pearlception/config/routes.rb | 3 + .../controllers/oysters_controller_test.rb | 9 ++ 15 files changed, 175 insertions(+) create mode 100644 Pearlception/app/assets/javascripts/oysters.coffee create mode 100644 Pearlception/app/assets/javascripts/oysters.js create mode 100644 Pearlception/app/assets/stylesheets/oysters.scss create mode 100644 Pearlception/app/controllers/oysters_controller.rb create mode 100644 Pearlception/app/helpers/oysters_helper.rb create mode 100644 Pearlception/app/views/oysters/index.html.erb create mode 100644 Pearlception/app/views/oysters/show.html.erb create mode 100644 Pearlception/test/controllers/oysters_controller_test.rb diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile index 882f710..9db7abe 100644 --- a/Pearlception/Gemfile +++ b/Pearlception/Gemfile @@ -38,6 +38,8 @@ gem 'bcrypt', '~> 3.1.7' gem 'devise' #for pagination gem 'kaminari' +#for popovers and tooltips +gem 'bootstrap-popover-rails' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock index e375e40..e1dd0bc 100644 --- a/Pearlception/Gemfile.lock +++ b/Pearlception/Gemfile.lock @@ -47,6 +47,7 @@ GEM bcrypt (3.1.11) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-popover-rails (0.1.0) builder (3.2.2) byebug (9.0.6) coderay (1.1.1) @@ -206,6 +207,7 @@ PLATFORMS DEPENDENCIES awesome_rails_console bcrypt (~> 3.1.7) + bootstrap-popover-rails byebug coffee-rails (~> 4.2) devise diff --git a/Pearlception/app/assets/javascripts/application.js b/Pearlception/app/assets/javascripts/application.js index 159326e..fe47c91 100644 --- a/Pearlception/app/assets/javascripts/application.js +++ b/Pearlception/app/assets/javascripts/application.js @@ -13,3 +13,5 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap/bootstrap-rails-tooltip +//= require bootstrap/bootstrap-rails-popover diff --git a/Pearlception/app/assets/javascripts/oysters.coffee b/Pearlception/app/assets/javascripts/oysters.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/Pearlception/app/assets/javascripts/oysters.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/Pearlception/app/assets/javascripts/oysters.js b/Pearlception/app/assets/javascripts/oysters.js new file mode 100644 index 0000000..7208817 --- /dev/null +++ b/Pearlception/app/assets/javascripts/oysters.js @@ -0,0 +1,3 @@ +$(function () { + $('[data-toggle="popover"]').popover(); +}) diff --git a/Pearlception/app/assets/stylesheets/application.css b/Pearlception/app/assets/stylesheets/application.css index 0ebd7fe..a75d597 100644 --- a/Pearlception/app/assets/stylesheets/application.css +++ b/Pearlception/app/assets/stylesheets/application.css @@ -12,4 +12,6 @@ * *= require_tree . *= require_self + *= require bootstrap/bootstrap-rails-tooltip + *= require bootstrap/bootstrap-rails-popover */ diff --git a/Pearlception/app/assets/stylesheets/oysters.scss b/Pearlception/app/assets/stylesheets/oysters.scss new file mode 100644 index 0000000..fd42caa --- /dev/null +++ b/Pearlception/app/assets/stylesheets/oysters.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Oysters controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/Pearlception/app/controllers/oysters_controller.rb b/Pearlception/app/controllers/oysters_controller.rb new file mode 100644 index 0000000..a62305a --- /dev/null +++ b/Pearlception/app/controllers/oysters_controller.rb @@ -0,0 +1,10 @@ +class OystersController < ApplicationController + def show + end + + def index + @oysters = Oyster.where(:run_id => params[:result_id]) + @oysters_count = @oysters.count + @oysters = @oysters.page(params[:page]).per(5) + end +end diff --git a/Pearlception/app/helpers/oysters_helper.rb b/Pearlception/app/helpers/oysters_helper.rb new file mode 100644 index 0000000..9b44a08 --- /dev/null +++ b/Pearlception/app/helpers/oysters_helper.rb @@ -0,0 +1,2 @@ +module OystersHelper +end diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb index 3514394..cfe3ccb 100644 --- a/Pearlception/app/models/oyster.rb +++ b/Pearlception/app/models/oyster.rb @@ -8,4 +8,5 @@ class Oyster < ApplicationRecord :password => ENV['STATS_DB_PASS'], :database => "main" ) + scope :run_id, -> (id) { where run_id: id.to_i } end diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index accc7ef..56fc2c9 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -103,6 +103,7 @@ Distributor Total Processed Other + Oyster Info @@ -198,6 +199,9 @@ <%= run.other ? run.other : "" %> + + <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> + <% end %> <% end %> diff --git a/Pearlception/app/views/oysters/index.html.erb b/Pearlception/app/views/oysters/index.html.erb new file mode 100644 index 0000000..bb4cc5b --- /dev/null +++ b/Pearlception/app/views/oysters/index.html.erb @@ -0,0 +1,128 @@ +<%= stylesheet_link_tag "dashboard" %>_ + + + + +
+
+ +
+ <%= link_to "Back", root_path( :page => params[:page_num]), :class => "btn btn-primary" %> +

Results of <%= Run.find(params[:result_id]).runDate %>

+

Processed Oysters: <%= @oysters_count %>

+ <% if @oysters.empty? %> +
+

No Oysters Processed

+
+ <% else %> +
+ + + + + + + + + + + + <% @oysters.each_slice(1) do |row| %> + + <% row.each do |oyster|%> + + + + + + + + + + + + + + + + <% end %> + + <% end %> + +
Oyster GradeVolumeLengthWidthHeight
+ <%= oyster.grade %> + + <%= oyster.volume %> + + <%= oyster.length %> + + <%= oyster.width %> + + <%= oyster.height %> +
+
+ <% end %> + <% if !@oysters.empty? %> +
+
+ <%= paginate @oysters %>
+ <%= page_entries_info @oysters %> +
+
+ <% end %> +
+
+
+ <%= javascript_include_tag "bootstrap.min" %>_ + diff --git a/Pearlception/app/views/oysters/show.html.erb b/Pearlception/app/views/oysters/show.html.erb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Pearlception/app/views/oysters/show.html.erb @@ -0,0 +1 @@ + diff --git a/Pearlception/config/routes.rb b/Pearlception/config/routes.rb index 1a1ae89..17e3991 100644 --- a/Pearlception/config/routes.rb +++ b/Pearlception/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do + get 'oysters/show' + get 'oysters/index' + root "dashboard#index" resources :runs resources :companies diff --git a/Pearlception/test/controllers/oysters_controller_test.rb b/Pearlception/test/controllers/oysters_controller_test.rb new file mode 100644 index 0000000..eece1f2 --- /dev/null +++ b/Pearlception/test/controllers/oysters_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class OystersControllerTest < ActionDispatch::IntegrationTest + test "should get show" do + get oysters_show_url + assert_response :success + end + +end From 3f62c9f03c4e06937df4d0fc07d7cc5a5ff25a63 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Fri, 20 Jan 2017 11:48:10 -0500 Subject: [PATCH 2/2] forgotten files for previous commit --- .../app/views/dashboard/index.html.erb | 253 +++++++++--------- .../app/views/layouts/application.html.erb | 2 +- Pearlception/app/views/oysters/index.html.erb | 80 +++--- 3 files changed, 173 insertions(+), 162 deletions(-) diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index 56fc2c9..150e22e 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -89,131 +89,138 @@ <% else %>

Recent Results

<% end %> -
+
- - - <% if current_user.admin? %> - - <% end %> - - - - - - - - - - - - <% if current_user.admin? %> - <% @results.each_slice(1) do |row| %> - - <% row.each do |result| - run = Run.find(result.id) - #company = Company.find(run.company_id) - %> - - - - - - - - - - - - - - - - - - - - - - - - - <% end %> - - <% end %> - <% else %> - <% @results.each_slice(1) do |row| %> - - <% row.each do |result| - run = Run.find(result.id) %> - - - - - - - - - - - - - - - - - - - - - - <% end %> - - <% end %> - <% end %> - -
CompanyRun DateLocationHarvest TimeSupplierDistributorTotal ProcessedOtherOyster Info
- <%= #company.company_name - "Fake Industries" %> - - <%= run.runDate %> - - <%= run.location ? run.location : "" %> - - <%= "" %> - - - <%= run.supplier ? run.supplier : "" %> - - <%= run.distributor ? run.distributor : "" %> - - <%= result.total %> - - <%= run.other ? run.other : "" %> -
- <%= run.runDate %> - - <%= run.location ? run.location : "" %> - - <%= "" %> - - - <%= run.supplier ? run.supplier : "" %> - - <%= run.distributor ? run.distributor : "" %> - - <%= result.total %> - - <%= run.other ? run.other : "" %> - - <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> -
-
-
- <%= paginate @results %>
- <%= page_entries_info @results %> +
+ + + <% if current_user.admin? %> + Company + <% end %> + Run Date + Location + Harvest Time + Supplier + Distributor + Total Processed + Other + Oyster Info + +
-
+
+ + <% if current_user.admin? %> + <% @results.each_slice(1) do |row| %> + + <% row.each do |result| + run = Run.find(result.id) + #company = Company.find(run.company_id) + %> + + + + <%= #company.company_name + "Fake Industries" %> + + + + + <%= run.runDate %> + + + + + <%= run.location ? run.location : "" %> + + + + + <%= "" %> + + + + + + <%= run.supplier ? run.supplier : "" %> + + + + + <%= run.distributor ? run.distributor : "" %> + + + + + <%= result.total %> + + + + + <%= run.other ? run.other : "" %> + + + <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> + + <% end %> + + <% end %> + <% else %> + <% @results.each_slice(1) do |row| %> + + <% row.each do |result| + run = Run.find(result.id) %> + + + <%= run.runDate %> + + + + + <%= run.location ? run.location : "" %> + + + + + <%= "" %> + + + + + + <%= run.supplier ? run.supplier : "" %> + + + + + <%= run.distributor ? run.distributor : "" %> + + + + + <%= result.total %> + + + + + <%= run.other ? run.other : "" %> + + + <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> + + <% end %> + + <% end %> + <% end %> + +
+ +
+
+
+ <%= paginate @results %>
+ <%= page_entries_info @results %> +
diff --git a/Pearlception/app/views/layouts/application.html.erb b/Pearlception/app/views/layouts/application.html.erb index 5978e7f..2dc8dbc 100644 --- a/Pearlception/app/views/layouts/application.html.erb +++ b/Pearlception/app/views/layouts/application.html.erb @@ -16,7 +16,7 @@ <%= yield %> - <%= debug(params) if Rails.env.development? %> + diff --git a/Pearlception/app/views/oysters/index.html.erb b/Pearlception/app/views/oysters/index.html.erb index bb4cc5b..81bee88 100644 --- a/Pearlception/app/views/oysters/index.html.erb +++ b/Pearlception/app/views/oysters/index.html.erb @@ -68,54 +68,58 @@ <% else %>
- - - - - - - - - - - <% @oysters.each_slice(1) do |row| %> - - <% row.each do |oyster|%> +
+
+ + + + + + + + + +
+
+ <% @oysters.each_slice(1) do |row| %> + + <% row.each do |oyster|%> - - + + - - + + - - + + - - + + - - - <% end %> - - <% end %> - + + + <% end %> + + <% end %> + +
Oyster GradeVolumeLengthWidthHeight
Oyster GradeVolumeLengthWidthHeight
- <%= oyster.grade %> - + <%= oyster.grade %> + - <%= oyster.volume %> - + <%= oyster.volume %> + - <%= oyster.length %> - + <%= oyster.length %> + - <%= oyster.width %> - + <%= oyster.width %> + - <%= oyster.height %> -
+ <%= oyster.height %> +
<% end %> <% if !@oysters.empty? %>
-
+
<%= paginate @oysters %>
<%= page_entries_info @oysters %>