/* global $ */ import React, { PropTypes, Component } from 'react' import Metacode from './Metacode' import Permission from './Permission' // TODO use a callback instead of an import import Visualize from '../../Metamaps/Visualize' const inmaps = (topic) => { const inmapsArray = topic.get('inmaps') || [] const inmapsLinks = topic.get('inmapsLinks') || [] let html = '' if (inmapsArray.length < 6) { for (let i = 0; i < inmapsArray.length; i++) { const url = '/maps/' + inmapsLinks[i] html += '
  • ' + inmapsArray[i] + '
  • ' } } else { for (let i = 0; i < 5; i++) { const url = '/maps/' + inmapsLinks[i] html += '
  • ' + inmapsArray[i] + '
  • ' } const extra = inmapsArray.length - 5 html += '
  • See ' + extra + ' more...
  • ' for (let i = 5; i < inmapsArray.length; i++) { const url = '/maps/' + inmapsLinks[i] html += '
  • ' + inmapsArray[i] + '
  • ' } } return html } // TODO all of these should be largely turned into passed-in callbacks const bindShowCardListeners = (topic, ActiveMapper) => { $('.links .mapCount').unbind().click(function(event) { $('.mapCount .tip').toggle() $('.showcard .hoverTip').toggleClass('hide') }) $('.showcard').unbind('.hideTip').bind('click.hideTip', function() { $('.mapCount .tip').hide() $('.showcard .hoverTip').removeClass('hide') }) var originalText = $('.showMore').html() $('.mapCount .tip .showMore').unbind().toggle( function(event) { $('.extraText').toggleClass('hideExtra') $('.showMore').html('Show less...') }, function(event) { $('.extraText').toggleClass('hideExtra') $('.showMore').html(originalText) } ) } class Links extends Component { componentDidMount = () => { bindShowCardListeners(this.props.topic, this.props.ActiveMapper) } handleMetacodeClick = metacodeId => { this.props.updateTopic({ metacode_id: metacodeId }) Visualize.mGraph.plot() } render = () => { const { topic, ActiveMapper } = this.props const metacode = topic.getMetacode() return (
    {topic.get('user_name')}
    {topic.get('map_count').toString()}
    Click to see which maps topic appears on
      {inmaps(topic)}
    {topic.get('synapse_count').toString()}
    Click to see this topics synapses
    ) } } Links.propTypes = { topic: PropTypes.object, // backbone object ActiveMapper: PropTypes.object, updateTopic: PropTypes.func, metacodeSets: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string, metacodes: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.number, icon_path: PropTypes.string, // url name: PropTypes.string })) })) } export default Links