<commit_before>NodeInspectorView = React.createFactory require './node-inspector-view'
LinkInspectorView = React.createFactory require './link-inspector-view'
LinkValueInspectorView = React.createFactory require './link-value-inspector-view'
NodeValueInspectorView = React.createFactory require './node-value-inspector-view'
LinkRelationInspectorView = React.createFactory require './relation-inspector-view'
NodeRelationInspectorView = React.createFactory require './relation-inspector-view'
SimulationInspectorView   = React.createFactory require './simulation-inspector-view'


{div, i, span} = React.DOM

ToolButton = React.createFactory React.createClass
  displayName: 'toolButton'
  render: ->
    name = @props.name
    onClick = =>
      @props.onClick(@props.name) if @props.onClick

    classes = "icon-codap-#{name} tool-button"
    classes = "#{classes} selected" if @props.selected
    classes = "#{classes} disabled" if @props.disabled
    (div {className: classes, onClick: onClick})

ToolPanel = React.createFactory React.createClass
  displayName: 'toolPanel'

  buttonData: [
      {name: "styles", simple: true, shows: "design",'enabled': ['node','link'] }
      {name: "values", simple: false, shows: "value", 'enabled': ['node'] }
      {name: "qualRel", simple: false, shows: "relations",'enabled': ['node']}
      {name: "options",  simple: true, shows: "simulation", 'enabled': ['nothing'] }
    ]

  isDisabled: (button) ->
    return false if _.includes(button.enabled, 'nothing')
    return false if _.includes(button.enabled, 'node') and @props.node
    return false if _.includes(button.enabled, 'link') and @props.link
    return true

  buttonProps: (button) ->
    props =
      name:     button.name
      shows:    button.shows
      selected: false
      disabled: @isDisabled(button)

    unless @isDisabled(button)
      props.onClick = =>
        @select button.name
      props.selected = @props.nowShowing is button.shows

    props

  select: (name) ->
    button = _.find @buttonData, {name: name}
    if button
      if @props.nowShowing isnt button.shows
        @props.onNowShowing(button.shows)
      else
        @props.onNowShowing(null)

  render: ->
    buttons = @buttonData.slice 0
    if @props.diagramOnly
      buttons = _.filter buttons, (button) -> button.simple
    buttonsView = _.map buttons, (button) =>
      props = @buttonProps(button)
      (ToolButton props)

    (div {className: 'tool-panel'}, buttonsView)



module.exports = React.createClass

  displayName: 'InspectorPanelView'

  getInitialState: ->
    nowShowing: null

  setShowing: (item) ->
    @setState(nowShowing: item)

  renderSimulationInspector: ->
    (SimulationInspectorView {})

  renderDesignInspector: ->
    if @props.node
      (NodeInspectorView {
        node: @props.node
        onNodeChanged: @props.onNodeChanged
        onNodeDelete: @props.onNodeDelete
        palette: @props.palette
      })
    else if @props.link
      (LinkInspectorView {link: @props.link,  graphStore: @props.graphStore})

  renderValueInspector: ->
    if @props.node
      (NodeValueInspectorView {node: @props.node, graphStore: @props.graphStore})
    else if @props.link
      (LinkValueInspectorView {link:@props.link})

  renderRelationInspector: ->
    if @props.node
      (NodeRelationInspectorView {node:@props.node, graphStore: @props.graphStore})
    else if @props.link
      (LinkRelationInspectorView {link:@props.link, graphStore: @props.graphStore})


  renderInspectorPanel: ->
    view = switch @state.nowShowing
      when 'simulation' then @renderSimulationInspector()
      when 'design'     then @renderDesignInspector()
      when 'value'      then @renderValueInspector()
      when 'relations'  then @renderRelationInspector()

    (div {className: "inspector-panel-content"},
      view
    )

  render: ->
    className = "inspector-panel"
    unless @state.nowShowing
      className = "#{className} collapsed"

    (div {className: className},
      (ToolPanel
        node: @props.node
        link: @props.link
        nowShowing: @state.nowShowing
        onNowShowing: @setShowing
        diagramOnly: @props.diagramOnly
      )
      @renderInspectorPanel()
    )
<commit_msg>Clicking outside the inspector panel should close it. It should not automatically reopen.<commit_after>NodeInspectorView = React.createFactory require './node-inspector-view'
LinkInspectorView = React.createFactory require './link-inspector-view'
LinkValueInspectorView = React.createFactory require './link-value-inspector-view'
NodeValueInspectorView = React.createFactory require './node-value-inspector-view'
LinkRelationInspectorView = React.createFactory require './relation-inspector-view'
NodeRelationInspectorView = React.createFactory require './relation-inspector-view'
SimulationInspectorView   = React.createFactory require './simulation-inspector-view'


{div, i, span} = React.DOM

ToolButton = React.createFactory React.createClass
  displayName: 'toolButton'
  render: ->
    name = @props.name
    onClick = =>
      @props.onClick(@props.name) if @props.onClick

    classes = "icon-codap-#{name} tool-button"
    classes = "#{classes} selected" if @props.selected
    classes = "#{classes} disabled" if @props.disabled
    (div {className: classes, onClick: onClick})

ToolPanel = React.createFactory React.createClass
  displayName: 'toolPanel'

  buttonData: [
      {name: "styles", simple: true, shows: "design",'enabled': ['node','link'] }
      {name: "values", simple: false, shows: "value", 'enabled': ['node'] }
      {name: "qualRel", simple: false, shows: "relations",'enabled': ['node']}
      {name: "options",  simple: true, shows: "simulation", 'enabled': ['nothing'] }
    ]

  isDisabled: (button) ->
    return false if _.includes(button.enabled, 'nothing')
    return false if _.includes(button.enabled, 'node') and @props.node
    return false if _.includes(button.enabled, 'link') and @props.link
    return true

  buttonProps: (button) ->
    props =
      name:     button.name
      shows:    button.shows
      selected: false
      disabled: @isDisabled(button)

    unless @isDisabled(button)
      props.onClick = =>
        @select button.name
      props.selected = @props.nowShowing is button.shows

    props

  select: (name) ->
    button = _.find @buttonData, {name: name}
    if button
      if @props.nowShowing isnt button.shows
        @props.onNowShowing(button.shows)
      else
        @props.onNowShowing(null)

  render: ->
    buttons = @buttonData.slice 0
    if @props.diagramOnly
      buttons = _.filter buttons, (button) -> button.simple
    buttonsView = _.map buttons, (button) =>
      props = @buttonProps(button)
      (ToolButton props)

    (div {className: 'tool-panel'}, buttonsView)



module.exports = React.createClass

  displayName: 'InspectorPanelView'

  getInitialState: ->
    nowShowing: null

  setShowing: (item) ->
    @setState(nowShowing: item)

  renderSimulationInspector: ->
    (SimulationInspectorView {})

  renderDesignInspector: ->
    if @props.node
      (NodeInspectorView {
        node: @props.node
        onNodeChanged: @props.onNodeChanged
        onNodeDelete: @props.onNodeDelete
        palette: @props.palette
      })
    else if @props.link
      (LinkInspectorView {link: @props.link,  graphStore: @props.graphStore})

  renderValueInspector: ->
    if @props.node
      (NodeValueInspectorView {node: @props.node, graphStore: @props.graphStore})
    else if @props.link
      (LinkValueInspectorView {link:@props.link})

  renderRelationInspector: ->
    if @props.node
      (NodeRelationInspectorView {node:@props.node, graphStore: @props.graphStore})
    else if @props.link
      (LinkRelationInspectorView {link:@props.link, graphStore: @props.graphStore})

  # 2015-12-09 NP: Deselection makes inpector panel hide http://bit.ly/1ORBBp2
  componentWillReceiveProps: (nextProps) ->
    unless (nextProps.node or nextProps.link)
      @setState
        nowShowing: null

  renderInspectorPanel: ->
    view = switch @state.nowShowing
      when 'simulation' then @renderSimulationInspector()
      when 'design'     then @renderDesignInspector()
      when 'value'      then @renderValueInspector()
      when 'relations'  then @renderRelationInspector()

    (div {className: "inspector-panel-content"},
      view
    )

  render: ->
    className = "inspector-panel"
    unless @state.nowShowing
      className = "#{className} collapsed"

    (div {className: className},
      (ToolPanel
        node: @props.node
        link: @props.link
        nowShowing: @state.nowShowing
        onNowShowing: @setShowing
        diagramOnly: @props.diagramOnly
      )
      @renderInspectorPanel()
    )

{'fraction_non_alphanumeric': 0.12146118721461187, 'fraction_numerical': 0.0013698630136986301, 'mean_word_length': 3.32641975308642, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '4928079', 'n_tokens_mistral': 2677, 'n_tokens_neox': 2604, 'n_words': 605}