<commit_before>Augury.Views.Tests.New = Backbone.View.extend(
  initialize: ->
    @samples = new Augury.Collections.Samples()
    @samples.bind 'add', @showSamples

  events:
    'click button#create-endpoint-message': 'createMessage'
    'select2-selected select#endpoint-message-samples': 'loadSample'
    'click button#cancel': 'cancel'

  render: ->
    @$el.html JST['admin/templates/tests/new']()
    @initializeAceEditor()
    @resetSamples()
    @$('select#endpoint-message-samples').select2()
    @

  resetSamples: ->
    $('#endpoint-message-samples').empty()
    @samples.fetch()

  showSamples: (sample) ->
    sampleMessage = sample.keys()[0]
    $('#endpoint-message-samples').
      append($('<option></option>').
                val(sampleMessage).html(sampleMessage))

  loadSample: (e) ->
    new Augury.Models.Sample(id: $(e.target).val()).
      fetch().
      done((sample) => @showSample(@editor, sample))

  showSample: (editor, sample) ->
    editor.getSession().setValue JSON.stringify(sample, null, 4)

  createMessage: (e) ->
    e.preventDefault()
    message = new Augury.Models.Message()
    message.save { source: 'test', message: @messageValueToJSON() },
      success: @created,
      error: @displayErrors

  created: (message) ->
    messageLink = $("<a></a>").
      html(message.get('id')).
      attr('href', "#{Augury.url}/messages/#{message.get('id')}")
    @$('#endpoint-last-generated-message').html messageLink
    Augury.Flash.success "The message was successfully inserted into Incoming queue."

  messageValueToJSON: ->
    JSON.parse @editor.getSession().getValue()

  initializeAceEditor: ->
    @editor = ace.edit @$el.find('#endpoint-message-editor')[0]
    @editor.setTheme 'ace/theme/chrome'
    @editor.getSession().setMode 'ace/mode/json'
    @editor.setShowPrintMargin false
    @editor

  cancel: (e) ->
    e.preventDefault()
    Backbone.history.navigate '/', trigger: true
)
<commit_msg>Uses internal link for the last generated message<commit_after>Augury.Views.Tests.New = Backbone.View.extend(
  initialize: ->
    @samples = new Augury.Collections.Samples()
    @samples.bind 'add', @showSamples

  events:
    'click button#create-endpoint-message': 'createMessage'
    'select2-selected select#endpoint-message-samples': 'loadSample'
    'click button#cancel': 'cancel'

  render: ->
    @$el.html JST['admin/templates/tests/new']()
    @initializeAceEditor()
    @resetSamples()
    @$('select#endpoint-message-samples').select2()
    @

  resetSamples: ->
    $('#endpoint-message-samples').empty()
    @samples.fetch()

  showSamples: (sample) ->
    sampleMessage = sample.keys()[0]
    $('#endpoint-message-samples').
      append($('<option></option>').
                val(sampleMessage).html(sampleMessage))

  loadSample: (e) ->
    new Augury.Models.Sample(id: $(e.target).val()).
      fetch().
      done((sample) => @showSample(@editor, sample))

  showSample: (editor, sample) ->
    editor.getSession().setValue JSON.stringify(sample, null, 4)

  createMessage: (e) ->
    e.preventDefault()
    message = new Augury.Models.Message()
    message.save { source: 'test', message: @messageValueToJSON() },
      success: @created,
      error: @displayErrors

  created: (message) ->
    messageLink = $("<a></a>").
      html(message.get('id')).
      attr('href', "/admin/integration/messages/#{message.get('id')}")
    @$('#endpoint-last-generated-message').html messageLink
    Augury.Flash.success "The message was successfully inserted into Incoming queue."

  messageValueToJSON: ->
    JSON.parse @editor.getSession().getValue()

  initializeAceEditor: ->
    @editor = ace.edit @$el.find('#endpoint-message-editor')[0]
    @editor.setTheme 'ace/theme/chrome'
    @editor.getSession().setMode 'ace/mode/json'
    @editor.setShowPrintMargin false
    @editor

  cancel: (e) ->
    e.preventDefault()
    Backbone.history.navigate '/', trigger: true
)

{'fraction_non_alphanumeric': 0.17272034544069087, 'fraction_numerical': 0.00254000508001016, 'mean_word_length': 3.542099192618224, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '9527', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1202, 'n_words': 215}