Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CatalinVoineag committed Jan 4, 2024
1 parent 1db3ad8 commit 7fda689
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gem "down", "~> 5.0"

# HTTP Request
gem "httparty"
gem 'pg_search'

group :development do
gem "annotate", require: false
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.4)
pg_search (2.3.6)
activerecord (>= 5.2)
activesupport (>= 5.2)
prettier_print (1.2.1)
propshaft (0.8.0)
actionpack (>= 7.0.0)
Expand Down Expand Up @@ -551,6 +554,7 @@ DEPENDENCIES
omniauth-rails_csrf_protection
omniauth_openid_connect
pg (~> 1.1)
pg_search
prettier_print
propshaft
pry
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Claims::Support::GiasSchoolSuggestionsController < ApplicationController
def index
gias_schools = GiasSchool.search_scope(query_params)
render json: gias_schools.map { |school| formatted_school(school) }
end

private

def query_params
params.require(:query).downcase
end

def formatted_school(school)
{
urn: school.urn,
name: school.name,
}
end
end
28 changes: 28 additions & 0 deletions app/controllers/claims/support/schools_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
class Claims::Support::SchoolsController < Claims::Support::ApplicationController
def new
@school = Claims::School.new
end

def create
school = gias_school.school || gias_school.build_school
school.claims = true

if school.save
redirect_to claims_support_schools_path
else
render :new
end
end

def check
@school = gias_school
end

private

def gias_school
@gias_school ||= GiasSchool.find_by_urn(gias_school_urn)
end

def gias_school_urn
params[:gias_school_urn] || params.dig(:gias_school, :urn)
end
end
3 changes: 3 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { initAll } from "govuk-frontend";
import autocompleteSetup from "./autocomplete";
import accreditedProviderAutocompleteSetup from "./accredited_provider";
import giasSchoolAutocompleteSetup from "./gias_school_autocomplete";

initAll();
autocompleteSetup();
accreditedProviderAutocompleteSetup();
accreditedProviderAutocompleteSetup();
giasSchoolAutocompleteSetup();
28 changes: 28 additions & 0 deletions app/javascript/gias_school_autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import initAutocomplete from "./autocomplete";

const giasSchoolTemplate = (result) => result && result.name;
const giasSchoolSuggestionTemplate = (result) =>
result && `${result.name}`;
const onConfirm = (input) => (option) =>
(input.value = option ? option.urn : "");

function init() {
const options = {
path: `/support/gias_school_suggestions`,
template: {
inputValue: giasSchoolTemplate,
suggestion: giasSchoolSuggestionTemplate,
},
minLength: 2,
inputName: "gias_school_urn",
onConfirm,
};

initAutocomplete(
"gias-school-autocomplete",
"gias-school-search-form-query-field",
options,
);
}

export default init;
21 changes: 21 additions & 0 deletions app/models/gias_school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,30 @@
# index_gias_schools_on_urn (urn) UNIQUE
#
class GiasSchool < ApplicationRecord
include PgSearch::Model
has_one :school, foreign_key: :urn, primary_key: :urn

validates :urn, presence: true
validates :urn, uniqueness: { case_sensitive: false }
validates :name, presence: true


#pg_search_scope :search_scope,
# against: [:code, :name],
# using: {
# tsearch: {only: [:code, :name]},
# trigram: {
# only: [:code, :name],
# threshold: 0.7,
# word_similarity: true
# }
# }
pg_search_scope :search_scope,
against: [:name, :postcode, :urn],
using: {
tsearch: {only: [:name, :postcode, :urn]},
#trigram: {
# only: [:name, :postcode, :urn, :ukprn]
#},
}
end
83 changes: 83 additions & 0 deletions app/views/claims/support/schools/check.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: new_claims_support_school_path) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with(model: @school, url: claims_support_schools_path, method: "post", data: { turbo: false }) do |f| %>
<%= f.hidden_field :urn, value: @school.urn %>

<label class="govuk-label govuk-label--l">
<span class="govuk-caption-l"><%= t(".add_organisation") %></span>
<%= t(".title") %>
</label>

<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= t(".organisation_name") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @school.name %>
</dd>
</div>

<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">
<%= t(".urn") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @school.urn %>
</dd>
</div>
</dl>

<h2 class="govuk-heading-m govuk-!-margin-top-7">
<%= t(".contact_details") %>
</h2>
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">
<%= t(".telephone") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @school.telephone %>
</dd>
</div>

<div class="govuk-summary-list__row govuk-summary-list__row--no-actions">
<dt class="govuk-summary-list__key">
<%= t(".website") %>
</dt>
<dd class="govuk-summary-list__value">
<%= @school.website %>
</dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= t(".address") %>
</dt>
<dd class="govuk-summary-list__value">
<p class="govuk-body">
<%= @school.address1 %>
<br>
<%= @school.address2 %>
<br>
<%= @school.address3 %>
<br>
<%= @school.town %>
<br>
<%= @school.postcode %>
</p>
</dd>
</div>
</dl>

<%= f.govuk_submit t(".add_organisation") %>
<p class="govuk-body">
<%= govuk_link_to(t(".cancel"), claims_support_schools_path) %>
</p>
<% end %>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/claims/support/schools/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Support / Schools

<%= govuk_button_to(t("add_organisation"), new_claims_support_school_path, method: :get) %>

<ul>
<li><%= link_to "School 1", claims_support_school_path(1) %></li>
</ul>
30 changes: 30 additions & 0 deletions app/views/claims/support/schools/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= content_for(:before_content) do %>
<%= govuk_back_link(href: root_path) %>
<% end %>

<%= form_with(model: @school, url: check_claims_support_schools_path, method: "get", data: { turbo: false }) do |f| %>
<%= f.govuk_error_summary %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-form-group">
<%= f.label :query, { class: "govuk-label govuk-label--l", for: "gias-school-search-form-query-field" } do %>
<span class="govuk-caption-l"><%= t(".caption") %></span>
<%= t(".title") %>
<% end %>

<%= f.text_field :query,
id: "gias-school-search-form-query-field",
value: params[:query],
class: "govuk-input" %>
<div id="gias-school-autocomplete" class="govuk-!-margin-bottom-7"></div>
</div>

<%= f.govuk_submit t("continue") %>

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), root_path) %>
</p>
</div>
</div>
<% end %>
3 changes: 3 additions & 0 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
namespace :support do
root to: redirect("/support/schools")

# should we restrict with only, except here?
resources :schools do
collection { get :check }
resources :claims
resources :users
end
resources :gias_school_suggestions, only: [:index]
end
end

0 comments on commit 7fda689

Please sign in to comment.