diff --git a/Pearlception/.pryrc b/Pearlception/.pryrc new file mode 100644 index 0000000..a95f43e --- /dev/null +++ b/Pearlception/.pryrc @@ -0,0 +1,4 @@ +if Rails.env.development? || Rails.env.test? + # This introduces the `table` statement + extend Hirb::Console +end diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile index 9a447a8..882f710 100644 --- a/Pearlception/Gemfile +++ b/Pearlception/Gemfile @@ -36,6 +36,8 @@ gem 'bcrypt', '~> 3.1.7' # gem 'capistrano-rails', group: :development # for sign in sign up gem 'devise' +#for pagination +gem 'kaminari' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console @@ -49,7 +51,21 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'awesome_rails_console' + gem 'hirb' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +# Please clean up duplicated gems if any. +# Feel free to remove gems that you don't want to use or if they conflict with other gem dependencies. (you might need to update .pryrc also) +group :development, :test do + gem 'hirb' + gem 'hirb-unicode' + gem 'pry-byebug' + gem 'pry-stack_explorer' +end + +group :development, :test do +end diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock index 7b37024..e375e40 100644 --- a/Pearlception/Gemfile.lock +++ b/Pearlception/Gemfile.lock @@ -39,9 +39,17 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + awesome_print (1.7.0) + awesome_rails_console (0.4.0) + awesome_print + pry-rails + railties bcrypt (3.1.11) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) builder (3.2.2) byebug (9.0.6) + coderay (1.1.1) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -62,6 +70,10 @@ GEM ffi (1.9.14) globalid (0.3.7) activesupport (>= 4.1.0) + hirb (0.7.3) + hirb-unicode (0.0.5) + hirb (~> 0.5) + unicode-display_width (~> 0.1.1) i18n (0.7.0) jbuilder (2.6.1) activesupport (>= 3.0.0, < 5.1) @@ -70,6 +82,18 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -89,6 +113,18 @@ GEM nokogiri (1.7.0) mini_portile2 (~> 2.1.0) orm_adapter (0.5.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.4.2) + byebug (~> 9.0) + pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) + pry-stack_explorer (0.4.9.2) + binding_of_caller (>= 0.7) + pry (>= 0.9.11) puma (3.6.2) rack (2.0.1) rack-test (0.6.3) @@ -129,6 +165,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + slop (3.6.0) spring (2.0.0) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -151,6 +188,7 @@ GEM thread_safe (~> 0.1) uglifier (3.0.4) execjs (>= 0.3.0, < 3) + unicode-display_width (0.1.1) warden (1.2.6) rack (>= 1.0) web-console (3.4.0) @@ -166,14 +204,20 @@ PLATFORMS ruby DEPENDENCIES + awesome_rails_console bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.2) devise + hirb + hirb-unicode jbuilder (~> 2.5) jquery-rails + kaminari listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) + pry-byebug + pry-stack_explorer puma (~> 3.0) rails (~> 5.0.1) sass-rails (~> 5.0) diff --git a/Pearlception/app/assets/images/ajax-loader.gif b/Pearlception/app/assets/images/ajax-loader.gif new file mode 100644 index 0000000..3eaeeca Binary files /dev/null and b/Pearlception/app/assets/images/ajax-loader.gif differ diff --git a/Pearlception/app/assets/javascripts/companies.coffee b/Pearlception/app/assets/javascripts/companies.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/Pearlception/app/assets/javascripts/companies.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/stylesheets/companies.scss b/Pearlception/app/assets/stylesheets/companies.scss new file mode 100644 index 0000000..412c0f5 --- /dev/null +++ b/Pearlception/app/assets/stylesheets/companies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Companies 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/assets/stylesheets/custom.scss b/Pearlception/app/assets/stylesheets/custom.scss new file mode 100644 index 0000000..0f37419 --- /dev/null +++ b/Pearlception/app/assets/stylesheets/custom.scss @@ -0,0 +1,22 @@ +//@import "bootstrap-sprockets"; +@import "bootstrap"; + +/* mixins, variables, etc. */ + +$gray-medium-light: #eaeaea; + +@mixin box_sizing { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +/* miscellaneous */ + +.debug_dump { + clear: both; + float: left; + width: 100%; + margin-top: 45px; + @include box_sizing; +} diff --git a/Pearlception/app/controllers/companies_controller.rb b/Pearlception/app/controllers/companies_controller.rb new file mode 100644 index 0000000..f50f318 --- /dev/null +++ b/Pearlception/app/controllers/companies_controller.rb @@ -0,0 +1,32 @@ +class CompaniesController < ApplicationController + require 'securerandom' + before_filter :deny_to_visitors + + def new + @company = Company.new + end + + def create + @company = Company.new(company_params) + @company.company_token = SecureRandom.uuid + + if @company.save + redirect_to :action => 'index' + else + flash[:alert] = @company.errors.full_messages.to_sentence + redirect_to :action => 'new' + end + end + + def index + @companies = Company.all + end + + def deny_to_visitors + redirect_to "/signin" unless user_signed_in? && current_user.admin? + end + + def company_params + params.require(:company).permit(:company_name, :company_token) + end +end diff --git a/Pearlception/app/controllers/dashboard_controller.rb b/Pearlception/app/controllers/dashboard_controller.rb index 573a03c..10a757e 100644 --- a/Pearlception/app/controllers/dashboard_controller.rb +++ b/Pearlception/app/controllers/dashboard_controller.rb @@ -1,7 +1,13 @@ class DashboardController < ApplicationController + before_filter :deny_to_visitors def index - + @results = Result.page(params[:page]).per(5) + + end + + def deny_to_visitors + redirect_to "/signin" unless user_signed_in? end end diff --git a/Pearlception/app/controllers/registrations_controller.rb b/Pearlception/app/controllers/registrations_controller.rb index b97cbdf..8ce31be 100644 --- a/Pearlception/app/controllers/registrations_controller.rb +++ b/Pearlception/app/controllers/registrations_controller.rb @@ -1,7 +1,23 @@ class RegistrationsController < Devise::RegistrationsController - private + include ApplicationHelper + #protected + + def create + binding.pry + @user = User.new(sign_up_params) + if !@user.admin? + #search by company token given by one of pearlception admins to the company + #and look up comany_id # + @user.company_id = 0 + else + @user.company_id = -1 + end + @user.save + sign_in @user + redirect_to "/" + end def sign_up_params - params.require(:user).permit(:company_id, :email, :password, :password_confirmation) + params.require(:user).permit(:email, :password, :password_confirmation, :company_id) end end diff --git a/Pearlception/app/helpers/application_helper.rb b/Pearlception/app/helpers/application_helper.rb index de6be79..2768dce 100644 --- a/Pearlception/app/helpers/application_helper.rb +++ b/Pearlception/app/helpers/application_helper.rb @@ -1,2 +1,13 @@ module ApplicationHelper + def resource_name + :user + end + + def resource + @resource ||= User.new + end + + def devise_mapping + @devise_mapping ||= Devise.mappings[:user] + end end diff --git a/Pearlception/app/helpers/companies_helper.rb b/Pearlception/app/helpers/companies_helper.rb new file mode 100644 index 0000000..099b151 --- /dev/null +++ b/Pearlception/app/helpers/companies_helper.rb @@ -0,0 +1,2 @@ +module CompaniesHelper +end diff --git a/Pearlception/app/models/company.rb b/Pearlception/app/models/company.rb index c2737b5..fdc526f 100644 --- a/Pearlception/app/models/company.rb +++ b/Pearlception/app/models/company.rb @@ -1,3 +1,4 @@ class Company < ApplicationRecord - belongs_to :user + has_many :users + has_many :runs end diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb index 0a7cdb6..3514394 100644 --- a/Pearlception/app/models/oyster.rb +++ b/Pearlception/app/models/oyster.rb @@ -1,6 +1,11 @@ class Oyster < ApplicationRecord belongs_to :run - Oyster.establish_connection(:"stats_#{Rails.env}") - - + #Oyster.establish_connection(:"stats_#{Rails.env}") + Oyster.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/result.rb b/Pearlception/app/models/result.rb index f03b554..cbd0ed2 100644 --- a/Pearlception/app/models/result.rb +++ b/Pearlception/app/models/result.rb @@ -1,3 +1,10 @@ class Result < ApplicationRecord - establish_connection(:"stats_#{Rails.env}") + #establish_connection(:"stats_#{Rails.env}") + Result.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/run.rb b/Pearlception/app/models/run.rb index 18c81f6..1dd5a5e 100644 --- a/Pearlception/app/models/run.rb +++ b/Pearlception/app/models/run.rb @@ -1,4 +1,12 @@ class Run < ApplicationRecord has_many :oysters - establish_connection(:"stats_#{Rails.env}") + belongs_to :companies + # establish_connection(:"stats_#{Rails.env}") + Run.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb index b2091f9..a44f648 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -1,4 +1,6 @@ class User < ApplicationRecord + belongs_to :company + has_many :runs # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, diff --git a/Pearlception/app/views/companies/index.html.erb b/Pearlception/app/views/companies/index.html.erb new file mode 100644 index 0000000..b505cdf --- /dev/null +++ b/Pearlception/app/views/companies/index.html.erb @@ -0,0 +1,111 @@ +<%= stylesheet_link_tag "dashboard" %>_ + +
+ + +| Company ID | +Company Name | +Registration Serial Key | +
|---|
No Companies Registered
+| # | -Header | -Header | -Header | -Header | + <% if current_user.admin? %> +Company | + <% end %> +Run Date | +Location | +Harvest Time | +Supplier | +Distributor | +Total Processed | +Other |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1,001 | -Lorem | -ipsum | -dolor | -sit | -||||||||
| 1,002 | -amet | -consectetur | -adipiscing | -elit | -||||||||
| 1,003 | -Integer | -nec | -odio | -Praesent | -||||||||
| 1,003 | -libero | -Sed | -cursus | -ante | -||||||||
| 1,004 | -dapibus | -diam | -Sed | -nisi | -||||||||
| 1,005 | -Nulla | -quis | -sem | -at | -||||||||
| 1,006 | -nibh | -elementum | -imperdiet | -Duis | -||||||||
| 1,007 | -sagittis | -ipsum | -Praesent | -mauris | -||||||||
| 1,008 | -Fusce | -nec | -tellus | -sed | -||||||||
| 1,009 | -augue | -semper | -porta | -Mauris | -||||||||
| 1,010 | -massa | -Vestibulum | -lacinia | -arcu | -||||||||
| 1,011 | -eget | -nulla | -Class | -aptent | -||||||||
| 1,012 | -taciti | -sociosqu | -ad | -litora | -||||||||
| 1,013 | -torquent | -per | -conubia | -nostra | -||||||||
| 1,014 | -per | -inceptos | -himenaeos | -Curabitur | -||||||||
| 1,015 | -sodales | -ligula | -in | -libero | -||||||||
| + <%= #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 : "" %> + | + <% end %> +|||||
| + <%= run.runDate %> + | + + ++ <%= run.location ? run.location : "" %> + | + + ++ <%= "" %> + | + + ++ + <%= run.supplier ? run.supplier : "" %> + | + + ++ <%= run.distributor ? run.distributor : "" %> + | + + ++ <%= result.total %> + | + + ++ <%= run.other ? run.other : "" %> + | + <% end %> +
<%= notice %>
+ <% end %> + <% if alert %> +<%= alert %>
+ <% end %> - <% if notice %> -<%= notice %>
- <% end %> - <% if alert %> -<%= alert %>
- <% end %> <%= yield %> + <%= debug(params) if Rails.env.development? %>