Commit 2a936820 authored by Tobias Steiner's avatar Tobias Steiner
Browse files

Hide the widget if we do not have any links

parent f925c2f3
......@@ -22,12 +22,15 @@
<histhub-widget endpoint="//api.orgalinker.histhub.ch/v1/sameas/" resolver="resolvermanual" location="https://dodis.ch/R20">
<h3 slot="title">Example 2: Links from orgalinker dodis: Lombard, Odier & Cie</h3>
</histhub-widget>
<histhub-widget endpoint="//api.geolinker.histhub.ch/v1/sameas/" resolver="resolverneo4j" location="https://dodis.ch/G82">
<histhub-widget endpoint="//api.geolinker.histhub.ch/v1-1/sameas/" resolver="resolverneo4j" location="https://dodis.ch/G82">
<h3 slot="title">Example 3: Links (sameas) from geolinker dodis: Diedenhofen</h3>
</histhub-widget>
<histhub-widget endpoint="//api.geolinker.histhub.ch/v1/similarto/" resolver="resolverelasticsearch" location="https://dodis.ch/G82">
<histhub-widget endpoint="//api.geolinker.histhub.ch/v1-1/similarto/" resolver="resolverelasticsearch" location="https://dodis.ch/G82">
<h3 slot="title">Example 4: Links (similarto) from geolinker dodis: Diedenhofen</h3>
</histhub-widget>
<histhub-widget endpoint="//api.geolinker.histhub.ch/v1-1/sameas/" resolver="resolverneo4j" location="https://dodis.ch/G82000000000000">
<h3 slot="title">Example 5: No links (sameas) from geolinker</h3>
</histhub-widget>
</div>
</body>
</html>
......@@ -119,28 +119,34 @@
if (this.loading) {
this._linksSlot.innerHTML = `Loading data...`;
} else {
// small util to build the links
const buildLinks = () => this.links.map((link) => {
let anchor = null;
let href = null;
// check f we get an array or an object
if (typeof link === "object") {
const provider = Object.keys(link)[0];
// often we do not have information about the provider
if (typeof provider === "string" && provider !== "") {
anchor = provider;
if(this.links.length === 0) {
// hide if there is no data
this._linksSlot.style.display = 'none';
this._titleSlot.style.display = 'none';
} else {
// small util to build the links
const buildLinks = () => this.links.map((link) => {
let anchor = null;
let href = null;
// check f we get an array (v1) or an object (v1.1)
if (typeof link === "object") {
const provider = Object.keys(link)[0];
// often we do not have information about the provider
if (typeof provider === "string" && provider !== "") {
anchor = provider;
} else {
anchor = link[provider];
}
href = link[provider];
} else {
anchor = link[provider];
href = link;
anchor = link;
}
href = link[provider];
} else {
href = link;
anchor = link;
}
// build the list
return `<li><a href="${href}"> ${anchor}</a></li>`;
});
this._linksSlot.innerHTML = `<ul>${buildLinks().join("")}</ul>`;
// build the list
return `<li><a href="${href}"> ${anchor}</a></li>`;
});
this._linksSlot.innerHTML = `<ul>${buildLinks().join("")}</ul>`;
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment