-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1254 from alphagov/controls-mvp-1
Add basic scaffolding for Boosts
- Loading branch information
Showing
17 changed files
with
565 additions
and
2 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
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,51 @@ | ||
class BoostsController < ApplicationController | ||
def index | ||
@boosts = Boost.order(:name) | ||
end | ||
|
||
def show | ||
@boost = Boost.find(params[:id]) | ||
end | ||
|
||
def new | ||
@boost = Boost.new | ||
end | ||
|
||
def create | ||
@boost = Boost.new(boost_params) | ||
if @boost.save | ||
redirect_to @boost, notice: "Boost created successfully" | ||
else | ||
render "new", status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def edit | ||
@boost = Boost.find(params[:id]) | ||
end | ||
|
||
def update | ||
@boost = Boost.find(params[:id]) | ||
if @boost.update(boost_params) | ||
redirect_to @boost, notice: "Boost updated successfully" | ||
else | ||
render "edit", status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@boost = Boost.find(params[:id]) | ||
|
||
if @boost.destroy | ||
redirect_to boosts_path, notice: "Boost deleted successfully" | ||
else | ||
redirect_to @boost, alert: "Boost could not be deleted. Try again later." | ||
end | ||
end | ||
|
||
private | ||
|
||
def boost_params | ||
params.require(:boost).permit(:name, :active, :boost_amount, :filter) | ||
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,13 @@ | ||
module BoostsHelper | ||
def boost_status_tag(boost) | ||
if boost.active? | ||
content_tag(:span, "Active", class: "govuk-tag govuk-tag--blue") | ||
else | ||
content_tag(:span, "Not active", class: "govuk-tag govuk-tag--grey") | ||
end | ||
end | ||
|
||
def filter_expression_code(boost) | ||
content_tag(:code, boost.filter, class: "app-filter-expression") | ||
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 @@ | ||
class Boost < ApplicationRecord | ||
validates :name, :filter, presence: true | ||
validates :boost_amount, numericality: { | ||
greater_than_or_equal_to: -1.0, less_than_or_equal_to: 1.0 | ||
} | ||
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,59 @@ | ||
<%= form_for(boost) do |f| %> | ||
<% if boost.errors.any? %> | ||
<%= render "govuk_publishing_components/components/error_summary", { | ||
id: "error-summary", | ||
title: "There is a problem", | ||
description: "The boost could not be updated because some fields are missing or incorrect.", | ||
items: error_summary_items(boost) | ||
} %> | ||
<% end %> | ||
|
||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: Boost.human_attribute_name(:name) | ||
}, | ||
id: "boost_name", | ||
name: "boost[name]", | ||
value: boost.name, | ||
error_items: error_items(boost, :name) | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: Boost.human_attribute_name(:boost_amount) | ||
}, | ||
hint: "A value between -1.0 and 1.0 used to influence the order of search results.", | ||
id: "boost_boost_amount", | ||
name: "boost[boost_amount]", | ||
value: boost.boost_amount, | ||
error_items: error_items(boost, :boost_amount) | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/textarea", { | ||
label: { | ||
text: Boost.human_attribute_name(:filter) | ||
}, | ||
hint: "Determines which documents are affected by this boost. See #{link_to 'Vertex AI Search filter syntax', 'https://cloud.google.com/retail/docs/filter-and-order#filter', class: 'govuk-link'} for details.".html_safe, | ||
id: "boost_filter", | ||
name: "boost[filter]", | ||
value: boost.filter, | ||
error_items: error_items(boost, :filter) | ||
} %> | ||
|
||
<%= hidden_field_tag "boost[active]", "0" %> | ||
<%= render "govuk_publishing_components/components/checkboxes", { | ||
name: "boost[active]", | ||
items: [ | ||
{ | ||
label: Boost.human_attribute_name(:active), | ||
hint: "Boosts that are not active will not affect search results.", | ||
value: "1", | ||
checked: boost.active? | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Save" | ||
} %> | ||
<% 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,19 @@ | ||
<%= render "govuk_publishing_components/components/breadcrumbs", { | ||
breadcrumbs: [ | ||
{ | ||
title: "Boosts", | ||
url: boosts_path | ||
}, | ||
{ | ||
title: @boost.name, | ||
url: boost_path(@boost) | ||
}, | ||
{ | ||
title: "Edit" | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "common/page_title", title: @boost.name %> | ||
|
||
<%= render "form", boost: @boost %> |
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,42 @@ | ||
<%= render "common/page_title", title: "Boosts" %> | ||
|
||
<div class="actions"> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "New boost", | ||
href: new_boost_path, | ||
inline_layout: true | ||
} %> | ||
</div> | ||
|
||
<div class="govuk-!-margin-top-6 app-table__container" data-module="filterable-table"> | ||
<% if @boosts.any? %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "Filter boosts" | ||
}, | ||
name: "table-filter", | ||
type: "search", | ||
search_icon: true, | ||
tabindex: 0 | ||
} %> | ||
|
||
<div> | ||
<%= GovukPublishingComponents::AppHelpers::TableHelper.helper(self) do |t| %> | ||
<%= t.head do %> | ||
<%= t.header Boost.human_attribute_name(:name) %> | ||
<%= t.header "Status" %> | ||
<% end %> | ||
<%= t.body do %> | ||
<% @boosts.each do |boost| %> | ||
<%= t.row do %> | ||
<%= t.cell link_to(boost.name, boost_path(boost), class:'govuk-link') %> | ||
<%= t.cell boost_status_tag(boost) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% else %> | ||
<p class="govuk-body">No boosts have been set up yet.</p> | ||
<% end %> | ||
</div> |
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,15 @@ | ||
<%= render "govuk_publishing_components/components/breadcrumbs", { | ||
breadcrumbs: [ | ||
{ | ||
title: "Boosts", | ||
url: boosts_path | ||
}, | ||
{ | ||
title: "New boost" | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "common/page_title", title: "New boost" %> | ||
|
||
<%= render "form", boost: @boost %> |
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,47 @@ | ||
<%= render "govuk_publishing_components/components/breadcrumbs", { | ||
breadcrumbs: [ | ||
{ | ||
title: "Boosts", | ||
url: boosts_path | ||
}, | ||
{ | ||
title: @boost.name, | ||
} | ||
] | ||
} %> | ||
|
||
<%= render "common/page_title", title: @boost.name %> | ||
|
||
<div class="actions"> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Edit boost", | ||
href: edit_boost_path(@boost), | ||
inline_layout: true | ||
} %> | ||
<%= delete_button "Delete boost", boost_path(@boost), is_inline: true %> | ||
</div> | ||
|
||
<%= render "govuk_publishing_components/components/summary_list", { | ||
items: [ | ||
{ | ||
field: "Status", | ||
value: boost_status_tag(@boost) | ||
}, | ||
{ | ||
field: Boost.human_attribute_name(:boost_amount), | ||
value: @boost.boost_amount | ||
}, | ||
{ | ||
field: Boost.human_attribute_name(:filter), | ||
value: filter_expression_code(@boost) | ||
}, | ||
{ | ||
field: Boost.human_attribute_name(:created_at), | ||
value: @boost.created_at.to_formatted_s(:govuk_date) | ||
}, | ||
{ | ||
field: Boost.human_attribute_name(:updated_at), | ||
value: @boost.updated_at.to_formatted_s(:govuk_date) | ||
} | ||
] | ||
} %> |
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,12 @@ | ||
class CreateBoosts < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :boosts do |t| | ||
t.string :name, null: false | ||
t.boolean :active, null: false | ||
t.float :boost_amount, null: false | ||
t.text :filter, null: false | ||
|
||
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
Oops, something went wrong.