Commit 75fcd9c7 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Fixed issue #2 - forced selection of a data source

parent 54b9dcfe1422
......@@ -374,5 +374,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
let data = getTabData(request.tabId);
data.updateWith(request.tabData);
updateTab(request.tabId);
sendResponse(data);
}
});
......@@ -21,7 +21,6 @@
import * as React from "react";
import { TabData, DataSource, NO_DATA } from "../common/data";
import "chrome";
import { stat } from "fs";
export class Menu extends React.Component {
state: TabData;
......@@ -30,6 +29,7 @@ export class Menu extends React.Component {
constructor(props: any) {
super(props);
this.state = new TabData();
this.onUpdate = this.onUpdate.bind(this);
this.onClickActivate = this.onClickActivate.bind(this);
this.onClickAutomatic = this.onClickAutomatic.bind(this);
this.onSelectSource = this.onSelectSource.bind(this);
......@@ -42,21 +42,34 @@ export class Menu extends React.Component {
chrome.runtime.sendMessage(
{ reqType: "GetTabData", tabId: tabs[0].id },
(response: TabData) => {
self.setState(response);
self.state.updateWith(response);
self.state.sources = self.state.sources.concat(response.sources);
self.state.mainSource = response.mainSource;
self.setState(self.state);
}
);
}
);
}
onUpdate() {
let self = this;
chrome.runtime.sendMessage(
{
reqType: "UpdateTabData",
tabId: this.tabId,
tabData: self.state
},
(response: TabData) => {
self.state.mainSource = response.mainSource;
self.setState(self.state);
}
);
}
onClickActivate(event: React.FormEvent<HTMLInputElement>) {
this.state.command.isActive = event.currentTarget.checked;
this.setState(this.state);
chrome.runtime.sendMessage({
reqType: "UpdateTabData",
tabId: this.tabId,
tabData: this.state
});
this.onUpdate();
}
onClickAutomatic(event: React.FormEvent<HTMLInputElement>) {
......@@ -65,12 +78,7 @@ export class Menu extends React.Component {
this.state.command.selectedSource = null;
this.state.command.selectedView == null;
}
this.setState(this.state);
chrome.runtime.sendMessage({
reqType: "UpdateTabData",
tabId: this.tabId,
tabData: this.state
});
this.onUpdate();
}
onSelectSource(event: React.FormEvent<HTMLSelectElement>) {
......@@ -79,12 +87,7 @@ export class Menu extends React.Component {
this.state.command.selectedSource = null;
this.state.command.selectedView == null;
}
this.setState(this.state);
chrome.runtime.sendMessage({
reqType: "UpdateTabData",
tabId: this.tabId,
tabData: this.state
});
this.onUpdate();
}
onSelectedView(event: React.FormEvent<HTMLSelectElement>) {}
......@@ -124,7 +127,10 @@ export class Menu extends React.Component {
</label>
</div>
</div>
<div className="row">
<div
className="row"
style={{ display: this.state.command.isAutomatic ? "none" : "block" }}
>
<div className="col-sm-4">
<label>Data source</label>
</div>
......@@ -133,7 +139,6 @@ export class Menu extends React.Component {
className="form-control"
id="fieldDataSource"
disabled={this.state.command.isAutomatic}
style={{ marginTop: "10pt;" }}
onChange={this.onSelectSource}
value={this.state.command.selectedSource}
>
......@@ -147,7 +152,25 @@ export class Menu extends React.Component {
</select>
</div>
</div>
<div className="row">
<div
className="row"
style={{ display: this.state.command.isAutomatic ? "block" : "none" }}
>
<div className="col-sm-4">
<label>Selected source</label>
</div>
<div className="col-sm-8">
<input
className="form-control"
readOnly={true}
value={this.state.mainSource.name}
/>
</div>
</div>
<div
className="row"
style={{ display: this.state.command.isAutomatic ? "none" : "block" }}
>
<div className="col-sm-4">
<label>View</label>
</div>
......@@ -156,7 +179,6 @@ export class Menu extends React.Component {
className="form-control"
id="fiedView"
disabled={this.state.command.isAutomatic}
style={{ marginTop: "10pt;" }}
onChange={this.onSelectedView}
value={this.state.command.selectedView}
/>
......
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