Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Replacing VocabularyCollection with sub-Vocabularies
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Apr 18, 2017
1 parent d927747 commit 8cb157e
Show file tree
Hide file tree
Showing 43 changed files with 67 additions and 518 deletions.
4 changes: 3 additions & 1 deletion app/controllers/vocabularies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def show
# GET /vocabularies/new
def new
@vocabulary = Vocabulary.new
@parent_id = params[:parent_id]
end

# GET /vocabularies/1/edit
def edit
@parent_id = @vocabulary.parent.id if @vocabulary.parent
end

# POST /vocabularies
Expand Down Expand Up @@ -71,6 +73,6 @@ def set_vocabulary

# Never trust parameters from the scary internet, only allow the white list through.
def vocabulary_params
params.require(:vocabulary).permit(:label)
params.require(:vocabulary).permit(:label, :parent_id)
end
end
77 changes: 0 additions & 77 deletions app/controllers/vocabulary_collections_controller.rb

This file was deleted.

3 changes: 1 addition & 2 deletions app/controllers/vocabulary_terms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def show
def new
@vocabulary_term = VocabularyTerm.new
@vocabulary_id = params[:vocabulary_id]
@vocabulary_collection_id = params[:vocabulary_collection_id]
end

# GET /vocabulary_terms/1/edit
Expand Down Expand Up @@ -73,6 +72,6 @@ def set_vocabulary_term

# Never trust parameters from the scary internet, only allow the white list through.
def vocabulary_term_params
params.require(:vocabulary_term).permit(:label, :uri, :code, :tgm_label, :lcsh_label, :vocabulary_id, :vocabulary_collection_id)
params.require(:vocabulary_term).permit(:label, :uri, :code, :tgm_label, :lcsh_label, :vocabulary_id)
end
end
1 change: 1 addition & 0 deletions app/models/vocabulary.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Vocabulary < ApplicationRecord
belongs_to :parent, class_name: "Vocabulary"
validates :label, presence: true
end
4 changes: 0 additions & 4 deletions app/models/vocabulary_collection.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/vocabulary_term.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class VocabularyTerm < ApplicationRecord
belongs_to :vocabulary
belongs_to :vocabulary_collection
validates :label, :vocabulary, presence: true
end
5 changes: 5 additions & 0 deletions app/views/vocabularies/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<%= f.input :label %>
</div>

<div class="field">
<%= f.label :parent_id %>
<%= f.collection_select :parent_id, Vocabulary.order(:label), :id, :label, include_blank: true, selected: @parent_id %>
</div>

<div class="actions">
<%= f.submit(class: 'btn btn-primary') %>
<% if params[:action] == "new" %>
Expand Down
15 changes: 9 additions & 6 deletions app/views/vocabularies/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<p id="notice"><%= notice %></p>

<h1>
<%= link_to 'Vocabularies', vocabularies_path %> » <%= @vocabulary.label %>
<%= link_to 'Vocabularies', vocabularies_path %> »
<% if @vocabulary.parent %>
<%= link_to @vocabulary.parent.label, @vocabulary.parent %> »
<% end %>
<%= @vocabulary.label %>
</h1>

<%= link_to 'All Vocabularies', vocabularies_path %> |
<%= link_to 'Edit', edit_vocabulary_path(@vocabulary) %> |
<%= link_to 'Add Collection', vocabulary_add_collection_path(@vocabulary.id) %> |
<%= link_to 'Add Sub-Vocabulary', vocabulary_add_sub_vocabulary_path(@vocabulary.id) %> |
<%= link_to 'Add Term', vocabulary_add_term_path(@vocabulary.id) %>


<h2>Collections</h2>
<h2>Sub-Vocabularies</h2>
<ul>
<% VocabularyCollection.where(vocabulary_id: @vocabulary.id).order(:label).each do |collection| %>
<li><%= link_to collection.label, collection %></li>
<% Vocabulary.where(parent_id: @vocabulary.id).order(:label).each do |sub_vocab| %>
<li><%= link_to sub_vocab.label, sub_vocab %></li>
<% end %>
</ul>

Expand Down
32 changes: 0 additions & 32 deletions app/views/vocabulary_collections/_form.html.erb

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/vocabulary_collections/edit.html.erb

This file was deleted.

31 changes: 0 additions & 31 deletions app/views/vocabulary_collections/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/vocabulary_collections/index.json.jbuilder

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/vocabulary_collections/new.html.erb

This file was deleted.

24 changes: 0 additions & 24 deletions app/views/vocabulary_collections/show.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/vocabulary_collections/show.json.jbuilder

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/vocabulary_terms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<%= f.collection_select :vocabulary_id, Vocabulary.order(:label), :id, :label, selected: @vocabulary_id %>
</div>

<div class="field">
<%= f.label :vocabulary_collection_id %>
<%= f.collection_select :vocabulary_collection_id, VocabularyCollection.order(:label), :id, :label, include_blank: true, selected: @vocabulary_collection_id %>
</div>

<div class="actions">
<%= f.submit(class: 'btn btn-primary') %>
<% if params[:action] == "new" %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/vocabulary_terms/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<th>Label</th>
<th>URI</th>
<th>Vocabulary</th>
<th>Collection</th>
<th colspan="3"></th>
</tr>
</thead>
Expand All @@ -21,7 +20,6 @@
<td class="vocab"><%= vocabulary_term.label %></td>
<td class="vocab"><%= link_to vocabulary_term.uri, vocabulary_term.uri %></td>
<td class="vocab"><%= link_to vocabulary_term.vocabulary.label, vocabulary_term.vocabulary %></td>
<td class="vocab"><%= link_to vocabulary_term.vocabulary_collection.label if vocabulary_term.vocabulary_collection %></td>
<td class="vocab"><%= link_to 'Show', vocabulary_term %></td>
<td class="vocab"><%= link_to 'Edit', edit_vocabulary_term_path(vocabulary_term) %></td>
<td class="vocab"><%= link_to 'Destroy', vocabulary_term, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
10 changes: 0 additions & 10 deletions app/views/vocabulary_terms/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<h1>
<%= link_to 'Vocabularies', vocabularies_path %> »
<%= link_to @vocabulary_term.vocabulary.label, @vocabulary_term.vocabulary %> »
<% if @vocabulary_term.vocabulary_collection %>
<%= link_to @vocabulary_term.vocabulary_collection.label, @vocabulary_term.vocabulary_collection %> »
<% end %>
<%= @vocabulary_term.label %>
</h1>

Expand Down Expand Up @@ -34,12 +31,5 @@
<%= link_to @vocabulary_term.vocabulary.label, @vocabulary_term.vocabulary %>
</p>

<p>
<strong>Vocabulary collection:</strong>
<% if @vocabulary_term.vocabulary_collection %>
<%= link_to(@vocabulary_term.vocabulary_collection.label, @vocabulary_term.vocabulary_collection) %>
<% end %>
</p>

<%= link_to 'All Terms', vocabulary_terms_path %> |
<%= link_to 'Edit', edit_vocabulary_term_path(@vocabulary_term) %>
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@
mount Qa::Engine => '/authorities'

resources :vocabularies
resources :vocabulary_collections
resources :vocabulary_terms
get '/vocabularies/:vocabulary_id/add_collection' => 'vocabulary_collections#new', as: 'vocabulary_add_collection'
get '/vocabularies/:vocabulary_id/add_term' => 'vocabulary_terms#new', as: 'vocabulary_add_term'
get '/vocabularies/:vocabulary_id/collections/:vocabulary_collection_id/add_term' => 'vocabulary_terms#new', as: 'vocabulary_collection_add_term'
get '/vocabularies/:parent_id/add_sub_vocabulary' => 'vocabularies#new', as: 'vocabulary_add_sub_vocabulary'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DropVocabularyCollectionsTable < ActiveRecord::Migration[5.0]
def change
drop_table :vocabulary_collections do |t|
t.string :label
t.references :vocabulary, foreign_key: true
t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveVocabularyCollectionFromVocabularyTerms < ActiveRecord::Migration[5.0]
def change
remove_reference :vocabulary_terms, :vocabulary_collection, foreign_key: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170418135317_add_parent_to_vocabularies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddParentToVocabularies < ActiveRecord::Migration[5.0]
def change
add_reference :vocabularies, :parent, Vocabulary: true, foreign_key: true
end
end
Loading

0 comments on commit 8cb157e

Please sign in to comment.