Commit 48f7d3fb authored by Eugene Shen's avatar Eugene Shen

Fix enough miscellaneous bugs to pass all tests

Split local Text Post storage from the configurator Person storage,
completely rewrite URL matching regexp, handle Handlebars' =,
add field in MappingStorage to keep mapping in the main document,
always set that to true, wrap custom configs in MappingStorages,
use Rusha to generate SHA1 hashes of JSON messages for mapping,
set dav_url as the value of its input and not the placeholder,
rename connect-form to storage-form to avoid style conflicts,
wrap labels and inputs by <label>, prepend "chat-" to stuff,
remove all line breaks from all forms, make email readonly,
prepend https:// instead of http:// to protocol-less URLs,
update join_time on actual join instead of jIO discovery,
use has_joined instead of message_count > 0 for joining,
create all queries as modifications to a general_query,
stop repairing the non-replicate configurator storage,
shift the chat-hidden class instead of style.display,
and leave all the things with XXX to future commits!
parent 97465970
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<script src="handlebars.js"></script> <script src="handlebars.js"></script>
<script src="jio_mappingstorage.js"></script> <script src="jio_mappingstorage.js"></script>
<script src="gadget_erp5_chat_room.js"></script> <script src="gadget_erp5_chat_room.js"></script>
<script class="connect-form-template" type="text/x-handlebars-template"> <script class="storage-form-template" type="text/x-handlebars-template">
<label> <label>
<input type="radio" name="jio_type" value="erp5" required="required" {{#if jio_type_erp5}}checked="checked"{{/if}} /> <input type="radio" name="jio_type" value="erp5" required="required" {{#if jio_type_erp5}}checked="checked"{{/if}} />
ERP5, ERP5,
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</label> </label>
<label> <label>
URL: URL:
<input type="text" name="dav_url" placeholder="{{dav_url}}" /> <input type="text" name="dav_url" value="{{dav_url}}" />
</label> </label>
<label> <label>
WebDAV Username: WebDAV Username:
...@@ -43,30 +43,35 @@ ...@@ -43,30 +43,35 @@
jIO Configuration: jIO Configuration:
<input type="text" name="custom_configuration" value="{{jio_configuration}}" /> <input type="text" name="custom_configuration" value="{{jio_configuration}}" />
</label> </label>
<br /> <input class="chat-submit" type="submit" value="Connect!" />
<input type="submit" value="Connect!" />
</script> </script>
<script class="contact-form-template" type="text/x-handlebars-template"> <script class="contact-form-template" type="text/x-handlebars-template">
<label>E-mail Address:</label> <label>
<input type="text" name="default_email_coordinate_text" E-mail Address:
value="{{default_email_coordinate_text}}" /> <input type="text" name="default_email_coordinate_text"
<label>Last Name:</label> value="{{default_email_coordinate_text}}" readonly />
<input type="text" name="last_name" value="{{last_name}}" /> </label>
<label>First Name:</label> <label>
<input type="text" name="first_name" value="{{first_name}}" /> Last Name:
<label>jIO Configuration:</label> <input type="text" name="last_name" value="{{last_name}}" />
<input type="text" name="jio_configuration" </label>
value="{{jio_configuration}}" /> <label>
<br /> First Name:
<input type="submit" value="Update!" /> <input type="text" name="first_name" value="{{first_name}}" />
</label>
<label>
jIO Configuration:
<input type="text" name="jio_configuration" value="{{jio_configuration}}" />
</label>
<input class="chat-submit" type="submit" value="Update!" />
</script> </script>
</head> </head>
<body> <body>
<h1>Choose Shared Storage</h1> <h1>Choose Shared Storage</h1>
<form class="connect-form"> <form class="chat-storage-form">
</form> </form>
<h1>Edit Contact Details</h1> <h1>Edit Contact Details</h1>
<form class="contact-form"> <form class="chat-contact-form">
</form> </form>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.41620.48534.44868</string> </value> <value> <string>958.51664.2960.4232</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -259,7 +259,7 @@ ...@@ -259,7 +259,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1492008152.73</float> <float>1492679668.09</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
.declareAcquiredMethod("jio_put", "jio_put") .declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_repair", "jio_repair")
/* Render the gadget. /* Render the gadget.
...@@ -33,15 +32,15 @@ ...@@ -33,15 +32,15 @@
var gadget = this; var gadget = this;
return gadget.jio_get(gadget.state.jio_id) return gadget.jio_get(gadget.state.jio_id)
.push(function (result) { .push(function (result) {
var connect_form_template = Handlebars.compile( var storage_form_template = Handlebars.compile(
Object.getPrototypeOf(gadget).constructor.__template_element Object.getPrototypeOf(gadget).constructor.__template_element
.querySelector(".connect-form-template").innerHTML .querySelector(".storage-form-template").innerHTML
), ),
contact_form_template = Handlebars.compile( contact_form_template = Handlebars.compile(
Object.getPrototypeOf(gadget).constructor.__template_element Object.getPrototypeOf(gadget).constructor.__template_element
.querySelector(".contact-form-template").innerHTML .querySelector(".contact-form-template").innerHTML
), ),
connect_form_param_dict = { storage_form_param_dict = {
erp5_url: gadget.state.default_erp5_url, erp5_url: gadget.state.default_erp5_url,
dav_url: gadget.state.default_dav_url, dav_url: gadget.state.default_dav_url,
jio_configuration: result.jio_configuration jio_configuration: result.jio_configuration
...@@ -49,19 +48,19 @@ ...@@ -49,19 +48,19 @@
switch (gadget.state.default_jio_type) { switch (gadget.state.default_jio_type) {
case "erp5": case "erp5":
connect_form_param_dict.jio_type_erp5 = true; storage_form_param_dict.jio_type_erp5 = true;
break; break;
case "dav": case "dav":
connect_form_param_dict.jio_type_dav = true; storage_form_param_dict.jio_type_dav = true;
break; break;
case "custom": case "custom":
connect_form_param_dict.jio_type_custom = true; storage_form_param_dict.jio_type_custom = true;
break; break;
} }
gadget.element.querySelector(".connect-form").innerHTML = gadget.element.querySelector(".chat-storage-form").innerHTML =
connect_form_template(connect_form_param_dict); storage_form_template(storage_form_param_dict);
gadget.element.querySelector(".contact-form").innerHTML = gadget.element.querySelector(".chat-contact-form").innerHTML =
contact_form_template(result); contact_form_template(result);
}); });
}) })
...@@ -82,11 +81,23 @@ ...@@ -82,11 +81,23 @@
remote_sub_storage, remote_sub_storage,
fields = event.target.elements; fields = event.target.elements;
/* The goal of jIO MappingStorage is to ensure that all Text Posts
* have exactly the same IDs in all MappingStorage sub_storages,
* by storing a unique deterministic ID for each Text Post
* in its mapping property. This allows repair to correctly
* synchronize Text Posts across many storages simultaneously.
* If the implementation of MappingStorage changes in the future,
* please carefully consider other options to synchronize
* across many storages simultaneously, since that is the
* only reason MappingStorage is used, before taking action.
*/
switch (fields.jio_type.value) { switch (fields.jio_type.value) {
case "erp5": case "erp5":
remote_sub_storage = { remote_sub_storage = {
type: "mapping", type: "mapping",
id: ["equalSubProperty", "mapping"], id: ["equalSubProperty", "mapping"],
keep_map_id_in_main_document: true,
query: gadget.state.mapping_query, query: gadget.state.mapping_query,
sub_storage: { sub_storage: {
type: "erp5", type: "erp5",
...@@ -110,7 +121,13 @@ ...@@ -110,7 +121,13 @@
}; };
break; break;
case "custom": case "custom":
remote_sub_storage = JSON.parse(fields.custom_configuration.value); remote_sub_storage = {
type: "mapping",
id: ["equalSubProperty", "mapping"],
keep_map_id_in_main_document: true,
query: gadget.state.mapping_query,
sub_storage: JSON.parse(fields.custom_configuration.value)
};
break; break;
} }
...@@ -118,7 +135,7 @@ ...@@ -118,7 +135,7 @@
type: "replicate", type: "replicate",
use_remote_post: true, use_remote_post: true,
conflict_handling: 2, conflict_handling: 2,
query: gadget.state.query, query: gadget.state.sorted_query,
local_sub_storage: gadget.state.local_sub_storage, local_sub_storage: gadget.state.local_sub_storage,
remote_sub_storage: remote_sub_storage remote_sub_storage: remote_sub_storage
}); });
...@@ -147,10 +164,7 @@ ...@@ -147,10 +164,7 @@
jio_document[fields[i].name] = fields[i].value; jio_document[fields[i].name] = fields[i].value;
} }
} }
return gadget.jio_put(gadget.state.jio_id, jio_document) return gadget.jio_put(gadget.state.jio_id, jio_document);
.push(function () {
return gadget.jio_repair();
});
}) })
...@@ -179,10 +193,10 @@ ...@@ -179,10 +193,10 @@
.onEvent("submit", function (event) { .onEvent("submit", function (event) {
var gadget = this; var gadget = this;
if (event.target.className === "connect-form") { if (event.target.className === "chat-storage-form") {
return gadget.createJioReplicate(event); return gadget.createJioReplicate(event);
} }
if (event.target.className === "contact-form") { if (event.target.className === "chat-contact-form") {
return gadget.updateContact(event); return gadget.updateContact(event);
} }
}); });
......
...@@ -237,7 +237,7 @@ ...@@ -237,7 +237,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.44541.58107.9130</string> </value> <value> <string>958.54709.48866.24405</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -255,7 +255,7 @@ ...@@ -255,7 +255,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1492188930.99</float> <float>1492794053.33</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="handlebars.js"></script> <script src="handlebars.js"></script>
<script src="rusha.js"></script>
<script src="gadget_global.js"></script> <script src="gadget_global.js"></script>
<script src="gadget_erp5_page_chat_box.js"></script> <script src="gadget_erp5_page_chat_box.js"></script>
<script class="chat-list-template" type="text/x-handlebars-template"> <script class="chat-list-template" type="text/x-handlebars-template">
...@@ -33,10 +34,10 @@ ...@@ -33,10 +34,10 @@
<div class="chat-form-panel"> <div class="chat-form-panel">
<form class="join-form"> <form class="join-form">
<input type="text" name="content" /> <input type="text" name="content" />
<input type="submit" value="Join room!" /> <input class="chat-submit" type="submit" value="Join room!" />
</form> </form>
<form class="edit-form"> <form class="edit-form">
<input type="submit" value="Edit contact!" /> <input class="chat-submit" type="submit" value="Edit contact!" />
</form> </form>
</div> </div>
</div> </div>
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
</ul> </ul>
<form class="send-form"> <form class="send-form">
<input type="text" name="content" /> <input type="text" name="content" />
<input type="submit" name="send" value="Send!" /> <input class="chat-submit" type="submit" name="send" value="Send!" />
</form> </form>
</div> </div>
</div> </div>
......
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.41714.1894.49698</string> </value> <value> <string>958.54482.29236.23739</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -259,7 +259,7 @@ ...@@ -259,7 +259,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1492008152.15</float> <float>1492783825.69</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -237,7 +237,7 @@ ...@@ -237,7 +237,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.44733.2615.38656</string> </value> <value> <string>958.54814.24278.28364</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -255,7 +255,7 @@ ...@@ -255,7 +255,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1492189329.87</float> <float>1492794457.43</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -191,6 +191,7 @@ ...@@ -191,6 +191,7 @@
this._query = spec.query || {}; this._query = spec.query || {};
this._map_id = spec.id || ["equalSubId"]; this._map_id = spec.id || ["equalSubId"];
this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false; this._id_mapped = (spec.id !== undefined) ? spec.id[1] : false;
this._keep_map_id_in_main_document = spec.keep_map_id_in_main_document;
if (this._query.query !== undefined) { if (this._query.query !== undefined) {
this._query.query = QueryFactory.create(this._query.query); this._query.query = QueryFactory.create(this._query.query);
...@@ -255,7 +256,10 @@ ...@@ -255,7 +256,10 @@
function mapToMainDocument(storage, sub_doc, sub_id) { function mapToMainDocument(storage, sub_doc, sub_id) {
var doc = {}, var doc = {},
property, property,
property_list = [storage._id_mapped]; property_list = [];
if (!storage._keep_map_id_in_main_document) {
property_list.push(storage._id_mapped);
}
for (property in storage._mapping_dict) { for (property in storage._mapping_dict) {
if (storage._mapping_dict.hasOwnProperty(property)) { if (storage._mapping_dict.hasOwnProperty(property)) {
property_list.push(mapToMainProperty( property_list.push(mapToMainProperty(
......
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1492185269.35</float> <float>1492787013.94</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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