Merged branch Companies into master

This commit is contained in:
Okechi Onyeje 2017-01-20 02:40:59 -05:00
commit e127b930a2
11 changed files with 308 additions and 4 deletions

View File

@ -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/

View File

@ -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/

View File

@ -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

View File

@ -0,0 +1,2 @@
module CompaniesHelper
end

View File

@ -1,3 +1,4 @@
class Company < ApplicationRecord class Company < ApplicationRecord
belongs_to :user has_many :users
has_many :runs
end end

View File

@ -1,5 +1,5 @@
class User < ApplicationRecord class User < ApplicationRecord
has_one :company belongs_to :company
has_many :runs has_many :runs
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable

View File

@ -0,0 +1,111 @@
<%= stylesheet_link_tag "dashboard" %>_
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Pearlception</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<!-- <li><a href="#">Dashboard</a></li> -->
<!-- <li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li> -->
<li>
<%= link_to(destroy_user_session_path, class: 'logout-link', :method => :delete) do %>
<i class="fa fa-external-link"></i> Logout
<% end %>
</li>
</ul>
<!-- <form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form> -->
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li><a href="/">Overview <span class="sr-only">(current)</span></a></li>
<% if current_user.admin? %>
<li class="active"><a href="companies#index">Companies</a></li>
<% else %>
<li><a href="#">Reports</a></li>
<li><a href="#">Analytics</a></li>
<li><a href="#">Export</a></li>
<% end %>
</ul>
<!-- <ul class="nav nav-sidebar">
<li><a href="">Nav item</a></li>
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
<li><a href="">More navigation</a></li>
</ul>
<ul class="nav nav-sidebar">
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
</ul> -->
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Companies</h1>
<h2 class="sub-header">Registered Companies: <%= @companies.count %> </h2>
<div class="panel panel-primary table-responsive">
<%= link_to(new_company_path, :method => :get) do %>
<i class="fa fa-external-link"></i> Register a Company
<% end %>
<table class="table table-striped">
<thead>
<tr>
<th>Company ID</th>
<th>Company Name</th>
<th>Registration Serial Key</th>
</tr>
</thead>
<% if @companies.empty? %>
</table>
<div class="panel panel-primary">
<p>No Companies Registered</p>
</div>
<% else %>
<tbody>
<% @companies.each_slice(1) do |row| %>
<tr>
<% row.each do |company|%>
<!-- company id -->
<td>
<%= company.id %>
</td>
<!-- company_name -->
<td>
<%= company.company_name %>
</td>
<!-- company registration token -->
<td>
<%= company.company_token %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>
</div>
</div>
<%= javascript_include_tag "bootstrap.min" %>_
</body>

View File

@ -0,0 +1,83 @@
<%= stylesheet_link_tag "dashboard" %>_
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Pearlception</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<!-- <li><a href="#">Dashboard</a></li> -->
<!-- <li><a href="#">Settings</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Help</a></li> -->
<li>
<%= link_to(destroy_user_session_path, class: 'logout-link', :method => :delete) do %>
<i class="fa fa-external-link"></i> Logout
<% end %>
</li>
</ul>
<!-- <form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form> -->
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li><a href="/">Overview <span class="sr-only">(current)</span></a></li>
<% if current_user.admin? %>
<li class="active"><a href="companies#index">Companies</a></li>
<% else %>
<li><a href="#">Reports</a></li>
<li><a href="#">Analytics</a></li>
<li><a href="#">Export</a></li>
<% end %>
</ul>
<!-- <ul class="nav nav-sidebar">
<li><a href="">Nav item</a></li>
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
<li><a href="">More navigation</a></li>
</ul>
<ul class="nav nav-sidebar">
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
</ul> -->
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Companies</h1>
<h2 class="sub-header">Register a New Company</h2>
<div class="panel panel-primary">
<%= link_to(companies_path, :method => :get) do %>
<i class="fa fa-external-link"></i> Back
<% end %>
<%= form_for @company, url: {action: "create"}, html: {class: "company_form"} do |f| %>
<div class="field form-group">
<%= f.text_field :company_name, class: 'form-control', placeholder: 'Company Name' %>
</div>
<div class="actions">
<%= f.submit "Create" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
<%= javascript_include_tag "bootstrap.min" %>_
</body>

View File

@ -84,11 +84,18 @@
</div> </div>
</div> --> </div> -->
<% if current_user.admin? %>
<h2 class="sub-header">Recent Results From All Companies</h2>
<% else %>
<h2 class="sub-header">Recent Results</h2> <h2 class="sub-header">Recent Results</h2>
<% end %>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<% if current_user.admin? %>
<th>Company</th>
<% end %>
<th>Run Date</th> <th>Run Date</th>
<th>Location</th> <th>Location</th>
<th>Harvest Time</th> <th>Harvest Time</th>
@ -99,6 +106,59 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% if current_user.admin? %>
<% @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 date -->
<td>
<%= run.runDate %>
</td>
<!-- location -->
<td>
<%= run.location ? run.location : "" %>
</td>
<!-- harvest time -->
<td>
<%= "" %>
</td>
<!-- supplier -->
<td>
<%= run.supplier ? run.supplier : "" %>
</td>
<!-- distributor -->
<td>
<%= run.distributor ? run.distributor : "" %>
</td>
<!-- total processed -->
<td>
<%= result.total %>
</td>
<!-- other -->
<td>
<%= run.other ? run.other : "" %>
</td>
<% end %>
</tr>
<% end %>
<% else %>
<% @results.each_slice(1) do |row| %> <% @results.each_slice(1) do |row| %>
<tr> <tr>
<% row.each do |result| <% row.each do |result|
@ -141,6 +201,7 @@
<% end %> <% end %>
</tr> </tr>
<% end %> <% end %>
<% end %>
</tbody> </tbody>
</table> </table>
<div class="center-block"> <div class="center-block">

View File

@ -2,6 +2,7 @@ Rails.application.routes.draw do
root "dashboard#index" root "dashboard#index"
resources :runs resources :runs
resources :companies
devise_for :users, :controllers => {:registrations => 'registrations'} devise_for :users, :controllers => {:registrations => 'registrations'}
devise_scope :users do devise_scope :users do

View File

@ -0,0 +1,7 @@
require 'test_helper'
class CompaniesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end