Skip to content

Commit

Permalink
Merge pull request #311 from freelawproject/190-add-last-filing-button
Browse files Browse the repository at this point in the history
feat(district): Add button to autofill docket query form
  • Loading branch information
mlissner authored Jan 10, 2023
2 parents 239acb7 + 11c56df commit 867db07
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Features:
- Add banners to advertise RECAP Email in appellate courts ([#313](https://github.com/freelawproject/recap/issues/313), [#295](https://github.com/freelawproject/recap-chrome/pull/295)).
- Add links to review RECAP in the extension Popup ([#286](https://github.com/freelawproject/recap/issues/286), [#303](https://github.com/freelawproject/recap-chrome/pull/303))
- Upload free documents from Appellate PACER ([#322](https://github.com/freelawproject/recap/issues/322), [#305](https://github.com/freelawproject/recap-chrome/pull/305))
- Add button to autofill docket query form in district courts ([#311](https://github.com/freelawproject/recap-chrome/pull/311), [#190](https://github.com/freelawproject/recap/issues/190))

Changes:
- None yet
Expand Down
51 changes: 41 additions & 10 deletions spec/ContentDelegateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('The ContentDelegate class', function () {
set: jasmine.createSpy('set').and.callFake(function () {}),
remove: jasmine.createSpy('remove').and.callFake(() => {}),
},
}
}
},
};

// 'path' values
const districtCourtURI = 'https://ecf.canb.uscourts.gov';
Expand Down Expand Up @@ -232,8 +232,15 @@ describe('The ContentDelegate class', function () {
beforeEach(function () {
clearDocumentBody();
form = document.createElement('form');

dateToField = document.createElement('input');
dateToField.setAttribute('name', 'date_to');
document.body.appendChild(dateToField);

document.body.appendChild(form);
document.querySelector = jasmine.createSpy('querySelector').and.callFake((id) => (id != 'form' ? null : form));
document.querySelector = jasmine
.createSpy('querySelector')
.and.callFake((id) => (document.querySelectorAll(id).length ? document.querySelectorAll(id)[0] : null));
});

afterEach(function () {
Expand Down Expand Up @@ -268,10 +275,12 @@ describe('The ContentDelegate class', function () {
status: 200,
contentType: 'application/json',
responseText:
'{"count": 1, "results": [' +
'{"date_modified": "04/16/15", "absolute_url": ' +
'"/download/gov.uscourts.' +
'canb.531591/gov.uscourts.canb.531591.docket.html"}]}',
'{"count": 1,' +
'"results": [{' +
'"date_modified": "04/16/15",' +
'"absolute_url": "/download/gov.uscourts.canb.531591/gov.uscourts.canb.531591.docket.html",' +
'"date_last_filing": "2015-04-20"' +
'}]}',
});
const banner = document.querySelectorAll('.recap-banner')[0];
expect(banner).not.toBeNull();
Expand All @@ -281,6 +290,28 @@ describe('The ContentDelegate class', function () {
expect(link.href).toBe(
'https://www.courtlistener.com/download/gov.uscourts.' + 'canb.531591/gov.uscourts.canb.531591.docket.html'
);
const autofill = document.querySelector('.recap-filing-button');
expect(autofill).not.toBeNull();
});

it("don't inserts the autofill button when a docket don't have last_filing", function () {
const cd = docketQueryContentDelegate;
spyOn(PACER, 'hasPacerCookie').and.returnValue(true);
cd.handleDocketQueryUrl();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'application/json',
responseText: '{"count": 1,' +
'"results": [{' +
'"date_modified": "04/16/15",' +
'"absolute_url": "/download/gov.uscourts.canb.531591/gov.uscourts.canb.531591.docket.html",' +
'"date_last_filing": null' +
'}]}',
});
const banner = document.querySelectorAll('.recap-banner')[0];
expect(banner).not.toBeNull();
const autofill = document.querySelector('.recap-filing-button');
expect(autofill).toBeNull();
});

it('has no effect when on a docket query that has no RECAP', function () {
Expand Down Expand Up @@ -1075,9 +1106,9 @@ describe('The ContentDelegate class', function () {
// });
});

afterEach(function(){
window.getPacerCaseIdFromPacerDocId = jasmine.createSpy().and.callThrough()
})
afterEach(function () {
window.getPacerCaseIdFromPacerDocId = jasmine.createSpy().and.callThrough();
});

it('makes the back button redisplay the previous page', async function () {
await cd.showPdfPage(html);
Expand Down
2 changes: 1 addition & 1 deletion spec/RecapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('The Recap export module', function () {
'https://www.courtlistener.com/api/rest/v3/dockets/' +
'?source__in=1%2C3%2C5%2C7%2C9%2C11%2C13%2C15' +
'&court=canb' +
'&fields=absolute_url%2Cdate_modified'+
'&fields=absolute_url%2Cdate_modified%2Cdate_last_filing'+
'&pacer_case_id=531316');
});

Expand Down
9 changes: 9 additions & 0 deletions src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,13 @@ footer #version {
.recap-inline-appellate{
display: inline-flex;
padding: 0px 3px;
}

.recap-filing-button{
vertical-align: middle;
padding-left: 4px;
}

.recap-filing-button > img{
padding-top: 2px;
}
4 changes: 4 additions & 0 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,16 @@ ContentDelegate.prototype.handleDocketQueryUrl = function () {
} else {
if (result.results) {
PACER.removeBanners();
const dateToInput = document.querySelector('input[name=date_to]');
const form = document.querySelector('form');
const div = document.createElement('div');

div.classList.add('recap-banner');
div.appendChild(recapAlertButton(this.court, this.pacer_case_id, true));
form.appendChild(recapBanner(result.results[0]));
form.appendChild(div);

if (result.results[0].date_last_filing) dateToInput.after(recapAddLatestFilingButton(result.results[0]));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/pacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ let PACER = {

// Remove banners inserted by the extension
removeBanners: ()=>{
let banners = document.querySelectorAll('.recap-banner');
let banners = document.querySelectorAll('.recap-banner, .recap-filing-button');
banners.forEach(banner => { banner.remove(); });
},

Expand Down
2 changes: 1 addition & 1 deletion src/recap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Recap() {
// Ensure RECAP is a source so we don't get back IDB-only dockets.
source__in: '1,3,5,7,9,11,13,15',
court: PACER.convertToCourtListenerCourt(pacer_court),
fields: 'absolute_url,date_modified'
fields: 'absolute_url,date_modified,date_last_filing'
}

if (pacer_case_id){
Expand Down
36 changes: 36 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ const removeFilingState = () => {
document.cookie = "isFilingAccount=false;path=/;domain=.uscourts.gov";
}

// converts an ISO-8601 date str to 'MM/DD/YYYY' format
function pacerDateFormat(date) {
return date.replace(/(\d+)-(\d+)-(\d+)/, "$2/$3/$1");
}

// Default settings for any jquery $.ajax call.
$.ajaxSetup({
// The dataType parameter is a security measure requested by Opera code
Expand Down Expand Up @@ -283,7 +288,38 @@ const recapAlertButton = (court, pacerCaseId, isActive) => {
return anchor;
};

// Creates an anchor element to autofill the Docket Query form
const recapAddLatestFilingButton = (result) => {
let date = result.date_last_filing;
let formatted_date = pacerDateFormat(date)

const anchor = document.createElement('a');
anchor.classList.add('recap-filing-button');
anchor.title = 'Autofill the form to get the latest content not yet in RECAP, omitting parties and member cases.';
anchor.setAttribute('data-date_from', formatted_date);
anchor.href = '#';

const img = document.createElement('img');
img.src = chrome.extension.getURL('assets/images/icon-16.png');

anchor.innerHTML = `${img.outerHTML}`;

anchor.onclick = function (e) {
let target = e.currentTarget || e.target;

let dateInput = document.querySelector("[name='date_from']");
let partyCheckbox = document.getElementById('list_of_parties_and_counsel');
let filedCheckbox = document.querySelector('input[value="Filed"]');

dateInput.value = target.dataset.date_from;
partyCheckbox.checked = false;
filedCheckbox.checked = true;

return false;
};

return anchor;
};

// Creates a div element to show a docket is available for free
const recapBanner = (result) => {
Expand Down

0 comments on commit 867db07

Please sign in to comment.