Commit 812d5390 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[feature] Implementing the side bar

parent f2a7a32880e9
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
"page": "options/index.html", "page": "options/index.html",
"browser_style": true "browser_style": true
}, },
"sidebar_action": {
"default_title": "Linked Data Browser",
"default_panel": "sidebar/index.html",
"default_icon": "icons/app.png"
},
"web_accessible_resources": ["ldviews/*", "ldbrowser/*", "popup/*"], "web_accessible_resources": ["ldviews/*", "ldbrowser/*", "popup/*"],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
} }
/*******************************************************************************
* 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 ReactDOM = require("react-dom");
import { definition } from "@logilab/libview";
import { getViewRegistry, getCurrentResource } from "../common/messages";
import { ResourceData } from "../common/data";
import { ConfigLoading } from "../common/config/ConfigLoading";
/**
* Gets the identifier of the currently active tab
*/
function getCurrentTabId(): Promise<number> {
return new Promise<number>(
(resolve: (tabId: number) => void, reject: (reason: any) => void) => {
chrome.tabs.query(
{ active: true, currentWindow: true },
(tabs: chrome.tabs.Tab[]) => {
let tabId = tabs[0].id;
resolve(tabId);
}
);
}
);
}
interface State {
pane: string;
tabId: number;
data: ResourceData;
registry: definition.ViewRegistry;
}
class Sidebar extends React.Component<{}, State> {
state: State;
constructor(props: any) {
super(props);
this.state = {
pane: "loading",
tabId: -1,
data: null,
registry: null
};
let self = this;
let loadForTab = (tabId: number) => {
self.state.tabId = tabId;
Promise.all([getCurrentResource(tabId), getViewRegistry()]).then(
(values: [ResourceData, definition.ViewRegistry]) => {
self.state.data = values[0];
self.state.registry = values[1];
self.state.pane = "menu";
self.setState(self.state);
}
);
};
// load for the current tab
getCurrentTabId().then(loadForTab);
// listen for change of the current tab
chrome.tabs.onActivated.addListener(
(activeInfo: chrome.tabs.TabActiveInfo) => {
this.state.pane = "loading";
self.setState(self.state);
loadForTab(activeInfo.tabId);
}
);
}
render() {
if (this.state.pane == "loading") {
return <ConfigLoading />;
} else {
return <span>{this.state.tabId}</span>;
}
}
}
ReactDOM.render(<Sidebar />, document.getElementById("root"));
...@@ -212,5 +212,47 @@ module.exports = [ ...@@ -212,5 +212,47 @@ module.exports = [
{} {}
) )
] ]
},
{
entry: "./src/sidebar/main.tsx",
mode: isProd ? "production" : "development",
output: {
path: path.join(__dirname, "build/"),
publicPath: path.join(__dirname, "build/sidebar/"),
filename: "sidebar/main.js"
},
externals: {
chrome: "chrome"
},
devtool: "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
plugins: [
new CopyWebpackPlugin(
[
{
from: "src/common/config/index.html",
to: "sidebar/index.html"
},
{ from: "src/common/config/main.css", to: "sidebar/main.css" },
{
from: "node_modules/bootstrap/dist/css/bootstrap.min.css",
to: "sidebar/bootstrap.min.css"
},
{
from: "node_modules/bootstrap/dist/js/bootstrap.min.js",
to: "sidebar/bootstrap.min.js"
}
],
{}
)
]
} }
]; ];
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