From 091fbb0d41994e735ff8b1c96266b6557b44b3b6 Mon Sep 17 00:00:00 2001 From: hamza zia Date: Thu, 3 Jul 2014 01:04:03 +0800 Subject: [PATCH] only update aria2 download and global settings when they change --- js/ctrls/modal.js | 15 +++++++++++---- js/ctrls/nav.js | 13 ++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/js/ctrls/modal.js b/js/ctrls/modal.js index ab2f742..fbbf0ef 100644 --- a/js/ctrls/modal.js +++ b/js/ctrls/modal.js @@ -57,11 +57,14 @@ angular delete self.inst; if (self.cb) { var settings = {}; + // no need to send in default values, just the changed ones for (var i in self.settings) { - settings[i] = self.settings[i].val; + if (fsettings[i].val != self.settings[i].val) + settings[i] = self.settings[i].val; } for (var i in self.fsettings) { - settings[i] = self.fsettings[i].val; + if (fsettings[i].val != self.fsettings[i].val) + settings[i] = self.fsettings[i].val; } console.log('sending settings:', settings); @@ -152,11 +155,15 @@ angular if (cb) { parseFiles(self.files, function(txts) { var settings = {}; + + // no need to send in default values, just the changed ones for (var i in self.settings) { - settings[i] = self.settings[i].val; + if (fsettings[i].val != self.settings[i].val) + settings[i] = self.settings[i].val; } for (var i in self.fsettings) { - settings[i] = self.fsettings[i].val; + if (fsettings[i].val != self.fsettings[i].val) + settings[i] = self.fsettings[i].val; } console.log('sending settings:', settings); diff --git a/js/ctrls/nav.js b/js/ctrls/nav.js index 590d244..c71ec57 100644 --- a/js/ctrls/nav.js +++ b/js/ctrls/nav.js @@ -103,19 +103,22 @@ angular } modals.invoke( - 'settings', settings, - 'Global Settings', 'Save', function(settings) { + 'settings', _.cloneDeep(settings), + 'Global Settings', 'Save', function(chsettings) { var sets = {}; var starred = []; - for (var i in settings) { - sets[i] = settings[i].val + for (var i in chsettings) { + // no need to change default values + if (settings[i].val != chsettings[i].val) + sets[i] = chsettings[i].val - if (settings[i].starred) { + if (chsettings[i].starred) { starred.push(i); } }; + console.log('saving aria2 settings:', sets); console.log('saving aria2 starred:', starred); rpc.once('changeGlobalOption', [sets]);