diff --git a/frontend/src/components/TopicCard/Links.js b/frontend/src/components/TopicCard/Links.js new file mode 100644 index 00000000..a5442812 --- /dev/null +++ b/frontend/src/components/TopicCard/Links.js @@ -0,0 +1,73 @@ +import React from 'react' + +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 +} + +const Links = (props) => { + const { topic } = props + const topicId = topic.isNew() ? topic.cid : topic.id // TODO should we really be using cid here?!? + const permission = topic.get('permission') + // the code for this is stored in /views/main/_metacodeOptions.html.erb + const metacodeSelectHTML = $('#metacodeOptions').html() + + return ( +
    +
    +
    + {topic.getMetacode().get('name')} +
    +
    +
    +
    +
    +
    + +
    {topic.get('user_name')}
    +
    +
    +
    + {topic.get('map_count').toString()} +
    Click to see which maps topic appears on
    +
      {inmaps(props.topic)}
    +
    + +
    + {topic.get('synapse_count').toString()} +
    Click to see this topics synapses
    +
    +
    +
    +
    + ) +} + +/* + * Links.propTypes = { + * topic: PropTypes.object, // backbone object + * } + */ + +export default Links diff --git a/frontend/src/components/TopicCard/Title.js b/frontend/src/components/TopicCard/Title.js new file mode 100644 index 00000000..4981b561 --- /dev/null +++ b/frontend/src/components/TopicCard/Title.js @@ -0,0 +1,34 @@ +import React from 'react' +import { RIETextArea } from 'riek' + +const Title = (props) => { + return ( + + { + const ENTER = 13 + if (e.which === ENTER) { + e.preventDefault() + props.onChange({ name: e.target.value }) + } + } + }} + /> + + ) +} + +/* + * Title.propTypes = { + * name: PropTypes.string, + * onChange: PropTypes.func + * } + */ + +export default Title diff --git a/frontend/src/components/TopicCard.js b/frontend/src/components/TopicCard/index.js similarity index 67% rename from frontend/src/components/TopicCard.js rename to frontend/src/components/TopicCard/index.js index d41b3720..f7d0e365 100644 --- a/frontend/src/components/TopicCard.js +++ b/frontend/src/components/TopicCard/index.js @@ -2,54 +2,20 @@ import React, { PropTypes, Component } from 'react' import { RIETextArea } from 'riek' -import Util from '../Metamaps/Util' +import Util from '../../Metamaps/Util' + +import Title from './Title' +import Links from './Links' + +const descHTML = (topic, ActiveMapper) => { + const authorized = topic.authorizeToEdit(ActiveMapper) + const descMarkdown = (topic.get('desc') === '' && authorized) + ? 'Click to add description...' + : topic.get('desc') + return Util.mdToHTML(descMarkdown) +} var funcs = { - buildObject: function(topic, ActiveMapper) { - var nodeValues = {} - var authorized = topic.authorizeToEdit(ActiveMapper) - var inmapsAr = topic.get('inmaps') || [] - var inmapsLinks = topic.get('inmapsLinks') || [] - nodeValues.inmaps = '' - if (inmapsAr.length < 6) { - for (let i = 0; i < inmapsAr.length; i++) { - const url = '/maps/' + inmapsLinks[i] - nodeValues.inmaps += '
  • ' + inmapsAr[i] + '
  • ' - } - } else { - for (let i = 0; i < 5; i++) { - const url = '/maps/' + inmapsLinks[i] - nodeValues.inmaps += '
  • ' + inmapsAr[i] + '
  • ' - } - const extra = inmapsAr.length - 5 - nodeValues.inmaps += '
  • See ' + extra + ' more...
  • ' - for (let i = 5; i < inmapsAr.length; i++) { - const url = '/maps/' + inmapsLinks[i] - nodeValues.inmaps += '
  • ' + inmapsAr[i] + '
  • ' - } - } - nodeValues.permission = topic.get('permission') - nodeValues.mk_permission = topic.get('permission').substring(0, 2) - nodeValues.map_count = topic.get('map_count').toString() - nodeValues.synapse_count = topic.get('synapse_count').toString() - nodeValues.id = topic.isNew() ? topic.cid : topic.id - nodeValues.metacode = topic.getMetacode().get('name') - nodeValues.metacode_class = 'mbg' + topic.get('metacode_id') - nodeValues.imgsrc = topic.getMetacode().get('icon') - nodeValues.name = topic.get('name') - nodeValues.userid = topic.get('user_id') - nodeValues.username = topic.get('user_name') - nodeValues.userimage = topic.get('user_image') - nodeValues.date = topic.getDate() - // the code for this is stored in /views/main/_metacodeOptions.html.erb - nodeValues.metacode_select = $('#metacodeOptions').html() - nodeValues.desc_nil = 'Click to add description...' - nodeValues.desc_markdown = (topic.get('desc') === '' && authorized) - ? nodeValues.desc_nil - : topic.get('desc') - nodeValues.desc_html = Util.mdToHTML(nodeValues.desc_markdown) - return nodeValues - }, bindShowCardListeners: function(topic, ActiveMapper) { var authorized = topic.authorizeToEdit(ActiveMapper) var selectingMetacode = false @@ -134,6 +100,12 @@ var funcs = { $('.metacodeSelect li li').click(metacodeLiClick) } + var hidePermissionSelect = function() { + selectingPermission = false + $('.showcard .yourTopic .mapPerm').removeClass('minimize') // this line flips the pull up arrow to a drop down arrow + $('.showcard .permissionSelect').remove() + } + var permissionLiClick = function(event) { selectingPermission = false var permission = $(this).attr('class') @@ -141,8 +113,8 @@ var funcs = { permission: permission, defer_to_map_id: null }) - $('.showcard .mapPerm').removeClass('co pu pr minimize').addClass(permission.substring(0, 2)) - $('.showcard .permissionSelect').remove() + $('.showcard .mapPerm').removeClass('co pu pr').addClass(permission.substring(0, 2)) + hidePermissionSelect() } var openPermissionSelect = function(event) { @@ -160,12 +132,6 @@ var funcs = { event.stopPropagation() } } - - var hidePermissionSelect = function() { - selectingPermission = false - $('.showcard .yourTopic .mapPerm').removeClass('minimize') // this line flips the pull up arrow to a drop down arrow - $('.showcard .permissionSelect').remove() - } // ability to change permission var selectingPermission = false if (topic.authorizePermissionChange(ActiveMapper)) { @@ -276,7 +242,6 @@ class ReactTopicCard extends Component { render = () => { const { topic, ActiveMapper, removeLink } = this.props const { linkEdit, embedlyLinkLoaded, embedlyLinkStarted, embedlyLinkError } = this.state - const values = funcs.buildObject(topic, ActiveMapper) var authorizedToEdit = topic.authorizeToEdit(ActiveMapper) let classname = 'permission' @@ -289,58 +254,16 @@ class ReactTopicCard extends Component { if (topic.authorizePermissionChange(ActiveMapper)) classname += ' yourTopic' const hasAttachment = topic.get('link') && topic.get('link') !== '' + const topicId = topic.isNew() ? topic.cid : topic.id return (
    -
    - - { - const ENTER = 13 - if (e.which === ENTER) { - e.preventDefault() - this.props.updateTopic({ name: e.target.value }) - } - } - }} - /> - -
    -
    -
    - {values.metacode} -
    -
    -
    -
    -
    -
    - -
    {values.username}
    -
    -
    -
    - {values.map_count} -
    Click to see which maps topic appears on
    -
      {values.inmaps}
    -
    - -
    - {values.synapse_count} -
    Click to see this topics synapses
    -
    -
    -
    -
    +
    + + <Links topic={topic} /> <div className="scroll"> <div className="desc"> <span className="best_in_place best_in_place_desc" - dangerouslySetInnerHTML={{__html: values.desc_html}} + dangerouslySetInnerHTML={{ __html: descHTML(topic, ActiveMapper) }} > </span> <div className="clearfloat"></div>