/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/"; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 0); /******/ }) /************************************************************************/ /******/ ({ /***/ "./src/index.jsx": /*!***********************!*\ !*** ./src/index.jsx ***! \***********************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _react = _interopRequireDefault(__webpack_require__(/*! react */ "react")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } class BathroomComponent extends _react.default.Component { constructor(props) { super(props); this.hostTable = _react.default.createRef(); this.headerLeft = _react.default.createRef(); this.headerCenter = _react.default.createRef(); this.headerRight = _react.default.createRef(); this.state = { doors: {} }; this.settings = {}; } componentDidMount() { this.getSettings(); this.resizeTable(); } async getSettings() { try { var url = window.location.origin + "/plugins/com.mattermost.bathroom/settings"; var res = await fetch(url); this.settings = await res.json(); } catch (e) { console.log(e); setTimeout(this.getSettings.bind(this), 5000); return; } Registry.registerWebSocketEventHandler("custom_com.mattermost.bathroom_updated", this.updateDoors.bind(this)); this.updateDoors(); this.interval = setInterval(this.updateDoors.bind(this), 90000); } componentWillUnmount() { if (this.interval) { clearInterval(this.interval); this.interval = null; } Registry.unregisterWebSocketEventHandler("custom_com.mattermost.bathroom_updated"); } async updateDoors(msg) { //var url = Store.getState().entities.general.config.SiteURL + "/plugins/com.mattermost.bathroom/status"; try { var url = window.location.origin + "/plugins/com.mattermost.bathroom/status"; var res = await fetch(url); var json = await res.json(); this.setState({ "doors": json }); } catch (e) { console.log(e); setTimeout(this.updateDoors.bind(this), 3000); } } render() { if (!this.state.doors) return; var borderString = "1px solid " + this.props.theme.sidebarText; var Host = props => _react.default.createElement("div", { style: { "text-align": "center", width: "100%", "padding-top": "5px" } }, _react.default.createElement("table", { ref: this.hostTable, style: { "border-collapse": "collapse", "margin-left": "auto", "margin-right": "auto" } }, _react.default.createElement("tr", null, _react.default.createElement("td", { ref: this.headerLeft, style: { "border-bottom": borderString, "height": "11px" } }), _react.default.createElement("td", { ref: this.headerCenter, rowspan: 2, style: { "width": "22px", "text-align": "center" } }, _react.default.createElement("img", { src: props.icon, style: { "width": "18px" } })), _react.default.createElement("td", { ref: this.headerRight, style: { "border-bottom": borderString } })), _react.default.createElement("tr", null, _react.default.createElement("td", { style: { "border-left": borderString } }), _react.default.createElement("td", { style: { "border-right": borderString } })), _react.default.createElement("tr", null, _react.default.createElement("td", { colspan: 3, style: { "text-align": "center", "border-left": borderString, "border-right": borderString, "border-bottom": borderString } }, props.content)))); var columns = 6; var keys = Object.keys(this.state.doors).sort(); var width = Math.floor(100 / columns /*+ 1*/ ) + "%"; var widthPx = "23px"; var elems = []; var row = []; var rows = 0; var IconImg = props => _react.default.createElement("img", { src: props.src, width: "100%", style: { "padding": "2px" }, title: props.title }); var totalRows = Math.floor(keys.length / columns) + 1; for (var i = 0; i < keys.length /*(Math.floor(keys.length / 6) + 1) * 6*/ ; i++) { var img = null; if (i < keys.length) { var key = keys[i]; var door = this.state.doors[key]; var imgFile = this.settings[door + "_icon"]; if (imgFile) { img = _react.default.createElement(IconImg, { src: imgFile, title: this.settings.doors[key] }); //img = <img src={imgFile} width="100%" style={{"padding":"2px"}} title={this.settings.doors[key]}/> } } row.push(_react.default.createElement("td", { width: widthPx }, img)); if (i % columns == columns - 1 || i == keys.length - 1) { /* if (rows == 0) { row.unshift( //<td rowspan={99} width={widthPx}><img src={this.settings.info_icon} width="100%" style={{"padding":"2px"}}/></td> <td rowspan={totalRows} width={widthPx} style={{"color": this.props.theme.sidebarText, "padding-right":"5px"}}><IconImg src={this.settings.info_icon}/>:</td> ); } */ elems.push(_react.default.createElement("tr", { style: { "height": "15px" } }, [...row])); row.length = 0; rows++; } } var content = _react.default.createElement("table", { style: { "margin": "5px", "margin-left": "auto", "margin-right": "auto" } }, elems); return _react.default.createElement(Host, { content: content, icon: this.settings.info_icon }); } componentDidUpdate() { this.resizeTable(); } resizeTable() { this.headerLeft.current.width = this.headerRight.current.width = Math.max(50, (this.hostTable.current.clientWidth - this.headerCenter.current.clientWidth) / 2); } } var Registry = null; var Store = null; class BathroomMonitorPlugin { initialize(registry, store) { Registry = registry; Store = store; registry.registerLeftSidebarHeaderComponent(BathroomComponent); } } window.registerPlugin('com.mattermost.bathroom', new BathroomMonitorPlugin()); /***/ }), /***/ 0: /*!*****************************!*\ !*** multi ./src/index.jsx ***! \*****************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(/*! ./src/index.jsx */"./src/index.jsx"); /***/ }), /***/ "react": /*!************************!*\ !*** external "React" ***! \************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = React; /***/ }) /******/ }); //# sourceMappingURL=main.js.map