Commit 12d8ca64 authored by Boris Kocherov's avatar Boris Kocherov

demo: improve xmla_connection demo

parent 00f99934
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (response && response.numRows > 0) {
schema.properties.DataSourceInfo = { schema.properties.DataSourceInfo = {
title: " ",
oneOf: [] oneOf: []
}; };
var arr = schema.properties.DataSourceInfo.oneOf; var arr = schema.properties.DataSourceInfo.oneOf;
...@@ -94,6 +95,7 @@ ...@@ -94,6 +95,7 @@
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (response && response.numRows > 0) {
schema.properties.Catalog = { schema.properties.Catalog = {
title: " ",
oneOf: [] oneOf: []
}; };
var arr = schema.properties.Catalog.oneOf; var arr = schema.properties.Catalog.oneOf;
...@@ -116,6 +118,7 @@ ...@@ -116,6 +118,7 @@
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (response && response.numRows > 0) {
schema.properties.Cube = { schema.properties.Cube = {
title: " ",
oneOf: [] oneOf: []
}; };
var arr = schema.properties.Cube.oneOf; var arr = schema.properties.Cube.oneOf;
...@@ -131,8 +134,8 @@ ...@@ -131,8 +134,8 @@
}); });
} }
function init_schema() { function generateSchema(settings) {
return { var schema = {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"required": ["Cube"], "required": ["Cube"],
...@@ -142,6 +145,74 @@ ...@@ -142,6 +145,74 @@
"Cube": {"type": "string"} "Cube": {"type": "string"}
} }
}; };
if (!settings) {
return new RSVP.Queue()
.push(function () {
return schema;
});
}
if (!settings.hasOwnProperty('properties')) {
settings.properties = {};
}
return new RSVP.Queue()
.push(function () {
return RSVP.all([
discoverDataSources(schema, {
urls: settings.urls,
prop: {}
}),
discoverDBCatalogs(schema, {
urls: settings.urls,
prop: {
properties: {
DataSourceInfo: settings.properties.DataSourceInfo
}
}
}),
discoverMDCubes(schema, {
urls: settings.urls,
prop: {
properties: {
DataSourceInfo: settings.properties.DataSourceInfo,
Catalog: settings.properties.Catalog
}
}
})
]);
})
.push(function () {
return schema;
});
}
function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g, '/').replace(/~0/g, '~');
}
function convertOnMultiLevel(d, key, value) {
var ii,
kk,
key_list = key.split("/");
for (ii = 1; ii < key_list.length; ii += 1) {
kk = decodeJsonPointer(key_list[ii]);
if (ii === key_list.length - 1) {
if (value !== undefined) {
d[kk] = value[0];
} else {
return d[kk];
}
} else {
if (!d.hasOwnProperty(kk)) {
if (value !== undefined) {
d[kk] = {};
} else {
return;
}
}
d = d[kk];
}
}
} }
rJS(window) rJS(window)
...@@ -156,10 +227,23 @@ ...@@ -156,10 +227,23 @@
}) })
.allowPublicAcquisition("notifyInvalid", function (arr, scope) { .allowPublicAcquisition("notifyInvalid", function (arr, scope) {
}) })
.declareMethod("render", function (opt) {
this.props.init_value = opt.value;
return this.getDeclaredGadget("xmla_settings")
.push(function (g) {
return g.render(opt);
});
})
.declareMethod("getContent", function () {
return this.getDeclaredGadget("xmla_settings")
.push(function (g) {
return g.getContent();
});
})
.declareAcquiredMethod("notifyChange", "notifyChange")
.allowPublicAcquisition("notifyChange", function (arr, scope) { .allowPublicAcquisition("notifyChange", function (arr, scope) {
var g = this, var g = this,
p = arr[0], p = arr[0],
schema = init_schema(),
gadget_settings, gadget_settings,
path; path;
...@@ -172,32 +256,19 @@ ...@@ -172,32 +256,19 @@
}) })
.push(function (c) { .push(function (c) {
settings = c; settings = c;
if (!c.hasOwnProperty('properties')) { return generateSchema(c);
c.properties = {};
}
var opt = {
urls: c.urls,
prop: {
properties: {
DataSourceInfo: c.properties.DataSourceInfo,
Catalog: c.properties.Catalog
}
},
cube: c.properties.Cube
};
return RSVP.all([
discoverDataSources(schema, opt),
discoverDBCatalogs(schema, opt),
discoverMDCubes(schema, opt)
]);
})
.push(function () {
g.props.xmla_connections[p] = schema;
return gadget_settings.getGadgetByPath(p);
}) })
.push(function (schema) {
return gadget_settings.getGadgetByPath(p + '/properties')
.push(function (ret) { .push(function (ret) {
return ret.gadget.rerender(settings); return ret.gadget.rerender({
schema: schema,
value: convertOnMultiLevel(settings, '/properties')
});
});
})
.push(function () {
// return g.notifyChange();
}); });
} }
...@@ -207,29 +278,35 @@ ...@@ -207,29 +278,35 @@
return f(path); return f(path);
} }
} }
// return g.notifyChange();
}) })
.allowPublicAcquisition("resolveExternalReference", function (arr) { .allowPublicAcquisition("resolveExternalReference", function (arr) {
var g = this, var g = this,
url = arr[0], url = arr[0],
schema_path = arr[1], schema_path = arr[1],
path = arr[2], path = arr[2],
settings,
connection_path; connection_path;
if ("urn:jio:properties_from_xmla.connection.json" === url) { if ("urn:jio:properties_from_xmla.connection.json" === url) {
return g.getDeclaredGadget("xmla_settings")
.push(function (gadget) {
return gadget.getContent();
})
.push(function (value) {
connection_path = path.split('/').slice(0, -1).join('/'); connection_path = path.split('/').slice(0, -1).join('/');
if (!g.props.xmla_connections.hasOwnProperty(connection_path)) { if (!g.props.xmla_connections[connection_path]) {
g.props.xmla_connections[connection_path] = init_schema(); return new RSVP.Queue()
.push(function () {
if (g.props.init_value) {
settings = convertOnMultiLevel(g.props.init_value, connection_path);
if (settings) {
convertOnMultiLevel(g.props.init_value, connection_path, []);
} }
return g.props.xmla_connections[connection_path];
});
} }
throw Error("urn: '" + url + "' not supported"); return generateSchema(settings);
}) })
.onStateChange(function (modification_dict) { .push(function (s) {
g.props.xmla_connections[connection_path] = false;
return s;
});
}
}
throw new Error("urn: '" + url + "' not supported");
}); });
}(window, rJS)); }(window, rJS));
\ No newline at end of file
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