Commit d89dbc08 authored by preetwinder's avatar preetwinder Committed by preetwinder

[erp5_officejs] Add wrapper storage to cache allDocs call and then service get requests.

parent 2f622c5f
/*jslint nomen: true */
/*global RSVP, UriTemplate*/
(function (jIO, RSVP) {
"use strict";
var posts;
function resultToDict(result) {
var i, resultDict = {};
for (i = 0; i < result.length; i++) {
resultDict[result[i].id] = result[i].value;
}
return resultDict;
}
function WrapperStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._default_field_list = spec.default_field_list;
}
WrapperStorage.prototype.get = function (id) {
var that = this;
if (posts) {
return posts[id];
}
return this._sub_storage.get(id);
};
WrapperStorage.prototype.buildQuery = function (query) {
var that = this;
query.select_list = that._default_field_list;
return this._sub_storage.buildQuery(query)
.push(function(result) {
posts = resultToDict(result);
return result;
});
};
WrapperStorage.prototype.hasCapacity = function (name) {
var this_storage_capacity_list = ["list", "select", "include", "limit"];
if (this_storage_capacity_list.indexOf(name) !== -1) {
return true;
}
};
jIO.addStorage('wrapper', WrapperStorage);
}(jIO, RSVP));
\ No newline at end of file
...@@ -44,10 +44,14 @@ ...@@ -44,10 +44,14 @@
remote_sub_storage: { remote_sub_storage: {
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "facebook", type: "wrapper",
access_token: access_token, default_field_list: ['id', 'message', 'created_time', 'link', 'story'],
user_id: user_id, sub_storage: {
default_field_list: ['id', 'message', 'created_time', 'link', 'story'] type: "facebook",
access_token: access_token,
user_id: user_id,
default_field_list: ['id', 'message', 'created_time', 'link', 'story']
}
} }
} }
} }
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.20848.25415.9847</string> </value> <value> <string>961.26541.35617.5188</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1502381591.58</float> <float>1502876105.87</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -197,8 +197,13 @@ gadget_erp5_page_ojs_fb_posts_document_list.js\n ...@@ -197,8 +197,13 @@ gadget_erp5_page_ojs_fb_posts_document_list.js\n
gadget_erp5_page_ojs_fb_posts_panel.html\n gadget_erp5_page_ojs_fb_posts_panel.html\n
gadget_erp5_page_ojs_fb_posts_panel.js\n gadget_erp5_page_ojs_fb_posts_panel.js\n
jio_fbstorage.js\n jio_fbstorage.js\n
jio_wrapperstorage.js\n
gadget_erp5_page_ojs_fb_posts_jio.html\n gadget_erp5_page_ojs_fb_posts_jio.html\n
gadget_ojs_fb_posts_jio.js\n gadget_ojs_fb_posts_jio.js\n
gadget_erp5_sort_editor.html\n
gadget_erp5_sort_editor.js\n
gadget_erp5_search_editor.js\n
gadget_erp5_search_editor.html\n
GADGET:\n GADGET:\n
NETWORK:\n NETWORK:\n
*</string> </value> *</string> </value>
...@@ -342,7 +347,7 @@ NETWORK:\n ...@@ -342,7 +347,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.20841.15763.31249</string> </value> <value> <string>961.26541.35617.5188</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -360,7 +365,7 @@ NETWORK:\n ...@@ -360,7 +365,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1502440236.9</float> <float>1502876355.62</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<script src="jio_mappingstorage.js" type="text/javascript"></script> <script src="jio_mappingstorage.js" type="text/javascript"></script>
<script src="jio_fixstorage.js" type="text/javascript"></script> <script src="jio_fixstorage.js" type="text/javascript"></script>
<script src="jio_fbstorage.js" type="text/javascript"></script> <script src="jio_fbstorage.js" type="text/javascript"></script>
<script src="jio_wrapperstorage.js" type="text/javascript"></script>
<!-- custom script --> <!-- custom script -->
......
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>961.16340.21976.59340</string> </value> <value> <string>961.29117.52664.59050</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1502286442.68</float> <float>1502876063.05</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