Cleanup cruft. Start wiring things up

This commit is contained in:
s1341 2013-12-13 11:59:17 +02:00
parent 360bb55dac
commit 11146ce1cd
4 changed files with 40 additions and 225 deletions

View file

@ -1,128 +0,0 @@
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
/**
* Copyright 2009 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// revision info is a skip list whos entries represent a particular revision
// of the document. These revisions are connected together by various
// changesets, or deltas, between any two revisions.
function loadBroadcastRevisionsJS(clientVars)
{
function Revision(revNum)
{
this.rev = revNum;
this.changesets = [];
}
Revision.prototype.addChangeset = function(destIndex, changeset, timeDelta)
{
var changesetWrapper = {
deltaRev: destIndex - this.rev,
deltaTime: timeDelta,
getValue: function()
{
return changeset;
}
};
this.changesets.push(changesetWrapper);
this.changesets.sort(function(a, b)
{
return (b.deltaRev - a.deltaRev);
});
};
revisionInfo = {};
revisionInfo.addChangeset = function(fromIndex, toIndex, changeset, backChangeset, timeDelta)
{
var startRevision = revisionInfo[fromIndex] || revisionInfo.createNew(fromIndex);
var endRevision = revisionInfo[toIndex] || revisionInfo.createNew(toIndex);
startRevision.addChangeset(toIndex, changeset, timeDelta);
endRevision.addChangeset(fromIndex, backChangeset, -1 * timeDelta);
}
revisionInfo.latest = clientVars.collab_client_vars.rev || -1;
revisionInfo.createNew = function(index)
{
revisionInfo[index] = new Revision(index);
if (index > revisionInfo.latest)
{
revisionInfo.latest = index;
}
return revisionInfo[index];
}
// assuming that there is a path from fromIndex to toIndex, and that the links
// are laid out in a skip-list format
revisionInfo.getPath = function(fromIndex, toIndex)
{
var changesets = [];
var spans = [];
var times = [];
var elem = revisionInfo[fromIndex] || revisionInfo.createNew(fromIndex);
if (elem.changesets.length != 0 && fromIndex != toIndex)
{
var reverse = !(fromIndex < toIndex)
while (((elem.rev < toIndex) && !reverse) || ((elem.rev > toIndex) && reverse))
{
var couldNotContinue = false;
var oldRev = elem.rev;
for (var i = reverse ? elem.changesets.length - 1 : 0;
reverse ? i >= 0 : i < elem.changesets.length;
i += reverse ? -1 : 1)
{
if (((elem.changesets[i].deltaRev < 0) && !reverse) || ((elem.changesets[i].deltaRev > 0) && reverse))
{
couldNotContinue = true;
break;
}
if (((elem.rev + elem.changesets[i].deltaRev <= toIndex) && !reverse) || ((elem.rev + elem.changesets[i].deltaRev >= toIndex) && reverse))
{
var topush = elem.changesets[i];
changesets.push(topush.getValue());
spans.push(elem.changesets[i].deltaRev);
times.push(topush.deltaTime);
elem = revisionInfo[elem.rev + elem.changesets[i].deltaRev];
break;
}
}
if (couldNotContinue || oldRev == elem.rev) break;
}
}
var status = 'partial';
if (elem.rev == toIndex) status = 'complete';
return {
'fromRev': fromIndex,
'rev': elem.rev,
'status': status,
'changesets': changesets,
'spans': spans,
'times': times
};
}
}
exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS;

View file

@ -1,9 +1,3 @@
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
/**
* Copyright 2009 Google Inc.
*
@ -20,8 +14,6 @@
* limitations under the License.
*/
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.
var _ = require('./underscore');
var padmodals = require('./pad_modals').padmodals;
var sliderui = require('./sliderui');
@ -31,9 +23,9 @@ $.Class("RevisionSlider",
{//statics
},
{//instance
init: function (timeslider, root_element) {
this.timeslider = timeslider;
this.revision_number = this.timeslider.head_revision;
init: function (connection, root_element) {
this.connection = connection;
this.revision_number = this.connection.head_revision;
console.log("New RevisionSlider, head_revision = %d", this.revision_number);
// parse the various elements we need:
this.elements = {};
@ -41,12 +33,13 @@ $.Class("RevisionSlider",
var _this = this;
this.slider = new SliderUI(this.elements.slider_bar,
options = {
max: this.timeslider.head_revision,
value: this.revision_number,
max: this.connection.head_revision,
change: function () { _this.onChange.apply(_this, arguments); },
slide: function () { _this.onSlide.apply(_this, arguments); },
});
this.loadSavedRevisionHandles();
this.slider.render();
this._mouseInit();
},
onChange: function (value) {
@ -69,8 +62,8 @@ $.Class("RevisionSlider",
this.elements.authors = root_element.first("#authorsList");
},
loadSavedRevisionHandles: function () {
for (var r in this.timeslider.savedRevisions) {
var rev = this.timeslider.savedRevisions[r];
for (var r in this.connection.savedRevisions) {
var rev = this.connection.savedRevisions[r];
this.slider.createHandle(rev.revNum, "star");
}
},
@ -79,8 +72,8 @@ $.Class("RevisionSlider",
//and changeset rendering that that implies), and perform the setPosition in a callback.
//TODO: we need some kind of callback for setting revision metadata.
//TODO: at some point we need to set window.location.hash
if (revNum > this.timeslider.head_revision)
revNum = this.timeslider.latest_revision;
if (revNum > this.connection.head_revision)
revNum = this.connection.latest_revision;
if (revNum < 0)
revNum = 0;
console.log("GO TO REVISION", revNum);
@ -105,7 +98,7 @@ $.Class("RevisionSlider",
}
);
function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
function init(tsclient, fireWhenAllScriptsAreLoaded)
{
var BroadcastSlider;
@ -119,6 +112,8 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
var rev = Number(window.location.hash.substr(1));
if(!isNaN(rev))
tsui.goToRevision(rev);
} else {
//tsui.goToRevision()
}
@ -490,4 +485,4 @@ function loadBroadcastSliderJS(tsclient, fireWhenAllScriptsAreLoaded)
return BroadcastSlider;
}
exports.loadBroadcastSliderJS = loadBroadcastSliderJS;
exports.init = init;

View file

@ -1,9 +1,3 @@
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
/**
* Copyright 2009 Google Inc.
*
@ -19,12 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// revision info is a skip list whos entries represent a particular revision
// of the document. These revisions are connected together by various
// changesets, or deltas, between any two revisions.
//require('./jquery.class');
require('./jquery.class');
var libchangeset = require("./Changeset");
$.Class("Changeset",
{//statics
@ -39,6 +29,17 @@ $.Class("Changeset",
getValue: function () {
return this.value;
},
/**
* Apply this changeset to the passed pad.
* @param {PadClient} pad - The pad to apply the changeset to.
*/
apply: function (pad) {
// must mutate attribution lines before text lines
libchangeset.mutateAttributionLines(this.value, pad.alines, pad.apool);
// Looks like this function can take a regular array of strings
libchangeset.mutateTextLines(this.value, /* padcontents */ /*this.lines */ pad.divs);
},
/**
* 'Follow' the Changeset in a given direction, returning the revision at
* the specified end of the edge.
@ -52,33 +53,6 @@ $.Class("Changeset",
}
);
//TODO: cruft! remove?
$.Class("DirectionalIterator",
{//statics
},
{//instance
init: function (list, direction) {
self.list = list;
self.direction = direction;
self.current = self.direction ? self.list.length - 1 : 0;
},
haveNext: function () {
if ((self.direction && self.current > 0) ||
(!self.direction && self.current < self.list.length))
return true;
return false;
},
next: function () {
if (self.direction && self.current > 0)
return self.list[self.current--];
if (!self.direction && self.current < self.list.length)
return self.list[self.current++];
return undefined;
}
}
);
/**
* Revision class. Represents a specific revision. Each instance has three
* possible edges in each direction. Each edge is essentially a Changeset.
@ -360,25 +334,6 @@ $.Class("RevisionCache",
//Something went wrong!
}
},
/**
* Iterate over the list of changesets required to go from one revision to another.
* @param {number} from - The starting revision.
* @param {number} to - The end revision.
* @param {function} callback - The function to apply to each changeset.
*/
iterChangesets: function (from, to, callback) {
// first try to build a path from the cache:
var path = this.findPath(from, to);
if (!path.is_complete) {
// TODO: request load of any other changesets.
// before we start iterating over existing
// in the hope that some of them will be
// fulfilled soon.bt
}
// we have a partial path
console.log(from, to, path.current.revnum);
// TODO: loop over existing changesets and apply
}
}
);
@ -558,7 +513,6 @@ Thread("ChangesetLoader",
}
);
var libchangeset = require("./Changeset");
var AttribPool = require("./AttributePool");
var domline = require("./domline").domline;
var linestylefilter = require("./linestylefilter").linestylefilter;
@ -659,15 +613,14 @@ $.Class("PadClient",
},
}
);
function loadBroadcastRevisionsJS(clientVars, connection)
function init(clientVars, connection)
{
revisionCache = new RevisionCache(connection, clientVars.collab_client_vars.rev || 0);
// revisionInfo.latest = clientVars.collab_client_vars.rev || -1;
var collabClientVars = clientVars.collab_client_vars;
p = new PadClient(collabClientVars.rev, collabClientVars.time, collabClientVars.initialAttributedText.text, collabClientVars.initialAttributedText.attribs, collabClientVars.apool);
}
exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS;
exports.init = init;

View file

@ -1,9 +1,3 @@
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
/**
* Copyright 2009 Google Inc.
*
@ -178,6 +172,7 @@ SocketClient("AuthenticatedSocketClient",
}
);
require('./revisioncache');
AuthenticatedSocketClient("TimesliderClient",
{ //statics
},
@ -197,15 +192,16 @@ AuthenticatedSocketClient("TimesliderClient",
this.clientVars = data;
this.current_revision = this.head_revision = this.clientVars.collab_client_vars.rev;
this.savedRevisions = this.clientVars.savedRevisions;
this.revisionCache = new RevisionCache(this, this.clientVars.collab_client_vars.rev || 0);
var collabClientVars = this.clientVars.collab_client_vars;
this.padClient = new PadClient(collabClientVars.rev, collabClientVars.time, collabClientVars.initialAttributedText.text, collabClientVars.initialAttributedText.attribs, collabClientVars.apool);
},
handle_COLLABROOM: function(data) {
console.log("[timeslider_client] handle_COLLABROOM: ", data);
},
//handle_CHANGESET_REQ: function(data) {
//console.log("[timeslider_client] handle_CHANGESET_REQ: ", data);
//},
}
);
@ -243,10 +239,9 @@ function init(baseURL) {
var timesliderclient = new TimesliderClient(url, padId)
.on("CLIENT_VARS", function(data, context, callback) {
//load all script that doesn't work without the clientVars
BroadcastSlider = require('./broadcast_slider').loadBroadcastSliderJS(this,fireWhenAllScriptsAreLoaded);
cl = require('./revisioncache').loadBroadcastRevisionsJS(this.clientVars, this);
//require('./broadcast_revisions').loadBroadcastRevisionsJS(this.clientVars);
changesetLoader = require('./broadcast').loadBroadcastJS(this, fireWhenAllScriptsAreLoaded, BroadcastSlider);
BroadcastSlider = require('./broadcast_slider').init(this,fireWhenAllScriptsAreLoaded);
//cl = require('./revisioncache').init(this.clientVars, this);
//changesetLoader = require('./broadcast').loadBroadcastJS(this, fireWhenAllScriptsAreLoaded, BroadcastSlider);
//initialize export ui
require('./pad_impexp').padimpexp.init();
@ -266,7 +261,7 @@ function init(baseURL) {
{
fireWhenAllScriptsAreLoaded[i]();
}
$("#ui-slider-handle").css('left', $("#ui-slider-bar").width() - 2);
//$("#ui-slider-handle").css('left', $("#ui-slider-bar").width() - 2);
});
//get all the export links