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

demo: improve xmla_connection demo

parent 00f99934
......@@ -71,6 +71,7 @@
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.DataSourceInfo = {
title: " ",
oneOf: []
};
var arr = schema.properties.DataSourceInfo.oneOf;
......@@ -94,6 +95,7 @@
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Catalog = {
title: " ",
oneOf: []
};
var arr = schema.properties.Catalog.oneOf;
......@@ -116,6 +118,7 @@
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Cube = {
title: " ",
oneOf: []
};
var arr = schema.properties.Cube.oneOf;
......@@ -131,8 +134,8 @@
});
}
function init_schema() {
return {
function generateSchema(settings) {
var schema = {
"type": "object",
"additionalProperties": false,
"required": ["Cube"],
......@@ -142,6 +145,74 @@
"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)
......@@ -156,10 +227,23 @@
})
.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) {
var g = this,
p = arr[0],
schema = init_schema(),
gadget_settings,
path;
......@@ -172,32 +256,19 @@
})
.push(function (c) {
settings = c;
if (!c.hasOwnProperty('properties')) {
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)
]);
return generateSchema(c);
})
.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) {
return ret.gadget.rerender({
schema: schema,
value: convertOnMultiLevel(settings, '/properties')
});
});
})
.push(function (ret) {
return ret.gadget.rerender(settings);
.push(function () {
// return g.notifyChange();
});
}
......@@ -207,29 +278,35 @@
return f(path);
}
}
// return g.notifyChange();
})
.allowPublicAcquisition("resolveExternalReference", function (arr) {
var g = this,
url = arr[0],
schema_path = arr[1],
path = arr[2],
settings,
connection_path;
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('/');
if (!g.props.xmla_connections.hasOwnProperty(connection_path)) {
g.props.xmla_connections[connection_path] = init_schema();
}
return g.props.xmla_connections[connection_path];
});
connection_path = path.split('/').slice(0, -1).join('/');
if (!g.props.xmla_connections[connection_path]) {
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 generateSchema(settings);
})
.push(function (s) {
g.props.xmla_connections[connection_path] = false;
return s;
});
}
}
throw Error("urn: '" + url + "' not supported");
})
.onStateChange(function (modification_dict) {
throw new Error("urn: '" + url + "' not supported");
});
}(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