Skip to content

Commit 96a0099

Browse files
authored
977 add breadcrumbs model (#1014)
* WIP trying to implement breadcrumbs * Added breadcrumbs model and breadcrumbs in project page * Rubocop fixes * Added stub test
1 parent 596021a commit 96a0099

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
@import "alternate_mediaflux";
1717
@import "banner";
18+
@import "components/breadcrumbs";
1819
@import "components/mediaflux_status";
1920
@import "emulator";
2021
@import "footer";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.breadcrumbs {
2+
3+
list-style-type: none;
4+
padding: 0px;
5+
margin: 2em 0em;
6+
7+
a {
8+
color: $black;
9+
text-decoration: none;
10+
}
11+
12+
a:hover {
13+
text-decoration: underline;
14+
color: $black;
15+
}
16+
17+
li {
18+
display: inline-block;
19+
}
20+
21+
.inactive {
22+
opacity: 0.4;
23+
}
24+
}

app/controllers/application_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
55
around_action :mediaflux_session
66
before_action :emulate_user
77

8+
helper_method :breadcrumbs
9+
810
def new_session_path(_scope)
911
new_user_session_path
1012
end
@@ -13,6 +15,14 @@ def require_admin_user
1315
head :forbidden unless current_user&.eligible_sysadmin?
1416
end
1517

18+
def breadcrumbs
19+
@breadcrumbs ||= []
20+
end
21+
22+
def add_breadcrumb(name, path = nil)
23+
breadcrumbs << Breadcrumb.new(name, path)
24+
end
25+
1626
private
1727

1828
def mediaflux_session

app/controllers/projects_controller.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# frozen_string_literal: true
22
class ProjectsController < ApplicationController
3+
4+
before_action :set_breadcrumbs
5+
36
def new
7+
add_breadcrumb("New Project Request")
48
return build_new_project if current_user.eligible_sponsor?
59

610
redirect_to root_path
@@ -67,6 +71,8 @@ def create
6771
end
6872

6973
def show
74+
add_breadcrumb(project.title, project_path)
75+
add_breadcrumb("Details")
7076
project
7177
@departments = project.departments.join(", ")
7278
@project_metadata = project.metadata_model
@@ -122,6 +128,8 @@ def show
122128
end
123129

124130
def edit
131+
add_breadcrumb(project.title, project_path)
132+
add_breadcrumb("Edit")
125133
project
126134
if project.metadata_model.status != Project::APPROVED_STATUS
127135
flash[:notice] = "Pending projects can not be edited."
@@ -164,6 +172,8 @@ def confirmation; end
164172
def revision_confirmation; end
165173

166174
def contents
175+
add_breadcrumb(project.title, project_path)
176+
add_breadcrumb("Contents", project_contents_path)
167177
project
168178

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

209219
def approve
210220
if current_user.eligible_sysadmin?
221+
add_breadcrumb(project.title, project_path)
222+
add_breadcrumb("Approval Settings", project_approve_path)
223+
add_breadcrumb("Edit")
211224
project
212225
@departments = project.departments.join(", ")
213226
@project_metadata = project.metadata
@@ -248,4 +261,8 @@ def shared_file_location(filename)
248261
location = Pathname.new(Rails.configuration.mediaflux["shared_files_location"])
249262
location.join(filename).to_s
250263
end
264+
265+
def set_breadcrumbs
266+
add_breadcrumb("Dashboard","/")
267+
end
251268
end

app/models/breadcrumb.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
class Breadcrumb
3+
attr_reader :name, :path
4+
def initialize(name, path)
5+
@name = name
6+
@path = path
7+
end
8+
9+
def link?
10+
@path.present?
11+
end
12+
end

app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<% end %>
5656
<div class="row">
5757
<div class="col">
58+
<%= render partial: 'shared/breadcrumbs' %>
5859
<%= yield %>
5960
</div>
6061
</div>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<nav>
2+
<ul class="breadcrumbs">
3+
<% breadcrumbs.each do |crumb| %>
4+
<li>
5+
<% if crumb.link? %>
6+
<%= link_to crumb.name, crumb.path, class: "breadcrumb-link" %>
7+
<% else %>
8+
<span class="breadcrumb-page inactive">
9+
<%= crumb.name %>
10+
</span>
11+
<% end %>
12+
13+
<% unless crumb == breadcrumbs.last %>
14+
<span class="breadcrumb-separator">></span>
15+
<% end %>
16+
</li>
17+
<% end %>
18+
</ul>
19+
</nav>

spec/models/breadcrumb_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
require "rails_helper"
3+
4+
RSpec.describe Breadcrumb, type: :model do
5+
pending "add some examples to (or delete) #{__FILE__}"
6+
end

0 commit comments

Comments
 (0)