mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 11:47:41 +00:00
Pre merge
This commit is contained in:
commit
9726f8529e
@ -2,7 +2,34 @@ class DashboardController < ApplicationController
|
||||
before_filter :deny_to_visitors
|
||||
|
||||
def index
|
||||
<<<<<<< HEAD
|
||||
@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?
|
||||
puts params
|
||||
@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/,''))
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
>>>>>>> 66dfc7d12c7a612332c9b8de8f32df39a0d362ce
|
||||
end
|
||||
|
||||
def deny_to_visitors
|
||||
|
||||
@ -9,6 +9,8 @@ class User < ApplicationRecord
|
||||
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
|
||||
|
||||
@ -87,17 +87,24 @@
|
||||
|
||||
<% if current_user.admin? %>
|
||||
<h2 class="sub-header">Recent Results From All Companies</h2>
|
||||
<% else %>
|
||||
<h2 class="sub-header">Recent Results</h2>
|
||||
<% end %>
|
||||
|
||||
<div class="panel-group" id="accordion">
|
||||
<span hidden><%= @i = 1 %></span>
|
||||
<% ((Company.pluck :company_name) - ["IVA"]).each do |company_name| %>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title text-center">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<%="#{@i}"%>">
|
||||
<%= company_name %> </a>
|
||||
</h3>
|
||||
</div>
|
||||
<div id="collapse<%="#{@i}"%>" class="panel-collapse collapse <%= (@results[company_name.gsub(/'/,'').gsub(/\s/,'')][:active] && @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:name] == company_name.gsub(/'/,'').gsub(/\s/,'') ) ? "in" : ""%>">
|
||||
<div class="panel-body">
|
||||
<div class="table-responsive panel panel-primary">
|
||||
<table class="table table-striped">
|
||||
<div class="panel-heading">
|
||||
<thead>
|
||||
<tr>
|
||||
<% if current_user.admin? %>
|
||||
<th>Company</th>
|
||||
<% end %>
|
||||
<th>Run Date</th>
|
||||
<th>Location</th>
|
||||
<th>Harvest Time</th>
|
||||
@ -110,21 +117,12 @@
|
||||
</thead>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<span hidden><%= Apartment::Tenant.switch!(company_name.gsub(/'/,'').gsub(/\s/,'')) %></span>
|
||||
<tbody>
|
||||
<% if current_user.admin? %>
|
||||
<% @results.each_slice(1) do |row| %>
|
||||
<% @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results].each_slice(1) do |row| %>
|
||||
<tr>
|
||||
<% row.each do |result|
|
||||
run = Run.find(result.id)
|
||||
#company = Company.find(run.company_id)
|
||||
%>
|
||||
|
||||
<!-- company name -->
|
||||
<td>
|
||||
<%= #company.company_name
|
||||
"Fake Industries" %>
|
||||
</td>
|
||||
|
||||
run = result#Run.find(result.id) %>
|
||||
<!-- run date -->
|
||||
<td>
|
||||
<%= run.runDate %>
|
||||
@ -153,7 +151,7 @@
|
||||
|
||||
<!-- total processed -->
|
||||
<td>
|
||||
<%= result.total %>
|
||||
"result"
|
||||
</td>
|
||||
|
||||
<!-- other -->
|
||||
@ -166,7 +164,43 @@
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</div>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="center-block">
|
||||
<div class="col-sm-6 col-sm-offset-3 panel panel-primary" align="center">
|
||||
<%= paginate @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] , params: {company: company_name.gsub(/'/,'').gsub(/\s/,'')} %></br>
|
||||
<%= page_entries_info @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span hidden><%= @i = @i + 1%></span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% else %>
|
||||
<h2 class="sub-header">Recent Results</h2>
|
||||
<div class="table-responsive panel panel-primary">
|
||||
<table class="table table-striped">
|
||||
<div class="panel-heading">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Run Date</th>
|
||||
<th>Location</th>
|
||||
<th>Harvest Time</th>
|
||||
<th>Supplier</th>
|
||||
<th>Distributor</th>
|
||||
<th>Total Processed</th>
|
||||
<th>Other</th>
|
||||
<th>Oyster Info</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<tbody>
|
||||
<% @results.each_slice(1) do |row| %>
|
||||
<tr>
|
||||
<% row.each do |result|
|
||||
@ -199,7 +233,7 @@
|
||||
|
||||
<!-- total processed -->
|
||||
<td>
|
||||
<%= result.total %>
|
||||
"result"
|
||||
</td>
|
||||
|
||||
<!-- other -->
|
||||
@ -212,7 +246,6 @@
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</div>
|
||||
</table>
|
||||
@ -223,6 +256,8 @@
|
||||
<%= page_entries_info @results %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -31,8 +31,13 @@ stats_test:
|
||||
development:
|
||||
<<: *default
|
||||
database: Pearlception_development
|
||||
<<<<<<< HEAD
|
||||
username: <%= ENV['DEV_DB_USER']%>
|
||||
password: <%= ENV['DEV_DB_PASS']%>
|
||||
=======
|
||||
username: bmv
|
||||
password: 1156244terps!
|
||||
>>>>>>> 66dfc7d12c7a612332c9b8de8f32df39a0d362ce
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
@ -40,8 +45,13 @@ development:
|
||||
test:
|
||||
<<: *default
|
||||
database: Pearlception_test
|
||||
<<<<<<< HEAD
|
||||
username: <%= ENV['DEV_DB_USER']%>
|
||||
password: <%= ENV['DEV_DB_PASS']%>
|
||||
=======
|
||||
username: bmv
|
||||
password: 1156244terps!
|
||||
>>>>>>> 66dfc7d12c7a612332c9b8de8f32df39a0d362ce
|
||||
|
||||
# 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
|
||||
|
||||
@ -50,29 +50,10 @@ Apartment.configure do |config|
|
||||
|
||||
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.
|
||||
|
||||
40
migrate.rb
Normal file
40
migrate.rb
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user