<commit_before>require('./TabbedSourceView.scss')

React = require('react')
reqwest = require('reqwest')
normalizeReferences = require('./normalizeReferences')
{button, div, textarea} = React.DOM


module.exports = React.createClass
  getInitialState: ->
    tab: null
    sourceCode: null

  getDefaultProps: ->
    files: []
    sourceFiles: []

  componentDidMount: ->
    @loadSourceCode()

  componentDidUpdate: ->
    @loadSourceCode() unless @state.sourceCode?

  render: ->
    div {className: 'cg-Specimen-TabbedSourceView'},
      if @props.sourceFiles.length > 1
        @props.sourceFiles.map (file, i) =>
          button
            className: "cg-Specimen-TabbedSourceView-tab #{'active' if i is @state.tab}"
            key: i
            'data-tab-id': i
            onClick: @selectTab
            file.target

      if @state.tab?
        textarea
          className: 'cg-Specimen-TabbedSourceView-source'
          value: if @state.sourceCode? then @state.sourceCode else 'Loading …'
          readOnly: true

  selectTab: (evt) ->
    nextTab = +evt.currentTarget.getAttribute('data-tab-id')
    @setState
      sourceCode: null
      tab: if nextTab is @state.tab then null else nextTab

  loadSourceCode: ->
    return unless @state.tab?

    file = @props.sourceFiles[@state.tab]

    requests = [reqwest({url: file.source, type: 'text', headers: {Accept: 'text/plain,*/*'}})]
    requests.push(reqwest({url: file.template, type: 'text', headers: {Accept: 'text/plain,*/*'}})) if file.template?

    Promise.all(requests)
      .then((res) =>
        content = res.map((d) -> d.responseText)
        sourceCode = parseSourceCode(content...)
        @setState sourceCode: normalizeReferences(@props.rootPath, @props.files, sourceCode)
      )
      .catch (res) =>
        @setState<commit_msg>Show full files in tabbed source view, not templated files<commit_after>require('./TabbedSourceView.scss')

React = require('react')
reqwest = require('reqwest')
normalizeReferences = require('./normalizeReferences')
{button, div, textarea} = React.DOM


module.exports = React.createClass
  getInitialState: ->
    tab: null
    sourceCode: null

  getDefaultProps: ->
    files: []
    sourceFiles: []

  componentDidMount: ->
    @loadSourceCode()

  componentDidUpdate: ->
    @loadSourceCode() unless @state.sourceCode?

  render: ->
    div {className: 'cg-Specimen-TabbedSourceView'},
      if @props.sourceFiles.length > 1
        @props.sourceFiles.map (file, i) =>
          button
            className: "cg-Specimen-TabbedSourceView-tab #{'active' if i is @state.tab}"
            key: i
            'data-tab-id': i
            onClick: @selectTab
            file.target

      if @state.tab?
        textarea
          className: 'cg-Specimen-TabbedSourceView-source'
          value: if @state.sourceCode? then @state.sourceCode else 'Loading …'
          readOnly: true

  selectTab: (evt) ->
    nextTab = +evt.currentTarget.getAttribute('data-tab-id')
    @setState
      sourceCode: null
      tab: if nextTab is @state.tab then null else nextTab

  loadSourceCode: ->
    return unless @state.tab?

    file = @props.sourceFiles[@state.tab]

    requests = [reqwest({url: file.source, type: 'text', headers: {Accept: 'text/plain,*/*'}})]

    # Currently disabled, we only show whole files
    # requests.push(reqwest({url: file.template, type: 'text', headers: {Accept: 'text/plain,*/*'}})) if file.template?

    Promise.all(requests)
      .then((res) =>
        content = res.map((d) -> d.responseText)
        sourceCode = parseSourceCode(content...)
        @setState sourceCode: normalizeReferences(@props.rootPath, @props.files, sourceCode)
      )
      .catch (res) =>
        @setState
{'fraction_non_alphanumeric': 0.13761713520749666, 'fraction_numerical': 0.000535475234270415, 'mean_word_length': 2.796747967479675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '7388064', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1123, 'n_words': 257}