import $ from 'jquery'; import React from 'react/addons'; import Router from 'react-router'; import shell from 'shell'; import RetinaImage from 'react-retina-image'; import metrics from '../utils/MetricsUtil'; import containerActions from '../actions/ContainerActions'; import imageActions from '../actions/ImageActions'; import containerStore from '../stores/ContainerStore'; import tagStore from '../stores/TagStore'; import tagActions from '../actions/TagActions'; import numeral from 'numeral'; var ImageCard = React.createClass({ mixins: [Router.Navigation], getInitialState: function () { return { tags: this.props.tags || [], chosenTag: this.props.chosenTag || 'latest' }; }, componentDidMount: function () { tagStore.listen(this.update); }, componentWillUnmount: function () { tagStore.unlisten(this.update); }, update: function () { let repo = this.props.image.namespace + '/' + this.props.image.name; let state = tagStore.getState(); if (this.state.tags.length && !state.tags[repo]) { $(this.getDOMNode()).find('.tag-overlay').fadeOut(300); } this.setState({ loading: tagStore.getState().loading[repo] || false, tags: tagStore.getState().tags[repo] || [] }); }, handleTagClick: function (tag) { this.setState({ chosenTag: tag }); var $tagOverlay = $(this.getDOMNode()).find('.tag-overlay'); $tagOverlay.fadeOut(300); metrics.track('Selected Image Tag'); }, handleClick: function () { metrics.track('Created Container', { from: 'search', private: this.props.image.is_private, official: this.props.image.namespace === 'library', userowned: this.props.image.is_user_repo, recommended: this.props.image.is_recommended, local: this.props.image.is_local || false }); let name = containerStore.generateName(this.props.image.name); let localImage = this.props.image.is_local || false; let repo = (this.props.image.namespace === 'library' || this.props.image.namespace === 'local') ? this.props.image.name : this.props.image.namespace + '/' + this.props.image.name; containerActions.run(name, repo, this.state.chosenTag, localImage); this.transitionTo('containerHome', {name}); }, handleMenuOverlayClick: function () { let $menuOverlay = $(this.getDOMNode()).find('.menu-overlay'); $menuOverlay.fadeIn(300); }, handleCloseMenuOverlay: function () { var $menuOverlay = $(this.getDOMNode()).find('.menu-overlay'); $menuOverlay.fadeOut(300); }, handleTagOverlayClick: function () { let $tagOverlay = $(this.getDOMNode()).find('.tag-overlay'); $tagOverlay.fadeIn(300); let localImage = this.props.image.is_local || false; if (localImage) { tagActions.localTags(this.props.image.namespace + '/' + this.props.image.name, this.props.tags); } else { tagActions.tags(this.props.image.namespace + '/' + this.props.image.name); } }, handleCloseTagOverlay: function () { let $menuOverlay = $(this.getDOMNode()).find('.menu-overlay'); $menuOverlay.hide(); var $tagOverlay = $(this.getDOMNode()).find('.tag-overlay'); $tagOverlay.fadeOut(300); }, handleDeleteImgClick: function (image) { if (this.state.chosenTag && !this.props.image.inUse) { imageActions.destroy(image.RepoTags[0].split(':')[0] + ':' + this.state.chosenTag); } }, handleRepoClick: function () { var repoUri = 'https://hub.docker.com/'; if (this.props.image.namespace === 'library') { repoUri = repoUri + '_/' + this.props.image.name; } else { repoUri = repoUri + 'r/' + this.props.image.namespace + '/' + this.props.image.name; } shell.openExternal(repoUri); }, render: function () { var self = this; var name; if (this.props.image.namespace === 'library') { name = (
To delete, remove all containers
using the above image