VRFS-1576 affiliate report view integration
This commit is contained in:
parent
22566f1b29
commit
7b2d124b33
Binary file not shown.
|
After Width: | Height: | Size: 392 B |
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<!-- Account Summary Dialog -->
|
||||
<div layout="screen" layout-id="account/affiliate" class="screen secondary" id="account-affiliate">
|
||||
<!-- header -->
|
||||
<div class="content-head">
|
||||
<!-- icon -->
|
||||
<div class="content-icon">
|
||||
<%= image_tag "content/icon_dollar.png", {:width => 24, :height => 24} %>
|
||||
</div>
|
||||
<!-- section head text -->
|
||||
<h1>affiliate report</h1>
|
||||
<%= render "screen_navigation" %>
|
||||
</div>
|
||||
<!-- end header -->
|
||||
|
||||
<!-- profile scrolling area -->
|
||||
<div class="content-body">
|
||||
<div id="account-affiliate-content-scroller" class="content-body-scroller">
|
||||
AFFILIATE
|
||||
</div>
|
||||
</div>
|
||||
<!-- end content scrolling area -->
|
||||
</div>
|
||||
|
||||
<script type="text/template" id="template-account-affiliate">
|
||||
<!-- content wrapper -->
|
||||
<div class="content-wrapper account-affiliate">
|
||||
<br />
|
||||
<div class="account-left">
|
||||
<h2>affiliate:</h2>
|
||||
</div>
|
||||
<br clear="all" />
|
||||
</div>
|
||||
<!-- end content wrapper -->
|
||||
|
||||
</script>
|
||||
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,13 @@
|
|||
<!--<li class="subscriptions"><%= link_to "Subscriptions", '/client#/account/subscriptions' %></li> -->
|
||||
<!-- <li class="payments"><%= link_to "Payments", '/client#/account/payments' %></li> -->
|
||||
<% if current_user && current_user.musician? %>
|
||||
<li class="audio"><%= link_to "Audio Gear", '/client#/account/audio' %></li>
|
||||
<% class_val = current_user.affiliate_partner.present? ? 'audio' : 'audio account-menu-group' %>
|
||||
<li class="<%= class_val%>"><%= link_to "Audio Gear", '/client#/account/audio' %></li>
|
||||
<% end %>
|
||||
<% if current_user && current_user.affiliate_partner.present? %>
|
||||
<li class="affiliate account-menu-group"><%= link_to "Affiliate Report", '/client#/account/affiliate' %></li>
|
||||
<% end %>
|
||||
<% if current_user && current_user.musician? %>
|
||||
<li class="band-setup"><%= link_to "Band Setup", '/client#/band/setup/new' %></li>
|
||||
<% end %>
|
||||
<li class="invite-friends"><span class='menuheader'><span class="arrow-right"></span><%= link_to "Invite Friends", '#' %></span>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue