From a5241e6b6c3371e1f1fb11bcfbd00390038d1589 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Fri, 15 Jul 2016 19:15:05 +0200 Subject: fix error render, update cart-number and name on progress diff --git a/www/js/importer.js b/www/js/importer.js index cbea665..7e72150 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -247,7 +247,7 @@ Rdxport.Importer.prototype.getUploadByCartNumber = function(cartNumber) { } var upload = null; $.each(this.uploads, function(index, currentUpload) { - if (currentUpload.cartNumber === cartNumber) { + if (parseInt(currentUpload.cartNumber) === parseInt(cartNumber)) { upload = currentUpload; return false; //break; } @@ -274,7 +274,7 @@ Rdxport.Importer.prototype.getUploadsByCartNumber = function(cartNumber) { return null; } return this.uploads.filter(function (currentUpload) { - return currentUpload.cartNumber === cartNumber; + return currentUpload.cartNumber === parseInt(cartNumber); }); }; @@ -300,10 +300,12 @@ Rdxport.Upload = function(fileOrsourceUri, group, groupView, cartNumber, useMeta this.filename = fileOrsourceUri.name; this.sourceUri = 'attachment://' + fileOrsourceUri.size + '/' + this.filename; } + this.title = this.filename; this.group = group; this.groupView = groupView; this.cartNumber = cartNumber; + this.cutNumber = null; this.useMetadata = useMetadata; this.uploadId = null; @@ -332,37 +334,44 @@ Rdxport.Upload.prototype.onerror = function(error) { console.log('error'); console.log(error); - var file = { - cartNumber: this.cartNumber - }; - this.importFileUploadError(file, 500, error); + this.importFileUploadError(500, error); }; Rdxport.Upload.prototype.onmessage = function(event) { var data = $.parseJSON(event.data); this.uploadId = data.ID; - var file = { - cartNumber: this.cartNumber - }; switch (data.TYPE.toLowerCase()) { case Rdxport.Importer.TYPE_ERROR: + this.importFileUploadError(data.RESPONSE_CODE, data.ERROR_STRING); + break; + case Rdxport.Importer.TYPE_ACK: console.log(data); - this.importFileUploadError(file, data.RESPONSE_CODE, data.ERROR_STRING); + this.groupView.uploadProgress(this); break; case Rdxport.Importer.TYPE_PROGRESS: + console.log(data); this.uploadprogress.current = data.CURRENT; this.uploadprogress.total = data.TOTAL; this.uploadprogress.progress = data.PROGRESS; this.uploadprogress.progress_step = data.PROGRESS_STEP; this.uploadprogress.progress_step_name = data.PROGRESS_STEP_NAME; - this.groupView.uploadProgress(this, file); + if (data.CART_NUMBER) { + this.cartNumber = data.CART_NUMBER; + } + if (data.CUT_NUMBER) { + this.cutNumber = data.CUT_NUMBER; + } + if (data.TITLE) { + this.title = data.TITLE; + } + this.groupView.uploadProgress(this); break; case Rdxport.Importer.TYPE_DONE: console.log(data); if(data.RESPONSE_CODE < 400) { this.importFileUploadSuccess(); } else { - this.importFileUploadError(file, data.RESPONSE_CODE, data.ERROR_STRING); + this.importFileUploadError(data.RESPONSE_CODE, data.ERROR_STRING); } break; } @@ -421,7 +430,7 @@ Rdxport.Upload.prototype.import = function() { sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.cartNumber + '/' + self.filename; sendOptions.CART_NUMBER = parseInt(self.cartNumber); } else if (self.group instanceof Rdxport.Musicpool) { - sendOptions.REFERENCE_ID = self.group.groupName + '/' + '/' + self.filename; + sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.filename; sendOptions.MUSIC_POOL_GROUP = self.group.groupName; } console.log(sendOptions); @@ -454,15 +463,16 @@ Rdxport.Upload.prototype.reconnect = function(id, reference) { Rdxport.Upload.prototype.close = function() { this.webSocket.close(); - this.group.fetchCarts(); importer.removeUpload(this); + this.group.fetchCarts(); }; Rdxport.Upload.prototype.cancel = function() { this.webSocket.send(JSON.stringify({ COMMAND: 'cancel' })); this.webSocket.close(); - this.group.fetchCarts(); + // todo: only do this when i get "done" importer.removeUpload(this); + this.group.fetchCarts(); }; Rdxport.Upload.prototype.importFileUploadSuccess = function() { @@ -470,9 +480,10 @@ Rdxport.Upload.prototype.importFileUploadSuccess = function() { this.group.fetchCarts(); }; -Rdxport.Upload.prototype.importFileUploadError = function(file, status, errorString) { +Rdxport.Upload.prototype.importFileUploadError = function(status, errorString) { + this.uploadprogress.progress_step = 99; // makes isUploading return false var self = this; - this.groupView.uploadError(this, file, status, errorString, function() { - self.cancel(); + this.groupView.uploadError(this, status, errorString, function() { + self.close(); }); }; diff --git a/www/js/jingles.js b/www/js/jingles.js index 04ae087..3475faf 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -116,11 +116,10 @@ Rdxport.JingleGroupView.prototype.destroy = function() { $('table > tbody', this.$el).empty(); }; -Rdxport.JingleGroupView.prototype.uploadProgress = function(upload, file) { +Rdxport.JingleGroupView.prototype.uploadProgress = function(upload) { var $cut = $('tr[data-upload-id="' + upload.uploadId + '"]').first(); if (!$cut.hasClass('uploading')) { var $progressBar = $('.progressBarTemplate.jingles').clone().removeClass('progressBarTemplate'); - $('.file-name', $progressBar).text(upload.filename); $cut.html($progressBar.html()); $('button', $cut).on('click', function() { @@ -129,14 +128,17 @@ Rdxport.JingleGroupView.prototype.uploadProgress = function(upload, file) { $cut.addClass('uploading'); } + if (upload.title) { + $('.file-name', $cut).text(upload.title); + } + if (upload.cutNumber) { + $('.cut-number', $cut).text(upload.cutNumber); + } updateProgressBar($cut, upload); }; -Rdxport.JingleGroupView.prototype.uploadError = function(upload, file, status, errorString, acknowledge) { - if (!file.cartNumber || !file.cutNumber) { - return; - } +Rdxport.JingleGroupView.prototype.uploadError = function(upload, status, errorString, acknowledge) { var reason = $('').addClass('label').addClass('label-danger').text(status).after($('').text(' ' + errorString)); var dismiss_button = ''; var $errorRow = $('') - .attr('id', 'musicpool-' + file.cartNumber) - .append($('').text(file.cartNumber)) - .append($('').addClass('file-name').text(upload.filename)) + .attr('data-upload-id', upload.uploadId) + .append($('').addClass('.cart-number').text('...')) + .append($('').addClass('file-name')) .append($('').append($('').text('Import Fehler'))) .append($('').append(reason)) .append($('').css('text-align', 'center').append(dismiss_button)); + if (upload.cartNumber) { + $('.cart-number', $errorRow).text(upload.cartNumber); + } + if (upload.title) { + $('.file-name', $errorRow).text(upload.title); + } + $('button', $errorRow).on('click', function() { acknowledge(); }); - $('#musicpool-' + file.cartNumber).replaceWith($errorRow); + var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]').first(); + $cart.replaceWith($errorRow); }; Rdxport.MusicpoolCartView = function(model) { @@ -281,7 +290,7 @@ Rdxport.MusicpoolCartView.prototype.render = function() { Rdxport.MusicpoolCartView.renderUploading = function(upload) { var $progressBar = $('.progressBarTemplate.musicpools').clone().removeClass('progressBarTemplate'); - $('.file-name', $progressBar).text(upload.filename); + $('.file-name', $progressBar).text(upload.title); var $el = $('') .html($progressBar.html()) diff --git a/www/js/shows.js b/www/js/shows.js index 82e38b5..7dc94d3 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -251,7 +251,7 @@ Rdxport.ShowView.prototype.render = function() { var cart = self.model.getCartByNumber(log.cartNumber); var upload = importer.getUploadByCartNumber(log.cartNumber); if (upload) { - $('#app-shows table > tbody').append(Rdxport.ShowCartView.renderUploading(upload, log.cartNumber)); + $('#app-shows table > tbody').append(Rdxport.ShowCartView.renderUploading(upload)); } else if (cart) { var cartView = new Rdxport.ShowCartView(cart, self); self.cartViews.push(cartView); @@ -263,12 +263,10 @@ Rdxport.ShowView.prototype.render = function() { }); }; -Rdxport.ShowView.prototype.uploadProgress = function(upload, file) { +Rdxport.ShowView.prototype.uploadProgress = function(upload) { var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]').first(); if (!$cart.hasClass('uploading')) { var $progressBar = $('.progressBarTemplate.shows').clone().removeClass('progressBarTemplate'); - $('.file-name', $progressBar).text(file.name); - $('.cart-number', $progressBar).text(file.cartNumber); $cart.html($progressBar.html()); $('button', $cart).off('click').on('click', function() { @@ -277,32 +275,43 @@ Rdxport.ShowView.prototype.uploadProgress = function(upload, file) { $cart.addClass('uploading'); } + if (upload.title) { + $('.file-name', $cart).text(upload.title); + } + if (upload.cartNumber) { + $('.cart-number', $cart).text(upload.cartNumber); + } updateProgressBar($cart, upload); }; -Rdxport.ShowView.prototype.uploadError = function(upload, file, status, errorString, acknowledge) { - if (!file.cartNumber) { - return; - } +Rdxport.ShowView.prototype.uploadError = function(upload, status, errorString, acknowledge) { var reason = $('').addClass('label').addClass('label-danger').text(status).after($('').text(' ' + errorString)); var dismiss_button = ''; var $errorRow = $('') - .attr("id", "show-cart-" + file.cartNumber) - .append($('').text(file.cartNumber)) - .append($('').addClass('file-name').text(upload.filename)) + .attr('data-upload-id', upload.uploadId) + .append($('').addClass('.cart-number').text('...')) + .append($('').addClass('file-name')) .append($('').append($('').text('Import Fehler'))) .append($('').append(reason)) .append($('').css('text-align', 'center').append(dismiss_button)); + if (upload.cartNumber) { + $('.cart-number', $errorRow).text(upload.cartNumber); + } + if (upload.title) { + $('.file-name', $errorRow).text(upload.title); + } + $('button', $errorRow).off('click').on('click', function() { acknowledge(); }); - $('#show-cart-' + file.cartNumber).replaceWith($errorRow); + var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]').first(); + $cart.replaceWith($errorRow); }; Rdxport.ShowCartView = function(model, groupView) { @@ -345,14 +354,14 @@ Rdxport.ShowCartView.prototype.render = function() { .append($('').css('text-align', 'center').append($deleteButton)); }; -Rdxport.ShowCartView.renderUploading = function(upload, cartNumber) { +Rdxport.ShowCartView.renderUploading = function(upload) { var $progressBar = $('.progressBarTemplate.shows').clone().removeClass('progressBarTemplate'); - $('.file-name', $progressBar).text(upload.filename); - $('.cart-number', $progressBar).text(cartNumber); + $('.file-name', $progressBar).text(upload.title); + $('.cart-number', $progressBar).text(upload.cartNumber); var $el = $('') .html($progressBar.html()) - .attr('id', 'show-cart-' + cartNumber) + .attr('id', 'show-cart-' + upload.cartNumber) .addClass('uploading') .attr('data-upload-id', upload.uploadId); -- cgit v0.10.2