Commit d1d4e280 authored by Sven Franck's avatar Sven Franck

added storage option skip_total_query, to not run allDocs for total records

parent eafbb794
{
"generate":"gadget",
"type": "setStorage",
"property_dict": {
"force_field_definitions": true,
"skip_total_records": true,
"storage_type": "JIO",
"modernizr": ["blobconstructor", "filereader"]
},
"children": [{
"generate": "gadget",
"type": "makeStorage",
"property_dict": {
"definition": {
"type": "local",
"username": "slapos",
"application_name": "settings"
}
}
}, {
"generate": "gadget",
"type": "makeStorage",
"property_dict": {
"definition": {
"type":"local",
"username":"slapos",
"application_name": "items"
}
}
}]
}
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"type": "setStorage", "type": "setStorage",
"property_dict": { "property_dict": {
"force_field_definitions": true, "force_field_definitions": true,
"skip_total_records": true,
"storage_type": "JIO", "storage_type": "JIO",
"modernizr": ["blobconstructor", "filereader"] "modernizr": ["blobconstructor", "filereader"]
}, },
......
...@@ -1162,24 +1162,31 @@ ...@@ -1162,24 +1162,31 @@
* @param {object} content_dict JSON configuration for storage * @param {object} content_dict JSON configuration for storage
**/ **/
"setStorage": function (content_dict) { "setStorage": function (content_dict) {
var i, supported, promises = []; var i, supported, props, promises = [];
props = content_dict.property_dict;
// setup JIO or alternative storage system here! // setup JIO or alternative storage system here!
switch (content_dict.property_dict.storage_type) { switch (props.storage_type) {
case "JIO": case "JIO":
// test supported // test supported
if (content_dict.property_dict.modernizr) { if (props.modernizr) {
supported = util.testBrowserSupport( supported = util.testBrowserSupport(
content_dict.property_dict.modernizr props.modernizr
); );
} }
// set force_field_definitions over include_docs // set force_field_definitions over include_docs
if (content_dict.property_dict.force_field_definitions) { if (props.force_field_definitions) {
storage.force_fields = true; storage.force_fields = true;
} }
if (supported || content_dict.property_dict.modernizr === undefined) { // skip total_queries
if (props.skip_total_records) {
storage.skip_total = true;
}
if (supported || props.modernizr === undefined) {
// loop children = storages // loop children = storages
for (i = 0; i < content_dict.children.length; i += 1) { for (i = 0; i < content_dict.children.length; i += 1) {
promises[i] = app.setContent(content_dict.children[i]); promises[i] = app.setContent(content_dict.children[i]);
...@@ -1670,7 +1677,7 @@ ...@@ -1670,7 +1677,7 @@
* @return {object} finished config object * @return {object} finished config object
**/ **/
factory.util.paginationBar = function (spec) { factory.util.paginationBar = function (spec) {
var n, option, props, option_list, class_list; var n, option, props, option_list, class_list, config;
option_list = [{"value": "", "text": "", "text_i18n": ""}]; option_list = [{"value": "", "text": "", "text_i18n": ""}];
props = spec.slot ? {"slot": spec.slot} : {}; props = spec.slot ? {"slot": spec.slot} : {};
...@@ -1681,7 +1688,7 @@ ...@@ -1681,7 +1688,7 @@
option_list.push({"value": option.value, "text": option.text, "text_i18n": option.text_i18n}); option_list.push({"value": option.value, "text": option.text, "text_i18n": option.text_i18n});
} }
return { config = {
"generate": "widget", "generate": "widget",
"type": "controlbar", "type": "controlbar",
"class_list": class_list, "class_list": class_list,
...@@ -1729,7 +1736,12 @@ ...@@ -1729,7 +1736,12 @@
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"Next"} "logic": {"text":"Next"}
}, { }]
}]
};
if (storage.skip_total === undefined) {
config.children.push({
"type": "a", "type": "a",
"direct":{"className":"action", "href":"#"}, "direct":{"className":"action", "href":"#"},
"attributes":{ "attributes":{
...@@ -1739,9 +1751,10 @@ ...@@ -1739,9 +1751,10 @@
"data-iconpos": "notext" "data-iconpos": "notext"
}, },
"logic": {"text":"Last"} "logic": {"text":"Last"}
}] });
}] }
};
return config;
}; };
/** /**
...@@ -4785,7 +4798,9 @@ ...@@ -4785,7 +4798,9 @@
* @param {string} value New limit when changing number of records * @param {string} value New limit when changing number of records
*/ */
app.paginate = function (config, type, value) { app.paginate = function (config, type, value) {
var start, records; var start, records, total;
total = config.state.total;
if (config.gadget) { if (config.gadget) {
if (config.state) { if (config.state) {
...@@ -4803,7 +4818,7 @@ ...@@ -4803,7 +4818,7 @@
records = config.state.query.limit[1]; records = config.state.query.limit[1];
break; break;
case "last": case "last":
start = config.state.total - config.state.query.limit[1]; start = total - config.state.query.limit[1];
records = config.state.query.limit[1]; records = config.state.query.limit[1];
break; break;
case "limit": case "limit":
...@@ -4812,7 +4827,7 @@ ...@@ -4812,7 +4827,7 @@
break; break;
} }
if (start > config.state.total || start < 0) { if ((start > total && total !== undefined) || start < 0) {
return; return;
} }
...@@ -5081,10 +5096,12 @@ ...@@ -5081,10 +5096,12 @@
app.updateInfoElement = function (element, options, total, selected) { app.updateInfoElement = function (element, options, total, selected) {
var i, j, l, selection, info_field, min, pointer, no_items, var i, j, l, selection, info_field, min, pointer, no_items,
text_snippet, i18n_snippet, zero_no_show, select_counter, no_limit, text_snippet, i18n_snippet, zero_no_show, select_counter, no_limit,
slot, first, last, info, info_field_list, generateInfo; slot, first, last, info, info_field_list, generateInfo, no_total,
use_total, total_records;
info_field_list = element.querySelectorAll(".info"); info_field_list = element.querySelectorAll(".info");
info = ""; info = "";
no_total = total === undefined && storage.skip_total;
generateInfo = function (text, text_i18n) { generateInfo = function (text, text_i18n) {
return factory.element( return factory.element(
"span", "span",
...@@ -5094,6 +5111,13 @@ ...@@ -5094,6 +5111,13 @@
); );
}; };
// we are working without total query
if (no_total) {
use_total = 0;
} else {
use_total = total;
}
// on updates, info_field_list may be empty, because only part of the // on updates, info_field_list may be empty, because only part of the
// gadget is updated. Need to find info_fields by hand // gadget is updated. Need to find info_fields by hand
if (info_field_list.length === 0) { if (info_field_list.length === 0) {
...@@ -5114,15 +5138,21 @@ ...@@ -5114,15 +5138,21 @@
switch (info_field.getAttribute("data-info")) { switch (info_field.getAttribute("data-info")) {
case "records": case "records":
if (total !== undefined) { if (use_total !== undefined) {
no_limit = options.limit[0] || 0; no_limit = options.limit[0] || 0;
no_items = options.limit[1] || 0; no_items = options.limit[1] || 0;
zero_no_show = (no_limit === 0 && total !== 0) ? 1 : no_limit; zero_no_show = (no_limit === 0 && use_total !== 0) ? 1 : no_limit;
if (no_total) {
min = ((no_limit + no_items === 0) ? use_total : no_limit + no_items);
total_records = "";
} else {
min = Math.min( min = Math.min(
total, use_total,
((no_limit + no_items === 0) ? total : no_limit + no_items) ((no_limit + no_items === 0) ? use_total : no_limit + no_items)
); );
info = zero_no_show + "-" + min + "/" + total; total_records = "/" + use_total;
}
info = zero_no_show + "-" + min + total_records;
text_snippet = " Records"; text_snippet = " Records";
i18n_snippet = "records"; i18n_snippet = "records";
slot = 0; slot = 0;
...@@ -5145,8 +5175,8 @@ ...@@ -5145,8 +5175,8 @@
case "selected": case "selected":
select_counter = 0; select_counter = 0;
if (selected) { if (selected) {
if (selected[0] === "all") { if (selected[0] === "all" && no_total === undefined) {
select_counter = total; select_counter = use_total;
} else { } else {
select_counter = selected.length; select_counter = selected.length;
} }
...@@ -6212,10 +6242,23 @@ ...@@ -6212,10 +6242,23 @@
* @return {object} promise object/pass * @return {object} promise object/pass
*/ */
app.fetchData = function (parcel) { app.fetchData = function (parcel) {
var method, convert, select_list, hacked_view; var method, convert, select_list, hacked_view, pass, skip, query;
pass = parcel.pass;
query = parcel.query;
skip = query && query.limit.length === 0 && storage.skip_total;
// return here, if skipping total query
if (skip) {
return {
"pass": parcel.pass
};
}
select_list = parcel.query && parcel.query.select_list && parcel.query.select_list.length; select_list = parcel.query && parcel.query.select_list && parcel.query.select_list.length;
// single item query GET
if (parcel.query._id) { if (parcel.query._id) {
// TODO: don't set if don't need... // TODO: don't set if don't need...
delete parcel.query.limit; delete parcel.query.limit;
...@@ -6224,6 +6267,7 @@ ...@@ -6224,6 +6267,7 @@
convert = "single_item"; convert = "single_item";
} }
// query that will return value {} object vs. doc
if (select_list && parcel.query.include_docs === undefined) { if (select_list && parcel.query.include_docs === undefined) {
convert = "values"; convert = "values";
} }
...@@ -6565,7 +6609,6 @@ ...@@ -6565,7 +6609,6 @@
//customValidations: util.declareJS(), //customValidations: util.declareJS(),
form: { form: {
onInvalid: function (error) { onInvalid: function (error) {
console.log(error);
util.return_out(); util.return_out();
} }
} }
......
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