Commit ee3facce authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Fixing cweb #10129142 Problème de chargement de plusieurs vues personne à la suite

parent cee5765f3628
......@@ -381,6 +381,8 @@ chrome.runtime.onMessage.addListener(
data.sources = data.sources.concat(detectDataOnLinks(request.payload));
data.selectMain();
onTabUpdated(sender.tab.id);
} else if (request.requestType == "GetTabId") {
sendResponse(sender.tab.id);
} else if (request.requestType == "GetTabData") {
let tabId = request.payload;
if (tabId == null || tabId == undefined) {
......
......@@ -152,6 +152,25 @@ export function getResourceContent(
);
}
/**
* Gets the identifier of the current tab from the background
*/
export function getTabId(): Promise<number> {
return new Promise<number>(
(resolve: (tabId: number) => void, reject: (reason: any) => void) => {
chrome.runtime.sendMessage(
{
requestType: "GetTabId",
payload: null
},
(tabId: number) => {
resolve(tabId);
}
);
}
);
}
/**
* Gets data about the current tab to the background
* @param tabId The corresponding tab number
......@@ -197,7 +216,7 @@ export function setTabData(tabId: number, tabData: TabData): Promise<TabData> {
}
/**
* Sends a request for update to a tab
* Sends a request for updating to a tab
* @param id The identifier of a tab
* @param tabData The data for the tab
*/
......@@ -209,7 +228,7 @@ export function updateTab(tabId: number, tabData: TabData): void {
}
/**
* Sends a request for refresh to a tab
* Sends a request for refreshing to a tab
* @param id The identifier of a tab
*/
export function refreshTab(tabId: number): void {
......@@ -219,6 +238,18 @@ export function refreshTab(tabId: number): void {
});
}
/**
* Sends a request for navigating a tab to an URI
* @param id The identifier of a tab
* @param
*/
export function navigateTabTo(tabId: number, uri: string): void {
chrome.tabs.sendMessage(tabId, {
requestType: "NavigateTo",
payload: uri
});
}
/**
* Gets the identifier of the currently active tab
*/
......
......@@ -85,7 +85,7 @@ export class RdfTriplesRendering implements implementation.ViewImplementation {
}
)
.map((triple: Triple) => {
tbody.appendChild(renderRdfTriple(triple));
tbody.appendChild(renderRdfTriple(renderer, triple));
});
table.appendChild(tbody);
result.appendChild(table);
......@@ -94,15 +94,21 @@ export class RdfTriplesRendering implements implementation.ViewImplementation {
}
}
function renderRdfTriple(triple: Triple): HTMLElement {
function renderRdfTriple(
renderer: application.ViewRenderer,
triple: Triple
): HTMLElement {
let tr = document.createElement("tr");
tr.appendChild(renderRdfNode(triple.subject));
tr.appendChild(renderRdfNode(triple.predicate));
tr.appendChild(renderRdfNode(triple.object));
tr.appendChild(renderRdfNode(renderer, triple.subject));
tr.appendChild(renderRdfNode(renderer, triple.predicate));
tr.appendChild(renderRdfNode(renderer, triple.object));
return tr;
}
function renderRdfNode(node: Term): HTMLElement {
function renderRdfNode(
renderer: application.ViewRenderer,
node: Term
): HTMLElement {
let result = document.createElement("td");
if (node == undefined || node == null) {
let sub = document.createElement("span");
......@@ -112,6 +118,11 @@ function renderRdfNode(node: Term): HTMLElement {
let nodeIRI = node as NamedNode;
let sub = document.createElement("a");
sub.href = nodeIRI.uri;
sub.onclick = (event: Event) => {
event.preventDefault();
renderer.onMoveTo(nodeIRI.uri);
return false;
};
sub.appendChild(document.createTextNode(nodeIRI.uri));
result.appendChild(sub);
} else if (node.termType == "BlankNode") {
......
......@@ -23,7 +23,9 @@ import {
Message,
getResourceContent,
getViewRegistry,
getTabData
getTabData,
navigateTabTo,
getTabId
} from "../common/messages";
import { loadRdfStore } from "../common/rdf";
import "chrome";
......@@ -123,6 +125,16 @@ class MainViewer implements application.Application {
this.renderer = null;
}
/**
* Reacts to a user clicking on a link to a new resource
* @param uri The uri of the resource
*/
public onMoveTo(uri: string): void {
getTabId().then((tabId: number) => {
navigateTabTo(tabId, uri);
});
}
/**
* Sets the content for the application
* @param content The content
......
......@@ -99,6 +99,8 @@ chrome.runtime.onMessage.addListener(function(
else onUpdateDeactivate();
} else if (request.requestType == "Refresh") {
window.location.reload(true);
} else if (request.requestType == "NavigateTo") {
window.location.assign(request.payload);
}
});
......
......@@ -38,6 +38,12 @@ export interface ViewRendering {
* A renderer for an application
*/
export interface ViewRenderer {
/**
* Reacts to a user clicking on a link to a new resource
* @param uri The uri of the resource
*/
onMoveTo(uri: string): void;
/**
* Renders a resource belonging to an RDF store
* @param store The RDF store holding the data to be rendered
......@@ -51,6 +57,12 @@ export interface ViewRenderer {
* The public interface for the application
*/
export interface Application {
/**
* Reacts to a user clicking on a link to a new resource
* @param uri The uri of the resource
*/
onMoveTo(uri: string): void;
/**
* Sets the content for the application
* @param content The content
......
......@@ -253,6 +253,14 @@ class ViewRendererImpl implements ViewRenderer {
*/
forceView: string;
/**
* Reacts to a user clicking on a link to a new resource
* @param uri The uri of the resource
*/
onMoveTo(uri: string): void {
this.application.onMoveTo(uri);
}
/**
* Renders a resource belonging to an RDF store
* @param store The RDF store holding the data to be rendered
......
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