<commit_before>import React from 'react';
import Gravatar from 'components/common/Gravatar.react';
import Backbone from 'backbone';
import Bookmark from 'components/images/common/Bookmark.react';
import context from 'context';
import moment from 'moment';
import stores from 'stores';


// Note:
// -----
// pulled out of a defunct module called 'url', in history you can
// see it -> `troposphere/static/js/url.js`. This module was used
// for building internal, in-app links prior to the adoption of
// React-Router. When the Public Image Catalog was re-introduced,
// @lenards (me) carelessly added back the "Login to Launch"
// functionality without properly wiring in the internal URLs
//
// this is a stop-gap, but not a full fix
//
// FIXME: use React-Router Link objects or external link + push state
let buildImageUrl = function (model) {
    return '/application/images/' + model.id;
}

let buildLoginUrl = function () {
    return '/login'
}


export default React.createClass({
      displayName: "ImageLaunchCard",

      propTypes: {
        image: React.PropTypes.instanceOf(Backbone.Model).isRequired,
        onLaunch: React.PropTypes.func.isRequired
      },

      render: function () {
        var image = this.props.image;
        var versions = stores.ImageStore.getVersions(image.id);
        var type = stores.ProfileStore.get().get('icon_set');
        var loggedInUser = context.hasLoggedInUser();

        var iconSize = 145;
        // always use the Gravatar icons
        var icon = (
            <Gravatar hash={image.get('uuid_hash')} size={iconSize} type={type}/>
          );

        // Hide bookmarking on the public page
        var bookmark;
        if (loggedInUser) {
          bookmark = (
            <Bookmark image={image}/>
          );
        }
        if (versions) {
          var now = moment();
          version_arr = versions.filter(function(ver) {
              var end_date = ver.get('end_date');

              return end_date == null || end_date.isAfter(now);
          });
          versions = new Backbone.Collection(version_arr);
        }
        //When versions is 'not loaded' OR 'has length > 0', you can launch.
        var canLaunch = (versions !== null && versions.length !== 0) ? true : false;
        var button;
        if (loggedInUser) {
          button = (
            <button className='btn btn-primary launch-button'
                onClick={this.props.onLaunch}
                disabled={!canLaunch}>
              Launch
            </button>
          );
        } else {
            // Move this to using a more React-Router friendly approach
            var loginUrl = buildLoginUrl(),
                imageUrl = buildImageUrl(this.props.image),
                fullUrl = loginUrl + "?redirect_to=" + imageUrl +<commit_msg>Trickle-down Merge branch 'odd-owl'<commit_after>import React from 'react';
import Gravatar from 'components/common/Gravatar.react';
import Backbone from 'backbone';
import Bookmark from 'components/images/common/Bookmark.react';
import context from 'context';
import moment from 'moment';
import stores from 'stores';


// Note:
// -----
// pulled out of a defunct module called 'url', in history you can
// see it -> `troposphere/static/js/url.js`. This module was used
// for building internal, in-app links prior to the adoption of
// React-Router. When the Public Image Catalog was re-introduced,
// @lenards (me) carelessly added back the "Login to Launch"
// functionality without properly wiring in the internal URLs
//
// this is a stop-gap, but not a full fix
//
// FIXME: use React-Router Link objects or external link + push state
let buildImageUrl = function (model) {
    return '/application/images/' + model.id;
}

let buildLoginUrl = function () {
    return '/login'
}


export default React.createClass({
      displayName: "ImageLaunchCard",

      propTypes: {
        image: React.PropTypes.instanceOf(Backbone.Model).isRequired,
        onLaunch: React.PropTypes.func.isRequired
      },

      render: function () {
        var image = this.props.image;
        var versions = stores.ImageStore.getVersions(image.id);
        var type = stores.ProfileStore.get().get('icon_set');
        var loggedInUser = context.hasLoggedInUser();

        var iconSize = 145;
        // always use the Gravatar icons
        var icon = (
            <Gravatar hash={image.get('uuid_hash')} size={iconSize} type={type}/>
          );

        // Hide bookmarking on the public page
        var bookmark;
        if (loggedInUser) {
          bookmark = (
            <Bookmark image={image}/>
          );
        }
        if (versions) {
          var now = moment();
          var version_arr = versions.filter(function(ver) {
              var end_date = ver.get('end_date');

              return end_date == null || end_date.isAfter(now);
          });
          versions = new Backbone.Collection(version_arr);
        }
        //When versions is 'not loaded' OR 'has length > 0', you can launch.
        var canLaunch = (versions !== null && versions.length !== 0) ? true : false;
        var button;
        if (loggedInUser) {
          button = (
            <button className='btn btn-primary launch-button'
                onClick={this.props.onLaunch}
                disabled={!canLaunch}>
              Launch
            </button>
          );
        } else {
            // Move this to using a more React-Router friendly approach
            var loginUrl = buildLoginUrl(),
                imageUrl = buildImageUrl(this.props.image),
                fullUrl = loginUrl + "?redirect_to=" + imageUrl +
{'fraction_non_alphanumeric': 0.11324103656372027, 'fraction_numerical': 0.001774937877174299, 'mean_word_length': 2.2255294791070406, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20088', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1509, 'n_words': 472}