Skip to content

Commit

Permalink
[wip] Improving the file tree browsing interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Jan 28, 2022
1 parent 375c9e9 commit 5860a82
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 64 deletions.
23 changes: 10 additions & 13 deletions app/assets/stylesheets/browse_everything/modules/file_tree.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@

.view {
position: relative;
height: 100%;
box-shadow: 12px 24px 4px rgba(0, 0, 0, 0.25);
box-shadow: 8px 12px 4px rgba(0, 0, 0, 0.25);
z-index:10;
overflow-y:auto;

padding-left:20px;
padding-right:20px;
padding-top:10px;
padding-bottom:10px;

overflow-y: scroll;
max-height: 576px;
border: 0.4rem solid #444;
border-radius: 0.6rem;

margin-left: 0.8rem;
margin-right: 0.8rem;

.folder {
display: block;
border: 1px solid transparent;
overflow: hidden;
max-height: 1000px;

& > input { display:none; }

Expand Down Expand Up @@ -77,13 +81,6 @@
animation: pull 0.25s, hide 1s infinite;
animation-delay: 0s, 0.25s;
}

/*
input:checked ~ .label {
i.hide{ display:inline-block; }
i.show{ display:none; }
}
*/
}

@keyframes pull{
Expand Down
3 changes: 3 additions & 0 deletions app/views/browse_everything/providers/_auth.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="container-fluid">
<h3>Authentication</h3>
</div>
8 changes: 8 additions & 0 deletions app/views/browse_everything/providers/_file.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<div class="file">
<input type="checkbox" id="file_1" />
<label class="label" for="file_1">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span>
<div class="text"><%= node.basename %></div>
</label>
</div><!--/.file -->
37 changes: 0 additions & 37 deletions app/views/browse_everything/providers/_files.html.erb

This file was deleted.

22 changes: 22 additions & 0 deletions app/views/browse_everything/providers/_folder.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<div class="folder">
<input type="checkbox" id="folder_1" />
<label class="label" for="folder_1">
<span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span>
<div class="text"><%= node.basename %></div>
</label>

<% if node.is_a?(BrowseEverything::Driver::FileSystem::ResourceTree) && !node.children.empty? %>
<div class="folder__children">

<% node.children.each do |child| %>
<% if child.is_a?(BrowseEverything::Driver::FileSystem::ResourceTree) %>
<%= render(partial: 'folder', locals: { node: child }) %>
<% else %>
<%= render(partial: 'file', locals: { node: child }) %>
<% end %>
<% end %>
</div><!--/.children -->
<% end %>
</div><!--/.folder -->

6 changes: 6 additions & 0 deletions app/views/browse_everything/providers/_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<div class="view">
<% page.each do |node| %>
<%= render(partial: 'folder', locals: { node: node }) %>
<% end %>
</div>
4 changes: 4 additions & 0 deletions app/views/browse_everything/providers/browse.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% @pages.each do |page| %>
<%= render(partial: 'page', locals: { page: page }) %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/browse_everything/providers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<li><a href="providers/aws">Amazon Web Services</a></li>
<li><a href="providers/google-drive">Google Drive</a></li>
<li class="dropdown-header">Local Providers</li>
<li><a href="<%= provider_path(id: 'file_system') %>">File System</a></li>
<li><a href="<%= provider_browse_path(id: 'file_system') %>">File System</a></li>
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BrowseEverything::Engine.routes.draw do
root to: 'providers#index'

get 'providers/:id/browse(/:path)', to: 'providers#browse'
get 'providers/:id/browse(/:path)', to: 'providers#browse', as: :provider_browse
get 'providers/:id', to: 'providers#show', as: :provider
get 'providers', to: 'providers#index'
end
22 changes: 17 additions & 5 deletions lib/browse_everything/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ def configuration_path
Rails.root.join('config', 'browse_everything_providers.yml')
end

def config_file_content
File.read(configuration_path)
end

def config_file_template
ERB.new(config_file_content)
end

def config_values
YAML.safe_load(config_file_template.result, [Symbol])
end

def parse_configuration
config_file_content = File.read(configuration_path)
config_file_template = ERB.new(config_file_content)
config_values = YAML.safe_load(config_file_template.result, [Symbol])
config = ActiveSupport::HashWithIndifferentAccess.new(config_values)
config.deep_symbolize_keys
#config_file_content = File.read(configuration_path)
#config_file_template = ERB.new(config_file_content)
#config_values = YAML.safe_load(config_file_template.result, [Symbol])
#config = ActiveSupport::HashWithIndifferentAccess.new(config_values)
config_values.deep_symbolize_keys
end

def configuration
Expand Down
33 changes: 26 additions & 7 deletions lib/browse_everything/driver/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.configuration_class
end

class ResourceUpload
attr_reader :uri, :local_path, :parent
attr_reader :local_path, :parent, :uri

def initialize(**options)
unresolved = options[:uri]
Expand All @@ -33,10 +33,13 @@ def initialize(**options)
@uri = "file://#{local_path}"
end

delegate :basename, to: :local_path

def attributes
{
path: path,
parent: parent
basename: basename,
parent: parent,
path: path
}
end

Expand Down Expand Up @@ -137,9 +140,11 @@ def attributes
end

delegate :as_json, to: :attributes
delegate :basename, to: :root
end

class Pages
include Enumerable
attr_reader :pages, :page_length

def self.build(resource_tree:, page_length: Page::DEFAULT_LENGTH)
Expand All @@ -158,8 +163,14 @@ def initialize(pages: nil, elements: [], page_length: Page::DEFAULT_LENGTH)
@page_length = page_length
end

def each
pages.each do |page|
yield page
end
end

delegate :empty?, to: :pages
delegate :first, to: :pages
#delegate :first, to: :pages
delegate :last, to: :pages
delegate :length, to: :pages
delegate :to_a, to: :pages
Expand All @@ -175,12 +186,20 @@ def as_json

class Page
DEFAULT_LENGTH = 25

include Enumerable
attr_reader :elements

def initialize(elements:)
@elements = elements
end

def each
elements.each do |element|
yield element
end
end

delegate :[], to: :elements
delegate :empty?, to: :elements
delegate :first, to: :elements
Expand Down Expand Up @@ -213,7 +232,7 @@ def resolve(uri:)

# Retrieve the contents of a directory
# @param path [String] the path to a file system resource
# @return [Array<BrowseEverything::RemoteFile>]
# @return [Pages]
def browse(path: nil)
full_path = if path.nil?
Pathname.new(root_path)
Expand All @@ -227,8 +246,8 @@ def browse(path: nil)
end
alias contents browse

# Legacy Methods (to be removed)
####
#
## Legacy Methods (to be removed)

def icon
'file'
Expand Down

0 comments on commit 5860a82

Please sign in to comment.