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 %> +
+ +
+ +
+ + <%= yield %> + +
+ + diff --git a/app/views/markets/_form.html.erb b/app/views/markets/_form.html.erb new file mode 100644 index 00000000..7ac0ac6f --- /dev/null +++ b/app/views/markets/_form.html.erb @@ -0,0 +1,17 @@ +

Please edit or add your market

+ +<%= form_for @market do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> +<%= f.label :address %> +<%= f.text_field :address %> +<%= f.label :city %> +<%= f.text_field :city %> +<%= f.label :county %> +<%= f.text_field :county %> +<%= f.label :state %> +<%= select_tag :state, options_for_select(us_states) %> +<%= f.label :zip %> +<%= f.text_field :zip%> +<%= f.submit%> +<% end %> diff --git a/app/views/markets/edit.html.erb b/app/views/markets/edit.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/markets/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/markets/index.html.erb b/app/views/markets/index.html.erb new file mode 100644 index 00000000..ffdc5766 --- /dev/null +++ b/app/views/markets/index.html.erb @@ -0,0 +1,16 @@ +
+

Markets Main Page

+
+

+<%= link_to "Add New Market", new_market_path, method: :get%> +

+ + + + <% @market.all.each do |market| %> + + + + <% end %> + +
<%= link_to "#{market.name}", market_path(market) %> <%= link_to image_tag("/assets/edit.svg"), edit_market_path(market), method: :get%>
diff --git a/app/views/markets/new.html.erb b/app/views/markets/new.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/markets/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/markets/show.html.erb b/app/views/markets/show.html.erb new file mode 100644 index 00000000..687294fc --- /dev/null +++ b/app/views/markets/show.html.erb @@ -0,0 +1,19 @@ +
+

<%=@market.name%>

+
+ <%= link_to "Add A New Vendor", [:new, @market, @vendor], method: :get%> +
+

List of Vendors

+
+ + + + + <%@market.vendors.all.each do |vendor|%> + + + + + <% end %> + +
Vendor <%=vendor.name%><%= link_to image_tag("/assets/edit.svg"), [:edit, @market, @vendor], method: :get%><%= link_to image_tag("/assets/delete.svg"), market_vendor_path(@market, vendor), method: :delete, data: { confirm: "Are you really sure?" } %>
diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 00000000..fd5aa043 --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,17 @@ +

Please enter or update your product

+ +<% if @product.errors.any? %> + +<% end %> + +<%= form_for [@vendor, @product] do |f| %> + <%= f.label "Product name" %> + <%= f.text_field :name %> + <%= f.submit %> +<% end %> diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 00000000..c56b2814 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,3 @@ +

This is the generic product landing page

+ +

If you ended up here, perhaps you'd like to go <%= link_to "Home", root_path %>

diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 00000000..00b700ba --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,5 @@ +
+
+

<%= @product.name %>

+
+
diff --git a/app/views/sales/new.html.erb b/app/views/sales/new.html.erb new file mode 100644 index 00000000..3919dbb0 --- /dev/null +++ b/app/views/sales/new.html.erb @@ -0,0 +1,18 @@ +

Please enter your sale

+ +<% if @sale.errors.any? %> + +<% end %> + +<%= form_for [@product.vendor, @product, @sale], url: {action: "create"} do |f| %> + <%= f.label "Sale amount" %> + <%= f.text_field :amount %> + + <%= f.submit %> +<% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 00000000..e8edf406 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,5 @@ +
+

Farmer's Market

+
+

<%= link_to "Continue as a Vendor", vendors_path %>

+

<%= link_to "Continue as a Market", markets_path %>

diff --git a/app/views/users/markets.html.erb b/app/views/users/markets.html.erb new file mode 100644 index 00000000..35131d3a --- /dev/null +++ b/app/views/users/markets.html.erb @@ -0,0 +1,12 @@ +
+

List of Markets

+
+
+ +
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 00000000..45c7b2a7 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,21 @@ +
+
+

<%= @market.name %>

+
+ +

Address

+
<%= @market.address %> +
<%= @market.city %> +
<%= @market.state %> +
<%= @market.zip %> +
<%= @market.county %> County + +

Vendor list

+ +
diff --git a/app/views/vendors/_form.html.erb b/app/views/vendors/_form.html.erb new file mode 100644 index 00000000..715bde39 --- /dev/null +++ b/app/views/vendors/_form.html.erb @@ -0,0 +1,11 @@ +
+

Add or Change a Vendor

+
+<%= form_for [@market, @vendor] do |f| %> +<%= f.label :name %> +<%= f.text_field :name %> +<%= f.label "Number of Employees" %> +<%= f.text_field :employee_number %> + +<%= f.submit%> +<% end %> diff --git a/app/views/vendors/edit.html.erb b/app/views/vendors/edit.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/vendors/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/vendors/index.html.erb b/app/views/vendors/index.html.erb new file mode 100644 index 00000000..a2b90334 --- /dev/null +++ b/app/views/vendors/index.html.erb @@ -0,0 +1,13 @@ +
+

Vendors Main Page

+
+ +

Please select a Vendor from the list below:

+ + diff --git a/app/views/vendors/new.html.erb b/app/views/vendors/new.html.erb new file mode 100644 index 00000000..d44c608b --- /dev/null +++ b/app/views/vendors/new.html.erb @@ -0,0 +1 @@ +<%= render partial: "form" %> diff --git a/app/views/vendors/show.html.erb b/app/views/vendors/show.html.erb new file mode 100644 index 00000000..cb7c0e9f --- /dev/null +++ b/app/views/vendors/show.html.erb @@ -0,0 +1,87 @@ +
+
+

<%= @vendor.name %>

+
+
+
Number of employees: <%= @vendor.employee_number %> + +
Market: <%= @vendor.market.name %> + +

Product list

+ + + + <% @vendor.products.all.each do |product| %> + + + + + + <% end %> + +
<%= product.name %><%= link_to image_tag("/assets/edit.svg"), edit_vendor_product_path(@vendor, product) %><%= link_to image_tag("/assets/delete.svg"), vendor_product_path(@vendor, product), method: :delete, data: { confirm: "Are you really sure?" } %><%= link_to "Create Sale", new_vendor_product_sale_path(vendor_id: @vendor.id, product_id: product.id) %>
+
+ +

Would you like to add a new product? If so, <%= link_to "click here", new_vendor_product_path(@vendor) %>

+ +

Total Sales List

+
+ <% if @vendor.sales == nil %> +

This vendor has no sales

+ <% else %> + + + + + + + + + + + <% @vendor.sales.all.each do |sale| %> + + + + + <% end %> + +
ProductDateAmount
<%= sale.product.name %><%= sale.purchase_time.strftime("%m/%d/%Y") %><%= number_to_currency(sale.amount/100.00) %>
+ <% end %> +

+ Total Sales: + $<%= (Sale.where(vendor_id: @vendor.id).sum(:amount))/100.00 %> +

+
+ +

Monthly Sales List

+
+ <% monthly_sales = @vendor.sales.where(:purchase_time => Time.now.beginning_of_month..Time.now.end_of_month) %> + <% if monthly_sales.count == 0 %> +

This vendor has no sales this month

+ <% else %> + + + + + + + + + + + <% monthly_sales.each do |sale| %> + + + + + <% end %> + +
ProductDateAmount
<%= sale.product.name %><%= sale.purchase_time.strftime("%m/%d/%Y") %><%= number_to_currency(sale.amount/100.00) %>
+ <% end %> +

+ Total Monthly Sales: + $<%= (monthly_sales.where(vendor_id: @vendor.id).sum(:amount))/100.00 %> +

+
+
diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e4..87a56444 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -29,7 +29,12 @@ # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + # Before deployment, this was FALSE - stack overflow said change to true + config.assets.compile = true + + # Stack overflow said to add these two lines + config.serve_static_assets = true + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. diff --git a/config/routes.rb b/config/routes.rb index 3f66539d..9929b950 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,19 @@ Rails.application.routes.draw do + #We have created the first routes for markets and the user page. + root 'users#index' + get '/users' => 'users#index' + get '/users/markets' => 'users#markets' + get '/users/markets/:id', to: 'users#show', as:'user_market' + + resources :markets, except: [:destroy] do + resources :vendors + end + + resources :vendors, only: [:index, :show] do + resources :products do + resources :sales, only: [:show, :create, :new] + end + end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20161004191027_create_markets.rb b/db/migrate/20161004191027_create_markets.rb new file mode 100644 index 00000000..8155ce25 --- /dev/null +++ b/db/migrate/20161004191027_create_markets.rb @@ -0,0 +1,14 @@ +class CreateMarkets < ActiveRecord::Migration + def change + create_table :markets do |t| + t.string :name + t.string :address + t.string :city + t.string :county + t.string :state + t.string :zip + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004191111_create_vendors.rb b/db/migrate/20161004191111_create_vendors.rb new file mode 100644 index 00000000..b1204a8e --- /dev/null +++ b/db/migrate/20161004191111_create_vendors.rb @@ -0,0 +1,11 @@ +class CreateVendors < ActiveRecord::Migration + def change + create_table :vendors do |t| + t.belongs_to :market, index: true + t.string :name + t.integer :employee_number + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004191122_create_products.rb b/db/migrate/20161004191122_create_products.rb new file mode 100644 index 00000000..058dff47 --- /dev/null +++ b/db/migrate/20161004191122_create_products.rb @@ -0,0 +1,10 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.belongs_to :vendor, index: true + t.string :name + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004191144_create_sales.rb b/db/migrate/20161004191144_create_sales.rb new file mode 100644 index 00000000..86152f31 --- /dev/null +++ b/db/migrate/20161004191144_create_sales.rb @@ -0,0 +1,12 @@ +class CreateSales < ActiveRecord::Migration + def change + create_table :sales do |t| + t.belongs_to :vendor, index: true + t.belongs_to :product, index: true + t.integer :amount + t.datetime :purchase_time + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004192843_delete_column_from_markets.rb b/db/migrate/20161004192843_delete_column_from_markets.rb new file mode 100644 index 00000000..b8f2db8d --- /dev/null +++ b/db/migrate/20161004192843_delete_column_from_markets.rb @@ -0,0 +1,6 @@ +class DeleteColumnFromMarkets < ActiveRecord::Migration + def change + remove_column :markets, :state, :string + remove_column :markets, :zip, :string + end +end diff --git a/db/migrate/20161004212208_add_columns_to_market.rb b/db/migrate/20161004212208_add_columns_to_market.rb new file mode 100644 index 00000000..0c1968b7 --- /dev/null +++ b/db/migrate/20161004212208_add_columns_to_market.rb @@ -0,0 +1,6 @@ +class AddColumnsToMarket < ActiveRecord::Migration + def change + add_column :markets, :state, :string + add_column :markets, :zip, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..26deda69 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,58 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20161004212208) do + + create_table "markets", force: :cascade do |t| + t.string "name" + t.string "address" + t.string "city" + t.string "county" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "state" + t.string "zip" + end + + create_table "products", force: :cascade do |t| + t.integer "vendor_id" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "products", ["vendor_id"], name: "index_products_on_vendor_id" + + create_table "sales", force: :cascade do |t| + t.integer "vendor_id" + t.integer "product_id" + t.integer "amount" + t.datetime "purchase_time" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "sales", ["product_id"], name: "index_sales_on_product_id" + add_index "sales", ["vendor_id"], name: "index_sales_on_vendor_id" + + create_table "vendors", force: :cascade do |t| + t.integer "market_id" + t.string "name" + t.integer "employee_number" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "vendors", ["market_id"], name: "index_vendors_on_market_id" + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..8fd732b5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,50 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +require 'csv' + + +farm_mrkt = [] +CSV.open('./seed_csvs/markets.csv', 'r'). each do |place| + markets = {} + markets[:id] = place[0].to_i + markets[:name] = place[1] + markets[:address] = place[2] + markets[:city] = place[3] + markets[:county] = place[4] + markets[:state] = place[5] + markets[:zip] = place[6] + farm_mrkt << Market.create(markets) +end + + +farm_vend = [] +CSV.open('./seed_csvs/vendors.csv', 'r').each do |vend| + vendors = {} + vendors[:id] = vend[0].to_i + vendors[:name] = vend[1] + vendors[:employee_number] = vend[2] + vendors[:market_id] = vend[3].to_i + farm_vend << Vendor.create(vendors) +end + +merch = [] +CSV.open('./seed_csvs/products.csv', 'r').each do |line| + products = {} + products[:id] = line[0].to_i + products[:name] = line[1] + products[:vendor_id] = line[2].to_i + merch << Product.create(products) +end + + +discount = [] +CSV.open('./seed_csvs/sales.csv', 'r').each do |line| + sales = {} + sales[:id] = line[0].to_i + sales[:amount] = line[1].to_i + sales[:purchase_time] = line[2] + sales[:vendor_id] = line[3].to_i + sales[:product_id] = line[4].to_i + discount << Sale.create(sales) +end diff --git a/erd.pdf b/erd.pdf new file mode 100644 index 00000000..54f6449a Binary files /dev/null and b/erd.pdf differ diff --git a/test/controllers/markets_controller_test.rb b/test/controllers/markets_controller_test.rb new file mode 100644 index 00000000..f43ed535 --- /dev/null +++ b/test/controllers/markets_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MarketsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 00000000..c881fa68 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/sales_controller_test.rb b/test/controllers/sales_controller_test.rb new file mode 100644 index 00000000..669ca5cf --- /dev/null +++ b/test/controllers/sales_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SalesControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 00000000..d23f1829 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/vendors_controller_test.rb b/test/controllers/vendors_controller_test.rb new file mode 100644 index 00000000..2a6edb24 --- /dev/null +++ b/test/controllers/vendors_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VendorsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/markets.yml b/test/fixtures/markets.yml new file mode 100644 index 00000000..13e26ee7 --- /dev/null +++ b/test/fixtures/markets.yml @@ -0,0 +1,17 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + address: MyString + city: MyString + county: MyString + state: MyString + zip: MyString + +two: + name: MyString + address: MyString + city: MyString + county: MyString + state: MyString + zip: MyString diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 00000000..56066c68 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/fixtures/sales.yml b/test/fixtures/sales.yml new file mode 100644 index 00000000..9f2ea287 --- /dev/null +++ b/test/fixtures/sales.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + amount: 1 + purchase_time: 2016-10-04 12:11:44 + +two: + amount: 1 + purchase_time: 2016-10-04 12:11:44 diff --git a/test/fixtures/vendors.yml b/test/fixtures/vendors.yml new file mode 100644 index 00000000..8e3e27a7 --- /dev/null +++ b/test/fixtures/vendors.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + employee_number: 1 + +two: + name: MyString + employee_number: 1 diff --git a/test/models/market_test.rb b/test/models/market_test.rb new file mode 100644 index 00000000..62e16016 --- /dev/null +++ b/test/models/market_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MarketTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 00000000..211cdd0b --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/sale_test.rb b/test/models/sale_test.rb new file mode 100644 index 00000000..8f0c60c0 --- /dev/null +++ b/test/models/sale_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SaleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/vendor_test.rb b/test/models/vendor_test.rb new file mode 100644 index 00000000..07dd4193 --- /dev/null +++ b/test/models/vendor_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VendorTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end