@sisu-llc/pki-suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
166 lines (133 loc) • 6.21 kB
JavaScript
;
exports.__esModule = true;
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _spotfire = require('../lib/spotfire-7.5');
var _spotfire2 = _interopRequireDefault(_spotfire);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var LOGIN_URL = 'http://crspotfire191.pkiapps.net:443/spotfire/login.html';
var DEFAULT_HOST = 'http://crspotfire191.pkiapps.net:443/spotfire/wp/';
var DEFAULT_FILE = '/User Demos/Gerard Conway/worldbank';
function _guid() {
function f() {
return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
}
return f() + f() + f() + f();
}
function constructFilterString(filterObjects) {
// TODO: check for empty array input
var filters = filterObjects || [{}];
var filterString = filters.reduce(function (acc, filter) {
if (filter.table && filter.column && filter.values) {
var values = filter.values.map(function (value) {
return '"' + value + '"';
});
var valuesString = '{' + values.join(',') + '}';
return acc + 'SetFilter(tableName="' + filter.table + '", columnName="' + filter.column + '", values=' + valuesString + ');';
}
return acc;
}, '');
return filterString;
}
/**
* Embeds a Spotfire WebPlayer using Spotfire JS library!
*/
var SpotfireWebPlayer = (_temp = _class = function (_React$Component) {
_inherits(SpotfireWebPlayer, _React$Component);
function SpotfireWebPlayer(props) {
_classCallCheck(this, SpotfireWebPlayer);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.state = {
msg: 'Initializing Spotfire Web Player...',
isLoaded: false,
isInitializing: true,
requiresLogin: false,
guid: props.guid || _guid()
// filters: props.filters || [{}],
};
// SetFilter(tableName=”WorldBankData”,columnName=”Country Name”,values={”Algeria”});
var parameters = constructFilterString(props.filters);
var customizationInfo = new _spotfire2.default.webPlayer.Customization();
customizationInfo.showStatusBar = false;
customizationInfo.showToolbar = false;
customizationInfo.showPageNavigation = false;
customizationInfo.showFilterPanel = false;
var app = new _spotfire2.default.webPlayer.Application(props.host, customizationInfo, props.file, parameters);
app.onError(_this.errorCallback.bind(_this));
app.onClosed(_this.onClosedCallback.bind(_this));
app.onOpened(_this.onOpenedCallback.bind(_this));
_this.app = app;
return _this;
}
SpotfireWebPlayer.prototype.componentDidMount = function componentDidMount() {
this.app.openDocument(this.state.guid);
};
SpotfireWebPlayer.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.app) {
this.app.close();
}
};
SpotfireWebPlayer.prototype.onOpenedCallback = function onOpenedCallback() {
this.setState({ msg: '', isLoaded: true, isInitializing: false });
};
SpotfireWebPlayer.prototype.onClosedCallback = function onClosedCallback(path) {
this.setState({ msg: 'Document at path "' + path + '" closed.', isLoaded: false });
};
SpotfireWebPlayer.prototype.errorCallback = function errorCallback(errorCode, errorMessage) {
var msg = errorCode + ': ' + errorMessage;
var requiresLogin = false;
if (errorCode === _spotfire2.default.webPlayer.errorCodes.ERROROPEN) {
// Could be a 401 issue meaning the user needs to log in
// console.error('Could be a 401');
msg = 'Please sign into Spotfire';
requiresLogin = true;
} else if (errorCode === _spotfire2.default.webPlayer.errorCodes.ERRORINTERNAL) {
// Could be a bad filter setting
msg = 'Internal Spotfire error: please check the filter parameters!';
requiresLogin = false;
}
console.error(errorMessage);
this.setState({ msg: msg, isLoaded: false, isInitializing: false, requiresLogin: requiresLogin });
};
SpotfireWebPlayer.prototype.render = function render() {
var spotfireStyle = { height: 350, display: 'none' };
if (this.state.isLoaded || this.state.isInitializing) {
spotfireStyle = { height: 350, display: 'block' };
}
var loginLink = this.state.requiresLogin ? _react2.default.createElement(
'p',
null,
_react2.default.createElement(
'a',
{ href: this.props.loginUrl, target: '_blank' },
'Sign into Spotfire and refresh this page.'
)
) : _react2.default.createElement('span', null);
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(
'div',
null,
this.state.msg
),
loginLink,
_react2.default.createElement('div', { className: 'spotfireContainer', id: this.state.guid, style: spotfireStyle })
);
};
return SpotfireWebPlayer;
}(_react2.default.Component), _class.displayName = 'SpotfireWebPlayer', _class.defaultProps = {
host: DEFAULT_HOST,
file: DEFAULT_FILE,
loginUrl: LOGIN_URL,
guid: '',
filters: [{}]
}, _temp);
// TODO: move to class method?
SpotfireWebPlayer.constructFilterString = constructFilterString;
exports.default = SpotfireWebPlayer;
module.exports = exports['default'];