Skip to content

Commit

Permalink
977 add breadcrumbs model (#1014)
Browse files Browse the repository at this point in the history
* WIP trying to implement breadcrumbs

* Added breadcrumbs model and breadcrumbs in project page

* Rubocop fixes

* Added stub test
  • Loading branch information
kelynch authored Oct 29, 2024
1 parent 596021a commit 96a0099
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@import "alternate_mediaflux";
@import "banner";
@import "components/breadcrumbs";
@import "components/mediaflux_status";
@import "emulator";
@import "footer";
Expand Down
24 changes: 24 additions & 0 deletions app/assets/stylesheets/components/breadcrumbs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.breadcrumbs {

list-style-type: none;
padding: 0px;
margin: 2em 0em;

a {
color: $black;
text-decoration: none;
}

a:hover {
text-decoration: underline;
color: $black;
}

li {
display: inline-block;
}

.inactive {
opacity: 0.4;
}
}
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
around_action :mediaflux_session
before_action :emulate_user

helper_method :breadcrumbs

def new_session_path(_scope)
new_user_session_path
end
Expand All @@ -13,6 +15,14 @@ def require_admin_user
head :forbidden unless current_user&.eligible_sysadmin?
end

def breadcrumbs
@breadcrumbs ||= []
end

def add_breadcrumb(name, path = nil)
breadcrumbs << Breadcrumb.new(name, path)
end

private

def mediaflux_session
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true
class ProjectsController < ApplicationController

before_action :set_breadcrumbs

def new
add_breadcrumb("New Project Request")
return build_new_project if current_user.eligible_sponsor?

redirect_to root_path
Expand Down Expand Up @@ -67,6 +71,8 @@ def create
end

def show
add_breadcrumb(project.title, project_path)
add_breadcrumb("Details")
project
@departments = project.departments.join(", ")
@project_metadata = project.metadata_model
Expand Down Expand Up @@ -122,6 +128,8 @@ def show
end

def edit
add_breadcrumb(project.title, project_path)
add_breadcrumb("Edit")
project
if project.metadata_model.status != Project::APPROVED_STATUS
flash[:notice] = "Pending projects can not be edited."
Expand Down Expand Up @@ -164,6 +172,8 @@ def confirmation; end
def revision_confirmation; end

def contents
add_breadcrumb(project.title, project_path)
add_breadcrumb("Contents", project_contents_path)
project

@storage_usage = project.storage_usage(session_id: current_user.mediaflux_session)
Expand Down Expand Up @@ -208,6 +218,9 @@ def file_list_download

def approve
if current_user.eligible_sysadmin?
add_breadcrumb(project.title, project_path)
add_breadcrumb("Approval Settings", project_approve_path)
add_breadcrumb("Edit")
project
@departments = project.departments.join(", ")
@project_metadata = project.metadata
Expand Down Expand Up @@ -248,4 +261,8 @@ def shared_file_location(filename)
location = Pathname.new(Rails.configuration.mediaflux["shared_files_location"])
location.join(filename).to_s
end

def set_breadcrumbs
add_breadcrumb("Dashboard","/")
end
end
12 changes: 12 additions & 0 deletions app/models/breadcrumb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
class Breadcrumb
attr_reader :name, :path
def initialize(name, path)
@name = name
@path = path
end

def link?
@path.present?
end
end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<% end %>
<div class="row">
<div class="col">
<%= render partial: 'shared/breadcrumbs' %>
<%= yield %>
</div>
</div>
Expand Down
19 changes: 19 additions & 0 deletions app/views/shared/_breadcrumbs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<nav>
<ul class="breadcrumbs">
<% breadcrumbs.each do |crumb| %>
<li>
<% if crumb.link? %>
<%= link_to crumb.name, crumb.path, class: "breadcrumb-link" %>
<% else %>
<span class="breadcrumb-page inactive">
<%= crumb.name %>
</span>
<% end %>

<% unless crumb == breadcrumbs.last %>
<span class="breadcrumb-separator">></span>
<% end %>
</li>
<% end %>
</ul>
</nav>
6 changes: 6 additions & 0 deletions spec/models/breadcrumb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
require "rails_helper"

RSpec.describe Breadcrumb, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 96a0099

Please sign in to comment.