<commit_before><% provide(:title, "Project #{@project.name}") %>
<div class="row">
  <section class="col-md-6">
    <h3><%= @project.name %></h3>
    <p>
      <strong>Language:</strong> <%= @project.language %>
      <br><strong>Total scripts:</strong> <%= @project.scripts.count %>
      <% if current_user.admin? %><br><%= link_to 'Edit', edit_project_path(@project) %><% end %>
      <br><%= link_to raw("#{glyphicon 'download-alt'} Download ZIP"),
      download_project_path(@project),
      class: 'btn btn-primary' %>
    </p>
  </section>
  <section class="col-md-6" id="project_members">
    <h3>Members</h3>
    <% if @project.project_memberships.any? %>
      <ul class="panel_list clearfix">
        <% @project.project_memberships.each do |membership| %>
          <li class="panel panel-default with_avatar col-md-5<%= membership.write_access? ? "" : " membership_read_only invisible" %>">
            <aside class="avatar">
              <%= avatar_for membership.user %>
            </aside>
            <section class="content">
              <strong><%= link_to membership.user.name, membership.user %></strong>
              <% unless membership.position.blank? %><br><em><%= membership.position %></em><% end %>
              <% unless membership.write_access? %><br>(read only)<% end %>
              <% if current_user.admin? %>
                <br><%= link_to '(remove)', membership, method: :delete, data: { confirm: 'Are you sure?' } %>
              <% end %>
            </section>
          </li>
        <% end %>
      </ul>
    <% else %>
      none
    <% end %>
    <p><%= link_to "toggle read only", "#", id: "toggle_read_only" %></p>
    <% if current_user.admin? %>
      <p><hr>
      <%= form_with(model: @membership, class: "form-horizontal", local: true) do |form| %>
        <%= form.hidden_field :project_id, value: @project.id %>
        <div class="form-group">
          <%= form.label :user_id, "User", class: "control-label col-xs-2" %>
          <div class="col-xs-10">
            <%= form.collection_select :user_id, 
                                        User.where_not_member_of_project(@project),
                                        :id,
                                        :name,
                                        {},
                                        class: "form-control input-sm" %>
          </div>
        </div>
        <div class="form-group">
          <%= form.label :position, class: "control-label col-xs-2" %>
          <div class="col-xs-10">
            <%= form.text_field :position, class: "form-control input-sm" %>
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-10">
            <div class="checkbox">
              <%= form.label :write_access do %>
                <%= form.check_box :write_access %>
                Write access?
              <% end %>
            </div>
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-10">
             <%= form.submit "Add to project", class: "btn btn-primary btn-sm" %>
          </div>
        </div>
      <% end %>
      </p>
    <% end %>
  </section>
</div>

<hr>

<div class="row">
  <h3>Files</h3>
  <table width="100%" class="table" id="scripts_table">
    <thead>
      <tr>
        <th>Name</th>
        <th>Stage</th>
        <th>Note count</th>
        <th>Last change</th>
      </tr>
    </thead>
    <tbody>
      <% @scripts.each do |script| %>
        <tr>
          <td><strong><%= link_to script.name, edit_script_path(script) %></strong></td>
          <td><%= friendly_stage_names[script.stage] %></td>
          <td><%= script.note_count %></td>
          <td data-order="<%= script.updated_at.to_i %>"><%= display_time(script.updated_at) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

<hr>

<div class="row">
  <h3>Recent changes</h3>
  <% if @changes.any? %>
    <ul class="panel_list">
      <% @changes.each do |change| %>
        <li class="panel panel-default with_avatar">
          <aside class="avatar">
            <%= avatar_for change.user %>
          </aside>
          <section class="content">
            <p>
              <em><%= display_time(change.created_at) %></em>
              <% if change.user.present? %>
                <br><strong><%= link_to change.user.name, change.user %></strong> updated
                <strong><%= link_to change.auditable.name, edit_script_path(change.auditable) %></strong>
              <% else %>
                <br><strong><%= link_to change.auditable.name, edit_script_path(change.auditable) %></strong> was updated
              <% end %>
            </p>
            <% if change.audited_changes.include? "stage" %>
              <p>
                <strong>Stage</strong> went from
                <strong><%= change.audited_changes["stage"].first %></strong>
                to <strong><%= change.audited_changes["stage"].second %></strong>
              </p>
            <% end %>
            <% if change.comment.present? %>
              <p>
                <strong>Comment:</strong> <%= parsed_comment(change) %>
              </p>
            <% end %>
            <p>
              <strong><%= link_to_script_version(change) %></strong>
              <% unless change.version == 1 %>
                <%= link_to "(diff to previous)",
                                    diff_script_path(id: change.auditable.id, first: change.version - 1, second: change.version) %>
              <% end %>
            </p>
          </section>
        </li>
      <% end %>
    </ul>
  <% else %>
    none
  <% end %>
  
  <%= will_paginate @changes %>
</div>


<script type="text/javascript">
  $(document).ready(function() {
    $('#scripts_table').DataTable({
      "info": false,
      "searching": false
    });
    
    $("#toggle_read_only").click(function() {
      $(".membership_read_only").toggleClass("invisible");
    });
  });
</script><commit_msg>add filters to scripts table<commit_after><% provide(:title, "Project #{@project.name}") %>
<div class="row">
  <section class="col-md-6">
    <h3><%= @project.name %></h3>
    <p>
      <strong>Language:</strong> <%= @project.language %>
      <br><strong>Total scripts:</strong> <%= @project.scripts.count %>
      <% if current_user.admin? %><br><%= link_to 'Edit', edit_project_path(@project) %><% end %>
      <br><%= link_to raw("#{glyphicon 'download-alt'} Download ZIP"),
      download_project_path(@project),
      class: 'btn btn-primary' %>
    </p>
  </section>
  <section class="col-md-6" id="project_members">
    <h3>Members</h3>
    <% if @project.project_memberships.any? %>
      <ul class="panel_list clearfix">
        <% @project.project_memberships.each do |membership| %>
          <li class="panel panel-default with_avatar col-md-5<%= membership.write_access? ? "" : " membership_read_only invisible" %>">
            <aside class="avatar">
              <%= avatar_for membership.user %>
            </aside>
            <section class="content">
              <strong><%= link_to membership.user.name, membership.user %></strong>
              <% unless membership.position.blank? %><br><em><%= membership.position %></em><% end %>
              <% unless membership.write_access? %><br>(read only)<% end %>
              <% if current_user.admin? %>
                <br><%= link_to '(remove)', membership, method: :delete, data: { confirm: 'Are you sure?' } %>
              <% end %>
            </section>
          </li>
        <% end %>
      </ul>
    <% else %>
      none
    <% end %>
    <p><%= link_to "toggle read only", "#", id: "toggle_read_only" %></p>
    <% if current_user.admin? %>
      <p><hr>
      <%= form_with(model: @membership, class: "form-horizontal", local: true) do |form| %>
        <%= form.hidden_field :project_id, value: @project.id %>
        <div class="form-group">
          <%= form.label :user_id, "User", class: "control-label col-xs-2" %>
          <div class="col-xs-10">
            <%= form.collection_select :user_id, 
                                        User.where_not_member_of_project(@project),
                                        :id,
                                        :name,
                                        {},
                                        class: "form-control input-sm" %>
          </div>
        </div>
        <div class="form-group">
          <%= form.label :position, class: "control-label col-xs-2" %>
          <div class="col-xs-10">
            <%= form.text_field :position, class: "form-control input-sm" %>
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-10">
            <div class="checkbox">
              <%= form.label :write_access do %>
                <%= form.check_box :write_access %>
                Write access?
              <% end %>
            </div>
          </div>
        </div>
        <div class="form-group">
          <div class="col-xs-offset-2 col-xs-10">
             <%= form.submit "Add to project", class: "btn btn-primary btn-sm" %>
          </div>
        </div>
      <% end %>
      </p>
    <% end %>
  </section>
</div>

<hr>

<div class="row">
  <h3>Files</h3>
  <p>
    <label><input type="checkbox" id="check_only_with_notes" class="scripts_table_filter"> Only with notes</label>
  </p>
  <p>
    <table width="100%">
      <tr>
        <td><label><input type="checkbox" id="check_all_stages" class="scripts_table_filter" checked> All</label></td>
        <% friendly_stage_names.each_value do |stage| %>
          <td><label><input type="checkbox" class="scripts_table_filter stages_checkbox" data-stage="<%= stage %>" checked> <%= stage %></label></td>
        <% end %>
      </tr>
    </table>
  </p>
  <table width="100%" class="table" id="scripts_table">
    <thead>
      <tr>
        <th>Name</th>
        <th>Stage</th>
        <th>Note count</th>
        <th>Last change</th>
      </tr>
    </thead>
    <tbody>
      <% @scripts.each do |script| %>
        <tr>
          <td><strong><%= link_to script.name, edit_script_path(script) %></strong></td>
          <td><%= friendly_stage_names[script.stage] %></td>
          <td><%= script.note_count %></td>
          <td data-order="<%= script.updated_at.to_i %>"><%= display_time(script.updated_at) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

<hr>

<div class="row">
  <h3>Recent changes</h3>
  <% if @changes.any? %>
    <ul class="panel_list">
      <% @changes.each do |change| %>
        <li class="panel panel-default with_avatar">
          <aside class="avatar">
            <%= avatar_for change.user %>
          </aside>
          <section class="content">
            <p>
              <em><%= display_time(change.created_at) %></em>
              <% if change.user.present? %>
                <br><strong><%= link_to change.user.name, change.user %></strong> updated
                <strong><%= link_to change.auditable.name, edit_script_path(change.auditable) %></strong>
              <% else %>
                <br><strong><%= link_to change.auditable.name, edit_script_path(change.auditable) %></strong> was updated
              <% end %>
            </p>
            <% if change.audited_changes.include? "stage" %>
              <p>
                <strong>Stage</strong> went from
                <strong><%= change.audited_changes["stage"].first %></strong>
                to <strong><%= change.audited_changes["stage"].second %></strong>
              </p>
            <% end %>
            <% if change.comment.present? %>
              <p>
                <strong>Comment:</strong> <%= parsed_comment(change) %>
              </p>
            <% end %>
            <p>
              <strong><%= link_to_script_version(change) %></strong>
              <% unless change.version == 1 %>
                <%= link_to "(diff to previous)",
                                    diff_script_path(id: change.auditable.id, first: change.version - 1, second: change.version) %>
              <% end %>
            </p>
          </section>
        </li>
      <% end %>
    </ul>
  <% else %>
    none
  <% end %>
  
  <%= will_paginate @changes %>
</div>


<script type="text/javascript">
  $(document).ready(function() {
    var table = $('#scripts_table').DataTable({
      "info": false
    });
    var lock = false;
    $('.scripts_table_filter').change(function() {
      if (!lock) table.draw();
    });
    $('#check_all_stages').change(function() {
      lock = true;
      $(".stages_checkbox").prop('checked', $(this).prop("checked"));
      table.draw();
      lock = false;
    });
    $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
      if($("#check_only_with_notes")[0].checked && parseInt(data[2], 10) == 0) return false;
      
      var checked_stages = [];
      $('.stages_checkbox').each(function() {
        if($(this)[0].checked) checked_stages.push($(this).data('stage'));
      });
      console.log(checked_stages);
      if(checked_stages.includes(data[1])) return true;
    
      return false;
    });
    
    $("#toggle_read_only").click(function() {
      $(".membership_read_only").toggleClass("invisible");
    });
  });
</script>
{'fraction_non_alphanumeric': 0.18345323741007194, 'fraction_numerical': 0.0049460431654676255, 'mean_word_length': 1.896678966789668, 'pattern_counts': {'":': 3, '<': 434, '<?xml version=': 0, '>': 434, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4916219', 'n_tokens_mistral': 4331, 'n_tokens_neox': 4013, 'n_words': 783}