Commit 56a0c9e9 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[feature] Browser support for supplementary resources

parent f0d0ba5d66f5
......@@ -654,6 +654,10 @@ export class ResourceData {
* The associated user command
*/
command: ResourceUserCommand;
/**
* The URI of supplementary resources that have been merged into this one
*/
supplements: string[];
}
/**
......
......@@ -177,7 +177,8 @@ class LDBrowserImpl implements LDBrowser {
let observations = observeContent(observable);
let resource: ResourceData = {
observations: observations,
command: new ResourceUserCommand()
command: new ResourceUserCommand(),
supplements: []
};
self.cacheResources[uri] = resource;
resolve(resource);
......@@ -306,6 +307,35 @@ class LDBrowserImpl implements LDBrowser {
this.refresh();
}
/**
* When supplementary resources has been suggested for the current one
* @param resource The current resource
* @param uris The URIs of the suggested supplementary ones
*/
private async onSuggestedResources(
resource: ResourceData,
uris: string[]
): Promise<any> {
uris = uris.filter((uri: string) => resource.supplements.indexOf(uri) < 0);
if (uris.length == 0) return;
let parentStore = await this.resolveRdfStore(resource);
let self = this;
let count = 0;
let onFinishedPart = function() {
count++;
if (count >= uris.length) self.refresh();
};
uris.forEach(async (uri: string) => {
let childResource = await self.resolveResourceData(uri);
let childStore = await self.resolveRdfStore(childResource);
childStore.statements.forEach((statement: $rdf.Statement) =>
parentStore.addStatement(statement)
);
resource.supplements.push(uri);
onFinishedPart();
});
}
/**
* When an URI has been reached
* @param uri The URI
......@@ -323,10 +353,8 @@ class LDBrowserImpl implements LDBrowser {
this.handler.onLoad("Rendering");
let rendering = renderer.render(context, context.root);
if (rendering != null) {
rendering.suggestedResources.forEach((uri: string) => {
// onSuggestedResource(uri);
});
this.handler.onContent(registry, rendering);
this.onSuggestedResources(resource, rendering.suggestedResources);
} else {
this.handler.onError("Rendering failed!");
}
......
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