Skip to content

Commit

Permalink
Adding a presenter for the project show page (#951)
Browse files Browse the repository at this point in the history
This is a step to allow us to display only part of the path to the user

refs #941
  • Loading branch information
carolyncole authored Sep 24, 2024
1 parent 7c16295 commit 4a1fe82
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def show
@project_purpose = @project_metadata[:project_purpose]

respond_to do |format|
format.html
format.html do
@project = ProjectShowPresenter.new(project)
end
format.json do
render json: project.to_json
end
Expand Down
10 changes: 10 additions & 0 deletions app/presenters/project_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true
class ProjectShowPresenter
delegate "id", "in_mediaflux?", "mediaflux_id", "metadata", "metadata_model", "pending?", "project_directory", "status", "title", to: :project

attr_reader :project

def initialize(project)
@project = project
end
end
10 changes: 5 additions & 5 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Project Details:
<div class="details">
<h2>Roles
<% if @project_eligible_to_edit %>
<%= link_to "Edit", edit_project_path(@project), id:"revisible-heading", class: "btn btn-primary btn-sm" %>
<%= link_to "Edit", edit_project_path(@project.id), id:"revisible-heading", class: "btn btn-primary btn-sm" %>
<% end %>
</h2>
<dl>
Expand Down Expand Up @@ -58,7 +58,7 @@ Project Details:
<div class="details">
<h2>Project Description
<% if @project_eligible_to_edit %>
<%= link_to "Edit", edit_project_path(@project), id:"revisible-heading", class: "btn btn-primary btn-sm" %>
<%= link_to "Edit", edit_project_path(@project.id), id:"revisible-heading", class: "btn btn-primary btn-sm" %>
<% end %>
</h2>
<dl>
Expand Down Expand Up @@ -96,7 +96,7 @@ Project Details:

<div class="details">
<% if !current_user.eligible_sysadmin? %>
<%= link_to "Review Contents", project_contents_path(@project), class: "btn btn-primary btn-sm" %>
<%= link_to "Review Contents", project_contents_path(@project.id), class: "btn btn-primary btn-sm" %>
<%= link_to "Withdraw Project Request", "", class: "btn btn-secondary btn-sm" %>
<%= link_to "Return to Dashboard", root_path, class: "btn btn-primary btn-sm" %>
<% end %>
Expand All @@ -105,11 +105,11 @@ Project Details:
<div class="details">
<% if current_user.eligible_sysadmin? %>
<% if @project.pending? %>
<%= link_to "Approve Project", project_approve_path(@project), class: "btn btn-primary btn-sm" %>
<%= link_to "Approve Project", project_approve_path(@project.id), class: "btn btn-primary btn-sm" %>
<%= link_to "Deny Project", "", class: "btn btn-secondary btn-sm" %>
<%= link_to " View Create Script", "#", class: "bi bi-code btn btn-secondary btn-sm", id: "create-script-btn" %>
<% end %>
<%= link_to "Review Contents", project_contents_path(@project), class: "btn btn-primary btn-sm" %>
<%= link_to "Review Contents", project_contents_path(@project.id), class: "btn btn-primary btn-sm" %>
<%= link_to "Return to Dashboard", root_path, class: "btn btn-return btn-sm" %>
<% end %>
</div>
Expand Down
55 changes: 55 additions & 0 deletions spec/models/project_show_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true
require "rails_helper"

RSpec.describe ProjectShowPresenter, type: :model, connect_to_mediaflux: false do
let(:project) { FactoryBot.create :project }
subject(:presenter) { ProjectShowPresenter.new(project) }

describe "#id" do
it "delegates to project" do
expect(presenter.id).to eq(project.id)
end
end

describe "#in_mediaflux?" do
it "delegates to project" do
expect(presenter.in_mediaflux?).to eq(project.in_mediaflux?)
end
end

describe "#mediaflux_id" do
it "delegates to project" do
expect(presenter.mediaflux_id).to eq(project.mediaflux_id)
end
end

describe "#metadata" do
it "delegates to project" do
expect(presenter.metadata).to eq(project.metadata)
end
end

describe "#pending?" do
it "delegates to project" do
expect(presenter.pending?).to eq(project.pending?)
end
end

describe "#project_directory" do
it "delegates to project" do
expect(presenter.project_directory).to eq(project.project_directory)
end
end

describe "#status" do
it "delegates to project" do
expect(presenter.status).to eq(project.status)
end
end

describe "#title" do
it "delegates to project" do
expect(presenter.title).to eq(project.title)
end
end
end

0 comments on commit 4a1fe82

Please sign in to comment.