mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 13:23:04 +01:00
Moved notification settings to DB
This commit is contained in:
@@ -225,8 +225,7 @@ export default class HistoryGraph extends Component {
|
||||
getData = (days = this.state.days) => {
|
||||
Axios.get('api/settings/config')
|
||||
.then((resp) => {
|
||||
var data = resp.data;
|
||||
console.log(data)
|
||||
var data = resp.data.graphs;
|
||||
this.setState({
|
||||
graph_ul_dl_enabled: Boolean(Number(data.download_upload_graph_enabled.value)),
|
||||
graph_ul_dl_width: data.download_upload_graph_width.value,
|
||||
@@ -274,11 +273,6 @@ export default class HistoryGraph extends Component {
|
||||
var failOptions = this.state.failOptions;
|
||||
var days = this.state.days;
|
||||
|
||||
console.log(failData);
|
||||
console.log(failOptions);
|
||||
console.log(pingData);
|
||||
console.log(pingOptions);
|
||||
|
||||
var graph_ul_dl_enabled = this.state.graph_ul_dl_enabled;
|
||||
var graph_ul_dl_width = this.state.graph_ul_dl_width;
|
||||
var graph_ping_enabled = this.state.graph_ping_enabled;
|
||||
|
||||
129
resources/js/components/Home/SettingWithModal.js
vendored
129
resources/js/components/Home/SettingWithModal.js
vendored
@@ -12,7 +12,8 @@ export default class SettingWithModal extends Component {
|
||||
title: this.props.title,
|
||||
description: this.props.description,
|
||||
settings: this.props.settings,
|
||||
show: false
|
||||
show: false,
|
||||
autoClose: this.props.autoClose
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +41,9 @@ export default class SettingWithModal extends Component {
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(this.state.title + ' updated');
|
||||
this.toggleShow();
|
||||
if(this.state.autoClose) {
|
||||
this.toggleShow();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
@@ -111,51 +114,135 @@ export default class SettingWithModal extends Component {
|
||||
var name = e.obj.name.split('_');
|
||||
name[0] = this.ucfirst(name[0]);
|
||||
name = name.join(' ');
|
||||
|
||||
if(e.obj.description == null) {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 12 };
|
||||
} else {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 6 };
|
||||
}
|
||||
|
||||
var readonly = false;
|
||||
if(window.config.editable[e.obj.name] == false) {
|
||||
readonly = true;
|
||||
}
|
||||
|
||||
if(e.type == 'checkbox') {
|
||||
return (
|
||||
<Row key={e.obj.id} className="d-flex align-items-center">
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Check type="checkbox" label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Check type="checkbox" disabled label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Check type="checkbox" label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'number') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
<Form.Control type="number" min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="number" disabled min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="number" min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<p>{e.obj.description}</p>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'text') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="text" disabled defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="text" defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'select') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
<Form.Control as="select" defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control as="select" disabled defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control as="select" defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
<Col md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<p>{e.obj.description}</p>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'button-get') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{name}</p>
|
||||
<Button onClick={() => { Axios.get(e.url) }} >{name}</Button>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
|
||||
25
resources/js/components/Home/Settings.js
vendored
25
resources/js/components/Home/Settings.js
vendored
@@ -61,7 +61,7 @@ export default class Settings extends Component {
|
||||
<Setting name={e.server.name} value={e.server.value} description={e.server.description} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Graph settings" description="Control settings for the graphs." settings={[
|
||||
<SettingWithModal title="Graph settings" description="Control settings for the graphs." autoClose={true} settings={[
|
||||
{
|
||||
obj: e.download_upload_graph_enabled,
|
||||
type: 'checkbox'
|
||||
@@ -119,7 +119,28 @@ export default class Settings extends Component {
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Notification settings" description="Control which types of notifications the server sends." settings={[
|
||||
<SettingWithModal title="Notification settings" description="Control which types of notifications the server sends." autoClose={false} settings={[
|
||||
{
|
||||
obj: e.slack_webhook,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_bot_token,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_chat_id,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test notifications",
|
||||
description: "After saving your updated notification settings, use this to check your settings are correct."
|
||||
},
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-notification'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_notifications,
|
||||
type: 'checkbox'
|
||||
|
||||
Reference in New Issue
Block a user