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/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/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/user.rb b/Pearlception/app/models/user.rb index 0a39c7f..a44f648 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -1,5 +1,5 @@ class User < ApplicationRecord - has_one :company + belongs_to :company has_many :runs # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable 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
+| Company | + <% end %>Run Date | Location | Harvest Time | @@ -99,10 +106,20 @@|||
|---|---|---|---|---|---|---|
| + <%= #company.company_name + "Fake Industries" %> + | +<%= run.runDate %> @@ -141,6 +158,50 @@ <% end %> | |||||
| + <%= run.runDate %> + | + + ++ <%= run.location ? run.location : "" %> + | + + ++ <%= "" %> + | + + ++ + <%= run.supplier ? run.supplier : "" %> + | + + ++ <%= run.distributor ? run.distributor : "" %> + | + + ++ <%= result.total %> + | + + ++ <%= run.other ? run.other : "" %> + | + <% end %> +