Add connect defaults readonly flag, closes #10

This commit is contained in:
Ken-Håvard Lieng 2018-04-15 01:02:28 +02:00
parent fcd204321a
commit 39641c315f
6 changed files with 96 additions and 72 deletions

File diff suppressed because one or more lines are too long

View File

@ -219,8 +219,18 @@ i[class*=' icon-']:before {
} }
.connect-form h1 { .connect-form h1 {
margin-bottom: 15px;
text-align: center; text-align: center;
margin-bottom: 15px;
}
.connect-details {
color: #999;
text-align: center;
margin-bottom: 15px;
}
.connect-details h2 {
color: #6bb758;
} }
.connect-form input { .connect-form input {

View File

@ -8,27 +8,32 @@ export default class Connect extends Component {
}; };
handleSubmit = e => { handleSubmit = e => {
const { connect, select, join } = this.props; const { connect, select, join, defaults } = this.props;
e.preventDefault(); e.preventDefault();
let address = e.target.address.value.trim();
const nick = e.target.nick.value.trim(); const nick = e.target.nick.value.trim();
const channels = e.target.channels.value let { address, channels } = defaults;
.split(',')
.map(s => s.trim())
.filter(s => s);
const opts = { const opts = {
name: e.target.name.value.trim(), name: defaults.name
tls: e.target.ssl.checked
}; };
if (this.state.showOptionals) { if (!defaults.readonly) {
opts.realname = e.target.realname.value.trim(); address = e.target.address.value.trim();
opts.username = e.target.username.value.trim(); channels = e.target.channels.value
.split(',')
.map(s => s.trim())
.filter(s => s);
opts.name = e.target.name.value.trim();
opts.tls = e.target.ssl.checked;
if (this.state.passwordTouched) { if (this.state.showOptionals) {
opts.password = e.target.password.value.trim(); opts.realname = e.target.realname.value.trim();
opts.username = e.target.username.value.trim();
if (this.state.passwordTouched) {
opts.password = e.target.password.value.trim();
}
} }
} }
@ -76,9 +81,24 @@ export default class Connect extends Component {
); );
} }
return ( let form;
<div className="connect">
<Navicon /> if (defaults.readonly) {
form = (
<form className="connect-form" onSubmit={this.handleSubmit}>
<h1>Connect</h1>
{defaults.showDetails && (
<div className="connect-details">
<h2>{defaults.address}</h2>
{defaults.channels.sort().map(channel => <p>{channel}</p>)}
</div>
)}
<input name="nick" type="text" placeholder="Nick" />
<input type="submit" value="Connect" />
</form>
);
} else {
form = (
<form className="connect-form" onSubmit={this.handleSubmit}> <form className="connect-form" onSubmit={this.handleSubmit}>
<h1>Connect</h1> <h1>Connect</h1>
<input <input
@ -111,6 +131,13 @@ export default class Connect extends Component {
</p> </p>
<input type="submit" value="Connect" /> <input type="submit" value="Connect" />
</form> </form>
);
}
return (
<div className="connect">
<Navicon />
{form}
</div> </div>
); );
} }

View File

@ -14,7 +14,9 @@ const ConnectDefaults = Record({
address: '', address: '',
channels: [], channels: [],
ssl: false, ssl: false,
password: false password: false,
readonly: false,
showDetails: false
}); });
const App = Record({ const App = Record({

View File

@ -11,6 +11,10 @@ channels = [
] ]
password = "" password = ""
ssl = true ssl = true
# Only allow a nick to be filled in
readonly = false
# Show server and channel info when readonly is enabled
show_details = false
[https] [https]
enabled = false enabled = false

View File

@ -11,11 +11,13 @@ import (
) )
type connectDefaults struct { type connectDefaults struct {
Name string `json:"name"` Name string `json:"name"`
Address string `json:"address"` Address string `json:"address"`
Channels []string `json:"channels"` Channels []string `json:"channels"`
Password bool `json:"password"` Password bool `json:"password,omitempty"`
SSL bool `json:"ssl"` SSL bool `json:"ssl,omitempty"`
ReadOnly bool `json:"readonly,omitempty"`
ShowDetails bool `json:"showDetails,omitempty"`
} }
type indexData struct { type indexData struct {
@ -78,11 +80,13 @@ func getIndexData(r *http.Request, session *Session) *indexData {
data.Channels = channels data.Channels = channels
data.Defaults = connectDefaults{ data.Defaults = connectDefaults{
Name: viper.GetString("defaults.name"), Name: viper.GetString("defaults.name"),
Address: viper.GetString("defaults.address"), Address: viper.GetString("defaults.address"),
Channels: viper.GetStringSlice("defaults.channels"), Channels: viper.GetStringSlice("defaults.channels"),
Password: viper.GetString("defaults.password") != "", Password: viper.GetString("defaults.password") != "",
SSL: viper.GetBool("defaults.ssl"), SSL: viper.GetBool("defaults.ssl"),
ReadOnly: viper.GetBool("defaults.readonly"),
ShowDetails: viper.GetBool("defaults.show_details"),
} }
server, channel := getTabFromPath(r.URL.EscapedPath()) server, channel := getTabFromPath(r.URL.EscapedPath())