integrating api, (without music_notations, start scheduled information)

This commit is contained in:
Bert Owen 2014-06-05 03:19:45 +08:00
parent 6a4be359c0
commit 60a004a252
6 changed files with 200 additions and 64 deletions

View File

@ -140,6 +140,7 @@ module JamRuby
current_time = Time.now
query = MusicSession.where("music_sessions.user_id = '#{user.id}'")
query = query.where("music_sessions.scheduled_start IS NOT NULL AND music_sessions.scheduled_start < '#{current_time + 12.hours}'")
query = query.where("music_session_id IS NULL")
query = query.order("music_sessions.scheduled_start ASC")
return query

View File

@ -45,6 +45,17 @@
});
}
function createScheduledSession(options) {
return $.ajax({
type: "POST",
dataType: "json",
contentType: 'application/json',
url: "/api/sessions",
processData: false,
data: JSON.stringify(options)
});
}
function legacyJoinSession(options) {
var sessionId = options["session_id"];
delete options["session_id"];
@ -1102,6 +1113,7 @@
// Expose publics
this.initialize = initialize;
this.legacyCreateSession = legacyCreateSession;
this.createScheduledSession = createScheduledSession;
this.legacyJoinSession = legacyJoinSession;
this.joinSession = joinSession;
this.getUserDetail = getUserDetail;

View File

@ -79,6 +79,8 @@
});
context._.each(sessionList, function (session) {
session.scheduled_start = (new Date(session.scheduled_start)).toDateString() +
getFormattedTime(new Date(session.scheduled_start), false);
var options = {
id: session.id,
name: session.name,
@ -215,42 +217,55 @@
}
function beforeMoveStep1() {
createSessionSettings.startDate = $('#session-start-date').val();
createSessionSettings.startTime = $('#start-time-list').val();
createSessionSettings.endTime = $('#end-time-list').val();
createSessionSettings.selectedSessionId = $scheduledSessions.find('input[name="scheduled-session-info"][checked="checked"]').attr('id');
var $timezoneList = $('#timezone-list');
createSessionSettings.timezone.value = $timezoneList.val();
createSessionSettings.timezone.label = $timezoneList.get(0).options[$timezoneList.get(0).selectedIndex].text;
var $recurringMode = $('#recurring-mode-list');
createSessionSettings.recurring_mode.label = $recurringMode.get(0).options[$recurringMode.get(0).selectedIndex].text;
createSessionSettings.recurring_mode.value = $recurringMode.val();
var errors = false;
if (createSessionSettings.createType == 'start-scheduled') {
if (createSessionSettings.selectedSessionId) {
var session = scheduledSessions[createSessionSettings.selectedSessionId];
var scheduledDate = new Date(session.scheduled_start);
var currentDate = new Date();
var diff = scheduledDate - currentDate;
if (diff > 60 * 60) {
}
}
var session = scheduledSessions[createSessionSettings.selectedSessionId];
createSessionSettings.startDate = new Date(session.scheduled_start).toDateString();
createSessionSettings.startTime = getFormattedTime(new Date(session.scheduled_start), false);
createSessionSettings.genresValues = ['Pop'];
createSessionSettings.genres = ['pop'];
createSessionSettings.timezone.label = "(GMT-06:00) Central Time (US & Canada)";
createSessionSettings.timezone.value = "Central Time (US & Canada),America/Chicago";
createSessionSettings.name = "Private Test Session";
createSessionSettings.description = "Private session set up just to test things out in the session interface by myself.";
createSessionSettings.notations = [];
createSessionSettings.language.label = 'English';
createSessionSettings.language.value = 'en';
createSessionSettings.session_policy = 'Standard';
createSessionSettings.musician_access.label = "Only RSVP musicians may join";
createSessionSettings.musician_access.value = "only-rsvp";
createSessionSettings.fans_access.label = "Fans may not listen to session";
createSessionSettings.fans_access.value = "no-listen-chat";
}
else if (createSessionSettings.createType == 'quick-start') {
createSessionSettings.genresValues = ['Pop'];
createSessionSettings.genres = ['pop'];
createSessionSettings.timezone.label = "(GMT-06:00) Central Time (US & Canada)";
createSessionSettings.timezone.value = "Central Time (US & Canada),America/Chicago";
createSessionSettings.name = "Private Test Session";
createSessionSettings.description = "Private session set up just to test things out in the session interface by myself.";
createSessionSettings.notations = [];
createSessionSettings.language.label = 'English';
createSessionSettings.language.value = 'en';
createSessionSettings.session_policy = 'Standard';
createSessionSettings.musician_access.label = "Only RSVP musicians may join";
createSessionSettings.musician_access.value = "only-rsvp";
createSessionSettings.fans_access.label = "Fans may not listen to session";
createSessionSettings.fans_access.value = "no-listen-chat";
}
else {
createSessionSettings.startDate = $('#session-start-date').val();
createSessionSettings.startTime = $('#start-time-list').val();
createSessionSettings.endTime = $('#end-time-list').val();
createSessionSettings.selectedSessionId = $scheduledSessions.find('input[name="scheduled-session-info"][checked="checked"]').attr('id');
var $timezoneList = $('#timezone-list');
createSessionSettings.timezone.value = $timezoneList.val();
createSessionSettings.timezone.label = $timezoneList.get(0).options[$timezoneList.get(0).selectedIndex].text;
var $recurringMode = $('#recurring-mode-list');
createSessionSettings.recurring_mode.label = $recurringMode.get(0).options[$recurringMode.get(0).selectedIndex].text;
createSessionSettings.recurring_mode.value = $recurringMode.val();
}
return true;
// var confirmDialog = new context.JK.ConfirmDialog(app, "Start Session Now",
// "You are starting a session that is scheduled to begin more than one hour from now. Are you sure you want to do this?",
// "Future Session", function() {
// errors = true;
// app.layout.closeDialog('confirm');
// $.holdReady(false);
// }
// );
//
// confirmDialog.initialize();
// app.layout.showDialog('confirm');
}
function beforeMoveStep2() {
@ -334,6 +349,105 @@
function beforeMoveStep5() {
}
function startSession() {
var data = {};
data.name = createSessionSettings.name;
data.description = createSessionSettings.description;
data.genres = createSessionSettings.genres;
if (createSessionSettings.musician_access.value == 'only_rsvp') {
data.musician_access = false;
data.approval_required = false;
}
else if (createSessionSettings.musician_access.value == 'musicians-approval') {
data.musician_access = true;
data.approval_required = true;
}
else if (createSessionSettings.musician_access.value == 'musicians') {
data.musician_access = true;
data.approval_required = false;
}
if (createSessionSettings.fans_access.value == 'no-listen-chat') {
data.fan_access = false; data.fan_chat = false;
}
else if (createSessionSettings.fans_access.value == 'listen-chat-each') {
data.fan_access = true; data.fan_chat = false;
}
else if (createSessionSettings.fans_access.value == 'listen-chat-band') {
data.fan_access = true; data.fan_chat = true;
}
data.legal_policy = createSessionSettings.session_policy;
data.legal_terms = true;
data.language = createSessionSettings.language.value;
if (createSessionSettings.createType == 'quick-start') {
data.start = new Date().toDateString() + ' ' + getFormattedTime(new Date(), false);
}
data.invitations = inviteMusiciansUtil.getInvitedFriends();
data.recurring_mode = createSessionSettings.recurring_mode;
data.music_notations = createSessionSettings.music_notations;
if (createSessionSettings.createType == 'start-scheduled') {
data = scheduledSessions[createSessionSettings.selectedSessionId];
}
var tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
if(tracks.length == 0) {
logger.error("we should never have 0 tracks and have gotten this far. Launch FTUE is the best we can do right now")
// If user hasn't completed FTUE - do so now.
app.afterFtue = function() { startSession(); };
app.layout.startNewFtue();
return false;
}
var joinSession = function(sessionId) {
// var options = {};
// options.client_id = app.clientId;
// options.session_id = sessionId;
// options.as_musician = true;
// options.tracks = tracks;
// rest.joinSession(options)
// .done(function(response) {
var invitationCount = data.invitations.length;
context.location = '/client#/session/' + sessionId;
context.JK.GA.trackSessionCount(data.musician_access, data.fan_access, invitationCount);
context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.create);
// })
// .fail(function(jqXHR) {
// var handled = false;
// if(jqXHR.status = 422) {
// var response = JSON.parse(jqXHR.responseText);
// if(response["errors"] && response["errors"]["tracks"] && response["errors"]["tracks"][0] == "Please select at least one track") {
// app.notifyAlert("No Inputs Configured", $('<span>You will need to reconfigure your audio device.</span>'));
// handled = true;
// }
// }
// if(!handled) {
// app.notifyServerError(jqXHR, "Unable to Create Session");
// }
// })
};
if (createSessionSettings.createType == 'start-scheduled') {
joinSession(createSessionSettings.selectedSessionId);
}
else {
rest.createScheduledSession(data)
.done(function(response) {
var newSessionId = response.id;
$(".btn-next").off('click');
if (createSessionSettings.createType == 'quick-start') {
joinSession(newSessionId);
}
})
.fail(function(jqXHR){
app.notifyServerError(jqXHR, "Unable to Create Session");
});
}
}
var STEPS = {
0: {
beforeShow: beforeShowStep1,
@ -357,8 +471,6 @@
}
};
function moveToStep() {
var $nextWizardStep = $wizardSteps.filter($('[layout-wizard-step=' + step + ']'));
@ -445,9 +557,11 @@
if (step == STEP_SELECT_CONFIRM) {
$btnNext.html(createSessionSettings.startType);
$btnNext.on('click', startSession);
}
else
$btnNext.on('click', next);
$btnNext.on('click', next);
$btnBack.on('click', back);
$sessionButtons.empty();
@ -520,6 +634,30 @@
function afterShow() {
}
function getFormattedTime(date, change) {
if (change) {
date.setMinutes(Math.ceil(date.getMinutes() / 30) * 30);
}
var h12h = date.getHours();
var m12h = date.getMinutes();
var ampm;
if (h12h >= 0 && h12h < 12) {
if (h12h === 0) {
h12h = 12; // 0 becomes 12
}
ampm = "AM";
}
else {
if (h12h > 12) {
h12h -= 12; // 13-23 becomes 1-11
}
ampm = "PM";
}
var timeString = ("00" + h12h).slice(-2) + ":" + ("00" + m12h).slice(-2) + " " + ampm;
return timeString;
}
function toggleDate() {
var selectedDate = new Date($('#session-start-date').val());
var currentDate = new Date();
@ -528,23 +666,8 @@
if (currentDate.getYear() == selectedDate.getYear() &&
currentDate.getMonth() == selectedDate.getMonth() &&
currentDate.getDate() == selectedDate.getDate()) {
currentDate.setMinutes(Math.ceil(currentDate.getMinutes() / 30) * 30);
var h12h = currentDate.getHours();
var m12h = currentDate.getMinutes();
var ampm;
if (h12h >= 0 && h12h < 12) {
if (h12h === 0) {
h12h = 12; // 0 becomes 12
}
ampm = "AM";
}
else {
if (h12h > 12) {
h12h -= 12; // 13-23 becomes 1-11
}
ampm = "PM";
}
var timeString = ("00" + h12h).slice(-2) + ":" + ("00" + m12h).slice(-2) + " " + ampm;
var timeString = getFormattedTime(currentDate, true);
startIndex = defaultTimeArray.indexOf(timeString);
}
var $startTimeList = $('#start-time-list');

View File

@ -9,7 +9,7 @@ class ApiMusicNotationsController < ApiController
client_id = params[:client_id]
if client_id.nil?
raise JamArgumentError, "client_id must be asdfasfdasdf specified"
raise JamArgumentError, "client_id must be specified"
end
@music_notation = MusicNotation.new

View File

@ -241,7 +241,7 @@ class ApiMusicSessionsController < ApiController
client_id = params[:client_id]
if client_id.nil?
raise JamArgumentError, "client_id must be asdfasfdasdf specified"
raise JamArgumentError, "client_id must be specified"
end
begin

View File

@ -270,7 +270,7 @@
<div class="clearall"></div>
</li>
<li>
<input type="radio" name="session-policy-type" id="session-policy-creative" policy-id="Creative">
<input type="radio" name="session-policy-type" id="session-policy-creative" policy-id="Creative Commons">
<label for="session-policy-creative" class="radio-text">
Session participants agree to Creative Commons license<br>
</label>
@ -299,7 +299,7 @@
the music. Use the following link for full legal details of this choice:
<a href="http://www.jamkazam.com/session-legal-policies/standard" target="_blank">www.jamkazam.com/session-legal-policies/standard</a>.
</div>
<div class="info-box hidden" policy-type="Creative">
<div class="info-box hidden" policy-type="Creative Commons">
This is a good option to choose when the session participants are creating new music that is not
already copyrighted, and when the musicians can agree that everyone will share ownership of any
music created in the session. Use the following link for full legal details of this choice:
@ -448,8 +448,8 @@
<script type="text/template" id="template-scheduled-session">
<li>
<input type="radio" name="scheduled-session-info" id="{{data.id}}" value="false" />
<label for="{{data.id}}" class="radio-text">
{{data.scheduled_start}} {{data.name}}
<label for="{{data.id}}" class="radio-text w85">
{{data.scheduled_start}} : {{data.name}}
</label>
<div class="clearall"></div>
</li>
@ -488,12 +488,12 @@
<option value="4">4</option>
</select>
<select class="f12 rsvp-level" session-instrument-id="{value}">
<option value="Any Skill Level">Any Skill Level</option>
<option value="Beginner">Beginner</option>
<option value="Beginner to Intermediate">Beginner to Intermediate</option>
<option value="Intermediate">Intermediate</option>
<option value="Intermediate to Advanced">Intermediate to Advanced</option>
<option value="Advanced">Advanced</option>
<option value="Any">Any Skill Level</option>
<option value="Beg">Beginner</option>
<option value="Beg/Int">Beginner to Intermediate</option>
<option value="Int">Intermediate</option>
<option value="Int/Adv">Intermediate to Advanced</option>
<option value="Adv">Advanced</option>
</select>
</div>
</script>