This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e6786a
commit c840ff0
Showing
13 changed files
with
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: bundle exec puma -C config/puma.rb | ||
worker: bundle exec sidekiq | ||
worker: bundle exec sidekiq -c $SIDEKIQ_CONCURRENCY |
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 @@ | ||
class TypesController < ApplicationController | ||
|
||
def index | ||
@types = Type.order('records_count desc') | ||
end | ||
|
||
def show | ||
@type = Type.find(params[:id].gsub('T','')) | ||
|
||
@records = @type.records.select(:identifier, :title).limit(100) | ||
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,29 @@ | ||
class UpdateTypesFromMetadataJob < ActiveJob::Base | ||
queue_as :default | ||
|
||
def perform(record) | ||
|
||
genres = record.metadata.fetch('655', []) | ||
|
||
genres.each do |genre| | ||
|
||
genre_name = genre['a'].gsub(/\.\z/, '') | ||
|
||
genre_reference = genre_name.downcase | ||
|
||
if genre_name | ||
|
||
type = Type.find_by_reference(genre_reference) || Type.create!(references: [genre_reference], name: genre_name) | ||
|
||
begin | ||
record.types << type | ||
rescue ActiveRecord::RecordNotUnique | ||
# Already added - ignore. | ||
end | ||
|
||
end | ||
|
||
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 @@ | ||
class RecordType < ActiveRecord::Base | ||
|
||
belongs_to :type, counter_cache: :records_count | ||
belongs_to :record | ||
|
||
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,15 @@ | ||
class Type < ActiveRecord::Base | ||
|
||
has_many :record_types, dependent: :destroy | ||
has_many :records, through: :record_types | ||
|
||
|
||
def to_param | ||
"T#{id}" | ||
end | ||
|
||
def self.find_by_reference(reference) | ||
find_by(["? = ANY(types.references)", reference]) | ||
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,15 @@ | ||
<h1>Types of things</h1> | ||
|
||
<ul> | ||
<% @types.each do |type| %> | ||
<li><%= link_to type.name, type %> | ||
|
||
<small> | ||
<%= number_with_delimiter(type.digitized_records_count) %> | ||
of | ||
<%= number_with_delimiter(type.records_count) %> | ||
things digitised | ||
</small> | ||
</li> | ||
<% end %> | ||
</ul> |
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,11 @@ | ||
<h1><%= @type.name %></h1> | ||
|
||
<p><%= pluralize_with_delimiter(@type.records_count, 'record') %></p> | ||
|
||
<ul> | ||
<% @records.each do |record| %> | ||
|
||
<li><%= link_to record.title, thing_path(record) %></li> | ||
|
||
<% end %> | ||
</ul> |
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 @@ | ||
class CreateTypes < ActiveRecord::Migration | ||
def change | ||
create_table :types do |t| | ||
t.text :name, null: false | ||
t.text :description | ||
t.text :references, array: true, null: false, default: [] | ||
t.integer :records_count, null: false, default: 0 | ||
t.integer :digitized_records_count, null: false, default: 0 | ||
end | ||
|
||
add_index :types, :references | ||
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,10 @@ | ||
class CreateRecordTypes < ActiveRecord::Migration | ||
def change | ||
create_table :record_types do |t| | ||
t.integer :record_id, null: false | ||
t.integer :type_id, null: false | ||
end | ||
|
||
add_index :record_types, [:record_id, :type_id], unique: true | ||
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