diff --git a/Gemfile b/Gemfile index e87fad5f..e46fcb76 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,6 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.7' -# Use sqlite3 as the database for Active Record -gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -22,7 +20,7 @@ gem 'turbolinks' gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc - +gem 'font-awesome-rails' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -32,9 +30,17 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +# For deployment to Heroku +group :production do + gem 'pg' + gem 'rails_12factor' +end + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + # Use sqlite3 as the database for Active Record + gem 'sqlite3' end group :development do @@ -43,5 +49,12 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' -end + gem 'better_errors' + # Optional but allows more advanced features of better_errors + gem 'binding_of_caller' + + gem 'pry-rails' + + gem 'rails-erd' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6c97c19f..9a93720f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,16 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (9.0.6) + choice (0.2.0) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -52,6 +58,8 @@ GEM debug_inspector (0.0.2) erubis (2.7.0) execjs (2.7.0) + font-awesome-rails (4.6.3.1) + railties (>= 3.2, < 5.1) globalid (0.3.7) activesupport (>= 4.1.0) i18n (0.7.0) @@ -67,6 +75,7 @@ GEM nokogiri (>= 1.5.9) mail (2.6.4) mime-types (>= 1.16, < 4) + method_source (0.8.2) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) @@ -76,7 +85,14 @@ GEM nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) + pg (0.19.0) pkg-config (1.1.7) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.4) + pry (>= 0.9.10) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -97,8 +113,18 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.5.0) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) railties (4.2.7) actionpack (= 4.2.7) activesupport (= 4.2.7) @@ -107,6 +133,7 @@ GEM rake (11.3.0) rdoc (4.2.2) json (~> 1.4) + ruby-graphviz (1.2.2) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -117,6 +144,7 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + slop (3.6.0) spring (2.0.0) activesupport (>= 4.2) sprockets (3.7.0) @@ -147,11 +175,18 @@ PLATFORMS ruby DEPENDENCIES + better_errors + binding_of_caller byebug coffee-rails (~> 4.1.0) + font-awesome-rails jbuilder (~> 2.0) jquery-rails + pg + pry-rails rails (= 4.2.7) + rails-erd + rails_12factor sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/assets/images/Grass.jpg b/app/assets/images/Grass.jpg new file mode 100644 index 00000000..f9150e80 Binary files /dev/null and b/app/assets/images/Grass.jpg differ diff --git a/app/assets/images/delete.svg b/app/assets/images/delete.svg new file mode 100644 index 00000000..c41db97d --- /dev/null +++ b/app/assets/images/delete.svg @@ -0,0 +1,51 @@ + + + + diff --git a/app/assets/images/edit.svg b/app/assets/images/edit.svg new file mode 100644 index 00000000..953925d8 --- /dev/null +++ b/app/assets/images/edit.svg @@ -0,0 +1,52 @@ + + + diff --git a/app/assets/javascripts/markets.coffee b/app/assets/javascripts/markets.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/markets.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/app/assets/javascripts/products.coffee b/app/assets/javascripts/products.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/products.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/app/assets/javascripts/sales.coffee b/app/assets/javascripts/sales.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sales.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/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/users.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/app/assets/javascripts/vendors.coffee b/app/assets/javascripts/vendors.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/vendors.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/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f9cd5b34..b7de0315 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,65 @@ *= require_tree . *= require_self */ + +/*All pages*/ + +html { + font: normal normal 16px/1.2 "Helvetica Neue", Helvetica, Arial, sans-serif; + text-align: center; +} + +header a, footer a { + color: white; + font-size: 18px; + margin: 0 15px; +} + +header { + padding: 30px 0; +} + +header li { + display: inline-block; +} + +.main-body { + padding-left: 20px; + padding-right: 20px; +} + +footer { + padding: 10px 0; + margin-top: 50px; +} + +header, footer { + background: url("/assets/Grass.jpg"); + color: white; +} + +.individual-market { + font-size: 18px; +} + +.overall-header-text { + font: 24px/1 "Lato", sans-serif; + color: #2d47a3; +} + +li { + display: block; +} + +.vendor-sales, .products-employees { + display: inline-block; + margin: 0 auto; +} + +.all-markets { + text-align: center; +} + +a { + color: black; +} diff --git a/app/assets/stylesheets/markets.scss b/app/assets/stylesheets/markets.scss new file mode 100644 index 00000000..55603bdf --- /dev/null +++ b/app/assets/stylesheets/markets.scss @@ -0,0 +1,9 @@ +// Place all the styles related to the markets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.list-of-markets { + text-align: left; + margin: 0 auto; + +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 00000000..89e2e8db --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the products controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sales.scss b/app/assets/stylesheets/sales.scss new file mode 100644 index 00000000..6f3405b9 --- /dev/null +++ b/app/assets/stylesheets/sales.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sales controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 00000000..31a2eacb --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/vendors.scss b/app/assets/stylesheets/vendors.scss new file mode 100644 index 00000000..1ca74408 --- /dev/null +++ b/app/assets/stylesheets/vendors.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the vendors controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/markets_controller.rb b/app/controllers/markets_controller.rb new file mode 100644 index 00000000..a2a4d0f4 --- /dev/null +++ b/app/controllers/markets_controller.rb @@ -0,0 +1,47 @@ +class MarketsController < ApplicationController + + def index + @market = Market.all + end + + def show + @vendor = Vendor.find(params[:id]) + @market = Market.find(params[:id]) + end + + def new + @market = Market.new + @vendor = @market.vendors.build + end + + def create + @market = Market.new(market_params) + + if @market.save + redirect_to markets_path + else + render :new + end + end + + def edit + @market = Market.find(params[:id]) + end + + def update + @market = Market.find(params[:id]) + if @market.update(market_params) + redirect_to markets_path + else + render :edit + end + end + private + def market_params + params.require(:market).permit(:name, :address, :city, :county, :state, :zip, + :vendors => [:name, :employee_number]) + + + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 00000000..81767bda --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,54 @@ +class ProductsController < ApplicationController + def index + @products = Product.all + end + + def show + @product = Product.find(params[:id]) + end + + def new + @vendor = Vendor.find(params[:vendor_id]) + @product = @vendor.products.build + end + + def create + @product = Product.new(product_params) + @vendor = Vendor.find(params[:vendor_id]) + @product.vendor_id = @vendor.id + if @product.save + redirect_to vendor_path(@vendor.id) + else + render :new + end + end + + def destroy + @vendor = Vendor.find(params[:vendor_id]) + @product = Product.find(params[:id]).destroy + redirect_to vendor_path(@vendor.id) + end + + def edit # Will give the form, like new + @product = Product.find(params[:id]) + @vendor = Vendor.find(params[:vendor_id]) + end + + def update # Actually do the update, like create + @product = Product.find(params[:id]) + @vendor = Vendor.find(params[:vendor_id]) + @product.vendor_id = @vendor.id + if @product.update(product_params) + redirect_to vendor_path(@vendor.id) + else + render :edit + end + end + + private + + def product_params + params.require(:product).permit(:name, + :vendors => [:name, :employee_number, :market_id]) + end +end diff --git a/app/controllers/sales_controller.rb b/app/controllers/sales_controller.rb new file mode 100644 index 00000000..56c8ae06 --- /dev/null +++ b/app/controllers/sales_controller.rb @@ -0,0 +1,37 @@ +class SalesController < ApplicationController + def index + @sales = Sale.all + end + + def show + @sale = Sale.find(params[:id]) + end + + def new + @product = Product.find(params[:vendor_id]) + @sale = @product.sales.build + end + + def create + @vendor = Vendor.find(params[:vendor_id]) + @product = @vendor.products.find(params[:product_id]) + @sale = @product.sales.new(sale_params) + @sale.vendor = @vendor + @sale.purchase_time = Time.now + if @sale.valid? + @sale.amount *= 100 + end + if @sale.save + redirect_to vendor_path(@vendor.id) + else + render :new + end + end + + private + + def sale_params + params.require(:sale).permit(:amount, :purchase_time, + :product => [:name]) + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..72418411 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,12 @@ +class UsersController < ApplicationController + def index + end + + def show + @market = Market.find(params[:id]) + end + + def markets + @market = Market.all + end +end diff --git a/app/controllers/vendors_controller.rb b/app/controllers/vendors_controller.rb new file mode 100644 index 00000000..34acb410 --- /dev/null +++ b/app/controllers/vendors_controller.rb @@ -0,0 +1,53 @@ +class VendorsController < ApplicationController + + def index + @vendors = Vendor.all + end + + def show + @vendor = Vendor.find(params[:id]) + end + + def new + @market = Market.find(params[:market_id]) + @vendor = @market.vendors.build + end + + def create + @market = Market.find(params[:market_id]) + @vendor = Vendor.new(vendor_params) + @vendor.market_id = @market.id + if @vendor.save + redirect_to market_path(@market.id) + else + render :new + end + end + + def destroy + @market = Market.find(params[:market_id]) + @vendor = Vendor.find(params[:id]).destroy + redirect_to market_path(@market.id) + end + + def edit # Will give the form, like new + @vendor = Vendor.find(params[:id]) + @market = Market.find(params[:market_id]) + end + + def update # Actually do the update, like create + @vendor = Vendor.find(params[:id]) + if @vendor.update(vendor_params) + redirect_to market_path + else + render :edit + end + end + + private + + def vendor_params + params.require(:vendor).permit(:name, :employee_number, + :markets => [:name, :address, :city, :county, :state, :zip]) + end +end diff --git a/app/helpers/markets_helper.rb b/app/helpers/markets_helper.rb new file mode 100644 index 00000000..2fc19e4c --- /dev/null +++ b/app/helpers/markets_helper.rb @@ -0,0 +1,59 @@ +module MarketsHelper + + def us_states + [ + ['Alabama', 'Alabama'], + ['Alaska', 'Alaska'], + ['Arizona', 'Arizona'], + ['Arkansas', 'Arkansas'], + ['California', 'California'], + ['Colorado', 'Colorado'], + ['Connecticut', 'Connecticut'], + ['Delaware', 'Delaware'], + ['District of Columbia','District of Columbia'], + ['Florida', 'Florida'], + ['Georgia', 'Georgia'], + ['Hawaii', 'Hawaii'], + ['Idaho', 'Idaho'], + ['Illinois', 'Illinois'], + ['Indiana', 'Indiana'], + ['Iowa', 'Iowa'], + ['Kansas', 'Kansas'], + ['Kentucky', 'Kentucky'], + ['Louisiana', 'Louisiana'], + ['Maine', 'Maine'], + ['Maryland', 'Maryland'], + ['Massachusetts', 'Massachusetts'], + ['Michigan', 'Michigan'], + ['Minnesota', 'Minnesota'], + ['Mississippi', 'Mississippi'], + ['Missouri', 'Missouri'], + ['Montana', 'Montana'], + ['Nebraska', 'Nebraska'], + ['Nevada', 'Nevada'], + ['New Hampshire', 'New Hampshire'], + ['New Jersey', 'New Jersey'], + ['New Mexico', 'New Mexico'], + ['New York', 'New York'], + ['North Carolina', 'North Carolina'], + ['North Dakota', 'North Dakota'], + ['Ohio', 'Ohio'], + ['Oklahoma', 'Oklahoma'], + ['Oregon', 'Oregon'], + ['Pennsylvania', 'Pennsylvania'], + ['Puerto Rico', 'Puerto Rico'], + ['Rhode Island', 'Rhode Island'], + ['South Carolina', 'South Carolina'], + ['South Dakota', 'South Dakota'], + ['Tennessee', 'Tennessee'], + ['Texas', 'Texas'], + ['Utah', 'Utah'], + ['Vermont', 'Vermont'], + ['Virginia', 'Virginia'], + ['Washington', "Washington"], + ['West Virginia', 'West Virginia'], + ['Wisconsin', 'Wisconsin'], + ['Wyoming', 'Wyoming'] + ] + end +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 00000000..ab5c42b3 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/sales_helper.rb b/app/helpers/sales_helper.rb new file mode 100644 index 00000000..8611c4a0 --- /dev/null +++ b/app/helpers/sales_helper.rb @@ -0,0 +1,2 @@ +module SalesHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 00000000..2310a240 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/helpers/vendors_helper.rb b/app/helpers/vendors_helper.rb new file mode 100644 index 00000000..5429ffa4 --- /dev/null +++ b/app/helpers/vendors_helper.rb @@ -0,0 +1,2 @@ +module VendorsHelper +end diff --git a/app/models/market.rb b/app/models/market.rb new file mode 100644 index 00000000..6a148291 --- /dev/null +++ b/app/models/market.rb @@ -0,0 +1,3 @@ +class Market < ActiveRecord::Base + has_many :vendors +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 00000000..8af9a346 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,6 @@ +class Product < ActiveRecord::Base + belongs_to :vendor + has_many :sales + + validates :name, presence: true +end diff --git a/app/models/sale.rb b/app/models/sale.rb new file mode 100644 index 00000000..e6261b8f --- /dev/null +++ b/app/models/sale.rb @@ -0,0 +1,6 @@ +class Sale < ActiveRecord::Base + belongs_to :vendor + belongs_to :product + + validates :amount, presence: true +end diff --git a/app/models/vendor.rb b/app/models/vendor.rb new file mode 100644 index 00000000..fd5a3471 --- /dev/null +++ b/app/models/vendor.rb @@ -0,0 +1,5 @@ +class Vendor < ActiveRecord::Base + belongs_to :market + has_many :products + has_many :sales +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 443f3152..c64eff76 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,32 @@
-<%= yield %> +