diff --git a/Gemfile b/Gemfile index c3392751..0ef641d1 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,6 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.5' # 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 @@ -46,4 +45,9 @@ group :development do gem 'better_errors' gem 'binding_of_caller' gem 'pry' + gem 'sqlite3' +end + +group :production do + gem 'pg' end diff --git a/Gemfile.lock b/Gemfile.lock index bcfce4b5..96282a53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,7 @@ GEM multi_json (1.11.2) nokogiri (1.6.6.3) mini_portile (~> 0.6.0) + pg (0.18.4) pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -122,7 +123,7 @@ GEM json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) slop (3.6.0) - spring (1.4.3) + spring (1.4.4) sprockets (3.4.0) rack (> 1, < 3) sprockets-rails (2.3.3) @@ -156,6 +157,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails + pg pry rails (= 4.2.5) sass-rails (~> 5.0) diff --git a/README.md b/README.md index 2f53e640..05bd9e2f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -#Secret Message for Sarah - # FarMar Rails Build a database backend application to view, create, and manage farmers markets as well as their vendors, products, and sales. In this implementation we'll be seeding with static data, and also building a tool to allow markets and/or vendors to sign up and add their own data. diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 00000000..b6b7bc67 Binary files /dev/null and b/app/assets/.DS_Store differ diff --git a/app/assets/images/p-patch.jpg b/app/assets/images/p-patch.jpg new file mode 100644 index 00000000..f5af48c6 Binary files /dev/null and b/app/assets/images/p-patch.jpg differ 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/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/markets.scss b/app/assets/stylesheets/markets.scss new file mode 100644 index 00000000..260d87ae --- /dev/null +++ b/app/assets/stylesheets/markets.scss @@ -0,0 +1,142 @@ +// 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/ + +@import url('https://fonts.googleapis.com/css?family=Amatic+SC|Open+Sans'); + +body { + font-family: 'Open Sans', sans-serif; + background-image: image-url("p-patch.jpg"); + background-size: cover; + color: #004d00; +} + +a:hover {text-decoration: underline; +} + +a { + text-decoration:none; + color: #004d00; +} + +nav { + text-align: center; + font-size: 16px; + background-color: #004d00; + border-radius: 5px; + padding: 5px; +} + +.nav_link { + color: white; + font-family: 'Open Sans'; +} + +h1 { + font-family: 'Amatic SC', sans-serif; + text-align: center; + font-size: 3em; +} + +div.fade { + width: 700px; + background-color: rgba(255, 255, 255, .75); + margin: 50px auto; + padding: 15px 50px; + border-radius: 10px; + text-align: left; +} + +div.button { + display:inline-block; + padding: 40px; + border-radius: 10px; + border-width: medium; + margin: 10px; + margin-bottom: 20px; + text-align: center; + +} + +div.button > a { + text-decoration: none; + font-family: 'Amatic SC', sans-serif; + color: #ffffff; + font-weight: bold; + font-size: 2em; +} + +div.button > a:hover { + font-size: 250%; +} + +div.center{ + text-align: center; +} + +div.show_sales { + display:inline-block; + padding: 20px; + border-width: medium; + border-radius: 10px; + margin: 10px; + text-align: center; + background-color: rgba(184, 184, 148, .75) +} + +li { + line-height: 150%; +} + + + +.market_button { + background-color: rgba(41, 41, 163, .75); +} + +.vendor_button{ + background-color: rgba(0, 102, 34, .75); + +} + +.edit { + color: #392613; +} + +.delete { + color: #cc3300; +} + +form { + margin: auto; + padding: 0px 50px 0px 50px; + line-height: 200%; +} + +fieldset { + padding-bottom: 20px; + border: 0; +} + +legend { + padding: 10px; +} + +label { + margin-left: 10px; +} + +input { + border: none; + border-glow: none; + background-color: rgba(0, 102, 34, .4); + outline: none; + padding: 5px; + font-size: 1.05em; + border-radius: 5px; + margin: 10px; +} + +.submit_button { + font-family: 'Open Sans' +} 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/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..9455fe57 --- /dev/null +++ b/app/controllers/markets_controller.rb @@ -0,0 +1,57 @@ +class MarketsController < ApplicationController + + def home + @markets = Market.all + end + + def show + id = params[:id] + @market = Market.find(id) + @vendors = @market.vendors + end + + def index + @is_a_market = true + @markets = Market.all + end + + def edit + id = params[:id] + @market= Market.find(id) + @title = "Edit Market" + @action = :update + end + + def update + Market.update(params[:id], market_params[:market] ) + redirect_to market_path(params[:id]) + end + + def new + id = params[:id] + @market= Market.new + @title = "Create a Market" + @action = :create + end + + def view + show + end + + def create + a = Market.create( market_params[:market] ) + redirect_to market_path(a.id) + end + + def destroy + Market.destroy(params[:id]) + redirect_to markets_path + end + + private + + def market_params + params.permit(market:[:name, :address, :city, :county, :state, :zip]) + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 00000000..369a13dd --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,44 @@ +class ProductsController < ApplicationController + + def new + @product = Product.new + end + + def edit + id = params[:id] + @product = Product.find(id) + @title = "Edit Product" + @action = :update + end + + def update + id = params[:id] + product = Product.find(id) + vendor_id = product.vendor_id + Product.update(params[:id], product_params[:product]) + redirect_to vendor_path(vendor_id) + end + + def create + Product.create(product_params[:product]) + redirect_to vendor_path(params[:vendor_id]) + end + + def destroy + Product.destroy(params[:id]) + redirect_to vendor_path(params[:vendor_id]) + end + + def show + @product = Product.find(params[:id]) + @sales = @product.sales + end + + private + + def product_params + params.permit(product:[:id, :name, :vendor_id]) + end + + +end diff --git a/app/controllers/sales_controller.rb b/app/controllers/sales_controller.rb new file mode 100644 index 00000000..bd9eff12 --- /dev/null +++ b/app/controllers/sales_controller.rb @@ -0,0 +1,25 @@ +class SalesController < ApplicationController + + def new + @sale = Sale.new + end + + def create + a = Sale.create( + :amount => ((sale_params[:sale][:amount]).to_i * 100), + :purchase_time => sale_params[:sale][:purchase_time], + :vendor_id => sale_params[:sale][:vendor_id], + :product_id => sale_params[:sale][:product_id], + + ) + redirect_to vendor_product_path(a.vendor_id, a.product_id) + end + + private + + def sale_params + params.permit(sale:[:amount, :purchase_time, :vendor_id, :product_id]) + end + + +end diff --git a/app/controllers/vendors_controller.rb b/app/controllers/vendors_controller.rb new file mode 100644 index 00000000..152d9d34 --- /dev/null +++ b/app/controllers/vendors_controller.rb @@ -0,0 +1,58 @@ +class VendorsController < ApplicationController + + def vendors + @vendors = Vendor.all + render :index + end + + def new + @new_vendor = Vendor.new + end + + def create + a = Vendor.create(vendor_params[:vendor]) + redirect_to market_path(a.market_id) + end + + def show + @is_a_vendor = true + id = params[:id] + @vendor = Vendor.find(id) + @products = @vendor.products + @sales = @vendor.sales + @total_sales = total_sales(@sales) + @sales_this_month = @sales.find_all { |sale| sale.purchase_time.month == Time.now.month && sale.purchase_time.year == Time.now.year } + @total_sales_this_month = total_sales(@sales_this_month) + end + + def total_sales(sales) + total_sales = 0 + sales.each do |sale| + total_sales += sale.amount + end + return total_sales/100 + end + + + def edit + id = params[:id] + @vendor = Vendor.find(id) + end + + def update + Vendor.update(params[:id], vendor_params[:vendor]) + redirect_to market_path(vendor_params[:vendor][:market_id]) + end + + def destroy + Vendor.destroy(params[:id]) + redirect_to market_path(params[:market_id]) + end + + private + + def vendor_params + params.permit(vendor:[:name, :employees, :market_id]) + end + +end diff --git a/app/helpers/markets_helper.rb b/app/helpers/markets_helper.rb new file mode 100644 index 00000000..655b79b7 --- /dev/null +++ b/app/helpers/markets_helper.rb @@ -0,0 +1,2 @@ +module MarketsHelper +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/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..57812154 --- /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..86f8d94b --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,4 @@ +class Product < ActiveRecord::Base + belongs_to :vendor + has_many :sales +end diff --git a/app/models/sale.rb b/app/models/sale.rb new file mode 100644 index 00000000..7142a28c --- /dev/null +++ b/app/models/sale.rb @@ -0,0 +1,4 @@ +class Sale < ActiveRecord::Base + belongs_to :vendor + belongs_to :product +end diff --git a/app/models/vendor.rb b/app/models/vendor.rb new file mode 100644 index 00000000..f8f66089 --- /dev/null +++ b/app/models/vendor.rb @@ -0,0 +1,6 @@ +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..e76ed765 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,12 @@ <%= csrf_meta_tags %>
+