Skip to content

Commit

Permalink
Add popovers w/ bioportal lookup to EML 2.2.0 annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
amoeba committed Jul 27, 2019
1 parent 81778e7 commit 8030f16
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/css/metacatui-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,6 @@ a.btn.metrics-button-disabled {
.entitydetails table,
.entitydetails tbody,
.entitydetails td {
display: block;
word-wrap: break-word;
box-sizing: border-box;
}
Expand Down Expand Up @@ -2306,6 +2305,11 @@ a.btn.metrics-button-disabled {
.popover-title {
text-transform: capitalize;
}

/* Don't force capitalization on annotation popover titles */
.annotation-view .popover .popover-title {
text-transform: none;
}
.annotation-viewer-container .concept a{
white-space: pre-wrap;
}
Expand All @@ -2314,6 +2318,11 @@ a.btn.metrics-button-disabled {
color: #DDD;
}

/* Force hyperlinks in popovers to wrap */
.annotation-view .popover .popover-content a {
white-space: normal;
}

/** Hide the search when in the dropdown menu **/
.dropdown-menu .ncboAutocomplete {
display: none;
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


<!-- Pull in correct theme configuration, then use Require.js to manage dependencies -->
<script id="loader" type="text/javascript" src="/metacatui/loader.js?v=2.6.4"
data-theme="default"
<script id="loader" type="text/javascript" src="/loader.js?v=2.6.4"
data-theme="arctic"
data-metacat-context="metacat"
data-map-key="YOUR-GOOGLE-MAPS-API-KEY"
></script>
Expand Down
3 changes: 2 additions & 1 deletion src/js/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ define(['jquery', 'underscore', 'backbone'],

// If true, then archived content is available in the search index.
// Set to false if this MetacatUI is using a Metacat version before 2.10.0
archivedContentIsIndexed: true
archivedContentIsIndexed: true,
bioportalAPIKey: "5c385237-ec28-4ef6-8ba1-f5bcfb752142"
},

defaultView: "data",
Expand Down
8 changes: 5 additions & 3 deletions src/js/themes/arctic/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ define(['jquery', 'underscore', 'backbone'],

allowAccessPolicyChanges: false,

baseUrl: window.location.origin || (window.location.protocol + "//" + window.location.host),
// baseUrl: window.location.origin || (window.location.protocol + "//" + window.location.host),
baseUrl: "https://neutral-cat.nceas.ucsb.edu",
// the most likely item to change is the Metacat deployment context
context: '/metacat',
d1Service: '/d1/mn/v2',
d1CNBaseUrl: "https://cn.dataone.org/",
d1CNBaseUrl: "https://cn-stage.test.dataone.org/",
d1CNService: "cn/v2",
d1LogServiceUrl: null,
nodeServiceUrl: null,
Expand Down Expand Up @@ -168,7 +169,8 @@ define(['jquery', 'underscore', 'backbone'],

// If true, then archived content is available in the search index.
// Set to false if this MetacatUI is using a Metacat version before 2.10.0
archivedContentIsIndexed: true
archivedContentIsIndexed: true,
bioportalAPIKey: "5c385237-ec28-4ef6-8ba1-f5bcfb752142"
},

defaultView: "data",
Expand Down
3 changes: 2 additions & 1 deletion src/js/themes/dataone/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ define(['jquery', 'underscore', 'backbone'],

// If true, then archived content is available in the search index.
// Set to false if this MetacatUI is using a Metacat version before 2.10.0
archivedContentIsIndexed: true
archivedContentIsIndexed: true,
bioportalAPIKey: "5c385237-ec28-4ef6-8ba1-f5bcfb752142"
},

defaultView: "data",
Expand Down
3 changes: 2 additions & 1 deletion src/js/themes/knb/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ define(['jquery', 'underscore', 'backbone'],

// If true, then archived content is available in the search index.
// Set to false if this MetacatUI is using a Metacat version before 2.10.0
archivedContentIsIndexed: true
archivedContentIsIndexed: true,
bioportalAPIKey: "5c385237-ec28-4ef6-8ba1-f5bcfb752142"
},

defaultView: "data",
Expand Down
3 changes: 2 additions & 1 deletion src/js/themes/nceas/models/AppModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ define(['jquery', 'underscore', 'backbone'],
tokenUrl: null,
//annotatorUrl: null,
accountsUrl: null,
isJSONLDEnabled: true
isJSONLDEnabled: true,
bioportalAPIKey: "5c385237-ec28-4ef6-8ba1-f5bcfb752142"
},

defaultView: "submit",
Expand Down
154 changes: 154 additions & 0 deletions src/js/views/AnnotationView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*global define */
define(['jquery',
'underscore',
'backbone',
'MetricsChart',
'text!templates/metricModalTemplate.html',
'collections/Citations',
'views/CitationListView'],
function($, _, Backbone) {
'use strict';

var AnnotationView = Backbone.View.extend({
className: 'annotation-view',
template: _.template('<span class="annotation" title="<%= termLabel %>" data-content="<%= termURI %>"><%= termLabel %></span>'),
bioportalTooltipTemplate: _.template('<strong>Definition:</strong> <%= definition %><br /><a href="<%= termURI %>" target="_blank"><%= termURI %></a>'),

termURI: null,
termLabel: null,
termDefinition: null,
popoverSource: null,
visible: null,
loaded: null,

events: {
"click" : "toggle"
},

initialize: function (options) {
this.termURI = options.termURI;
this.termLabel = options.termLabel;
this.termDefinition = "";

this.visible = false;
this.resolved = false; // Whether we queried for more details,
// successful or not
},

render: function () {
this.$el.html(this.template({
termLabel: this.termLabel,
termURI: this.termURI,
termDefinition: this.termDefinition
}));

this.createPopover(
'<a href="' + this.termURI + '" target="_blank">' +
this.termURI +
'</a>'
);

return this;
},

// Destroy the popover if it's visible, stale
toggle: function (e) {
// Don't do anything if we clicked on the popover
// (This lets people click and copy/paste on the popover text, aka
// normal behavior, since we're overriding the normal click
// behavior in order to edit the popover after we create and show
// it )
if (e.target.className !== "annotation") {
return;
}

if (!this.resolved) {
this.query();
}

if (this.visible) {
// Re-create the popover
this.popoverSource.popover("destroy");
this.createPopover();
}

this.visible = !this.visible;
},

query: function () {
var viewRef = this;
var popover_content = $(this.$el).find(".popover-content").first();

// Grab and verify token before moving on
var token = MetacatUI.appModel.get("bioportalAPIKey");

if (typeof token !== "string") {
this.resolved = true;

return;
}

var url = "https://data.bioontology.org/search?q=" +
encodeURIComponent(this.termURI) +
"&apikey=" +
token;

$.get(url, function (data) {
var match = null;

// TODO: Make sure to handle not-found case
data.collection.filter(function(result) {
if (result["@id"] === viewRef.termURI) {
match = result;
}
});

// Verify structure of response looks right and bail out if it
// doesn't
if (!match ||
!match.definition ||
!match.definition.length ||
!match.definition.length > 0) {
viewRef.resolved = true;

return;
}

// Render updated popover content
var new_content = viewRef.bioportalTooltipTemplate({
definition: match.definition[0],
termURI: viewRef.termURI
});

// Update both the existing DOM and the underlying data
// attribute in order to persist the updated content between
// displays of the popover
$(viewRef.popoverSource).data("content", new_content);
$(popover_content).html(new_content);

viewRef.resolved = true;
});
},

// Note: Has a side-effect of updating this.popoverSource;
createPopover: function (content) {
var el = $(this.$el).children("span").first();
var options = {
trigger: "click",
placement: "right",
container: this.$el,
title: this.termLabel,
html: true
};

// Override the content if provided, allows us to get around an
// apparently limitation in underscore related to double quotes
// in template strings I couldn't figure out
options.content = content;

this.popoverSource = el.popover(options);
}
});

return AnnotationView;
});
45 changes: 41 additions & 4 deletions src/js/views/MetadataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ define(['jquery',
'views/PackageTableView',
'views/AnnotatorView',
'views/CitationView',
'views/AnnotationView',
'views/MarkdownView',
'text!templates/metadata/metadata.html',
'text!templates/dataSource.html',
'text!templates/publishDOI.html',
Expand All @@ -36,11 +38,11 @@ define(['jquery',
'text!templates/annotation.html',
'text!templates/metaTagsHighwirePress.html',
'uuid',
'views/MetricView'
'views/MetricView',
],
function($, $ui, _, Backbone, gmaps, fancybox, Clipboard, DataPackage, DataONEObject, Package, SolrResult, ScienceMetadata,
MetricsModel, DownloadButtonView, ProvChart, MetadataIndex, ExpandCollapseList, ProvStatement, PackageTable,
AnnotatorView, CitationView, MetadataTemplate, DataSourceTemplate, PublishDoiTemplate,
AnnotatorView, CitationView, AnnotationView, MarkdownView, MetadataTemplate, DataSourceTemplate, PublishDoiTemplate,
VersionTemplate, LoadingTemplate, ControlsTemplate, MetadataInfoIconsTemplate, UsageTemplate,
DownloadContentsTemplate, AlertTemplate, EditMetadataTemplate, DataDisplayTemplate,
MapTemplate, AnnotationTemplate, metaTagsHighwirePressTemplate, uuid, MetricView) {
Expand Down Expand Up @@ -131,6 +133,10 @@ define(['jquery',

this.listenTo(MetacatUI.appUserModel, "change:loggedIn", this.render);

this.once("metadataLoaded", function(){
this.insertMarkdownViews();
});

this.getModel();

return this;
Expand Down Expand Up @@ -328,6 +334,7 @@ define(['jquery',
}

this.insertCitationMetaTags();
this.createAnnotationViews();
},

/* If there is no view service available, then display the metadata fields from the index */
Expand Down Expand Up @@ -2675,8 +2682,38 @@ define(['jquery',

// Insert
document.head.insertAdjacentHTML("beforeend", hwpt);
}
},

createAnnotationViews: function(){
var viewRef = this;

_.each($(".annotation"), function (annoEl) {
var newView = new AnnotationView({
el: annoEl
});
viewRef.subviews.push(newView);
newView.render();
});
},

insertMarkdownViews: function() {
var viewRef = this;

_.each($(".markdown"), function (markdownEl) {
var newView = new MarkdownView({
markdown: $(markdownEl).text().trim(),
el: $(markdownEl).parent()
});

viewRef.subviews.push(newView);

// Clear out old content before rendering
$(markdownEl).remove();

newView.render();
});
}
});

return MetadataView;
});
});
2 changes: 1 addition & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MetacatUI.useD3 = true;
// of assets and, if not set correctly, a lot of things break. Your web server
// should also set a FallbackResource directive accordingly in order to support
// users entering MetacatUI from URLs other than the root
MetacatUI.root = "/metacatui"
MetacatUI.root = "/"
// Remove trailing slash if one is present
MetacatUI.root = MetacatUI.root.replace(/\/$/, "");

Expand Down

0 comments on commit 8030f16

Please sign in to comment.