|
| 1 | +<template> |
| 2 | + <v-container fluid class="protocol-driver-instances-tab"> |
| 3 | + |
| 4 | + <v-btn color="primary" class="mt-4" @click="openAddProtocolDriverInstanceDialog">{{ |
| 5 | + $t('admin.protocolDriverInstances.addProtocolDriverInstance') }} |
| 6 | + <v-icon>mdi-plus</v-icon> |
| 7 | + </v-btn> |
| 8 | + <v-data-table :headers="headers" :items="driverInstances" :items-per-page="5" class="elevation-1" |
| 9 | + :load-children="fetchDriverInstances" :items-per-page-text="$t('common.itemsPerPageText')"> |
| 10 | + <template #[`item.enabled`]="{ item }"> |
| 11 | + <v-icon v-if="item.enabled" color="green">mdi-check</v-icon> |
| 12 | + <v-icon v-else color="red">mdi-close</v-icon> |
| 13 | + </template> |
| 14 | + <template #[`item.actions`]="{ item }"> |
| 15 | + <v-icon size="small" class="me-2" @click="openEditProtocolDriverInstanceDialog(item)"> |
| 16 | + mdi-pencil |
| 17 | + </v-icon> |
| 18 | + <v-icon v-if="item.name !== 'admin'" size="small" @click="openDeleteProtocolDriverInstanceDialog(item)"> |
| 19 | + mdi-delete |
| 20 | + </v-icon> |
| 21 | + </template> |
| 22 | + </v-data-table> |
| 23 | + |
| 24 | + </v-container> |
| 25 | + |
| 26 | +</template> |
| 27 | +<script setup> |
| 28 | +import { ref, computed, onMounted, onUnmounted } from 'vue'; |
| 29 | +import { useI18n } from 'vue-i18n'; |
| 30 | +
|
| 31 | +const { t } = useI18n(); |
| 32 | +const headers = computed(() => [ |
| 33 | + { title: '#', key: 'id' }, |
| 34 | + { title: t('admin.protocolDriverInstances.headers.protocolDriver'), align: 'start', key: 'protocolDriver' }, |
| 35 | + { title: t('admin.protocolDriverInstances.headers.protocolDriverInstanceNumber'), key: 'protocolDriverInstanceNumber' }, |
| 36 | + { title: t('admin.protocolDriverInstances.headers.enabled'), key: 'enabled' }, |
| 37 | + { title: t('admin.protocolDriverInstances.headers.logLevel'), key: 'logLevel' }, |
| 38 | + { title: t('admin.protocolDriverInstances.headers.allowedNodesList'), key: 'nodesText' }, |
| 39 | + { title: t('admin.protocolDriverInstances.headers.actions'), key: 'actions', sortable: false }, |
| 40 | +]); |
| 41 | +
|
| 42 | +const dialogAddNode = ref(false); |
| 43 | +const dialogDelInst = ref(false); |
| 44 | +const active = ref([]); |
| 45 | +const newNode = ref(""); |
| 46 | +const nodeNames = ref([]); |
| 47 | +const driverNameItems = [ |
| 48 | + "IEC60870-5-104", |
| 49 | + "IEC60870-5-104_SERVER", |
| 50 | + "IEC60870-5-101", |
| 51 | + "IEC60870-5-101_SERVER", |
| 52 | + "IEC61850", |
| 53 | + "IEC61850_SERVER", |
| 54 | + "DNP3", |
| 55 | + "DNP3_SERVER", |
| 56 | + "MQTT-SPARKPLUG-B", |
| 57 | + "OPC-UA", |
| 58 | + "OPC-UA_SERVER", |
| 59 | + "OPC-DA", |
| 60 | + "OPC-DA_SERVER", |
| 61 | + "PLCTAG", |
| 62 | + "PLC4X", |
| 63 | + "TELEGRAF-LISTENER", |
| 64 | + "ICCP", |
| 65 | + "ICCP_SERVER", |
| 66 | + "I104M", |
| 67 | + "PI_DATA_ARCHIVE_INJECTOR", |
| 68 | + "PI_DATA_ARCHIVE_CLIENT", |
| 69 | +]; |
| 70 | +const driverInstances = ref([]); |
| 71 | +
|
| 72 | +const selected = computed(() => { |
| 73 | + if (!active.value.length) return undefined; |
| 74 | + return driverInstances.value.find((item) => item.id === active.value[0]); |
| 75 | +}); |
| 76 | +
|
| 77 | +onMounted(() => { |
| 78 | + fetchDriverInstances(); |
| 79 | + document.documentElement.style.overflowY = 'scroll'; |
| 80 | +}); |
| 81 | +
|
| 82 | +onUnmounted(() => { |
| 83 | + document.documentElement.style.overflowY = 'auto'; |
| 84 | +}); |
| 85 | +
|
| 86 | +async function fetchNodes() { |
| 87 | + try { |
| 88 | + const res = await fetch("/Invoke/auth/listNodes"); |
| 89 | + const json = await res.json(); |
| 90 | + nodeNames.value = json; |
| 91 | + } catch (err) { |
| 92 | + console.warn(err); |
| 93 | + } |
| 94 | +} |
| 95 | +
|
| 96 | +async function fetchDriverInstances() { |
| 97 | + await fetchNodes(); |
| 98 | + try { |
| 99 | + const res = await fetch("/Invoke/auth/listProtocolDriverInstances"); |
| 100 | + const json = await res.json(); |
| 101 | + json.forEach((item, index) => { |
| 102 | + item.id = index + 1; |
| 103 | + item.nodesText = item.nodeNames.join(', '); |
| 104 | + item.driverNameInstance = `${item.protocolDriver} ( ${item.protocolDriverInstanceNumber} )`; |
| 105 | + }); |
| 106 | + driverInstances.value = json; |
| 107 | + } catch (err) { |
| 108 | + console.warn(err); |
| 109 | + } |
| 110 | +} |
| 111 | +
|
| 112 | +async function deleteDriverInstance() { |
| 113 | + try { |
| 114 | + const res = await fetch("/Invoke/auth/deleteProtocolDriverInstance", { |
| 115 | + method: "post", |
| 116 | + headers: { |
| 117 | + Accept: "application/json", |
| 118 | + "Content-Type": "application/json", |
| 119 | + }, |
| 120 | + body: JSON.stringify({ |
| 121 | + protocolDriver: selected.value.protocolDriver, |
| 122 | + protocolDriverInstanceNumber: selected.value.protocolDriverInstanceNumber, |
| 123 | + _id: selected.value._id, |
| 124 | + }), |
| 125 | + }); |
| 126 | + const json = await res.json(); |
| 127 | + if (json.error) console.log(json); |
| 128 | + fetchDriverInstances(); // refreshes instances |
| 129 | + } catch (err) { |
| 130 | + console.warn(err); |
| 131 | + } |
| 132 | +} |
| 133 | +
|
| 134 | +async function createDriverInstance() { |
| 135 | + try { |
| 136 | + const res = await fetch("/Invoke/auth/createProtocolDriverInstance", { |
| 137 | + method: "post", |
| 138 | + headers: { |
| 139 | + Accept: "application/json", |
| 140 | + "Content-Type": "application/json", |
| 141 | + }, |
| 142 | + body: JSON.stringify({ |
| 143 | + protocolDriver: "IEC60870-5-104", // Default value, can be changed later |
| 144 | + protocolDriverInstanceNumber: 1, // Default value, can be changed later |
| 145 | + enabled: true, |
| 146 | + logLevel: "INFO", |
| 147 | + nodeNames: [], |
| 148 | + }), |
| 149 | + }); |
| 150 | + const json = await res.json(); |
| 151 | + if (json.error) console.log(json); |
| 152 | + fetchDriverInstances(); // Refresh instances |
| 153 | + } catch (err) { |
| 154 | + console.warn(err); |
| 155 | + } |
| 156 | +} |
| 157 | +
|
| 158 | +async function updateProtocolDriverInstance() { |
| 159 | + if (!selected.value) return; |
| 160 | + try { |
| 161 | + const res = await fetch("/Invoke/auth/updateProtocolDriverInstance", { |
| 162 | + method: "post", |
| 163 | + headers: { |
| 164 | + Accept: "application/json", |
| 165 | + "Content-Type": "application/json", |
| 166 | + }, |
| 167 | + body: JSON.stringify(selected.value), |
| 168 | + }); |
| 169 | + const json = await res.json(); |
| 170 | + if (json.error) console.log(json); |
| 171 | + fetchDriverInstances(); // Refresh instances |
| 172 | + } catch (err) { |
| 173 | + console.warn(err); |
| 174 | + } |
| 175 | +} |
| 176 | +
|
| 177 | +async function addNewNode() { |
| 178 | + if (!selected.value || !newNode.value) return; |
| 179 | + try { |
| 180 | + const updatedInstance = { |
| 181 | + ...selected.value, |
| 182 | + nodeNames: [...selected.value.nodeNames, newNode.value], |
| 183 | + }; |
| 184 | + const res = await fetch("/Invoke/auth/updateProtocolDriverInstance", { |
| 185 | + method: "post", |
| 186 | + headers: { |
| 187 | + Accept: "application/json", |
| 188 | + "Content-Type": "application/json", |
| 189 | + }, |
| 190 | + body: JSON.stringify(updatedInstance), |
| 191 | + }); |
| 192 | + const json = await res.json(); |
| 193 | + if (json.error) console.log(json); |
| 194 | + newNode.value = ""; // Clear the input |
| 195 | + fetchDriverInstances(); // Refresh instances |
| 196 | + } catch (err) { |
| 197 | + console.warn(err); |
| 198 | + } |
| 199 | +} |
| 200 | +
|
| 201 | +const openAddProtocolDriverInstanceDialog = () => { |
| 202 | + dialogAddNode.value = true; |
| 203 | +}; |
| 204 | +
|
| 205 | +const openEditProtocolDriverInstanceDialog = (item) => { |
| 206 | + selected.value = item; |
| 207 | + dialogAddNode.value = true; |
| 208 | +}; |
| 209 | +
|
| 210 | +</script> |
0 commit comments