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" %>_ + + + + +
+
+ +
+

Companies

+

Registered Companies: <%= @companies.count %>

+
+ <%= link_to(new_company_path, :method => :get) do %> + Register a Company + <% end %> + + + + + + + + + <% if @companies.empty? %> +
Company IDCompany NameRegistration Serial Key
+
+

No Companies Registered

+
+ <% else %> + + <% @companies.each_slice(1) do |row| %> + + <% row.each do |company|%> + + + + <%= company.id %> + + + + + <%= company.company_name %> + + + + + <%= company.company_token %> + + <% end %> + + <% end %> + + + <% end %> +
+
+
+
+ <%= javascript_include_tag "bootstrap.min" %>_ + diff --git a/Pearlception/app/views/companies/new.html.erb b/Pearlception/app/views/companies/new.html.erb new file mode 100644 index 0000000..e68b7d4 --- /dev/null +++ b/Pearlception/app/views/companies/new.html.erb @@ -0,0 +1,83 @@ +<%= stylesheet_link_tag "dashboard" %>_ + + + + +
+
+ +
+

Companies

+

Register a New Company

+
+ <%= link_to(companies_path, :method => :get) do %> + Back + <% end %> + <%= form_for @company, url: {action: "create"}, html: {class: "company_form"} do |f| %> +
+ <%= f.text_field :company_name, class: 'form-control', placeholder: 'Company Name' %> +
+
+ <%= f.submit "Create" %> +
+
+ + <% end %> + +
+
+
+ + <%= javascript_include_tag "bootstrap.min" %>_ + diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index fdaf05d..accc7ef 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -84,11 +84,18 @@ --> -

Recent Results

+ <% if current_user.admin? %> +

Recent Results From All Companies

+ <% else %> +

Recent Results

+ <% end %>
+ <% if current_user.admin? %> + + <% end %> @@ -99,10 +106,20 @@ + <% if current_user.admin? %> <% @results.each_slice(1) do |row| %> <% row.each do |result| - run = Run.find(result.id) %> + run = Run.find(result.id) + #company = Company.find(run.company_id) + %> + + + + <% end %> + <% else %> + <% @results.each_slice(1) do |row| %> + + <% row.each do |result| + run = Run.find(result.id) %> + + + + + + + + + + + + + + + + + + + + + <% end %> + + <% end %> + <% end %>
CompanyRun Date Location Harvest Time
+ <%= #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 : "" %> +
diff --git a/Pearlception/config/routes.rb b/Pearlception/config/routes.rb index 625aa85..1a1ae89 100644 --- a/Pearlception/config/routes.rb +++ b/Pearlception/config/routes.rb @@ -2,6 +2,7 @@ Rails.application.routes.draw do root "dashboard#index" resources :runs + resources :companies devise_for :users, :controllers => {:registrations => 'registrations'} devise_scope :users do diff --git a/Pearlception/test/controllers/companies_controller_test.rb b/Pearlception/test/controllers/companies_controller_test.rb new file mode 100644 index 0000000..c3c7d1a --- /dev/null +++ b/Pearlception/test/controllers/companies_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CompaniesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end