2015-12-04 22:42:41 -05:00
|
|
|
module.exports = plugin;
|
|
|
|
|
2015-12-05 18:44:51 -05:00
|
|
|
var formatAuthor = require("../lib/format-name.js");
|
2015-12-04 22:42:41 -05:00
|
|
|
|
|
|
|
function plugin() {
|
|
|
|
return function (files, smith, done){
|
2015-12-05 18:44:51 -05:00
|
|
|
var lab = smith.metadata().labMembers;
|
2015-12-04 22:42:41 -05:00
|
|
|
var grants = smith.metadata().okennedy.data.grants;
|
|
|
|
var grantsByYear = {}
|
|
|
|
for(i in grants){
|
|
|
|
var grant = grants[i]
|
2016-03-25 10:52:26 -04:00
|
|
|
if(!(grant.status == "accepted" || grant.status == "completed")){ continue; }
|
2015-12-04 22:42:41 -05:00
|
|
|
|
|
|
|
var year = grant.start.split(/\//)[1]
|
|
|
|
|
|
|
|
var pis = [ smith.metadata().okennedy.data.name ]
|
|
|
|
if(typeof grant.copis != 'undefined'){
|
2015-12-05 18:44:51 -05:00
|
|
|
pis = grant.copis.concat(pis)
|
2015-12-04 22:42:41 -05:00
|
|
|
}
|
|
|
|
// console.log(pis)
|
|
|
|
var piFormat = pis.map(formatAuthor(lab)).join(", ")
|
|
|
|
|
|
|
|
// console.log(grant.supports)
|
|
|
|
var supportsFormat = null;
|
|
|
|
if(typeof grant.supports != 'undefined'){
|
|
|
|
supportsFormat = grant.supports.map(formatAuthor(lab)).join(", ")
|
|
|
|
}
|
|
|
|
|
|
|
|
var amount = parseInt(grant.amount)
|
|
|
|
|
|
|
|
var resourcesFormat = ""
|
|
|
|
if(typeof grant.urls == 'object') {
|
|
|
|
var resources = []
|
|
|
|
for(cat in grant.urls){
|
|
|
|
resources.push("<a href="+grant.urls[cat]+">"+cat+"</a>");
|
|
|
|
}
|
|
|
|
resourcesFormat = resources.join(" // ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(typeof grantsByYear[year] == 'undefined') {
|
|
|
|
grantsByYear[year] = []
|
|
|
|
}
|
|
|
|
grantsByYear[year].push(
|
|
|
|
{
|
|
|
|
title: grant.title,
|
|
|
|
agency: grant.agency,
|
|
|
|
amount: amount,
|
|
|
|
pis: pis,
|
|
|
|
piFormat: piFormat,
|
|
|
|
supports: grant.supports,
|
|
|
|
supportsFormat: supportsFormat,
|
|
|
|
resources: grant.urls,
|
|
|
|
resourcesFormat: resourcesFormat
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
var out = []
|
|
|
|
for(i in grantsByYear) {
|
|
|
|
out.push({year: i, grants: grantsByYear[i]})
|
|
|
|
}
|
|
|
|
// console.log(out)
|
|
|
|
smith.metadata()["allGrants"] = out.reverse()
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
}
|