hal-browser
Advanced tools
Comparing version 0.8.0 to 0.8.1
Changelog | ||
========= | ||
0.8.1 (2019-11-04) | ||
------------------ | ||
* Pager buttons had incorrect text color in new theme. | ||
0.8.0 (2019-10-09) | ||
@@ -5,0 +11,0 @@ ------------------ |
@@ -0,2 +1,3 @@ | ||
import { Context } from '@curveball/core'; | ||
import { Link, SureOptions } from '../types'; | ||
export default function forms(links: Link[], options: SureOptions): string; | ||
export default function forms(ctx: Context, links: Link[], options: SureOptions): string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const util_1 = require("../util"); | ||
function forms(links, options) { | ||
const hal_forms_1 = __importDefault(require("./forms/hal-forms")); | ||
const templated_links_1 = __importDefault(require("./forms/templated-links")); | ||
function forms(ctx, links, options) { | ||
let formHtml = ''; | ||
for (const link of links) { | ||
if (options.hiddenRels.includes(link.rel) || link.rel in options.navigationLinks) { | ||
continue; | ||
} | ||
// We're only interested in templated links | ||
if (!link.templated) { | ||
continue; | ||
} | ||
const fields = []; | ||
const hiddenFields = []; | ||
// We only support 2 styles of templated links: | ||
// | ||
// https://foo/{?a}{?b} | ||
// | ||
// and | ||
// | ||
// https://foo/?foo={bar} | ||
// | ||
// More formats might be added if they are requested. | ||
// This regex finds blocks like {?foo} | ||
const reg = /{\?[A-Za-z]+}/g; | ||
const matches = link.href.match(reg); | ||
if (matches) { | ||
for (const match of matches) { | ||
// Stripping off {? and } | ||
fields.push({ | ||
name: match.slice(2, -1), | ||
value: '', | ||
label: match.slice(2, -1), | ||
}); | ||
} | ||
} | ||
// Removing {?foo} blocks. | ||
const [target, querystring] = link.href.replace(reg, '').split('?'); | ||
if (target.indexOf('{') !== -1) { | ||
// We don't support expressions in the path/hostname part of the uri | ||
continue; | ||
} | ||
if (querystring) { | ||
for (const qsPart of querystring.split('&')) { | ||
const [field, value] = qsPart.split('='); | ||
if (value.match(/{.*}$/)) { | ||
fields.push({ | ||
name: field, | ||
value: '', | ||
label: value.slice(1, -1), | ||
}); | ||
} | ||
else { | ||
hiddenFields.push({ | ||
name: field, | ||
value: decodeURIComponent(value), | ||
label: '', | ||
}); | ||
} | ||
} | ||
} | ||
const title = link.title || link.rel; | ||
let html = `<form method="GET" action="${util_1.h(target)}" class="long-form"> | ||
<h3>${util_1.h(title)}</h3> | ||
`; | ||
for (const field of hiddenFields) { | ||
html += `<input type="hidden" name="${util_1.h(field.name)}" value="${util_1.h(field.value)}" />`; | ||
} | ||
for (const field of fields) { | ||
html += `<label>${util_1.h(field.label)}</label><input type="text" name="${util_1.h(field.name)}" />`; | ||
} | ||
html += '<button type="submit">Submit</button>'; | ||
html += '</form>'; | ||
formHtml += html; | ||
link.rendered = true; | ||
formHtml += templated_links_1.default(links, options); | ||
const target = '_htarget' in ctx.request.query ? ctx.request.query._htarget : ctx.request.path; | ||
if (ctx.response.is('application/prs.hal-forms+json')) { | ||
formHtml += hal_forms_1.default(target, ctx.response.body); | ||
} | ||
@@ -78,0 +15,0 @@ if (!formHtml) { |
@@ -17,3 +17,3 @@ "use strict"; | ||
async function resource(ctx, body, links, options) { | ||
const formsHtml = forms_1.default(links, options); | ||
const formsHtml = forms_1.default(ctx, links, options); | ||
const linksHtml = links_table_1.default(links, options); | ||
@@ -20,0 +20,0 @@ return ` |
@@ -14,2 +14,3 @@ "use strict"; | ||
'text/csv', | ||
'application/prs.hal-forms+json' | ||
]; | ||
@@ -16,0 +17,0 @@ /* |
{ | ||
"name": "hal-browser", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "A HAL browser middleware", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
100491
87
1926