From 7b2d124b3325864b048e20d5692d87bf811fda45 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 23 Apr 2014 06:38:49 +0000 Subject: [PATCH] VRFS-1576 affiliate report view integration --- web/app/assets/images/content/icon_dollar.png | Bin 0 -> 392 bytes .../assets/javascripts/affiliate_report.js | 56 ++++++++++++++++++ .../stylesheets/client/content.css.scss | 2 +- web/app/controllers/api_users_controller.rb | 24 +++++++- .../views/clients/_affiliate_report.html.erb | 36 +++++++++++ web/app/views/clients/index.html.erb | 4 ++ web/app/views/users/_user_dropdown.html.erb | 8 ++- web/config/routes.rb | 1 + web/spec/requests/affilate_referral_spec.rb | 41 +++++++++++++ 9 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 web/app/assets/images/content/icon_dollar.png create mode 100644 web/app/assets/javascripts/affiliate_report.js create mode 100644 web/app/views/clients/_affiliate_report.html.erb create mode 100644 web/spec/requests/affilate_referral_spec.rb diff --git a/web/app/assets/images/content/icon_dollar.png b/web/app/assets/images/content/icon_dollar.png new file mode 100644 index 0000000000000000000000000000000000000000..7d6c1aac2855de8fce895e07a5ebd62b3f0e8c66 GIT binary patch literal 392 zcmV;30eAk1P)bjJV zCc{nt!p@CH1!f(`R4ULrn@EfWIFP?;eEVDi?s<}D;fxo<$r%s6O|Aif26pvC&1~4? zoh%WsiynrpAvfH}`z>_x9hZo}j**oj;A9Tx?y$~PuGATuPEH zr&KWKnrH&{C3)b3LSEccf*>ZqL0^=uq{?Oq*pt2^A*x_+B?3HF29U`XuM&X;wk36E zhn=hOEPR_(fsWSTp6frSR45}BANW9(bhOUXY}`BucDE{_Cv$}5Kzj0min@gsSD8&; m5a+TZ)$|nP{y{dr0t^846Y$`$^ params[:id]) + .includes(:affiliate_partner) + .limit(1) + .first + .affiliate_partner + referrals_by_date = affiliate.referrals_by_date do |by_date| + by_date.inject([]) { |rr, key| rr << key } + end + result = { + :total_count => affiliate.referral_user_count, + :by_date => referrals_by_date + } + render json: result.to_json, status: 200 + rescue + render :json => { :message => $!.to_s }, :status => 400 + end + end + def add_play if params[:id].blank? render :json => { :message => "Playable ID is required" }, :status => 400 diff --git a/web/app/views/clients/_affiliate_report.html.erb b/web/app/views/clients/_affiliate_report.html.erb new file mode 100644 index 000000000..5386d9e31 --- /dev/null +++ b/web/app/views/clients/_affiliate_report.html.erb @@ -0,0 +1,36 @@ + +
+ +
+ +
+ <%= image_tag "content/icon_dollar.png", {:width => 24, :height => 24} %> +
+ +

affiliate report

+ <%= render "screen_navigation" %> +
+ + + +
+
+ AFFILIATE +
+
+ +
+ + + diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index bd37726f2..a573d1758 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -38,6 +38,7 @@ <%= render "testBridge" %> <%= render "account" %> <%= render "account_identity" %> +<%= render "affiliate_report" %> <%= render "account_profile" %> <%= render "friendSelector" %> <%= render "account_profile_avatar" %> @@ -182,6 +183,9 @@ var accountIdentityScreen = new JK.AccountIdentityScreen(JK.app); accountIdentityScreen.initialize(); + var affiliateReportScreen = new JK.AffiliateReportScreen(JK.app); + affiliateReportScreen.initialize(); + var accountProfileScreen = new JK.AccountProfileScreen(JK.app); accountProfileScreen.initialize(); diff --git a/web/app/views/users/_user_dropdown.html.erb b/web/app/views/users/_user_dropdown.html.erb index 6cbb97ed0..5504c5b0f 100644 --- a/web/app/views/users/_user_dropdown.html.erb +++ b/web/app/views/users/_user_dropdown.html.erb @@ -20,7 +20,13 @@ <% if current_user && current_user.musician? %> -
  • <%= link_to "Audio Gear", '/client#/account/audio' %>
  • + <% class_val = current_user.affiliate_partner.present? ? 'audio' : 'audio account-menu-group' %> +
  • <%= link_to "Audio Gear", '/client#/account/audio' %>
  • + <% end %> + <% if current_user && current_user.affiliate_partner.present? %> + + <% end %> + <% if current_user && current_user.musician? %>
  • <%= link_to "Band Setup", '/client#/band/setup/new' %>
  • <% end %>
  • <%= link_to "Invite Friends", '#' %> diff --git a/web/config/routes.rb b/web/config/routes.rb index b225e907f..dd94a2ce8 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -267,6 +267,7 @@ SampleApp::Application.routes.draw do # match '/users/:id/recordings/:recording_id' => 'api_users#recording_destroy', :via => :delete match '/users/:id/plays' => 'api_users#add_play', :via => :post, :as => 'api_users_add_play' + match '/users/:id/affiliate' => 'api_users#affiliate_report', :via => :get, :as => 'api_users_affiliate' # bands match '/bands' => 'api_bands#index', :via => :get diff --git a/web/spec/requests/affilate_referral_spec.rb b/web/spec/requests/affilate_referral_spec.rb new file mode 100644 index 000000000..7a61f8ec4 --- /dev/null +++ b/web/spec/requests/affilate_referral_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe "Affiliate Reports", :type => :api do + + include Rack::Test::Methods + + let!(:user) { FactoryGirl.create(:user) } + let!(:partner) { + AffiliatePartner.create_with_params({:partner_name => Faker::Company.name, + :partner_code => Faker::Lorem.words[0], + :user_email => user.email}) + } + + it "valid score" do + FactoryGirl.create(:user, :created_at => Time.now - 5.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 6.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 6.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 7.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 7.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 7.days, :affiliate_referral_id => partner.id) + FactoryGirl.create(:user, :created_at => Time.now - 7.days, :affiliate_referral_id => partner.id) + + post('/api/auth_session.json', + { :email => user.email, :password => user.password }.to_json, + "CONTENT_TYPE" => 'application/json') + last_response.status.should == 200 + expect(JSON.parse(last_response.body)).to eq({ "success" => true }) + + get "/api/users/#{user.id}/affiliate" + + expect(last_response.status).to eq(200) + json = JSON.parse(last_response.body) + + expect(json['total_count']).to eq(7) + by_date = json['by_date'] + expect(by_date.count).to eq(3) + expect(by_date.first.last).to eq(1) + expect(by_date.last.last).to eq(4) + end + +end