Newer
Older
bathroom-plugin / mattermost / webapp / dist / main.js
(()=>{"use strict";var t,e={594:t=>{t.exports=React}},r={},a=(t=function t(a){var s=r[a];if(void 0!==s)return s.exports;var i=r[a]={exports:{}};return e[a](i,i.exports,t),i.exports}(594))&&t.__esModule?t:{default:t};class s extends a.default.Component{constructor(t){super(t),this.hostTable=a.default.createRef(),this.headerLeft=a.default.createRef(),this.headerCenter=a.default.createRef(),this.headerRight=a.default.createRef(),this.state={doors:{}},this.settings={}}componentDidMount(){this.getSettings(),this.resizeTable()}async getSettings(){try{var t=window.location.origin+"/plugins/com.mattermost.bathroom/settings",e=await fetch(t);this.settings=await e.json()}catch(t){return console.log(t),void setTimeout(this.getSettings.bind(this),5e3)}i.registerWebSocketEventHandler("custom_com.mattermost.bathroom_updated",this.updateDoors.bind(this)),this.updateDoors(),this.interval=setInterval(this.updateDoors.bind(this),9e4)}componentWillUnmount(){this.interval&&(clearInterval(this.interval),this.interval=null),i.unregisterWebSocketEventHandler("custom_com.mattermost.bathroom_updated")}async updateDoors(t){try{var e=window.location.origin+"/plugins/com.mattermost.bathroom/status",r=await fetch(e),a=await r.json();this.setState({doors:a})}catch(t){console.log(t),setTimeout(this.updateDoors.bind(this),3e3)}}render(){if(this.state.doors){var t="1px solid "+this.props.theme.sidebarText,e=e=>a.default.createElement("div",{style:{"text-align":"center",width:"100%","padding-top":"5px"}},a.default.createElement("table",{ref:this.hostTable,style:{"border-collapse":"collapse","margin-left":"auto","margin-right":"auto"}},a.default.createElement("tr",null,a.default.createElement("td",{ref:this.headerLeft,style:{"border-bottom":t,height:"11px"}}),a.default.createElement("td",{ref:this.headerCenter,rowspan:2,style:{width:"22px","text-align":"center"}},a.default.createElement("img",{src:e.icon,style:{width:"18px"}})),a.default.createElement("td",{ref:this.headerRight,style:{"border-bottom":t}})),a.default.createElement("tr",null,a.default.createElement("td",{style:{"border-left":t}}),a.default.createElement("td",{style:{"border-right":t}})),a.default.createElement("tr",null,a.default.createElement("td",{colspan:3,style:{"text-align":"center","border-left":t,"border-right":t,"border-bottom":t}},e.content)))),r=Object.keys(this.state.doors).sort();this.settings.door_order&&this.settings.door_order.length==r.length&&(r=this.settings.door_order),Math.floor(100/6);for(var s=[],i=[],o=t=>a.default.createElement("img",{src:t.src,width:"100%",style:{padding:"2px"},title:t.title}),n=(Math.floor(r.length/6),0);n<r.length;n++){var l=null;if(n<r.length){var d=""+r[n],h=this.state.doors[d],c=this.settings[h+"_icons"],u=parseInt(d)-1,m=c[Math.max(0,Math.min(c.length-1,u))];m&&(l=a.default.createElement(o,{src:m,title:this.settings.doors[d]}))}i.push(a.default.createElement("td",{width:"23px"},l)),n%6!=5&&n!=r.length-1||(s.push(a.default.createElement("tr",{style:{height:"15px"}},[...i])),i.length=0)}var g=a.default.createElement("table",{style:{margin:"5px","margin-left":"auto","margin-right":"auto"}},s);return a.default.createElement(e,{content:g,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 i=null;window.registerPlugin("com.mattermost.bathroom",new class{initialize(t,e){i=t,t.registerLeftSidebarHeaderComponent(s)}})})();
//# sourceMappingURL=main.js.map