Commit 18831a65 authored by Sven Franck's avatar Sven Franck

added option force_field_definition on storage, use select_list vs include_docs if set

parent 4b57ee55
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"generate":"gadget", "generate":"gadget",
"type": "setStorage", "type": "setStorage",
"property_dict": { "property_dict": {
"force_field_definitions": true,
"no_content": true, "no_content": true,
"storage_type": "JIO", "storage_type": "JIO",
"modernizr": ["blobconstructor", "filereader"] "modernizr": ["blobconstructor", "filereader"]
......
...@@ -1182,7 +1182,13 @@ ...@@ -1182,7 +1182,13 @@
content_dict.property_dict.modernizr content_dict.property_dict.modernizr
); );
} }
if (supported) {
// set force_field_definitions over include_docs
if (content_dict.property_dict.force_field_definitions) {
storage.force_fields = true;
}
if (supported || content_dict.property_dict.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]);
...@@ -3949,6 +3955,23 @@ ...@@ -3949,6 +3955,23 @@
// generate storage object // generate storage object
storage = {}; storage = {};
/**
* Generate an array of fields from a dict
* @method makeSelectList
* @param {object} field_dict Dictionary of fields
* @return {array} select_list
**/
storage.makeSelectList = function (field_dict) {
var field, select_list = [];
for (field in field_dict) {
if (field_dict.hasOwnProperty(field)) {
select_list.push(field);
}
}
return select_list;
};
/** /**
* Convert storage responses into allDocs response format which * Convert storage responses into allDocs response format which
* is used in subsequent methods * is used in subsequent methods
...@@ -3958,29 +3981,32 @@ ...@@ -3958,29 +3981,32 @@
* @return {object} "allDocs" response object * @return {object} "allDocs" response object
**/ **/
storage.mapResponse = function (response, convert) { storage.mapResponse = function (response, convert) {
var answer, i, record, key, data; var answer, i, record, key, data, pushit;
answer = {"data": {"total_rows": null, "rows": []}}; answer = {"data": {"total_rows": null, "rows": []}};
pushit = function (obj, record_id) {
return {
"id": record_id,
"key": record_id,
"value": {},
"doc": obj
}
};
if (convert === "single_item") { if (convert === "single_item") {
answer.data.total_rows = 1; answer.data.total_rows = 1;
answer.data.rows.push({ answer.data.rows.push(pushit(response.data, response.id));
"id": response.id,
"key": response.id,
"values": {},
"doc": response.data
});
} else { } else {
data = {};
answer.data.total_rows = response.data.total_rows; answer.data.total_rows = response.data.total_rows;
for (i = 0; i < response.data.total_rows; i += 1) { for (i = 0; i < response.data.total_rows; i += 1) {
record = response.data.rows[i].values; data = {};
record = response.data.rows[i].value;
for (key in record) { for (key in record) {
if (record.hasOwnProperty(key)) { if (record.hasOwnProperty(key)) {
data[key] = record[key]; data[key] = record[key];
} }
} }
answer.data.rows.push(data); answer.data.rows.push(pushit(data));
} }
} }
return answer; return answer;
...@@ -4208,7 +4234,6 @@ ...@@ -4208,7 +4234,6 @@
/** /**
* @object {object} Object containing default names, which can be overridden * @object {object} Object containing default names, which can be overridden
**/ **/
// TODO: remove!?
app.default_dict = { app.default_dict = {
"storage_dict": { "storage_dict": {
"settings": "settings", "settings": "settings",
...@@ -4285,7 +4310,7 @@ ...@@ -4285,7 +4310,7 @@
* @param {string} provider Provider through which register should run * @param {string} provider Provider through which register should run
**/ **/
app.register = function (provider) { app.register = function (provider) {
var token, query, user; var token, query, user, field_dict, field;
// fetch profile // fetch profile
return hello(provider).api("/me") return hello(provider).api("/me")
...@@ -4299,33 +4324,49 @@ ...@@ -4299,33 +4324,49 @@
token, token,
profile.id profile.id
); );
// check to find in storage
return app.fetchData({ // need field values for allDocs select_list...
"storage": "items", return app.fetchConfiguration({
"query": query, "storage": app.default_dict.storage_dict.settings,
"pass": {"profile": profile} "file": app.default_dict.storage_dict.data_type,
"attachment": "person_fieldlist",
"pass": {"query": query, "profile": profile}
}) })
// returns pass and user? .then(function(answer) {
.then(function (reply) {
if (reply.response) { if (answer.response) {
if (reply.response.result === "success" && answer.query.select_list = storage.makeSelectList(
reply.response.data.total_rows === 0) { util.parse(answer.response)
);
// TODO: shitty mapping, make generic
user = {
"person_gender": reply.pass.profile.gender,
"person_first_name": reply.pass.profile.first_name,
"person_last_name": reply.pass.profile.last_name,
"person_default_email_text": reply.pass.profile.email
};
user[token] = reply.pass.profile.id;
return app.store({
"response": [user],
"pass": {"type": "Person"}
});
}
util.error("Register: need account sync!");
} }
return app.fetchData({
"storage": "items",
"query": answer.query,
"pass": {"profile": answer.profile}
})
.then(function (reply) {
if (reply.response) {
if (reply.response.result === "success" &&
reply.response.data.total_rows === 0) {
// TODO: shitty mapping, make generic
user = {
"person_gender": reply.pass.profile.gender,
"person_first_name": reply.pass.profile.first_name,
"person_last_name": reply.pass.profile.last_name,
"person_default_email_text": reply.pass.profile.email
};
user[token] = reply.pass.profile.id;
return app.store({
"response": [user],
"pass": {"type": "Person"}
});
}
util.error("Register: need account sync!");
}
})
.fail(util.error);
}) })
.fail(util.error); .fail(util.error);
}) })
...@@ -4952,7 +4993,7 @@ ...@@ -4952,7 +4993,7 @@
is_value = value && value !== ""; is_value = value && value !== "";
// "id" = "bar" => THIS SHOULD BE A GET! // "id" = "bar" => THIS SHOULD BE GET!
if (is_value && key && key === "_id") { if (is_value && key && key === "_id") {
obj = {"_id": value}; obj = {"_id": value};
...@@ -4993,7 +5034,7 @@ ...@@ -4993,7 +5034,7 @@
} else if (is_value) { } else if (is_value) {
// we need to check an existing query for the fields we are already // we need to check an existing query for the fields we are already
// searching. These fields should not be set in the search // searching. These fields should not be set in the search
if (query && field_list) { if (field_dict && query) {
wrap = ""; wrap = "";
for (property in field_list) { for (property in field_list) {
if (field_list.hasOwnProperty(property)) { if (field_list.hasOwnProperty(property)) {
...@@ -5022,6 +5063,12 @@ ...@@ -5022,6 +5063,12 @@
if (default_query.include_docs || value !== undefined) { if (default_query.include_docs || value !== undefined) {
obj.include_docs = true; obj.include_docs = true;
} }
if (field_list && storage.force_fields) {
delete obj.include_docs;
obj.select_list = storage.makeSelectList(field_list);
}
if (default_query.select_list && default_query.select_list.length > 0) { if (default_query.select_list && default_query.select_list.length > 0) {
obj.select_list = default_query.select_list; obj.select_list = default_query.select_list;
} }
...@@ -5041,7 +5088,6 @@ ...@@ -5041,7 +5088,6 @@
obj.wildcard_character = "%"; obj.wildcard_character = "%";
} }
} }
return obj; return obj;
}; };
...@@ -5389,7 +5435,8 @@ ...@@ -5389,7 +5435,8 @@
pass.config.initial_query, pass.config.initial_query,
pass.type, pass.type,
pass.config.property_dict.initial_query_url_identifier || '_id', pass.config.property_dict.initial_query_url_identifier || '_id',
pass.value pass.value,
pass.fields
); );
} }
...@@ -5453,6 +5500,7 @@ ...@@ -5453,6 +5500,7 @@
} }
// generate new query object // generate new query object
// TODO: we don't pass fields here!
if (pass.config.initial_query) { if (pass.config.initial_query) {
pass.state.query = app.generateQueryObject( pass.state.query = app.generateQueryObject(
{"query": pass.config.initial_query.query}, {"query": pass.config.initial_query.query},
...@@ -5900,9 +5948,8 @@ ...@@ -5900,9 +5948,8 @@
* @param {object} parcel Storage, query options and pass to return * @param {object} parcel Storage, query options and pass to return
* @return {object} promise object/pass * @return {object} promise object/pass
*/ */
// NOTE: until we have real data we load fake data on application init!
app.fetchData = function (parcel) { app.fetchData = function (parcel) {
var method, convert, answer, select_list; var method, convert, select_list;
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;
...@@ -5922,12 +5969,13 @@ ...@@ -5922,12 +5969,13 @@
// TODO: best way? // TODO: best way?
if (convert !== undefined && response.status === 200) { if (convert !== undefined && response.status === 200) {
answer = storage.mapResponse(response, convert); return {
} else { "response": storage.mapResponse(response, convert),
answer = response; "pass": parcel.pass
};
} }
return { return {
"response": answer, "response": response,
"pass": parcel.pass "pass": parcel.pass
}; };
}); });
......
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