From 80d4df4b349fe59d481116950c6e5a793eeef140 Mon Sep 17 00:00:00 2001 From: cole m alban Date: Wed, 22 Feb 2017 16:22:05 -0500 Subject: [PATCH 1/5] Add migration script for aws->local server data migration --- Pearlception/config/database.yml | 11 ++++----- migrate.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 migrate.rb diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index d5624af..025b1d5 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -13,9 +13,6 @@ default: &default adapter: mysql2 encoding: utf8 pool: 5 - username: <%= ENV['TEST_USER'] %> - password: <%= ENV['TEST_PASS'] %> - socket: <%= ENV['TEST_SOCKET'] %> stats_development: &stats adapter: mysql2 @@ -34,8 +31,8 @@ stats_test: development: <<: *default database: Pearlception_development - username: root - password: Kemitscafe1 + username: bmv + password: 1156244terps! # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -43,8 +40,8 @@ development: test: <<: *default database: Pearlception_test - username: root - password: Kemitscafe1 + username: bmv + password: 1156244terps! # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is diff --git a/migrate.rb b/migrate.rb new file mode 100644 index 0000000..a60ee60 --- /dev/null +++ b/migrate.rb @@ -0,0 +1,40 @@ +#Script to migrate things to the bmv server from a csv file + +require 'mysql2' +require 'csv' + + +class Run + + attr_accessor :id, :run_date, :location, :harvest_time, :supplier, :distributor, :other, :machine_id + + def initialize(id, run_date, location, harvest_time, supplier, distributor, other, machine_id) + @id = id + @run_date = run_date + @location = location + @harvest_time = harvest_time + @supplier = supplier + @distributor = distributor + @other = other + @machine_id = machine_id + end + +end + +client = Mysql2::Client.new( + #INSERT LOGIN INFO HERE + ) +runs = [] +CSV.foreach("#{ARGV[0]}") do |row| + runs.push(Run.new(*row)) unless row[0] == "run_id" +end +runs.each do |run| + puts run.inspect + query = "INSERT INTO runs (id, runDate, location, harvest_time, supplier, distributor, + other, machine_id, created_at, updated_at) + VALUES + (#{run.id},NOW(), \"UMD\" ,\"#{run.location}\",\"#{run.supplier}\", + \"#{run.distributor}\",\"\",1,NOW(),NOW());" + res = client.query(query) + puts res +end From 4783f37dccd8ca1b733803f90a22812f0e111f05 Mon Sep 17 00:00:00 2001 From: cole m alban Date: Thu, 23 Feb 2017 12:03:59 -0500 Subject: [PATCH 2/5] Removed dead code from apartment config file --- Pearlception/config/initializers/apartment.rb | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Pearlception/config/initializers/apartment.rb b/Pearlception/config/initializers/apartment.rb index 73051b9..dc08608 100644 --- a/Pearlception/config/initializers/apartment.rb +++ b/Pearlception/config/initializers/apartment.rb @@ -47,32 +47,13 @@ Apartment.configure do |config| # end # end # - + names = (Company.pluck :company_name) - ["IVA"] - #client = Mysql2::Client.new( - # :adapter => "mysql2", - # :host => ENV['STATS_DB_URL'], - # :username => ENV['STATS_DB_USER'], - # :password => ENV['STATS_DB_PASS'] - #) - names.map!{|tenant| tenant.gsub(/'/,'').gsub(/\s/,'')} - #names.each { - # |tenant| - # binding.pry - # if ENV['RAILS_ENV'] == "production" - # client.query("CREATE DATABASE IF NOT EXISTS #{tenant};") - # else - # client.query("CREATE DATABASE IF NOT EXISTS #{tenant};") - # end - #} - # client.close config.tenant_names = names - #names = (Company.pluck :company_name) - ["IVA"] -# # ==> PostgreSQL only options # Specifies whether to use PostgreSQL schemas or create a new database per Tenant. From eab7216058517978134aff3401642eb56b3f7eef Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Thu, 23 Feb 2017 12:18:44 -0500 Subject: [PATCH 3/5] Add auto switch to default db for admin user --- Pearlception/app/models/user.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb index 486d2eb..1c27f7e 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -5,10 +5,12 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - + def after_database_authentication if !self.admin Apartment::Tenant.switch!(Company.find(self.company_id).company_name.gsub(/'/,'').gsub(/\s/,'')) + else + Apartment::Tenant.switch! end end end From 4c141c7a2ce488865d6b0e3920a9c666eedbe309 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Thu, 23 Feb 2017 17:09:58 -0500 Subject: [PATCH 4/5] 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 5/5] 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 %>