<commit_before>{% extends "base.html" %}

{% block content %}
<div class="content row">
  <div class="col-lg-6">
    <ol class="breadcrumb">
      {% for path in folder_info.path_collection.entries %}
      <li><a href="?folder={{ path.id }}">{{ path.name }}</a></li>
      {% endfor %}
      <li class="active">{{ folder_info.name }}</li>
    </ol>
    <form method="POST" enctype="multipart/form-data" id="upload">{% csrf_token %}
      <input type="hidden" name="folder" value="{{ folder_info.id }}">
      <input type="hidden" name="filename" value="">
      <input type="file" name="file" class="hidden">
    </form>
    <table class="table table-bordered">
      <thead>
        <tr><th>Contract</th><th>Metadata</th></tr>
      </thead>
      <tbody>
        {% for item in items_info %}
        <tr>
          <td>
            {% if item.type == "folder" %}
            <a href="?folder={{ item.id }}">{{ item.name }}</a>
            {% else %}
            {{ item.name }}
            <div class="btn-group pull-right">
              <button class="file-view btn btn-sm btn-info" data-id="{{ item.id }}" title="View"><i class="glyphicon glyphicon-eye-open"></i> View</button>
              <a class="btn btn-sm btn-success" href="{% url 'metadata_download' item.id %}" title="Download"><i class="glyphicon glyphicon-download-alt"></i> Download</a>
            </div>
            {% endif %}
          </td>
          <td>
            {% if item.type == "file" %}
            <div class="btn-group pull-right">
              {% if item.metadata %}
              <button class="file-view btn btn-sm btn-info" data-id="{{ item.metadata.id }}" title="View"><i class="glyphicon glyphicon-eye-open"></i> View</button>
              <a class="btn btn-sm btn-success" href="{% url 'metadata_download' item.metadata.id %}" title="Download"><i class="glyphicon glyphicon-download-alt"></i> Download</a>
              {% else %}
              <button class="file-selector btn btn-sm btn-primary" data-filename="{{ item.filename }}_metadata"><i class="glyphicon glyphicon-plus"></i> Add</button>
              {% endif %}
            </div>
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  <div class="col-lg-6">
    {% if metadata %}
    <h2>Metadata</h2>
    <table class="table table-striped">
      <tbody>
        {% for row in metadata %}
        <tr>
          {% for item in row %}
          <td>{{ item }}</td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    <div id="progress" class="text-center" style="display:none;">
      <p class="lead">Opening…</p>
      <div class="progress progress-striped active">
        <div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
          <span class="sr-only">100% Complete</span>
        </div>
      </div>
    </div>
    <p id="error" class="hidden alert-danger" style="display:none;"></p>
    <iframe style="display:none;width: 100%;height: 500px;margin: auto;border: none;" src="" seamless="seamless" allowfullscreen="true"></iframe>
  </div>
</div>
{% endblock %}

{% block scripts %}{{ block.super }}
<script type="text/javascript">
  /* Error Function */
  function showError() {
    $('#progress').toggle();
    $('#error').text('Error viewing file').show();
  }

  /* Form Submit Events */
  function fetchSession(documentID) {
    var data = new FormData();
    data.append('document_id', documentID);

    $.ajax({
      type: 'POST',
      contentType: false,
      processData: false,
      data: data,
      dataType: 'json',
      url: '{% url "box-view-session" %}',
      error: function (data) {
        console.log(data);
        showError();
      },
      statusCode: {
        200: function(data) {
          console.log(data);
          $('#progress').toggle();
          $('#error').hide();
          $('iframe').attr('src', data.urls.view).delay(1000).fadeIn('slow');
        },
        202: function() {
          fetchSession(documentID);
        }
      }
    });
  }

  $(function(){
    $(".file-selector").click(function(e){
      e.preventDefault();
      $("input[name='filename']").val($(this).data('filename'));
      $("input[name='file']").click();
    });
    $("input[name='file']").change(function(e){
      $("#upload").submit();
    });
    // Box.com View API
    $(".file-view").click(function(e){
      e.preventDefault();
      $('button').blur();
      $('#progress').toggle('fast');
      var data = new FormData();
      data.append('file_id', $(this).data('id'));
      $.ajax({
        type: 'POST',
        contentType: false,
        processData: false,
        data: data,
        dataType: 'json',
        url: '{% url "box-view-file" %}',
        error: function (data) {
            console.log(data);
            showError();
        }
      }).done(function (data) {
        console.log('Document ID is: ' + data.id);
        fetchSession(data.id);
      });
    });
  });
</script>
{% endblock %}
<commit_msg>Folder view switch<commit_after>{% extends "base.html" %}

{% block content %}
<div class="content row">
  <div class="col-lg-6">
    <div class="row">
      <div class="col-lg-11">
        <ol class="breadcrumb">
          {% for path in folder_info.path_collection.entries %}
          <li><a href="?folder={{ path.id }}">{{ path.name }}</a></li>
          {% endfor %}
          <li class="active">{{ folder_info.name }}</li>
        </ol>
      </div>
      <div class="col-lg-1">
        <button data-id="{{ folder_info.id }}" class="switch btn btn-sm btn-info pull-right">Box</button>
      </div>
    </div>
    <div class="row folder">
      <form method="POST" enctype="multipart/form-data" id="upload">{% csrf_token %}
        <input type="hidden" name="folder" value="{{ folder_info.id }}">
        <input type="hidden" name="filename" value="">
        <input type="file" name="file" class="hidden">
      </form>
      <table class="table table-bordered">
        <thead>
          <tr><th>Contract</th><th>Metadata</th></tr>
        </thead>
        <tbody>
          {% for item in items_info %}
          <tr>
            <td>
              {% if item.type == "folder" %}
              <a href="?folder={{ item.id }}">{{ item.name }}</a>
              {% else %}
              {{ item.name }}
              <div class="btn-group pull-right">
                <button class="file-view btn btn-sm btn-info" data-id="{{ item.id }}" title="View"><i class="glyphicon glyphicon-eye-open"></i> View</button>
                <a class="btn btn-sm btn-success" href="{% url 'metadata_download' item.id %}" title="Download"><i class="glyphicon glyphicon-download-alt"></i> Download</a>
              </div>
              {% endif %}
            </td>
            <td>
              {% if item.type == "file" %}
              <div class="btn-group pull-right">
                {% if item.metadata %}
                <button class="file-view btn btn-sm btn-info" data-id="{{ item.metadata.id }}" title="View"><i class="glyphicon glyphicon-eye-open"></i> View</button>
                <a class="btn btn-sm btn-success" href="{% url 'metadata_download' item.metadata.id %}" title="Download"><i class="glyphicon glyphicon-download-alt"></i> Download</a>
                {% else %}
                <button class="file-selector btn btn-sm btn-primary" data-filename="{{ item.filename }}_metadata"><i class="glyphicon glyphicon-plus"></i> Add</button>
                {% endif %}
              </div>
              {% endif %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    <div class="row folder" style="display:none;">
      <iframe class="folder-view" style="width: 100%;height: 500px;margin: auto;border: none;" src="" seamless="seamless" allowfullscreen="true"></iframe>
    </div>
  </div>
  <div class="col-lg-6">
    {% if metadata %}
    <h2>Metadata</h2>
    <table class="table table-striped">
      <tbody>
        {% for row in metadata %}
        <tr>
          {% for item in row %}
          <td>{{ item }}</td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    <div id="progress" class="text-center" style="display:none;">
      <p class="lead">Opening…</p>
      <div class="progress progress-striped active">
        <div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
          <span class="sr-only">100% Complete</span>
        </div>
      </div>
    </div>
    <p id="error" class="hidden alert-danger" style="display:none;"></p>
    <iframe class="view" style="display:none;width: 100%;height: 500px;margin: auto;border: none;" src="" seamless="seamless" allowfullscreen="true"></iframe>
  </div>
</div>
{% endblock %}

{% block scripts %}{{ block.super }}
<script type="text/javascript">
  /* Error Function */
  function showError() {
    $('#progress').toggle();
    $('#error').text('Error viewing file').show();
  }

  /* Form Submit Events */
  function fetchSession(documentID) {
    var data = new FormData();
    data.append('document_id', documentID);

    $.ajax({
      type: 'POST',
      contentType: false,
      processData: false,
      data: data,
      dataType: 'json',
      url: '{% url "box-view-session" %}',
      error: function (data) {
        console.log(data);
        showError();
      },
      statusCode: {
        200: function(data) {
          console.log(data);
          $('#progress').toggle();
          $('#error').hide();
          $('iframe.view').attr('src', data.urls.view).delay(1000).fadeIn('slow');
        },
        202: function() {
          fetchSession(documentID);
        }
      }
    });
  }

  $(function(){
    $(".file-selector").click(function(e){
      e.preventDefault();
      $("input[name='filename']").val($(this).data('filename'));
      $("input[name='file']").click();
    });
    $("input[name='file']").change(function(e){
      $("#upload").submit();
    });
    // Box.com View API
    $(".file-view").click(function(e){
      e.preventDefault();
      $('button').blur();
      $('#progress').toggle('fast');
      var data = new FormData();
      data.append('file_id', $(this).data('id'));
      $.ajax({
        type: 'POST',
        contentType: false,
        processData: false,
        data: data,
        dataType: 'json',
        url: '{% url "box-view-file" %}',
        error: function (data) {
            console.log(data);
            showError();
        }
      }).done(function (data) {
        console.log('Document ID is: ' + data.id);
        fetchSession(data.id);
      });
    });
    $(".switch").click(function(e){
      e.preventDefault();
      $(".folder").toggle();
      if ($(".folder-view").attr("src") === ""){
        $(".folder-view").attr("src", "https://app.box.com/embed_widget/files/0/f/" + $(this).data("id"));
      }
    });
  });
</script>
{% endblock %}

{'fraction_non_alphanumeric': 0.20530159588855829, 'fraction_numerical': 0.006852402849156974, 'mean_word_length': 2.257562408223201, 'pattern_counts': {'":': 0, '<': 195, '<?xml version=': 0, '>': 195, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2201653', 'n_tokens_mistral': 3602, 'n_tokens_neox': 3397, 'n_words': 689}