Skip to content

Commit

Permalink
Add Service Level field to blank request form
Browse files Browse the repository at this point in the history
Fixes PR-2056.
  • Loading branch information
MikeTaylor authored Jan 9, 2025
1 parent 0754028 commit 42d004e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Make robust against old version of mod-rs (e.g. 2.15.5) that do not return lists of copyright types. Fixes PR-1841.
* Support per-service config item `allowAnyDate` to disable date validation in forms. Update docs, add tests. Fixes PR-2059.
* Support per-service config item `alwaysShowForm` to specify that the full form always should be displayed once for confirmation even when the submitted OpenURL has complete basic metadata. Update docs. Fixes PR-2059.
* Add Service Level field to blank request form. Fixes PR-2056.

## [1.6.0](https://github.com/openlibraryenvironment/listener-openurl/tree/v1.6.0) (2024-03-04)

Expand Down
11 changes: 11 additions & 0 deletions config/templates/form1.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ <h2>Request type</h2>
</div>
</div>

<div class="key-value-pair">
<div class="key">Service level</div>
<div class="value">
<select class="select" id="input-serviceLevel" name="svc.level">
{{#each serviceLevels}}
<option value="{{this.code}}" {{this.selected}}>{{this.name}}</option>
{{/each}}
</select>
</div>
</div>

{{#unless digitalOnly}}
<div id="div-pickupLocation" class="key-value-pair">
<label class="key" for="input-pickupLocation">Pick up location</label>
Expand Down
22 changes: 18 additions & 4 deletions src/OkapiSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class OkapiSession {
}

async _getDataFromReShare(path, caption) {
if (this.logger.values?.withoutOkapi) {
// Running as part of a test: do nothing
return {};
}

const res = await this.okapiFetch('GET', path);
if (res.status !== 200) throw new HTTPError(res, `cannot fetch default ${caption} for '${this.label}'`);
const json = await res.json();
Expand All @@ -54,11 +59,20 @@ class OkapiSession {
});
}

async _getRefDataValues(desc, caption) {
const path = `/rs/refdata?filters=desc%3D%3D${desc}&sort=desc%3Basc&max=100`;
const json = await this._getDataFromReShare(path, caption);
return json[0]?.values.map(r => ({ id: r.id, code: r.value, name: r.label }));
}

async getCopyrightTypes() {
const path = '/rs/refdata?filters=desc%3D%3DcopyrightType&sort=desc%3Basc&max=100';
const json = await this._getDataFromReShare(path, 'copyright types');
this.copyrightTypes = json[0]?.values
.map(r => ({ id: r.id, code: r.value, name: r.label }));
// XXX could no-op if this.copyrightTypes is already defined
this.copyrightTypes = await this._getRefDataValues('copyrightType', 'copyright types');
}

async getServiceLevels() {
// XXX could no-op if this.serviceLevels is already defined
this.serviceLevels = await this._getRefDataValues('ServiceLevels', 'service levels');
}

async getDefaultCopyrightType() {
Expand Down
12 changes: 10 additions & 2 deletions src/OpenURLServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ function makeFormData(ctx, query, service, valuesNotShownInForm, firstTry, npl)
name: x.charAt(0).toUpperCase() + x.slice(1),
checked: x === query.svc_id || (!query.svc_id && i === 0) ? 'checked' : '',
})),
serviceLevels: (service.serviceLevels || []).map(x => ({
...x,
selected: x.code === query['svc.level'] ? 'selected' : '',
})),
pubDateValidation: ctx.state?.svcCfg?.allowAnyDate ? '' : 'pattern="[0-9]*" ',
});

Expand Down Expand Up @@ -179,7 +183,7 @@ async function maybeRenderForm(ctx, next) {
formName = 'form1';
formFields.push('rft.title', 'rft.au', 'rft.date', 'rft.pub', 'rft.place', 'rft.edition', 'rft.isbn', 'rft.oclc',
'rft.authorOfComponent', 'rft.copyrightType', 'rft.genre', 'rft.issn', 'rft.jtitle', 'rft.pagesRequested',
'rft.sponsoringBody', 'rft.subtitle', 'rft.titleOfComponent', 'rft.issue', 'svc_id');
'rft.sponsoringBody', 'rft.subtitle', 'rft.titleOfComponent', 'rft.issue', 'svc_id', 'svc.level');
}

ctx.cfg.log('flow', 'Rendering form', formName);
Expand All @@ -192,6 +196,8 @@ async function maybeRenderForm(ctx, next) {
]);
}

await service.getServiceLevels();

const originalQuery = co.getQuery();
const query = {};
Object.keys(originalQuery).forEach(key => {
Expand Down Expand Up @@ -322,7 +328,9 @@ class OpenURLServer {

const serviceConfigs = cfg.getValues().services || [];
Object.keys(serviceConfigs).forEach(label => {
this.services[label] = new OkapiSession(cfg, label, serviceConfigs[label]);
const values = { ...serviceConfigs[label] };
if (cfg.values.withoutOkapi) values.withoutOkapi = true;
this.services[label] = new OkapiSession(cfg, label, values);
});

// Default service
Expand Down
1 change: 1 addition & 0 deletions src/ReshareRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function translateCOtoRR(co) {

// These are non-standard fields in OpenURL 1.0
rr.serviceType = _.get(a, 'svc.id'); // No example of this in Z39.88
rr.serviceLevel = _.get(m, 'svc.level');
rr.isRequester = true;
const copyrightType = _.get(m, 'rft.copyrightType');
if (copyrightType) rr.copyrightType = { value: copyrightType };
Expand Down
2 changes: 1 addition & 1 deletion test/05-OpenURLServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ chai.use(chaiHttp);
const app = (new OpenURLServer(new Config({
// loggingCategories: 'error,start,okapi,co,rr,admindata,metadata,flow',
loggingCategories: '',
withoutOkapi: true,
services: {
'US-EAST': {
withoutOkapi: true,
reqIdToLower: true,
reqIdRegex: 'abc-(.*)',
reqIdReplacement: '$1-b',
Expand Down

0 comments on commit 42d004e

Please sign in to comment.