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

Fixed issue cweb #10129157 rien ne s'affiche dans liste déroulante "Views"

parent bd7336dea5fd
......@@ -319,8 +319,8 @@ export class TabCommand {
constructor() {
this.isActive = false;
this.isAutomatic = true;
this.selectedSource = null;
this.selectedView = null;
this.selectedSource = "";
this.selectedView = "";
}
/**
* Whether the user activated the extension for this tab
......@@ -398,8 +398,8 @@ export class TabData {
*/
clear(): void {
this.command.isAutomatic = true;
this.command.selectedSource = null;
this.command.selectedView = null;
this.command.selectedSource = "";
this.command.selectedView = "";
this.mainSource = NO_DATA;
this.sources = [];
this.primaryTopic = null;
......@@ -409,7 +409,11 @@ export class TabData {
* Selects the main resource among the provided one
*/
selectMain(): DataSource {
if (this.command.isAutomatic || this.command.selectedSource == null) {
if (
this.command.isAutomatic ||
this.command.selectedSource == null ||
this.command.selectedSource == ""
) {
if (this.sources.length == 0) {
this.mainSource = NO_DATA;
} else {
......
......@@ -54,7 +54,11 @@ function onUpdateActivate(tabData: TabData): void {
},
(registry: definition.ViewRegistry) => {
implementation
.newRenderer(currentApp, registry)
.newRenderer(
currentApp,
registry,
tabData.command.isAutomatic ? null : tabData.command.selectedView
)
.then((renderer: application.ViewRenderer) => {
currentApp.onContent(renderer, store, tabData.primaryTopic);
});
......
......@@ -147,7 +147,7 @@ class Popup extends React.Component<{}, State> {
requestType: "UpdateTabData",
senderId: "popup",
payload: {
tabId: this.state.tabId,
tabId: self.state.tabId,
tabData: self.state.tabData
}
},
......@@ -166,8 +166,8 @@ class Popup extends React.Component<{}, State> {
onTabCommandAutomatic(event: React.FormEvent<HTMLInputElement>) {
this.state.tabData.command.isAutomatic = event.currentTarget.checked;
if (this.state.tabData.command.isAutomatic) {
this.state.tabData.command.selectedSource = null;
this.state.tabData.command.selectedView == null;
this.state.tabData.command.selectedSource = "";
this.state.tabData.command.selectedView = "";
}
this.onUpdateTabCommand();
}
......@@ -175,13 +175,20 @@ class Popup extends React.Component<{}, State> {
onTabCommandSelectSource(event: React.FormEvent<HTMLSelectElement>) {
this.state.tabData.command.selectedSource = event.currentTarget.value;
if (this.state.tabData.command.isAutomatic) {
this.state.tabData.command.selectedSource = null;
this.state.tabData.command.selectedView == null;
this.state.tabData.command.selectedSource = "";
this.state.tabData.command.selectedView = "";
}
this.onUpdateTabCommand();
}
onTabCommandSelectView(event: React.FormEvent<HTMLSelectElement>) {}
onTabCommandSelectView(event: React.FormEvent<HTMLSelectElement>) {
this.state.tabData.command.selectedView = event.currentTarget.value;
if (this.state.tabData.command.isAutomatic) {
this.state.tabData.command.selectedSource = "";
this.state.tabData.command.selectedView = "";
}
this.onUpdateTabCommand();
}
onRegistryUpdateNewSourceName(event: React.FormEvent<HTMLInputElement>) {
this.state.registryNewSourceName = event.currentTarget.value;
......@@ -309,12 +316,20 @@ class Popup extends React.Component<{}, State> {
</label>
</div>
</div>
<div
className="row"
style={{
display: this.state.tabData.command.isAutomatic ? "none" : ""
}}
>
<div className="row">
<div className="col-4">
<label>Primary topic</label>
</div>
<div className="col-8">
<input
className="form-control"
readOnly={true}
value={this.state.tabData.primaryTopic}
style={{ width: "250px" }}
/>
</div>
</div>
<div className="row">
<div className="col-4">
<label>Data source</label>
</div>
......@@ -327,6 +342,9 @@ class Popup extends React.Component<{}, State> {
value={this.state.tabData.command.selectedSource}
style={{ width: "250px" }}
>
<option key={"view-default"} value="">
{"-- auto --"}
</option>
{this.state.tabData.sources
.filter((source: DataSource) => source != NO_DATA)
.map((source: DataSource, index: number) => (
......@@ -337,43 +355,7 @@ class Popup extends React.Component<{}, State> {
</select>
</div>
</div>
<div
className="row"
style={{
display: this.state.tabData.command.isAutomatic ? "" : "none"
}}
>
<div className="col-4">
<label>Data source</label>
</div>
<div className="col-8">
<input
className="form-control"
readOnly={true}
value={this.state.tabData.mainSource.name}
style={{ width: "250px" }}
/>
</div>
</div>
<div className="row">
<div className="col-4">
<label>Primary topic</label>
</div>
<div className="col-8">
<input
className="form-control"
readOnly={true}
value={this.state.tabData.primaryTopic}
style={{ width: "250px" }}
/>
</div>
</div>
<div
className="row"
style={{
display: this.state.tabData.command.isAutomatic ? "none" : ""
}}
>
<div className="col-4">
<label>View</label>
</div>
......@@ -385,7 +367,26 @@ class Popup extends React.Component<{}, State> {
onChange={this.onTabCommandSelectView}
value={this.state.tabData.command.selectedView}
style={{ width: "250px" }}
/>
>
<option key={"view-default"} value="">
{"-- auto --"}
</option>
{Object.keys(this.state.registry.descriptors)
.map((key: string) => this.state.registry.descriptors[key])
.sort(
(
a: definition.ViewDescriptor,
b: definition.ViewDescriptor
): number => a.name.localeCompare(b.name)
)
.map((descriptor: definition.ViewDescriptor, index: number) => {
return (
<option key={"view-" + index} value={descriptor.identifier}>
{descriptor.name + " (" + descriptor.identifier + ")"}
</option>
);
})}
</select>
</div>
</div>
</div>
......
......@@ -228,15 +228,18 @@ class ViewRendererImpl implements ViewRenderer {
* @param application The parent application
* @param registry The registry to use
* @param implementations The view implementations
* @param forceView Forces the selection of a specific view
*/
constructor(
application: Application,
registry: ViewRegistry,
implementations: ViewImplementations
implementations: ViewImplementations,
forceView: string = null
) {
this.application = application;
this.registry = registry;
this.implementations = implementations;
this.forceView = forceView;
}
/**
......@@ -251,6 +254,10 @@ class ViewRendererImpl implements ViewRenderer {
* The view implementations
*/
implementations: ViewImplementations;
/**
* Forces the selection of a specific view
*/
forceView: string;
/**
* Renders a resource belonging to an RDF store
......@@ -259,8 +266,19 @@ class ViewRendererImpl implements ViewRenderer {
* @param target The target resource for this view
*/
render(store: RdfStore, root: string, target: string = root): HTMLElement {
let view = resolveViewFor(this.implementations, store, target);
if (view == null) return null;
var view = null;
if (this.forceView != null && this.forceView != "") {
// try to use the forced view
view = this.implementations[this.forceView];
}
if (view == null || view == undefined) {
// try to resolve a view
view = resolveViewFor(this.implementations, store, target);
}
if (view == null || view == undefined) {
// cannot resolve a view ...
return null;
}
return view.render(this, store, root, target);
}
}
......@@ -269,10 +287,12 @@ class ViewRendererImpl implements ViewRenderer {
* Creates a new view renderer
* @param application The current application
* @param registry The view registry to use
* @param forceView Forces the selection of a specific view
*/
export function newRenderer(
application: Application,
registry: ViewRegistry
registry: ViewRegistry,
forceView: string = null
): Promise<ViewRenderer> {
return new Promise<ViewRenderer>(
(
......@@ -280,7 +300,12 @@ export function newRenderer(
reject: (reason: any) => void
) => {
loadImplementations(registry).then((impls: ViewImplementations) => {
let renderer = new ViewRendererImpl(application, registry, impls);
let renderer = new ViewRendererImpl(
application,
registry,
impls,
forceView
);
resolve(renderer);
});
}
......
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