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 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: [], 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 }); let name = containerStore.generateName(this.props.image.name); let repo = this.props.image.namespace === 'library' ? this.props.image.name : this.props.image.namespace + '/' + this.props.image.name; containerActions.run(name, repo, this.state.chosenTag); 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); 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); }, handleRepoClick: function () { var repoUri = 'https://registry.hub.docker.com/'; if (this.props.image.namespace === 'library') { repoUri = repoUri + '_/' + this.props.image.name; } else { repoUri = repoUri + 'u/' + 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 = (