"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require("react");
var react_redux_1 = require("react-redux");
var _ = require("lodash");
var dashboard_1 = require("../dashboard");
var DatasourceFrames = (function (_super) {
__extends(DatasourceFrames, _super);
function DatasourceFrames() {
_super.apply(this, arguments);
}
DatasourceFrames.prototype.render = function () {
var _this = this;
return React.createElement("div", {style: { width: 1, height: 1, position: "fixed", left: 0, top: 0 }}, _.valuesIn(this.props.datasources).map(function (dsState) {
var pluginLoaded = dashboard_1.default.getInstance().datasourcePluginRegistry.hasPlugin(dsState.type);
var datasourcePluginState = _this.props.datasourcePlugins[dsState.type];
return pluginLoaded
? React.createElement(DatasourceIFrame, {key: dsState.id, datasourcePluginState: datasourcePluginState, datasourceState: dsState})
: React.createElement("div", {key: dsState.id}, "Datasource Loading ...");
}));
};
return DatasourceFrames;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = react_redux_1.connect(function (state) {
return {
datasources: state.datasources,
datasourcePlugins: state.datasourcePlugins
};
}, function (dispatch) {
return {};
})(DatasourceFrames);
var DatasourceIFrame = (function (_super) {
__extends(DatasourceIFrame, _super);
function DatasourceIFrame(props) {
_super.call(this, props);
}
DatasourceIFrame.prototype.componentDidMount = function () {
var element = this.refs['frame'];
// TODO: UI is loaded before the datasource is loaded to the registry, this throws then ...
var dsFactory = dashboard_1.default.getInstance().datasourcePluginRegistry.getPlugin(this.props.datasourceState.type);
var dsInstance = dsFactory.getInstance(this.props.datasourceState.id);
dsInstance.iFrame = element;
};
// allow-popups allow-same-origin allow-modals allow-forms
// A sandbox that includes both the allow-same-origin and allow-scripts flags,
// then the framed page can reach up into the parent, and remove the sandbox attribute entirely.
// Only if the framed content comes from the same origin of course.
DatasourceIFrame.prototype.render = function () {
return React.createElement("iframe", {id: 'frame-' + this.props.datasourceState.id, ref: "frame", src: "datasource.html#" + this.props.datasourcePluginState.url, frameBorder: "0", width: "100%", height: "100%", scrolling: "no", sandbox: "allow-scripts"}, "Browser does not support iFrames.");
};
;
return DatasourceIFrame;
}(React.Component));
|