Skip to content

Commit

Permalink
feat(fworks): basic framework register lists frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Aug 25, 2023
1 parent d767290 commit 955befc
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 24 deletions.
12 changes: 9 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def maintenance

protected

helper_method :current_user, :cookie_policy, :record_ga?, :engagement_portal?, :support_portal?, :frameworks_portal?
helper_method :current_user, :cookie_policy, :record_ga?, :engagement_portal?, :support_portal?, :frameworks_portal?, :current_url_b64

# @return [User, Guest]
#
Expand Down Expand Up @@ -86,8 +86,14 @@ def cookie_policy
CookiePolicy.new(cookies)
end

def current_url_b64
Base64.encode64(request.fullpath)
def current_url_b64(tab = nil)
Base64.encode64("#{request.fullpath}#{"##{tab.to_s.dasherize}" if tab.present?}")
end

def back_link_param(back_to = params[:back_to])
return if back_to.blank?

Base64.decode64(back_to)
end

def tracking_base_properties = { user_id: current_user.id }
Expand Down
14 changes: 0 additions & 14 deletions app/controllers/engagement/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ module Engagement
class ApplicationController < ::ApplicationController
include SupportAgents

helper_method :current_url_b64

protected

def back_link_param(back_to = params[:back_to])
return if back_to.blank?

Base64.decode64(back_to)
end

def current_url_b64(tab = "")
Base64.encode64("#{request.fullpath}##{tab.to_s.dasherize}")
end

private

def portal_namespace = :engagement
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/frameworks/frameworks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Frameworks::FrameworksController < Frameworks::ApplicationController
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index
before_action :set_back_url, only: %i[new show]

def new; end

def index
@frameworks = Frameworks::Framework.paginate(page: params[:frameworks_page])
end

def show
@framework = Frameworks::Framework.find(params[:id])
end

private

def filter_form_params
params.require(:frameworks_filter).permit(:sort_by, :sort_order, :status, :provider)
end

def set_back_url
@back_url = back_link_param
end

def redirect_to_register_tab
redirect_to frameworks_root_path(anchor: "frameworks-register", **request.params.except(:controller, :action))
end
end
1 change: 1 addition & 0 deletions app/models/frameworks/framework.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Frameworks::Framework < ApplicationRecord
include FafImportable
include StatusChangeable
include Presentable

belongs_to :provider
end
16 changes: 16 additions & 0 deletions app/models/frameworks/framework/filterable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Frameworks::Framework::Filterable
extend ActiveSupport::Concern

included do
end

class_name do
def filtering(params)
Filter.new(params)
end

def filtered_by(params)
filtering(params).results
end
end
end
25 changes: 25 additions & 0 deletions app/models/frameworks/framework/filtering.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Frameworks::Framework::Filtering
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Validations

attribute :scoped_frameworks, default: -> { Frameworks::Framework }
attribute :status, default: -> { [] }
attribute :provider, default: -> { [] }
attribute :sort_by
attribute :sort_order

def results
results = scoped_frameworks

filters.each_value { |filter| results = filter.filter(results) }

results.sorted_by(sort_by:, sort_order:)
end

private

def filters
[]
end
end
7 changes: 7 additions & 0 deletions app/models/frameworks/framework/presentable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Frameworks::Framework::Presentable
extend ActiveSupport::Concern

included do
delegate :name, to: :provider, prefix: true
end
end
14 changes: 13 additions & 1 deletion app/views/frameworks/dashboards/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
<h1 class="govuk-header-l">Frameworks Portal</h1>
<div class="govuk-tabs" data-module="govuk-tabs" data-component="select-tab">
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item govuk-tabs__list-item--selected">
<%= link_to "Frameworks Register", "#frameworks-register", class: "govuk-tabs__tab" %>
</li>
</ul>

<%= turbo_frame_tag "frameworks-register-frame", src: frameworks_frameworks_path(frameworks_page: params[:frameworks_page]) do %>
<div id="frameworks-register" class="govuk-tabs__panel govuk-tabs__panel">
<p class="govuk-body">Loading...</p>
</div>
<% end %>
</div>
44 changes: 44 additions & 0 deletions app/views/frameworks/frameworks/_framework.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="govuk-grid-row case-panel">
<div class="govuk-grid-column-one-half govuk-!-margin-bottom-3">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Ref</dt>
<dd class="govuk-summary-list__value"><%= link_to framework.provider_reference, frameworks_framework_path(framework, back_to: current_url_b64(:frameworks_register)), class: "govuk-link", "data-turbo" => false %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Name</dt>
<dd class="govuk-summary-list__value"><%= framework.name %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Provider</dt>
<dd class="govuk-summary-list__value"><%= framework.provider_name %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Category tags</dt>
<dd class="govuk-summary-list__value"></dd>
</div>
</dl>
</div>

<div class="govuk-grid-column-one-half">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Is approved?</dt>
<dd class="govuk-summary-list__value"><%= render "framework_status", framework: %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Start date</dt>
<dd class="govuk-summary-list__value"><%= framework.starts_at&.strftime("%d %b %Y") %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">End date</dt>
<dd class="govuk-summary-list__value"><%= framework.ends_at&.strftime("%d %b %Y") %></dd>
</div>
</dl>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/frameworks/frameworks/_framework_status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<strong class="govuk-tag <%= "govuk-tag--yellow" if framework.pending_evaluation? %> <%= "govuk-tag--grey" if framework.not_approved? %>">
<%= framework.status.humanize %>
</strong>
3 changes: 3 additions & 0 deletions app/views/frameworks/frameworks/_index_filters.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="filters-panel">

</div>
17 changes: 17 additions & 0 deletions app/views/frameworks/frameworks/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= turbo_frame_tag "frameworks-register-frame" do %>
<div id="frameworks-register" class="govuk-tabs__panel">

<div class="case-list govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
<%= link_to "Add Framework", new_frameworks_framework_path(back_to: current_url_b64(:frameworks_register)), class: "govuk-button", "data-turbo" => false %>

<%= render "index_filters" %>
</div>

<div class="govuk-grid-column-three-quarters">
<%= render @frameworks %>
<%= render "components/pagination", records: @frameworks, page_param_name: :frameworks_page, pagination_params: { anchor: "frameworks-register" } %>
</div>
</div>
</div>
<% end %>
Empty file.
3 changes: 3 additions & 0 deletions app/views/frameworks/frameworks/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="govuk-heading-l"><%= @framework.name %></h1>

<p class="govuk-body">Content here</p>
40 changes: 37 additions & 3 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"check_name": "MassAssignment",
"message": "Specify exact keys allowed for mass assignment instead of using `permit!` which allows any keys",
"file": "app/controllers/support/cases_controller.rb",
"line": 145,
"line": 138,
"link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
"code": "params.fetch(:tower, {}).fetch(tab, {}).permit!",
"render_path": null,
Expand Down Expand Up @@ -202,8 +202,42 @@
79
],
"note": ""
},
{
"warning_type": "Dynamic Render Path",
"warning_code": 15,
"fingerprint": "febe8cdc12216de55b0a752231a3aa9dd1e6729d6f768b01ee7411f3f24fada6",
"check_name": "Render",
"message": "Render path contains parameter value",
"file": "app/views/frameworks/frameworks/index.html.erb",
"line": 12,
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
"code": "render(action => Frameworks::Framework.paginate(:page => params[:frameworks_page]), {})",
"render_path": [
{
"type": "controller",
"class": "Frameworks::FrameworksController",
"method": "index",
"line": 7,
"file": "app/controllers/frameworks/frameworks_controller.rb",
"rendered": {
"name": "frameworks/frameworks/index",
"file": "app/views/frameworks/frameworks/index.html.erb"
}
}
],
"location": {
"type": "template",
"template": "frameworks/frameworks/index"
},
"user_input": "params[:frameworks_page]",
"confidence": "Weak",
"cwe_id": [
22
],
"note": ""
}
],
"updated": "2023-07-20 15:35:53 +0100",
"brakeman_version": "6.0.0"
"updated": "2023-08-25 10:25:39 +0100",
"brakeman_version": "6.0.1"
}
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
# Frameworks portal
namespace :frameworks do
root to: "dashboards#index"
resources :frameworks, only: %i[index show new]
end

namespace :exit_survey do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "rails_helper"

describe "Agent can browse frameworks register", js: true do
include_context "with a framework evaluation agent"

before do
create(:frameworks_framework, provider_reference: "books", name: "Books & Stationary")
create(:frameworks_framework, provider_reference: "legal", name: "Legal services")
create(:frameworks_framework, provider_reference: "water", name: "Water services")
end

it "lists all frameworks" do
visit frameworks_root_path
expect(page).to have_summary("Framework Ref", "books")
expect(page).to have_summary("Framework Name", "Books & Stationary")
end
end
6 changes: 3 additions & 3 deletions spec/models/frameworks/framework/faf_importable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
provider_name: "Super Books LTD",
provider_url: "https://my.framework.com",
ends_at: 2.weeks.from_now,
description: "Description of books"
description: "Description of books",
)
end

Expand All @@ -30,7 +30,7 @@
existing_framework.reload
expect(existing_framework.provider_url).to eq("https://my.framework.com")
expect(existing_framework.name).to eq("Books, stationery and education supplies")
expect(existing_framework.ends_at).to eq(framework_data.ends_at)
expect(existing_framework.ends_at).to be_within(1.second).of(framework_data.ends_at)
expect(existing_framework.description).to eq("Description of books")
end
end
Expand All @@ -43,7 +43,7 @@
new_framework = Frameworks::Framework.where(provider_reference: "books").first
expect(new_framework.provider_url).to eq("https://my.framework.com")
expect(new_framework.name).to eq("Books, stationery and education supplies")
expect(new_framework.ends_at).to eq(framework_data.ends_at)
expect(new_framework.ends_at).to be_within(1.second).of(framework_data.ends_at)
expect(new_framework.description).to eq("Description of books")
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/support/shared/govuk_design_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RSpec::Matchers.define :have_summary do |label, text|
match do |page|
page.all(".govuk-summary-list__key", text: label).any? { |key| key.sibling(".govuk-summary-list__value", text:).present? }
end

failure_message do |page|
available_keys = page.all(".govuk-summary-list__key").map(&:text)
<<~MESSAGE
expected to find summary row with label "#{label}" and text "#{text}" but did not.
Found summary keys:
#{available_keys.join("\n")}
MESSAGE
end
end
4 changes: 4 additions & 0 deletions spec/support/shared/support_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
click_start
end
end

RSpec.shared_context "with a framework evaluation agent" do
include_context "with an agent", roles: [:framework_evaluator]
end

0 comments on commit 955befc

Please sign in to comment.