From 4c141c7a2ce488865d6b0e3920a9c666eedbe309 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Thu, 23 Feb 2017 17:09:58 -0500 Subject: [PATCH 1/2] Added admin global company lookup for result data - currently a bug that is not displaying data --- .../app/controllers/dashboard_controller.rb | 17 +- .../app/views/dashboard/index.html.erb | 294 ++++++++++-------- 2 files changed, 179 insertions(+), 132 deletions(-) diff --git a/Pearlception/app/controllers/dashboard_controller.rb b/Pearlception/app/controllers/dashboard_controller.rb index 10a757e..047b1ce 100644 --- a/Pearlception/app/controllers/dashboard_controller.rb +++ b/Pearlception/app/controllers/dashboard_controller.rb @@ -2,7 +2,22 @@ class DashboardController < ApplicationController before_filter :deny_to_visitors def index - @results = Result.page(params[:page]).per(5) + #This is a temporary fix until runs and results models are properly discussed with bobby + #@results = Result.page(params[:page]).per(5) + if current_user.admin? + @results = Hash.new + names = (Company.pluck :company_name) - ["IVA"] + names.map!{|tenant| tenant.gsub(/'/,'').gsub(/\s/,'')} + names.each do + |name| + + Apartment::Tenant.switch!(name.gsub(/'/,'').gsub(/\s/,'')) + @results[name.gsub(/'/,'').gsub(/\s/,'')] = Run.page(params[:page]).per(5) + end + Apartment::Tenant.switch! + else + @results = Run.page(params[:page]).per(5) + end end diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index 4cbdef9..46aa466 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -87,142 +87,174 @@ <% if current_user.admin? %>

Recent Results From All Companies

+ +
+ <% ((Company.pluck :company_name) - ["IVA"]).each do |company_name| %> +
+ +
+
+
+ +
+
+ + + + + + + + + + + + +
+
+ <% @results[company_name.gsub(/'/,'').gsub(/\s/,'')].each_slice(1) do |row| %> + + <% row.each do |result| + run = Run.find(result.id) %> + + + + + + + + + + + + + + + + + + + + + + <% end %> + + <% end %> + + +
Run DateLocationHarvest TimeSupplierDistributorTotal ProcessedOtherOyster Info
+ <%= run.runDate %> + + <%= run.location ? run.location : "" %> + + <%= "" %> + + + <%= run.supplier ? run.supplier : "" %> + + <%= run.distributor ? run.distributor : "" %> + + "result" + + <%= run.other ? run.other : "" %> + + <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> +
+
+ +
+
+ <%= paginate @results[company_name.gsub(/'/,'').gsub(/\s/,'')] %>
+ <%= page_entries_info @results[company_name.gsub(/'/,'').gsub(/\s/,'')] %> +
+
+
+
+
+ <% end %> +
<% else %>

Recent Results

- <% end %> -
- -
-
- - <% if current_user.admin? %> - +
+
Company
+
+
+ + + + + + + + + + + + +
+
+ <% @results.each_slice(1) do |row| %> + + <% row.each do |result| + run = Run.find(result.id) %> + + + + + + + + + + + + + + + + + + + + + + <% end %> + <% end %> - - - - - - - - - - + + +
Run DateLocationHarvest TimeSupplierDistributorTotal ProcessedOtherOyster Info
+ <%= run.runDate %> + + <%= run.location ? run.location : "" %> + + <%= "" %> + + + <%= run.supplier ? run.supplier : "" %> + + <%= run.distributor ? run.distributor : "" %> + + "result" + + <%= run.other ? run.other : "" %> + + <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %> +
Run DateLocationHarvest TimeSupplierDistributorTotal ProcessedOtherOyster Info
+
+
+
+ <%= paginate @results %>
+ <%= page_entries_info @results %>
-
- - <% 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 %> - - - <%= #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 %> -
-
From c2e780ddf538e119df596fd6a2515de99d67d511 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Fri, 24 Feb 2017 14:37:43 -0500 Subject: [PATCH 2/2] Admin Global Data view Implemented --- .../app/controllers/dashboard_controller.rb | 9 ++++++++- Pearlception/app/views/dashboard/index.html.erb | 15 +++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Pearlception/app/controllers/dashboard_controller.rb b/Pearlception/app/controllers/dashboard_controller.rb index 047b1ce..02d741b 100644 --- a/Pearlception/app/controllers/dashboard_controller.rb +++ b/Pearlception/app/controllers/dashboard_controller.rb @@ -5,6 +5,7 @@ class DashboardController < ApplicationController #This is a temporary fix until runs and results models are properly discussed with bobby #@results = Result.page(params[:page]).per(5) if current_user.admin? + puts params @results = Hash.new names = (Company.pluck :company_name) - ["IVA"] names.map!{|tenant| tenant.gsub(/'/,'').gsub(/\s/,'')} @@ -12,8 +13,14 @@ class DashboardController < ApplicationController |name| Apartment::Tenant.switch!(name.gsub(/'/,'').gsub(/\s/,'')) - @results[name.gsub(/'/,'').gsub(/\s/,'')] = Run.page(params[:page]).per(5) + + if params[:company] == name + @results[name.gsub(/'/,'').gsub(/\s/,'')] = {results: Run.page(params[:page]).per(5), active: true, name: name} + else + @results[name.gsub(/'/,'').gsub(/\s/,'')] = {results: Run.page(params[:page]).per(5), active: false} + end end + #binding.pry Apartment::Tenant.switch! else @results = Run.page(params[:page]).per(5) diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index 46aa466..21783b8 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -89,15 +89,16 @@

Recent Results From All Companies

+ <% ((Company.pluck :company_name) - ["IVA"]).each do |company_name| %>
-
+
" class="panel-collapse collapse <%= (@results[company_name.gsub(/'/,'').gsub(/\s/,'')][:active] && @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:name] == company_name.gsub(/'/,'').gsub(/\s/,'') ) ? "in" : ""%>">
@@ -116,11 +117,12 @@
+
- <% @results[company_name.gsub(/'/,'').gsub(/\s/,'')].each_slice(1) do |row| %> + <% @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results].each_slice(1) do |row| %> <% row.each do |result| - run = Run.find(result.id) %> + run = result#Run.find(result.id) %>
<%= run.runDate %> @@ -169,13 +171,14 @@
- <%= paginate @results[company_name.gsub(/'/,'').gsub(/\s/,'')] %>
- <%= page_entries_info @results[company_name.gsub(/'/,'').gsub(/\s/,'')] %> + <%= paginate @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] , params: {company: company_name.gsub(/'/,'').gsub(/\s/,'')} %>
+ <%= page_entries_info @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] %>
+ <% end %> <% else %>