Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/stylesheets/files.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
.box-metadata {
padding-right: 1rem;
}

#uploaded-file-filters > li.list-inline-item.active {
font-weight: bold;
}
20 changes: 19 additions & 1 deletion app/controllers/streams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,27 @@ class StreamsController < ApplicationController
skip_authorize_resource only: %i[normalized_dump resourcelist]
protect_from_forgery with: :null_session, if: :jwt_token

# rubocop:disable Metrics/AbcSize
# GET /organizations/1/streams/2
def show
@uploads = @stream.uploads.active.order(created_at: :desc).page(params[:page])
@uploads = @stream.uploads.active
@current_filter = params[:filter]

if params[:filter].present?
filter_status = params[:filter].to_sym

filtered_ids = @uploads.select do |upload|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to scale to thousands (or 100k+ uploads). There's probably a faster but more annoying/complex way to do this with joins:

You'd need to combine multiple where conditions depending on the filter...but:

stream.uploads.joins(:files_blobs).where('active_storage_blobs.metadata LIKE ?', '%"analyzer":"MarcAnalyzer"%')

upload.files.any? { |file| file.pod_metadata_status == filter_status }
end.map(&:id)

@uploads = Upload.where(id: filtered_ids)
end

# Reset to page 1 if a filter is applied
page_number = params[:filter].present? ? 1 : params[:page]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this mean that paging won't work if a filter is applied?

@uploads = @uploads.order(created_at: :desc).page(page_number)
end
# rubocop:enable Metrics/AbcSize

def resourcelist
authorize! :read, @stream
Expand Down
14 changes: 8 additions & 6 deletions app/views/streams/_stream_uploads.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%= render 'uploads/file_table' do %>
<% uploads.each do |upload| %>
<%= render 'uploads/file_rows', upload: upload %>
<% end %>
<% end %>
<turbo-frame id="stream-upload-files">
<%= render 'uploads/file_table', filtering_enabled: true do %>
<% uploads.each do |upload| %>
<%= render 'uploads/file_rows', upload: upload %>
<% end %>
<% end %>

<%= paginate uploads %>
<%= paginate uploads %>
</turbo-frame>
9 changes: 8 additions & 1 deletion app/views/uploads/_file_rows.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
<%= render 'uploads/file_rows', upload: u %>
<% end %>
<% end %>
<% upload.files.each do |file| %>
<% files_to_render = if params[:filter].present?
upload.files.select { |f| f.pod_metadata_status.to_s == params[:filter].to_s }
else
upload.files
end %>

<% files_to_render.each do |file| %>

<tr>
<td class="align-middle text-center">
<%= render(MetadataStatusIconComponent.new(status: file.pod_metadata_status)) %>
Expand Down
20 changes: 16 additions & 4 deletions app/views/uploads/_file_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<ul class="table-key list-unstyled list-inline pt-3" aria-hidden="true">
<% Settings.metadata_status.keys.each do |status| %>
<li class="list-inline-item">
<%= render(MetadataStatusIconComponent.new(status: status, show_label: true)) %>
<ul class="table-key list-unstyled list-inline pt-3" id="uploaded-file-filters">
<% Settings.metadata_status.each do |status, _values| %>
<li class="list-inline-item <%= 'active' if @current_filter == status.to_s %>">
<% if local_assigns[:filtering_enabled] %>
<%= link_to organization_stream_path(@organization, @stream, filter: status), data: { turbo_frame: 'stream-upload-files' } do %>
<%= render(MetadataStatusIconComponent.new(status: status, show_label: true)) %>
<% end %>
<% else %>
<%= render(MetadataStatusIconComponent.new(status: status, show_label: true)) %>
<% end %>
</li>
<% end %>

<% if local_assigns[:filtering_enabled] %>
<li class="list-inline-item">
<%= link_to "Clear filter", organization_stream_path(@organization, @stream), data: { turbo_frame: 'stream-upload-files' }, class: 'btn btn-link btn-sm' %>
</li>
<% end %>
</ul>

<table class="table table-striped mb-3 text-break">
Expand Down
2 changes: 1 addition & 1 deletion spec/features/upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
it 'allows an org owner to upload a file to the default stream' do
visit '/'

click_on 'Best University home'
visit organization_stream_path(organization, stream)
click_on 'New upload'
attach_file('file', Rails.root.join('spec/fixtures/stanford-50.mrc.gz'))
click_on 'Create upload'
Expand Down