список устройств

This commit is contained in:
Dmitry Borisenko
2022-02-07 16:36:43 +01:00
parent b426958f8a
commit ffd427c52a
11 changed files with 219 additions and 130 deletions

View File

@@ -1,20 +1,34 @@
<script>
import Card from "../components/Card.svelte";
import CrossIcon from "../svg/Cross.svelte";
import OpenIcon from "../svg/Open.svelte";
export let deviceList;
export let showInput;
export let newDevice = {};
export let devListSave = () => {};
export let deleteLineFromDevlist = (num) => {};
let debug = true;
function deleteLineFromDevlist(num) {
for (let i = 0; i < deviceList.length; i++) {
if (num === i) {
deviceList.splice(i, 1);
deviceList = deviceList;
if (debug) console.log("[i]", "item " + num + " deleted from dev list");
break;
}
}
}
</script>
<div class="grd-1cols">
<div class="grd-1col1">
<Card title={"Список устройств"}>
<table class="tbl">
<thead class="bg-gray-100">
<tr class="tbl-txt-sz tbl-txt-p">
<tr class="txt-sz txt-pad">
<th class="tbl-hd">Название устройства</th>
<th class="tbl-hd">IP адрес</th>
<th class="tbl-hd">Идентификатор</th>
@@ -24,20 +38,20 @@
</thead>
<tbody class="bg-white">
{#each deviceList as device, i}
<tr class="tbl-txt-sz tbl-txt-p">
<td class="tbl-bdy tbl-ipt w-full">{device.name}</td>
<td class="tbl-bdy tbl-ipt w-full"><a href={"http://" + device.ip}>{device.ip}</a></td>
<td class="tbl-bdy tbl-ipt w-full">{device.id}</td>
<td class="tbl-bdy tbl-ipt w-full {device.status ? 'bg-green-50' : 'bg-red-50'}">{device.status ? "online" : "offline"}</td>
<td class="tbl-bdy"><svg on:click={() => deleteLineFromDevlist(i)} class="h-6 w-6 text-red-400 cursor-pointer" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="18" y1="6" x2="6" y2="18" /> <line x1="6" y1="6" x2="18" y2="18" /></svg></td>
<tr class="txt-sz txt-pad">
<td class="tbl-bdy-lg ipt-lg w-full">{device.name}</td>
<td class="tbl-bdy-lg ipt-lg w-full"><a href={"http://" + device.ip}>{device.ip}</a></td>
<td class="tbl-bdy-lg ipt-lg w-full">{device.id}</td>
<td class="tbl-bdy-lg ipt-lg w-full {device.status ? 'bg-green-50' : 'bg-red-50'}">{device.status ? "online" : "offline"}</td>
<td class="tbl-bdy-lg"><CrossIcon i={i} click={(i) => deleteLineFromDevlist(i)} /></td>
</tr>
{/each}
{#if showInput}
<tr class="tbl-txt-sz tbl-txt-p">
<td class="tbl-bdy"><input bind:value={newDevice.name} class="tbl-ipt w-full" type="text" /></td>
<td class="tbl-bdy"><input bind:value={newDevice.ip} class="tbl-ipt w-full" type="text" /></td>
<td class="tbl-bdy"><input bind:value={newDevice.id} class="tbl-ipt w-full" type="text" /></td>
<td class="tbl-bdy" />
<tr class="txt-sz txt-pad">
<td class="tbl-bdy-lg"><input bind:value={newDevice.name} class="ipt-lg w-full" type="text" /></td>
<td class="tbl-bdy-lg"><input bind:value={newDevice.ip} class="ipt-lg w-full" type="text" /></td>
<td class="tbl-bdy-lg"><input bind:value={newDevice.id} class="ipt-lg w-full" type="text" /></td>
<td class="tbl-bdy-lg" />
</tr>
{/if}
</tbody>