diff --git a/backend/internal/web/public/assets/index.js b/backend/internal/web/public/assets/index.js index 9bfe348..f2a40a3 100644 --- a/backend/internal/web/public/assets/index.js +++ b/backend/internal/web/public/assets/index.js @@ -1 +1 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const s of n)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function l(n){const s={};return n.integrity&&(s.integrity=n.integrity),n.referrerPolicy&&(s.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?s.credentials="include":n.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function i(n){if(n.ep)return;n.ep=!0;const s=l(n);fetch(n.href,s)}})();const pe=!1,$e=(e,t)=>e===t,we=Symbol("solid-track"),B={equals:$e};let te=re;const E=1,M=2,le={owned:null,cleanups:null,context:null,owner:null};var d=null;let F=null,ye=null,h=null,g=null,A=null,R=0;function P(e,t){const l=h,i=d,n=e.length===0,s=t===void 0?i:t,o=n?le:{owned:null,cleanups:null,context:s?s.context:null,owner:s},r=n?e:()=>e(()=>T(()=>N(o)));d=o,h=null;try{return O(r,!0)}finally{h=l,d=i}}function ie(e,t){t=t?Object.assign({},B,t):B;const l={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},i=n=>(typeof n=="function"&&(n=n(l.value)),se(l,n));return[ne.bind(l),i]}function V(e,t,l){const i=q(e,t,!1,E);D(i)}function me(e,t,l){te=ve;const i=q(e,t,!1,E);i.user=!0,A?A.push(i):D(i)}function Se(e,t,l){l=l?Object.assign({},B,l):B;const i=q(e,t,!0,0);return i.observers=null,i.observerSlots=null,i.comparator=l.equals||void 0,D(i),ne.bind(i)}function T(e){if(h===null)return e();const t=h;h=null;try{return e()}finally{h=t}}function _e(e){me(()=>T(e))}function xe(e){return d===null||(d.cleanups===null?d.cleanups=[e]:d.cleanups.push(e)),e}function ne(){if(this.sources&&this.state)if(this.state===E)D(this);else{const e=g;g=null,O(()=>U(this),!1),g=e}if(h){const e=this.observers?this.observers.length:0;h.sources?(h.sources.push(this),h.sourceSlots.push(e)):(h.sources=[this],h.sourceSlots=[e]),this.observers?(this.observers.push(h),this.observerSlots.push(h.sources.length-1)):(this.observers=[h],this.observerSlots=[h.sources.length-1])}return this.value}function se(e,t,l){let i=e.value;return(!e.comparator||!e.comparator(i,t))&&(e.value=t,e.observers&&e.observers.length&&O(()=>{for(let n=0;n1e6)throw g=[],new Error},!1)),t}function D(e){if(!e.fn)return;N(e);const t=R;Ce(e,e.value,t)}function Ce(e,t,l){let i;const n=d,s=h;h=d=e;try{i=e.fn(t)}catch(o){return e.pure&&(e.state=E,e.owned&&e.owned.forEach(N),e.owned=null),e.updatedAt=l+1,ce(o)}finally{h=s,d=n}(!e.updatedAt||e.updatedAt<=l)&&(e.updatedAt!=null&&"observers"in e?se(e,i):e.value=i,e.updatedAt=l)}function q(e,t,l,i=E,n){const s={fn:e,state:i,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:d,context:d?d.context:null,pure:l};return d===null||d!==le&&(d.owned?d.owned.push(s):d.owned=[s]),s}function H(e){if(e.state===0)return;if(e.state===M)return U(e);if(e.suspense&&T(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt=0;l--)if(e=t[l],e.state===E)D(e);else if(e.state===M){const i=g;g=null,O(()=>U(e,t[0]),!1),g=i}}function O(e,t){if(g)return e();let l=!1;t||(g=[]),A?l=!0:A=[],R++;try{const i=e();return Ae(l),i}catch(i){l||(A=null),g=null,ce(i)}}function Ae(e){if(g&&(re(g),g=null),e)return;const t=A;A=null,t.length&&O(()=>te(t),!1)}function re(e){for(let t=0;t=0;t--)N(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)N(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function Ee(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function ce(e,t=d){throw Ee(e)}const ke=Symbol("fallback");function Z(e){for(let t=0;t1?[]:null;return xe(()=>Z(s)),()=>{let f=e()||[],a=f.length,u,c;return f[we],T(()=>{let b,p,S,x,C,w,$,y,v;if(a===0)o!==0&&(Z(s),s=[],i=[],n=[],o=0,r&&(r=[])),l.fallback&&(i=[ke],n[0]=P(L=>(s[0]=L,l.fallback())),o=1);else if(o===0){for(n=new Array(a),c=0;c=w&&y>=w&&i[$]===f[y];$--,y--)S[y]=n[$],x[y]=s[$],r&&(C[y]=r[$]);for(b=new Map,p=new Array(y+1),c=y;c>=w;c--)v=f[c],u=b.get(v),p[c]=u===void 0?-1:u,b.set(v,c);for(u=w;u<=$;u++)v=i[u],c=b.get(v),c!==void 0&&c!==-1?(S[c]=n[u],x[c]=s[u],r&&(C[c]=r[u]),c=p[c],b.set(v,c)):s[u]();for(c=w;ce(t||{}))}function Te(e){const t="fallback"in e&&{fallback:()=>e.fallback};return Se(Ne(()=>e.each,e.children,t||void 0))}function De(e,t,l){let i=l.length,n=t.length,s=i,o=0,r=0,f=t[n-1].nextSibling,a=null;for(;ou-r){const p=t[o];for(;r{n=s,t===document?e():_(t,e(),t.firstChild?null:void 0,l)},i.owner),()=>{n(),t.textContent=""}}function I(e,t,l,i){let n;const s=()=>{const r=document.createElement("template");return r.innerHTML=e,r.content.firstChild},o=()=>(n||(n=s())).cloneNode(!0);return o.cloneNode=o,o}function Ie(e,t=window.document){const l=t[z]||(t[z]=new Set);for(let i=0,n=e.length;iK(e,t(),n,l),i)}function Pe(e){let t=e.target;const l=`$$${e.type}`,i=e.target,n=e.currentTarget,s=f=>Object.defineProperty(e,"target",{configurable:!0,value:f}),o=()=>{const f=t[l];if(f&&!t.disabled){const a=t[`${l}Data`];if(a!==void 0?f.call(t,a,e):f.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&s(t.host),!0},r=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),e.composedPath){const f=e.composedPath();s(f[0]);for(let a=0;a{let r=t();for(;typeof r=="function";)r=r();l=K(e,r,l,i)}),()=>l;if(Array.isArray(t)){const r=[],f=l&&Array.isArray(l);if(G(r,t,l,n))return V(()=>l=K(e,r,l,i,!0)),()=>l;if(r.length===0){if(l=k(e,l,i),o)return l}else f?l.length===0?ee(e,r,i):De(e,l,r):(l&&k(e),ee(e,r));l=r}else if(t.nodeType){if(Array.isArray(l)){if(o)return l=k(e,l,i,t);k(e,l,null,t)}else l==null||l===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);l=t}}return l}function G(e,t,l,i){let n=!1;for(let s=0,o=t.length;s=0;o--){const r=t[o];if(n!==r){const f=r.parentNode===e;!s&&!o?f?e.replaceChild(n,r):e.insertBefore(n,l):f&&r.remove()}else s=!0}}else e.insertBefore(n,l);return[n]}const[Be,Me]=ie([]),He="",Ue=async()=>{const e=He+"/api/all";return await(await fetch(e)).json()};var je=I(''),Ke=I(''),Re=I('.
');function Fe(e){const t="http://"+e.host.IP;let l=je();e.host.Now==1&&(l=Ke());let i=!1;return e.host.Known==1&&(i=!0),(()=>{var n=Re(),s=n.firstChild,o=s.firstChild,r=s.nextSibling,f=r.nextSibling,a=f.nextSibling,u=a.firstChild,c=a.nextSibling,m=c.nextSibling,b=m.nextSibling,p=b.nextSibling,S=p.firstChild,x=S.firstChild,C=p.nextSibling;return _(s,()=>e.index,o),_(r,()=>e.host.Name),_(f,()=>e.host.Iface),Le(u,"href",t),_(u,()=>e.host.IP),_(c,()=>e.host.Mac),_(m,()=>e.host.Hw),_(b,()=>e.host.Date),x.checked=i,_(C,l),n})()}var Ve=I('
Header
');function Ge(){const e=t=>{console.log("SORT BY",t)};return _e(async()=>{Me(await Ue())}),(()=>{var t=Ve(),l=t.firstChild,i=l.nextSibling,n=i.firstChild,s=n.firstChild,o=s.firstChild,r=o.firstChild,f=r.nextSibling,a=f.firstChild,u=a.nextSibling,c=f.nextSibling,m=c.firstChild,b=m.nextSibling,p=c.nextSibling,S=p.firstChild,x=S.nextSibling,C=p.nextSibling,w=C.firstChild,$=w.nextSibling,y=C.nextSibling,v=y.firstChild,L=v.nextSibling,Q=y.nextSibling,fe=Q.firstChild,W=fe.nextSibling,X=Q.nextSibling,ae=X.firstChild,Y=ae.nextSibling,ue=X.nextSibling,he=ue.firstChild,J=he.nextSibling,de=s.nextSibling;return u.$$click=e,u.$$clickData="Name",b.$$click=e,b.$$clickData="Iface",x.$$click=e,x.$$clickData="IP",$.$$click=e,$.$$clickData="Mac",L.$$click=e,L.$$clickData="Hw",W.$$click=e,W.$$clickData="Date",Y.$$click=e,Y.$$clickData="Known",J.$$click=e,J.$$clickData="Now",_(de,j(Te,{get each(){return Be()},children:(be,ge)=>j(Fe,{host:be,index:ge})})),t})()}Ie(["click"]);var qe=I('
');function Qe(){return(()=>{var e=qe(),t=e.firstChild,l=t.firstChild;return _(l,j(Ge,{})),e})()}const We=document.getElementById("root");Oe(()=>j(Qe,{}),We); +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))l(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&l(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function l(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();const Se=!1,_e=(e,t)=>e===t,xe=Symbol("solid-track"),U={equals:_e};let ce=de;const I=1,F=2,fe={owned:null,cleanups:null,context:null,owner:null};var h=null;let W=null,ve=null,d=null,g=null,k=null,G=0;function H(e,t){const n=d,l=h,i=e.length===0,s=t===void 0?l:t,o=i?fe:{owned:null,cleanups:null,context:s?s.context:null,owner:s},r=i?e:()=>e(()=>T(()=>O(o)));h=o,d=null;try{return M(r,!0)}finally{d=n,h=l}}function L(e,t){t=t?Object.assign({},U,t):U;const n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},l=i=>(typeof i=="function"&&(i=i(n.value)),ue(n,i));return[ae.bind(n),l]}function K(e,t,n){const l=Z(e,t,!1,I);B(l)}function Ce(e,t,n){ce=Ie;const l=Z(e,t,!1,I);l.user=!0,k?k.push(l):B(l)}function j(e,t,n){n=n?Object.assign({},U,n):U;const l=Z(e,t,!0,0);return l.observers=null,l.observerSlots=null,l.comparator=n.equals||void 0,B(l),ae.bind(l)}function T(e){if(d===null)return e();const t=d;d=null;try{return e()}finally{d=t}}function Ae(e){Ce(()=>T(e))}function ke(e){return h===null||(h.cleanups===null?h.cleanups=[e]:h.cleanups.push(e)),e}function ae(){if(this.sources&&this.state)if(this.state===I)B(this);else{const e=g;g=null,M(()=>V(this),!1),g=e}if(d){const e=this.observers?this.observers.length:0;d.sources?(d.sources.push(this),d.sourceSlots.push(e)):(d.sources=[this],d.sourceSlots=[e]),this.observers?(this.observers.push(d),this.observerSlots.push(d.sources.length-1)):(this.observers=[d],this.observerSlots=[d.sources.length-1])}return this.value}function ue(e,t,n){let l=e.value;return(!e.comparator||!e.comparator(l,t))&&(e.value=t,e.observers&&e.observers.length&&M(()=>{for(let i=0;i1e6)throw g=[],new Error},!1)),t}function B(e){if(!e.fn)return;O(e);const t=G;Ee(e,e.value,t)}function Ee(e,t,n){let l;const i=h,s=d;d=h=e;try{l=e.fn(t)}catch(o){return e.pure&&(e.state=I,e.owned&&e.owned.forEach(O),e.owned=null),e.updatedAt=n+1,be(o)}finally{d=s,h=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?ue(e,l):e.value=l,e.updatedAt=n)}function Z(e,t,n,l=I,i){const s={fn:e,state:l,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:h,context:h?h.context:null,pure:n};return h===null||h!==fe&&(h.owned?h.owned.push(s):h.owned=[s]),s}function R(e){if(e.state===0)return;if(e.state===F)return V(e);if(e.suspense&&T(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt=0;n--)if(e=t[n],e.state===I)B(e);else if(e.state===F){const l=g;g=null,M(()=>V(e,t[0]),!1),g=l}}function M(e,t){if(g)return e();let n=!1;t||(g=[]),k?n=!0:k=[],G++;try{const l=e();return Ne(n),l}catch(l){n||(k=null),g=null,be(l)}}function Ne(e){if(g&&(de(g),g=null),e)return;const t=k;k=null,t.length&&M(()=>ce(t),!1)}function de(e){for(let t=0;t=0;t--)O(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)O(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function Te(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function be(e,t=h){throw Te(e)}const De=Symbol("fallback");function ne(e){for(let t=0;t1?[]:null;return ke(()=>ne(s)),()=>{let f=e()||[],a=f.length,u,c;return f[xe],T(()=>{let b,_,m,v,A,$,p,w,x;if(a===0)o!==0&&(ne(s),s=[],l=[],i=[],o=0,r&&(r=[])),n.fallback&&(l=[De],i[0]=H(E=>(s[0]=E,n.fallback())),o=1);else if(o===0){for(i=new Array(a),c=0;c=$&&w>=$&&l[p]===f[w];p--,w--)m[w]=i[p],v[w]=s[p],r&&(A[w]=r[p]);for(b=new Map,_=new Array(w+1),c=w;c>=$;c--)x=f[c],u=b.get(x),_[c]=u===void 0?-1:u,b.set(x,c);for(u=$;u<=p;u++)x=l[u],c=b.get(x),c!==void 0&&c!==-1?(m[c]=i[u],v[c]=s[u],r&&(A[c]=r[u]),c=_[c],b.set(x,c)):s[u]();for(c=$;ce(t||{}))}const Oe=e=>`Stale read from <${e}>.`;function Le(e){const t="fallback"in e&&{fallback:()=>e.fallback};return j(Pe(()=>e.each,e.children,t||void 0))}function $e(e){const t=e.keyed,n=j(()=>e.when,void 0,void 0),l=t?n:j(n,void 0,{equals:(i,s)=>!i==!s});return j(()=>{const i=l();if(i){const s=e.children;return typeof s=="function"&&s.length>0?T(()=>s(t?i:()=>{if(!T(l))throw Oe("Show");return n()})):s}return e.fallback},void 0,void 0)}function Be(e,t,n){let l=n.length,i=t.length,s=l,o=0,r=0,f=t[i-1].nextSibling,a=null;for(;ou-r){const _=t[o];for(;r{i=s,t===document?e():y(t,e(),t.firstChild?null:void 0,n)},l.owner),()=>{i(),t.textContent=""}}function C(e,t,n,l){let i;const s=()=>{const r=document.createElement("template");return r.innerHTML=e,r.content.firstChild},o=()=>(i||(i=s())).cloneNode(!0);return o.cloneNode=o,o}function z(e,t=window.document){const n=t[le]||(t[le]=new Set);for(let l=0,i=e.length;lq(e,t(),i,n),l)}function je(e){let t=e.target;const n=`$$${e.type}`,l=e.target,i=e.currentTarget,s=f=>Object.defineProperty(e,"target",{configurable:!0,value:f}),o=()=>{const f=t[n];if(f&&!t.disabled){const a=t[`${n}Data`];if(a!==void 0?f.call(t,a,e):f.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&s(t.host),!0},r=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),e.composedPath){const f=e.composedPath();s(f[0]);for(let a=0;a{let r=t();for(;typeof r=="function";)r=r();n=q(e,r,n,l)}),()=>n;if(Array.isArray(t)){const r=[],f=n&&Array.isArray(n);if(J(r,t,n,i))return K(()=>n=q(e,r,n,l,!0)),()=>n;if(r.length===0){if(n=D(e,n,l),o)return n}else f?n.length===0?ie(e,r,l):Be(e,n,r):(n&&D(e),ie(e,r));n=r}else if(t.nodeType){if(Array.isArray(n)){if(o)return n=D(e,n,l,t);D(e,n,null,t)}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}}return n}function J(e,t,n,l){let i=!1;for(let s=0,o=t.length;s=0;o--){const r=t[o];if(i!==r){const f=r.parentNode===e;!s&&!o?f?e.replaceChild(i,r):e.insertBefore(i,n):f&&r.remove()}else s=!0}}else e.insertBefore(i,n);return[i]}const ge="",Ue=async()=>{const e=ge+"/api/all";return await(await fetch(e)).json()},se=async(e,t,n)=>{const l=ge+"/api/edit/"+e+"/"+t+"/"+n;return await(await fetch(l)).json()},[pe,Y]=L([]);L();const[we,re]=L(!1);var Fe=C(''),Ke=C(''),Re=C(""),Ve=C('
Name Iface IP MAC Hardware Date Known Online
.
');function qe(e){const[t,n]=L(e.host.Name),l="http://"+e.host.IP;let i=Fe();e.host.Now==1&&(i=Ke());let s=!1;e.host.Known==1&&(s=!0);const o=async f=>{n(f),await se(e.host.ID,t(),"")},r=async()=>{await se(e.host.ID,t(),"toggle")};return(()=>{var f=Ve(),a=f.firstChild,u=a.firstChild,c=a.nextSibling,S=c.nextSibling,b=S.nextSibling,_=b.firstChild,m=b.nextSibling,v=m.nextSibling,A=v.nextSibling,$=A.nextSibling,p=$.firstChild,w=p.firstChild,x=$.nextSibling;return y(a,()=>e.index,u),y(c,N($e,{get when(){return we()},get fallback(){return t()},get children(){var E=Re();return E.$$input=Q=>o(Q.target.value),K(()=>E.value=t()),E}})),y(S,()=>e.host.Iface),He(_,"href",l),y(_,()=>e.host.IP),y(m,()=>e.host.Mac),y(v,()=>e.host.Hw),y(A,()=>e.host.Date),w.$$click=r,w.checked=s,y(x,i),f})()}z(["input","click"]);var Ge=C('
Name Iface IP MAC Hardware Date Known Online ');function et(){const e=t=>{Je(t)};return(()=>{var t=ze(),n=t.firstChild,l=n.firstChild,i=l.nextSibling,s=i.firstChild,o=s.nextSibling,r=i.nextSibling,f=r.firstChild,a=f.nextSibling,u=r.nextSibling,c=u.firstChild,S=c.nextSibling,b=u.nextSibling,_=b.firstChild,m=_.nextSibling,v=b.nextSibling,A=v.firstChild,$=A.nextSibling,p=v.nextSibling,w=p.firstChild,x=w.nextSibling,E=p.nextSibling,Q=E.firstChild,ee=Q.nextSibling,ye=E.nextSibling,me=ye.firstChild,te=me.nextSibling;return o.$$click=e,o.$$clickData="Name",a.$$click=e,a.$$clickData="Iface",S.$$click=e,S.$$clickData="IP",m.$$click=e,m.$$clickData="Mac",$.$$click=e,$.$$clickData="Hw",x.$$click=e,x.$$clickData="Date",ee.$$click=e,ee.$$clickData="Known",te.$$click=e,te.$$clickData="Now",t})()}z(["click"]);var tt=C('
');function nt(){return(()=>{var e=tt(),t=e.firstChild,n=t.nextSibling,l=n.firstChild,i=l.firstChild;return y(t,N(Xe,{})),y(l,N(et,{}),i),y(i,N(Le,{get each(){return pe()},children:(s,o)=>N(qe,{host:s,index:o})})),e})()}var lt=C('
');function it(){return Ae(async()=>{const e=await Ue();Y(e)}),(()=>{var e=lt(),t=e.firstChild,n=t.firstChild;return y(n,N(nt,{})),e})()}const st=document.getElementById("root");Me(()=>N(it,{}),st); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index fec3b0d..f577cbb 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,8 +1,17 @@ +import { onMount } from 'solid-js'; import './App.css' +import { apiGetAllHosts } from './functions/api'; +import { setAllHosts } from './functions/exports'; import Body from './pages/Body' function App() { + onMount(async () => { + + const hosts = await apiGetAllHosts(); + setAllHosts(hosts); + }); + return (
diff --git a/frontend/src/components/CardHead.tsx b/frontend/src/components/CardHead.tsx new file mode 100644 index 0000000..0e7cb88 --- /dev/null +++ b/frontend/src/components/CardHead.tsx @@ -0,0 +1,20 @@ +import { Show } from "solid-js"; +import { editNames, setEditNames } from "../functions/exports"; + +function CardHead() { + + return ( +
+
+ Edit names} + > + + +
+
+ ) +} + +export default CardHead diff --git a/frontend/src/components/TableHead.tsx b/frontend/src/components/TableHead.tsx new file mode 100644 index 0000000..f769b1a --- /dev/null +++ b/frontend/src/components/TableHead.tsx @@ -0,0 +1,28 @@ +import { Host } from "../functions/exports"; +import { sortByAnyField } from "../functions/sort"; + +function TableHead() { + + const handleSort = (sortBy: keyof Host) => { + sortByAnyField(sortBy); + }; + + return ( +
+ + + + + + + + + + + + + + ) +} + +export default TableHead \ No newline at end of file diff --git a/frontend/src/components/TableRow.tsx b/frontend/src/components/TableRow.tsx index ad0c9a6..fdfa118 100644 --- a/frontend/src/components/TableRow.tsx +++ b/frontend/src/components/TableRow.tsx @@ -1,8 +1,11 @@ - - +import { createSignal, Show } from "solid-js"; +import { editNames } from "../functions/exports"; +import { apiEditHost } from "../functions/api"; function TableRow(_props: any) { + const [name, setName] = createSignal(_props.host.Name); + const link = "http://" + _props.host.IP; let now = ; @@ -15,10 +18,27 @@ function TableRow(_props: any) { known = true; } + const handleInput = async (n: string) => { + // console.log('Edit:', n); + setName(n); + await apiEditHost(_props.host.ID, name(), ''); + }; + const handleToggle = async () => { + await apiEditHost(_props.host.ID, name(), 'toggle'); + }; + return ( - + @@ -26,11 +46,12 @@ function TableRow(_props: any) { - + ) } diff --git a/frontend/src/functions/api.ts b/frontend/src/functions/api.ts index 2b4968b..c79f743 100644 --- a/frontend/src/functions/api.ts +++ b/frontend/src/functions/api.ts @@ -1,8 +1,16 @@ const api = 'http://0.0.0.0:8840'; -export const getAllHosts = async () => { +export const apiGetAllHosts = async () => { const url = api+'/api/all'; const hosts = await (await fetch(url)).json(); return hosts; +}; + +export const apiEditHost = async (id:number, name:string, known:string) => { + + const url = api+'/api/edit/'+id+'/'+name+'/'+known; + const res = await (await fetch(url)).json(); + + return res; }; \ No newline at end of file diff --git a/frontend/src/functions/exports.ts b/frontend/src/functions/exports.ts index dc80b58..e1006a0 100644 --- a/frontend/src/functions/exports.ts +++ b/frontend/src/functions/exports.ts @@ -13,17 +13,17 @@ export interface Host { Now: number; }; -export const emptyHost: Host = { - ID: 0, - Name: "", - DNS: "", - Iface: "", - IP: "", - Mac: "", - Hw: "", - Date: "", - Known: 0, - Now: 0, +export interface Conf { + Color: string; + Timeout: number; }; -export const [allHosts, setAllHosts] = createSignal([]); \ No newline at end of file +export const [allHosts, setAllHosts] = createSignal([]); + +export const [appConfig, setAppConfig] = createSignal(); + +export const [editNames, setEditNames] = createSignal(false); + +// export const [store, setStore] = createStore({ hosts: allHosts() }); + +// export const [updBody, setUpdBody] = createSignal(false); \ No newline at end of file diff --git a/frontend/src/functions/sort.ts b/frontend/src/functions/sort.ts new file mode 100644 index 0000000..6fc6561 --- /dev/null +++ b/frontend/src/functions/sort.ts @@ -0,0 +1,51 @@ +import { allHosts, Host, setAllHosts } from "./exports"; + +let down = false; +let oldField = "Name"; + +export function sortByAnyField(field: keyof Host) { + + if (field != oldField) { + oldField = field; + down = !down; + } else { + oldField = ''; + down = !down; + } + + // localStorage.setItem("sortDown", down); + // localStorage.setItem("sortField", field); + // checkNotEmpty(addrsArray); + + let someArray = allHosts(); + if (field == 'IP') { + someArray.sort((a, b) => sortIP(a, b, down)); + } else { + someArray.sort((a, b) => byField(a, b, field, down)); + } + + setAllHosts([]); + setAllHosts(someArray); +} + +function byField(a:Host, b:Host, fieldName: keyof Host, down:boolean){ + if (a[fieldName] > b[fieldName]) { + return down ? 1 : -1; + } else { + return !down ? 1 : -1; + } +} + +function sortIP(a:Host, b:Host, down: boolean) { + const num1 = numIP(a); + const num2 = numIP(b); + if (down) { + return num1-num2; + } else { + return num2-num1; + } +} + +function numIP(a:Host) { + return Number(a.IP.split(".").map((num) => (`000${num}`).slice(-3) ).join("")); +} \ No newline at end of file diff --git a/frontend/src/pages/Body.tsx b/frontend/src/pages/Body.tsx index 261053b..ac5ec4c 100644 --- a/frontend/src/pages/Body.tsx +++ b/frontend/src/pages/Body.tsx @@ -1,42 +1,20 @@ -import { onMount } from "solid-js"; -import { allHosts, setAllHosts } from "../functions/exports"; -import { getAllHosts } from "../functions/api"; +import { allHosts } from "../functions/exports"; import { For } from "solid-js"; import TableRow from "../components/TableRow"; +import CardHead from "../components/CardHead"; +import TableHead from "../components/TableHead"; function Body() { - const handleSort = (sortBy: string) => { - console.log("SORT BY", sortBy); - }; - - onMount(async () => { - - setAllHosts(await getAllHosts()); - }); - return (
- Header +
-
Name Iface IP MAC Hardware Date Known Online
{_props.index}.{_props.host.Name} + + handleInput(e.target.value)}> + + {_props.host.Iface} {_props.host.IP} {_props.host.Mac}{_props.host.Date}
- +
{now}
- - - - - - - - - - - - - - +
Name Iface IP MAC Hardware Date Known Online
+ {(host, index) =>