Skip to content

Commit

Permalink
Sorting tweaks and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
euler-room committed Dec 5, 2024
1 parent 1ec386d commit 08c28a2
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module DirectoryUtilsConcern
# Constants for sorting
ASCENDING = true
DESCENDING = false
# Constants for grouping
DIRECTORIES = true
FILES = false
DEFAULT_SORTING_PARAMS = { col: 'name', direction: ASCENDING, grouped?: true }

extend ActiveSupport::Concern
Expand Down Expand Up @@ -42,10 +39,11 @@ def validate_path!
end

def set_sorting_params(parameters)
Rails.logger.debug("Sorting params: #{parameters}")
@sorting_params = {
col: parameters[:col],
direction: parameters[:direction],
grouped?: parameters[:grouped?]
col: parameters&.[](:col),
direction: !parameters&.[](:direction),
grouped?: parameters&.[](:grouped?)
}
end

Expand Down
13 changes: 4 additions & 9 deletions apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class ProjectsController < ApplicationController
def show
project_id = show_project_params[:id]
@project = Project.find(project_id)

parse_path
validate_path!
set_sorting_params(show_project_params[:sorting_params] || default_sorting_params)
set_files

if @project.nil?
respond_to do |format|
Expand Down Expand Up @@ -41,7 +38,9 @@ def directory
@project = Project.find(directory_params[:project_id])
parse_path("#{directory_params[:dir_path]}")
validate_path!
set_sorting_params(directory_params[:sorting_params] || DEFAULT_SORTING_PARAMS)

Rails.logger.debug("Sorting params: #{@sorting_params}")
set_sorting_params(directory_params[:sorting_params] || DEFAULT_SORTING_PARAMS )
set_files
render( partial: 'projects/directory',
locals: { project: @project,
Expand Down Expand Up @@ -214,10 +213,6 @@ def resolved_fs
'fs'
end

def default_sorting_params
DEFAULT_SORTING_PARAMS
end

def templates
Project.templates.map do |project|
label = project.title
Expand All @@ -240,7 +235,7 @@ def directory_params
end

def file_params
params.permit(:project_id, :format, :path, :sorting_params)
params.permit(:project_id, :format, :path, sorting_params: [:col, :direction, :grouped?])
end

def show_project_params
Expand Down
43 changes: 28 additions & 15 deletions apps/dashboard/app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,53 @@ def project_size
# )
# end

def column_head_link(column)
link_to(
link_text(column),
target_path(column),
def column_head_link(column, sorting_params)
a = link_to(
link_text(column, sorting_params),
target_path(column, sorting_params),
title: tool_tip,
class: "text-dark",
data: data_attributes
)

Rails.logger.debug("\n\n\n\n\n============== #{column} ===================")
Rails.logger.debug("Column head link: #{a}")
Rails.logger.debug("========================================\n\n\n\n\n")
a
end

def direction(column)
if column.to_s == @sorting_params[:col]
@sorting_params[:direction] == ascending ? descending : ascending
else
DirectoryUtilsConcern::ASCENDING
def direction(column, sorting_params)
if column.to_s == sorting_params[:col].to_s
Rails.logger.debug("\n\n\n\n\n______________--------============-----------______________")
Rails.logger.debug(" COLUMN: #{column}")
Rails.logger.debug(" is #{column.to_s == sorting_params[:col] ? 'EQUAL' : 'NOT EQUAL'} to")
Rails.logger.debug(" SP COL: #{sorting_params[:col]}")
Rails.logger.debug(" RETURNING: descending") if column.to_s == sorting_params[:col].to_s && sorting_params[:direction] == ascending

Rails.logger.debug("--------------========____________===========--------------\n\n\n\n\n")
end
if column.to_s == sorting_params[:col].to_s
!sorting_params[:direction]
end
ascending
end

def link_text(column)
def link_text(column, sorting_params)
col_title = t("dashboard.#{column.to_s}")
if column.to_s == @sorting_params[:col]
"#{col_title} #{fa_icon( direction(column) == ascending ? 'sort-up' : 'sort-down', classes: 'fa-md')}".html_safe
if column.to_s == sorting_params[:col]
"#{col_title} #{fa_icon( direction(column, sorting_params) == ascending ? 'sort-up' : 'sort-down', classes: 'fa-md')}".html_safe
else
"#{col_title} #{fa_icon('sort', classes: 'fa-md')}".html_safe
end
end

def target_path(column, grouped = @sorting_params[:grouped?])
def target_path(column, sorting_params)
project_directory_path(
{ project_id: @project.id,
dir_path: @path.to_s,
sorting_params: { col: column,
direction: direction(column),
grouped?: grouped
direction: direction(column, sorting_params),
grouped?: sorting_params[:grouped]
}
}
)
Expand Down
44 changes: 21 additions & 23 deletions apps/dashboard/app/views/projects/_directory.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<%= turbo_frame_tag "project_directory" do %>
<div class="border border-2 shadow p-3 mt-3 mb-5 bg-white rounded">
<div class="d-flex justify-content-left lead text-weight-800">
<strong>.../projects<%= @path.to_s.split('projects')[1] %></strong>
<div class="d-flex justify-content-left lead text-weight-800">
<strong>.../projects<%= @path.to_s.split('projects')[1] %></strong>
</div>
<table class="table table-striped table-condensed w-100 table-hover caption-right">
<thead>
<tr>
<th><%= t('dashboard.type') %></span></th>
<th><%= column_head_link(:name, sorting_params) %></th>
<th><%= column_head_link(:size, sorting_params) %></th>
<th><%= column_head_link(:date, sorting_params) %></th>
<th><%= column_head_link(:owner, sorting_params) %></th>
<th>Mode</th>
</tr>
</thead>
<tbody>
<%= render partial: "files", locals: { project: project, path: path, files: files, sorting_params: sorting_params } %>
</tbody>
</table>
<div class="row content-justied-center col-6 mx-auto">
<div class="btn btn-primary">
<span><i class="fa fa-folder-open"></i>&nbsp<%= files_button %></span>
</div>
<table class="table table-striped table-condensed w-100 table-hover caption-right">
<caption>
<div class="my-2 btn btn-sm btn-primary">
<span><i class="fa fa-folder-open"></i>&nbsp<%= files_button %></span>
</div>
</caption>
<thead>
<tr>
<th><%= t('dashboard.type') %></span></th>
<th><%= column_head_link(:name) %></th>
<th><%= column_head_link(:size) %></th>
<th><%= column_head_link(:date) %></th>
<th><%= column_head_link(:owner) %></th>
<th>Mode</th>
</tr>
</thead>
<tbody>
<%= render partial: "files", locals: { project: project, path: path, files: files, sorting_params: sorting_params } %>
</tbody>
</table>
</div>
<% end %>
38 changes: 18 additions & 20 deletions apps/dashboard/app/views/projects/_file.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
<%= turbo_frame_tag "project_directory" do %>

<div class="border border-2 shadow p-3 mt-3 mb-5 bg-white rounded">
<div class="h5 border-bottom border-1 pb-2">
<div class="row">
<div class="pl-2">
<%= link_to("",
project_directory_path(project_id: @project.id, dir_path: "#{@path.parent}", sorting_params: @sorting_params),
class: 'fa fa-window-close align-self-start button buttom-sm text-danger',
data: { turbo_frame: "project_directory" }
)
%>&nbsp
.../projects<%= @path.to_s.split('projects')[1] %>
</div>
<div class="h5 border-bottom border-1 pb-2">
<div class="row">
<div class="pl-2">
<%= link_to("",
project_directory_path(project_id: @project.id, dir_path: "#{@path.parent}", sorting_params: @sorting_params),
class: 'fa fa-window-close align-self-start button buttom-sm text-danger',
data: { turbo_frame: "project_directory" }
)
%>&nbsp
.../projects<%= @path.to_s.split('projects')[1] %>
</div>
</div>
<div >
<pre><%= @file %></pre>
</div>
<div>
<div class="my-2 btn btn-sm btn-primary">
<span><i class="fa fa-folder-open"></i>&nbsp<%= files_button %></span>
</div>
</div>
<div >
<pre><%= @file %></pre>
</div>
<hr>
<div class="row content-justied-center col-6 mx-auto">
<div class="btn btn-sm btn-primary">
<span><i class="fa fa-folder-open"></i>&nbsp<%= files_button %></span>
</div>
</div>
<%- end -%>
14 changes: 0 additions & 14 deletions apps/dashboard/app/views/projects/_files_column_head.html.erb

This file was deleted.

51 changes: 34 additions & 17 deletions apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>

<div class='row'>
<div class="col-2 align-self-center justify-content-center d-flex">
<div class="col-2 align-self-center justify-content-left d-flex">
<%= link_to 'Back', projects_path, class: 'btn btn-default align-self-start', title: 'Return to projects page' %>
</div>

Expand All @@ -21,12 +21,12 @@
</div>

<div class="row mb-3">
<div class="col-md-2">
<div class="list-group">
<div class="col-md-2 mt-3">
<div class="list-group shadow bg-white rounded">
<a class="list-group-item list-group-item-action bg-light font-weight-bold list-toggler"
data-bs-toggle="collapse" data-bs-target="#launcher_list"
aria-expanded="true" aria-controls="launcher_list">
<span><%= t('dashboard.jobs_launchers') %></span>
<span class="lead fw-bolder"><%= t('dashboard.jobs_launchers') %></span>
</a>

<div id="launcher_list" class="collapse show">
Expand All @@ -51,25 +51,42 @@
</div>

<div class="col-md-4">
<div class="row">
<h2 class="h3 d-flex justify-content-center">Active Jobs</h2>
<%= render(partial: 'job_details', collection: @project.active_jobs, as: :job, locals: { project: @project }) %>
</div>
<div class="border border-2 shadow p-3 mt-3 mb-5 bg-white rounded">
<div class="row">
<h2 class="lead fw-bolder d-flex justify-content-center">Active Jobs</h2>
<%= render(partial: 'job_details', collection: @project.active_jobs, as: :job, locals: { project: @project }) %>
</div>

<div class="row">
<h2 class="h3 d-flex justify-content-center">Completed Jobs</h2>
<div id="completed_jobs" class="row">
<%- @project.completed_jobs.each do |job| -%>
<div class="col-md-4" id="<%= "job_#{job.cluster}_#{job.id}" %>">
<%= render(partial: 'job_details_content', locals: { job: job, project: @project }) %>
<div class="row">
<h2 class="lead fw-bolder d-flex justify-content-center">Completed Jobs</h2>
<div id="completed_jobs" class="row">
<%- @project.completed_jobs.each do |job| -%>
<div class="col-md-4" id="<%= "job_#{job.cluster}_#{job.id}" %>">
<%= render(partial: 'job_details_content', locals: { job: job, project: @project }) %>
</div>
<%- end -%>
</div>
<%- end -%>
</div>
</div>
</div>
<div class="col-md-6">
<h2 class="h3 d-flex justify-content-center"><%= "#{t('dashboard.project')} #{t('dashboard.directory')}" %>: &nbsp<i><%= @project.id %></i></h2>
<%= render partial: 'directory', locals: { project: @project, path: @path, files: @files, sorting_params: @sorting_params } %>
<div class="border border-2 shadow p-3 mt-3 mb-5 bg-white rounded">
<h2 class="lead fw-bolder d-flex justify-content-center"><%= "#{t('dashboard.project')} #{t('dashboard.directory')}" %>: &nbsp<i><%= @project.id %></i></h2>
<hr>
<%= turbo_frame_tag "project_directory",
src: project_directory_path(
project_id: @project.id,
dir_path: @path,
sorting_params: @sorting_params
) do
%>
<div class="d-flex justify-content-center">
<div id="loading-icon" class="spinner-border rem-5" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<%- end -%>
</div>
</div>
</div>

Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
:format => false
put 'files/api/v1/:fs/*filepath' => 'files#update', :format => false,
:defaults => { :fs => 'fs', :format => 'json' }

if Configuration.can_access_files?
get 'files/directory' => 'files#directory', as: 'files_directory'
get 'files/file' => 'files#file', as: 'files_display_file'
end
end
post 'files/upload/:fs' => 'files#upload', :defaults => { :fs => 'fs' } if Configuration.upload_enabled?

Expand Down
Loading

0 comments on commit 08c28a2

Please sign in to comment.