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

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

parent 2759a318
...@@ -59,7 +59,7 @@ module.exports = function(config) { ...@@ -59,7 +59,7 @@ module.exports = function(config) {
// start these browsers // start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'], browsers: ['Firefox', 'Chrome' ],
// Continuous Integration mode // 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) { ...@@ -71,18 +71,20 @@ DOIController.prototype.getData = function (doi) {
doiData.dataciteLink = _this.doiServer + doi; doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = data.publisher; doiData.publisher = data.publisher;
doiData.creator = data.creator; doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor(); var jsonExtractor = new JsonExtractor();
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.mintingYear = jsonExtractor.getMintingYear(data); doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data); doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.publiclyAccessibleYear = data.publication_year; doiData.publiclyAccessibleYear = data.publication_year;
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description"); 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); _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.investigationId = jsonExtractor.extractInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data); doiData.resourceType = jsonExtractor.getResourceType(data);
......
...@@ -4,11 +4,8 @@ function JsonExtractor(json) { ...@@ -4,11 +4,8 @@ function JsonExtractor(json) {
/** /**
* Extract investigationId from the data.doi field as received from the json * Extract investigationId from the data.doi field as received from the json
* response. * response.
* * @param {string} data The data object provided by datacite
* @param {string} * @return {string} investigationId The investigationID requested for accessing data in ICAT.
* data The data object provided by datacite
* @return {string}
* investigationId The investigationID requested for accessing data in ICAT.
*/ */
JsonExtractor.prototype.extractInvestigationId = function (data) { JsonExtractor.prototype.extractInvestigationId = function (data) {
var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/); var regExp = RegExp(/\/\w*-*[Ee][Ss][Rr][Ff]-[Ee][Ss]-(\d+)$/);
...@@ -19,7 +16,6 @@ JsonExtractor.prototype.extractInvestigationId = function (data) { ...@@ -19,7 +16,6 @@ JsonExtractor.prototype.extractInvestigationId = function (data) {
/** /**
* Extract field value (beamline, proposal number and proposal type) from the * Extract field value (beamline, proposal number and proposal type) from the
* data json object. Returns null if the field is not found. * data json object. Returns null if the field is not found.
*
* @param {array} subject The array containing objects of interest template * @param {array} subject The array containing objects of interest template
* @param {string} field The text field which is searched * @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 * @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) { ...@@ -42,11 +38,8 @@ JsonExtractor.prototype.getFieldFromSubject = function (subject, field) {
/** /**
* Get minting year from the data object. * Get minting year from the data object.
* * @param {object} data The data object provided by datacite template
* @param {object} * @return {string} The minting year. Null if it does not exist.
* data The data object provided by datacite template
* @return {string}
* The minting year. Null if it does not exist.
*/ */
JsonExtractor.prototype.getMintingYear = function (data) { JsonExtractor.prototype.getMintingYear = function (data) {
if (data) { if (data) {
...@@ -59,11 +52,8 @@ JsonExtractor.prototype.getMintingYear = function (data) { ...@@ -59,11 +52,8 @@ JsonExtractor.prototype.getMintingYear = function (data) {
/** /**
* Get session date from the data object. * Get session date from the data object.
* * @param {object} data The data object provided by datacite
* @param {object} * @return {string} The formatted (YYY-M-D) session date. Null if it does not exist.
* 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) { JsonExtractor.prototype.getSessionDate = function (data) {
if (data) { if (data) {
...@@ -77,10 +67,8 @@ JsonExtractor.prototype.getSessionDate = function (data) { ...@@ -77,10 +67,8 @@ JsonExtractor.prototype.getSessionDate = function (data) {
/** /**
* Get the resource type general * Get the resource type general
* @param {object} * @param {object} data The data object provided by datacite
* data The data object provided by datacite * @return {string} The resource type general. Null if it does not exist.
* @return {string}
* The resource tyoe general. Null if it does not exist.
* */ * */
JsonExtractor.prototype.getResourceTypeGeneral = function (data) { JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
if (data && data.resource_type_general) { if (data && data.resource_type_general) {
...@@ -92,7 +80,7 @@ JsonExtractor.prototype.getResourceTypeGeneral = function (data) { ...@@ -92,7 +80,7 @@ JsonExtractor.prototype.getResourceTypeGeneral = function (data) {
/** /**
* Get the resource type * Get the resource type
* @param {object} data The data object provided by datacite * @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) { JsonExtractor.prototype.getResourceType = function (data) {
if (data && data.resource_type) { if (data && data.resource_type) {
...@@ -105,3 +93,39 @@ JsonExtractor.prototype.getResourceType = function (data) { ...@@ -105,3 +93,39 @@ JsonExtractor.prototype.getResourceType = function (data) {
} }
return null; 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; * Helper function which displays the proposals and beamlines under the form of a table. Used in the context of a doi
var beamlines = params.beamlines; * created for a dataset collection.
*/
chunk.write('<table class="table table-striped">'); function proposalBeamlineTable(chunk, context, bodies, params) {
chunk.write('<thead>'); var proposalAndBeamlines = params.mergedProposalBeamlines;
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];
chunk.write('<table class="table table-striped">');
chunk.write('<thead>');
chunk.write('<tr>'); chunk.write('<tr>');
chunk.write('<td>' + proposals[index] + '</td>'); chunk.write('<th scope="col">Proposal</th>');
if (beamlines[index]) { chunk.write('<th scope="col">Beamline</th>');
chunk.write('<td>' + beamlines[index] + '</td>'); 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 { } else {
chunck.write('<td> unknown </td>'); chunk.write('There is no abstract for this session.')
} }
chunk.write('</tr>');
} chunk.write('</div >');
chunk.write('</div >');
chunk.write('</tbody>'); return chunk.render(bodies.block, context);
chunk.write('</table>');
return chunk.render(bodies.block, context);
} }
dust.helpers.proposalBeamLineTable = proposalBeamLineTable;
dust.helpers.proposalBeamlineTable = proposalBeamlineTable;
dust.helpers.abstract = abstract;
...@@ -54,22 +54,8 @@ ...@@ -54,22 +54,8 @@
<hr> <hr>
<div class="row" id="metadata"> <div class="row" id="metadata"> </div>
</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>
<hr> <hr>
<div class="row"> <div class="row">
......
...@@ -58,21 +58,42 @@ ...@@ -58,21 +58,42 @@
<div class="padding-left-15"> Not available</div> <div class="padding-left-15"> Not available</div>
{/data.proposalType} {/data.proposalType}
</div> </div>
</div> </div>
<hr>
<div class="row">
<div class="col-12">
{@abstract abstract=data.abstract} {/abstract}
</div>
</div>
{/eq} {/eq}
{@eq key=data.resourceType value=data.DC_RESOURCE_TYPE} {@eq key=data.resourceType value=data.DC_RESOURCE_TYPE}
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-6">
{@abstract abstract=data.abstract} {/abstract}
</div>
<div class="col-sm-3"> <div class="col-sm-3">
<div class="myBorder-left"> <div class="myBorder-left">
{@proposalBeamLineTable proposals=data.proposalName beamlines=data.beamline } {@proposalBeamlineTable mergedProposalBeamlines=data.mergedProposalBeamlines} {/proposalBeamlineTable}
{/proposalBeamLineTable}
</div> </div>
</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> </div>
</div> </div>
{/eq} {/eq}
...@@ -104,7 +104,25 @@ describe("jsonExtractor", () => { ...@@ -104,7 +104,25 @@ describe("jsonExtractor", () => {
expect(myJsonExtractor.getResourceType(actualDoiData)).toEqual(expectedResourceType); 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