Commit 7573a676 authored by Boris Kocherov's avatar Boris Kocherov

[erp5_only_office] olap_wizard.js: filter used hierarchies instead used dimensions

parent dc1f33e1
...@@ -434,6 +434,18 @@ DocsAPI.DocEditor.version = function () { ...@@ -434,6 +434,18 @@ DocsAPI.DocEditor.version = function () {
console.error(err); console.error(err);
}); });
}) })
.allowPublicAcquisition("xmla_getDimension", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.getDimension(arr[0], arr[1]);
});
})
.allowPublicAcquisition("xmla_getHierarchies", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.getHierarchies(arr[0], arr[1]);
});
})
// methods emulating Gateway used for connection with ooffice begin. // methods emulating Gateway used for connection with ooffice begin.
.declareMethod('appReady', function () { .declareMethod('appReady', function () {
......
...@@ -4,19 +4,19 @@ ...@@ -4,19 +4,19 @@
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
function get_used_dimensions(g) { function get_used_hierarchies(g) {
return g.getContent() return g.getContent()
.push(function (v) { .push(function (v) {
var dimensions = [], var hierarchies = [],
key, key,
dimension; hierarchy;
if (v) { if (v) {
if (v.columns) { if (v.columns) {
for (key in v.columns) { for (key in v.columns) {
if (v.columns.hasOwnProperty(key)) { if (v.columns.hasOwnProperty(key)) {
dimension = v.columns[key].dimension; hierarchy = v.columns[key].hierarchy;
if (dimension) { if (hierarchy) {
dimensions.push(dimension); hierarchies.push(hierarchy);
} }
} }
} }
...@@ -24,19 +24,45 @@ ...@@ -24,19 +24,45 @@
if (v.rows) { if (v.rows) {
for (key in v.rows) { for (key in v.rows) {
if (v.rows.hasOwnProperty(key)) { if (v.rows.hasOwnProperty(key)) {
dimension = v.rows[key].dimension; hierarchy = v.rows[key].hierarchy;
if (dimension) { if (hierarchy) {
dimensions.push(dimension); hierarchies.push(hierarchy);
} }
} }
} }
} }
} }
return dimensions; return hierarchies;
}); });
} }
function discoverDimensions(g, connection_name, used_dimensions) { function discoverDimensions(g, connection_name, used_hierarchies) {
return g.request("discoverMDDimensions", connection_name) return g.getHierarchies(connection_name)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var dimensions = {},
i,
row,
uname,
tasks = [];
for (i = 0; i < response.length; i += 1) {
row = response[i];
uname = row.DIMENSION_UNIQUE_NAME;
if (!dimensions.hasOwnProperty(uname) &&
used_hierarchies.indexOf(row.HIERARCHY_UNIQUE_NAME) < 0 &&
row.DIMENSION_TYPE !== 2 // !measure
) {
dimensions[uname] = true;
}
}
for (i in dimensions) {
if (dimensions.hasOwnProperty(i)) {
tasks.push(g.getDimension(connection_name, i))
}
}
return RSVP.all(tasks);
})
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
...@@ -46,19 +72,16 @@ ...@@ -46,19 +72,16 @@
row; row;
for (i = 0; i < response.length; i += 1) { for (i = 0; i < response.length; i += 1) {
row = response[i]; row = response[i];
if (row["DIMENSION_TYPE"] !== 2 && arr.push({
used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) { const: row.DIMENSION_UNIQUE_NAME || undefined,
arr.push({ title: row.DIMENSION_NAME || undefined
const: row["DIMENSION_UNIQUE_NAME"] || undefined, });
title: row["DIMENSION_NAME"] || undefined
});
}
} }
return arr; return arr;
}); });
} }
function discoverHierarchies(g, connection_name, opt) { function discoverHierarchies(g, connection_name, used_hierarchies, opt) {
return g.request("discoverMDHierarchies", connection_name, opt) return g.request("discoverMDHierarchies", connection_name, opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
...@@ -66,13 +89,17 @@ ...@@ -66,13 +89,17 @@
.push(function (response) { .push(function (response) {
var arr = [], var arr = [],
i, i,
row; row,
uname;
for (i = 0; i < response.length; i += 1) { for (i = 0; i < response.length; i += 1) {
row = response[i]; row = response[i];
arr.push({ uname = row.HIERARCHY_UNIQUE_NAME;
const: row["HIERARCHY_UNIQUE_NAME"] || undefined, if (used_hierarchies.indexOf(uname) < 0) {
title: row["HIERARCHY_NAME"] || undefined arr.push({
}); const: uname || undefined,
title: row.HIERARCHY_NAME || undefined
});
}
} }
return arr; return arr;
}); });
...@@ -103,13 +130,13 @@ ...@@ -103,13 +130,13 @@
}); });
} }
function generateChoiceSchema(g, connection_name, used_dimensions, choice_settings) { function generateChoiceSchema(g, connection_name, used_hierarchies, choice_settings) {
var schema = { var schema = {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": {} "properties": {}
}, },
current_dimension; current_hierarchy;
if (!connection_name) { if (!connection_name) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -119,25 +146,28 @@ ...@@ -119,25 +146,28 @@
if (!choice_settings) { if (!choice_settings) {
choice_settings = {}; choice_settings = {};
} }
current_dimension = choice_settings.dimension;
if (current_dimension) { current_hierarchy = choice_settings.hierarchy;
used_dimensions = used_dimensions if (current_hierarchy) {
.filter(function (d) { used_hierarchies = used_hierarchies
return d !== current_dimension; .filter(function (h) {
return h !== current_hierarchy;
}); });
} }
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var tasks = [discoverDimensions(g, connection_name, used_dimensions)]; var tasks = [discoverDimensions(g, connection_name, used_hierarchies)];
if (choice_settings.dimension) { if (choice_settings.dimension) {
tasks.push( tasks.push(
discoverHierarchies(g, connection_name,{prop: { discoverHierarchies(g, connection_name,
restrictions: { used_hierarchies,
DIMENSION_UNIQUE_NAME: choice_settings.dimension {prop: {
} restrictions: {
}}) DIMENSION_UNIQUE_NAME: choice_settings.dimension
}
}})
); );
} }
if (choice_settings.hierarchy) { if (choice_settings.hierarchy) {
...@@ -187,6 +217,8 @@ ...@@ -187,6 +217,8 @@
}) })
.declareAcquiredMethod("getRemoteSettings", "getRemoteSettings") .declareAcquiredMethod("getRemoteSettings", "getRemoteSettings")
.declareAcquiredMethod("request", "xmla_request") .declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getDimension", "xmla_getDimension")
.declareAcquiredMethod("getHierarchies", "xmla_getHierarchies")
.declareAcquiredMethod("getLevels", "xmla_getLevels") .declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) { .allowPublicAcquisition("notifyValid", function (arr, scope) {
}) })
...@@ -222,7 +254,7 @@ ...@@ -222,7 +254,7 @@
scope = arr[0].scope, scope = arr[0].scope,
relPath = arr[0].rel_path, relPath = arr[0].rel_path,
action = arr[0].action, action = arr[0].action,
used_diemensions, used_hierarchy,
url = arr[0].ref, url = arr[0].ref,
allRerender, allRerender,
y; y;
...@@ -230,10 +262,10 @@ ...@@ -230,10 +262,10 @@
function rerender(sub_scope) { function rerender(sub_scope) {
var queue, var queue,
gadget_settings; gadget_settings;
if (!used_diemensions) { if (!used_hierarchy) {
queue = get_used_dimensions(g) queue = get_used_hierarchies(g)
.push(function (v) { .push(function (v) {
used_diemensions = v; used_hierarchy = v;
}); });
} else { } else {
queue = RSVP.Queue(); queue = RSVP.Queue();
...@@ -242,7 +274,7 @@ ...@@ -242,7 +274,7 @@
function rerender_once(connection_name, sub_gadget) { function rerender_once(connection_name, sub_gadget) {
return sub_gadget.getContent() return sub_gadget.getContent()
.push(function (content) { .push(function (content) {
return generateChoiceSchema(g, connection_name, used_diemensions, content); return generateChoiceSchema(g, connection_name, used_hierarchy, content);
}) })
.push(function (schema) { .push(function (schema) {
return gadget_settings.rerender({ return gadget_settings.rerender({
...@@ -270,7 +302,7 @@ ...@@ -270,7 +302,7 @@
return rerender_once(connection_name, sub_gadget) return rerender_once(connection_name, sub_gadget)
.push(function (changed) { .push(function (changed) {
if (changed && changed.length > 0) { if (changed && changed.length > 0) {
if (changed.indexOf('/dimension') >= 0) { if (changed.indexOf('/hierarchy') >= 0) {
return allRerender(); return allRerender();
} }
return rerender_once(connection_name, sub_gadget); return rerender_once(connection_name, sub_gadget);
...@@ -285,9 +317,9 @@ ...@@ -285,9 +317,9 @@
} }
allRerender = function () { allRerender = function () {
return get_used_dimensions(g) return get_used_hierarchies(g)
.push(function (v) { .push(function (v) {
used_diemensions = v; used_hierarchy = v;
return RSVP.all(g.props.choices.map(function (q) { return RSVP.all(g.props.choices.map(function (q) {
return rerender(q); return rerender(q);
})); }));
...@@ -314,7 +346,7 @@ ...@@ -314,7 +346,7 @@
g.props.choices.splice(y, 1); g.props.choices.splice(y, 1);
return allRerender(); return allRerender();
} }
if (relPath === "/dimension") { if (relPath === "/hierarchy") {
return allRerender(); return allRerender();
} }
return rerender(s) return rerender(s)
...@@ -353,8 +385,8 @@ ...@@ -353,8 +385,8 @@
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
g.getContent("/connection_name"), g.getContent("/connection_name"),
g.getContent(path), get_used_hierarchies(g),
get_used_dimensions(g) g.getContent(path)
]); ]);
}) })
.push(function (arr) { .push(function (arr) {
......
...@@ -16,6 +16,22 @@ ...@@ -16,6 +16,22 @@
return cache[key]; return cache[key];
} }
function cached_queue(cache, key, func) {
if (cache.hasOwnProperty(key)) {
return getFromCache(cache, key);
}
var queue = func()
.push(undefined, function (err) {
delete cache[key];
console.error(err);
})
.push(function (value) {
cache[key] = value;
});
cache[key] = queue;
return queue;
}
function xmla_request(func, prop) { function xmla_request(func, prop) {
var xmla = new Xmla({async: true}); var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop)); prop = JSON.parse(JSON.stringify(prop));
...@@ -141,6 +157,7 @@ ...@@ -141,6 +157,7 @@
console.log("xmla_client"); console.log("xmla_client");
g.props = { g.props = {
cache: {}, cache: {},
cache_flags: {},
connections: {} connections: {}
}; };
}) })
...@@ -179,10 +196,13 @@ ...@@ -179,10 +196,13 @@
delete g.props.connections[key]; delete g.props.connections[key];
if (m_dict[key] !== null) { if (m_dict[key] !== null) {
g.props.cache[key] = { g.props.cache[key] = {
dimensions: {},
hierarchies: {},
members: {}, members: {},
levels: {}, levels: {},
membersOnLevel: {} membersOnLevel: {}
}; };
g.props.cache_flags[key] = {};
g.props.connections[key] = JSON.parse(m_dict[key]); g.props.connections[key] = JSON.parse(m_dict[key]);
} }
} }
...@@ -202,6 +222,66 @@ ...@@ -202,6 +222,66 @@
console.error(error); console.error(error);
}); });
}) })
.declareMethod("getDimension", function (connection_name, uname) {
var g = this;
return cached_queue(g.props.cache[connection_name].dimensions,
uname,
function () {
return request(g, "discoverMDDimensions", {
prop: {
restrictions: {
DIMENSION_UNIQUE_NAME: uname
}
}
}, connection_name)
.push(function (r) {
if (r.rowCount() === 0) {
throw new Error("dimension " + uname + " not found");
}
return r.readAsObject();
});
});
})
.declareMethod("getHierarchies", function (connection_name, restrictions) {
var g = this,
arr,
cache = g.props.cache[connection_name].hierarchies,
key;
if (!restrictions && g.props.cache_flags[connection_name].all_hierarchies) {
arr = [];
for (key in cache) {
if (cache.hasOwnProperty(key)) {
arr.push(cache[key]);
}
}
return arr;
}
return request(g, "discoverMDHierarchies", {
prop: {
restrictions: restrictions
}
}, connection_name)
.push(function (response) {
var row,
ret = [],
uname;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
uname = row.HIERARCHY_UNIQUE_NAME;
if (!cache.hasOwnProperty(uname)) {
cache[uname] = row;
}
ret.push(row);
response.nextRow();
}
}
if (!restrictions) {
g.props.cache_flags[connection_name].all_hierarchies = true;
}
return ret;
});
})
.declareMethod("getLevel", function (connection_name, level_uname) { .declareMethod("getLevel", function (connection_name, level_uname) {
var g = this, var g = this,
cache = g.props.cache[connection_name], cache = g.props.cache[connection_name],
......
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