-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip out all special characters from csv headers #915
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
89a8ebb
Thats it, Ive had enough. we need status_message as a column on entry…
orangewolf 3a88627
call the cops
orangewolf 7fb851e
Add datatable to the importer show page. search, filter, sort and pag…
orangewolf 72426e6
fix filters
orangewolf 9c9f3e3
call the cops
orangewolf fc8c3c1
call the cops
orangewolf 87c69fc
Found another place we need to include the monad lib. This time so th…
orangewolf 578610a
we need to get the flag for update set before anything loads the csv
orangewolf f50128c
get the headers right for exporting error works
orangewolf 1adeff0
strip special characters out of header names. excel likes to leave od…
orangewolf 8da9aa9
Merge branch 'main' into strippers_and_rob_both_work_late
jeremyf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Blacklight.onLoad(function() { | ||
if($('#importer-show-table').length) { | ||
$('#importer-show-table').DataTable( { | ||
'processing': true, | ||
'serverSide': true, | ||
"ajax": window.location.href.replace(/(\/importers\/\d+)/, "$1/entry_table.json"), | ||
"pageLength": 30, | ||
"lengthMenu": [[30, 100, 200], [30, 100, 200]], | ||
"columns": [ | ||
{ "data": "identifier" }, | ||
{ "data": "id" }, | ||
{ "data": "status_message" }, | ||
{ "data": "type" }, | ||
{ "data": "updated_at" }, | ||
{ "data": "errors", "orderable": false }, | ||
{ "data": "actions", "orderable": false } | ||
], | ||
"dom": '<"toolbar">frtip', | ||
initComplete: function () { | ||
// Add entry class filter | ||
let entrySelect = document.createElement('select') | ||
entrySelect.id = 'entry-filter' | ||
entrySelect.classList.value = 'form-control input-sm' | ||
entrySelect.style.marginRight = '10px' | ||
|
||
entrySelect.add(new Option('Filter by Entry Class', '')) | ||
// Read the options from the footer and add them to the entrySelect | ||
$('#importer-entry-classes').text().split('|').forEach(function (col, i) { | ||
entrySelect.add(new Option(col.trim())) | ||
}) | ||
document.querySelector('div#importer-show-table_filter').firstChild.prepend(entrySelect) | ||
|
||
// Apply listener for user change in value | ||
entrySelect.addEventListener('change', function () { | ||
var val = entrySelect.value; | ||
this.api() | ||
.search(val ? val : '', false, false) | ||
.draw(); | ||
}.bind(this)); | ||
|
||
// Add status filter | ||
let statusSelect = document.createElement('select'); | ||
statusSelect.id = 'status-filter' | ||
statusSelect.classList.value = 'form-control input-sm' | ||
statusSelect.style.marginRight = '10px' | ||
|
||
statusSelect.add(new Option('Filter by Status', '')); | ||
statusSelect.add(new Option('Complete')) | ||
statusSelect.add(new Option('Pending')) | ||
statusSelect.add(new Option('Failed')) | ||
document.querySelector('div#importer-show-table_filter').firstChild.prepend(statusSelect) | ||
|
||
// Apply listener for user change in value | ||
statusSelect.addEventListener('change', function () { | ||
var val = statusSelect.value; | ||
this.api() | ||
.search(val ? val : '', false, false) | ||
.draw(); | ||
}.bind(this)); | ||
|
||
// Add refresh link | ||
let refreshLink = document.createElement('a'); | ||
refreshLink.onclick = function() { | ||
this.api().ajax.reload(null, false) | ||
}.bind(this) | ||
refreshLink.classList.value = 'glyphicon glyphicon-refresh' | ||
refreshLink.style.marginLeft = '10px' | ||
document.querySelector('div#importer-show-table_filter').firstChild.append(refreshLink) | ||
} | ||
} ); | ||
} | ||
}) |
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulkrax | ||
module DatatablesBehavior | ||
extend ActiveSupport::Concern | ||
|
||
def table_per_page | ||
per_page = params[:length].to_i | ||
per_page < 1 ? 30 : per_page | ||
end | ||
|
||
def order_value(column) | ||
params['columns']&.[](column)&.[]('data') | ||
end | ||
|
||
def table_order | ||
"#{order_value(params['order']['0']['column'])} #{params['order']['0']['dir']}" if params['order']['0']['column'].present? | ||
end | ||
|
||
# convert offset to page number | ||
def table_page | ||
params[:start].blank? ? 1 : (params[:start].to_i / params[:length].to_i) + 1 | ||
end | ||
|
||
def table_search | ||
return @table_search if @table_search | ||
return @table_search = false if params['search']&.[]('value').blank? | ||
|
||
table_search_value = params['search']&.[]('value') | ||
@table_search = ['identifier', 'id', 'status_message', 'type', 'updated_at'].map do |col| | ||
"cast(bulkrax_entries.#{col} as varchar(255)) ILIKE '%#{table_search_value}%'" | ||
end.join(' OR ') | ||
end | ||
|
||
def format_entries(entries, item) | ||
result = entries.map do |e| | ||
{ | ||
identifier: view_context.link_to(e.identifier, view_context.item_entry_path(item, e)), | ||
id: e.id, | ||
status_message: entry_status(e), | ||
type: e.type, | ||
updated_at: e.updated_at, | ||
errors: e.latest_status&.error_class&.present? ? view_context.link_to(e.latest_status.error_class, view_context.item_entry_path(item, e), title: e.latest_status.error_message) : "", | ||
actions: util_links(e, item) | ||
} | ||
end | ||
{ | ||
data: result, | ||
recordsTotal: item.entries.size, | ||
recordsFiltered: item.entries.size | ||
} | ||
end | ||
|
||
def util_links(e, item) | ||
links = [] | ||
links << view_context.link_to(view_context.raw('<span class="glyphicon glyphicon-info-sign"></span>'), view_context.item_entry_path(item, e)) | ||
links << "<a class='glyphicon glyphicon-repeat' data-toggle='modal' data-target='#bulkraxItemModal' data-entry-id='#{e.id}'></a>" if view_context.an_importer?(item) | ||
links << view_context.link_to(view_context.raw('<span class="glyphicon glyphicon-trash"></span>'), view_context.item_entry_path(item, e), method: :delete, data: { confirm: 'This will delete the entry and any work associated with it. Are you sure?' }) | ||
links.join(" ") | ||
end | ||
|
||
def entry_status(e) | ||
if e.status_message == "Complete" | ||
"<td><span class='glyphicon glyphicon-ok' style='color: green;'></span> #{e.status_message}</td>" | ||
elsif e.status_message == "Pending" | ||
"<td><span class='glyphicon glyphicon-option-horizontal' style='color: blue;'></span> #{e.status_message}</td>" | ||
else | ||
"<td><span class='glyphicon glyphicon-remove' style='color: #{e.status == 'Deleted' ? 'green' : 'red'};'></span> #{e.status_message}</td>" | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want underscore as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremyf \w includes underscore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today I (re-)learned!