-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
131 lines (123 loc) · 4.16 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Vue.filter('substring', function(string, value) {
return string.substring(value, string.length);
});
var app = new Vue({
el: '#app',
data: {
title: null,
description: null,
version: null,
date: null,
authors: [],
objects: [],
json: null,
preservation: null,
sharing: null,
documentation: null,
documentationLink: null,
budget: null,
budgetJustification: null,
overview: []
},
created: function() {
var self = this;
d3.json("dmp.json", function(data) {
self.json = data;
self.title = data["dcterms:title"];
self.description = data["dcterms:description"];
self.version = data["dcterms:hasVersion"];
self.date = data["dc:date"];
var authors = data["dc:creator"];
for (var a of authors) {
var email = a["foaf:mbox"];
self.authors.push({
name: a["foaf:name"],
email: email,
emailDisplay: email.substring(email.indexOf(":") + 1, email.length),
orcid: a["@id"]
});
}
var bundle = data["dmp:hasDataObject"][0];
var id = bundle["@id"];
var license = bundle["dmp:hasIntelectualPropertyRights"]["dcterms:license"];
var metadata = bundle["dmp:hasMetadata"]["premis:hasObjectCharacteristics"];
var format = metadata["premis:hasFormat"];
var sha = metadata["premis:fixity"]["premis:messageDigest"];
var repository = bundle["dmp:hasDataRepository"];
var count = bundle["dmp:hasDataObject"].length;
self.overview.push({
name: "ID",
value: '<a href=' + id + '>' + id + '</a>'
});
self.overview.push({
name: "Repository",
value: '<a href=' + repository + '>' + repository + '</a>'
});
self.overview.push({
name: "License",
value: '<a href=' + license + '>' + license + '</a>'
});
self.overview.push({
name: "Format",
value: format
});
self.overview.push({
name: "SHA-256",
value: sha
});
self.overview.push({
name: "Data Objects",
value: count
});
self.preservation = bundle["dmp:hasPreservation"];
self.sharing = bundle["dmp:hasDataSharing"];
self.documentation = bundle["dmp:hasDocumentation"];
self.documentationLink = bundle["hasDocumentationLink"];
self.budget = bundle["dmp:hasBudget"];
self.budgetJustification = bundle["hasBudgetJustification"];
for (var obj of bundle["dmp:hasDataObject"]) {
var github = obj["github"];
var id = obj["@id"];
var hostname = extractHostname(id);
self.objects.push({
type: obj["@type"] != "dmp:File" ? obj["@type"] : obj["dmp:hasMetadata"]["premis:hasObjectCharacteristics"]["premis:hasFormat"],
name: obj["dc:title"],
github: github !== undefined ? "<a href='" + github + "' target='_blank'>Source</a> (Github)" : null,
id: id !== undefined ? "<a href='" + id + "'>Source</a> (" + hostname + ")" : null,
json: JSON.stringify(obj, null, ' ').trim()
});
}
});
},
methods: {
classObject: function(obj) {
if (obj.type === 'dmp:Container') {
return 'icon devicon-docker-plain colored';
}
if (obj.type === 'premis:Format:json') {
return 'icon devicon-javascript-plain';
}
if (obj.type === 'premis:Format:ipynb') {
return 'icon devicon-python-plain colored';
}
}
}
});
function extractHostname(url) {
if (url === undefined) {
return null;
}
var hostname;
//find & remove protocol (http, ftp, etc.) and get hostname
if (url.indexOf("://") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
//find & remove port number
hostname = hostname.split(':')[0];
//find & remove "?"
hostname = hostname.split('?')[0];
return hostname;
}