-
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.
Vfep 958 - add ability to maintain keywords associated with accrediat…
…ion types (#1015) * refactor tests to run faster * further refactor tests for performance * Add accreditation action keyword functionality * fix rubocop error --------- Co-authored-by: nfstern02 <[email protected]>
- Loading branch information
Showing
44 changed files
with
1,976 additions
and
1,258 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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
class AccreditationTypeKeywordsController < ApplicationController | ||
before_action :set_accreditation_type, only: %i[index new destroy] | ||
|
||
# GET /accreditation_type_keywords | ||
def index | ||
@accreditation_type_keywords = | ||
AccreditationTypeKeyword | ||
.where(accreditation_type: @accreditation_type) | ||
.order(:keyword_match) | ||
end | ||
|
||
# GET /accreditation_type_keywords/new | ||
def new | ||
@accreditation_type_keyword = AccreditationTypeKeyword.new | ||
end | ||
|
||
# POST /accreditation_type_keywords | ||
def create | ||
@accreditation_type_keyword = AccreditationTypeKeyword.new(accreditation_type_keyword_params) | ||
@accreditation_type = @accreditation_type_keyword.accreditation_type | ||
|
||
if @accreditation_type_keyword.valid? | ||
@accreditation_type_keyword.save | ||
respond_to do |format| | ||
format.html { redirect_to accreditation_type_keywords_path } | ||
format.js | ||
end | ||
else | ||
respond_to do |format| | ||
format.html { redirect_to accreditation_type_keywords_path } | ||
format.js { render action: 'new_with_errors' } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /accreditation_type_keywords/1 | ||
def destroy | ||
@accreditation_type_keyword = AccreditationTypeKeyword.find(params[:id]) | ||
@accreditation_type = @accreditation_type_keyword.accreditation_type | ||
@accreditation_type_keyword.destroy | ||
respond_to do |format| | ||
format.html { redirect_to accreditation_type_keywords_path, notice: 'Keyword was successfully destroyed.' } | ||
format.js | ||
end | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_accreditation_type | ||
@accreditation_type = params[:accreditation_type] | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def accreditation_type_keyword_params | ||
params.require(:accreditation_type_keyword).permit(:accreditation_type, :keyword_match) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class AccreditationTypeKeyword < ApplicationRecord | ||
has_many(:accreditation_records, inverse_of: :accreditation_type_keyword, dependent: :nullify) | ||
|
||
# Order matters. The user should be asked about where to add any new ones. | ||
ACCREDITATION_TYPES = %w[regional national hybrid].freeze | ||
|
||
validates :accreditation_type, presence: true | ||
validates :accreditation_type, inclusion: { in: ACCREDITATION_TYPES } | ||
validates :keyword_match, presence: true | ||
validates :keyword_match, uniqueness: { scope: :accreditation_type } | ||
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,22 @@ | ||
<%= form_for @accreditation_type_keyword, remote: true do |form| %> | ||
<div class="field"> | ||
<%= form.hidden_field :accreditation_type, value: @accreditation_type %> | ||
</div> | ||
|
||
|
||
<div> | ||
<%= form.label :keyword %> | ||
<%= form.text_field :keyword_match %> | ||
<%= form.submit 'Save', class: 'btn btn-primary' %> | ||
</div> | ||
|
||
<% if @accreditation_type_keyword.errors.any? %> | ||
<div> | ||
<ul> | ||
<% @accreditation_type_keyword.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% 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,4 @@ | ||
<tr id="accreditation-type-keyword-<%= accreditation_type_keyword.id %>"> | ||
<td><%= accreditation_type_keyword.keyword_match %></td> | ||
<td> <%= link_to 'Delete', accreditation_type_keyword, method: :delete, data: { confirm: 'Are you sure?', remote: true } %></td> | ||
</tr> |
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,3 @@ | ||
$('#new_accreditation_type_keyword').remove(); | ||
$('#add-keyword-link').show(); | ||
$('#keywords').append('<%= j render partial: 'keyword', locals: {accreditation_type_keyword: @accreditation_type_keyword} %>'); |
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 @@ | ||
$('#accreditation-type-keyword-<%= @accreditation_type_keyword.id %>').remove(); |
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 @@ | ||
<p><%= link_to 'Back', dashboard_accreditation_issues_path %></p> | ||
|
||
<h1>Keywords for <%= @accreditation_type %> accreditation</h1> | ||
|
||
<table> | ||
<tbody id="keywords"> | ||
<% @accreditation_type_keywords.each do |accreditation_type_keyword| %> | ||
<%= render partial: 'keyword', locals: {accreditation_type_keyword: accreditation_type_keyword} %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<%= | ||
link_to 'Add Keyword', | ||
new_accreditation_type_keyword_path(accreditation_type: @accreditation_type = params[:accreditation_type]), | ||
id: 'add-keyword-link', | ||
remote: true | ||
%> |
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 @@ | ||
$('#add-keyword-link').hide().after('<%= j render("form") %>'); |
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 @@ | ||
$('#new_accreditation_type_keyword').replaceWith('<%= j render("form") %>'); |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div class="page-header"> | ||
<h1>GI Bill Comparison Tool <small class="dashboard-header"><%=controller.controller_name.humanize.singularize %></small></h1> | ||
<h1>GI Bill Comparison Tool <small class="dashboard-header"><%= controller_label_for_header %></small></h1> | ||
</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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Load the Rails application. | ||
require_relative 'application' | ||
|
||
# get rid of annoying field_with_errors wrapper | ||
# https://coderwall.com/p/s-zwrg/remove-rails-field_with_errors-wrapper | ||
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | ||
html_tag.html_safe | ||
end | ||
|
||
# Initialize the Rails application. | ||
Rails.application.initialize! |
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/20231118074354_create_accreditation_type_keywords.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 CreateAccreditationTypeKeywords < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :accreditation_type_keywords do |t| | ||
t.string :accreditation_type | ||
t.string :keyword_match | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :accreditation_type_keywords, [:accreditation_type, :keyword_match], name: 'index_type_and_keyword_match', unique: true | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
db/migrate/20231118091720_add_type_keyword_to_acrreditation_record.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,14 @@ | ||
class AddTypeKeywordToAcrreditationRecord < ActiveRecord::Migration[6.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
add_column :accreditation_records, :accreditation_type_keyword_id, :bigint, null: true | ||
add_index :accreditation_records, :accreditation_type_keyword_id, algorithm: :concurrently | ||
|
||
add_foreign_key :accreditation_records, | ||
:accreditation_type_keywords, | ||
column: :accreditation_type_keyword_id, | ||
validate: false, | ||
on_delete: :nullify | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
db/migrate/20231121083148_remove_accreditation_type_from_accreditation_record.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,9 @@ | ||
class RemoveAccreditationTypeFromAccreditationRecord < ActiveRecord::Migration[6.1] | ||
# The strong migrations gem indicated to be safe that we need to add | ||
# self.ignored_columns = ["accreditation_type"] to the AccreditationRecord model. | ||
# I think we can safely ignore that as the table is not heavily used. | ||
# However, safety_assured is still required. | ||
def change | ||
safety_assured { remove_column :accreditation_records, :accreditation_type, :string } | ||
end | ||
end |
Oops, something went wrong.