Skip to content

Commit

Permalink
feat(fworks): crud of framework entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Sep 14, 2023
1 parent 5e40d9a commit 969de62
Show file tree
Hide file tree
Showing 28 changed files with 310 additions and 84 deletions.
3 changes: 2 additions & 1 deletion app/controllers/frameworks/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class Frameworks::ApplicationController < ApplicationController
include SupportAgents
before_action { Current.actor = current_agent }
before_action :set_back_url

private

def authorize_agent_scope = :access_frameworks_portal?
def portal_namespace = :frameworks

def set_back_url
@back_url = back_link_param
@back_url = back_link_param if back_link_param.present?
end
end
17 changes: 15 additions & 2 deletions app/controllers/frameworks/frameworks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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]
before_action :load_form_options, only: %i[new create]
before_action :load_form_options, only: %i[new edit create update]

def new
@framework = Frameworks::Framework.new
end

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

def index
@filtering = Frameworks::Framework.filtering(filter_form_params)
@frameworks = @filtering.results.paginate(page: params[:frameworks_page])
Expand All @@ -27,6 +30,16 @@ def create
end
end

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

if @framework.update(framework_params)
redirect_to frameworks_framework_path(@framework)
else
render :edit
end
end

private

def load_form_options
Expand Down
22 changes: 20 additions & 2 deletions app/controllers/frameworks/provider_contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Frameworks::ProviderContactsController < Frameworks::ApplicationController
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index
before_action :set_back_url, only: %i[show edit]
before_action :load_form_options, only: %i[new edit update create]

def index
@filtering = Frameworks::ProviderContact.filtering(filter_form_params)
Expand All @@ -12,10 +12,24 @@ def show
@activity_log_items = @provider_contact.activity_log_items.paginate(page: params[:activities_page])
end

def new
@provider_contact = Frameworks::ProviderContact.new
end

def edit
@provider_contact = Frameworks::ProviderContact.find(params[:id])
end

def create
@provider_contact = Frameworks::ProviderContact.new(provider_contact_params)

if @provider_contact.save
redirect_to frameworks_provider_contact_path(@provider_contact)
else
render :new
end
end

def update
@provider_contact = Frameworks::ProviderContact.find(params[:id])

Expand All @@ -28,12 +42,16 @@ def update

private

def load_form_options
@providers = Frameworks::Provider.all
end

def filter_form_params
params.fetch(:provider_contacts_filter, {}).permit(:sort_by, :sort_order, provider: [])
end

def provider_contact_params
params.require(:frameworks_provider_contact).permit(:name, :email, :phone)
params.require(:frameworks_provider_contact).permit(:name, :email, :phone, :provider_id)
end

def redirect_to_register_tab
Expand Down
33 changes: 32 additions & 1 deletion app/controllers/frameworks/providers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Frameworks::ProvidersController < Frameworks::ApplicationController
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index
before_action :set_back_url, only: %i[new show]

def index
@filtering = Frameworks::Provider.filtering(filter_form_params)
Expand All @@ -12,8 +11,40 @@ def show
@activity_log_items = @provider.activity_log_items.paginate(page: params[:activities_page])
end

def new
@provider = Frameworks::Provider.new
end

def edit
@provider = Frameworks::Provider.find(params[:id])
end

def create
@provider = Frameworks::Provider.new(provider_params)

if @provider.save
redirect_to frameworks_provider_path(@provider)
else
render :new
end
end

def update
@provider = Frameworks::Provider.find(params[:id])

if @provider.update(provider_params)
redirect_to frameworks_provider_path(@provider)
else
render :edit
end
end

private

def provider_params
params.require(:frameworks_provider).permit(:name, :short_name)
end

def filter_form_params
params.fetch(:providers_filter, {}).permit(
:sort_by, :sort_order
Expand Down
2 changes: 1 addition & 1 deletion app/models/frameworks/provider/sortable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def sorted_by(sort_by:, sort_order:)

def available_sort_options
[
["Short Name", "short_name"]
["Short Name", "short_name"],
]
end

Expand Down
1 change: 1 addition & 0 deletions app/models/frameworks/provider_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class Frameworks::ProviderContact < ApplicationRecord

validates :name, presence: true
validates :email, presence: true
validates :provider_id, presence: true
end
53 changes: 53 additions & 0 deletions app/views/frameworks/frameworks/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<%= f.govuk_fieldset legend: { text: 'Basic Details' } do %>
<%= f.govuk_text_field :name %>
<%= f.govuk_text_field :short_name, width: "one-third", label: { text: "Abbreviated name" } %>
<%= f.govuk_text_field :url, label: { text: "Providers URL" } %>
<%= f.govuk_text_field :reference, width: "one-third", label: { text: "Providers reference" } %>
<% end %>

<div data-controller="select-option-filter" data-select-option-filter-param-name-value="providerId">
<%= f.govuk_select :provider_id, @providers.map {|provider| [provider.short_name, provider.id] },
"data-select-option-filter-target" => "input",
options: { include_blank: "Select a provider" },
label: { text: "Provider" } %>

<%= f.govuk_select :provider_contact_id, @provider_contacts.map {|contact| [contact.display_name, contact.id, { "data-provider-id" => contact.provider_id }] },
"data-select-option-filter-target" => "output",
options: { include_blank: "Select a contact" },
label: { text: "Provider contact" } %>
</div>

<%= f.govuk_fieldset legend: { text: 'Availability' } do %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half" id="dfe-start-date">
<%= f.govuk_date_field :dfe_start_date, legend: { size: "s", text: "DfE start date", class: "" } %>
</div>
<div class="govuk-grid-column-one-half" id="dfe-end-date">
<%= f.govuk_date_field :dfe_end_date, legend: { size: "s", text: "DfE end date", class: "" } %>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half" id="provider-start-date">
<%= f.govuk_date_field :provider_start_date, legend: { size: "s", text: "Provider start date" } %>
</div>
<div class="govuk-grid-column-one-half" id="provider-end-date">
<%= f.govuk_date_field :provider_end_date, legend: { size: "s", text: "Provider end date" } %>
</div>
</div>
<% end %>

<%= f.govuk_fieldset legend: { text: 'Other' } do %>
<% dps_options = [[true, 'Yes'], [false, 'No']] %>
<%= f.govuk_collection_radio_buttons :dps, dps_options, :first, :last, inline: true, legend: { size: 's', text: 'Is this framework a DPS (Dynamic purchasing system)?' } %>

<% lot_options = [['single', 'Single-lot'], ['multi', 'Multi-lot']] %>
<%= f.govuk_collection_radio_buttons :lot, lot_options, :first, :last, inline: true, legend: { size: 's', text: 'Is this framework a single or multi lot?' } %>

<% status_options = Frameworks::Framework.statuses.map {|status, id| [status, status.humanize] } %>
<%= f.govuk_collection_radio_buttons :status, status_options, :first, :last, legend: { size: 's', text: 'Approval Status' } %>
<% end %>

<div class="govuk-button-group flex-align-center">
<%= f.govuk_submit submit %>
<%= link_to "Cancel", @framework, class: "govuk-link govuk-link--no-visited-state" %>
</div>
2 changes: 2 additions & 0 deletions app/views/frameworks/frameworks/_index_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<h2 class="govuk-heading-m"><%= I18n.t("support.case.label.filters") %></h2>

<%= form_with model: @filtering, scope: :frameworks_filter, method: :get, url: frameworks_frameworks_path, html: { "data-controller" => "case-filters" } do |form| %>
<input type="hidden" name="viewing_from_entity" value="<%= params[:viewing_from_entity] %>">

<%= link_to I18n.t("support.case.filter.buttons.clear"), frameworks_frameworks_path(viewing_from_entity: params[:viewing_from_entity]), class: "govuk-button govuk-button--secondary", role: "button" %>

<%= form.govuk_select :sort_by,
Expand Down
14 changes: 14 additions & 0 deletions app/views/frameworks/frameworks/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= content_for :title, "GHBS | Frameworks | Edit Framework" %>

<%= turbo_frame_tag dom_id(@framework) do %>

<span class="govuk-caption-l">Edit Framework</span>
<h1 class="govuk-heading-l"><%= @framework.name %></h2>

<div class="govuk-!-width-two-thirds">
<%= form_for @framework do |f| %>
<%= render "frameworks/frameworks/form", f:, submit: "Save changes" %>
<% end %>
</div>

<% end %>
57 changes: 2 additions & 55 deletions app/views/frameworks/frameworks/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,7 @@
<h1 class="govuk-heading-l">New Framework</h1>

<div class="govuk-!-width-two-thirds">
<%= form_for @framework do |f| %>
<%= f.govuk_fieldset legend: { text: 'Basic Details' } do %>
<%= f.govuk_text_field :name %>
<%= f.govuk_text_field :short_name, width: "one-third", label: { text: "Abbreviated name" } %>
<%= f.govuk_text_field :url, label: { text: "Providers URL" } %>
<%= f.govuk_text_field :reference, width: "one-third", label: { text: "Providers reference" } %>
<%= form_for @framework do |f| %>
<%= render "frameworks/frameworks/form", f:, submit: "Create framework" %>
<% end %>

<div data-controller="select-option-filter" data-select-option-filter-param-name-value="providerId">
<%= f.govuk_select :provider_id, @providers.map {|provider| [provider.short_name, provider.id] },
"data-select-option-filter-target" => "input",
options: { include_blank: "Select a provider" },
label: { text: "Provider" } %>

<%= f.govuk_select :provider_contact_id, @provider_contacts.map {|contact| [contact.display_name, contact.id, { "data-provider-id" => contact.provider_id }] },
"data-select-option-filter-target" => "output",
options: { include_blank: "Select a contact" },
label: { text: "Provider contact" } %>
</div>

<%= f.govuk_fieldset legend: { text: 'Availability' } do %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half" id="dfe-start-date">
<%= f.govuk_date_field :dfe_start_date, legend: { size: "s", text: "DfE start date", class: "" } %>
</div>
<div class="govuk-grid-column-one-half" id="dfe-end-date">
<%= f.govuk_date_field :dfe_end_date, legend: { size: "s", text: "DfE end date", class: "" } %>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half" id="provider-start-date">
<%= f.govuk_date_field :provider_start_date, legend: { size: "s", text: "Provider start date" } %>
</div>
<div class="govuk-grid-column-one-half" id="provider-end-date">
<%= f.govuk_date_field :provider_end_date, legend: { size: "s", text: "Provider end date" } %>
</div>
</div>
<% end %>

<%= f.govuk_fieldset legend: { text: 'Other' } do %>
<% dps_options = [[true, 'Yes'], [false, 'No']] %>
<%= f.govuk_collection_radio_buttons :dps, dps_options, :first, :last, inline: true, legend: { size: 's', text: 'Is this framework a DPS (Dynamic purchasing system)?' } %>

<% lot_options = [['single', 'Single-lot'], ['multi', 'Multi-lot']] %>
<%= f.govuk_collection_radio_buttons :lot, lot_options, :first, :last, inline: true, legend: { size: 's', text: 'Is this framework a single or multi lot?' } %>

<% status_options = Frameworks::Framework.statuses.map {|status, id| [status, status.humanize] } %>
<%= f.govuk_collection_radio_buttons :status, status_options, :first, :last, legend: { size: 's', text: 'Approval Status' } %>
<% end %>

<div class="govuk-button-group flex-align-center">
<%= f.govuk_submit "Create framework" %>
<%= link_to "Cancel", @back_url, class: "govuk-link govuk-link--no-visited-state" %>
</div>

<% end %>
</div>
9 changes: 9 additions & 0 deletions app/views/frameworks/frameworks/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%= content_for :title, "GHBS | Frameworks | #{@framework.name}" %>

<%= turbo_frame_tag dom_id(@framework) do %>

<span class="govuk-caption-l"><%= @framework.reference_and_short_name %></span>
<h1 class="govuk-heading-l"><%= @framework.name %></h1>

Expand Down Expand Up @@ -36,3 +38,10 @@
</div>
<% end %>
</div>

<h2 class="govuk-heading-m">Actions</h2>
<ul class="govuk-list">
<li><%= link_to "Edit Framework", edit_frameworks_framework_path(@framework), class: "govuk-link" %></li>
</ul>

<% end %>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key govuk-!-width-one-third">Provider</dt>
<dd class="govuk-summary-list__value"><%= link_to @framework.provider_name, frameworks_provider_path(@framework.provider, back_to: current_url_b64(:framework_provider)), class: "govuk-link", "data-turbo" => false %></dd>
<dd class="govuk-summary-list__value"><%= link_to @framework.provider_name, frameworks_provider_path(@framework.provider, back_to: current_url_b64(:framework_provider)), class: "govuk-link", "data-turbo" => false if @framework.provider.present? %></dd>
</div>

<div class="govuk-summary-list__row">
Expand All @@ -11,7 +11,7 @@

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Owner</dt>
<dd class="govuk-summary-list__value"><%= link_to @framework.provider_framework_owner_name, frameworks_provider_contact_path(@framework.provider_contact, back_to: current_url_b64(:framework_provider)), class: "govuk-link", "data-turbo" => false %></dd>
<dd class="govuk-summary-list__value"><%= link_to @framework.provider_framework_owner_name, frameworks_provider_contact_path(@framework.provider_contact, back_to: current_url_b64(:framework_provider)), class: "govuk-link", "data-turbo" => false if @framework.provider_contact.present? %></dd>
</div>

<div class="govuk-summary-list__row">
Expand Down
12 changes: 12 additions & 0 deletions app/views/frameworks/provider_contacts/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= f.govuk_text_field :name %>
<%= f.govuk_text_field :email %>
<%= f.govuk_text_field :phone %>

<%= f.govuk_select :provider_id, @providers.map {|provider| [provider.short_name, provider.id] },
options: { include_blank: "Select a provider" },
label: { text: "Provider" } %>

<div class="govuk-button-group flex-align-center">
<%= f.govuk_submit submit %>
<%= link_to "Cancel", @provider_contact, class: "govuk-link govuk-link--no-visited-state" %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<h2 class="govuk-heading-m"><%= I18n.t("support.case.label.filters") %></h2>

<%= form_with model: @filtering, scope: :provider_contacts_filter, method: :get, url: frameworks_provider_contacts_path, html: { "data-controller" => "case-filters" } do |form| %>
<%= link_to I18n.t("support.case.filter.buttons.clear"), frameworks_provider_contacts_path, class: "govuk-button govuk-button--secondary", role: "button" %>
<input type="hidden" name="viewing_from_entity" value="<%= params[:viewing_from_entity] %>">

<%= link_to I18n.t("support.case.filter.buttons.clear"), frameworks_provider_contacts_path(viewing_from_entity: params[:viewing_from_entity]), class: "govuk-button govuk-button--secondary", role: "button" %>

<%= form.govuk_select :sort_by,
options_for_select(@filtering.available_sort_options, @filtering.sort_by),
Expand Down
9 changes: 1 addition & 8 deletions app/views/frameworks/provider_contacts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@

<div class="govuk-!-width-two-thirds">
<%= form_for @provider_contact do |f| %>
<%= f.govuk_text_field :name %>
<%= f.govuk_text_field :email %>
<%= f.govuk_text_field :phone %>

<div class="govuk-button-group flex-align-center">
<%= f.govuk_submit "Save changes" %>
<%= link_to "Cancel", @provider_contact, class: "govuk-link govuk-link--no-visited-state" %>
</div>
<%= render "frameworks/provider_contacts/form", f:, submit: "Save changes" %>
<% end %>
</div>
<% end %>
4 changes: 4 additions & 0 deletions app/views/frameworks/provider_contacts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<div id="provider-contacts" class="govuk-tabs__panel govuk-tabs__panel--hidden">
<div class="case-list govuk-grid-row">
<div class="govuk-grid-column-one-quarter">
<% unless params[:viewing_from_entity] == "true" %>
<%= link_to "Add Contact", new_frameworks_provider_contact_path(back_to: current_url_b64(:provider_contacts)), class: "govuk-button", "data-turbo" => false %>
<% end %>

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

Expand Down
Loading

0 comments on commit 969de62

Please sign in to comment.