Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

restructed import and data models a bit

  • Loading branch information...
commit 466c9c9b9ec6e21231da0541fe5cba1cf5e6bf28 1 parent ded5900
Andy Glass authored
2  Gemfile
@@ -16,7 +16,7 @@ group :test, :development do
16 16 gem "capybara"
17 17 gem 'simplecov'
18 18 gem 'guard'
19   - gem 'jasmine'
  19 + gem 'jasminerice'
20 20 end
21 21
22 22 gem 'jquery-rails'
12 Gemfile.lock
@@ -70,15 +70,13 @@ GEM
70 70 guard (1.0.3)
71 71 ffi (>= 0.5.0)
72 72 thor (>= 0.14.6)
  73 + haml (3.1.6)
73 74 hashie (1.2.0)
74 75 hike (1.2.1)
75 76 i18n (0.6.0)
76   - jasmine (1.2.0)
77   - jasmine-core (>= 1.2.0)
78   - rack (~> 1.0)
79   - rspec (>= 1.3.1)
80   - selenium-webdriver (>= 0.1.3)
81   - jasmine-core (1.2.0)
  77 + jasminerice (0.0.9)
  78 + coffee-rails
  79 + haml
82 80 journey (1.0.4)
83 81 jquery-rails (2.0.2)
84 82 railties (>= 3.2.0, < 5.0)
@@ -198,7 +196,7 @@ DEPENDENCIES
198 196 geocoder
199 197 gmaps4rails
200 198 guard
201   - jasmine
  199 + jasminerice
202 200 jquery-rails
203 201 jquery-ui-rails
204 202 omniauth
185 app/assets/javascripts/markets.js
@@ -2,17 +2,14 @@ $(document).ready(function() {
2 2
3 3 console.log(Gmaps.map)
4 4
5   - Gmaps.map.callback = function() {};
  5 +//revenue
6 6
7   -
8   -//rev
9   -
10   - var PriceRangeFilter = {
  7 + var RevenueRangeFilter = {
11 8 min: Market.min_revenue,
12 9 max: Market.max_revenue,
13 10 };
14 11
15   - $( "#filtered-rev" ).val( "$" + PriceRangeFilter.min + " - $" + PriceRangeFilter.max );
  12 + $( "#filtered-rev" ).val( "$" + RevenueRangeFilter.min + " - $" + RevenueRangeFilter.max );
16 13
17 14 $("#revenue-range").slider({
18 15 range: true,
@@ -20,8 +17,8 @@ $(document).ready(function() {
20 17 max: Market.max_revenue,
21 18 values: [ 0, Market.max_revenue ],
22 19 slide: function(event, ui) {
23   - PriceRangeFilter.min = ui.values[0];
24   - PriceRangeFilter.max = ui.values[1];
  20 + RevenueRangeFilter.min = ui.values[0];
  21 + RevenueRangeFilter.max = ui.values[1];
25 22 applyAllFilters()
26 23 $( "#filtered-rev" ).val( '$' +(ui.values[ 0 ]).formatMoney(0, '.', ',') + " - $" + (ui.values[ 1 ]).formatMoney(0, '.', ',') );
27 24 }
@@ -43,82 +40,8 @@ $(document).ready(function() {
43 40 applyAllFilters();
44 41 });
45 42
46   -//resets
47   -
48   - $('.filters-reset').click(function(){
49   - clearZips();
50   - clearCategories();
51   - clearProviders();
52   - clearRevenue();
53   - clearDates();
54   - });
55 43
56 44
57   - $('.zip-reset').click(function(){
58   - clearZips()
59   - });
60   -
61   - var clearZips = function() {
62   - console.log("itoman")
63   - $(".chzn-select-zips").val('').trigger("liszt:updated");
64   - ZipFilter = [];
65   - console.log(ZipFilter)
66   - $('#zip-boxes .showhide').prop("checked", true);
67   - _.each($('#zip-boxes .showhide'),function(box){
68   - AllPropertyFilters = _.filter(AllPropertyFilters, function(propertyFilter){ return propertyFilter.name != $(box).attr('data-property-name'); });
69   - });
70   - applyAllFilters();
71   - }
72   -
73   - $('.category-reset').click(function() {
74   - clearCategories();
75   - });
76   -
77   - var clearCategories = function() {
78   - $(".chzn-select-categories").val('').trigger("liszt:updated");
79   - CategoryFilter = [];
80   - applyAllFilters();
81   - }
82   -
83   - $('.provider-reset').click(function() {
84   - clearProviders();
85   - });
86   -
87   - var clearProviders = function() {
88   - $('#provider-boxes .showhide').prop("checked", true);
89   - _.each($('#provider-boxes .showhide'),function(box){
90   - AllPropertyFilters = _.filter(AllPropertyFilters, function(propertyFilter){ return propertyFilter.name != $(box).attr('data-property-name'); });
91   - });
92   - applyAllFilters();
93   - }
94   -
95   - $('.revenue-reset').click(function() {
96   - clearRevenue();
97   - });
98   -
99   - var clearRevenue = function() {
100   - $("#revenue-range").slider("values", 0, Market.min_revenue);
101   - $("#revenue-range").slider("values", 1, Market.max_revenue);
102   - PriceRangeFilter.min = Market.min_revenue;
103   - PriceRangeFilter.max = Market.max_revenue;
104   - $( "#filtered-rev" ).val( "$" + PriceRangeFilter.min + " - $" + PriceRangeFilter.max );
105   - applyAllFilters();
106   - }
107   -
108   -
109   - $('.date-reset').click(function() {
110   - clearDates();
111   - });
112   -
113   - var clearDates = function() {
114   - $("#date-range").slider("values", 0, 0);
115   - $("#date-range").slider("values", 1, Market.max_days);
116   - DateRangeFilter.recent = 0;
117   - DateRangeFilter.oldest = Market.max_days;
118   - $("#filtered-dates").val(dateToYMD(calculateDate(Market.max_days)) + " - " + dateToYMD(calculateDate(0)));
119   - applyAllFilters();
120   - }
121   -
122 45 // dates
123 46
124 47 var DateRangeFilter = {
@@ -176,12 +99,12 @@ $(document).ready(function() {
176 99
177 100
178 101 //markets
  102 +
179 103 $(".chzn-select-markets").chosen();
180 104
181 105 $(".chzn-select-markets").change(function(){
182 106 var id = $(".chzn-select-markets option:selected").attr('data-market-id')
183 107 var source = '/markets/'+ id
184   - console.log(source)
185 108 window.location.href = source;
186 109 });
187 110
@@ -200,7 +123,7 @@ $(document).ready(function() {
200 123
201 124 var visibleMarkers = function() {
202 125 var filtered = _.reject(Gmaps.map.markers, function(marker) {
203   - return _.all(marker.revenues, function(revenue) {return revenue < PriceRangeFilter.min || revenue > PriceRangeFilter.max;
  126 + return _.all(marker.revenues, function(revenue) {return revenue < RevenueRangeFilter.min || revenue > RevenueRangeFilter.max;
204 127 });
205 128 });
206 129 filtered = _.reject(filtered, function(marker) {
@@ -233,6 +156,80 @@ $(document).ready(function() {
233 156 };
234 157
235 158
  159 +//filter resets
  160 +
  161 + $('.filters-reset').click(function(){
  162 + clearZips();
  163 + clearCategories();
  164 + clearProviders();
  165 + clearRevenue();
  166 + clearDates();
  167 + });
  168 +
  169 +
  170 + $('.zip-reset').click(function(){
  171 + clearZips()
  172 + });
  173 +
  174 + var clearZips = function() {
  175 + $(".chzn-select-zips").val('').trigger("liszt:updated");
  176 + ZipFilter = [];
  177 + $('#zip-boxes .showhide').prop("checked", true);
  178 + _.each($('#zip-boxes .showhide'),function(box){
  179 + AllPropertyFilters = _.filter(AllPropertyFilters, function(propertyFilter){ return propertyFilter.name != $(box).attr('data-property-name'); });
  180 + });
  181 + applyAllFilters();
  182 + }
  183 +
  184 + $('.category-reset').click(function() {
  185 + clearCategories();
  186 + });
  187 +
  188 + var clearCategories = function() {
  189 + $(".chzn-select-categories").val('').trigger("liszt:updated");
  190 + CategoryFilter = [];
  191 + applyAllFilters();
  192 + }
  193 +
  194 + $('.provider-reset').click(function() {
  195 + clearProviders();
  196 + });
  197 +
  198 + var clearProviders = function() {
  199 + $('#provider-boxes .showhide').prop("checked", true);
  200 + _.each($('#provider-boxes .showhide'),function(box){
  201 + AllPropertyFilters = _.filter(AllPropertyFilters, function(propertyFilter){ return propertyFilter.name != $(box).attr('data-property-name'); });
  202 + });
  203 + applyAllFilters();
  204 + }
  205 +
  206 + $('.revenue-reset').click(function() {
  207 + clearRevenue();
  208 + });
  209 +
  210 + var clearRevenue = function() {
  211 + $("#revenue-range").slider("values", 0, Market.min_revenue);
  212 + $("#revenue-range").slider("values", 1, Market.max_revenue);
  213 + RevenueRangeFilter.min = Market.min_revenue;
  214 + RevenueRangeFilter.max = Market.max_revenue;
  215 + $( "#filtered-rev" ).val( "$" + RevenueRangeFilter.min + " - $" + RevenueRangeFilter.max );
  216 + applyAllFilters();
  217 + }
  218 +
  219 +
  220 + $('.date-reset').click(function() {
  221 + clearDates();
  222 + });
  223 +
  224 + var clearDates = function() {
  225 + $("#date-range").slider("values", 0, 0);
  226 + $("#date-range").slider("values", 1, Market.max_days);
  227 + DateRangeFilter.recent = 0;
  228 + DateRangeFilter.oldest = Market.max_days;
  229 + $("#filtered-dates").val(dateToYMD(calculateDate(Market.max_days)) + " - " + dateToYMD(calculateDate(0)));
  230 + applyAllFilters();
  231 + }
  232 +
236 233 //pins
237 234
238 235 $('#placeme').click(function() {
@@ -268,24 +265,10 @@ $(document).ready(function() {
268 265 return $.datepicker.formatDate('M dd yy', date);
269 266 };
270 267
  268 +//accordion
  269 +
271 270 $(function(){
272 271 $('#multiAccordion').multiAccordion();
273   -});
274   -
275   - $("#sidebar_accordion").addClass("ui-accordion ui-accordion-icons ui-widget ui-helper-reset")
276   - .find("h3")
277   - .addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-top ui-corner-bottom")
278   - .hover(function() { $(this).toggleClass("ui-state-hover"); })
279   - .prepend('<span class="ui-icon ui-icon-triangle-1-e"></span>')
280   - .click(function() {
281   - $(this)
282   - // .toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
283   - .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
284   - .next().toggleClass("ui-accordion-content-active").slideToggle();
285   - return false;
286   - })
287   - .next()
288   - .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
289   - .hide();
  272 + });
290 273
291 274 });
13 app/assets/stylesheets/application.css
@@ -17,17 +17,4 @@
17 17 */
18 18
19 19
20   - .pretty th .current {
21   - padding-right: 12px;
22   - background-repeat: no-repeat;
23   - background-position: right center;
24   -}
25   -
26   -.pretty th .asc {
27   - background-image: url(/images/up_arrow.gif);
28   -}
29   -
30   -.pretty th .desc {
31   - background-image: url(/images/down_arrow.gif);
32   -}
33 20
15 app/assets/stylesheets/bootstrap_and_overrides.css.less
@@ -146,3 +146,18 @@ revenue-reset {
146 146 .chzn-results {
147 147 color: #262626;
148 148 }
  149 +
  150 +.pretty th .current {
  151 + padding-right: 12px;
  152 + background-repeat: no-repeat;
  153 + background-position: right center;
  154 +}
  155 +
  156 +.pretty th .asc {
  157 + background-image: url(/images/up_arrow.gif);
  158 +}
  159 +
  160 +.pretty th .desc {
  161 + background-image: url(/images/down_arrow.gif);
  162 +}
  163 +
23 app/controllers/markets_controller.rb
@@ -10,19 +10,24 @@ def show
10 10 @market = Market.find(params[:id])
11 11 @json = @market.merchants.to_gmaps4rails do |merchant, marker|
12 12 marker.infowindow render_to_string(:partial => "/merchants/pop", :locals => { :merchant => merchant})
13   - marker.picture({
14   - :picture => "https://s3.amazonaws.com/huntericons/#{merchant.category_logo+merchant.provider_logo}.png",
15   - :width => 32,
16   - :height => 32})
17 13 marker.title "#{merchant.name}"
18   - marker.json({ :revenues => merchant.revenues, :run_with_ls => merchant.run_with_ls?,
19   - :run_with_gpn => merchant.run_with_gpn?, :third_party => merchant.third_party_only?, :zip => merchant.zip,
20   - :days_since => merchant.days_since_all_runs, :csa =>merchant.in_csa?, :outside_csa => merchant.outside_csa?, :categories => merchant.categories})
  14 + marker.picture({
  15 + :picture => "https://s3.amazonaws.com/huntericons/#{merchant.category_logo+merchant.provider_logo}.png",
  16 + :width => 32,
  17 + :height => 32})
  18 + marker.json({ :revenues => merchant.revenues,
  19 + :run_with_ls => merchant.run_with_ls?,
  20 + :run_with_gpn => merchant.run_with_gpn?,
  21 + :third_party => merchant.third_party_only?,
  22 + :zip => merchant.zip,
  23 + :days_since => merchant.days_since_all_runs,
  24 + :csa =>merchant.in_csa?,
  25 + :outside_csa => merchant.outside_csa?,
  26 + :categories => merchant.categories})
21 27 end
22 28
23 29 @gmap_options = {"map_options" => Map.map_options,
24   - "markers" => {"data" => @json,
25   - "options" => Map.marker_options}}
  30 + "markers" => {"data" => @json, "options" => Map.marker_options}}
26 31 end
27 32
28 33 def index
5 app/controllers/user_markets_controller.rb
... ... @@ -1,8 +1,9 @@
1 1 class UserMarketsController < ApplicationController
  2 +
2 3 def create
3 4 @user_market = UserMarket.new(params[:user_market])
4 5 if @user_market.save
5   - redirect_to root_url, :notice => "Added This Market"
  6 + redirect_to root_url, :notice => "This market has been added to your markets."
6 7 else
7 8 render :new
8 9 end
@@ -11,7 +12,7 @@ def create
11 12 def destroy
12 13 @user_market = UserMarket.find(params[:id])
13 14 @user_market.destroy
14   - redirect_to markets_path
  15 + redirect_to markets_path, :notice => "This market has been removed from your markets."
15 16 end
16 17
17 18 def new
10 app/models/deal.rb
... ... @@ -1,10 +1,10 @@
1 1 class Deal < ActiveRecord::Base
2 2
3   - attr_accessible :merchant_id,:market_id, :category, :date_added,
4   - :discount, :full_title, :price, :provider,
5   - :revenue, :revenue_index,:short_title, :date_ended,
6   - :sold, :sold_out, :value, :yipit_deal_id,
7   - :deal_url, :latitude, :longitude
  3 + attr_accessible :merchant_id, :market_id, :category, :date_added,
  4 + :discount, :full_title, :price, :provider,
  5 + :revenue, :date_ended, :value, :yipit_deal_id,
  6 + :sold, :sold_out, :deal_url, :revenue_index,
  7 + :short_title
8 8
9 9 after_create :standardize_provider
10 10
9 app/models/market.rb
... ... @@ -1,5 +1,6 @@
1 1 class Market < ActiveRecord::Base
2 2 include ApplicationHelper
  3 +
3 4 attr_accessible :name, :latitude, :longitude
4 5 has_many :deals
5 6 has_many :merchants, :through => :deals, :uniq => true
@@ -31,10 +32,6 @@ def all_csa_zipcodes
31 32 csa_zips.collect {|csazip| csazip.csa_zipcode}
32 33 end
33 34
34   - def categories
35   - deals.map(&:category).compact.uniq
36   - end
37   -
38 35 def categories_index
39 36 cats = deals.map(&:category).compact
40 37 index = {}
@@ -42,10 +39,6 @@ def categories_index
42 39 index.sort_by { |key, value| value }.reverse
43 40 end
44 41
45   - def zips
46   - merchants.map(&:zip).uniq
47   - end
48   -
49 42 def zips_index
50 43 zips = merchants.map(&:zip).compact
51 44 index = {}
22 app/models/merchant.rb
... ... @@ -1,21 +1,17 @@
1 1 class Merchant < ActiveRecord::Base
2 2 include ApplicationHelper
3 3
4   - attr_accessible :address, :appearances, :city, :zip,
5   - :name, :phone, :website, :latitude,
6   - :longitude, :yipit_merchant_id
  4 + attr_accessible :name, :address, :city, :zip,
  5 + :phone, :website, :latitude, :longitude,
  6 + :yipit_merchant_id
  7 +
7 8 has_many :deals
8 9 acts_as_gmappable :process_geocoding => false
9 10
10   -
11 11 def market
12 12 deals.first.market
13 13 end
14 14
15   - def providers
16   - deals.map(&:provider).uniq.compact
17   - end
18   -
19 15 def revenues
20 16 deals.map(&:revenue).uniq.compact
21 17 end
@@ -114,9 +110,13 @@ def provider_logo
114 110 "3"
115 111 end
116 112 end
117   -
118   -
119   -
  113 +
  114 +private
  115 +
  116 + def providers
  117 + deals.map(&:provider).uniq.compact
  118 + end
  119 +
120 120 end
121 121
122 122
4 app/views/layouts/application.html.erb
@@ -16,8 +16,8 @@
16 16 <span class="icon-bar"></span>
17 17 <span class="icon-bar"></span>
18 18 </a>
19   - <%= image_tag "ls_logo.png", :class=> "pull-left" %>
20   - <a class="brand" href="#">Merchant Hunter</a>
  19 + <%= link_to image_tag("ls_logo.png", :class=> "pull-left"), markets_path %>
  20 + <a class="brand">Merchant Hunter</a>
21 21 <div class="nav-collapse">
22 22 <ul class="nav">
23 23 </ul>
4 app/views/welcome/show.html.erb
... ... @@ -1,5 +1,7 @@
1 1 <br />
2 2 <br />
3   -<div class="span8 offset4">
  3 +<div class="span12">
  4 + <div class="well" id="welcomewell">
4 5 <h1>You Must Log in To Enter the Merchant Hunter</h1>
  6 +</div>
5 7 </div>
1  db/migrate/20120621191421_create_merchants.rb
@@ -10,7 +10,6 @@ def change
10 10 t.float :longitude
11 11 t.string :phone
12 12 t.string :website
13   - t.integer :appearances
14 13
15 14 t.timestamps
16 15 end
2  db/migrate/20120621191841_create_deals.rb
@@ -19,8 +19,6 @@ def change
19 19 t.float :revenue_index
20 20 t.string :deal_url
21 21 t.string :category
22   - t.float :latitude
23   - t.float :longitude
24 22
25 23 t.timestamps
26 24 end
7 lib/importer.rb
@@ -20,7 +20,6 @@ def self.import
20 20 :latitude => row['latitude'],
21 21 :longitude => row['longitude'],
22 22 :website => row['merchant_website'],
23   - :appearances =>row['appearances'],
24 23 :phone => row['phone'])
25 24
26 25 Deal.find_or_create_by_yipit_deal_id(
@@ -40,9 +39,7 @@ def self.import
40 39 :short_title => clean_characters(row['short_title']),
41 40 :sold => row['sold'],
42 41 :sold_out =>row ['sold_out'],
43   - :value => row['value'],
44   - :latitude => merchant.latitude,
45   - :longitude => merchant.longitude)
  42 + :value => row['value'])
46 43 end
47 44 end
48 45 end
@@ -52,8 +49,8 @@ def self.import_csa_zips
52 49 csv = CSV.parse(csv_text, {:headers => true, :header_converters => :symbol})
53 50 csv.each do |row|
54 51 row = row.to_hash.with_indifferent_access
55   - market = Market.find_or_create_by_name(row['name'])
56 52 if row['csa'] == "Y"
  53 + market = Market.find_or_create_by_name(row['name'])
57 54 CsaZip.create(csa_zipcode: row['zip'], market_id: market.id)
58 55 end
59 56 end
2  lib/map.rb
... ... @@ -1,4 +1,5 @@
1 1 module Map
  2 +
2 3 def self.map_options
3 4 {"auto_zoom" => true,
4 5 "zoom" => 22,
@@ -12,4 +13,5 @@ def self.marker_options
12 13 {"raw" =>
13 14 '{animation: google.maps.Animation.DROP}'}
14 15 end
  16 +
15 17 end
3  spec/javascripts/market_spec.js.coffee
... ... @@ -0,0 +1,3 @@
  1 +describe "CalculateDays", ->
  2 + it "caluculates the days from the current date", ->
  3 + calculateDate 10
3  spec/javascripts/spec.js.coffee
... ... @@ -0,0 +1,3 @@
  1 +#= require jquery
  2 +#= require_tree .
  3 +#= require markets.js
27 spec/models/market_spec.rb
@@ -26,29 +26,24 @@
26 26 end
27 27 end
28 28
29   - describe "#categories" do
30   - it "returns an array of categories for deals run in that market" do
31   - market.categories.class == Array
32   - end
33   -
34   - it "returns the categories for all of the deals" do
35   - market.deals.each do |deal|
36   - market.categories.include?(deal.category).should == true
  29 + describe "#categories_index" do
  30 + it "returns a hash with the categories mentioned in the market with their frequency" do
  31 + market.categories_index.each do |category, frequency|
  32 + category.class.should == String
  33 + frequency.class.should == Fixnum
37 34 end
38 35 end
39 36 end
40 37
41   - describe "#zips" do
42   - it "returns an array of zip codes for merchants in that market" do
43   - market.zips.class == Array
  38 + describe "#zips_index" do
  39 + it "returns a hash with the zipcodes with deals in the market with their frequency" do
  40 + market.zips_index.each do |zip, frequency|
  41 + zip.class.should == String
  42 + frequency.class.should == Fixnum
  43 + end
44 44 end
45 45 end
46 46
47   - it "returns the zip codes for each of the merchants" do
48   - market.merchants.each do |merchant|
49   - market.zips.include?(merchant.zip).should == true
50   - end
51   - end
52 47
53 48 describe "#all_csa_zipcodes" do
54 49 it "returns an array of core selling area zipcodes for the market" do
27 spec/models/merchant_spec.rb
... ... @@ -1,7 +1,7 @@
1 1 require 'spec_helper'
2 2 describe Merchant do
3 3
4   - let!(:merchant) { Merchant.create(name: "test") }
  4 + let!(:merchant) { Merchant.create(name: "test", city: "merchant_city") }
5 5 let!(:deal) { Deal.create(merchant_id: merchant.id, category: "deal_category1", provider: "livingsocial", revenue: 50, date_added: Date.strptime("10/04/1988", "%m/%d/%Y"))}
6 6 let!(:deal1) { Deal.create(merchant_id: merchant.id, category: "deal_category2", provider: "poop-on", revenue: 5, date_added: Date.strptime("10/04/2005", "%m/%d/%Y"))}
7 7
@@ -108,6 +108,31 @@
108 108 end
109 109 end
110 110
  111 + describe "#sfdc_url" do
  112 + it "should return a string" do
  113 + merchant.sfdc_url.class == String
  114 + end
  115 + it "should include the merchant name" do
  116 + merchant.sfdc_url.should match /#{merchant.name}/
  117 + end
  118 + it "should include the merchant city" do
  119 + merchant.sfdc_url.should match /#{merchant.city}/
  120 + end
  121 + end
  122 +
  123 + describe "#category_logo" do
  124 + it "returns a string representing the category of the merchant for a pin image" do
  125 + merchant.category_logo.class == String
  126 + end
  127 + end
  128 +
  129 + describe "#provider_logo" do
  130 + it "returns a string representing the provider of the merchant for a pin image" do
  131 + merchant.provider_logo.class == String
  132 + end
  133 + end
  134 +
  135 +
111 136 # describe "#in_csa" do
112 137 # it "should return a string" do
113 138 # raise merchant.in_csa.inspect

0 comments on commit 466c9c9

Please sign in to comment.
Something went wrong with that request. Please try again.