Fix title setter logic and separate it from UI

pull/1/head
Caleb James DeLisle 7 years ago
parent ec87f3f897
commit cf6d8c83b2

@ -16,6 +16,7 @@ define([], function () {
var dirty = true; var dirty = true;
var changeHandlers = []; var changeHandlers = [];
var lazyChangeHandlers = []; var lazyChangeHandlers = [];
var titleChangeHandlers = [];
var rememberedTitle; var rememberedTitle;
@ -50,13 +51,14 @@ define([], function () {
var lazyUserStr = JSON.stringify(metadataLazyObj.users[meta.user.netfluxId]); var lazyUserStr = JSON.stringify(metadataLazyObj.users[meta.user.netfluxId]);
dirty = false; dirty = false;
if (lazy || lazyUserStr !== JSON.stringify(meta.user)) { if (lazy || lazyUserStr !== JSON.stringify(meta.user)) {
metadataLazyObj.users = mdo; metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
lazyChangeHandlers.forEach(function (f) { f(); }); lazyChangeHandlers.forEach(function (f) { f(); });
} }
if (metadataObj.title !== rememberedTitle) { if (metadataObj.title !== rememberedTitle) {
console.log("Title update\n" + metadataObj.title + '\n'); console.log("Title update\n" + metadataObj.title + '\n');
rememberedTitle = metadataObj.title; rememberedTitle = metadataObj.title;
titleChangeHandlers.forEach(function (f) { f(metadataObj.title); });
} }
changeHandlers.forEach(function (f) { f(); }); changeHandlers.forEach(function (f) { f(); });
@ -113,6 +115,7 @@ define([], function () {
getMetadataLazy: function () { getMetadataLazy: function () {
return metadataLazyObj; return metadataLazyObj;
}, },
onTitleChange: function (f) { titleChangeHandlers.push(f); },
onChange: function (f) { changeHandlers.push(f); }, onChange: function (f) { changeHandlers.push(f); },
onChangeLazy: function (f) { lazyChangeHandlers.push(f); }, onChangeLazy: function (f) { lazyChangeHandlers.push(f); },
isConnected : function () { isConnected : function () {

@ -15,9 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define([ define([
'/common/metadata-manager.js',
'/bower_components/chainpad/chainpad.dist.js' '/bower_components/chainpad/chainpad.dist.js'
], function (MetadataMgr) { ], function () {
var ChainPad = window.ChainPad; var ChainPad = window.ChainPad;
var module = { exports: {} }; var module = { exports: {} };
@ -39,14 +38,13 @@ define([
var logLevel = typeof(config.logLevel) !== 'undefined'? config.logLevel : 1; var logLevel = typeof(config.logLevel) !== 'undefined'? config.logLevel : 1;
var readOnly = config.readOnly || false; var readOnly = config.readOnly || false;
var sframeChan = config.sframeChan; var sframeChan = config.sframeChan;
var metadataMgr = config.metadataMgr;
config = undefined; config = undefined;
var chainpad; var chainpad;
var myID; var myID;
var isReady = false; var isReady = false;
var metadataMgr = MetadataMgr.create(sframeChan);
sframeChan.on('EV_RT_DISCONNECT', function () { sframeChan.on('EV_RT_DISCONNECT', function () {
isReady = false; isReady = false;
onConnectionChange({ state: false }); onConnectionChange({ state: false });

@ -50,19 +50,9 @@ define(['jquery'], function ($) {
cb = cb || $.noop; cb = cb || $.noop;
if (newTitle === exp.title) { return; } if (newTitle === exp.title) { return; }
// Change the title now, and set it back to the old value if there is an error // Change the title now, and set it back to the old value if there is an error
var oldTitle = exp.title; //var oldTitle = exp.title;
Common.setPadTitleInDrive(newTitle, function (err, data) { Common.updateTitle(newTitle, cb)
if (err) { //cb(null, newTitle);
console.log("Couldn't set pad title");
console.error(err);
updateLocalTitle(oldTitle);
return void cb(err);
}
metadataMgr.updateTitle(newTitle);
//onLocal();
cb(null, data);
if (!$title) { return; }
});
}; };
// TODO not needed? // TODO not needed?

@ -2,9 +2,10 @@ define([
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/common/sframe-chainpad-netflux-inner.js', '/common/sframe-chainpad-netflux-inner.js',
'/common/sframe-channel.js', '/common/sframe-channel.js',
'/common/sframe-common-title.js' '/common/sframe-common-title.js',
'/common/metadata-manager.js',
], function (nThen, CpNfInner, SFrameChannel, Title) { ], function (nThen, CpNfInner, SFrameChannel, Title, MetadataMgr) {
// Chainpad Netflux Inner // Chainpad Netflux Inner
var funcs = {}; var funcs = {};
@ -13,6 +14,7 @@ define([
funcs.startRealtime = function (options) { funcs.startRealtime = function (options) {
if (ctx.cpNfInner) { return ctx.cpNfInner; } if (ctx.cpNfInner) { return ctx.cpNfInner; }
options.sframeChan = ctx.sframeChan; options.sframeChan = ctx.sframeChan;
options.metadataMgr = ctx.metadataMgr;
ctx.cpNfInner = CpNfInner.start(options); ctx.cpNfInner = CpNfInner.start(options);
ctx.cpNfInner.metadataMgr.onChangeLazy(options.onLocal); ctx.cpNfInner.metadataMgr.onChangeLazy(options.onLocal);
return ctx.cpNfInner; return ctx.cpNfInner;
@ -23,10 +25,10 @@ define([
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName; return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
}; };
funcs.setPadTitleInDrive = function (title, cb) { var titleUpdated;
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) { funcs.updateTitle = function (title, cb) {
if (cb) { cb(err, title); } ctx.metadataMgr.updateTitle(title);
}); titleUpdated = cb;
}; };
// Title module // Title module
@ -49,6 +51,13 @@ define([
SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; })); SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; }));
// CpNfInner.start() should be here.... // CpNfInner.start() should be here....
}).nThen(function () { }).nThen(function () {
ctx.metadataMgr = MetadataMgr.create(ctx.sframeChan);
ctx.metadataMgr.onTitleChange(function (title) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (err) { return; }
if (titleUpdated) { titleUpdated(undefined, title); }
});
});
cb(funcs); cb(funcs);
}); });
} }; } };

@ -725,6 +725,7 @@ define([
realtimeOptions.onError = onConnectError; realtimeOptions.onError = onConnectError;
var onLocal = realtimeOptions.onLocal = function () { var onLocal = realtimeOptions.onLocal = function () {
console.log('onlocal');
if (initializing) { return; } if (initializing) { return; }
if (isHistoryMode) { return; } if (isHistoryMode) { return; }
if (readOnly) { return; } if (readOnly) { return; }

Loading…
Cancel
Save