var $ = require('jquery'); var React = require('react/addons'); var Router = require('react-router'); var ContainerStore = require('./ContainerStore'); var ContainerList = require('./ContainerList.react'); var Header = require('./Header.react'); var ipc = require('ipc'); var remote = require('remote'); var metrics = require('./Metrics'); var autoUpdater = remote.require('auto-updater'); var RetinaImage = require('react-retina-image'); var machine = require('./DockerMachine'); var util = require('./Util'); var Containers = React.createClass({ mixins: [Router.Navigation, Router.State], getInitialState: function () { return { sidebarOffset: 0, containers: ContainerStore.containers(), sorted: ContainerStore.sorted(), updateAvailable: false, currentButtonLabel: '', error: ContainerStore.error(), downloading: ContainerStore.downloading() }; }, componentDidMount: function () { this.update(); ContainerStore.on(ContainerStore.SERVER_ERROR_EVENT, this.updateError); ContainerStore.on(ContainerStore.SERVER_CONTAINER_EVENT, this.update); ContainerStore.on(ContainerStore.CLIENT_CONTAINER_EVENT, this.updateFromClient); ipc.on('application:update-available', () => { this.setState({ updateAvailable: true }); }); autoUpdater.checkForUpdates(); }, componentDidUnmount: function () { ContainerStore.removeListener(ContainerStore.SERVER_CONTAINER_EVENT, this.update); ContainerStore.removeListener(ContainerStore.CLIENT_CONTAINER_EVENT, this.updateFromClient); }, updateError: function (err) { this.setState({ error: err }); }, update: function (name, status) { var sorted = ContainerStore.sorted(); this.setState({ containers: ContainerStore.containers(), sorted: sorted, pending: ContainerStore.pending(), downloading: ContainerStore.downloading() }); if (status === 'destroy') { if (sorted.length) { this.transitionTo('containerHome', {name: sorted[0].Name}); } else { this.transitionTo('containers'); } } }, updateFromClient: function (name, status) { this.update(name, status); if (status === 'create') { this.transitionTo('containerHome', {name: name}); } else if (status === 'pending' && ContainerStore.pending()) { this.transitionTo('pull'); } }, handleScroll: function (e) { if (e.target.scrollTop > 0 && !this.state.sidebarOffset) { this.setState({ sidebarOffset: e.target.scrollTop }); } else if (e.target.scrollTop === 0 && this.state.sidebarOffset) { this.setState({ sidebarOffset: 0 }); } }, handleNewContainer: function () { $(this.getDOMNode()).find('.new-container-item').parent().fadeIn(); this.transitionTo('new'); metrics.track('Pressed New Container'); }, handleAutoUpdateClick: function () { metrics.track('Restarted to Update'); ipc.send('application:quit-install'); }, handleClickPreferences: function () { metrics.track('Opened Preferences', { from: 'app' }); this.transitionTo('preferences'); }, handleClickDockerTerminal: function () { metrics.track('Opened Docker Terminal', { from: 'app' }); machine.dockerTerminal(); }, handleClickReportIssue: function () { metrics.track('Opened Issue Reporter', { from: 'app' }); util.exec(['open', 'https://github.com/kitematic/kitematic/issues/new']); }, handleMouseEnterDockerTerminal: function () { this.setState({ currentButtonLabel: 'Open terminal to use Docker command line.' }); }, handleMouseLeaveDockerTerminal: function () { this.setState({ currentButtonLabel: '' }); }, handleMouseEnterReportIssue: function () { this.setState({ currentButtonLabel: 'Report an issue or suggest feedback.' }); }, handleMouseLeaveReportIssue: function () { this.setState({ currentButtonLabel: '' }); }, handleMouseEnterPreferences: function () { this.setState({ currentButtonLabel: 'Change app preferences.' }); }, handleMouseLeavePreferences: function () { this.setState({ currentButtonLabel: '' }); }, render: function () { var sidebarHeaderClass = 'sidebar-header'; if (this.state.sidebarOffset) { sidebarHeaderClass += ' sep'; } var updateWidget; if (this.state.updateAvailable) { updateWidget = ( New Update ); } var container = this.getParams().name ? this.state.containers[this.getParams().name] : {}; return (

Containers

{this.state.currentButtonLabel}
{updateWidget}
); } }); module.exports = Containers;