qwc2
Version:
QGIS Web Client
207 lines (205 loc) • 10.4 kB
JavaScript
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 _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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, 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); }
/**
* Copyright 2020, Sourcepole AG.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { setCurrentTask } from '../actions/task';
import { openExternalUrl } from '../actions/windows';
import AppMenu from '../components/AppMenu';
import Icon from '../components/Icon';
import ThemeList from '../components/ThemeList';
import ConfigUtils from '../utils/ConfigUtils';
import LocaleUtils from '../utils/LocaleUtils';
import { UrlParams } from '../utils/PermaLinkUtils';
import ThemeUtils from '../utils/ThemeUtils';
import './style/Portal.css';
/**
* Displays a landing lage, consisting of a full-screen theme switcher and a configurable menu.
*/
var Portal = /*#__PURE__*/function (_React$Component) {
function Portal() {
var _this;
_classCallCheck(this, Portal);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Portal, [].concat(args));
_defineProperty(_this, "state", {
filter: "",
popupClosed: false,
menuVisible: false
});
_defineProperty(_this, "openUrl", function (url, target, title) {
if (target === "iframe") {
target = ":iframedialog:externallinkiframe";
}
_this.props.openExternalUrl(url, target, {
title: title,
zIndex: 250
});
});
_defineProperty(_this, "menuToggled", function (visible) {
_this.setState({
menuVisible: visible
});
});
return _this;
}
_inherits(Portal, _React$Component);
return _createClass(Portal, [{
key: "componentDidMount",
value: function componentDidMount() {
if (!this.props.startupParams.t && !this.props.startupParams.k && !this.props.startupParams.bk) {
this.props.setCurrentTask("Portal");
}
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.currentTask === "Portal" && (this.props.currentTask !== prevProps.currentTask || this.props.currentTheme !== prevProps.currentTheme || this.props.map !== prevProps.map)) {
UrlParams.clear();
} else if (!prevProps.themes && this.props.themes && this.props.currentTask !== "Portal") {
// Show portal if no theme is to be loaded
var theme = ThemeUtils.getThemeById(this.props.themes, this.props.startupParams.t);
if ((!theme || theme.restricted) && (ConfigUtils.getConfigProp("dontLoadDefaultTheme") || !this.props.themes.defaultTheme)) {
this.props.setCurrentTask("Portal");
}
}
}
}, {
key: "render",
value: function render() {
var _this2 = this;
if (this.props.currentTask !== "Portal") {
return null;
}
var assetsPath = ConfigUtils.getAssetsPath();
var preserveSettings = ConfigUtils.getConfigProp("preserveSettingsOnPortalThemeSwitch");
return /*#__PURE__*/React.createElement("div", {
className: "Portal"
}, /*#__PURE__*/React.createElement("div", {
className: "portal-topbar"
}, /*#__PURE__*/React.createElement("img", {
className: "portal-logo",
src: assetsPath + "/img/" + this.props.logo
}), /*#__PURE__*/React.createElement("span", {
className: "portal-topbar-text",
dangerouslySetInnerHTML: {
__html: this.props.topBarText
}
}), /*#__PURE__*/React.createElement("input", {
className: "portal-search-field",
onChange: function onChange(ev) {
return _this2.setState({
filter: ev.target.value
});
},
placeholder: LocaleUtils.tr("portal.filter"),
type: "text",
value: this.state.filter
}), /*#__PURE__*/React.createElement("span", {
className: "portal-topbar-spacer"
}), this.props.menuItems.length > 0 ? /*#__PURE__*/React.createElement(AppMenu, {
appMenuClearsTask: false,
buttonLabel: LocaleUtils.tr("portal.menulabel"),
keepMenuOpen: this.props.keepMenuOpen,
menuItems: this.props.menuItems,
onMenuToggled: this.menuToggled,
openExternalUrl: this.openUrl,
showOnStartup: this.props.showMenuOnStartup
}) : null), /*#__PURE__*/React.createElement("div", {
className: "portal-body " + (this.state.menuVisible ? "portal-body-menuvisible" : "")
}, /*#__PURE__*/React.createElement(ThemeList, {
collapsibleGroups: this.props.collapsibleGroups,
dontPreserveSettingsOnSwitch: !preserveSettings,
expandGroups: this.props.expandGroups,
filter: this.state.filter
})), /*#__PURE__*/React.createElement("div", {
className: "portal-bottombar"
}, this.props.userName ? /*#__PURE__*/React.createElement("div", {
className: "portal-bottombar-user"
}, /*#__PURE__*/React.createElement(Icon, {
icon: "logout"
}), /*#__PURE__*/React.createElement("span", null, this.props.userName)) : null, /*#__PURE__*/React.createElement("div", {
className: "portal-bottombar-links"
}, (this.props.bottomBarLinks || []).map(function (link, idx) {
var _link$label;
var label = (_link$label = link.label) !== null && _link$label !== void 0 ? _link$label : LocaleUtils.tr(link.labelmsgid);
return /*#__PURE__*/React.createElement("a", {
href: "#",
key: "l" + idx,
onClick: function onClick(ev) {
ev.preventDefault();
_this2.openUrl(link.href, link.target, label);
}
}, label);
}))));
}
}]);
}(React.Component);
_defineProperty(Portal, "propTypes", {
/** Links to show in the portal bottom bar */
bottomBarLinks: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
label: PropTypes.string,
labelmsgid: PropTypes.string,
target: PropTypes.string
})),
/** Whether to allow collapsing groups in the theme switcher. */
collapsibleGroups: PropTypes.bool,
currentTask: PropTypes.string,
currentTheme: PropTypes.object,
/** Whether to expand theme groups by default. */
expandGroups: PropTypes.bool,
keepMenuOpen: PropTypes.bool,
/** Name of a logo image below assets/img. */
logo: PropTypes.string,
map: PropTypes.object,
/** Portal menu items, in the same format as the TopBar menu items. */
menuItems: PropTypes.array,
openExternalUrl: PropTypes.func,
setCurrentTask: PropTypes.func,
/** Whether the menu should be visible on startup. */
showMenuOnStartup: PropTypes.bool,
startupParams: PropTypes.object,
themes: PropTypes.object,
/** Portal title text to show in the top bar. */
topBarText: PropTypes.string,
userName: PropTypes.string
});
_defineProperty(Portal, "defaultProps", {
menuItems: []
});
var selector = function selector(state) {
return {
currentTask: state.task.id,
currentTheme: state.theme.current,
map: state.map,
themes: state.theme.themes,
startupParams: state.localConfig.startupParams,
userName: state.localConfig.username || ""
};
};
export default connect(selector, {
setCurrentTask: setCurrentTask,
openExternalUrl: openExternalUrl
})(Portal);