Commit 7d8fc5a1 authored by PTSEFTON's avatar PTSEFTON
Browse files

Added CreateAction example to samples

parent 63b0b3c0
......@@ -81,6 +81,7 @@ module.exports = function () {
// K is for Key - ie the property name
// list is the list of values for propery k in item
// details: bool - are we doing pagination? If so need to display the "details element"
list = helper.value_as_array(list)
var l = list.length;
var html = "";
if (l === 1) {
......@@ -198,7 +199,11 @@ module.exports = function () {
}
var time = new Date().toISOString();
out_path = path.join(this.out_dir, this.get_html_path(node["@id"]))
if (node["@id"]) {
out_path = path.join(this.out_dir, this.get_html_path(node["@id"]))
} else {
out_path = path.join(this.out_dir, this.get_html_path(this.root_node["@id"]))
}
shell.mkdir("-p", path.dirname(out_path));
fs.writeFileSync(
......@@ -235,48 +240,6 @@ module.exports = function () {
return keys_in_order;
},
make_back_links: function make_back_links(item) {
for (let key of Object.keys(item)) {
if (key != "@id" && key != "@reverse") {
for (let part of item[key]) {
var target = this.item_by_id[part["@id"]];
var back_link = back_links[key];
if (target && back_link) {
if (!target[back_link]) {
//console.log("Making link", key, back_link, target)
target[back_link] = [{ "@id": item["@id"] }];
}
} else if (
!dont_back_link.has(key) &&
item["name"] &&
target &&
target["name"]
) {
// We are linking to something
//console.log("Doing a back link", key, target['name'], item['name'])
if (!target["@reverse"]) {
target["@reverse"] = {};
}
if (!target["@reverse"][key]) {
target["@reverse"][key] = [];
}
var got_this_reverse_already = false;
// for (let r of target["@reverse"][key]) {
// //console.log(r, r["@id"], item["@id"])
// if (r["@id"] === item["@id"]) {
// got_this_reverse_already = true
// }
// }
if (!got_this_reverse_already) {
target["@reverse"][key].push({ "@id": item["@id"] });
}
//console.log(JSON.stringify(target, null, 2))
}
}
}
}
},
format_property: function format_property(item, k, part) {
var td_ele = "";
......@@ -292,10 +255,10 @@ module.exports = function () {
} else if (
k === "thumbnail" &&
part["@id"] &&
this.item_by_id[part["@id"]]
this.helper.item_by_id[part["@id"]]
) {
td_ele += ele("img", {
src: this.get_file_ref(this.item_by_id[part["@id"]]["path"], item["@id"])
src: this.get_file_ref(this.helper.item_by_id[part["@id"]]["path"], item["@id"])
});
} else if (k === "path") {
td_ele += ele("a", { href: encodeURI(this.get_file_ref(part, item["@id"])) });
......@@ -331,22 +294,22 @@ module.exports = function () {
} else {
td_ele += item["@id"];
}
} else if (part["@id"] && this.item_by_id[part["@id"]]) {
} else if (part["@id"] && this.helper.item_by_id[part["@id"]]) {
/*else if (
!item["@name"] &&
k != "hasPart" &&
this.item_by_id[part["@id"]] &&
this.helper.item_by_id[part["@id"]] &&
!(
this.item_by_id[part["@id"]].name ||
this.item_by_id[part["@id"]].description
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
td_ele += this.dataset_to_html(this.item_by_id[part["@id"]]);
td_ele += this.dataset_to_html(this.helper.item_by_id[part["@id"]]);
} */
var target_name = this.item_by_id[part["@id"]].name
? this.item_by_id[part["@id"]].name
var target_name = this.helper.item_by_id[part["@id"]].name
? this.helper.item_by_id[part["@id"]].name
: part["@id"];
var href = this.get_href(part["@id"], item["@id"]);
td_ele += ele("a", { href: href });
......@@ -371,8 +334,8 @@ module.exports = function () {
},
get_html_path: function get_html_path(id) {
if (this.item_by_id[id] && this.item_by_id[id]["path"]) {
var actual_path = helper.value_as_array(this.item_by_id[id]["path"])[0];
if (this.helper.item_by_id[id] && this.helper.item_by_id[id]["path"]) {
var actual_path = helper.value_as_array(this.helper.item_by_id[id]["path"])[0];
if (actual_path === "./" || actual_path === "data/") {
return defaults.html_file_name;
}
......@@ -492,9 +455,9 @@ module.exports = function () {
key != "@id" &&
key != "@reverse" &&
v["@id"] &&
this.item_by_id[v["@id"]]
this.helper.item_by_id[v["@id"]]
) {
html += " | " + dataset_to_html(this.item_by_id[v["@id"]]);
html += " | " + dataset_to_html(this.helper.item_by_id[v["@id"]]);
}
}
}
......@@ -559,8 +522,8 @@ module.exports = function () {
node[part] = [node[part]];
}
for (let [key, value] of Object.entries(node[part])) {
if (value["@id"] && this.item_by_id[value["@id"]]) {
var child = this.item_by_id[value["@id"]];
if (value["@id"] && this.helper.item_by_id[value["@id"]]) {
var child = this.helper.item_by_id[value["@id"]];
if (child["@type"]) {
// if (!Array.isArray(child['@type'])) {
// child['@type'] = [child['@type']];
......@@ -634,49 +597,11 @@ module.exports = function () {
}
//console.log(crate_data);
this.json_ld = crate_data;
this.item_by_id = {};
this.item_by_url = {};
this.item_by_type = {}; // dict of arrays
//console.log("CRATE-data", crate_data)
graph = crate_data["@graph"];
for (let i = 0; i < graph.length; i++) {
var item = graph[i];
for (let key of Object.keys(item)) {
if (key != "@id" && key != "@reverse") {
if (!item[key]) {
item[key] = "";
}
if (!Array.isArray(item[key])) {
item[key] = [item[key]];
//console.log("Making array", key, item[key])
}
}
}
if (item["@id"]) {
this.item_by_id[item["@id"]] = item;
}
if (item["path"]) {
this.item_by_url[item["path"]] = item;
}
if (!item["@type"]) {
item["@type"] = ["Thing"];
}
//console.log("TYPE", item['@type'])
for (let t of item["@type"]) {
//console.log(t)
if (!this.item_by_type[t]) {
this.item_by_type[t] = [];
}
this.item_by_type[t].push(item);
}
}
this.helper = new jsonld();
this.helper.init(crate_data)
this.helper.add_back_links()
for (let i = 0; i < graph.length; i++) {
var item = graph[i];
this.make_back_links(item);
}
// A container for our page
},
make_index_html: function make_index_html(text_citation, zip_path) {
......@@ -685,11 +610,11 @@ module.exports = function () {
this.text_citation = text_citation;
this.first_page = true;
body_el += ele("div");
//console.log("DATA", this.item_by_url);
// Get root of graph
root_node = this.item_by_url["./"]
? this.item_by_url["./"]
: this.item_by_url["data/"];
//console.log("DATA", this.helper.item_by_url);
// Get root of this.helper.graph
root_node = this.helper.item_by_url["./"]
? this.helper.item_by_url["./"]
: this.helper.item_by_url["data/"];
this.root_node = root_node;
......@@ -701,26 +626,26 @@ module.exports = function () {
body_el += this.dataset_to_html(root_node, true);
//}
delete this.item_by_type["Dataset"];
delete this.item_by_type["File"];
delete this.item_by_type["RepositoryCollection"];
delete this.item_by_type["RepositoryObject"];
for (let type of Object.keys(this.item_by_type).sort()) {
delete this.helper.item_by_type["Dataset"];
delete this.helper.item_by_type["File"];
delete this.helper.item_by_type["RepositoryCollection"];
delete this.helper.item_by_type["RepositoryObject"];
for (let type of Object.keys(this.helper.item_by_type).sort()) {
body_el += ele("h1");
body_el += "Contextual info: ";
body_el += ele("span");
body_el += this.format_header(type);
body_el += close("span");
body_el += close("h1");
//this.items_to_html(this.item_by_type[type], body_el);
for (let i of this.item_by_type[type]) {
//this.items_to_html(this.helper.item_by_type[type], body_el);
for (let i of this.helper.item_by_type[type]) {
body_el += this.dataset_to_html(i, true);
} //console.log(type);
}
body_el += close("div");
if (!this.multiple_files_dir) {
this.write_html(this.out_path, body_el, this.json_ld);
this.write_html(this.out_path, body_el, this.helper.json_ld);
}
}
};
......
This diff is collapsed.
{
"@context": {
"affiliation": "http://schema.org/affiliation",
"familyName": "http://schema.org/familyName",
"givenName": "http://schema.org/givenName",
"name": "http://schema.org/name",
"address": "http://schema.org/address",
"identifier": "http://schema.org/identifier",
"memberOf": "http://schema.org/memberOf",
"name": "http://schema.org/name",
"issn": "http://schema.org/issn",
"contentSize": "http://schema.org/contentSize",
"path": "http://schema.org/contentUrl",
"creator": "http://schema.org/creator",
......@@ -14,7 +12,9 @@
"encodingFormat": "http://schema.org/encodingFormat",
"fileFormat": "http://schema.org/fileFormat",
"license": "http://schema.org/license",
"issn": "http://schema.org/issn",
"affiliation": "http://schema.org/affiliation",
"familyName": "http://schema.org/familyName",
"givenName": "http://schema.org/givenName",
"citation": "http://schema.org/citation",
"contactPoint": "http://schema.org/contactPoint",
"datePublished": "http://schema.org/datePublished",
......@@ -23,26 +23,16 @@
"publisher": "http://schema.org/publisher",
"isPartOf": "http://schema.org/isPartOf",
"contactType": "http://schema.org/contactType",
"Person": "http://schema.org/Person",
"Organization": "http://schema.org/Organization",
"File": "http://schema.org/MediaObject",
"Place": "http://schema.org/Place",
"journal": "http://schema.org/Periodical",
"Place": "http://schema.org/Place",
"File": "http://schema.org/MediaObject",
"Person": "http://schema.org/Person",
"Dataset": "http://schema.org/Dataset",
"ScholarlyArticle": "http://schema.org/ScholarlyArticle",
"ContactPoint": "http://schema.org/ContactPoint"
},
"@graph": [
{
"@id": "0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6",
"@type": "Person",
"affiliation": {
"@id": "1"
},
"familyName": "Cook",
"givenName": "Janet",
"name": "Janet Cook"
},
{
"@id": "1",
"@type": "Organization",
......@@ -83,6 +73,12 @@
},
"name": "South Western Sydney Clinical School, University of New South Wales"
},
{
"@id": "29ac8364-7cef-4eb2-86b3-c5cad9f6710a",
"@type": "journal",
"issn": "1932-6203",
"name": "PLOS ONE"
},
{
"@id": "3",
"@type": "Organization",
......@@ -127,6 +123,10 @@
},
"name": "School of Medicine and Public Health, The University of Newcastle"
},
{
"@id": "7cebec16-1fde-4862-aeed-73c8febb7fa2",
"@type": "Place"
},
{
"@id": "8",
"@type": "Organization",
......@@ -196,11 +196,17 @@
"name": "Dataset 3"
},
{
"@id": "a54739f2-4a31-4a28-9201-82723c5827f5",
"@type": "Place"
"@id": "a2c5862e-ac0d-4547-a867-8e884f2e2a5b",
"@type": "Person",
"affiliation": {
"@id": "1"
},
"familyName": "Cook",
"givenName": "Janet",
"name": "Janet Cook"
},
{
"@id": "b8a59de5-214d-4cc9-801e-3c792f3c3129",
"@id": "debb8d80-a627-43a2-8a9b-3e3a9050d162",
"@type": "Person",
"affiliation": {
"@id": "10"
......@@ -209,12 +215,6 @@
"givenName": "Jennifer",
"name": "Jennifer Houltram"
},
{
"@id": "db6f56ed-bffe-4dca-a07e-5ad1993fb584",
"@type": "journal",
"issn": "1932-6203",
"name": "PLOS ONE"
},
{
"@id": "http://doi.org/10.4225/59/59672c09f4a4b",
"@type": "Dataset",
......@@ -251,13 +251,13 @@
"@id": "http://nla.gov.au/nla.party-1509834"
},
{
"@id": "0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6"
"@id": "a2c5862e-ac0d-4547-a867-8e884f2e2a5b"
},
{
"@id": "http://orcid.org/0000-0003-4902-0654"
},
{
"@id": "b8a59de5-214d-4cc9-801e-3c792f3c3129"
"@id": "debb8d80-a627-43a2-8a9b-3e3a9050d162"
},
{
"@id": "http://orcid.org/0000-0001-6611-6565"
......@@ -333,13 +333,13 @@
"@id": "http://nla.gov.au/nla.party-1509834"
},
{
"@id": "0d6ab5d0-cacb-4839-8208-a7b99ebdb8a6"
"@id": "a2c5862e-ac0d-4547-a867-8e884f2e2a5b"
},
{
"@id": "http://orcid.org/0000-0003-4902-0654"
},
{
"@id": "b8a59de5-214d-4cc9-801e-3c792f3c3129"
"@id": "debb8d80-a627-43a2-8a9b-3e3a9050d162"
},
{
"@id": "http://orcid.org/0000-0001-6611-6565"
......@@ -351,7 +351,7 @@
"datePublished": "2017",
"identifier": "http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0181020",
"isPartOf": {
"@id": "db6f56ed-bffe-4dca-a07e-5ad1993fb584"
"@id": "29ac8364-7cef-4eb2-86b3-c5cad9f6710a"
},
"name": "Effects of facilitated family case conferencing for advanced dementia: A cluster randomised clinical trial"
},
......
<html>
<head>
<style>
table {
width: 90%;
text-align: left;
vertical-align: top;
margin-bottom: 2em;
}
td {
margin-right: 2em;
white-space: normal;
}
details {
margin-left: 2em;
}
.break {
word-break: break-all;
}
div.collection {
margin-left: +1em;
}
</style>
<script type="application/ld+json">
{
"@id": "https://dx.doi.org/10.5281/zenodo.1009240",
"@type": "Dataset",
"isOutputOf": "DataCrate",
"contact": {
"@id": "http://orcid.org/0000-0002-3545-944X"
},
"contentLocation": {
"@id": "http://www.geonames.org/8152662/catalina-park.html"
},
"path": "./",
"creator": {
"@id": "http://orcid.org/0000-0002-3545-944X"
},
"datePublished": "2017-06-29",
"description": "This is a simple dataset for demonstration purposes it contains just one image and a directory full of useless text files.",
"hasPart": [
{
"@id": "lots_of_little_files"
},
{
"@id": "pics"
}
],
"identifier": [
"https://dx.doi.org/10.5281/zenodo.1009240",
"dx.doi.org/10.5281/zenodo.1009240"
],
"keywords": "Dogs, Fences, The Gully",
"name": "Sample dataset for DataCrate v0.2",
"publisher": {
"@id": "http://uts.edu.au"
},
"relatedLink": {
"@id": "http://dx.doi.org/10.1000/123456"
},
"temporalCoverage": "2017",
"@reverse": {
"isPartOf": [
{
"@id": "lots_of_little_files"
},
{
"@id": "pics"
}
]
}
}
</script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset='utf-8'/>
</head>
<body>
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav" >
<li >
<a href="" class="active"><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>
</ul>
</nav>
<div class="container">
<div class="jumbotron">
<h3>Sample dataset for DataCrate v0.2</h3>
<h4></h4>
</div>
<p>A machine-readable version of this page, created at 2018-01-17T06:35:14.000Z is available <a href='CATALOG.json'>CATALOG.json</a></p>
<table class = 'table' id = 'https://dx.doi.org/10.5281/zenodo.1009240'
><hr
><tr
><th style = 'white-space: nowrap; width: 1%;'
>@id</th
><td
><a href = 'https://dx.doi.org/10.5281/zenodo.1009240' class = 'fa fa-external-link' title = 'Sample dataset for DataCrate v0.2'
>https://dx.doi.org/10.5281/zenodo.1009240</a
></td
></tr
><tr
><th
><span
>name<sup
><a href = 'http://schema.org/name' title = 'Definition of: name'
>?</a
></sup
></span
></th
><td
><b
>Sample dataset for DataCrate v0.2</b
></td
></tr
><tr
><th
>@type</th
><td
><span
>Dataset<sup
><a href = 'http://schema.org/Dataset' title = 'Definition of: Dataset'
>?</a
></sup
></span
></td
></tr
><tr
><th
>Items referencing this:</th
><td
><table class = 'table'
><tr
><th style = 'white-space: nowrap; width: 1%;'
>Relationship</th
><th
>Referenced-by</th
></tr
><tr
><th
>isPartOf</th
><td
><ul
><li
><a href = 'CATALOG_files/pairtree_root/lo/ts/_o/f_/li/tt/le/_f/il/es/index.html'
>lots_of_little_files</a
></li
><li
><a href = 'CATALOG_files/pairtree_root/pi/cs/index.html'
>Picture Diirectory</a
></li
></ul
></td
></tr
></table
></td
></tr
><tr
><th
><span
>description<sup
><a href = 'http://schema.org/description' title = 'Definition of: description'
>?</a
></sup
></span
></th
><td
>This is a simple dataset for demonstration purposes it contains just one image and a directory full of useless text files.</td
></tr
><tr
><th
><span
>datePublished<sup
><a href = 'http://schema.org/datePublished' title = 'Definition of: datePublished'
>?</a
></sup
></span
></th
><td
>2017-06-29</td
></tr
><tr
><th
><span
>creator<sup