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

feat: download rdf ttl file #509

Merged
merged 3 commits into from
Nov 9, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { map } from 'rxjs/operators';
import { from } from 'rxjs';
import { Interpreter, State } from 'xstate';
import { RxLitElement } from 'rx-lit';
import { Connect, Dots, Identity, Image, Object as ObjectIcon, Download, Theme, Cross, Open } from '@netwerk-digitaal-erfgoed/solid-crs-theme';
import { Connect, Dots, Identity, Image, Object as ObjectIcon, Theme, Cross, Open } from '@netwerk-digitaal-erfgoed/solid-crs-theme';
import { unsafeSVG } from 'lit-html/directives/unsafe-svg';
import { fetch as solidFetch } from '@netwerk-digitaal-erfgoed/solid-crs-client';
import { AddAlertEvent, DismissAlertEvent } from '../../app.events';
import { SelectedCollectionEvent } from '../collection/collection.events';
import { ObjectContext } from './object.machine';
Expand Down Expand Up @@ -132,9 +133,28 @@ export class ObjectRootComponent extends RxLitElement {
const alerts = this.alerts?.map((alert) => html`<nde-alert .logger='${this.logger}' .translator='${this.translator}' .alert='${alert}' @dismiss="${this.handleDismiss}"></nde-alert>`);
const collection = this.collections?.find((coll) => coll.uri === this.object?.collection);

const toggleImage = () => { this.imagePopup.toggle(); };
const toggleImage = () => { this.imagePopup.toggle(); };

const toggleInfo = () => { this.infoPopup.toggle(); };
const toggleInfo = () => { this.infoPopup.toggle(); };

const downloadRDF = () => {

solidFetch(this.object?.uri)
.then((response) => response.blob())
.then((blob) => {

const blobURL = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = blobURL;
const slashSplit = this.object?.uri.split('/');
a.download = `${slashSplit[slashSplit.length - 1]}.ttl`;
(a as any).style = 'display: none';
document.body.appendChild(a);
a.click();

});

};

return this.object ? html`

Expand All @@ -151,7 +171,7 @@ export class ObjectRootComponent extends RxLitElement {
${ unsafeSVG(Dots) }
<nde-popup id="info-popup">
<div slot="content">
<a target="_blank" rel="noopener noreferrer" href="${this.object.uri}">
<a @click="${downloadRDF}">
${this.translator.translate('object.root.menu.view-rdf')}
</a>
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/solid-crs-presentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
],
"coverageThreshold": {
"global": {
"statements": 87.06,
"statements": 85.95,
"branches": 83.59,
"lines": 88.2,
"functions": 71.72
"lines": 86.98,
"functions": 72.14
}
},
"automock": false,
Expand Down