Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing the BrowseEverything::Resource Class and extracting para…
…meter parsing Controller functionality into BrowseEverything::Parameters
- Loading branch information
1 parent
70119c9
commit 2cffe03
Showing
10 changed files
with
106 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require File.expand_path('../../../../lib/browse_everything/resource', __dir__) | ||
|
||
module BrowseEverything | ||
module Parameters | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# Retrieve the file and directory entries selected using the POST request | ||
# @return [Array<String>] | ||
def browse_everything_params | ||
return unless params[:browse_everything] | ||
|
||
file_values = params[:browse_everything].fetch(:selected_files, []) | ||
dir_values = params[:browse_everything].fetch(:selected_directories, []) | ||
# Ensure that these are empty Arrays if ActionController::Parameters are | ||
# empty | ||
file_values = [] if file_values.empty? | ||
dir_values = [] if dir_values.empty? | ||
|
||
file_values + dir_values | ||
end | ||
|
||
# Retrieve the file entries selected using the legacy POST request parameter | ||
# @return [Array<String>] | ||
def selected_params | ||
params[:selected_files] | ||
end | ||
|
||
# Retrieve the files selected from browse-everything | ||
# @return [BrowseEverything::Resource] | ||
def selected_files | ||
return [] unless selected_params | ||
|
||
values = selected_params.values.uniq | ||
values.map { |value| BrowseEverything::Resource.new(value) } | ||
end | ||
|
||
# Determine whether or not cloud service files are being uploaded | ||
# @return [Boolean] | ||
def selected_cloud_files? | ||
values = selected_files.map(&:cloud_file?) | ||
values.reduce(:|) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
# Class modeling resources selected for upload using browse-everything | ||
module BrowseEverything | ||
class Resource < ActiveSupport::HashWithIndifferentAccess | ||
# Retrieve the path for the resource | ||
# @return [String] | ||
def path | ||
return if url.nil? | ||
|
||
_provider_key, uri = url.split(/:\/\//) | ||
uri | ||
end | ||
|
||
# Determine whether or not this file is a cloud resource | ||
# @return [Boolean] | ||
def cloud_file? | ||
return false if url.nil? | ||
|
||
m = /^https?\:/.match(url) | ||
!m.nil? | ||
end | ||
|
||
private | ||
|
||
# Retrieve the URL for the resource | ||
# @return [String] | ||
def url | ||
fetch("url", nil) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters