qwc2
Version:
QGIS Web Client
206 lines (204 loc) • 10.7 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 2016-2024 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 isEmpty from 'lodash.isempty';
import PropTypes from 'prop-types';
import url from 'url';
import { View3DMode } from '../actions/display';
import { addMarker, removeMarker } from '../actions/layers';
import SideBar from '../components/SideBar';
import ShareLink from '../components/share/ShareLink';
import ShareQRCode from '../components/share/ShareQRCode';
import ShareSocials from '../components/share/ShareSocials';
import ToggleSwitch from '../components/widgets/ToggleSwitch';
import ConfigUtils from '../utils/ConfigUtils';
import CoordinatesUtils from '../utils/CoordinatesUtils';
import LocaleUtils from '../utils/LocaleUtils';
import { generatePermaLink } from '../utils/PermaLinkUtils';
import './style/Share.css';
/**
* Share the current map as a URL/permalink.
*
* Compact permalinks will be generated if `permalinkServiceUrl` in `config.json` points to a `qwc-permalink-service`.
*/
var Share = /*#__PURE__*/function (_React$Component) {
function Share() {
var _this;
_classCallCheck(this, Share);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, Share, [].concat(args));
_defineProperty(_this, "state", {
location: "",
expires: null,
pin: false,
permittedGroup: ""
});
_defineProperty(_this, "renderBody", function () {
var shareUrl = _this.state.location || 'about:blank';
if (_this.state.pin && _this.state.location) {
var urlParts = url.parse(shareUrl, true);
urlParts.query.hc = 1;
if (!urlParts.query.c) {
var posCrs = urlParts.query.crs || _this.props.map.projection;
var prec = CoordinatesUtils.getPrecision(posCrs);
urlParts.query.c = _this.props.map.center.map(function (x) {
return x.toFixed(prec);
}).join(",");
}
delete urlParts.search;
shareUrl = url.format(urlParts);
}
var shareSocials = _this.props.showSocials !== false ? /*#__PURE__*/React.createElement(ShareSocials, {
shareTitle: LocaleUtils.tr("share.shareTitle"),
shareUrl: shareUrl,
showSocials: _this.props.showSocials
}) : null;
var shareLink = _this.props.showLink ? /*#__PURE__*/React.createElement(ShareLink, {
shareUrl: shareUrl
}) : null;
var shareQRCode = _this.props.showQRCode ? /*#__PURE__*/React.createElement(ShareQRCode, {
shareUrl: shareUrl
}) : null;
var username = ConfigUtils.getConfigProp("username");
return /*#__PURE__*/React.createElement("div", null, _this.props.view3dMode !== View3DMode.FULLSCREEN && ConfigUtils.havePlugin("StartupMarker") ? /*#__PURE__*/React.createElement("div", {
className: "share-option-pin"
}, /*#__PURE__*/React.createElement("span", null, LocaleUtils.tr("share.showpin")), /*#__PURE__*/React.createElement(ToggleSwitch, {
active: _this.state.pin,
onChange: function onChange(active) {
return _this.setState({
pin: active
});
}
})) : null, !_this.state.location ? /*#__PURE__*/React.createElement("div", {
className: "share-reload-overlay"
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
className: "button",
onClick: _this.refreshPermalink
}, LocaleUtils.tr("share.refresh"))), username && !isEmpty(_this.props.restrictableGroups) ? /*#__PURE__*/React.createElement("div", {
className: "share-group-restriction"
}, /*#__PURE__*/React.createElement("span", null, LocaleUtils.tr("share.restricttogroup"), ": "), /*#__PURE__*/React.createElement("select", {
onChange: function onChange(ev) {
return _this.setState({
permittedGroup: ev.target.value
});
},
value: _this.state.permittedGroup
}, /*#__PURE__*/React.createElement("option", {
value: ""
}, LocaleUtils.tr("share.norestriction")), _this.props.restrictableGroups.map(function (entry) {
return /*#__PURE__*/React.createElement("option", {
key: entry,
value: entry
}, entry);
}))) : null) : /*#__PURE__*/React.createElement("div", {
className: "share-body"
}, shareSocials, shareLink, shareQRCode, _this.state.expires ? /*#__PURE__*/React.createElement("div", {
className: "share-validity"
}, LocaleUtils.tr("share.expires", _this.state.expires)) : null));
});
_defineProperty(_this, "refreshPermalink", function () {
generatePermaLink(function (permalink, expires) {
_this.setState({
location: permalink,
expires: expires,
permittedGroup: ""
});
}, false, _this.state.permittedGroup);
});
return _this;
}
_inherits(Share, _React$Component);
return _createClass(Share, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps, prevState) {
var isVisible = this.props.currentTask === "Share";
var wasVisible = prevProps.currentTask === "Share";
if (this.props.map && isVisible !== wasVisible || this.state.pin !== prevState.pin || this.props.map.center !== prevProps.map.center) {
if (isVisible && this.state.pin) {
this.props.addMarker('sharecenter', this.props.map.center, '', this.props.map.projection);
} else if (wasVisible) {
this.props.removeMarker('sharecenter');
}
}
if (isVisible !== wasVisible || this.props.map.center !== prevProps.map.center) {
this.setState({
location: "",
expires: null
});
}
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return /*#__PURE__*/React.createElement(SideBar, {
icon: "share",
id: "Share",
onShow: this.onShow,
side: this.props.side,
title: LocaleUtils.tr("appmenu.items.Share"),
width: "20em"
}, function () {
return {
body: _this2.renderBody()
};
});
}
}]);
}(React.Component);
_defineProperty(Share, "availableIn3D", true);
_defineProperty(Share, "propTypes", {
addMarker: PropTypes.func,
currentTask: PropTypes.string,
map: PropTypes.object,
removeMarker: PropTypes.func,
/** List of groups for which a permalink may optionally be restricted (only displayed for a logged-in user). */
restrictableGroups: PropTypes.array,
/** Show the map URL. */
showLink: PropTypes.bool,
/** Show the QR code of the map URL. */
showQRCode: PropTypes.bool,
/** Show the social buttons. Either `true` or `false`to enable/disable all, or an array of specific buttons to display (possible choices: `email`, `facebook`, `twitter`, `linkedin`, `whatsapp`). */
showSocials: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.string)]),
/** The side of the application on which to display the sidebar. */
side: PropTypes.string,
view3dMode: PropTypes.number
});
_defineProperty(Share, "defaultProps", {
showSocials: true,
showLink: true,
showQRCode: true,
side: 'right'
});
export default connect(function (state) {
return {
currentTask: state.task.id,
map: state.map,
view3dMode: state.display.view3dMode
};
}, {
addMarker: addMarker,
removeMarker: removeMarker
})(Share);