Commit 53fb84c8 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[feature] Implementing the side bar

parent bf7f8c781ef3
......@@ -33,7 +33,6 @@ import {
getAcceptRdf,
ORIGIN_KIND_DIRECT,
ORIGIN_KIND_LINKED_HTML,
ORIGIN_KIND_NEGOTIATED,
ORIGIN_KIND_REDIRECTED,
DocumentStatus
} from "../common/data";
......@@ -146,9 +145,10 @@ function onSendingHeaders(
)
return {};
if (observation.origin && observation.origin.kind == ORIGIN_KIND_REDIRECTED) {
observation.origin.kind = ORIGIN_KIND_NEGOTIATED;
} else {
if (
!observation.origin ||
observation.origin.kind != ORIGIN_KIND_REDIRECTED
) {
observation.origin = {
kind: ORIGIN_KIND_DIRECT,
url: details.url
......
......@@ -107,6 +107,7 @@ export interface LDBrowser {
/**
* When an URI has been reached
* @param uri The URI
* @param origin The origin for this URI, if any
*/
onReachedUri(uri: string, origin?: Origin): Promise<void>;
/**
......@@ -199,9 +200,11 @@ class LDBrowserImpl implements LDBrowser {
/**
* Resolves the data about a resource
* @param resource The resource
* @param origin The origin for this URI, if any
*/
private resolveResourceData(
resource: application.Resource
resource: application.Resource,
origin?: Origin
): Promise<ResourceData> {
let self = this;
return new Promise<ResourceData>(
......@@ -232,10 +235,15 @@ class LDBrowserImpl implements LDBrowser {
fetchObservableAt(uri)
.then((observable: ObservableContent) => {
onObservations(
observeContent(observable, {
kind: ORIGIN_KIND_DIRECT,
url: uri
})
observeContent(
observable,
origin
? origin
: {
kind: ORIGIN_KIND_DIRECT,
url: uri
}
)
);
})
.catch((reason: any) => {
......@@ -461,11 +469,14 @@ class LDBrowserImpl implements LDBrowser {
/**
* When an URI has been reached
* @param uri The URI
* @param origin The origin for this URI, if any
*/
public async onReachedUri(uri: string, origin?: Origin): Promise<void> {
this.handler.onLoad("Loading data");
let data = await this.resolveResourceData(this.resolveResource(uri));
if (origin) data.observations[uri].origin = origin;
let data = await this.resolveResourceData(
this.resolveResource(uri),
origin
);
this.currentData = data;
let store = await this.resolveRdfStore(data);
let context = this.newRenderingContext(data, store);
......
......@@ -27,7 +27,8 @@ import {
ORIGIN_KIND_DIRECT,
ORIGIN_KIND_NEGOTIATED,
ORIGIN_KIND_LINKED_HTTP,
ORIGIN_KIND_LINKED_HTML
ORIGIN_KIND_LINKED_HTML,
ORIGIN_KIND_REDIRECTED
} from "../data";
export interface CurrentTabDataSourcesProps {
......@@ -53,6 +54,15 @@ export class CurrentTabDataSources extends React.Component<
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_REDIRECTED) {
return (
<span
title={"Redirected from from " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_NEGOTIATED) {
return (
<span
......
......@@ -680,7 +680,7 @@ export function observeContent(
{ name: "rel", value: "alternate" },
{ name: "type", value: observable.contentType }
]),
{ kind: ORIGIN_KIND_NEGOTIATED, url: observable.url }
origin
);
let observations: DocumentObservations = {
origin: origin,
......
/*******************************************************************************
* Copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
*
* This file is part of CubicWeb.
*
* CubicWeb is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 2.1 of the License, or (at your option)
* any later version.
*
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import React = require("react");
import {
ResourceData,
getSourcesFor,
DocumentSource,
Origin,
ORIGIN_KIND_DIRECT,
ORIGIN_KIND_NEGOTIATED,
ORIGIN_KIND_LINKED_HTTP,
ORIGIN_KIND_LINKED_HTML,
ORIGIN_KIND_REDIRECTED
} from "../common/data";
export interface SideBarDataSourcesProps {
data: ResourceData;
}
export class SideBarDataSources extends React.Component<
SideBarDataSourcesProps,
{}
> {
constructor(props: SideBarDataSourcesProps) {
super(props);
}
renderOrigin(origin: Origin): React.ReactNode {
if (origin.kind == ORIGIN_KIND_DIRECT) {
return (
<span
title={"Direct request of " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_REDIRECTED) {
return (
<span
title={"Redirected from from " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_NEGOTIATED) {
return (
<span
title={"Negotiated from " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_LINKED_HTTP) {
return (
<span
title={"Linked in HTTP headers from " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
} else if (origin.kind == ORIGIN_KIND_LINKED_HTML) {
return (
<span
title={"Linked in HTML headers from " + origin.url}
style={{ color: "blue", cursor: "pointer", marginLeft: "5pt" }}
>
Why?
</span>
);
}
}
renderTriplesCount(count: number): React.ReactNode {
if (count == -1) {
return (
<span
className="badge badge-danger"
title="Failed to load this source"
style={{ marginRight: "5pt", marginLeft: "5pt" }}
>
error
</span>
);
}
if (count == 0) {
return (
<span
className="badge badge-secondary"
title="Not loaded"
style={{ marginRight: "5pt", marginLeft: "5pt" }}
>
0
</span>
);
}
return (
<span
className="badge badge-secondary"
title="Total loaded triples from this source"
style={{ marginRight: "5pt", marginLeft: "5pt" }}
>
{count}
</span>
);
}
render() {
let allSources = getSourcesFor(this.props.data);
return (
<div className="container-fluid">
<div className="row">
<div className="col-12">
<span style={{ fontSize: "17pt" }}>
Sources of data for this tab
</span>
</div>
</div>
<hr />
{Object.keys(allSources).map((url: string, index: number) => {
let series = allSources[url];
let totalLoaded = this.props.data.observations[url].totalLoaded;
let origin = this.props.data.observations[url].origin;
return (
<div key={"series-" + index} style={{ marginTop: "10px" }}>
<div className="row">
<span>{"\u25BA"}</span>
<span
className="badge badge-primary"
title="Total loaded triples from this URI"
style={{ marginRight: "5pt", marginLeft: "5pt" }}
>
{totalLoaded}
</span>
<a href={url}>{url}</a>
{origin ? this.renderOrigin(origin) : <span />}
</div>
{series.map((source: DocumentSource, index: number) => (
<div key={"source-" + index} className="row">
<div className="col-12">
<span>{"\u00A0\u00A0\u00A0\u00A0\u21B3"}</span>
{this.renderTriplesCount(source.loaded)}
<span>{source.name}</span>
{this.renderOrigin(source.origin)}
</div>
</div>
))}
</div>
);
})}
</div>
);
}
}
......@@ -24,7 +24,7 @@ import { definition } from "@logilab/libview";
import { getViewRegistry, getCurrentResource } from "../common/messages";
import { ResourceData } from "../common/data";
import { ConfigLoading } from "../common/config/ConfigLoading";
import { CurrentTabDataSources } from "../common/config/CurrentTabDataSources";
import { SideBarDataSources } from "./SideBarDataSources";
/**
* Gets the identifier of the currently active tab
......@@ -91,9 +91,7 @@ class Sidebar extends React.Component<{}, State> {
} else if (this.state.data == null || this.state.data == undefined) {
return <span>This tab is not using an active Linked Data browser.</span>;
} else {
return (
<CurrentTabDataSources data={this.state.data} onClickBack={() => {}} />
);
return <SideBarDataSources data={this.state.data} />;
}
}
}
......
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