var _ = require('underscore'); var $ = require('jquery'); var React = require('react/addons'); var exec = require('exec'); var ContainerStore = require('./ContainerStore'); var ContainerUtil = require('./ContainerUtil'); var Router = require('react-router'); var ContainerHomePreview = React.createClass({ mixins: [Router.State, Router.Navigation], getInitialState: function () { return { ports: {}, defaultPort: null }; }, componentWillReceiveProps: function () { this.init(); }, componentDidMount: function() { this.init(); this.timer = setInterval(this.tick, 2000); }, tick: function () { if (document.getElementById('web-preview-frame')) { var frameContent = document.getElementById('web-preview-frame').contentDocument; var $body = $(frameContent.body); if ($body.is(':empty')) { document.getElementById('web-preview-frame').contentDocument.location.reload(true); } } }, componentWillUnmount: function() { clearInterval(this.timer); }, init: function () { var container = ContainerStore.container(this.getParams().name); if (!container) { return; } var ports = ContainerUtil.ports(container); var webPorts = ['80', '8000', '8080', '3000', '5000', '2368']; this.setState({ ports: ports, defaultPort: _.find(_.keys(ports), function (port) { return webPorts.indexOf(port) !== -1; }) }); }, handleClickPreview: function () { if (this.state.defaultPort) { exec(['open', this.state.ports[this.state.defaultPort].url], function (err) { if (err) { throw err; } }); } }, handleClickNotShowingCorrectly: function () { this.transitionTo('containerSettingsPorts', {name: this.getParams().name}); }, render: function () { var preview; if (this.state.defaultPort) { preview = (
You can access this container from the outside using the following IP & Port(s):
{ports}