From 10793b9fec7dde0fbb005c70923f96975c8ffcc2 Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Sun, 17 Jul 2016 22:31:04 +0200 Subject: restructure socketlist, still in broken state. diff --git a/www/js/importer.js b/www/js/importer.js index 6579d4e..eacfd57 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -31,6 +31,7 @@ Rdxport.Importer = function(username, token, rhimpordEndpoint) { this.$el = $('#uploadModal'); this.listWebSocket = null; + this.sessions = []; this.uploads = []; this.initListWebSocket(); @@ -69,58 +70,50 @@ Rdxport.Importer.prototype.initListWebSocket = function() { PASSWORD: importer.token }; this.send(JSON.stringify(sendOptions)); - var self = this; - setInterval(function() { - self.send(JSON.stringify(sendOptions)); - }, 3 * 1000); }; this.listWebSocket.onmessage = function(event) { var data = $.parseJSON(event.data); - if (data.TYPE.toLowerCase() === Rdxport.Importer.TYPE_LIST) { - $.each(data.SESSIONS, function(id, reference) { - if (importer.getUploadById(id) !== null) { - return true; //continue; - } - var reference = reference.split('/'); - var groupName = reference[0]; - var cartNumber = reference[1]; - var filename = reference[2]; - - var groupViews = null; - switch (router.activeRoute) { - default: - //fallthrough - case 'shows': - if (showListView) { - groupViews = showListView.showViews; - } - case 'jingles': - if (jingleGroupListView) { - groupViews = jingleGroupListView.jingleGroupViews; - } - case 'musicpools': - if (musicpoolsView) { - groupViews = musicpoolsView.musicpoolViews; - } - } + console.log(data); + if (data.TYPE.toLowerCase() !== Rdxport.Importer.TYPE_LIST) { + return; + } - var groupView = groupViews.find(function (element) { - return element.model.groupName === groupName; - }); + $.each(data.SESSIONS_ADDED, function(id, reference) { + self.sessions[id] = reference; + }); + $.each(data.SESSIONS_REMOVED, function(id, reference) { + delete self.sessions[id]; + }); + console.log('sessions'); + console.log(self.sessions); + }; +}; - if (!groupView) { - return true; //continue; - } +Rdxport.Importer.prototype.syncUploads = function(route, groupView, done) { + console.log('syncUploads'); - var group = groupView.model; + var sessions = this.sessions.filter(function(reference) { + var reference = reference.split('/'); + return route === reference[0] && groupView.model.groupName === reference[1]; + }); - var upload = new Rdxport.Upload('/' + filename, group, groupView, cartNumber, cartNumber, null); - upload.reconnect(id, reference); - self.uploads.push(upload); - }); + var self = this; + $.each(sessions, function(id, reference) { + if (importer.getUploadById(id) !== null) { + return true; //continue; } - }; + var reference = reference.split('/'); + var cartNumber = reference[2]; + var filename = reference[3]; + var group = groupView.model; + var upload = new Rdxport.Upload('/' + filename, group, groupView, cartNumber, cartNumber, null); + upload.reconnect(id, reference); + self.uploads.push(upload); + }); + if (done) { + done(); + } }; Rdxport.Importer.prototype.resetModal = function() { @@ -245,10 +238,11 @@ Rdxport.Importer.prototype.isUploading = function() { return $result; }; -Rdxport.Importer.prototype.closeAllUploads = function() { +Rdxport.Importer.prototype.closeAllUploads = function(silent) { + silent = silent || false; $.each(this.uploads, function(index, upload) { if (upload) { - upload.close(); + upload.close(silent); } }); }; @@ -449,6 +443,17 @@ Rdxport.Upload.prototype.import = function() { this.webSocket.onmessage = function(event) { self.onmessage(event) }; this.webSocket.onopen = function() { + var reference = ''; + if (self.group instanceof Rdxport.Show) { + reference += 'shows/'; + } else if (self.group instanceof Rdxport.JingleGroup) { + reference += 'jingles/'; + } else if (self.group instanceof Rdxport.Musicpool) { + reference += 'musicpools/'; + } + reference += self.group.groupName + '/'; + reference += self.cartNumber ? self.cartNumber + '/' : '/'; + reference += self.filename; var sendOptions = { COMMAND: Rdxport.Importer.CMD_NEW, LOGIN_NAME: importer.username, @@ -458,16 +463,15 @@ Rdxport.Upload.prototype.import = function() { CHANNELS: 2, NORMALIZATION_LEVEL: self.group.normlevel, AUTOTRIM_LEVEL: self.group.trimlevel, - USE_METADATA: self.useMetadata - }; + USE_METADATA: self.useMetadata, + REFERENCE_ID: reference + }; if (self.group instanceof Rdxport.Show) { sendOptions.SHOW_ID = self.group.id; } if (self.cartNumber) { - 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.MUSIC_POOL_GROUP = self.group.groupName; } console.log(sendOptions); @@ -496,10 +500,13 @@ Rdxport.Upload.prototype.reconnect = function(id, reference) { }; }; -Rdxport.Upload.prototype.close = function() { +Rdxport.Upload.prototype.close = function(silent) { + silent = silent || false; this.webSocket.close(); importer.removeUpload(this); - this.group.fetchCarts(); + if (!silent) { + this.group.fetchCarts(); + } }; Rdxport.Upload.prototype.cancel = function() { diff --git a/www/js/jingles.js b/www/js/jingles.js index 7c82a39..fd2ddf1 100644 --- a/www/js/jingles.js +++ b/www/js/jingles.js @@ -32,7 +32,6 @@ function jingles_init() { } function jingles_cleanup() { - importer.closeAllUploads(); if (jingleGroupListView) { jingleGroupListView.destroy(); jingleGroupListView = null; diff --git a/www/js/musicpools.js b/www/js/musicpools.js index 7fdb3c6..6e7f81c 100644 --- a/www/js/musicpools.js +++ b/www/js/musicpools.js @@ -32,7 +32,6 @@ function musicpools_init(subpage) { } function musicpools_cleanup() { - importer.closeAllUploads(); musicpoolsView = null; } diff --git a/www/js/router.js b/www/js/router.js index 6dd6744..9e11383 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -62,6 +62,7 @@ Rdxport.Router.prototype.route = function(page, subpage) { } }; } + importer.closeAllUploads(true); if (!rdxport) { rdxport = new Rdxport.Rdxport(this.auth.username, this.auth.token, '/rd-bin/rdxport.cgi'); rdxport.setListDropboxesEndpoint('/rh-bin/listdropboxes.cgi'); @@ -148,6 +149,7 @@ Rdxport.Router.prototype.logout = function() { musicgrid_cleanup(); this.auth.cleanup(); + importer.closeAllUploads(true); importer = null; rdxport = null; diff --git a/www/js/shows.js b/www/js/shows.js index 9cbc72e..b9eb834 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -36,7 +36,6 @@ function shows_init(subpage) { function shows_cleanup() { $('#show-carts tbody').find('tr').remove(); - importer.closeAllUploads(); } Rdxport.ShowListView = function(model, subpage) { @@ -215,7 +214,6 @@ Rdxport.ShowView = function(model) { this.cartViews = []; this.$el = null; - var self = this; this.model.$this.off('update').on('update', function() { self.render(); @@ -242,7 +240,7 @@ Rdxport.ShowView.prototype.render = function() { } } - var $tableBody = $('#app-shows table tbody'); + var $tableBody = $('#app-shows table tbody', this.$el); $('tr', $tableBody).remove(); this.cartViews = []; @@ -251,7 +249,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)); + $('#app-shows table > tbody', self.$el).append(Rdxport.ShowCartView.renderUploading(upload)); if (upload.error) { self.uploadError(upload); } @@ -259,9 +257,9 @@ Rdxport.ShowView.prototype.render = function() { var cartView = new Rdxport.ShowCartView(cart, self); self.cartViews.push(cartView); cartView.render(); - $('#app-shows table > tbody').append(cartView.$el); + $('#app-shows table > tbody', self.$el).append(cartView.$el); } else { - $('#app-shows table > tbody').append(Rdxport.ShowCartView.renderEmpty(self.model, self, log.cartNumber)); + $('#app-shows table > tbody', self.$el).append(Rdxport.ShowCartView.renderEmpty(self.model, self, log.cartNumber)); } }); }; @@ -317,7 +315,6 @@ Rdxport.ShowView.prototype.uploadError = function(upload) { }); var $cart = $('tr[data-upload-id="' + upload.uploadId + '"]', this.$el).first(); - console.log($('tr')); $cart.replaceWith($errorRow); }; -- cgit v0.10.2