Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Provider partnerships to training partners #4842

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/components/add_course_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if required_organisation_details_present? %>
<%= govuk_button_link_to(
"Add course",
t("components.add_course_button.add_course"),
new_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: provider.recruitment_cycle_year
Expand All @@ -11,11 +11,11 @@
<% else %>

<div class="govuk-inset-text">
<p class="govuk-body">Before adding a course, you need to:</p>
<p class="govuk-body"><%= t("components.add_course_button.before_adding") %></p>
<ul class="govuk-list govuk-list--bullet">
<% incomplete_sections.each do |section| %>
<li>
<%= govuk_link_to(section.name, section.path) %>
<%= govuk_link_to(section.text, section.path) %>
</li>
<% end %>
</ul>
Expand Down
60 changes: 18 additions & 42 deletions app/components/add_course_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,42 @@ class AddCourseButton < ViewComponent::Base
include RecruitmentCycleHelper
attr_reader :provider

Section = Struct.new(:name, :path, keyword_init: true)
Section = Struct.new(:text, :path, keyword_init: true)

def initialize(provider:)
@provider = provider
super
@provider = provider
end

private

def incomplete_sections
incomplete_sections_hash.keys.select { |section| send(section) }.map do |section|
Section.new(name: "add #{incomplete_section_article(section)} #{incomplete_section_label_suffix(section)}", path: incomplete_sections_hash[section])
end
end

def incomplete_sections_hash
{
site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year),
accredited_provider_not_present?: publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, provider.recruitment_cycle_year)
}
end

def incomplete_section_label_suffix(section)
labels = {
accredited_provider_not_present?: 'accredited provider',
site_not_present?: 'school'
}

labels[section]
def required_organisation_details_present?
incomplete_sections.empty?
end

def required_organisation_details_present?
accredited_provider_present? && site_present?
def incomplete_sections
@incomplete_sections ||= [school, accredited_provider].compact
end

def accredited_provider_present?
return true if accredited_provider?
private

provider.accredited_providers.any?
end
def accredited_provider
return if accredited_partner_present?

def site_present?
provider.sites.any?
Section.new(text: t('components.add_course_button.add_accredited_provider'), path: publish_provider_recruitment_cycle_accredited_partnerships_path(provider.provider_code, provider.recruitment_cycle_year))
end

def accredited_provider_not_present?
return false if provider.accredited?
def school
return if school_present?

!accredited_provider_present?
Section.new(text: t('components.add_course_button.add_school'), path: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year))
end

def site_not_present?
!site_present?
end
def accredited_partner_present?
return true if provider.accredited?

def accredited_provider?
provider.accredited?
provider.accredited_partners.any?
end

def incomplete_section_article(section)
incomplete_section_label_suffix(section) == 'accredited provider' ? 'an' : 'a'
def school_present?
provider.sites.any?
end
end
23 changes: 23 additions & 0 deletions app/components/add_course_button_enrichments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if required_organisation_details_present? %>
<%= govuk_button_link_to(
"Add course",
new_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: provider.recruitment_cycle_year
),
class: "govuk-!-margin-bottom-6"
) %>

<% else %>

<div class="govuk-inset-text">
<p class="govuk-body">Before adding a course, you need to:</p>
<ul class="govuk-list govuk-list--bullet">
<% incomplete_sections.each do |section| %>
<li>
<%= govuk_link_to(section.name, section.path) %>
</li>
<% end %>
</ul>
</div>
<% end %>
69 changes: 69 additions & 0 deletions app/components/add_course_button_enrichments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# frozen_string_literal: true

class AddCourseButtonEnrichments < ViewComponent::Base
include RecruitmentCycleHelper
attr_reader :provider

Section = Struct.new(:name, :path, keyword_init: true)

def initialize(provider:)
@provider = provider
super
end

private

def incomplete_sections
incomplete_sections_hash.keys.select { |section| send(section) }.map do |section|
Section.new(name: "add #{incomplete_section_article(section)} #{incomplete_section_label_suffix(section)}", path: incomplete_sections_hash[section])
end
end

def incomplete_sections_hash
{
site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year),
accredited_provider_not_present?: publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, provider.recruitment_cycle_year)
}
end

def incomplete_section_label_suffix(section)
labels = {
accredited_provider_not_present?: 'accredited provider',
site_not_present?: 'school'
}

labels[section]
end

def required_organisation_details_present?
accredited_provider_present? && site_present?
end

def accredited_provider_present?
return true if accredited_provider?

provider.accredited_providers.any?
Copy link
Contributor

@tomas-stefano tomas-stefano Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provider.accredited_providers.any?
accredited_provider? || provider.accredited_providers.any?

end

def site_present?
provider.sites.any?
end

def accredited_provider_not_present?
return false if provider.accredited?

!accredited_provider_present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting deleted after the switch to provider partnerships

end

def site_not_present?
!site_present?
end

def accredited_provider?
provider.accredited?
end

def incomplete_section_article(section)
incomplete_section_label_suffix(section) == 'accredited provider' ? 'an' : 'a'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Publish
module Providers
module TrainingPartners
class CourseExportsController < ApplicationController
def index
authorize(provider, :can_list_training_providers?)

respond_to do |format|
format.csv do
send_data(data_export.data, filename: data_export.filename, disposition: :attachment)
end
end
end

private

def courses
@courses ||= provider.current_accredited_courses
end

def data_export
@data_export ||= Exports::AccreditedCourseList.new(courses:)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Publish
module Providers
module TrainingPartners
class CoursesController < ApplicationController
def index
authorize(provider, :index?)

@courses = fetch_courses
end

private

def training_partner
@training_partner ||= provider.training_partners.find_by(provider_code: params[:training_partner_code])
end

def fetch_courses
training_partner
.courses
.includes(:enrichments, :site_statuses, provider: [:recruitment_cycle])
.where(accredited_provider_code: provider.provider_code)
.order(:name)
.map(&:decorate)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Publish
module Providers
class TrainingPartnersController < ApplicationController
def index
authorize(provider, :can_list_training_providers?)

@training_partners = provider.training_partners.include_accredited_courses_counts(provider.provider_code).order(:provider_name)
@course_counts = @training_partners.to_h { |p| [p.provider_code, p.accredited_courses_count] }
end
end
end
end
10 changes: 7 additions & 3 deletions app/helpers/breadcrumb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ def training_providers_breadcrumb
end

def training_provider_courses_breadcrumb
path = publish_provider_recruitment_cycle_training_provider_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_provider.provider_code)
training_providers_breadcrumb.merge({ "#{@training_provider.provider_name}’s courses" => path })
if Settings.features.provider_partnerships
path = publish_provider_recruitment_cycle_training_partner_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_partner.provider_code)
training_providers_breadcrumb.merge({ "#{@training_partner.provider_name}’s courses" => path })
else
path = publish_provider_recruitment_cycle_training_provider_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_provider.provider_code)
training_providers_breadcrumb.merge({ "#{@training_provider.provider_name}’s courses" => path })
end
end

# rubocop:enable Rails/HelperInstanceVariable
end
2 changes: 2 additions & 0 deletions app/helpers/navigation_bar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def navigation_items(provider)
def partnership_link(provider)
if Settings.features.provider_partnerships && !provider.accredited?
{ name: t('navigation_bar.accredited_partnerships'), url: publish_provider_recruitment_cycle_accredited_partnerships_path(provider.provider_code, provider.recruitment_cycle_year) }
elsif Settings.features.provider_partnerships && provider.accredited?
{ name: t('navigation_bar.training_partners'), url: publish_provider_recruitment_cycle_training_partners_path(provider.provider_code, provider.recruitment_cycle_year) }
elsif provider.accredited?
{ name: t('navigation_bar.training_partners'), url: publish_provider_recruitment_cycle_training_providers_path(provider.provider_code, provider.recruitment_cycle_year) }
else
Expand Down
5 changes: 4 additions & 1 deletion app/views/publish/courses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<%= content_for :before_content, render_breadcrumbs(:courses) %>

<h1 class="govuk-heading-l">Courses</h1>

<% if Settings.features.provider_partnerships %>
<%= render AddCourseButton.new(provider: @provider) %>
<% else %>
<%= render AddCourseButtonEnrichments.new(provider: @provider) %>
<% end %>

<% if @self_accredited_courses %>
<section data-qa="courses__table-section">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% content_for :page_title, @provider.provider_name %>
<%= content_for :before_content, render_breadcrumbs(:training_provider_courses) %>

<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= t(".title") %></span>
<%= @training_partner.provider_name %>
</h1>

<section data-qa="courses__table-section">
<%= render partial: "publish/courses/course_table", locals: { courses: @courses } %>
</section>
65 changes: 65 additions & 0 deletions app/views/publish/providers/training_partners/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<% content_for :page_title, "Training partners" %>
<%= content_for :before_content, render_breadcrumbs(:training_providers) %>

<h1 class="govuk-heading-l">
<%= t(".title") %>
</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<ul class="govuk-list" data-qa="provider__training_partners_list">
<% @training_partners.each do |training_partner| %>
<li data-qa="training_partner">
<h3 class="govuk-heading-s">
<% if Settings.features.provider_partnerships %>
<%= govuk_link_to(
training_partner.provider_name,
publish_provider_recruitment_cycle_training_partner_courses_path(
@provider.provider_code,
@provider.recruitment_cycle_year,
training_partner.provider_code
),
class: "govuk-!-font-weight-bold",
data: { qa: "training_partner_name" }
) %>
<% else %>
<%= govuk_link_to(
training_partner.provider_name,
publish_provider_recruitment_cycle_training_provider_courses_path(
@provider.provider_code,
@provider.recruitment_cycle_year,
training_partner.provider_code
),
class: "govuk-!-font-weight-bold",
data: { qa: "training_partner_name" }
) %>
<% end %>
<span class="govuk-hint govuk-!-display-inline" data-qa="course_count">
<%= pluralize(@course_counts[training_partner.provider_code], "course") %>
</span>
</h3>
</li>
<% end %>
</ul>
</div>

<% unless @training_partners.empty? %>
<aside class="govuk-grid-column-one-third">
<div class="app-status-box" data-qa="download-section">
<h2 class="govuk-heading-m"><%= t(".download") %></h2>
<p class="govuk-body"><%= t(".export") %></p>
<p class="govuk-body">
<%= govuk_link_to(
t(".download_file"),
download_training_providers_courses_publish_provider_recruitment_cycle_path(
@provider.provider_code,
@provider.recruitment_cycle_year,
format: :csv
)
) %>
</p>
</div>
</aside>
<% end %>
</div>
Loading
Loading