-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Modbus configuration and info views. Signed-off-by: Bobby Noelte <[email protected]>
- Loading branch information
Showing
9 changed files
with
251 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface ModbusConfig { | ||
modbus_enabled: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface ModbusStatus { | ||
modbus_enabled: boolean; | ||
modbus_hostname: string; | ||
modbus_port: number; | ||
modbus_ip: string; | ||
modbus_id_dtupro: number; | ||
modbus_id_total: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<template> | ||
<BasePage :title="$t('modbusadmin.ModbusSettings')" :isLoading="dataLoading"> | ||
<BootstrapAlert v-model="showAlert" dismissible :variant="alertType"> | ||
{{ alertMessage }} | ||
</BootstrapAlert> | ||
|
||
<form @submit="saveModbusConfig"> | ||
<CardElement :text="$t('modbusadmin.ModbusConfiguration')" textVariant="text-bg-primary"> | ||
<InputElement :label="$t('modbusadmin.EnableModbus')" | ||
v-model="modbusConfigList.modbus_enabled" | ||
type="checkbox" wide/> | ||
|
||
</CardElement> | ||
|
||
<FormFooter @reload="getModbusConfig"/> | ||
</form> | ||
</BasePage> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import BasePage from '@/components/BasePage.vue'; | ||
import BootstrapAlert from "@/components/BootstrapAlert.vue"; | ||
import CardElement from '@/components/CardElement.vue'; | ||
import FormFooter from '@/components/FormFooter.vue'; | ||
import InputElement from '@/components/InputElement.vue'; | ||
import type { ModbusConfig } from "@/types/ModbusConfig"; | ||
import { authHeader, handleResponse } from '@/utils/authentication'; | ||
import { defineComponent } from 'vue'; | ||
export default defineComponent({ | ||
components: { | ||
BasePage, | ||
BootstrapAlert, | ||
CardElement, | ||
FormFooter, | ||
InputElement, | ||
}, | ||
data() { | ||
return { | ||
dataLoading: true, | ||
modbusConfigList: {} as ModbusConfig, | ||
alertMessage: "", | ||
alertType: "info", | ||
showAlert: false, | ||
qosTypeList: [ | ||
{ key: 0, value: 'QOS0' }, | ||
{ key: 1, value: 'QOS1' }, | ||
{ key: 2, value: 'QOS2' }, | ||
], | ||
}; | ||
}, | ||
created() { | ||
this.getModbusConfig(); | ||
}, | ||
methods: { | ||
getModbusConfig() { | ||
this.dataLoading = true; | ||
fetch("/api/modbus/config", { headers: authHeader() }) | ||
.then((response) => handleResponse(response, this.$emitter, this.$router)) | ||
.then((data) => { | ||
this.modbusConfigList = data; | ||
this.dataLoading = false; | ||
}); | ||
}, | ||
saveModbusConfig(e: Event) { | ||
e.preventDefault(); | ||
const formData = new FormData(); | ||
formData.append("data", JSON.stringify(this.modbusConfigList)); | ||
fetch("/api/modbus/config", { | ||
method: "POST", | ||
headers: authHeader(), | ||
body: formData, | ||
}) | ||
.then((response) => handleResponse(response, this.$emitter, this.$router)) | ||
.then( | ||
(response) => { | ||
this.alertMessage = this.$t('apiresponse.' + response.code, response.param); | ||
this.alertType = response.type; | ||
this.showAlert = true; | ||
} | ||
); | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<template> | ||
<BasePage :title="$t('modbusinfo.ModbusInformation')" :isLoading="dataLoading" :show-reload="true" @reload="getModbusInfo"> | ||
<CardElement :text="$t('modbusinfo.ConfigurationSummary')" textVariant="text-bg-primary"> | ||
<div class="table-responsive"> | ||
<table class="table table-hover table-condensed"> | ||
<tbody> | ||
<tr> | ||
<th>{{ $t('modbusinfo.Status') }}</th> | ||
<td> | ||
<StatusBadge :status="modbusDataList.modbus_enabled" true_text="modbusinfo.Enabled" false_text="modbusinfo.Disabled" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t('modbusinfo.Server') }}</th> | ||
<td>{{ modbusDataList.modbus_hostname }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t('modbusinfo.IpAddress') }}</th> | ||
<td>{{ modbusDataList.modbus_ip }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t('modbusinfo.Port') }}</th> | ||
<td>{{ modbusDataList.modbus_port }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t('modbusinfo.IDDTUPro') }}</th> | ||
<td>{{ modbusDataList.modbus_id_dtupro }}</td> | ||
</tr> | ||
<tr> | ||
<th>{{ $t('modbusinfo.IDTotal') }}</th> | ||
<td>{{ modbusDataList.modbus_id_total }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</CardElement> | ||
|
||
</BasePage> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import BasePage from '@/components/BasePage.vue'; | ||
import CardElement from '@/components/CardElement.vue'; | ||
import StatusBadge from '@/components/StatusBadge.vue'; | ||
import type { ModbusStatus } from '@/types/ModbusStatus'; | ||
import { authHeader, handleResponse } from '@/utils/authentication'; | ||
import { defineComponent } from 'vue'; | ||
export default defineComponent({ | ||
components: { | ||
BasePage, | ||
CardElement, | ||
StatusBadge | ||
}, | ||
data() { | ||
return { | ||
dataLoading: true, | ||
modbusDataList: {} as ModbusStatus, | ||
}; | ||
}, | ||
created() { | ||
this.getModbusInfo(); | ||
}, | ||
methods: { | ||
getModbusInfo() { | ||
this.dataLoading = true; | ||
fetch("/api/modbus/status", { headers: authHeader() }) | ||
.then((response) => handleResponse(response, this.$emitter, this.$router)) | ||
.then((data) => { | ||
this.modbusDataList = data; | ||
this.dataLoading = false; | ||
}); | ||
}, | ||
}, | ||
}); | ||
</script> |