import _ from 'underscore'; import React from 'react/addons'; import metrics from '../utils/MetricsUtil'; import electron, { clipboard } from 'electron'; const remote = electron.remote; const dialog = remote.dialog; import ContainerUtil from '../utils/ContainerUtil'; import containerActions from '../actions/ContainerActions'; import util from '../utils/Util'; var ContainerSettingsGeneral = React.createClass({ mixins: [React.addons.LinkedStateMixin], contextTypes: { router: React.PropTypes.func }, getInitialState: function () { let env = ContainerUtil.env(this.props.container) || []; env.push(['', '']); env = _.map(env, e => { return [util.randomId(), e[0], e[1]]; }); return { slugName: null, nameError: null, copiedId: false, env: env }; }, handleNameChange: function (e) { var name = e.target.value; if (name === this.state.slugName) { return; } name = name.replace(/^\s+|\s+$/g, ''); // Trim name = name.toLowerCase(); // Remove Accents let from = "àáäâèéëêìíïîòóöôùúüûñç·/,:;"; let to = "aaaaeeeeiiiioooouuuunc-----"; for (var i=0, l=from.length ; i { let [, key, value] = kvp; if ((key && key.length) || (value && value.length)) { list.push(key + '=' + value); } }); containerActions.update(this.props.container.Name, {Env: list}); }, handleChangeEnvKey: function (index, event) { let env = _.map(this.state.env, _.clone); env[index][1] = event.target.value; this.setState({ env: env }); }, handleChangeEnvVal: function (index, event) { let env = _.map(this.state.env, _.clone); env[index][2] = event.target.value; this.setState({ env: env }); }, handleAddEnvVar: function () { let env = _.map(this.state.env, _.clone); env.push([util.randomId(), '', '']); this.setState({ env: env }); metrics.track('Added Pending Environment Variable'); }, handleRemoveEnvVar: function (index) { let env = _.map(this.state.env, _.clone); env.splice(index, 1); if (env.length === 0) { env.push([util.randomId(), '', '']); } this.setState({ env: env }); metrics.track('Removed Environment Variable'); }, handleDeleteContainer: function () { dialog.showMessageBox({ message: 'Are you sure you want to delete this container?', buttons: ['Delete', 'Cancel'] }, index => { if (index === 0) { metrics.track('Deleted Container', { from: 'settings', type: 'existing' }); containerActions.destroy(this.props.container.Name); } }); }, render: function () { if (!this.props.container) { return false; } var clipboardStatus; var willBeRenamedAs; var btnSaveName = ( Save ); if (this.state.slugName) { willBeRenamedAs = (

Will be renamed as: {this.state.slugName}

); btnSaveName = ( Save ); } else if (this.state.nameError) { willBeRenamedAs = (

{this.state.nameError}

); } if (this.state.copiedId) { clipboardStatus = (

Copied to Clipboard

); } let containerInfo = (

Container Info

ID
Copy {clipboardStatus}
NAME
{btnSaveName} {willBeRenamedAs}
); let vars = _.map(this.state.env, (kvp, index) => { let [id, key, val] = kvp; let icon; if (index === this.state.env.length - 1) { icon = ; } else { icon = ; } return (
{icon}
); }); return (
{containerInfo}

Environment Variables

KEY
VALUE
{vars}
Save

Delete Container

Delete Container
); } }); module.exports = ContainerSettingsGeneral;