Commit be055e43 authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

[dublincore] add simpleRender method to be used in SparqlExplorer

parent 6368cdabb29d
......@@ -12,7 +12,7 @@ export const BlogPostComponent: React.FC<{
{"Blog Post of "}
<a href={container.__resource.uri}>{container.title}</a>
</div>
<DublinCoreElementComponent dcelement={blogpost} />
<DublinCoreElementComponent {...blogpost} />
</>
);
};
......@@ -7,8 +7,8 @@ export const BlogComponent: React.FC<{
}> = ({ blog }) => {
return (
<>
<DublinCoreElementComponent dcelement={blog} />
<DublinCoreElementComponent dcelement={blog.posts[0]} />
<DublinCoreElementComponent {...blog} />
<DublinCoreElementComponent {...blog.posts[0]} />
<h1>Other posts: </h1>
<ul>
{blog.posts
......
import * as React from "react";
import { DublinCoreElement } from "./dcschema";
import { DublinCoreElementProps } from "./dcschema";
import * as ReactMarkdown from "react-markdown";
export const DublinCoreElementComponent: React.FC<{
dcelement: DublinCoreElement;
}> = ({ dcelement }) => {
let contentDisplay = <div>{dcelement.description}</div>;
export const DublinCoreElementComponent: React.FC<
DublinCoreElementProps
> = ({ title, description, creator, date, contentType }) => {
let contentDisplay = <div>{description}</div>;
if (dcelement.contentType === "text/markdown") {
contentDisplay = <ReactMarkdown source={dcelement.description} />;
}
if (contentType === "text/markdown") {
contentDisplay = <ReactMarkdown source={description} />;
}
return (
<>
<h1>{dcelement.title}</h1>
<div>{dcelement.creator}</div>
<div>{dcelement.date}</div>
{contentDisplay}
</>
);
};
return (
<>
<h1>{title}</h1>
<div>{creator}</div>
<div>{date}</div>
{contentDisplay}
</>
);
};
import { rdfMeta, application } from "@logilab/libview";
import { rdfMeta, application, implementation } from "@logilab/libview";
import { ONTOLOGY } from "../common/schema";
/**
* The data for DublinCore Elements metadata
*/
export interface DublinCoreElement extends rdfMeta.Loadable {
export interface DublinCoreElementProps {
title: string;
description: string;
creator: string;
creator: string[];
date: string;
contentType: string;
dataFetcher?: implementation.DataFetcher;
}
export interface DublinCoreElement extends rdfMeta.Loadable, DublinCoreElementProps {
}
/**
......
......@@ -30,7 +30,7 @@ import {
import * as $rdf from "rdflib";
import { DublinCoreElementComponent } from "./DublinCoreImpl";
import { ONTOLOGY } from "../common/schema";
import { loadDublinCoreElement } from "./dcschema";
import { loadDublinCoreElement, DublinCoreElementProps } from "./dcschema";
import { httpsAlias } from "../common/aliases";
/**
......@@ -40,7 +40,7 @@ const DESCRIPTOR_DCELEMENT: definition.ViewDescriptor = {
identifier: "::Logilab::DublinCoreElement",
name: "Logilab: Dublin Core Element View",
description: "Renders a DublinCore Element",
entrypoint: "VIEW_DCE_ENTRYPOINT",
entrypoint: "VIEW_ENTRYPOINT",
resourceCss: [
{
uri:
......@@ -53,6 +53,8 @@ const DESCRIPTOR_DCELEMENT: definition.ViewDescriptor = {
}
};
const DC = $rdf.Namespace("http://purl.org/dc/elements/1.1/");
class DCElementRendering implements implementation.ViewImplementation {
descriptor: definition.ViewDescriptor;
constructor() {
......@@ -88,7 +90,7 @@ class DCElementRendering implements implementation.ViewImplementation {
let dcelement = loadDublinCoreElement(renderer, context, target);
let result = document.createElement("div");
ReactDOM.render(
<DublinCoreElementComponent dcelement={dcelement} />,
<DublinCoreElementComponent {...dcelement} />,
result
);
return {
......@@ -96,9 +98,32 @@ class DCElementRendering implements implementation.ViewImplementation {
suggestedResources: []
};
}
simpleRender(
nodeId: string,
context: $rdf.Formula,
target: string,
dataFetcher?: implementation.DataFetcher
): Element {
const targetSym = $rdf.sym(target);
const dcelement: DublinCoreElementProps = {
title: context.anyJS(targetSym, DC("title")),
description: context.anyJS(targetSym, DC("description")),
creator: context.each(targetSym, DC("creator")).map((node) => node.value),
date: context.anyJS(targetSym, DC("date")),
contentType: context.anyJS(targetSym, DC("format")),
dataFetcher
};
const result = document.createElement("div");
ReactDOM.render(<DublinCoreElementComponent {...dcelement} />, document.getElementById(nodeId));
return result;
}
}
/**
* Export the view
*/
export const VIEW_DCE_ENTRYPOINT: DCElementRendering = new DCElementRendering();
export const VIEW_ENTRYPOINT = VIEW_DCE_ENTRYPOINT;
......@@ -122,16 +122,14 @@
"identifier": "::Logilab::DublinCoreElement",
"name": "Logilab: Dublin Core Element View",
"description": "Renders a DublinCore Element",
"entrypoint": "VIEW_DCE_ENTRYPOINT",
"entrypoint": "VIEW_ENTRYPOINT",
"resourceCss": [
{
"location": "remote",
"uri": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
}
],
"resourceJs": [],
"resourceMain": {
"location": "remote",
"uri": "http://localhost:8080/view_dcelement.js"
}
}
......
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