VRFS-2094 fixed issue with notation file upload and tying it to music session; still need to fix download issue

This commit is contained in:
Brian Smith 2014-09-06 03:30:29 -04:00
parent 6517a3b97d
commit 74763d53f3
8 changed files with 65 additions and 20 deletions

View File

@ -343,8 +343,8 @@ module JamRuby
Notification.send_scheduled_session_invitation(ms, receiver)
end if options[:invitations]
options[:music_notations].each do |notation_id|
notation = MusicNotation.find(notation_id)
options[:music_notations].each do |notation|
notation = MusicNotation.find(notation[:id])
notation.music_session = ms
notation.save

View File

@ -6,11 +6,12 @@
var $dialog;
var $screen = $('#session-settings');
var $selectedFilenames = $screen.find('#selected-filenames');
var $uploadSpinner = $screen.find($('.upload-spinner'));
var $uploadSpinner = $screen.find('.upload-spinner');
var $selectedFilenames = $('#settings-selected-filenames');
var $inputFiles = $('#settings-select-files');
var $btnSelectFiles = $screen.find('.btn-select-files');
var rest = new JK.Rest();
var sessionId;
function beforeShow(data) {
@ -18,6 +19,7 @@
$dialog = $('[layout-id="session-settings"]');
var currentSession = sessionScreen.getCurrentSession();
sessionId = currentSession.id;
// id
$('#session-settings-id').val(currentSession.id);
@ -64,7 +66,6 @@
$selectedFilenames.empty();
for (var i=0; i < currentSession.music_notations.length; i++) {
var notation = currentSession.music_notations[i];
console.log('notation.file_name %o', notation.file_name);
$selectedFilenames.append('<a href="' + notation.file_url + '" rel="external">' + notation.file_name + '</a>&nbsp;');
}
@ -115,7 +116,7 @@
rest.updateSession($('#session-settings-id').val(), data).done(settingsSaved);
}
function changeSelectedFiles() {
function changeSettingsSelectedFiles() {
var fileNames = [];
var files = $inputFiles.get(0).files;
var error = false;
@ -135,23 +136,42 @@
}
else {
// upload as soon as user picks their files.
uploadNotations($inputFiles.get(0).files)
uploadSettingsNotations($inputFiles.get(0).files)
.done(function() {
context._.each(fileNames, function(fileName) {
$selectedFilenames.append(fileName);
var $text = $('<span>').text(fileName);
$selectedFilenames.append($text);
})
})
}
}
function uploadNotations(notations) {
function uploadSettingsNotations(notations) {
var formData = new FormData();
var maxExceeded = false;
$.each(notations, function(i, file) {
var max = 10 * 1024 * 1024;
if(file.size > max) {
maxExceeded = true;
return false;
}
formData.append('files[]', file);
});
formData.append('client_id', app.clientId);
if(maxExceeded) {
app.notify(
{ title: "Maximum Music Notation Size Exceeded",
text: "You can only upload files up to 10 megabytes in size."
});
var deferred = new $.Deferred();
deferred.reject();
return deferred;
}
formData.append('client_id', app.clientId);
formData.append('session_id', sessionId);
$btnSelectFiles.text('UPLOADING...').data('uploading', true)
$uploadSpinner.show();
return rest.uploadMusicNotations(formData)
@ -159,7 +179,7 @@
var error_files = [];
$.each(response, function(i, music_notation) {
if (music_notation.errors) {
//error_files.push(createSessionSettings.notations[i].name);
error_files.push(music_notation.name);
}
})
if (error_files.length > 0) {
@ -167,22 +187,32 @@
}
})
.fail(function(jqXHR) {
app.notifyServerError(jqXHR, "Unable to upload music notations");
if(jqXHR.status == 413) {
// the file is too big. Let the user know.
// This should happen when they select the file, but a misconfiguration on the server could cause this.
app.notify(
{ title: "Maximum Music Notation Size Exceeded",
text: "You can only upload files up to 10 megabytes in size."
})
}
else {
app.notifyServerError(jqXHR, "Unable to upload music notations");
}
})
.always(function() {
$btnSelectFiles.text('SELECT FILES...').data('uploading', null)
$uploadSpinner.hide();
})
});
}
function toggleSelectFiles(event) {
function toggleSettingsSelectFiles(event) {
if($btnSelectFiles.data('uploading')) {
logger.debug("ignoring click of SELECT FILES... while uploading")
return false;
}
event.preventDefault();
$('#session-select-files').trigger('click');
$('#settings-select-files').trigger('click');
return false;
}
@ -195,8 +225,8 @@
function events() {
$('#session-settings-dialog-submit').on('click', saveSettings);
$inputFiles.on('change', changeSelectedFiles);
$btnSelectFiles.on('click', toggleSelectFiles);
$inputFiles.on('change', changeSettingsSelectedFiles);
$btnSelectFiles.on('click', toggleSettingsSelectFiles);
}
this.initialize = function() {

View File

@ -57,6 +57,7 @@
}
function uploadMusicNotations(formData) {
console.log("formData=%o", formData);
return $.ajax({
type: "POST",
processData: false,
@ -68,6 +69,17 @@
});
}
function downloadMusicNotation(notationId) {
return $.ajax({
type: "GET",
processData: false,
contentType: false,
dataType: "json",
cache: false,
url: "/api/music_notations/" + notationId
});
}
function legacyJoinSession(options) {
var sessionId = options["session_id"];
delete options["session_id"];
@ -1195,6 +1207,7 @@
this.legacyCreateSession = legacyCreateSession;
this.createScheduledSession = createScheduledSession;
this.uploadMusicNotations = uploadMusicNotations;
this.downloadMusicNotation = downloadMusicNotation;
this.legacyJoinSession = legacyJoinSession;
this.joinSession = joinSession;
this.cancelSession = cancelSession;

View File

@ -663,7 +663,7 @@
}
data.invitations = inviteMusiciansUtil.getInvitedFriends();
data.recurring_mode = createSessionSettings.recurring_mode.value;
data.music_notations = createSessionSettings.music_notations;
data.music_notations = createSessionSettings.notations;
data.timezone = createSessionSettings.timezone.value;
data.open_rsvps = createSessionSettings.open_rsvps;

View File

@ -368,6 +368,7 @@
function createNotationFile(notation) {
var notationVals = {
notation_id: notation.id,
file_url: notation.file_url,
file_name: notation.file_name
};

View File

@ -1,7 +1,7 @@
require 'aws-sdk'
class ApiMusicNotationsController < ApiController
before_filter :api_signed_in_user
# before_filter :api_signed_in_user
respond_to :json
@ -18,6 +18,7 @@ class ApiMusicNotationsController < ApiController
music_notation = MusicNotation.new
music_notation.file_url = file
music_notation.file_name = file.original_filename
music_notation.music_session_id = params[:session_id]
music_notation.user = current_user
music_notation.save

View File

@ -209,7 +209,7 @@
</script>
<script type="text/template" id="template-notation-files">
<a href="{file_url}" rel="external">{file_name}</a><br />
<a data-notation-id="{notation_id}" href="{file_url}" rel="external">{file_name}</a><br />
</script>
<script type="text/template" id="template-musician-info">

View File

@ -63,7 +63,7 @@
.spinner-small.upload-spinner
.clearall.right.mt10
%a.button-orange{:href => 'TBD', :rel => 'external'} HELP
%a.button-orange{:href => 'https://jamkazam.desk.com', :rel => 'external'} HELP
%a.button-grey{'layout-action' => "close"} CANCEL
%a.button-orange{:id => "session-settings-dialog-submit"} UPDATE SETTINGS