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 @@
"type": "setStorage",
"property_dict": {
"force_field_definitions": true,
"skip_total_records": true,
"storage_type": "JIO",
"modernizr": ["blobconstructor", "filereader"]
},
......
......@@ -1162,24 +1162,31 @@
* @param {object} content_dict JSON configuration for storage
**/
"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!
switch (content_dict.property_dict.storage_type) {
switch (props.storage_type) {
case "JIO":
// test supported
if (content_dict.property_dict.modernizr) {
if (props.modernizr) {
supported = util.testBrowserSupport(
content_dict.property_dict.modernizr
props.modernizr
);
}
// set force_field_definitions over include_docs
if (content_dict.property_dict.force_field_definitions) {
if (props.force_field_definitions) {
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
for (i = 0; i < content_dict.children.length; i += 1) {
promises[i] = app.setContent(content_dict.children[i]);
......@@ -1670,7 +1677,7 @@
* @return {object} finished config object
**/
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": ""}];
props = spec.slot ? {"slot": spec.slot} : {};
......@@ -1681,7 +1688,7 @@
option_list.push({"value": option.value, "text": option.text, "text_i18n": option.text_i18n});
}
return {
config = {
"generate": "widget",
"type": "controlbar",
"class_list": class_list,
......@@ -1729,19 +1736,25 @@
"data-iconpos": "notext"
},
"logic": {"text":"Next"}
}, {
"type": "a",
"direct":{"className":"action", "href":"#"},
"attributes":{
"data-i18n": "global_dict.last",
"data-action": "last",
"data-icon": "step-forward",
"data-iconpos": "notext"
},
"logic": {"text":"Last"}
}]
}]
};
if (storage.skip_total === undefined) {
config.children.push({
"type": "a",
"direct":{"className":"action", "href":"#"},
"attributes":{
"data-i18n": "global_dict.last",
"data-action": "last",
"data-icon": "step-forward",
"data-iconpos": "notext"
},
"logic": {"text":"Last"}
});
}
return config;
};
/**
......@@ -4785,7 +4798,9 @@
* @param {string} value New limit when changing number of records
*/
app.paginate = function (config, type, value) {
var start, records;
var start, records, total;
total = config.state.total;
if (config.gadget) {
if (config.state) {
......@@ -4803,7 +4818,7 @@
records = config.state.query.limit[1];
break;
case "last":
start = config.state.total - config.state.query.limit[1];
start = total - config.state.query.limit[1];
records = config.state.query.limit[1];
break;
case "limit":
......@@ -4812,7 +4827,7 @@
break;
}
if (start > config.state.total || start < 0) {
if ((start > total && total !== undefined) || start < 0) {
return;
}
......@@ -5081,10 +5096,12 @@
app.updateInfoElement = function (element, options, total, selected) {
var i, j, l, selection, info_field, min, pointer, no_items,
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 = "";
no_total = total === undefined && storage.skip_total;
generateInfo = function (text, text_i18n) {
return factory.element(
"span",
......@@ -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
// gadget is updated. Need to find info_fields by hand
if (info_field_list.length === 0) {
......@@ -5114,15 +5138,21 @@
switch (info_field.getAttribute("data-info")) {
case "records":
if (total !== undefined) {
if (use_total !== undefined) {
no_limit = options.limit[0] || 0;
no_items = options.limit[1] || 0;
zero_no_show = (no_limit === 0 && total !== 0) ? 1 : no_limit;
min = Math.min(
total,
((no_limit + no_items === 0) ? total : no_limit + no_items)
);
info = zero_no_show + "-" + min + "/" + total;
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(
use_total,
((no_limit + no_items === 0) ? use_total : no_limit + no_items)
);
total_records = "/" + use_total;
}
info = zero_no_show + "-" + min + total_records;
text_snippet = " Records";
i18n_snippet = "records";
slot = 0;
......@@ -5145,8 +5175,8 @@
case "selected":
select_counter = 0;
if (selected) {
if (selected[0] === "all") {
select_counter = total;
if (selected[0] === "all" && no_total === undefined) {
select_counter = use_total;
} else {
select_counter = selected.length;
}
......@@ -6212,10 +6242,23 @@
* @return {object} promise object/pass
*/
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;
// single item query GET
if (parcel.query._id) {
// TODO: don't set if don't need...
delete parcel.query.limit;
......@@ -6224,6 +6267,7 @@
convert = "single_item";
}
// query that will return value {} object vs. doc
if (select_list && parcel.query.include_docs === undefined) {
convert = "values";
}
......@@ -6565,7 +6609,6 @@
//customValidations: util.declareJS(),
form: {
onInvalid: function (error) {
console.log(error);
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