Skip to content

Commit 527c4c8

Browse files
cmotelettkurki
authored andcommitted
feature: auto reload page when unit changed (#101)
1 parent 15536e3 commit 527c4c8

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

dist/help/help.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
padding-left: 0;
3030
}
3131
</style>
32-
<a id="menu"></a>
3332
#### Help and Instructions
3433
___
3534
+ [0. Introduction](#0)
@@ -90,7 +89,7 @@ The button's text changes to _Connecting_ indicate the connection status
9089
and once connected disappears. In most cases you won't see the _Connecting_ text at all.
9190

9291
If the _Connecting_ button reappears, it means that the connection
93-
to the Signal K server is broken and that instrumentpanel
92+
to the Signal K server is broken and that InstrumentPanel
9493
is trying to reconnect automatically.
9594

9695
For advanced users, you can manually specify the address and
@@ -249,7 +248,8 @@ Select your preferred unit from the listbox.
249248
>
250249
>![unit](./dist/help/widget-settingUnit.png#maxwidth)
251250
>
252-
To make the unit change active, please disconnect and reconnect or reload the page.
251+
To make the unit change active, InstrumentPanel must be reloaded. This will be done automatically when you leave settings tab.
252+
You will be informed by a message at the top of the screen.
253253

254254
<a id="2_3_4"></a>
255255
**2.3.4. Widget Specific Settings** [Back to menu](#menu)

lib/ui/instrumentpanel.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default function InstrumentPanel(streamBundle) {
6464
this.gridSettingsModel = new BaconModel.Model("");
6565
this.pushGridChanges();
6666
this.handleSaveLayoutDelay = null;
67+
this.reloadRequired = false;
6768
var isUnkownKey = function(key) {
6869
return typeof this.getCurrentPage().knownKeys[key.key] === 'undefined';
6970
}.bind(this)
@@ -96,6 +97,14 @@ export default function InstrumentPanel(streamBundle) {
9697

9798
}
9899

100+
InstrumentPanel.prototype.setReloadRequired = function() {
101+
this.reloadRequired = true;
102+
}
103+
104+
InstrumentPanel.prototype.isReloadRequired = function() {
105+
return this.reloadRequired;
106+
}
107+
99108
InstrumentPanel.prototype.setPage = function(page) {
100109
if (page > this.pages.length || page < notificationPageId) {
101110
console.error("No such page:" + page);

lib/ui/navbar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class IpNavBar extends React.Component {
6161

6262
return (
6363
<nav className="navbar navbar-default" style={{marginBottom: '0px'}}>
64+
<a id="menu"></a>
6465
<form className="navbar-form navbar-left" style={navBarStyles}>
6566
{buttons}
6667
<div className="btn-group btn navbar-btn pull-right" style={Object.assign({}, buttonStyle, {cursor: 'default'})}>
@@ -193,9 +194,14 @@ export default class IpNavBar extends React.Component {
193194
}
194195

195196
toggleSettingsVisible() {
196-
this.props.model.lens("settingsVisible")
197-
.set(!this.props.model.get().settingsVisible);
198-
this.props.instrumentPanel.sortNotificationLayout();
197+
if ((this.props.model.get().settingsVisible) &&
198+
(this.props.instrumentPanel.isReloadRequired())) {
199+
location.reload();
200+
} else {
201+
this.props.model.lens("settingsVisible")
202+
.set(!this.props.model.get().settingsVisible);
203+
this.props.instrumentPanel.sortNotificationLayout();
204+
}
199205
}
200206

201207
setPage(page) {

lib/ui/settings/settingspanel.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { ButtonGroup, Button, TabPane, Tabs, Tab } from 'react-bootstrap';
3+
import { ButtonGroup, Button, TabPane, Tabs, Tab, Alert } from 'react-bootstrap';
44

55
import GridJson from './gridjson';
66
import InstrumentPanel from '../instrumentpanel';
@@ -26,6 +26,9 @@ export default class SettingsPanel extends React.Component {
2626
marginTop: '4px'
2727
};
2828

29+
var reloadMessage =
30+
(<Alert bsStyle="warning"><strong>Reload is required</strong> This will be done when you leave settings tab.</Alert>);
31+
2932
return (
3033
<div>
3134
<ButtonGroup className="pull-right" style={buttonStyle}>
@@ -38,6 +41,7 @@ export default class SettingsPanel extends React.Component {
3841
<Tabs id={1} activeKey={this.state.activeKey}
3942
onSelect={this.handleSelect}>
4043
<Tab eventKey={1} title="By Display Widget">
44+
{(this.props.instrumentPanel.isReloadRequired())? reloadMessage : undefined}
4145
<WidgetList instrumentPanel={this.props.instrumentPanel}/>
4246
</Tab>
4347
<Tab eventKey={3} title="Grid as JSON">

lib/ui/widgets/digitaldatetime.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ DigitalDateTime.prototype.getSettingsElement = function() {
177177
that.options.convertTo = event.target.value === that.options.unit ? undefined : event.target.value;
178178
that.instrumentPanel.persist();
179179
that.instrumentPanel.pushGridChanges();
180+
that.instrumentPanel.setReloadRequired();
180181
}
181182
});
182183
}

lib/ui/widgets/specifictext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ SpecificText.prototype.getSettingsElement = function() {
104104
that.options.convertTo = event.target.value === that.options.unit ? undefined : event.target.value;
105105
that.instrumentPanel.persist();
106106
that.instrumentPanel.pushGridChanges();
107+
that.instrumentPanel.setReloadRequired();
107108
}
108109
});
109110
}

lib/ui/widgets/universal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Widget.prototype.getSettingsElement = function() {
137137
that.options.convertTo = event.target.value === that.options.unit ? undefined : event.target.value;
138138
that.instrumentPanel.persist();
139139
that.instrumentPanel.pushGridChanges();
140+
that.instrumentPanel.setReloadRequired();
140141
}
141142
});
142143
}

lib/ui/widgets/windmeter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ WindMeter.prototype.getSettingsElement = function() {
391391
that.options.convertTo = event.target.value ==='m/s' ? undefined : event.target.value;
392392
that.instrumentPanel.persist();
393393
that.instrumentPanel.pushGridChanges();
394+
that.instrumentPanel.setReloadRequired();
394395
}
395396
});
396397
}

0 commit comments

Comments
 (0)