Commit 362383d5 authored by Maxime Chaillet's avatar Maxime Chaillet

keep 'proposal,beamline' couple unique in the displayed table.

parent 2759a318
......@@ -59,7 +59,7 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
browsers: ['Firefox', 'Chrome' ],
// Continuous Integration mode
......
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -71,18 +71,20 @@ DOIController.prototype.getData = function (doi) {
doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = data.publisher;
doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.publiclyAccessibleYear = data.publication_year;
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalName = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
doiData.proposalNames = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
_this.experimentalReportController.requestFilenameList(doiData.proposalName);
doiData.beamline = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
doiData.beamlines = jsonExtractor.getFieldFromSubject(data.subject, "Instrument");
doiData.mergedProposalBeamlines = jsonExtractor.getMergedProposalAndBeamline(doiData.proposalNames, doiData.beamlines);
doiData.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
......
......@@ -4,11 +4,8 @@ function JsonExtractor(json) {
/**
* Extract investigationId from the data.doi field as received from the json
* response.
*
* @param {string}
* data The data object provided by datacite
* @return {string}
* investigationId The investigationID requested for accessing data in ICAT.
* @param {string} data The data object provided by datacite
* @return {string} investigationId The investigationID requested for accessing data in ICAT.
*/
JsonExtractor.prototype.extractInvestigationId = function (data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
......@@ -19,7 +16,6 @@ JsonExtractor.prototype.extractInvestigationId = function (data) {
/**
* Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns null if the field is not found.
*
* @param {array} subject The array containing objects of interest template
* @param {string} field The text field which is searched
* @returns {array} the found field in an array. When the field is string composed of coma separated items, each item is returned in the array. When there is no text, an empty array is returned
......@@ -42,11 +38,8 @@ JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
/**
* Get minting year from the data object.
*
* @param {object}
* data The data object provided by datacite template
* @return {string}
* The minting year. Null if it does not exist.
* @param {object} data The data object provided by datacite template
* @return {string} The minting year. Null if it does not exist.
*/
JsonExtractor.prototype.getMintingYear = function (data) {
if (data) {
......@@ -59,11 +52,8 @@ JsonExtractor.prototype.getMintingYear = function (data) {
/**
* Get session date from the data object.
*
* @param {object}
* data The data object provided by datacite
* @return {string}
* The formatted (YYY-M-D) session date. Null if it does not exist.
* @param {object} data The data object provided by datacite
* @return {string} The formatted (YYY-M-D) session date. Null if it does not exist.
*/
JsonExtractor.prototype.getSessionDate = function (data) {
if (data) {
......@@ -77,10 +67,8 @@ JsonExtractor.prototype.getSessionDate = function (data) {
/**
* Get the resource type general
* @param {object}
* data The data object provided by datacite
* @return {string}
* The resource tyoe general. Null if it does not exist.
* @param {object} data The data object provided by datacite
* @return {string} The resource type general. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
if (data && data.resource_type_general) {
......@@ -92,7 +80,7 @@ JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
/**
* Get the resource type
* @param {object} data The data object provided by datacite
* @return {string} Resource tyoe. Null if it does not exist.
* @return {string} Resource type. Null if it does not exist.
* */
JsonExtractor.prototype.getResourceType = function (data) {
if (data && data.resource_type) {
......@@ -105,3 +93,39 @@ JsonExtractor.prototype.getResourceType = function (data) {
}
return null;
};
/**
* Get the abstract from the data
* @param {*} data data object provided by datacite
* @return {string} the abstract . Null if it does not exist.
*/
JsonExtractor.prototype.getAbstract = function (data) {
if (data && data.description) {
var description = data.description;
if (description.type && description.type === 'Abstract') {
return description.text;
}
}
return null;
};
/**
* merge proposal and beamlines together and remove proposal, beamline duplicates if any
* @param {array} proposals the extracted proposals
* @param {array} beamlines the extracted beamlines
* @return {array} array of the form [ [proposal1, beamline1] , [proposal2, beamline2] ]. Null if input array length are not equal
*/
JsonExtractor.prototype.getMergedProposalAndBeamline = function (proposals, beamlines) {
console.log(proposals);
console.log(beamlines);
if (proposals && beamlines && proposals.length === beamlines.length) {
var result = [];
for (var index = 0; index < proposals.length; index++) {
result.push(new Array(proposals[index], beamlines[index]));
}
return _.uniqBy(result, function (value) { return JSON.stringify(value); });
}
return null;
}
function proposalBeamLineTable(chunk, context, bodies, params) {
var proposals = params.proposals;
var beamlines = params.beamlines;
chunk.write('<table class="table table-striped">');
chunk.write('<thead>');
chunk.write('<tr>');
chunk.write('<th scope="col">Proposal</th>');
chunk.write('<th scope="col">Beamline</th>');
chunk.write('</tr>');
chunk.write('</thead>');
chunk.write('<tbody>');
for (var index = 0; index < proposals.length; index++) {
var proposal = proposals[index];
var beamline = beamlines[index];
/**
* Helper function which displays the proposals and beamlines under the form of a table. Used in the context of a doi
* created for a dataset collection.
*/
function proposalBeamlineTable(chunk, context, bodies, params) {
var proposalAndBeamlines = params.mergedProposalBeamlines;
chunk.write('<table class="table table-striped">');
chunk.write('<thead>');
chunk.write('<tr>');
chunk.write('<td>' + proposals[index] + '</td>');
if (beamlines[index]) {
chunk.write('<td>' + beamlines[index] + '</td>');
chunk.write('<th scope="col">Proposal</th>');
chunk.write('<th scope="col">Beamline</th>');
chunk.write('</tr>');
chunk.write('</thead>');
chunk.write('<tbody>');
if (proposalAndBeamlines) {
for (var index = 0; index < proposalAndBeamlines.length; index++) {
if (proposalAndBeamlines[index] instanceof Array) {
var proposal = proposalAndBeamlines[index][0] || 'unknown';
var beamline = proposalAndBeamlines[index][1] || 'unknown';
chunk.write('<tr>');
chunk.write('<td>' + proposal + '</td>');
chunk.write('<td>' + beamline + '</td>');
chunk.write('</tr>');
} else {
chunk.write('<tr>');
chunck.write('<td> unknown </td>');
chunck.write('<td> unknown </td>');
chunk.write('</tr>');
}
}
chunk.write('</tbody>');
chunk.write('</table>');
return chunk.render(bodies.block, context);
}
}
/** Helper function which dislays the abstract for a given doi */
function abstract(chunk, context, bodies, params) {
var abstract = params.abstract;
chunk.write('<div class="myBorder-left">');
chunk.write('<label> Abstract </label>');
chunk.write('<div class="padding-left-15">');
if (abstract) {
chunk.write(abstract);
} else {
chunck.write('<td> unknown </td>');
chunk.write('There is no abstract for this session.')
}
chunk.write('</tr>');
}
chunk.write('</tbody>');
chunk.write('</table>');
return chunk.render(bodies.block, context);
chunk.write('</div >');
chunk.write('</div >');
return chunk.render(bodies.block, context);
}
dust.helpers.proposalBeamLineTable = proposalBeamLineTable;
dust.helpers.proposalBeamlineTable = proposalBeamlineTable;
dust.helpers.abstract = abstract;
......@@ -54,22 +54,8 @@
<hr>
<div class="row" id="metadata">
</div>
<hr>
<div class="row">
<div class="col-12">
<div class="myBorder-left">
<label> Abstract </label>
<div class="padding-left-15">
There is no abstract for this session.
</div>
</div>
</div>
</div>
<div class="row" id="metadata"> </div>
<hr>
<div class="row">
......
......@@ -58,21 +58,42 @@
<div class="padding-left-15"> Not available</div>
{/data.proposalType}
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-12">
{@abstract abstract=data.abstract} {/abstract}
</div>
</div>
{/eq}
{@eq key=data.resourceType value=data.DC_RESOURCE_TYPE}
<div class="container-fluid">
<div class="row">
<div class="col-6">
{@abstract abstract=data.abstract} {/abstract}
</div>
<div class="col-sm-3">
<div class="myBorder-left">
{@proposalBeamLineTable proposals=data.proposalName beamlines=data.beamline }
{/proposalBeamLineTable}
{@proposalBeamlineTable mergedProposalBeamlines=data.mergedProposalBeamlines} {/proposalBeamlineTable}
</div>
</div>
<div class="col-sm-9">
le reste
<div class="col-sm-3">
<div class="myBorder-left">
<label> Publication year </label>
{?data.mintingYear}
<div class="padding-left-15">{data.mintingYear}</div>
{:else}
<div class="padding-left-15"> Not available</div>
{/data.mintingYear}
</div>
</div>
</div>
</div>
{/eq}
......@@ -104,7 +104,25 @@ describe("jsonExtractor", () => {
expect(myJsonExtractor.getResourceType(actualDoiData)).toEqual(expectedResourceType);
})
})
describe("getMergedProposalAndBeamline", () => {
it('merge proposals and beamlines in a single table', () => {
let actualProposals = ['MA-4196', 'MD-1207'];
let actualBeamlines = ['ID11', 'ID21'];
let expectedMerge = [['MA-4196', 'ID11'], ['MD-1207', 'ID21']];
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines)).toEqual(expectedMerge);
})
it('merge proposals and beamlines in a single table and remove duplicates', () => {
let actualProposals = ['MA-4196', 'MD-1207', 'MA-4196'];
let actualBeamlines = ['ID11', 'ID21', 'ID11'];
let expectedMerge = [['MA-4196', 'ID11'], ['MD-1207', 'ID21']];
let myJsonExtractor = new JsonExtractor();
expect(myJsonExtractor.getMergedProposalAndBeamline(actualProposals, actualBeamlines)).toEqual(expectedMerge);
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment