From 6773ac5a208bd418bec8ecb7a1a14ba817c0fbb0 Mon Sep 17 00:00:00 2001 From: Szymon Nowak Date: Sun, 13 Sep 2015 21:04:52 +0200 Subject: [PATCH] More fixes/ES6 --- app/components/file-field.js | 8 ++--- app/components/ip-select.js | 6 ++-- app/components/modal-dialog.js | 5 ++- app/components/peer-avatar.js | 55 ++++++++++++++----------------- app/components/peer-widget.js | 32 +++++++++--------- app/components/popover-confirm.js | 4 +-- app/components/progress-bar.js | 18 +++++----- app/components/room-url.js | 2 +- 8 files changed, 62 insertions(+), 68 deletions(-) diff --git a/app/components/file-field.js b/app/components/file-field.js index d553a2d..034273d 100644 --- a/app/components/file-field.js +++ b/app/components/file-field.js @@ -4,23 +4,23 @@ export default Ember.TextField.extend({ type: 'file', classNames: ['invisible'], - click(event) { + click: function (event) { event.stopPropagation(); }, - change(event) { + change: function (event) { const input = event.target; const files = input.files; const file = files[0]; this.sendAction('action', { file: file }); - this.reset() + this.reset(); }, // Hackish way to reset file input when sender cancels file transfer, // so if sender wants later to send the same file again, // the 'change' event is triggered correctly. - reset() { + reset: function () { const field = this.$(); field.wrap('
').closest('form').get(0).reset(); field.unwrap(); diff --git a/app/components/ip-select.js b/app/components/ip-select.js index bc49eef..c88318b 100644 --- a/app/components/ip-select.js +++ b/app/components/ip-select.js @@ -4,9 +4,9 @@ export default Ember.Component.extend({ content: null, selectedValue: null, - didInitAttrs() { + didInitAttrs: function () { this._super(...arguments); - var content = this.get("content"); + const content = this.get("content"); if (!content) { this.set("content", []); @@ -14,7 +14,7 @@ export default Ember.Component.extend({ }, actions: { - change() { + change: function () { const changeAction = this.get("action"); const selectedEl = this.$("select")[0]; const selectedIndex = selectedEl.selectedIndex; diff --git a/app/components/modal-dialog.js b/app/components/modal-dialog.js index be93680..c1834bc 100644 --- a/app/components/modal-dialog.js +++ b/app/components/modal-dialog.js @@ -2,11 +2,10 @@ import Ember from 'ember'; export default Ember.Component.extend({ actions: { - close() { - console.log("nop"); + close: function () { return this.sendAction(); }, - nop() {} + nop: function () {} } }); diff --git a/app/components/peer-avatar.js b/app/components/peer-avatar.js index 5118bd6..c8ebd9a 100644 --- a/app/components/peer-avatar.js +++ b/app/components/peer-avatar.js @@ -19,29 +19,28 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, { "data-receiving-progress": alias('peer.transfer.receivingProgress'), didInsertElement: function () { - var self = this, - peer = this.get('peer'), - toggleTransferCompletedClass = function () { - var klass = 'transfer-completed'; + this._super(...arguments); + const peer = this.get('peer'); + const toggleTransferCompletedClass = () => { + const klass = 'transfer-completed'; - Ember.run.later(self, function () { - this.$().parent('.avatar') - .addClass(klass) - .delay(2000) - .queue(function () { - Ember.$(this).removeClass(klass).dequeue(); - }); - }, 250); - }; + Ember.run.later(this, function () { + this.$().parent('.avatar') + .addClass(klass) + .delay(2000) + .queue(function () { + Ember.$(this).removeClass(klass).dequeue(); + }); + }, 250); + }; peer.on('didReceiveFile', toggleTransferCompletedClass); peer.on('didSendFile', toggleTransferCompletedClass); - - this._super(); }, willDestroyElement: function () { - var peer = this.get('peer'); + this._super(...arguments); + const peer = this.get('peer'); peer.off('didReceiveFile'); peer.off('didSendFile'); @@ -71,14 +70,12 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, { drop: function (event) { this.cancelEvent(event); - this.$().parent('.avatar').removeClass('hover'); - var self = this, - peer = this.get('peer'), - dt = event.originalEvent.dataTransfer, - files = dt.files, - file = files[0]; + const peer = this.get('peer'); + const dt = event.originalEvent.dataTransfer; + const files = dt.files; + const file = files[0]; if (this.canSendFile()) { if (files.length > 1) { @@ -87,8 +84,8 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, { errorCode: 'multiple_files' }); } else { - this.isFile(file).then(function () { - self.triggerAction({ + this.isFile(file).then(() => { + this.triggerAction({ action: 'uploadFile', actionContext: { file: file @@ -105,14 +102,10 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, { }, canSendFile: function () { - var peer = this.get('peer'); + const peer = this.get('peer'); // Can't send files if another file transfer is already in progress - if (peer.get('transfer.file') || peer.get('transfer.info')) { - return false; - } - - return true; + return !(peer.get('transfer.file') || peer.get('transfer.info')); }, isFile: function (file) { @@ -124,7 +117,7 @@ export default Ember.Component.extend(Ember.ViewTargetActionSupport, { } else { // Try to read it using FileReader - if it's not a file, // it should trigger onerror handler - var reader = new FileReader(); + const reader = new FileReader(); reader.onload = function () { resolve(); }; reader.onerror = function () { reject(); }; reader.readAsArrayBuffer(file); diff --git a/app/components/peer-widget.js b/app/components/peer-widget.js index 4130e87..0c69602 100644 --- a/app/components/peer-widget.js +++ b/app/components/peer-widget.js @@ -18,19 +18,20 @@ export default Ember.Component.extend({ hasError: equal('peer.state', 'error'), filename: function () { - var file = this.get('peer.transfer.file'), - info = this.get('peer.transfer.info'); + const file = this.get('peer.transfer.file'); + const info = this.get('peer.transfer.info'); if (file) { return file.name; } if (info) { return info.name; } + return null; }.property('peer.transfer.file', 'peer.transfer.info'), actions: { // TODO: rename to something more meaningful (e.g. askIfWantToSendFile) uploadFile: function (data) { - var peer = this.get('peer'), - file = data.file; + const peer = this.get('peer'); + const file = data.file; // Cache the file, so that it's available // when the response from the recipient comes in @@ -39,8 +40,8 @@ export default Ember.Component.extend({ }, sendFileTransferInquiry: function () { - var webrtc = this.get('webrtc'), - peer = this.get('peer'); + const webrtc = this.get('webrtc'); + const peer = this.get('peer'); webrtc.connect(peer.get('peer.id')); }, @@ -52,14 +53,14 @@ export default Ember.Component.extend({ abortFileTransfer: function () { this._cancelFileTransfer(); - var webrtc = this.get('webrtc'), - connection = this.get('peer.peer.connection'); + const webrtc = this.get('webrtc'); + const connection = this.get('peer.peer.connection'); webrtc.sendCancelRequest(connection); }, acceptFileTransfer: function () { - var peer = this.get('peer'); + const peer = this.get('peer'); this._sendFileTransferResponse(true); @@ -70,7 +71,7 @@ export default Ember.Component.extend({ }, rejectFileTransfer: function () { - var peer = this.get('peer'); + const peer = this.get('peer'); this._sendFileTransferResponse(false); peer.set('transfer.info', null); @@ -79,7 +80,7 @@ export default Ember.Component.extend({ }, _cancelFileTransfer: function () { - var peer = this.get('peer'); + const peer = this.get('peer'); peer.setProperties({ 'transfer.file': null, @@ -88,15 +89,16 @@ export default Ember.Component.extend({ }, _sendFileTransferResponse: function (response) { - var webrtc = this.get('webrtc'), - peer = this.get('peer'), - connection = peer.get('peer.connection'); + const webrtc = this.get('webrtc'); + const peer = this.get('peer'); + const connection = peer.get('peer.connection'); webrtc.sendFileResponse(connection, response); }, errorTemplateName: function () { - var errorCode = this.get('peer.errorCode'); + const errorCode = this.get('peer.errorCode'); + return errorCode ? 'errors/popovers/' + errorCode : null; }.property('peer.errorCode'), diff --git a/app/components/popover-confirm.js b/app/components/popover-confirm.js index d6a7e25..1d5b8aa 100644 --- a/app/components/popover-confirm.js +++ b/app/components/popover-confirm.js @@ -4,8 +4,8 @@ export default Ember.Component.extend({ classNames: ['popover-confirm'], iconClass: function () { - var filename = this.get('filename'), - regex, match, extension; + const filename = this.get('filename'); + let regex, match, extension; if (filename) { regex = /\.([0-9a-z]+)$/i; diff --git a/app/components/progress-bar.js b/app/components/progress-bar.js index cf0bf2f..7966c29 100644 --- a/app/components/progress-bar.js +++ b/app/components/progress-bar.js @@ -15,7 +15,7 @@ export default Ember.Component.extend({ }, sendingProgressDidChange: function () { - var progress = this.get('transfer.sendingProgress'); + const progress = this.get('transfer.sendingProgress'); if (this.get('path')) { this._calculateSVGAnim(progress); @@ -23,7 +23,7 @@ export default Ember.Component.extend({ }.observes('transfer.sendingProgress'), receivingProgressDidChange: function () { - var progress = this.get('transfer.receivingProgress'); + const progress = this.get('transfer.receivingProgress'); if (this.get('path')) { this._calculateSVGAnim(progress); @@ -34,13 +34,13 @@ export default Ember.Component.extend({ const path = this.get('path'); if (!path) { return; } - var π = Math.PI, - α = progress * 360, - r = ( α * π / 180 ), - mid = ( α > 180 ) ? 1 : 0, - x = Math.sin( r ) * 38, - y = Math.cos( r ) * - 38, - anim = 'M 0 0 v -38 A 38 38 1 ' + mid + ' 1 ' + x + ' ' + y + ' z'; + const π = Math.PI; + const α = progress * 360; + const r = ( α * π / 180 ); + const mid = ( α > 180 ) ? 1 : 0; + const x = Math.sin( r ) * 38; + const y = Math.cos( r ) * - 38; + const anim = 'M 0 0 v -38 A 38 38 1 ' + mid + ' 1 ' + x + ' ' + y + ' z'; path.attr('d', anim); } diff --git a/app/components/room-url.js b/app/components/room-url.js index ea15e46..3f251c0 100644 --- a/app/components/room-url.js +++ b/app/components/room-url.js @@ -9,7 +9,7 @@ export default Ember.TextField.extend({ copyValueToClipboard: function () { if (window.ClipboardEvent) { - var pasteEvent = new window.ClipboardEvent('paste', { + const pasteEvent = new window.ClipboardEvent('paste', { dataType: 'text/plain', data: this.$().val() });