From 7fe39ba6fe714d902352bb01c0e6688ef897ab18 Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Fri, 23 Sep 2016 18:44:03 -0300 Subject: [PATCH] Improved Firebase synchronization and fixed bugs on service changed in second PC --- app/ux/Firebase.js | 44 ++++++++++++++++++++++++++++++++++++++------ app/ux/WebView.js | 10 ++++++---- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/ux/Firebase.js b/app/ux/Firebase.js index cebf25f1..6fc3e008 100644 --- a/app/ux/Firebase.js +++ b/app/ux/Firebase.js @@ -14,14 +14,43 @@ Ext.define('Rambox.ux.Firebase', { // Attach an asynchronous callback to read the data at our posts reference ref.on("child_changed", function(snapshot, prevChildKey) { + // Disable duplicate actions when user edit a service + var rec = Ext.getStore('Services').findRecord('firebase_key', snapshot.key); + var recData = Ext.clone(rec.data); + delete recData.id; + delete recData.firebase_key; + if ( Ext.Object.equals(recData, snapshot.val()) ) return; + console.info('Firebase - Child Changed', snapshot.val(), snapshot.key, prevChildKey); + // Suspend events Ext.getStore('Services').suspendEvent('update'); - var rec = Ext.getStore('Services').findRecord('firebase_key', snapshot.key); - + // Change the title of the Tab Ext.getCmp('tab_'+rec.get('id')).setTitle(snapshot.val().name); - + // Change sound of the Tab + Ext.getCmp('tab_'+rec.get('id')).setAudioMuted(snapshot.val().muted); + // Change notifications of the Tab + Ext.getCmp('tab_'+rec.get('id')).setNotifications(snapshot.val().notifications); + // Change the icon of the Tab + if ( rec.get('type') === 'custom' && rec.get('logo') !== snapshot.val().logo ) Ext.getCmp('tab_'+rec.get('id')).setConfig('icon', snapshot.val().logo === '' ? 'resources/icons/custom.png' : snapshot.val().logo); + // Change the URL of the Tab + if ( rec.get('url') !== snapshot.val().url ) Ext.getCmp('tab_'+rec.get('id')).setURL(snapshot.val().url); + + // Change the align of the Tab + if ( rec.get('align') !== snapshot.val().align ) { + if ( rec.get('align') === 'left' ) { + Ext.cq1('app-main').moveBefore(Ext.getCmp('tab_'+rec.get('id')), Ext.getCmp('tbfill')); + } else { + Ext.cq1('app-main').moveAfter(Ext.getCmp('tab_'+rec.get('id')), Ext.getCmp('tbfill')); + } + } + // Apply the JS Code of the Tab + if ( rec.get('js_unread') !== snapshot.val().js_unread ) { + Ext.Msg.confirm('CUSTOM CODE', 'Rambox needs to reload the service to execute the new JavaScript code. Do you want to do it now?', function( btnId ) { + if ( btnId === 'yes' ) Ext.getCmp('tab_'+rec.get('id')).reloadService(); + }); + } // Position if ( rec.get('position') !== snapshot.val().position ) { var pos = parseInt(snapshot.val().position); @@ -29,11 +58,14 @@ Ext.define('Rambox.ux.Firebase', { Ext.cq1('app-main').move(Ext.getCmp('tab_'+rec.get('id')), pos); } - // Enable/Disable - if ( rec.get('enable') !== snapshot.val().enable ) Ext.getCmp('tab_'+rec.get('id')).setEnabled(snapshot.val().enabled); - rec.set(snapshot.val()); rec.save(); + Ext.getCmp('tab_'+rec.get('id')).record = rec; + Ext.getCmp('tab_'+rec.get('id')).tabConfig.service = rec; + + // Enable/Disable + if ( recData.enabled !== snapshot.val().enabled ) Ext.getCmp('tab_'+rec.get('id')).setEnabled(snapshot.val().enabled); + Ext.getStore('Services').resumeEvent('update'); Ext.getStore('Services').load(); }, function (errorObject) { diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 0e208a38..38cdcaf3 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -129,11 +129,13 @@ Ext.define('Rambox.ux.WebView',{ me.callParent(config); } - ,webViewConstructor: function() { + ,webViewConstructor: function( enabled ) { var me = this; - + var cfg; - if ( !me.record.get('enabled') ) { + enabled = enabled || me.record.get('enabled'); + + if ( !enabled ) { cfg = { xtype: 'container' ,html: '

Service Disabled

' @@ -362,7 +364,7 @@ Ext.define('Rambox.ux.WebView',{ me.tab.setBadgeText(''); me.removeAll(); - me.add(me.webViewConstructor()); + me.add(me.webViewConstructor(enabled)); if ( enabled ) { me.resumeEvent('afterrender'); me.show();