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 000000000..7d6c1aac2
Binary files /dev/null and b/web/app/assets/images/content/icon_dollar.png differ
diff --git a/web/app/assets/javascripts/affiliate_report.js b/web/app/assets/javascripts/affiliate_report.js
new file mode 100644
index 000000000..d20d208ed
--- /dev/null
+++ b/web/app/assets/javascripts/affiliate_report.js
@@ -0,0 +1,56 @@
+(function(context,$) {
+
+ "use strict";
+
+ context.JK = context.JK || {};
+ context.JK.AffiliateReportScreen = function(app) {
+ var logger = context.JK.logger;
+ var rest = context.JK.Rest();
+ var user = {};
+
+ function beforeShow(data) {
+ }
+
+ function afterShow(data) {
+ renderAffiliateReport();
+ }
+
+ function populateAffiliateReport(report) {
+ console.log(report);
+ /*var template = context.JK.fillTemplate($('#template-account-affiliate').html(), {
+ email: userDetail.email
+ });*/
+ }
+
+ /****************** MAIN PORTION OF SCREEN *****************/
+ // events for main screen
+ function events() {
+ //$('#account-identity-content-scroller').on('click', '#account-edit-email-cancel', function(evt) { evt.stopPropagation(); navToAccount(); return false; } );
+ }
+
+ function renderAffiliateReport() {
+ $.ajax({
+ type: "GET",
+ dataType: "json",
+ url: "/api/users/" + context.JK.currentUserId + "/affiliate",
+ processData: false
+ }).done(populateAffiliateReport)
+ .error(app.ajaxError);
+ }
+
+ function initialize() {
+ var screenBindings = {
+ 'beforeShow': beforeShow,
+ 'afterShow': afterShow
+ };
+ app.bindScreen('account/affiliate', screenBindings);
+ events();
+ }
+
+ this.initialize = initialize;
+ this.beforeShow = beforeShow;
+ this.afterShow = afterShow;
+ return this;
+ };
+
+})(window,jQuery);
diff --git a/web/app/assets/stylesheets/client/content.css.scss b/web/app/assets/stylesheets/client/content.css.scss
index ad578a628..6685d883d 100644
--- a/web/app/assets/stylesheets/client/content.css.scss
+++ b/web/app/assets/stylesheets/client/content.css.scss
@@ -429,7 +429,7 @@ ul.shortcuts {
padding:2px;
}
- .account-home, .band-setup, .audio, .get-help, .download-app, .community-forum, .invite-friends {
+ .account-home, .band-setup, .account-menu-group, .get-help, .download-app, .community-forum, .invite-friends {
border-bottom:1px;
border-style:solid;
border-color:#ED3618;
diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb
index 5dc55cf9c..97fb849c7 100644
--- a/web/app/controllers/api_users_controller.rb
+++ b/web/app/controllers/api_users_controller.rb
@@ -11,7 +11,8 @@ class ApiUsersController < ApiController
:notification_index, :notification_destroy, # notifications
:band_invitation_index, :band_invitation_show, :band_invitation_update, # band invitations
:set_password, :begin_update_email, :update_avatar, :delete_avatar, :generate_filepicker_policy,
- :share_session, :share_recording]
+ :share_session, :share_recording,
+ :affiliate_report]
respond_to :json
@@ -605,6 +606,27 @@ class ApiUsersController < ApiController
end
end
+ def affiliate_report
+ begin
+ affiliate = User
+ .where(:id => 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" %>
+
+
+
+
+
+
+
+
+
+
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 %>
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