geoblacklight_admin 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3206d757d63794d306ce29d80d7bcf7ea9e2afe7f94f21792885a71e3edc9ac6
4
- data.tar.gz: 1916a1e90a1826bb509a497b6bab3c4f3253e44cac7f44f73e6f676638c78f91
3
+ metadata.gz: ccbde8ddbc9a147e70292b99dc32062b43c8517821ad3aff392e73b7bcd428c8
4
+ data.tar.gz: 13405c8253ee7f0f6ce925eba479a880f7ef06634841169622be946cc6ee2c53
5
5
  SHA512:
6
- metadata.gz: '09f174737d687d2a9d60a9a5a6fb73d11eefaf160ec2862a2ff0d12e4b926ab8b0b91d534ae4b20d781319b1b50107dd05cb214c54ffdc6c531bb600ca139c5b'
7
- data.tar.gz: af6d3f3e20943a2a8de0a1020d0a568e2870738c5c74d21ef9aad575fd9364360c620e78c2d16cead8261f77501c8a05c095ea94747801be4a63b81e3421af0e
6
+ metadata.gz: b7f19df4aecd8bbf08e0536b1cbcdc720d5f8c55e20e5c13d5296bbff61a8e8f79f724adda0899fbe566131bc7de2fdc3da141742fa064263b4136d9443dc26e
7
+ data.tar.gz: 524b5e9a4a1c37205d01456b5d3585183493e9d1c18397669ec692eb9072c31d1defbe8d7ca71cc3fdfef8b3dd6336ece4453cc589f4c7db92312fa00b84c9af
@@ -22,6 +22,11 @@ module Admin
22
22
  # GET /document_data_dictionaries/1 or /document_data_dictionaries/1.json
23
23
  def show
24
24
  @pagy, @document_data_dictionary_entries = pagy(@document_data_dictionary.document_data_dictionary_entries.order(position: :asc), items: 100)
25
+
26
+ respond_to do |format|
27
+ format.html
28
+ format.csv { render plain: @document_data_dictionary.to_csv }
29
+ end
25
30
  end
26
31
 
27
32
  # GET /document_data_dictionaries/new
@@ -15,15 +15,27 @@ class DocumentDataDictionary < ApplicationRecord
15
15
 
16
16
  # Validations
17
17
  validates :name, presence: true
18
- validates :csv_file, attached: true, content_type: {in: "text/csv", message: "is not a CSV file"}
19
-
20
- validates_with DocumentDataDictionary::CsvHeaderValidator
18
+ validates :csv_file, content_type: {in: "text/csv", message: "is not a CSV file"}, if: -> { csv_file.attached? }
19
+ validates_with DocumentDataDictionary::CsvHeaderValidator, if: -> { csv_file.attached? }
20
+
21
+ def to_csv
22
+ CSV.generate do |csv|
23
+ csv << DocumentDataDictionaryEntry.column_names.excluding("id", "created_at", "updated_at")
24
+ document_data_dictionary_entries.each do |entry|
25
+ csv << entry.attributes.values_at(*DocumentDataDictionaryEntry.column_names.excluding("id", "created_at", "updated_at"))
26
+ end
27
+ end
28
+ end
21
29
 
22
30
  def parse_csv_file
23
31
  if csv_file.attached?
24
32
  csv_data = CSV.parse(csv_file.download, headers: true)
25
33
  csv_data.each do |row|
26
- document_data_dictionary_entries.create!(row.to_h)
34
+ entry = document_data_dictionary_entries.find_or_initialize_by(
35
+ friendlier_id: row["friendlier_id"],
36
+ field_name: row["field_name"]
37
+ )
38
+ entry.update(row.to_h)
27
39
  end
28
40
  end
29
41
  end
@@ -6,4 +6,5 @@ class DocumentDataDictionaryEntry < ApplicationRecord
6
6
 
7
7
  # Validations
8
8
  validates :friendlier_id, :field_name, presence: true
9
+ validates :friendlier_id, uniqueness: {scope: :field_name, message: "and field_name combination must be unique"}
9
10
  end
@@ -13,6 +13,7 @@ require "csv"
13
13
  #
14
14
  # Callbacks:
15
15
  # - after_save :reindex_document
16
+ # - after_destroy :reindex_document
16
17
  #
17
18
  # Validations:
18
19
  # - Validates presence of :friendlier_id, :reference_type_id, :url
@@ -25,6 +26,7 @@ class DocumentDistribution < ApplicationRecord
25
26
  belongs_to :document, foreign_key: :friendlier_id, primary_key: :friendlier_id
26
27
  belongs_to :reference_type
27
28
  after_save :reindex_document
29
+ after_destroy :reindex_document
28
30
 
29
31
  # Validations
30
32
  validates :friendlier_id, :reference_type_id, :url, presence: true
@@ -7,6 +7,7 @@
7
7
  <th>Staff Notes</th>
8
8
  <th>Tags</th>
9
9
  <th>Entries</th>
10
+ <th>Export</th>
10
11
  <th colspan="2">Actions</th>
11
12
  </tr>
12
13
  </thead>
@@ -27,6 +28,9 @@
27
28
  <td>
28
29
  <%= link_to "#{document_data_dictionary.document_data_dictionary_entries.count} entries", admin_document_document_data_dictionary_path(document_data_dictionary.friendlier_id, document_data_dictionary) %>
29
30
  </td>
31
+ <td>
32
+ <%= link_to 'Export to CSV', admin_document_document_data_dictionary_path(document_data_dictionary.friendlier_id, document_data_dictionary, format: :csv), class: 'btn btn-outline-primary btn-block' %>
33
+ </td>
30
34
  <td>
31
35
  <%= link_to 'Edit', edit_admin_document_document_data_dictionary_path(document_data_dictionary.friendlier_id, document_data_dictionary) %>
32
36
  </td>
@@ -1,6 +1,7 @@
1
1
  <% if document&.kithe_model&.document_data_dictionaries.present? %>
2
2
  <% document.kithe_model.document_data_dictionaries.each do |dictionary| %>
3
3
  <h3><%= dictionary.name %></h3>
4
+ <p><%= dictionary.description %></p>
4
5
  <table class="table table-striped table-bordered">
5
6
  <thead class="thead-dark">
6
7
  <tr>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoblacklightAdmin
4
- VERSION = "0.7.1"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoblacklight_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Larson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_storage_validations