UNPKG

@metacell/geppetto-meta-client

Version:

Geppetto web frontend. Geppetto is an open-source platform to build web-based tools to visualize and simulate neuroscience data and models.

362 lines (352 loc) 14.7 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Geppetto redux store manager * * Dario Del Piano */ import { clientActions } from './actions/actions'; import { selectInstance, visibilityChanged, focusChanged, modelLoaded, projectLoading, projectLoaded, projectDownloaded, projectConfigLoaded, instanceDeleted, instancesCreated, showSpinner, hideSpinner, parametersSet, loadProjectFromId, loadProjectFromUrl, receivePythonMessage, errorWhileExecPythonCommand, websocketDisconnected, stopLogo, spinLogo, geppettoInfo, geppettoError, stopPersist, spinPersist, jupyterGeppettoExtensionReady, disableControls, addWidget as _addWidget, addWidgets as _addWidgets, deleteWidget as _deleteWidget, updateWidget as _updateWidget, setWidgets as _setWidgets, minimizeWidget as _minimizeWidget, maximizeWidget as _maximizeWidget, activateWidget as _activateWidget } from './actions'; export var callbacksList = {}; for (var action in clientActions) { callbacksList[action] = new Set(); } /** * Workaround to enable the use of EventManager without requiring a redux store. * * EventManager is used across geppetto-core, but not every application has a redux store. */ /** * @deprecated */ var EventManager = /*#__PURE__*/function () { function EventManager() { var _this = this, _defineProperty2; _classCallCheck(this, EventManager); _defineProperty(this, "store", void 0); _defineProperty(this, "initialized", false); _defineProperty(this, "clientActions", clientActions); _defineProperty(this, "eventsCallback", callbacksList); _defineProperty(this, "actionsHandler", (_defineProperty2 = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty2, clientActions.SELECT, function (scope, geometryIdentifier, point) { return _this.store.dispatch(selectInstance(scope, geometryIdentifier, point)); }), clientActions.VISIBILITY_CHANGED, function (instance) { return _this.store.dispatch(visibilityChanged(instance)); }), clientActions.FOCUS_CHANGED, function (instance) { return _this.store.dispatch(focusChanged(instance)); }), clientActions.MODEL_LOADED, function () { return _this.store.dispatch(modelLoaded()); }), clientActions.PROJECT_LOADING, function () { return _this.store.dispatch(projectLoading()); }), clientActions.PROJECT_LOADED, function () { return _this.store.dispatch(projectLoaded()); }), clientActions.PROJECT_DOWNLOADED, function () { return _this.store.dispatch(projectDownloaded()); }), clientActions.PROJECT_CONFIG_LOADED, function (configuration) { return _this.store.dispatch(projectConfigLoaded(configuration)); }), clientActions.INSTANCE_DELETED, function (instancePath) { return _this.store.dispatch(instanceDeleted(instancePath)); }), clientActions.INSTANCES_CREATED, function (instances) { return _this.store.dispatch(instancesCreated(instances)); }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty2, clientActions.PARAMETERS_SET, function () { return _this.store.dispatch(parametersSet()); }), clientActions.RECEIVE_PYTHON_MESSAGE, function (data) { return _this.store.dispatch(receivePythonMessage(data)); }), clientActions.ERROR_WHILE_EXEC_PYTHON_COMMAND, function (data) { return _this.store.dispatch(errorWhileExecPythonCommand(data)); }), clientActions.WEBSOCKET_DISCONNECTED, function () { return _this.store.dispatch(websocketDisconnected()); }), clientActions.STOP_LOGO, function () { return _this.store.dispatch(stopLogo()); }), clientActions.SPIN_LOGO, function () { return _this.store.dispatch(spinLogo()); }), clientActions.GEPPETTO_ERROR, function (message) { return _this.store.dispatch(geppettoError(message)); }), clientActions.GEPPETTO_INFO, function (message) { return _this.store.dispatch(geppettoInfo(message)); }), clientActions.STOP_PERSIST, function () { return _this.store.dispatch(stopPersist()); }), clientActions.SPIN_PERSIST, function () { return _this.store.dispatch(spinPersist()); }), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty2, clientActions.JUPYTER_GEPPETTO_EXTENSION_READY, function () { return _this.store.dispatch(jupyterGeppettoExtensionReady()); }), clientActions.DISABLE_CONTROLS, function () { return _this.store.dispatch(disableControls()); }), clientActions.SHOW_SPINNER, function (message, offAction) { _this.store.dispatch(showSpinner(message, offAction)); }), clientActions.HIDE_SPINNER, function () { _this.store.dispatch(hideSpinner()); }), clientActions.PROJECT_LOAD_FROM_ID, function (projectId) { return _this.store.dispatch(loadProjectFromId(projectId)); }), clientActions.PROJECT_LOAD_FROM_URL, function (projectUrl) { return _this.store.dispatch(loadProjectFromUrl(projectUrl)); }))); this.store = { dispatch: function dispatch(_) {} }; } return _createClass(EventManager, [{ key: "setStore", value: function setStore(store) { if (this.initialized) { console.warn("Multiple stores found, EventManager will use the last one set."); } this.store = store; this.initialized = true; } }, { key: "action", value: function action(_action, params) { this.store.dispatch({ type: _action, data: _objectSpread({}, params) }); } }, { key: "select", value: function select(scope, geometryIdentifier, point) { this.actionsHandler[clientActions.SELECT](scope, geometryIdentifier, point); } }, { key: "changeVisibility", value: function changeVisibility(instance) { this.actionsHandler[clientActions.VISIBILITY_CHANGED](instance); } }, { key: "changeFocus", value: function changeFocus(instance) { this.actionsHandler[clientActions.FOCUS_CHANGED](instance); } }, { key: "modelLoaded", value: function modelLoaded() { this.actionsHandler[clientActions.MODEL_LOADED](); } }, { key: "loadProjectFromId", value: function loadProjectFromId(projectId) { this.actionsHandler[clientActions.PROJECT_LOAD_FROM_ID](projectId); } }, { key: "loadProjectFromUrl", value: function loadProjectFromUrl(projectUrl) { this.actionsHandler[clientActions.PROJECT_LOAD_FROM_URL](projectUrl); } }, { key: "projectLoaded", value: function projectLoaded() { this.actionsHandler[clientActions.PROJECT_LOADED](); } }, { key: "projectDownloaded", value: function projectDownloaded() { this.actionsHandler[clientActions.PROJECT_DOWNLOADED](); } }, { key: "projectConfigLoaded", value: function projectConfigLoaded(configuration) { this.actionsHandler[clientActions.PROJECT_CONFIG_LOADED](configuration); } }, { key: "instanceDeleted", value: function instanceDeleted(instancePath) { this.actionsHandler[clientActions.INSTANCE_DELETED](instancePath); } }, { key: "instancesCreated", value: function instancesCreated(instances) { this.actionsHandler[clientActions.INSTANCES_CREATED](instances); } }, { key: "showQueryBuilder", value: function showQueryBuilder() { this.actionsHandler[clientActions.SHOW_QUERYBUILDER](); } }, { key: "hideQueryBuilder", value: function hideQueryBuilder() { this.actionsHandler[clientActions.HIDE_QUERYBUILDER](); } }, { key: "showSpinner", value: function showSpinner(message) { var offAction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; this.actionsHandler[clientActions.SHOW_SPINNER](message, offAction); } }, { key: "showHelp", value: function showHelp() { this.actionsHandler[clientActions.SHOW_HELP](); } }, { key: "hideHelp", value: function hideHelp() { this.actionsHandler[clientActions.HIDE_HELP](); } }, { key: "setColor", value: function setColor(parameters) { this.actionsHandler[clientActions.COLOR_SET](parameters); } }, { key: "projectMadePublic", value: function projectMadePublic() { this.actionsHandler[clientActions.PROJECT_MADE_PUBLIC](); } }, { key: "litEntitiesChanged", value: function litEntitiesChanged() { this.actionsHandler[clientActions.LIT_ENTITIES_CHANGED](); } }, { key: "componentDestroyed", value: function componentDestroyed() { this.actionsHandler[clientActions.COMPONENT_DESTROYED](); } }, { key: "projectPropertiesSaved", value: function projectPropertiesSaved() { this.actionsHandler[clientActions.PROJECT_PROPERTIES_SAVED](); } }, { key: "parametersSet", value: function parametersSet() { this.actionsHandler[clientActions.PARAMETERS_SET](); } }, { key: "receivePythonMessage", value: function receivePythonMessage(data) { this.actionsHandler[clientActions.RECEIVE_PYTHON_MESSAGE](data); } }, { key: "errorWhileExecPythonCommand", value: function errorWhileExecPythonCommand(data) { this.actionsHandler[clientActions.ERROR_WHILE_EXEC_PYTHON_COMMAND](data); } }, { key: "websocketDisconnected", value: function websocketDisconnected() { this.actionsHandler[clientActions.WEBSOCKET_DISCONNECTED](); } }, { key: "stopLogo", value: function stopLogo() { this.actionsHandler[clientActions.STOP_LOGO](); } }, { key: "spinLogo", value: function spinLogo() { this.actionsHandler[clientActions.SPIN_LOGO](); } }, { key: "geppettoError", value: function geppettoError(message) { this.actionsHandler[clientActions.GEPPETTO_ERROR](message); } }, { key: "geppettoInfo", value: function geppettoInfo(message) { this.actionsHandler[clientActions.GEPPETTO_INFO](message); } }, { key: "stopPersist", value: function stopPersist() { this.actionsHandler[clientActions.STOP_PERSIST](); } }, { key: "spinPersist", value: function spinPersist() { this.actionsHandler[clientActions.SPIN_PERSIST](); } }, { key: "jupyterGeppettoExtensionReady", value: function jupyterGeppettoExtensionReady() { this.actionsHandler[clientActions.JUPYTER_GEPPETTO_EXTENSION_READY](); } }, { key: "disableControls", value: function disableControls() { this.actionsHandler[clientActions.DISABLE_CONTROLS](); } /** * Add a widget to the layout * @param widget */ }, { key: "addWidget", value: function addWidget(widget) { this.store.dispatch(_addWidget(widget)); } /** * Update a widget * @param widget */ }, { key: "updateWidget", value: function updateWidget(widget) { this.store.dispatch(_updateWidget(widget)); } /** * Adds all the widgets to the layout * @param widget */ }, { key: "addWidgets", value: function addWidgets(widget) { this.store.dispatch(_addWidgets(widget)); } /** * Set/replaces widgets to the layout * @param widget */ }, { key: "setWidgets", value: function setWidgets(widget) { this.store.dispatch(_setWidgets(widget)); } /** * Removes a widget from the layout * @param widget */ }, { key: "deleteWidget", value: function deleteWidget(widgetId) { this.store.dispatch(_deleteWidget(widgetId)); } /** * Set widget to minimized status (sugar for update widget) * @param widget */ }, { key: "minimizeWidget", value: function minimizeWidget(widgetId) { this.store.dispatch(_minimizeWidget(widgetId)); } /** * Set widget to maximize status (sugar for update widget) * @param widget */ }, { key: "maximizeWidget", value: function maximizeWidget(widgetId) { this.store.dispatch(_maximizeWidget(widgetId)); } /** * Set widget to active status (sugar for update widget) * @param widget */ }, { key: "activateWidget", value: function activateWidget(widgetId) { this.store.dispatch(_activateWidget(widgetId)); } }]); }(); export default new EventManager();