Commit 6fccf8bd authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[feature] Implementing the side bar

parent a73e51eb0519
......@@ -39,7 +39,8 @@ import {
import {
getResourceContent,
getViewRegistry,
fetchObservableAt
fetchObservableAt,
updateSidebar
} from "../common/messages";
require("./view-defaults-impl");
......@@ -493,6 +494,7 @@ class LDBrowserImpl implements LDBrowser {
} else {
this.handler.onError("Rendering failed: Cannot resolve a view");
}
updateSidebar(data, registry);
} catch (e) {
this.handler.onError("Rendering failed: " + e);
}
......
......@@ -28,6 +28,7 @@ export interface CurrentTabMenuProps {
onSelectView: (viewId: string) => void;
onClickGotoCurrentTab: () => void;
onClickGotoOptions: () => void;
onClickGotoSidebar: () => void;
}
export class CurrentTabMenu extends React.Component<CurrentTabMenuProps, {}> {
......@@ -77,6 +78,17 @@ export class CurrentTabMenu extends React.Component<CurrentTabMenuProps, {}> {
</a>
</div>
</div>
<div className="row">
<div className="col-12">
<a
className="btn btn-outline-light"
onClick={this.props.onClickGotoSidebar}
title={"Open info sidebar"}
>
Open info sidebar ...
</a>
</div>
</div>
<div className="row">
<div className="col-12">
<a
......
/*******************************************************************************
* 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/>.
******************************************************************************/
declare namespace chrome.sidebarAction {
/**
* Open the sidebar in the active window.
*/
function open(): Promise<void>;
}
......@@ -26,6 +26,7 @@ import {
} from "./data";
import { definition } from "@logilab/libview";
import "chrome";
import { ViewRegistry } from "@logilab/libview/build/lib/view-def";
/**
* A message between parts of the extension
......@@ -286,6 +287,34 @@ export function backgroundToggleRawForTab(
);
}
/**
* Updates the content of the sidebar
* @param tabId The identifier for the sending tab
* @param data The data about the tab
* @param registry The registry
*/
export function updateSidebar(
data: ResourceData,
registry: ViewRegistry
): Promise<void> {
return new Promise<void>(
(resolve: (result: void) => void, reject: (reason: any) => void) => {
chrome.runtime.sendMessage(
{
requestType: "UpdateSidebar",
payload: {
data: data,
registry: registry
}
},
(result: void) => {
resolve(result);
}
);
}
);
}
/**
* Sends to a tab a message to turn the browser off
* @param id The identifier of a tab
......
......@@ -73,6 +73,7 @@ class Popup extends React.Component<{}, State> {
registry: null
};
this.onOpenOptions = this.onOpenOptions.bind(this);
this.onOpenSidebar = this.onOpenSidebar.bind(this);
this.onTunOff = this.onTunOff.bind(this);
this.onDisplayRaw = this.onDisplayRaw.bind(this);
this.onUpdateTabCommand = this.onUpdateTabCommand.bind(this);
......@@ -100,6 +101,10 @@ class Popup extends React.Component<{}, State> {
chrome.runtime.openOptionsPage(() => {});
}
onOpenSidebar() {
chrome.sidebarAction.open();
}
onTunOff() {
turnOffTab(this.state.tabId);
}
......@@ -165,6 +170,7 @@ class Popup extends React.Component<{}, State> {
self.setState(self.state);
}}
onClickGotoOptions={this.onOpenOptions}
onClickGotoSidebar={this.onOpenSidebar}
onSelectView={(viewId: string) => {
this.state.data.command.isAutomatic = false;
this.state.data.command.selectedView = viewId;
......
......@@ -21,7 +21,11 @@
import React = require("react");
import ReactDOM = require("react-dom");
import { definition } from "@logilab/libview";
import { getViewRegistry, getCurrentResource } from "../common/messages";
import {
getViewRegistry,
getCurrentResource,
Message
} from "../common/messages";
import { ResourceData } from "../common/data";
import { ConfigLoading } from "../common/config/ConfigLoading";
import { CurrentTabDataSources } from "../common/config/CurrentTabDataSources";
......@@ -64,7 +68,6 @@ class Sidebar extends React.Component<{}, State> {
registry: null
};
this.onTabActivated = this.onTabActivated.bind(this);
this.onTabUpdated = this.onTabUpdated.bind(this);
this.reloadTabData = this.reloadTabData.bind(this);
// load for the current tab
getCurrentTabId().then((tabId: number) => {
......@@ -74,7 +77,21 @@ class Sidebar extends React.Component<{}, State> {
});
// listen for change of the current tab
chrome.tabs.onActivated.addListener(this.onTabActivated);
chrome.tabs.onUpdated.addListener(this.onTabUpdated);
// listen to messages
let self = this;
chrome.runtime.onMessage.addListener(
(request: Message<any>, sender, sendResponse) => {
if (request.requestType == "UpdateSidebar") {
let tabId = sender.tab.id;
if (self.state.tabId == tabId) {
self.state.data = request.payload.data;
self.state.registry = request.payload.registry;
self.state.pane = "main";
self.setState(self.state);
}
}
}
);
}
onTabActivated(activeInfo: chrome.tabs.TabActiveInfo) {
......@@ -84,19 +101,6 @@ class Sidebar extends React.Component<{}, State> {
this.reloadTabData(activeInfo.tabId);
}
onTabUpdated(
tabId: number,
changeInfo: chrome.tabs.TabChangeInfo,
tab: chrome.tabs.Tab
) {
if (tabId != this.state.tabId) return;
if (!changeInfo.status) return;
if (changeInfo.status != "complete") return;
this.state.pane = "loading";
this.setState(this.state);
this.reloadTabData(this.state.tabId);
}
reloadTabData(tabId: number) {
Promise.all([getCurrentResource(tabId), getViewRegistry()]).then(
(values: [ResourceData, definition.ViewRegistry]) => {
......
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