Skip to content

Commit

Permalink
Merge pull request Arelle#467 from paulwarren-wk/js-modernize-inspector
Browse files Browse the repository at this point in the history
Modernize JavaScript in inspector.js
  • Loading branch information
rmconsole4-wk authored Jun 29, 2023
2 parents beb9a72 + 91790d3 commit 22a5654
Show file tree
Hide file tree
Showing 5 changed files with 997 additions and 944 deletions.
34 changes: 28 additions & 6 deletions iXBRLViewerPlugin/viewer/src/js/identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ const schemes = {
};

export class Identifiers {
static identifierURLForFact(fact) {
const data = schemes[fact.identifier().namespace];
static identifierURL(identifier) {
const data = schemes[identifier.namespace];
if (data !== undefined && data.url !== undefined) {
let url = data.url.replace('%s', fact.identifier().localname);
url = url.replace(/%0(\d+)d/, function (match, width) {
return fact.identifier().localname.padStart(width, "0");
});
let url = data.url.replace('%s', identifier.localname);
url = url.replace(/%0(\d+)d/, (match, width) => identifier.localname.padStart(width, "0"));
return url;
}
return undefined;
Expand All @@ -47,4 +45,28 @@ export class Identifiers {
}
return identifier.qname
}

static readableNameHTML(identifier) {
const data = schemes[identifier.namespace];
const span = document.createElement("span");
if (data !== undefined) {
const schemeSpan = span.appendChild(document.createElement("span"));
schemeSpan.textContent = "[" + data.name + "] ";
const url = Identifiers.identifierURL(identifier);
if (url !== undefined) {
const a = span.appendChild(document.createElement("a"));
a.textContent = identifier.localname;
a.setAttribute("target", "_blank");
a.setAttribute("href", url);
}
else {
const el = span.appendChild(document.createElement("span"));
el.textContent = identifier.localname;
}
}
else {
span.textContent = identifier.qname;
}
return span;
}
}
51 changes: 51 additions & 0 deletions iXBRLViewerPlugin/viewer/src/js/identifiers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Identifiers } from './identifiers.js';
import { QName } from './qname.js';

const prefixMap = {
"e": "http://example.com",
"cik": "http://www.sec.gov/CIK",
"crn": "http://www.companieshouse.gov.uk/",
"ua": "https://www.minfin.gov.ua",
};

function qname(s) {
return new QName(prefixMap, s);
}

describe("readableName", () => {
test("Unknown scheme", () => {
expect(Identifiers.readableName(qname("e:1234"))).toBe("e:1234");
});
test("Known scheme", () => {
expect(Identifiers.readableName(qname("cik:1234"))).toBe("[CIK] 1234");
expect(Identifiers.readableName(qname("ua:01234"))).toBe("[EDRPOU] 01234");
});
});

describe("readableNameHTML", () => {
test("Unknown scheme", () => {
const html = Identifiers.readableNameHTML(qname("e:1234"));
expect(html.textContent).toBe("e:1234");
});
test("Known scheme with URL", () => {
const html = Identifiers.readableNameHTML(qname("cik:1234"));
expect(html.childNodes.length).toBe(2);
expect(html.childNodes[0].textContent).toBe("[CIK] ");
expect(html.childNodes[1].nodeName).toBe("A");
expect(html.childNodes[1].getAttribute("href")).toBe("https://www.sec.gov/cgi-bin/browse-edgar?CIK=1234");
});
test("Known scheme with URL, padded identifier", () => {
const html = Identifiers.readableNameHTML(qname("crn:1234"));
expect(html.childNodes.length).toBe(2);
expect(html.childNodes[0].textContent).toBe("[UK CRN] ");
expect(html.childNodes[1].nodeName).toBe("A");
expect(html.childNodes[1].getAttribute("href")).toBe("https://beta.companieshouse.gov.uk/company/00001234");
});
test("Known scheme without URL", () => {
const html = Identifiers.readableNameHTML(qname("ua:1234"));
expect(html.childNodes.length).toBe(2);
expect(html.childNodes[0].textContent).toBe("[EDRPOU] ");
expect(html.childNodes[1].nodeName).toBe("SPAN");
expect(html.childNodes[1].textContent).toBe("1234");
});
});
Loading

0 comments on commit 22a5654

Please sign in to comment.