Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add NcML previewer #17 #18

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions 5.2curlcommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,10 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
}'
```

##Beta Versions:
As updates are made, they will be added to a /betatest sub-folder which will make them accessible to users via github.io without affecting people who are using the latest numbered release (e.g. v1.3). When previewers in the betatest branch are included in the next release (e.g. v1.4), sites may wish to change their registration of the tools to use the stable version as the betatest version may continue to receive changes.
## Beta Versions:
As updates and additions are made, they will be added to a /betatest sub-folder which will make them accessible to users via github.io without affecting people who are using the latest numbered release (e.g. v1.3). When previewers in the betatest branch are included in the next release (e.g. v1.4), sites may wish to change their registration of the tools to use the stable version as the betatest version may continue to receive changes.


###MapViewer:
### MapViewer:
Adds properties to geojson preview

```bash
Expand Down Expand Up @@ -579,3 +578,68 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
"contentType":"application/zip"
}'
```

### NcML Previewer Requirements:
* Dataverse version v5.13+ or NcML auxiliary files manually uploaded

```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
'{
"displayName":"Show NcML (XML)",
"description":"Metadata from HDF5 files.",
"toolName":"ncmlPreviewer",
"scope":"file",
"types":["preview"],
"toolUrl":"https://gdcc.github.io/dataverse-previewers/previewers/betatest/NcmlPreview.html",
"toolParameters": {
"queryParameters":[
{"fileid":"{fileId}"},
{"siteUrl":"{siteUrl}"},
{"key":"{apiToken}"},
{"datasetid":"{datasetId}"},
{"datasetversion":"{datasetVersion}"},
{"locale":"{localeCode}"}
]
},
"requirements": {
"auxFilesExist": [
{
"formatTag": "NcML",
"formatVersion": "0.1"
}
]
},
"contentType":"application/x-hdf5"
}'
```

```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
'{
"displayName":"Show NcML (XML)",
"description":"Metadata from NetCDF files.",
"toolName":"ncmlPreviewer",
"scope":"file",
"types":["preview"],
"toolUrl":"https://gdcc.github.io/dataverse-previewers/previewers/betatest/NcmlPreview.html",
"toolParameters": {
"queryParameters":[
{"fileid":"{fileId}"},
{"siteUrl":"{siteUrl}"},
{"key":"{apiToken}"},
{"datasetid":"{datasetId}"},
{"datasetversion":"{datasetVersion}"},
{"locale":"{localeCode}"}
]
},
"requirements": {
"auxFilesExist": [
{
"formatTag": "NcML",
"formatVersion": "0.1"
}
]
},
"contentType":"application/netcdf"
}'
```
32 changes: 32 additions & 0 deletions previewers/betatest/NcmlPreview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>

<head>
<meta charset="utf-8">
<title class="ncmlPreviewText">NcML Preview</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="js/xss.js"></script>
<script type="text/javascript" src="js/ncml.js"></script>
<script src="lib/jquery.i18n.js"></script>
<script src="lib/jquery.i18n.messagestore.js"></script>
<script src="lib/jquery.i18n.language.js"></script>
<script type="text/javascript" src="js/retriever.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css"
integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="css/preview.css" />
</head>

<body class="container">
<main><img id='logo' alt='Site Logo'>
<h1 class="page-title ncmlPreviewText">NcML Preview</h1>
<div class='preview-container'>
<div class='preview-header'></div>
<div class='preview'></div>
</div>
</main>
</body>

</html>
2 changes: 2 additions & 0 deletions previewers/betatest/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"textPreviewText": "Text Preview",
"videoPreviewText": "Video Preview",
"zipPreviewText": "ZIP Preview",
"ncmlPreviewText": "NcML Preview",
"prev": "Previous",
"next": "Next",
"pageText": "Page:",
"versionText": "version",
"descriptionText": "Description: ",
"ncmlErrorText": "Unable to retrieve NcML file. ",
"footer": "Previewers originally developed by <a href=\"https://qdr.syr.edu\">QDR</a> and maintained at <a href=\"https://github.com/gdcc/dataverse-previewers\">https://github.com/gdcc/dataverse-previewers</a>. Feedback and contributions welcome.",
"errorText" : "Please try again. The most common issue is that your login has timed out. If the problem persists, please contact the support team of this data repository. Please include any status code included at the end of this message: "
}
94 changes: 94 additions & 0 deletions previewers/betatest/js/ncml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
$(document).ready(function () {
startPreview(false);
});

function translateBaseHtmlPage() {
var ncmlPreviewText = $.i18n("ncmlPreviewText");
$('.ncmlPreviewText').text(ncmlPreviewText);
}

function writeContent(fileUrl, file, title, authors) {
addStandardPreviewHeader(file, title, authors);
var ncmlUrl = queryParams.get("siteUrl") + "/api/access/datafile/" + queryParams.get("fileid") + "/auxiliary/NcML/0.1";
// copied from text.js
var whiteList = {
a: ["title"],
abbr: ["title"],
address: [],
area: [],
article: [],
aside: [],
audio: [],
b: [],
bdi: ["dir"],
bdo: ["dir"],
big: [],
blockquote: ["cite"],
br: [],
caption: [],
center: [],
cite: [],
code: [],
col: ["align", "valign", "span", "width"],
colgroup: ["align", "valign", "span", "width"],
dd: [],
del: ["datetime"],
details: ["open"],
div: [],
dl: [],
dt: [],
em: [],
font: ["color", "size", "face"],
footer: [],
h1: [],
h2: [],
h3: [],
h4: [],
h5: [],
h6: [],
header: [],
hr: [],
i: [],
img: ["src", "alt", "title", "width", "height"],
ins: ["datetime"],
li: [],
mark: [],
nav: [],
ol: [],
p: [],
pre: [],
s: [],
section: [],
small: [],
span: [],
sub: [],
sup: [],
strong: [],
table: ["width", "border", "align", "valign"],
tbody: ["align", "valign"],
td: ["width", "rowspan", "colspan", "align", "valign"],
tfoot: ["align", "valign"],
th: ["width", "rowspan", "colspan", "align", "valign"],
thead: ["align", "valign"],
tr: ["rowspan", "align", "valign"],
tt: [],
u: [],
ul: [],
video: []
};
options = { "whiteList": whiteList };
$.ajax({
type: 'GET',
dataType: 'text',
crosssite: true,
url: ncmlUrl,
success: function (data, status) {
$('.preview').append($("<textarea/>").html(filterXSS(data,options))
.attr('style', 'width:100%;height:100%;')
);
},
error: function (request, status, error) {
reportFailure($.i18n("ncmlErrorText"), error);
}
});
}