2022-02-06 23:02:20 +01:00
< script >
import Card from "../components/Card.svelte";
2022-02-07 23:40:00 +01:00
import Alarm from "../components/Alarm.svelte";
2022-02-06 23:02:20 +01:00
2022-02-07 16:36:43 +01:00
import CrossIcon from "../svg/Cross.svelte";
import OpenIcon from "../svg/Open.svelte";
2022-02-13 00:37:58 +01:00
export let show;
2022-02-06 23:02:20 +01:00
export let deviceList;
export let showInput;
2022-02-07 02:08:21 +01:00
export let newDevice = {} ;
2022-02-06 23:02:20 +01:00
2022-02-12 03:07:59 +01:00
export let addDevInList = () => {} ;
2022-02-07 16:36:43 +01:00
2022-02-15 00:02:30 +01:00
export let sendToAllDevices = (msg) => {} ;
2022-02-07 16:36:43 +01:00
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;
}
}
}
2022-02-06 23:02:20 +01:00
< / script >
2022-02-13 00:37:58 +01:00
{ #if show }
< div class = "grd-1col1" >
< Card title = { "Список устройств" } >
< table class = "tbl" >
< thead class = "bg-gray-100" >
2022-02-07 16:36:43 +01:00
< tr class = "txt-sz txt-pad" >
2022-02-13 00:37:58 +01:00
< th class = "tbl-hd" > Название устройства< / th >
< th class = "tbl-hd" > IP адрес< / th >
< th class = "tbl-hd" > Идентификатор< / th >
< th class = "tbl-hd" > Состояние< / th >
< th class = "tbl-hd w-7" / >
2022-02-07 02:08:21 +01:00
< / tr >
2022-02-13 00:37:58 +01:00
< / thead >
< tbody class = "bg-white" >
{ #each deviceList as device , i }
< 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 click = {() => deleteLineFromDevlist ( i )} / ></ td >
< / tr >
{ /each }
{ #if showInput }
< 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 >
< / table >
2022-02-15 00:02:30 +01:00
< button class = "btn-lg mb-2" on:click = {() => (( showInput = ! showInput ), addDevInList ())} > { showInput ? "Сохранить" : "Добавить устройство" } </button >
< button class = "btn-lg" on:click = {( msg ) => sendToAllDevices ( "/reboot|" )} > { "Перезагрузить все устройства" } </button >
2022-02-13 00:37:58 +01:00
< / Card >
< Alarm >
2022-02-16 00:11:57 +01:00
< p > Прошитые прошивкой IoT Manager устройства появятся в списке автоматически в течении минуты. Для обновления названий устройств нужно обновить страницу. Устройства должны быть подключены к одному wifi роутеру.< / p >
2022-02-13 00:37:58 +01:00
< / Alarm >
< / div >
{ : else }
< Alarm title = "Загрузка..." / >
{ /if }