Skip to content
3 changes: 2 additions & 1 deletion apps/dashboard/app/javascript/active_jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import oboe from 'oboe';
import { supportPath } from './config.js';
import { cssBadgeForState, capitalizeFirstLetter } from './utils.js'
import { cssBadgeForState, capitalizeFirstLetter, customizeTableHeaders } from './utils.js'

window.fetch_table_data = fetch_table_data;
window.create_datatable = create_datatable;
Expand Down Expand Up @@ -165,6 +165,7 @@ function create_datatable(options){
},
processing: true, // Add the "processing" while json is being downloaded.
drawCallback: function(settings){
customizeTableHeaders('#job_status_table');
if(options.drawCallback){
options.drawCallback(settings);
}
Expand Down
9 changes: 6 additions & 3 deletions apps/dashboard/app/javascript/files/data_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getGlobusLink, updateGlobusLink } from './globus.js';
import { downloadEnabled } from '../config.js';
export { CONTENTID, EVENTNAME };
import { OODAlertError } from '../alert.js';
import { toHumanSize, ariaNotify } from '../utils.js';
import { toHumanSize, ariaNotify, customizeTableHeaders } from '../utils.js';

const EVENTNAME = {
getJsonResponse: 'getJsonResponse',
Expand Down Expand Up @@ -204,6 +204,9 @@ class DataTable {
// if you need to omit more columns, use a "selectable" class on the columns you want to support selection
selector: 'td:not(:first-child)'
},
drawCallback: function() {
customizeTableHeaders(CONTENTID);
},
layout: {
top1Start: {
div: {
Expand Down Expand Up @@ -303,8 +306,8 @@ class DataTable {
$('#select_all').trigger();
}

$(`${CONTENTID}_caption`).text(`Contents of directory ${data.path}`);
ariaNotify(`navigated to ${data.path}`);
$(`${CONTENTID}_caption`).text(`Contents of directory ${data.path}`);
ariaNotify(`navigated to ${data.path}`);

let result = await Promise.resolve(data);
$('td input[type=checkbox]').on('keypress', function(event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OODAlertError } from '../alert';
import { ariaNotify, hide, show } from "../utils";
import { ariaNotify, customizeTableHeaders, hide, show } from "../utils";

export class PathSelectorTable {
_table = null;
Expand Down Expand Up @@ -38,6 +38,7 @@ export class PathSelectorTable {
}

initDataTable() {
const tableId = this.tableId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a javascript expert, so I don't know if using this. is redundant here like it would be in ruby using self. In any case, why not just use this.tableId below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't my first instinct either, but it appears this gets lost when referenced inside a callback. (from console.logs it was undefined). But assigning it to a normal variable instead of referencing the instance resolved the issue. This thread discusses the central issue https://stackoverflow.com/questions/8317724/javascript-class-variable-scope-in-callback-function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that makes sense.

this._table = $(`#${this.tableId}`).DataTable({
autoWidth: false,
language: {
Expand All @@ -55,6 +56,9 @@ export class PathSelectorTable {
// if you need to omit more columns, use a "selectable" class on the columns you want to support selection
selector: 'td:not(:first-child)'
},
drawCallback: function() {
customizeTableHeaders(`#${tableId}`);
},
// https://datatables.net/reference/option/dom
// dom: '', dataTables_info nowrap
//
Expand Down
18 changes: 18 additions & 0 deletions apps/dashboard/app/javascript/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ export function pushNotify(message, options = {}) {
}
}

// rearrange table header labels so button labels are not part of header
export function customizeTableHeaders(tableId) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be an aside - and we don't have to fix it here, but we appear to be using the phrase 'id' like tableId here, but really it's a tableIdSelector with # prefix.

Again, we don't have to fix it here, just noting it because apparently CONTENTID is also not an id, but an id selector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great suggestion because I spent a lot of time troubleshooting the fact that tableId from the path selector (real id) and CONTENTID (selector) were not the same format.

$(`${tableId} th.dt-orderable-asc`).each(function(_index, el) {
const sortButton = $(el).find('span.dt-column-order');
const ariaLabel = sortButton.attr('aria-label');
const labelId = `${el.textContent.replaceAll(' ', '_').toLowerCase()}_label`;
var labelSpan = document.getElementById(labelId);
if (labelSpan === null) {
labelSpan = document.createElement('span');
labelSpan.id = labelId;
$('#header_labels').append(labelSpan);
}
labelSpan.textContent = ariaLabel;
sortButton.removeAttr('aria-label');
sortButton.attr('aria-describedby', labelId);
});
}

// Store a boolean value in localStorage
export function storeBoolean(key, value) {
localStorage.setItem(key, value ? 'true' : 'false');
Expand Down
2 changes: 2 additions & 0 deletions apps/dashboard/app/views/active_jobs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
</div>
<div class="col-auto col-lg col-md-12 table-responsive">
<h2>Active Jobs</h2>
<div id="header_labels" class="d-none">
</div>
<table id="job_status_table" class="table datatable table-hover" cellspacing="0" width="100%">
<thead>
<tr>
Expand Down
7 changes: 4 additions & 3 deletions apps/dashboard/app/views/files/_files_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<ol id="path-breadcrumbs" class="breadcrumb breadcrumb-no-delimiter rounded">
<%= render partial: 'breadcrumb', collection: @path.descend, as: :file, locals: { file_count: @path.descend.count, full_path: @path } %>
</ol>

<span id="select_all_label" class="sr-only">Select All</span>
<div id='header_labels' class='d-none'>
<span id="select_all_label">Select All</span>
</div>
<table class="table table-striped table-condensed w-100" id="directory-contents">
<caption id="directory-contents_caption" class="sr-only" aria-live='polite'> <%= "Contents of directory #{@path}" %> </caption>
<thead>
<tr>
<th>
<input type="checkbox" id="select_all" class="file-select" aria-labelledby="select_all_label"></input>
<input type="checkbox" id="select_all" class="file-select" aria-describedby="select_all_label">
<span class="sr-only">Select</span>
</th>
<th>Type</th>
Expand Down
2 changes: 2 additions & 0 deletions apps/dashboard/app/views/shared/_path_selector_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<span class="sr-only" aria-live="polite">Loading...</span>
</div>
</div>
<div id="header_labels" class="d-none">
</div>
<table class="table table-hover table-condensed d-table w-100" id="<%= table_id %>">
<caption>Choose a file or directory to use in the form.</caption>
<thead>
Expand Down
Loading