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

[fix] Refactoring the popup UI

parent 1bfdbea3b305
/*******************************************************************************
* 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 { application, definition } from "@logilab/libview";
import { ResourceData } from "../data";
export interface CurrentTabMenuProps {
data: ResourceData;
registry: definition.ViewRegistry;
onSelectView: (viewId: string) => void;
onClickGotoCurrentTab: () => void;
onClickGotoOptions: () => void;
}
export class CurrentTabMenu extends React.Component<CurrentTabMenuProps, {}> {
constructor(props: CurrentTabMenuProps) {
super(props);
}
render() {
return (
<div className="container-fluid">
{this.props.data.rendering.evaluations.map(
(evaluation: application.RenderingEvaluation, index: number) => {
let view = this.props.registry.descriptors[evaluation.viewId];
let isSelected =
this.props.data.rendering.viewId == evaluation.viewId;
return (
<div key={"evaluation-" + index} className="row">
<div className="col-2">
{isSelected ? (
<span style={{ color: "darkgreen" }}>&#x2713;</span>
) : (
<span />
)}
</div>
<div className="col-10">
<a
className="btn btn-outline-light"
onClick={() => this.props.onSelectView(view.identifier)}
title={view.identifier}
>
{view.name}
</a>
</div>
</div>
);
}
)}
<hr />
<div className="row">
<div className="col-12">
<a
className="btn btn-outline-light"
onClick={this.props.onClickGotoCurrentTab}
title={"Current tab options"}
>
Current tab ...
</a>
</div>
</div>
<div className="row">
<div className="col-12">
<a
className="btn btn-outline-light"
onClick={this.props.onClickGotoOptions}
title={"General options"}
>
General options ...
</a>
</div>
</div>
</div>
);
}
}
......@@ -35,6 +35,7 @@ import { CurrentTabViews } from "../common/config/CurrentTabViews";
import { CurrentTabDataSources } from "../common/config/CurrentTabDataSources";
import { CurrentTabResources } from "../common/config/CurrentTabRessources";
import { CurrentTabConfig } from "../common/config/CurrentTabConfig";
import { CurrentTabMenu } from "../common/config/CurrentTabMenu";
/**
* Gets the identifier of the currently active tab
......@@ -88,7 +89,7 @@ class Popup extends React.Component<{}, State> {
(values: [ResourceData, definition.ViewRegistry]) => {
self.state.data = values[0];
self.state.registry = values[1];
self.state.pane = "tab";
self.state.pane = "menu";
self.setState(self.state);
}
);
......@@ -150,6 +151,23 @@ class Popup extends React.Component<{}, State> {
let self = this;
if (this.state.pane == "loading") {
return <ConfigLoading />;
} else if (this.state.pane == "menu") {
return (
<CurrentTabMenu
data={this.state.data}
registry={this.state.registry}
onClickGotoCurrentTab={() => {
self.state.pane = "tab";
self.setState(self.state);
}}
onClickGotoOptions={this.onOpenOptions}
onSelectView={(viewId: string) => {
this.state.data.command.isAutomatic = false;
this.state.data.command.selectedView = viewId;
this.onUpdateTabCommand();
}}
/>
);
} else if (this.state.pane == "tab") {
return (
<CurrentTabConfig
......
......@@ -250,7 +250,11 @@ class ViewRendererImpl implements CachingViewRenderer {
*/
render(context: RenderingContext, target: Resource): RenderingResult {
var view: ViewImplementation = null;
var evaluations: RenderingEvaluation[] = null;
var evaluations: RenderingEvaluation[] = evaluateViewsFor(
this.implementations,
context.store,
target
);
let options = context.options[target.uri];
if (
options != null &&
......@@ -263,11 +267,6 @@ class ViewRendererImpl implements CachingViewRenderer {
}
if (view == null || view == undefined) {
// try to resolve a view
evaluations = evaluateViewsFor(
this.implementations,
context.store,
target
);
if (evaluations.length > 0)
view = this.implementations[evaluations[0].viewId];
}
......
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