Commit a0973c08 authored by PTSEFTON's avatar PTSEFTON
Browse files

Handling thunmbnails better, examples using CreateActivity

parent 84f39937
......@@ -22,16 +22,15 @@ const Collection = require("./lib/collection.js");
const Index = require("./lib/index_html.js");
const Datacite = require("./lib/datacite.js");
const Bag = require("./lib/bag.js");
const args = require("minimist")(process.argv.slice(2));
//const args = require("minimist")(process.argv.slice(2));
const path = require("path");
const shell = require("shelljs");
const program = require("commander");
const path = require("path");
const html_file_name = "CATALOG.html";
const catalog_file_name = "CATALOG.json";
const defaults = require("./lib/defaults.js");
const html_file_name = defaults.html_file_name;
const catalog_file_name = defaults.catalog_json_file_name;
const JSON_helper = require("./lib/jsonldhelper.js")
const fs = require("fs")
var dirs = undefined;
program
.version("0.1.0")
......@@ -194,7 +193,6 @@ if (program.generateHtml) {
}
}
var index_maker = new Index();
console.log("OUTPUT", output_dir)
index_maker.init(
path.join(output_dir, catalog_file_name),
output_dir,
......
......@@ -4,7 +4,7 @@
"Source-Organization":"University of Technology Sydney",
"Contact-Name":"Peter Sefton",
"External-Description":"BagIt profile for DataCrate research data packages. ",
"Version":"0.2"
"Version":"0.3"
},
Tag-Files-Required: ["CATALOG.html", "CATALOG.json" ],
......
......@@ -62,7 +62,7 @@ module.exports = function() {
},
index_graph: function index_graph() {
//TODO - make this a helper function
this.catalog_path = path.join(this.target_dir, "CATALOG.json");
this.catalog_path = path.join(this.target_dir, defaults.catalog_json_file_name);
this.json_ld = require(this.catalog_path);
this.json_by_id = {};
this.json_by_path = {};
......@@ -134,26 +134,26 @@ module.exports = function() {
var bag_name = path.basename(source_dir);
var target_dir = path.join(bag_dir, bag_name);
shell.cp(
path.join(source_dir, "CATALOG.json"),
path.join(tmpobj.name, "CATALOG_backup.json")
path.join(source_dir, defaults.catalog_json_file_name ),
path.join(tmpobj.name,"CATALOG_backup.json")
);
shell.cp(path.join(source_dir, "CATALOG.json"), tmpobj.name);
shell.rm(path.join(source_dir, "index.html")); // Don't worry, welll make a new one
shell.cp(path.join(source_dir, defaults.catalog_json_file_name), tmpobj.name);
shell.rm(path.join(source_dir, defaults.html_file_name)); // Don't worry, welll make a new one
shell.exec(
"bagit create --excludebaginfo " +
target_dir +
" " +
path.join(source_dir, "*")
);
shell.rm(path.join(target_dir, "data", "CATALOG.json"), target_dir);
shell.rm(path.join(target_dir, "data", defaults.catalog_json_file_name), target_dir);
shell.exec("bagit update " + target_dir);
shell.cp(path.join(tmpobj.name, "CATALOG.json"), target_dir);
shell.cp(path.join(tmpobj.name, defaults.catalog_json_file_name), target_dir);
shell.cp(
path.join(__dirname, "defaults", "profile-datacrate-v0.2.json"),
path.join(__dirname, "defaults", defaults.DataCrate_profile_file),
target_dir
);
fix_paths(path.join(target_dir, "CATALOG.json"));
fix_paths(path.join(target_dir, defaults.catalog_json_file_name));
this.target_dir = target_dir;
return target_dir;
}
......
......@@ -34,6 +34,8 @@ const DataCrate_Specification_Identifier =
"https://github.com/UTS-eResearch/datacrate/blob/master/spec/0.3/data_crate_specification_v0.3.md";
const DataCrate_version = "0.3";
const DataCrate_profile_file = "defaults/profile-datacrate-v" + DataCrate_version + ".json"
// DataCrate specific terms which have inverses
const back_links = {
hasFile: "fileOf",
......@@ -41,6 +43,8 @@ const back_links = {
hasMember: "memberOf"
};
const back_back_links = new Set(Object.values(back_links))
module.exports = {
html_multi_file_dirs: html_multi_file_dirs,
catalog_root_name: catalog_root_name,
......@@ -54,5 +58,7 @@ module.exports = {
BagIt_Profile_Identifier: BagIt_Profile_Identifier,
DataCrate_Specification_Identifier: DataCrate_Specification_Identifier,
DataCrate_version: DataCrate_version,
back_links: back_links
back_links: back_links,
back_back_links: back_back_links,
DataCrate_profile_file: DataCrate_profile_file
};
......@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
const defaults = require("./defaults.js");
var fs = require("fs");
var ejs = require("ejs");
context = require("../defaults/context.json");
//context = require("../defaults/context.json");
const path = require("path");
const shell = require("shelljs");
const jsonld_helper = require("./jsonldhelper")
......@@ -27,18 +27,24 @@ const filesize = require("filesize");
const display_keys = [
"name",
"familyName",
"givenName",
"@type",
"description",
"funder",
"memberOf",
"@reverse",
"isPartOf",
"fileOf",
"description",
"thumbnail",
"datePublished",
"creator",
"path",
"encodingFormat",
"contentSize"
"contentSize",
"affiliation",
"email",
"@reverse",
];
const page_size = 25;
const back_links = {
......@@ -75,17 +81,19 @@ module.exports = function () {
item,
k,
list,
details
details,
no_thumbs
) {
// Item is the thing we're displaying
// K is for Key - ie the property name
// list is the list of values for property k in item
// details: bool - are we doing pagination? If so need to display the "details element"
// no_thumbs: Bool, don't show thumbnail (as this is a reverse propery the thmbnail is fill size!)
list = this.helper.value_as_array(list)
var l = list.length;
var html = "";
if (l === 1) {
html += this.format_property(item, k, list[0]);
html += this.format_property(item, k, list[0], no_thumbs);
} else if (l <= page_size) {
if (details) {
html += ele("details");
......@@ -94,14 +102,16 @@ module.exports = function () {
item,
k,
list.slice(0, 1),
page_size
false,
no_thumbs
);
html += " --to-- ";
html += this.format_property_paginated(
item,
k,
list.slice(l - 1, l),
page_size
false,
no_thumbs
);
html += close("summary");
}
......@@ -112,7 +122,8 @@ module.exports = function () {
item,
k,
list.slice(i, i + 1),
true
true,
no_thumbs
);
html += close("li");
}
......@@ -125,15 +136,15 @@ module.exports = function () {
item,
k,
list.slice(0, page_size),
page_size,
true
true,
no_thumbs
);
html += this.format_property_paginated(
item,
k,
list.slice(page_size, l),
page_size,
true
true,
no_thumbs
);
} else {
html += ele("details");
......@@ -142,30 +153,32 @@ module.exports = function () {
item,
k,
list.slice(0, 1),
page_size
true,
no_thumbs
);
html += " --to-- ";
html += this.format_property_paginated(
item,
k,
list.slice(page_size * page_size, page_size * page_size + 1),
page_size
true,
no_thumbs
);
html += close("summary");
html += this.format_property_paginated(
item,
k,
list.slice(0, page_size * page_size),
page_size,
true
true,
no_thumbs
);
html += close("details");
html += this.format_property_paginated(
item,
k,
list.slice(page_size * page_size, l),
page_size,
true
true,
no_thumbs
);
}
return html;
......@@ -240,7 +253,7 @@ module.exports = function () {
return keys_in_order;
},
format_property: function format_property(item, k, part) {
format_property: function format_property(item, k, part, no_thumbs) {
/*
TODO: Work out *my* path
......@@ -258,6 +271,7 @@ module.exports = function () {
//td_ele.ele("a", part).att('href', item["@id"]).att('class', 'fa fa-external-link').att('title',item["@id"]);
} else if (
k === "thumbnail" &&
!no_thumbs &&
part["@id"] &&
this.helper.item_by_id[part["@id"]]
) {
......@@ -298,20 +312,18 @@ module.exports = function () {
} else {
td_ele += item["@id"];
}
} else if (part["@id"] && this.helper.item_by_id[part["@id"]]) {
/*else if (
!item["@name"] &&
} else if (
k != "hasPart" &&
this.helper.item_by_id[part["@id"]] &&
!(
this.helper.item_by_id[part["@id"]].name ||
this.helper.item_by_id[part["@id"]].description
)
) {
// Embed small bits of info that don't have a name or description
this.helper.item_by_id[part["@id"]]["@type"] == "PropertyValue" &&
"value" in this.helper.item_by_id[part["@id"]] &&
"name" in this.helper.item_by_id[part["@id"]]
td_ele += this.dataset_to_html(this.helper.item_by_id[part["@id"]]);
} */
) {
td_ele += this.helper.item_by_id[part["@id"]].name + " : " + this.helper.item_by_id[part["@id"]].value
}
else if (part["@id"] && this.helper.item_by_id[part["@id"]]) {
var target_name = this.helper.item_by_id[part["@id"]].name
? this.helper.item_by_id[part["@id"]].name
: part["@id"];
......@@ -392,38 +404,33 @@ module.exports = function () {
rev += "Referenced-by";
rev += close("th");
rev += close("tr");
for (let r of Object.keys(item["@reverse"])) {
for (let r of Object.keys(item["@reverse"]).filter(key => !(defaults.back_back_links.has(key)))) {
rev += ele("tr");
rev += ele("th");
rev += r;
rev += close("th");
rev += ele("td");
rev += this.format_property_paginated(item, r, item["@reverse"][r]);
rev += this.format_property_paginated(item, r, item["@reverse"][r], false, true);
rev += close("td");
rev += close("tr");
}
rev += close("table");
return rev;
} else {
return this.format_property_paginated(item, k, data);
return this.format_property_paginated(item, k, data, false, false);
}
},
format_header: function format_header(key) {
el = "";
if (context[key]) {
// TODO deal with more complex case by using JSON-LD library
var term = context[key];
arrayify(term, function (term) {
term = term[0];
var expand1 = term["@id"] ? term["@id"] : term;
href = context[expand1.split(":")[0]] + expand1.split(":")[1];
});
var term_href = this.helper.get_uri_for_term(key);
if (term_href) {
// TODO deal with more complex case by using JSON-LD library
el += ele("span");
el += key;
el += ele("sup");
el += ele("a", { href: href, title: "Definition of: " + key });
el += ele("a", { href: term_href, title: "Definition of: " + key });
el += "?";
el += close("a");
el += close("sup");
......@@ -453,6 +460,7 @@ module.exports = function () {
keys.delete("@id");
keys.delete("filename");
keys.delete("@reverse");
if (keys.has("encodingFormat")) {
keys.delete("fileFormat");
}
......@@ -484,10 +492,14 @@ module.exports = function () {
html += "@id";
html += close("th");
html += ele("td");
html += this.format_property(node, "@id", node);
html += this.format_property(node, "@id", node, false);
html += close("td");
html += close("tr");
key_set = this.sort_keys(keys);
// Show back-links last
if ("@reverse" in node) {
key_set.add("@reverse")
}
for (let key of key_set) {
var value = node[key];
html += ele("tr");
......
......@@ -105,6 +105,8 @@ module.exports = function() {
//console.log("Looking for relations", f.data[k], this.collection)
//console.log("GOT A LINK", f.name, f.id);
frag[f.name].push({ "@id": link_id }); //, "@type" : "@id"
} else if (f.is_json) {
frag[f.name] = JSON.parse(f.data[k])
} else {
frag[f.name].push(f.data[k]);
}
......
......@@ -73,6 +73,7 @@ module.exports = function() {
property: this.property,
data: this.data,
is_file: this.is_file,
is_json: this.is_json,
id: this.id,
nested_item_json: this.nested_item_json,
......@@ -90,6 +91,7 @@ module.exports = function() {
// Name is separated by > and needs to be turned into a heirarchy
this.is_nested = false;
this.parse_content = false;
this.is_json = false;
this.raw_name = name;
this.name = name;
this.nested_item_json = [];
......@@ -108,6 +110,9 @@ module.exports = function() {
} else if (this.name.startsWith("FILE:")) {
this.name = this.name.substring(5);
this.is_file = true;
} else if (this.name.startsWith("JSON:")) {
this.name = this.name.substring(5);
this.is_json = true;
}
//Assume what's left of header is a property, and hence starts with lowecase letter
this.name = lowercase_first(this.name);
......@@ -155,18 +160,18 @@ module.exports = function() {
this.is_name = true;
}
if (data) {
if (this.data) {
//console.log(this.data);
if (this.is_repeating || this.is_type) {
if (Array.isArray(this.data)) {
this.data = this.data[0]
}
this.data = this.data.replace(/, +/g, ",").split(",");
//console.log("SPLIT", this.type, this.name, this.data)
} else if (!Array.isArray(this.data)) {
this.data = [this.data];
}
if (data.length === 1) {
this.data = this.data[0];
}
}
}
};
......
......@@ -53,23 +53,6 @@ describe("Test helper functions", function() {
"./test/test_output/index.html",
true
);
<<<<<<< HEAD
=======
var home_path = index_maker.get_html_path("http://dx.doi.org/10.5281/zenodo.1009240")
assert.equal(home_path, "CATALOG.html")
var my_path = index_maker.get_html_path("http://soemthing.com/this/it")
assert.equal(my_path, "CATALOG_files/pairtree_root/ht/tp/+=/=s/oe/mt/hi/ng/,c/om/=t/hi/s=/it/index.html")
// Examples from pairtree spec
var http_path = index_maker.get_html_path("http://n2t.info/urn:nbn:se:kb:repos-1");
assert.equal(http_path, "CATALOG_files/pairtree_root/ht/tp/+=/=n/2t/,i/nf/o=/ur/n+/nb/n+/se/+k/b+/re/po/s-/1/index.html")
var swearing_path = index_maker.get_html_path("what-the-*@?#!^!?");
assert.equal(swearing_path, "CATALOG_files/pairtree_root/wh/at/-t/he/-^/2a/@^/3f/#!/^5/e!/^3/f/index.html")
>>>>>>> origin/feature/pairtree-paths
assert.equal(
......@@ -94,7 +77,7 @@ describe("Test helper functions", function() {
);
assert.equal(
index_maker.item_by_id["http://orcid.org/0000-0002-3545-944X"][
index_maker.helper.item_by_id["http://orcid.org/0000-0002-3545-944X"][
"@reverse"
]["creator"][0]["@id"],
"http://dx.doi.org/10.5281/zenodo.1009240"
......
......@@ -37,18 +37,14 @@
"URL": "https://en.wikipedia.org/wiki/Olympus_PEN_E-PL1",
"description": "Olympus camera with Panasonic 20mm lens",
"identifier": [],
"manufacturer": "Olympus",
"model": "EPL 1",
"name": "EPL1 Camera",
"serialNumber": "123456778",
"serialNumber": "B3B505338",
"@reverse": {
"instrument": [
{
"@id": "fa5f847a-7d36-467e-b8a8-863b9bee0854"
}
],
"contributor": [
{
"@id": "pics/19093074_10155469333581584_5707039334816454031_o.jpg"
"@id": "Photo1"
}
]
}
......@@ -70,13 +66,13 @@
<ul class="nav navbar-nav" >
<li >
<a href=../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.2</button></a> </li>
<a href=../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.3</button></a> </li>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Sample dataset for DataCrate v0.2</h3>
<h3>Sample dataset for DataCrate v0.3</h3>
<h4></h4>
</div>
......@@ -135,16 +131,8 @@
><th
>instrument</th
><td
><a href = '../../fa/5f/84/7a/-7/d3/6-/46/7e/-b/8a/8-/86/3b/9b/ee/08/54/index.html'
>fa5f847a-7d36-467e-b8a8-863b9bee0854</a
></td
></tr
><tr
><th
>contributor</th
><td
><a href = '../../pi/cs/=1/90/93/07/4_/10/15/54/69/33/35/81/58/4_/57/07/03/93/34/81/64/54/03/1_/o,/jp/g/index.html'
>pics/19093074_10155469333581584_5707039334816454031_o.jpg</a
><a href = '../../Ph/ot/o1/index.html'
>Photo1</a
></td
></tr
></table
......@@ -177,6 +165,18 @@
><tr
><th
><span
>manufacturer<sup
><a href = 'http://schema.org/manufacturer' title = 'Definition of: manufacturer'
>?</a
></sup
></span
></th
><td
>Olympus</td
></tr
><tr
><th
><span
>model<sup
><a href = 'http://schema.org/model' title = 'Definition of: model'
>?</a
......@@ -196,12 +196,12 @@
></span
></th
><td
>123456778</td
>B3B505338</td
></tr
></table
>
<p>This file was created at 2018-09-18T06:29:24.793Z by
<p>This file was created at 2018-09-19T06:52:38.037Z by
<a href='https://code.research.uts.edu.au/eresearch/calcytejs'>
Calcyte</a> which implements the <a href='https://github.com/UTS-eResearch/datacrate/blob/master/spec/0.3/data_crate_specification_v0.3.md'>
Draft DataCrate Packaging format</a>, version 0.3
......
......@@ -62,13 +62,13 @@
<ul class="nav navbar-nav" >
<li >
<a href=../../../../../../../../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.2</button></a> </li>
<a href=../../../../../../../../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.3</button></a> </li>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Sample dataset for DataCrate v0.2</h3>
<h3>Sample dataset for DataCrate v0.3</h3>
<h4></h4>
</div>
......@@ -151,7 +151,7 @@
></table
>
<p>This file was created at 2018-09-18T06:29:24.794Z by
<p>This file was created at 2018-09-19T06:52:38.041Z by
<a href='https://code.research.uts.edu.au/eresearch/calcytejs'>
Calcyte</a> which implements the <a href='https://github.com/UTS-eResearch/datacrate/blob/master/spec/0.3/data_crate_specification_v0.3.md'>
Draft DataCrate Packaging format</a>, version 0.3
......
......@@ -67,13 +67,13 @@
<ul class="nav navbar-nav" >
<li >
<a href=../../../../../../../../../../../../../../../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.2</button></a> </li>
<a href=../../../../../../../../../../../../../../../../../../CATALOG.html><button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-home"></span>&nbsp;Sample dataset for DataCrate v0.3</button></a> </li>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Sample dataset for DataCrate v0.2</h3>
<h3>Sample dataset for DataCrate v0.3</h3>
<h4></h4>
</div>
......@@ -135,7 +135,7 @@
>relatedLink</th
><td
><a href = '../../../../../../../../../../../../../../../../../../CATALOG.html'
>Sample dataset for DataCrate v0.2</a
>Sample dataset for DataCrate v0.3</a