<commit_before>var $importerResults = $('.importer-results');

<% if @json_document_importer.imported_claims.any? %>
	$importerResults.html(
      '<div class="results-body import-success">' +
        '<h4>Successfully imported <%= pluralize(@json_document_importer.imported_claims.count, "new claim") %> in draft state</h4>' +
      '</div>'
  );
	<% @json_document_importer.imported_claims.each do |imported_claim| %>
		<% present(imported_claim) do |claim| %>
			$('table.claims_table').prepend(
        '<tr>' +
          '<td><%= link_to (claim.case_number.blank? ? "not-provided" : claim.case_number), advocates_claim_path(claim) %></td>' +
          <% if current_user.persona.admin? %>
            '<td><%= claim.advocate.name %></td>' +
          <% end %>
          '<td><%= claim.defendant_names %></td>' +
          '<td><%= claim.total_inc_vat %></td>' +
          '<td><%= claim.amount_assessed %></td>' +
          '<td><%= claim.state.humanize %></td>' +
          '<td><%= claim.last_submitted_at %></td>' +
          '<td><span class="none">None</span></td>' +
        '</tr>'
      );
		<% end %>
	<% end %>
  $('#importer')
    .removeClass('has-errors')
    .find('form')
      .addClass('no-file-selected')
      .find('.file-upload-name')
        .empty();
<% else %>
	$importerResults.find('.import-success').remove();
<% end %>

<% if @json_document_importer.failed_imports.any? %>
	$importerResults.append(
      '<div class="results-body import-failed">' +
        '<h4>There were errors in the following <%= pluralize(@json_document_importer.failed_imports.count, "claim") %> and these were not imported</h4>' +
        '<ul>' +
        <% @json_document_importer.failed_imports.each do |fail| %>
          '<li><%= fail["claim"]["case_number"] %></li>' +
        <% end %>
        '</ul>' +
      '</div>'
    );
  $('#importer').addClass('has-errors');
<% else %>
  $importerResults.find('.import-failed').remove();
<% end %>

<% if @json_document_importer.failed_schema_validation.any? %>
  $importerResults.append(
    '<div class="results-body import-failed">' +
      '<h4>The following <%= pluralize(@json_document_importer.failed_schema_validation.count, "claim was") %> formatted incorrectly in the uploaded document</h4>' +
      '<ul>' +
      <% @json_document_importer.failed_schema_validation.each do |fail| %>
        '<li><%= fail["claim"]["case_number"] %></li>' +
      <% end %>
      '</ul>' +
      '<p>Please contact your case management system vendor.</p>' +
    '</div>'
  );
  $('#importer').addClass('has-errors');
<% else %>
	$importerResults.find('.import-schema-failed').remove();
<% end %>

// empty the field where format errors would occur, regardless of the result here, incase a previous error is shown
$('.claims-importer .errors').empty();
<commit_msg>GA: Add claims importer events<commit_after>var $importerResults = $('.importer-results');

<% if @json_document_importer.imported_claims.any? %>
  ga('send', 'event', 'claims-importer', 'imported', '<%= @json_document_importer.imported_claims.count %>');

	$importerResults.html(
      '<div class="results-body import-success">' +
        '<h4>Successfully imported <%= pluralize(@json_document_importer.imported_claims.count, "new claim") %> in draft state</h4>' +
      '</div>'
  );
	<% @json_document_importer.imported_claims.each do |imported_claim| %>
		<% present(imported_claim) do |claim| %>
			$('table.claims_table').prepend(
        '<tr>' +
          '<td><%= link_to (claim.case_number.blank? ? "not-provided" : claim.case_number), advocates_claim_path(claim) %></td>' +
          <% if current_user.persona.admin? %>
            '<td><%= claim.advocate.name %></td>' +
          <% end %>
          '<td><%= claim.defendant_names %></td>' +
          '<td><%= claim.total_inc_vat %></td>' +
          '<td><%= claim.amount_assessed %></td>' +
          '<td><%= claim.state.humanize %></td>' +
          '<td><%= claim.last_submitted_at %></td>' +
          '<td><span class="none">None</span></td>' +
        '</tr>'
      );
		<% end %>
	<% end %>
  $('#importer')
    .removeClass('has-errors')
    .find('form')
      .addClass('no-file-selected')
      .find('.file-upload-name')
        .empty();
<% else %>
	$importerResults.find('.import-success').remove();
<% end %>

<% if @json_document_importer.failed_imports.any? %>
  ga('send', 'event', 'claims-importer', 'failed', '<%= @json_document_importer.failed_imports.count %>');

	$importerResults.append(
      '<div class="results-body import-failed">' +
        '<h4>There were errors in the following <%= pluralize(@json_document_importer.failed_imports.count, "claim") %> and these were not imported</h4>' +
        '<ul>' +
        <% @json_document_importer.failed_imports.each do |fail| %>
          '<li><%= fail["claim"]["case_number"] %></li>' +
        <% end %>
        '</ul>' +
      '</div>'
    );
  $('#importer').addClass('has-errors');
<% else %>
  $importerResults.find('.import-failed').remove();
<% end %>

<% if @json_document_importer.failed_schema_validation.any? %>
  ga('send', 'event', 'claims-importer', 'validation-failed', '<%= @json_document_importer.failed_schema_validation.count %>');

  $importerResults.append(
    '<div class="results-body import-failed">' +
      '<h4>The following <%= pluralize(@json_document_importer.failed_schema_validation.count, "claim was") %> formatted incorrectly in the uploaded document</h4>' +
      '<ul>' +
      <% @json_document_importer.failed_schema_validation.each do |fail| %>
        '<li><%= fail["claim"]["case_number"] %></li>' +
      <% end %>
      '</ul>' +
      '<p>Please contact your case management system vendor.</p>' +
    '</div>'
  );
  $('#importer').addClass('has-errors');
<% else %>
	$importerResults.find('.import-schema-failed').remove();
<% end %>

// empty the field where format errors would occur, regardless of the result here, incase a previous error is shown
$('.claims-importer .errors').empty();

{'fraction_non_alphanumeric': 0.207770551942638, 'fraction_numerical': 0.002001000500250125, 'mean_word_length': 3.4200442151805452, 'pattern_counts': {'":': 0, '<': 152, '<?xml version=': 0, '>': 152, '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': '1560835', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1946, 'n_words': 339}