generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fworks): frameworks can be categorised
- Loading branch information
Showing
28 changed files
with
191 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Frameworks::CategorisationsController < Frameworks::ApplicationController | ||
def edit | ||
@framework = Frameworks::Framework.find(params[:framework_id]) | ||
end | ||
|
||
def update | ||
@framework = Frameworks::Framework.find(params[:framework_id]) | ||
|
||
@framework.update!(category_params) | ||
|
||
redirect_to @framework | ||
end | ||
|
||
private | ||
|
||
def category_params | ||
params.require(:frameworks_framework).permit(support_category_ids: []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Frameworks::ActivityEvent < ApplicationRecord | ||
include Frameworks::Activity | ||
|
||
def loaded_data | ||
OpenStruct.new(**data, **activity_log_item.subject.try(:activity_event_data_for, self).presence || {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/models/frameworks/framework/activity_event_loggable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Frameworks::Framework::ActivityEventLoggable | ||
extend ActiveSupport::Concern | ||
|
||
def activity_event_data_for(activity_event) | ||
case activity_event.event | ||
when "framework_category_added", "framework_category_removed" | ||
{ support_category: Support::Category.find(activity_event.data["support_category_id"]) } | ||
end | ||
end | ||
|
||
protected | ||
|
||
def log_framework_category_added(category) | ||
log_activity_event("framework_category_added", support_category_id: category.id) | ||
end | ||
|
||
def log_framework_category_removed(category) | ||
log_activity_event("framework_category_removed", support_category_id: category.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Frameworks::FrameworkCategory < ApplicationRecord | ||
belongs_to :support_category, class_name: "Support::Category" | ||
belongs_to :framework | ||
end |
4 changes: 4 additions & 0 deletions
4
app/views/frameworks/activity_log_items/activity/_activity_event.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= render "frameworks/activity_log_items/activity/activity_event/#{activity_log_item.activity.event}", | ||
activity_log_item:, | ||
activity: activity_log_item.activity, | ||
subject: activity_log_item.subject %> |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
.../frameworks/activity_log_items/activity/activity_event/_framework_category_added.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added category "<%= activity.loaded_data.support_category.title %>" to framework |
1 change: 1 addition & 0 deletions
1
...rameworks/activity_log_items/activity/activity_event/_framework_category_removed.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Removed category "<%= activity.loaded_data.support_category.title %>" from framework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%= content_for :title, "GHBS | Frameworks | Edit Framework Categories" %> | ||
|
||
<span class="govuk-caption-l">Edit Framework Categories</span> | ||
<h1 class="govuk-heading-l"><%= @framework.name %></h2> | ||
|
||
<%= form_for @framework, url: frameworks_framework_categorisations_path(@framework), method: :put do |f| %> | ||
|
||
<% procurement_category_grouped_options.each do |group, options| %> | ||
<% next if group == "Or" %> | ||
|
||
<%= f.govuk_check_boxes_fieldset :support_category_ids, legend: { text: group, size: "s" } do %> | ||
<% options.each do |category| %> | ||
<%= f.govuk_check_box :support_category_ids, category[1], label: { text: category[0] } %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="govuk-button-group flex-align-center"> | ||
<%= f.govuk_submit "Save changes" %> | ||
<%= link_to "Cancel", @framework, class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
db/migrate/20230915092131_create_frameworks_framework_categories.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateFrameworksFrameworkCategories < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :frameworks_framework_categories, id: :uuid do |t| | ||
t.uuid :support_category_id, null: false, foreign_key: true | ||
t.uuid :framework_id, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
|
||
remove_column :frameworks_frameworks, :support_category_id, :uuid | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20230915110928_create_frameworks_activity_events.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateFrameworksActivityEvents < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :frameworks_activity_events, id: :uuid do |t| | ||
t.string :event | ||
t.jsonb :data | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryBot.define do | ||
factory :frameworks_activity_event, class: "Frameworks::ActivityEvent" do | ||
event { 1 } | ||
data { "" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryBot.define do | ||
factory :frameworks_framework_category, class: "Frameworks::FrameworkCategory" do | ||
support_category { nil } | ||
framework { nil } | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
spec/features/frameworks/register/agent_can_categorise_framework_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "rails_helper" | ||
|
||
describe "Agent can categorise framework", js: true do | ||
include_context "with a framework evaluation agent" | ||
|
||
let(:framework) { create(:frameworks_framework) } | ||
|
||
before { define_basic_categories } | ||
|
||
it "saves the categories" do | ||
visit frameworks_framework_path(framework) | ||
within ".govuk-summary-list__row", text: "Categories" do | ||
click_on "Change" | ||
end | ||
check "Laptops" | ||
check "Electricity" | ||
click_on "Save changes" | ||
|
||
expect(page).to have_summary("Categories", "Laptops, Electricity") | ||
click_on "History" | ||
expect(page).to have_content('Added category "Laptops" to framework') | ||
expect(page).to have_content('Added category "Electricity" to framework') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Frameworks::ActivityEvent, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters