Commit 0d9586e0 authored by Eugene Shen's avatar Eugene Shen

Correctly reload and rewrite entire chat

parent edcd20f8
......@@ -79,7 +79,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>fast_priority_queue.js</string> </value>
<value> <string>erp5_page_launcher.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -89,13 +89,11 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>fast_priority_queue_js</string> </value>
<value> <string>erp5_page_launcher_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......@@ -109,13 +107,11 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Fast Priority Queue JS</string> </value>
<value> <string>OfficeJS Launcher JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
......
/**
* FastPriorityQueue.js : a fast heap-based priority queue in JavaScript.
* (c) the authors
* Licensed under the Apache License, Version 2.0.
*
* Speed-optimized heap-based priority queue for modern browsers and JavaScript engines.
*
* Usage :
Installation (in shell, if you use node):
$ npm install fastpriorityqueue
Running test program (in JavaScript):
// var FastPriorityQueue = require("fastpriorityqueue");// in node
var x = new FastPriorityQueue();
x.add(1);
x.add(0);
x.add(5);
x.add(4);
x.add(3);
x.peek(); // should return 0, leaves x unchanged
x.size; // should return 5, leaves x unchanged
while(!x.isEmpty()) {
console.log(x.poll());
} // will print 0 1 3 4 5
x.trim(); // (optional) optimizes memory usage
*/
"use strict";
var defaultcomparator = function (a, b) {
return a < b;
};
// the provided comparator function should take a, b and return *true* when a < b
function FastPriorityQueue(comparator) {
this.array = [];
this.size = 0;
this.compare = comparator || defaultcomparator;
}
// Add an element the the queue
// runs in O(log n) time
FastPriorityQueue.prototype.add = function (myval) {
var i = this.size;
this.array[this.size] = myval;
this.size += 1;
var p;
var ap;
while (i > 0) {
p = (i - 1) >> 1;
ap = this.array[p];
if (!this.compare(myval, ap)) {
break;
}
this.array[i] = ap;
i = p;
}
this.array[i] = myval;
};
// replace the content of the heap by provided array and "heapifies it"
FastPriorityQueue.prototype.heapify = function (arr) {
this.array = arr;
this.size = arr.length;
var i;
for (i = (this.size >> 1); i >= 0; i--) {
this._percolateDown(i);
}
};
// for internal use
FastPriorityQueue.prototype._percolateUp = function (i) {
var myval = this.array[i];
var p;
var ap;
while (i > 0) {
p = (i - 1) >> 1;
ap = this.array[p];
if (!this.compare(myval, ap)) {
break;
}
this.array[i] = ap;
i = p;
}
this.array[i] = myval;
};
// for internal use
FastPriorityQueue.prototype._percolateDown = function (i) {
var size = this.size;
var hsize = this.size >>> 1;
var ai = this.array[i];
var l;
var r;
var bestc;
while (i < hsize) {
l = (i << 1) + 1;
r = l + 1;
bestc = this.array[l];
if (r < size) {
if (this.compare(this.array[r], bestc)) {
l = r;
bestc = this.array[r];
}
}
if (!this.compare(bestc, ai)) {
break;
}
this.array[i] = bestc;
i = l;
}
this.array[i] = ai;
};
// Look at the top of the queue (a smallest element)
// executes in constant time
//
// This function assumes that the priority queue is
// not empty and the caller is resposible for the check.
// You can use an expression such as
// "isEmpty() ? undefined : peek()"
// if you expect to be calling peek on an empty priority queue.
//
FastPriorityQueue.prototype.peek = function () {
return this.array[0];
};
// remove the element on top of the heap (a smallest element)
// runs in logarithmic time
//
//
// This function assumes that the priority queue is
// not empty, and the caller is responsible for the check.
// You can use an expression such as
// "isEmpty() ? undefined : poll()"
// if you expect to be calling poll on an empty priority queue.
//
// For long-running and large priority queues, or priority queues
// storing large objects, you may want to call the trim function
// at strategic times to recover allocated memory.
FastPriorityQueue.prototype.poll = function () {
var ans = this.array[0];
if (this.size > 1) {
this.array[0] = this.array[--this.size];
this._percolateDown(0 | 0);
} else {
this.size -= 1;
}
return ans;
};
// recover unused memory (for long-running priority queues)
FastPriorityQueue.prototype.trim = function () {
this.array = this.array.slice(0, this.size);
};
// Check whether the heap is empty
FastPriorityQueue.prototype.isEmpty = function () {
return this.size === 0;
};
// just for illustration purposes
var main = function () {
// main code
var x = new FastPriorityQueue(function (a, b) {
return a < b;
});
x.add(1);
x.add(0);
x.add(5);
x.add(4);
x.add(3);
while (!x.isEmpty()) {
console.log(x.poll());
}
};
\ No newline at end of file
......@@ -7,8 +7,7 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jiodev.js"></script>
<script src="gadget_global.js" ></script>
<script src="fast_priority_queue.js"></script>
<script src="gadget_global.js"></script>
<script src="gadget_erp5_page_chat_box.js"></script>
</head>
<body>
......@@ -26,11 +25,7 @@
</form>
<form class="join-form">
<input type="text" name="content" />
<input type="submit" value="Add new contact (join existing room as guest)!" />
</form>
<form class="make-form">
<input type="text" name="content" />
<input type="submit" value="Add new room (make new room as host)!" />
<input type="submit" value="Join room!" />
</form>
</div>
</div>
......
......@@ -12,15 +12,15 @@
<form class="connect-form">
<label>E-mail Address:</label>
<input type="email" name="user_email" required="required" />
<label>Default WebRTC Authentication Method:</label>
<label>Default Shared Storage Type:</label>
<br />
<input type="radio" name="default_webrtc_storage" value="erp5">ERP5</input>
<input type="radio" name="default_webrtc_storage" value="dropbox">Dropbox</input>
<input type="radio" name="default_jio_type" value="erp5">ERP5</input>
<input type="radio" name="default_jio_type" value="dav">WebDAV</input>
<br />
<label>Default Dropbox Folder:</label>
<input type="text" name="default_dropbox_folder" placeholder="/Apps/OfficeJS Chat/" />
<label>Default ERP5 URL:</label>
<input type="text" name="default_erp5_url", placeholder="https://softinst75770.host.vifib.net/erp5/webrtc_rooms_module/" />
<input type="text" name="default_erp5_url", placeholder="https://softinst75770.host.vifib.net/erp5/web_site_module/hateoas" />
<label>Default WebDAV URL:</label>
<input type="text" name="default_dav_url", placeholder="https://softinst75722.host.vifib.net/share" />
<input type="submit" />
</form>
</body>
......
/* global window, RSVP, rJS */
/* jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global window, RSVP, rJS */
(function (window, RSVP, rJS) {
'use strict';
"use strict";
/* Settings modified:
* - user_email
* - default_webrtc_storage
* - default_dropbox_folder
* - default_jio_type
* - default_erp5_url
* - default_dav_url
*/
/* Store the given connection settings
/* Store the given connection settings.
* Parameters: all from the connect form,
* - user_email: an email, which acts as a username, example: eugene@abc.xyz
* - default_webrtc_storage: the type of storage to select by default
* for sharing WebRTC negotiations, example: dropbox
* - default_dropbox_folder: the Dropbox folder to select by default
* for sharing WebRTC negotiations, example: /Apps/OfficeJS Chat/
* - default_erp5_url: the ERP5 URL to select by default for sharing,
* example: https://softinst75770.host.vifib.net/erp5/web_site_module/
* - default_jio_type: the type of storage to select by default
* for sharing chat messages, example: erp5
* - default_erp5_url: the ERP5 URL to select by default, example:
* https://softinst75770.host.vifib.net/erp5/web_site_module/hateoas
* - default_dav_url: the WebDAV URL to select by default for sharing,
* example: https://softinst75722.host.vifib.net/share
* Effects:
* - set setting: user_email, default_webrtc_storage,
* default_dropbox_folder, default_erp5_url
* - setSetting: user_email, default_jio_type,
* default_erp5_url, default_dav_url
* - redirect to the front page
*/
function setConnectConfiguration(gadget, event) {
const fields = ['user_email', 'default_webrtc_storage',
'default_dropbox_folder', 'default_erp5_url'];
return new RSVP.Queue()
.push(function () {
const queue = new RSVP.Queue();
for (let i = 0, i_len = fields.length; i < i_len; i++) {
const field = fields[i];
if (event.target.hasOwnProperty(field) && event.target[field].value) {
queue.push(function () {
return gadget.setSetting(field, event.target[field].value);
});
}
}
return queue;
})
var i, field, queue = new RSVP.Queue(),
fields = ["user_email", "default_jio_type",
"default_erp5_url", "default_dav_url"],
callSetting = function (setting) {
return function () {
return gadget.setSetting(setting, event.target[setting].value);
};
};
// must call setSetting synchronously; RSVP.all causes race conditions
for (i = 0; i < fields.length; i += 1) {
field = fields[i];
if (event.target.hasOwnProperty(field) && event.target[field].value) {
queue.push(callSetting(field));
}
}
return queue
.push(function () {
return gadget.redirect();
});
}
rJS(window)
// Neither state to set nor ready to initialize
// The following functions are all acquired from erp5_launcher_nojqm.js
.declareAcquiredMethod('updateHeader', 'updateHeader')
.declareAcquiredMethod('redirect', 'redirect')
.declareAcquiredMethod('setSetting', 'setSetting')
/* Render the gadget
// Neither state to set nor ready to initialize.
// The following functions are all acquired from erp5_page_launcher.
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("setSetting", "setSetting")
/* Render the gadget.
* Parameters: nothing
* Effects:
* - update header, page_title to 'Connect to Chat'
* Effects: update header, page_title to "Connect to Chat"
*/
.declareMethod('render', function () {
.declareMethod("render", function () {
var gadget = this;
return gadget.updateHeader({
page_title: 'Connect to Chat',
page_title: "Connect to Chat",
submit_action: true
});
})
/* Manually click submit button when the right button is clicked,
* so that HTML5 form validation is automatically used
* so that HTML5 form validation is automatically used.
*/
.declareMethod('triggerSubmit', function (event) {
this.element.querySelector('input[type="submit"]').click();
.declareMethod("triggerSubmit", function () {
this.element.querySelector("input[type='submit']").click();
})
// Call setConnectionConfiguration when either proceed button is clicked
.onEvent('submit', function (event) {
const gadget = this;
// Call setConnectionConfiguration when either proceed button is clicked.
.onEvent("submit", function (event) {
var gadget = this;
return setConnectConfiguration(gadget, event);
});
......
......@@ -74,13 +74,13 @@
},
},
};
return RSVP.all([
gadget.setSetting('jio_storage_description', configuration),
gadget.setSetting('redirect_after_reload', {
command: 'display',
options: {page: 'sync'},
})
]);
return gadget.setSetting('jio_storage_description', configuration);
})
.push(function () {
return gadget.setSetting('redirect_after_reload', {
command: 'display',
options: {page: 'sync'},
});
})
.push(function () {
return gadget.reload();
......
/* global window, RSVP, rJS, URI */
/* global window, RSVP, rJS */
/* jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
(function (window, RSVP, rJS, URI) {
(function (window, RSVP, rJS) {
'use strict';
/* Settings required:
......@@ -65,18 +65,17 @@
},
remote_sub_storage: {
type: 'erp5',
erp5_url: erp5_url,
url: (new URI('hateoas')).absoluteTo(erp5_url).toString(),
url: erp5_url,
default_view_reference: 'jio_view',
},
};
return RSVP.all([
gadget.setSetting('jio_storage_description', configuration),
gadget.setSetting('redirect_after_reload', {
command: 'display',
options: {page: 'sync'},
})
]);
return gadget.setSetting('jio_storage_description', configuration);
})
.push(function () {
return gadget.setSetting('redirect_after_reload', {
command: 'display',
options: {page: 'sync'},
});
})
.push(function () {
return gadget.reload();
......@@ -131,7 +130,7 @@
})
.push(function (configuration) {
gadget.element.querySelector('input[name="erp5_url"]')
.value = configuration.remote_sub_storage.erp5_url;
.value = configuration.remote_sub_storage.url;
return;
});
} else {
......@@ -150,4 +149,4 @@
return setErp5Configuration(gadget, event);
});
}(window, RSVP, rJS, URI));
\ No newline at end of file
}(window, RSVP, rJS));
\ No newline at end of file
web_page_module/adapter_js
web_page_module/erp5_page_launcher*
web_page_module/fast_priority_queue_js
web_page_module/gadget_erp5_chat_panel_*
web_page_module/gadget_erp5_chat_webrtc_*
web_page_module/gadget_erp5_nojquery_css
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment