Skip to content

Commit

Permalink
Merge development into master for release
Browse files Browse the repository at this point in the history
  • Loading branch information
benwbrum committed Feb 13, 2022
2 parents 34687e7 + 219c85e commit 8f887db
Show file tree
Hide file tree
Showing 150 changed files with 8,116 additions and 65,037 deletions.
20 changes: 20 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ $.fn.categoriesSelect = function() {
});
};

$.fn.multiSelect = function() {
return this.each(function() {
var $element = $(this);

$element.select2({
placeholder: 'Choose...',
templateResult: function(category) {
if(!category.id) { return category.text; }
var level = $(category.element).data('level');
var $category = $('<div>').css('margin-left', level * 15).text(category.text);
return $category;
}
});
});
};




// Custom input file
$.fn.inputFile = function() {
Expand Down Expand Up @@ -274,6 +292,8 @@ $(function() {
// Manage subject categories
$('[data-assign-categories]').categoriesSelect();

$('[data-multi-select]').multiSelect();

// Category tree expand/collapse
$('.tree-bullet').on('click', function(e) {
e.preventDefault();
Expand Down
2,917 changes: 2,917 additions & 0 deletions app/assets/javascripts/plugins/jquery.inputmask.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/transcribe.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function unsavedTranscription(e){
//actual function to check for unsaved changes
function checkForUnsaved(inputs, msg, e){
inputs.each(function(){
if (this.type == 'select-one'){
if (this.type == 'select-one' || this.type == 'select-multiple'){
if(!(this.options[this.selectedIndex].defaultSelected) && (this.value != this.options[0].value)){
e.preventDefault();
alert(msg);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ button, .button, input[type="submit"], input[type="reset"], input[type="button"]
//&.bgred { @include button-colorize($btnRedColor, $btnRedBackground); }

// Green button
//&.bggreen { @include button-colorize($btnGreenColor, $btnGreenBackground); }
&.bggreen { @include button-colorize($btnGreenColor, $btnGreenBackground); }

// Orange button
//&.bgorange { @include button-colorize($btnOrangeColor, $btnOrangeBackground); }
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sections/collection.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
margin: 0.5em 0 0 0;
font-size: $fontSizeSmall;
}
&_action {
font-style: italic;
}
&_stats {
width: 100%;
color: $bodyFgFaded;
Expand Down
16 changes: 15 additions & 1 deletion app/controllers/article_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,21 @@ def subject_upload
@collection = Collection.find params[:upload][:collection_id]
# read the file
file = params[:upload][:file].tempfile
csv = CSV.read(params[:upload][:file].tempfile, :headers => true)

# csv = CSV.read(params[:upload][:file].tempfile, :headers => true)
begin
csv = CSV.read(params[:upload][:file].tempfile, :headers=>true)
rescue
contents = File.read(params[:upload][:file].tempfile)
detection = CharlockHolmes::EncodingDetector.detect(contents)

csv = CSV.read(params[:upload][:file].tempfile,
:encoding => "bom|#{detection[:encoding]}",
:liberal_parsing => true,
:headers => true)
end


provenance = params[:upload][:file].original_filename + " (uploaded #{Time.now} UTC)"
# check the values
if csv.headers.include?('HEADING') && csv.headers.include?('URI') && csv.headers.include?('ARTICLE') && csv.headers.include?('CATEGORY')
Expand Down
21 changes: 18 additions & 3 deletions app/controllers/bulk_export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ def show

def new
@bulk_export = BulkExport.new
@bulk_export.collection = @collection
if @collection.is_a? DocumentSet
@bulk_export.document_set = @collection
@bulk_export.collection = @collection.collection
else
@bulk_export.collection = @collection
end
end

def create
@bulk_export = BulkExport.new(bulk_export_params)
@bulk_export.collection = @collection
if @collection.is_a? DocumentSet
@bulk_export.document_set = @collection
@bulk_export.collection = @collection.collection
else
@bulk_export.collection = @collection
end
@bulk_export.user = current_user
@bulk_export.status = BulkExport::Status::NEW

Expand All @@ -31,7 +41,12 @@ def create

def create_for_work
@bulk_export = BulkExport.new(bulk_export_params)
@bulk_export.collection = @collection
if @collection.is_a? DocumentSet
@bulk_export.document_set = @collection
@bulk_export.collection = @collection.collection
else
@bulk_export.collection = @collection
end
@bulk_export.work = @work
@bulk_export.user = current_user
@bulk_export.status = BulkExport::Status::NEW
Expand Down
30 changes: 25 additions & 5 deletions app/controllers/collection_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def show
#combine ids anduse to get works that aren't complete
ids = translation_ids + transcription_ids

if @collection.metadata_entry?
description_ids = @collection.works.incomplete_description.pluck(:id)
ids += description_ids
end

works = @collection.works.includes(:work_statistic).where(id: ids).paginate(page: params[:page], per_page: 10)

if works.empty?
Expand All @@ -172,7 +177,7 @@ def show
@works = @collection.works.joins(:work_facet).where('work_facets.id in (?)', facet_ids).includes(:work_facet).paginate(page: params[:page], :per_page => @per_page) unless params[:search].is_a?(String)

@date_ranges = []
date_configs = @collection.facet_configs.where(:input_type => 'date').order('"order"')
date_configs = @collection.facet_configs.where(:input_type => 'date').where.not(:order => nil).order('"order"')
if date_configs.size > 0
collection_facets = WorkFacet.joins(:work).where("works.collection_id = #{@collection.id}")
date_configs.each do |facet_config|
Expand All @@ -197,9 +202,11 @@ def show
end

def add_owner
@user.owner = true
@user.account_type = "Staff"
@user.save!
unless @user.owner
@user.owner = true
@user.account_type = "Staff"
@user.save!
end
@collection.owners << @user
@user.notification.owner_stats = true
@user.notification.save!
Expand Down Expand Up @@ -306,6 +313,18 @@ def disable_fields
redirect_to action: 'edit', collection_id: @collection
end

def enable_metadata_entry
@collection.data_entry_type = Collection::DataEntryType::TEXT_AND_METADATA
@collection.save!
redirect_to collection_edit_metadata_fields_path(@collection.owner, @collection)
end

def disable_metadata_entry
@collection.data_entry_type = Collection::DataEntryType::TEXT_ONLY
@collection.save!
redirect_to action: 'edit', collection_id: @collection
end

def delete
@collection.destroy
redirect_to dashboard_owner_path
Expand Down Expand Up @@ -346,10 +365,11 @@ def update
@collection.update(collection_params)
end

if @collection.save!
if @collection.save
flash[:notice] = t('.notice')
redirect_to action: 'edit', collection_id: @collection.id
else
edit # load the appropriate variables
render action: 'edit'
end
end
Expand Down
37 changes: 33 additions & 4 deletions app/controllers/concerns/export_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def export_work_metadata_as_csv(collection)
'FromThePage URL',
'Identifier',
'Originating Manifest ID',
'Creation Date',
'Total Pages',
'Pages Transcribed',
'Pages Corrected',
Expand All @@ -318,8 +319,11 @@ def export_work_metadata_as_csv(collection)

raw_metadata_strings = collection.works.pluck(:original_metadata)
metadata_headers = raw_metadata_strings.map{|raw| raw.nil? ? [] : JSON.parse(raw).map{|element| element["label"] } }.flatten.uniq
# append the headers for described metadata, read from the metadata_field configuration for the project
static_description_headers = ['Description Status', 'Described By']
described_headers = collection.metadata_fields.map {|field| field.label}

csv << static_headers + metadata_headers
csv << static_headers + metadata_headers + static_description_headers + described_headers

collection.works.includes(:document_sets, :work_statistic, :sc_manifest).reorder(:id).each do |work|
row = [
Expand All @@ -332,6 +336,7 @@ def export_work_metadata_as_csv(collection)
collection_read_work_url(collection.owner, collection, work),
work.identifier,
work.sc_manifest.nil? ? '' : work.sc_manifest.at_id,
work.created_on,
work.work_statistic.total_pages,
work.work_statistic.transcribed_pages,
work.work_statistic.corrected_pages,
Expand All @@ -351,6 +356,28 @@ def export_work_metadata_as_csv(collection)
end
end

unless work.metadata_description.blank?
# description status
row << work.description_status
# described by
row << User.find(work.metadata_description_versions.pluck(:user_id)).map{|u| u.display_name}.join('; ')

metadata = JSON.parse(work.metadata_description)
# we rely on a consistent order of fields returned by collection.metadata_fields to prevent scrambling columns
collection.metadata_fields.each do |field|
element = metadata.detect{|candidate| candidate['transcription_field_id'] == field.id}
if element
value = element['value']
if value.is_a? Array
value = value.join("; ")
end
row << value
else
row << nil
end
end
end

csv << row
end
end
Expand Down Expand Up @@ -528,9 +555,11 @@ def process_header_footer_data(data_cells, running_data, cell_array, rownum)
# are we in row 1? fill the running data with non-spreadsheet fields
if rownum == 1
cell_array.each do |cell|
unless cell.transcription_field.input_type == 'spreadsheet'
running_data << cell
end
if cell.transcription_field
unless cell.transcription_field.input_type == 'spreadsheet'
running_data << cell
end
end
end
else
# are we in row 2 or greater?
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/concerns/static_site_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,7 @@ def write_work_page(dirname, out, collection, work)
path = File.join dirname, 'pages', 'works', "#{work.slug}.md"
out.put_next_entry path

metadata = []
if work.original_metadata
metadata += JSON[work.original_metadata]
end
work_metadata = work.attributes.except("id", "title", "next_untranscribed_page_id", "description","created_on", "transcription_version", "owner_user_id", "restrict_scribes", "transcription_version", "transcription_conventions", "collection_id", "scribes_can_edit_titles", "supports_translation", "translation_instructions", "pages_are_meaningful", "ocr_correction", "slug", "picture", "featured_page", "original_metadata", "in_scope").delete_if{|k,v| v.blank?}

work_metadata.each_pair { |label,value| metadata << { "label" => label.titleize, "value" => value.to_s } }
metadata = work.merge_metadata

frontmatter = {
'title' => work.title,
Expand Down
34 changes: 33 additions & 1 deletion app/controllers/document_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,46 @@ class DocumentSetsController < ApplicationController
respond_to :html

# no layout if xhr request
layout Proc.new { |controller| controller.request.xhr? ? false : nil }, :only => [:new, :create, :edit, :update]
layout Proc.new { |controller| controller.request.xhr? ? false : nil }, :only => [:new, :create, :edit, :update, :transfer_form]

def authorized?
unless user_signed_in? && @collection && current_user.like_owner?(@collection)
ajax_redirect_to dashboard_path
end
end

def transfer_form
end

def transfer
source_set = @collection.document_sets.where(slug: params[:source_set]).first
target_set = @collection.document_sets.where(slug: params[:target_set]).first

if source_set == target_set
flash[:error] = t('.source_and_target_can_not_be_the_same')
render :action => 'transfer_form', :layout => false
flash.clear
else
if params[:status_filter] == 'all'
works = source_set.works
else
works = source_set.works.joins(:work_statistic).where('work_statistics.complete' => 100)
end

works.each do |work|
unless work.document_sets.include? target_set
work.document_sets << target_set
end
if params[:transfer_type] == 'move'
work.document_sets.delete(source_set)
end
end

ajax_redirect_to document_sets_path(:collection_id => @collection)
end
end


def index
page = params[:page]
page = 1 if page.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ExportController < ApplicationController
layout Proc.new { |controller| controller.request.xhr? ? false : nil } #, :only => [:update, :update_profile]

def index
@collection = Collection.friendly.find(params[:collection_id])
# @collection = Collection.friendly.find(params[:collection_id])
#check if there are any translated works in the collection
if @collection.works.where(supports_translation: true).exists?
@header = "Translated"
Expand Down
28 changes: 27 additions & 1 deletion app/controllers/facets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class FacetsController < ApplicationController

def enable
@collection = Collection.find(params[:collection_id])
@collection.facets_enabled = true
Expand Down Expand Up @@ -59,10 +60,18 @@ def update
unless metadata.nil?
if !metadata['order'].blank?
facet_label = metadata['label'].blank? ? m.key : metadata['label']
if m.facet_config.label.nil?
label_hash = {}
else
label_hash = JSON.parse(m.facet_config.label)
end
label_hash[locale.to_s] = facet_label
facet_label = label_hash.to_json
else
facet_label = nil
end
m.facet_config.update(label: facet_label,

m.facet_config.update(label: facet_label,
input_type: metadata['input_type'],
order: metadata['order'])
end
Expand All @@ -89,6 +98,23 @@ def update
render('collection/facets', :locals => { :@metadata_coverages => collection.metadata_coverages, :@errors => errors })
end
end


def localize
render('collection/localize', layout: false)
end

def update_localization
facet_params = params[:facets]
facet_params.each do |facet_config_id, labels|
facet_config = @collection.facet_configs.where(id: facet_config_id).first
if facet_config
facet_config.label = labels.to_json
facet_config.save!
end
end
ajax_redirect_to collection_facets_path(@collection.owner, @collection)
end
end


2 changes: 1 addition & 1 deletion app/controllers/ia_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def confirm_import

def import_work
detail_url = params[:detail_url]
id = detail_url.split('/').last
id = detail_url.sub(/.*archive.org\/details\//,'').sub(/\/.*/,'')

# pull relevant info about the work from here
@ia_work = IaWork.new
Expand Down
Loading

0 comments on commit 8f887db

Please sign in to comment.