Skip to content

Commit

Permalink
fix (ui): Timeline entries now link to Things pages
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Sep 6, 2024
1 parent a2ece01 commit d270471
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 29 deletions.
3 changes: 0 additions & 3 deletions ToDo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ items:
links:
- https://github.com/enola-dev/enola/issues/845

- Timeline links to Things pages; both for DocGen and in UI:
tags: [ui, docgen]

- Don't load JS from unpkg.com, but use the local copies from the //third_party module:
tags: [google]

Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Enola uses Metadata about all of its _Things_ when rendering them:
* image of a logo; e.g. from [favicon](https://de.wikipedia.org/wiki/Favicon) or something like that; or an 😃 Emoji!
* curie is a compact URI; a shorter form of the original "long" IRI of the Thing.

[The `info metadata` sub-command](../use/info/index.md) is a handy tool to test this.
[The `info metadata` sub-command](../use/info/index.md#metadata) is a handy tool to test this.

<!-- The following documents the dev.enola.thing.metadata.ThingMetadataProvider service; keep it updated, if it ever changes. -->

Expand Down Expand Up @@ -59,14 +59,14 @@ This is optional and may be empty.

## Image of Logo

This is read, again in order from:
This is read, again in order, from:

1. [https://enola.dev/emoji](../models/enola.dev/emoji.md)
1. https://schema.org/logo
1. https://schema.org/thumbnailUrl
1. https://schema.org/image

On the Thing itself, or via its [RDFS range](../models/www.w3.org/2000/01/rdf-schema/range.md) or
and similarly to above first on the Thing itself, or if none then via its [RDFS range](../models/www.w3.org/2000/01/rdf-schema/range.md) or
[RDF type](../models/www.w3.org/1999/02/22-rdf-syntax-ns/type.md).

## CURIE
Expand Down
3 changes: 1 addition & 2 deletions java/dev/enola/thing/gen/EnolaDevKnownDocsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.common.collect.ImmutableList;

import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -46,7 +45,7 @@ public class EnolaDevKnownDocsProvider implements KnownDocsProvider {
"http://www.w3.org/2001/XMLSchema");

@Override
public @Nullable String get(String iri) {
public String get(String iri) {
for (var wellKnownPrefix : wellKnownPrefixes) {
if (iri.startsWith(wellKnownPrefix)) {
try {
Expand Down
12 changes: 1 addition & 11 deletions java/dev/enola/thing/gen/KnownDocsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
*/
package dev.enola.thing.gen;

import dev.enola.data.ProviderFromIRI;

import org.jspecify.annotations.NonNull;

/**
* KnownDocsProvider offers, if available, a "better URL" to use as link target in generated HTML or
* Markdown etc. documentation for some known IRIs. For example:
Expand All @@ -32,11 +28,5 @@
* http://www.w3.org/1999/02/22-rdf-syntax-ns#type (for which we cannot set up any HTTP
* redirector; and which is nicer to read than e.g. https://www.w3.org/TR/rdf-schema/#ch_type)
* </ul>
*
* <p>The KnownMetadataProvider (TBD) is related to this, but has a different purpose.
*/
public interface KnownDocsProvider extends ProviderFromIRI<String> {

@Override
@NonNull String get(String iri);
}
public interface KnownDocsProvider extends LinkTransformer {}
29 changes: 29 additions & 0 deletions java/dev/enola/thing/gen/LinkTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.thing.gen;

import dev.enola.data.ProviderFromIRI;

import org.jspecify.annotations.NonNull;

/** LinkTransformer transforms an IRI (link); see implementations for how. */
public interface LinkTransformer extends ProviderFromIRI<String> {

@Override
@NonNull String get(String iri);
}
30 changes: 30 additions & 0 deletions java/dev/enola/thing/gen/StaticSiteLinkTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.thing.gen;

import org.jspecify.annotations.NonNull;

public class StaticSiteLinkTransformer implements LinkTransformer {

@Override
public @NonNull String get(String iri) {
// TODO This is wrong, and needs to be (something like, or exactly?)
// what's in dev.enola.thing.gen.markdown.MarkdownLinkWriter.rel()
return iri;
}
}
1 change: 1 addition & 0 deletions java/dev/enola/thing/gen/markdown/MarkdownLinkWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void writeLabel(Metadata md, Appendable out) throws IOException {
}
}

// TODO Move this into StaticSiteLinkTransformer (?)
private String rel(
String linkIRI,
URI outputIRI,
Expand Down
5 changes: 4 additions & 1 deletion java/dev/enola/thing/gen/markdown/MarkdownSiteGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import dev.enola.data.ProviderFromIRI;
import dev.enola.datatype.DatatypeRepository;
import dev.enola.thing.KIRI;
import dev.enola.thing.gen.LinkTransformer;
import dev.enola.thing.gen.Relativizer;
import dev.enola.thing.gen.StaticSiteLinkTransformer;
import dev.enola.thing.gen.gexf.GexfGenerator;
import dev.enola.thing.gen.graphviz.GraphvizGenerator;
import dev.enola.thing.gen.visjs.VisJsTimelineGenerator;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class MarkdownSiteGenerator {
private final ThingMetadataProvider thingMetadataProvider;
private final ProtoThingMetadataProvider protoThingMetadataProvider;
private final DatatypeRepository datatypeRepository;
private final LinkTransformer linkTransformer = new StaticSiteLinkTransformer();
private final Templates.Format format;
private final GraphvizGenerator graphvizGenerator;
private final GexfGenerator gexfGenerator;
Expand Down Expand Up @@ -92,7 +95,7 @@ public MarkdownSiteGenerator(
this.rp = rp;
this.graphvizGenerator = new GraphvizGenerator(thingMetadataProvider);
this.gexfGenerator = new GexfGenerator(thingMetadataProvider);
this.timelineGenerator = new VisJsTimelineGenerator(thingMetadataProvider);
this.timelineGenerator = new VisJsTimelineGenerator(thingMetadataProvider, linkTransformer);
}

public void generate(
Expand Down
10 changes: 6 additions & 4 deletions java/dev/enola/thing/gen/visjs/VisJsTimelineGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import dev.enola.common.yamljson.JSON;
import dev.enola.thing.KIRI;
import dev.enola.thing.Thing;
import dev.enola.thing.gen.LinkTransformer;
import dev.enola.thing.gen.ThingsIntoAppendableConverter;
import dev.enola.thing.metadata.ThingMetadataProvider;
import dev.enola.thing.metadata.ThingTimeProvider;
Expand All @@ -45,8 +46,6 @@ public class VisJsTimelineGenerator implements ThingsIntoAppendableConverter {
// TODO "Define a start and an end in the timeline options. This will improve initial loading."
// TODO Add clickable URLs to all Things

// TODO Try it all out with more interesting real data

// TODO https://github.com/javdome/timeline-arrows

// TODO #feature Support Timezone, but don't convert in Java, but purely client side in HTML
Expand All @@ -66,12 +65,15 @@ public class VisJsTimelineGenerator implements ThingsIntoAppendableConverter {

private final ThingTimeProvider timeProvider = new ThingTimeProvider();
private final ThingMetadataProvider metadataProvider;
private final LinkTransformer linkTransformer;

private static final ReadableResource template =
new ClasspathResource("dev/enola/thing/gen/visjs/timeline-template.html");

public VisJsTimelineGenerator(ThingMetadataProvider metadataProvider) {
public VisJsTimelineGenerator(
ThingMetadataProvider metadataProvider, LinkTransformer linkTransformer) {
this.metadataProvider = metadataProvider;
this.linkTransformer = linkTransformer;
}

@Override
Expand All @@ -97,7 +99,7 @@ GroupsAndItems groupsAndItemsJSON(Iterable<Thing> things) {
var groups = new HashMap<String, Group>();
var items = new ArrayList<Item>();
for (var thing : things) {
String url = null; // TODO TBD
String url = linkTransformer.get(thing.iri());
var thingLabel = label(metadataProvider.get(thing));

// TODO How to best handle Things with multiple parent types...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import dev.enola.common.context.testlib.TestTLCRule;
import dev.enola.common.io.resource.ClasspathResource;
import dev.enola.common.io.resource.MemoryResource;
import dev.enola.thing.gen.LinkTransformer;
import dev.enola.thing.io.Loader;
import dev.enola.thing.metadata.ThingMetadataProvider;

Expand All @@ -49,7 +50,8 @@ public void html() throws IOException {
assertThat(things).isNotEmpty();
var actual = new MemoryResource(MediaType.HTML_UTF_8);

var gen = new VisJsTimelineGenerator(TLC.get(ThingMetadataProvider.class));
LinkTransformer linkTransformer = iri -> iri;
var gen = new VisJsTimelineGenerator(TLC.get(ThingMetadataProvider.class), linkTransformer);
gen.convertIntoOrThrow(things, actual);

var expected = new ClasspathResource("dev/enola/thing/gen/visjs/timeline.expected.html");
Expand Down
2 changes: 2 additions & 0 deletions java/dev/enola/thing/gen/visjs/timeline.expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
"id": "https://example.org/greeting3",
"group": "https://example.org/Salutation",
"label": "ex:greeting3",
"url": "https://example.org/greeting3",
"start": "2024-08-11T01:50:56.737412406Z"
},
{
"id": "https://example.org/world",
"group": "https://example.org/Planet",
"label": "ex:world",
"url": "https://example.org/world",
"start": "-1000000000-01-02T00:00:00Z",
"end": "+300000-12-31T00:00:00Z"
}
Expand Down
7 changes: 5 additions & 2 deletions java/dev/enola/web/ThingUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.escape.Escaper;
import com.google.common.html.HtmlEscapers;

import dev.enola.thing.gen.LinkTransformer;
import dev.enola.thing.message.ProtoThingMetadataProvider;
import dev.enola.thing.proto.ThingOrBuilder;
import dev.enola.thing.proto.Value;
Expand All @@ -41,9 +42,11 @@ public class ThingUI {
// TODO Use Appendable-based approach, for better memory efficiency, and less String "trashing"

private final ProtoThingMetadataProvider metadataProvider;
private final LinkTransformer linkTransformer;

public ThingUI(ProtoThingMetadataProvider metadataProvider) {
public ThingUI(ProtoThingMetadataProvider metadataProvider, LinkTransformer linkTransformer) {
this.metadataProvider = metadataProvider;
this.linkTransformer = linkTransformer;
}

public CharSequence html(ThingOrBuilder thing) {
Expand Down Expand Up @@ -105,7 +108,7 @@ private CharSequence link(String iri) {
sb.append(meta.imageHTML());
sb.append(' ');
// TODO s(uri) or not - or another escaping?
sb.append("<a href=" + s("/ui/" + iri));
sb.append("<a href=" + s(linkTransformer.get(iri)));
var description = meta.descriptionHTML();
if (!description.isEmpty()) {
sb.append(" title=\"");
Expand Down
7 changes: 5 additions & 2 deletions java/dev/enola/web/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import dev.enola.core.proto.GetFileDescriptorSetRequest;
import dev.enola.core.proto.GetThingRequest;
import dev.enola.core.view.EnolaMessages;
import dev.enola.thing.gen.LinkTransformer;
import dev.enola.thing.gen.visjs.VisJsTimelineGenerator;
import dev.enola.thing.message.ProtoThingMetadataProvider;
import dev.enola.thing.metadata.ThingMetadataProvider;
Expand All @@ -59,6 +60,7 @@ public class UI implements WebHandler {
private final TypeRegistryWrapper typeRegistryWrapper;
private final EnolaMessages enolaMessages;
private final EnolaThingProvider /* TODO ThingProvider*/ thingProvider;
private final LinkTransformer linkTransformer = new UiLinkTransformer();
private final ThingUI thingUI;
private final ThingsConverterWrapperHandler timelineHandler;
private ProtoIO protoIO;
Expand All @@ -74,12 +76,13 @@ public UI(EnolaServiceBlockingStub service, ThingMetadataProvider metadataProvid
thingProvider = new EnolaThingProvider(service);

var protoThingMetadataProvider = new ProtoThingMetadataProvider(metadataProvider);
thingUI = new ThingUI(protoThingMetadataProvider);
thingUI = new ThingUI(protoThingMetadataProvider, linkTransformer);

ThingRepository thingRepository = new ProtoToThingRepository(thingProvider);
timelineHandler =
new ThingsConverterWrapperHandler(
thingRepository, new VisJsTimelineGenerator(metadataProvider));
thingRepository,
new VisJsTimelineGenerator(metadataProvider, linkTransformer));
}

public void register(WebHandlers handlers) {
Expand Down
28 changes: 28 additions & 0 deletions java/dev/enola/web/UiLinkTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.web;

import dev.enola.thing.gen.LinkTransformer;

public class UiLinkTransformer implements LinkTransformer {

@Override
public String get(String iri) {
return "/ui/" + iri;
}
}

0 comments on commit d270471

Please sign in to comment.