signalk-multihelm 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var e=window.__SK_REACT__;if(!e)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Children:t,Component:n,Fragment:r,Profiler:i,PureComponent:a,StrictMode:o,Suspense:s,cloneElement:c,createContext:l,createElement:u,createRef:d,forwardRef:f,isValidElement:p,lazy:m,memo:h,startTransition:g,use:_,useActionState:v,useCallback:y,useContext:ee,useDebugValue:b,useDeferredValue:te,useEffect:x,useId:ne,useImperativeHandle:S,useInsertionEffect:C,useLayoutEffect:w,useMemo:re,useOptimistic:ie,useReducer:ae,useRef:T,useState:E,useSyncExternalStore:oe,useTransition:se,version:ce}=e;function D(e){return e===1?`1 server`:`${String(e)} servers`}function O(e,t){if(!e.running)return{tone:`danger`,text:`Multihelm is not running. Enable it above.`};if(e.masterConflict)return{tone:`danger`,text:`More than one server is set to be the boat's master. Set one only.`};if(e.role===`master`){let t=e.pairedBy.length,n=e.pairedBy.filter(e=>e.online).length;return{tone:`info`,text:t===0?`This server is the boat's master. No other server is paired with it yet.`:`This server is the boat's master. ${String(n)} of the ${D(t)} paired with it ${n===1?`is`:`are`} online.`}}if(e.master)return{tone:`success`,text:`The boat's master is ${e.master.name}; it answered ${F(e.master.lastSeen,t)}.`};let n=e.peers.filter(e=>e.state===`paired`),r=n.filter(e=>e.online===!1);return r.length>0?{tone:`danger`,text:`No master found: ${r.map(e=>e.name).join(`, `)} ${r.length===1?`is`:`are`} not reachable.`}:n.length===0?{tone:`warning`,text:`No master found: this server is not paired yet. Pair it with the server set to be the boat's master below.`}:{tone:`warning`,text:`No master found: none of the paired servers is set to be the boat's master.`}}function k(e,t){return e.url===t.url||e.name.toLowerCase()===t.name.toLowerCase()}function A(e){return e.discovered.filter(t=>!e.peers.some(e=>k(t,e)))}function j(e,t){return e.id===``?t.find(t=>t.url===e.url)?.name??e.name:e.name}function M(e){return`/skServer/security/access/requests/${encodeURIComponent(e)}/approved`}function N(e){return[e.signalk&&`Signal K ${e.signalk}`,e.multihelm&&`Multihelm ${e.multihelm}`].filter(Boolean).join(` · `)}function P(e){return`${e}/admin/#/security/access/requests`}function F(e,t){if(e===void 0)return`never`;let n=Math.max(0,Math.round((t-e)/1e3));if(n<10)return`just now`;if(n<90)return`${String(n)} s ago`;let r=Math.round(n/60);if(r<90)return`${String(r)} min ago`;let i=Math.round(r/60);return i<36?`${String(i)} h ago`:`${String(Math.round(i/24))} days ago`}var I=window.__SK_REACT_JSX_RUNTIME__;if(!I)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Fragment:L,jsx:R,jsxs:z}=I,B=`/plugins/signalk-multihelm`,V=3e3,H=`own-access`;async function U(e,t){let n=await fetch(e,{credentials:`same-origin`,...t}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(typeof r.error==`string`?r.error:`HTTP ${String(n.status)}`);return r}function W(e){return e instanceof Error?e.message:String(e)}function G(e){return{master:e?.master===!0,followVessel:e?.followVessel!==!1,followMetadata:e?.followMetadata!==!1,followSourcePriorities:e?.followSourcePriorities!==!1,historyFromMaster:e?.historyFromMaster!==!1}}function K({configuration:e,save:t}){let[n,r]=E(null),[i,a]=E(null),[o,s]=E(null),[c,l]=E(null),[u,d]=E(``),f=y(async()=>{try{r(await U(`${B}/status`)),a(null)}catch(e){a(W(e))}},[]);x(()=>{f();let e=setInterval(()=>void f(),V);return()=>{clearInterval(e)}},[f]);let p=async(e,t)=>{s(e),l(null);try{return await t(),!0}catch(t){return l({key:e,text:W(t)}),!1}finally{s(null),await f()}},m=e=>p(e,()=>U(`${B}/peers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})})),h=(e,t)=>{window.confirm(`Stop keeping this server in step with ${t}?`)&&p(e.url,()=>U(`${B}/peers?url=${encodeURIComponent(e.url)}`,{method:`DELETE`}))},g=e=>{window.confirm(`Take ${e.name} off this list? It comes back once it asks this server again.`)&&p(e.id,()=>U(`${B}/paired-by?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}))},_=e=>{p(H,()=>U(M(e),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({permissions:`admin`})}))},v=async e=>{e.preventDefault(),u.trim()!==``&&await m(u.trim())&&d(``)};return z(`div`,{children:[i&&z(`div`,{className:`alert alert-danger`,children:[`Cannot read Multihelm's status: `,i,n&&`. What is shown below may be out of date.`]}),n&&R(q,{status:n,allowing:o===H,allowError:c?.key===H?c.text:null,onAllow:_}),n?.running&&z(L,{children:[n.role===`master`&&R(Z,{status:n,busy:o,onForget:g}),R(J,{status:n,busy:o,onPair:m,onUnpair:h}),n.role!==`master`&&n.pairedBy.length>0&&R(Z,{status:n,busy:o,onForget:g}),z(`div`,{className:`card mb-3`,children:[R(`div`,{className:`card-header`,children:`Pair with another server`}),z(`div`,{className:`card-body`,children:[R(`p`,{className:`small text-body-secondary`,children:n.role===`master`?`The other servers pair with this one in their own Multihelm settings. Pair this one with another only to replicate charts both ways.`:`Each server takes over what the servers it is paired with share. Pair this one with the boat's master; to replicate charts both ways, pair the other server with this one too.`}),R(Q,{status:n,busy:o,onPair:m}),z(`form`,{className:`row g-2 mt-1`,onSubmit:e=>void v(e),children:[R(`div`,{className:`col-sm`,children:R(`input`,{className:`form-control`,value:u,onChange:e=>{d(e.target.value)},placeholder:`Or enter its address, e.g. 192.168.1.10 or helm.local:3000`,"aria-label":`Address of the other server`})}),R(`div`,{className:`col-sm-auto`,children:R(`button`,{type:`submit`,className:`btn btn-primary`,disabled:o!==null||u.trim()===``,children:o===u.trim()?`Pairing…`:`Pair`})})]}),c&&c.key!==H&&R(`div`,{className:`alert alert-danger mt-3 mb-0`,children:c.text})]})]})]}),R($,{configuration:e,save:t})]})}function q({status:e,allowing:t,allowError:n,onAllow:r}){let i=O(e,Date.now()),a=e.ownAccess;return z(L,{children:[R(`div`,{className:`alert alert-${i.tone}`,children:i.text}),!e.available&&R(`div`,{className:`alert alert-danger`,children:`This Signal K server is older than 2.31, so the other servers cannot read from it. Update it.`}),a?.state===`waiting-approval`&&z(`div`,{className:`alert alert-warning`,children:[z(`p`,{children:[R(`strong`,{children:`One more step:`}),` Multihelm needs admin access to this server to write the master's vessel data, path metadata and source priorities here.`]}),R(`button`,{type:`button`,className:`btn btn-primary`,disabled:t,onClick:()=>{r(a.request)},children:t?`Allowing…`:`Allow`}),z(`div`,{className:`small mt-2`,children:[`This approves the request “Multihelm: take the vessel settings over from the master” under `,R(`a`,{href:`#/security/access/requests`,children:`Security → Access Requests`}),`.`]}),n&&R(`div`,{className:`text-danger mt-2`,children:n})]}),a?.state===`denied`&&R(`div`,{className:`alert alert-danger`,children:`The access request on this server was denied, so the vessel settings are not taken over from the master. Save the settings below to ask again.`})]})}function J({status:e,busy:t,onPair:n,onUnpair:r}){let i=Date.now();return z(`div`,{className:`card mb-3`,children:[R(`div`,{className:`card-header`,children:`Paired servers`}),R(`div`,{className:`card-body`,children:e.peers.length===0?R(`p`,{className:`text-body-secondary mb-0`,children:e.role===`master`?`This server takes nothing over from another.`:`This server is not paired with another yet.`}):R(`table`,{className:`table table-sm align-middle mb-0`,children:R(`tbody`,{children:e.peers.map(a=>{let o=j(a,e.discovered);return z(`tr`,{children:[z(`td`,{children:[R(`strong`,{children:o}),a.master&&R(`span`,{className:`badge text-bg-primary ms-2`,children:`master`}),R(`div`,{className:`small text-body-secondary`,children:a.url}),N(a)&&R(`div`,{className:`small text-body-secondary`,children:N(a)})]}),R(`td`,{children:R(Y,{peer:a,name:o,status:e,now:i})}),z(`td`,{className:`text-end text-nowrap`,children:[a.state===`needs-pairing`&&R(`button`,{type:`button`,className:`btn btn-sm btn-primary me-2`,disabled:t!==null,onClick:()=>void n(a.url),children:`Pair again`}),R(`button`,{type:`button`,className:`btn btn-sm btn-outline-danger`,disabled:t!==null,onClick:()=>{r(a,o)},children:`Remove`})]})]},a.url)})})})})]})}function Y({peer:e,name:t,status:n,now:r}){return z(L,{children:[e.state===`paired`&&z(L,{children:[R(X,{online:e.online===!0}),z(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,F(e.lastSeen,r)]})]}),e.state===`waiting-approval`&&z(L,{children:[R(`span`,{className:`badge text-bg-warning`,children:`Waiting for approval`}),z(`div`,{className:`small mt-1`,children:[`On `,t,`, approve “Multihelm on `,n.name,`” under`,` `,R(`a`,{href:P(e.url),target:`_blank`,rel:`noreferrer`,children:`Security → Access Requests`}),`.`]})]}),e.state===`needs-pairing`&&R(`span`,{className:`badge text-bg-danger`,children:`Not paired`}),e.lastError&&R(`div`,{className:`small text-danger mt-1`,children:e.lastError})]})}function X({online:e}){return e?R(`span`,{className:`badge text-bg-success`,children:`Online`}):R(`span`,{className:`badge text-bg-secondary`,children:`Offline`})}function Z({status:e,busy:t,onForget:n}){let r=Date.now();return z(`div`,{className:`card mb-3`,children:[R(`div`,{className:`card-header`,children:`Servers paired with this one`}),R(`div`,{className:`card-body`,children:e.pairedBy.length===0?R(`p`,{className:`text-body-secondary mb-0`,children:`No other server is paired with this one yet. Pair the others with it in their Multihelm settings.`}):R(`table`,{className:`table table-sm align-middle mb-0`,children:R(`tbody`,{children:e.pairedBy.map(e=>z(`tr`,{children:[z(`td`,{children:[R(`strong`,{children:e.name}),N(e)&&R(`div`,{className:`small text-body-secondary`,children:N(e)})]}),z(`td`,{children:[R(X,{online:e.online}),z(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,F(e.lastSeen,r)]})]}),R(`td`,{className:`text-end`,children:!e.online&&R(`button`,{type:`button`,className:`btn btn-sm btn-outline-secondary`,disabled:t!==null,onClick:()=>{n(e)},children:`Forget`})})]},e.id))})})})]})}function Q({status:e,busy:t,onPair:n}){let r=A(e);return r.length===0?R(`p`,{className:`text-body-secondary`,children:`No other Signal K server that is not paired yet was found on the network.`}):R(`table`,{className:`table table-sm align-middle`,children:R(`tbody`,{children:r.map(e=>z(`tr`,{children:[z(`td`,{children:[R(`strong`,{children:e.name}),e.vessel&&z(`span`,{className:`text-body-secondary ms-2`,children:[`vessel `,e.vessel]}),R(`div`,{className:`small text-body-secondary`,children:e.url})]}),R(`td`,{className:`text-end`,children:R(`button`,{type:`button`,className:`btn btn-sm btn-primary`,disabled:t!==null,onClick:()=>void n(e.url),children:t===e.url?`Pairing…`:`Pair`})})]},e.url))})})}function $({configuration:e,save:t}){let[n,r]=E(()=>G(e)),i=(e,t)=>{r(n=>({...n,[e]:t}))},a=(e,t,r,a=!1)=>z(`div`,{className:`form-check mb-3`,children:[R(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${e}`,checked:n[e],disabled:a,onChange:t=>{i(e,t.target.checked)}}),R(`label`,{className:`form-check-label`,htmlFor:`multihelm-${e}`,children:t}),R(`div`,{className:`form-text`,children:r})]}),o=n.master;return z(`div`,{className:`card mb-3`,children:[R(`div`,{className:`card-header`,children:`Settings`}),z(`div`,{className:`card-body`,children:[a(`master`,`This server is the boat's master`,`Set this on one server only. Plugins that run on the master alone run here, and the other servers use them through this one.`),o&&R(`p`,{className:`small text-body-secondary`,children:`The options below apply to the servers that are not the master.`}),a(`followVessel`,`Take the vessel data over from the master`,`Name, MMSI, call sign, dimensions and ship type from Server → Settings. Changes made here are replaced by the master's.`,o),a(`followMetadata`,`Take the path metadata over from the master`,`Display names, units, zones and alarm limits set for paths. Changes made here are replaced by the master's.`,o),a(`followSourcePriorities`,`Take the source priorities over from the master`,`Which source wins for a path, from Data → Source Priorities. They name sources by connection, so give the NMEA 2000 bus the same connection name on every server. Changes made here are replaced by the master's.`,o),a(`historyFromMaster`,`Answer this server's History API from the master`,`While the master has a history provider (signalk-questdb, for example), history graphs on this server show the master's history, so it is kept once on the boat. Needs Signal K 2.32.0 or later.`,o),R(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{t({...e,...n})},children:`Save settings`})]})]})}export{K as default};
1
+ var e=window.__SK_REACT__;if(!e)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Children:t,Component:n,Fragment:r,Profiler:i,PureComponent:a,StrictMode:o,Suspense:s,cloneElement:c,createContext:l,createElement:u,createRef:d,forwardRef:f,isValidElement:p,lazy:m,memo:h,startTransition:g,use:_,useActionState:v,useCallback:y,useContext:ee,useDebugValue:te,useDeferredValue:ne,useEffect:b,useId:re,useImperativeHandle:ie,useInsertionEffect:ae,useLayoutEffect:oe,useMemo:x,useOptimistic:se,useReducer:S,useRef:ce,useState:C,useSyncExternalStore:w,useTransition:le,version:ue}=e;function T(e){return e===1?`1 server`:`${String(e)} servers`}function E(e,t){if(!e.running)return{tone:`danger`,text:`Multihelm is not running. Enable it above.`};if(e.masterConflict)return{tone:`danger`,text:`More than one server is set to be the boat's master. Set one only.`};if(e.role===`master`){let t=e.pairedBy.length,n=e.pairedBy.filter(e=>e.online).length;return{tone:`info`,text:t===0?`This server is the boat's master. No other server is paired with it yet.`:`This server is the boat's master. ${String(n)} of the ${T(t)} paired with it ${n===1?`is`:`are`} online.`}}if(e.master)return{tone:`success`,text:`The boat's master is ${e.master.name}; it answered ${N(e.master.lastSeen,t)}.`};let n=e.peers.filter(e=>e.state===`paired`),r=n.filter(e=>e.online===!1);return r.length>0?{tone:`danger`,text:`No master found: ${r.map(e=>e.name).join(`, `)} ${r.length===1?`is`:`are`} not reachable.`}:n.length===0?{tone:`warning`,text:`No master found: this server is not paired yet. Pair it with the server set to be the boat's master below.`}:{tone:`warning`,text:`No master found: none of the paired servers is set to be the boat's master.`}}function D(e,t){return e.url===t.url||e.name.toLowerCase()===t.name.toLowerCase()}function O(e){return e.discovered.filter(t=>!e.peers.some(e=>D(t,e)))}function k(e,t){return e.id===``?t.find(t=>t.url===e.url)?.name??e.name:e.name}function A(e){return`/skServer/security/access/requests/${encodeURIComponent(e)}/approved`}function j(e){return[e.signalk&&`Signal K ${e.signalk}`,e.multihelm&&`Multihelm ${e.multihelm}`].filter(Boolean).join(` · `)}function M(e){return`${e}/admin/#/security/access/requests`}function N(e,t){if(e===void 0)return`never`;let n=Math.max(0,Math.round((t-e)/1e3));if(n<10)return`just now`;if(n<90)return`${String(n)} s ago`;let r=Math.round(n/60);if(r<90)return`${String(r)} min ago`;let i=Math.round(r/60);return i<36?`${String(i)} h ago`:`${String(Math.round(i/24))} days ago`}var P=window.__SK_REACT_JSX_RUNTIME__;if(!P)throw Error(`signalk-multihelm: the admin UI does not expose React (Signal K 2.27 or later)`);var{Fragment:F,jsx:I,jsxs:L}=P,R=`/plugins/signalk-multihelm`,z=3e3,B=`own-access`;async function V(e,t){let n=await fetch(e,{credentials:`same-origin`,...t}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(typeof r.error==`string`?r.error:`HTTP ${String(n.status)}`);return r}function H(e){return e instanceof Error?e.message:String(e)}function U(e){return{master:e?.master===!0,syncResources:e?.syncResources!==!1,followVessel:e?.followVessel!==!1,followMetadata:e?.followMetadata!==!1,followSourcePriorities:e?.followSourcePriorities!==!1,historyFromMaster:e?.historyFromMaster!==!1,autopilotFromMaster:e?.autopilotFromMaster!==!1,courseFromMaster:e?.courseFromMaster!==!1,alarmsFromMaster:e?.alarmsFromMaster!==!1}}function W({configuration:e,save:t}){let[n,r]=C(null),[i,a]=C(null),[o,s]=C(null),[c,l]=C(null),[u,d]=C(``),f=y(async()=>{try{r(await V(`${R}/status`)),a(null)}catch(e){a(H(e))}},[]);b(()=>{f();let e=setInterval(()=>void f(),z);return()=>{clearInterval(e)}},[f]);let p=async(e,t)=>{s(e),l(null);try{return await t(),!0}catch(t){return l({key:e,text:H(t)}),!1}finally{s(null),await f()}},m=e=>p(e,()=>V(`${R}/peers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})})),h=(e,t)=>{window.confirm(`Stop keeping this server in step with ${t}?`)&&p(e.url,()=>V(`${R}/peers?url=${encodeURIComponent(e.url)}`,{method:`DELETE`}))},g=e=>{window.confirm(`Take ${e.name} off this list? It comes back once it asks this server again.`)&&p(e.id,()=>V(`${R}/paired-by?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}))},_=e=>{p(B,()=>V(A(e),{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({permissions:`admin`})}))},v=async e=>{e.preventDefault(),u.trim()!==``&&await m(u.trim())&&d(``)};return L(`div`,{children:[i&&L(`div`,{className:`alert alert-danger`,children:[`Cannot read Multihelm's status: `,i,n&&`. What is shown below may be out of date.`]}),n&&I(G,{status:n,allowing:o===B,allowError:c?.key===B?c.text:null,onAllow:_}),n?.running&&L(F,{children:[n.role===`master`&&I(Y,{status:n,busy:o,onForget:g}),I(K,{status:n,busy:o,onPair:m,onUnpair:h}),n.role!==`master`&&n.pairedBy.length>0&&I(Y,{status:n,busy:o,onForget:g}),I(Q,{status:n,onSaved:f}),L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Pair with another server`}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:n.role===`master`?`The other servers pair with this one in their own Multihelm settings. Pair this one with another only to replicate charts both ways.`:`Each server takes over what the servers it is paired with share. Pair this one with the boat's master; to replicate charts both ways, pair the other server with this one too.`}),I(X,{status:n,busy:o,onPair:m}),L(`form`,{className:`row g-2 mt-1`,onSubmit:e=>void v(e),children:[I(`div`,{className:`col-sm`,children:I(`input`,{className:`form-control`,value:u,onChange:e=>{d(e.target.value)},placeholder:`Or enter its address, e.g. 192.168.1.10 or helm.local:3000`,"aria-label":`Address of the other server`})}),I(`div`,{className:`col-sm-auto`,children:I(`button`,{type:`submit`,className:`btn btn-primary`,disabled:o!==null||u.trim()===``,children:o===u.trim()?`Pairing…`:`Pair`})})]}),c&&c.key!==B&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:c.text})]})]})]}),I($,{configuration:e,save:t})]})}function G({status:e,allowing:t,allowError:n,onAllow:r}){let i=E(e,Date.now()),a=e.ownAccess;return L(F,{children:[I(`div`,{className:`alert alert-${i.tone}`,children:i.text}),!e.available&&I(`div`,{className:`alert alert-danger`,children:`This Signal K server is older than 2.31, so the other servers cannot read from it. Update it.`}),a?.state===`waiting-approval`&&L(`div`,{className:`alert alert-warning`,children:[L(`p`,{children:[I(`strong`,{children:`One more step:`}),` Multihelm needs admin access to this server to write the master's vessel data, path metadata and source priorities here, and to start and stop the plugins that run on the master only.`]}),I(`button`,{type:`button`,className:`btn btn-primary`,disabled:t,onClick:()=>{r(a.request)},children:t?`Allowing…`:`Allow`}),L(`div`,{className:`small mt-2`,children:[`This approves Multihelm's own request under`,` `,I(`a`,{href:`#/security/access/requests`,children:`Security → Access Requests`}),`.`]}),n&&I(`div`,{className:`text-danger mt-2`,children:n})]}),e.controlAccess&&L(`div`,{className:`alert alert-warning`,children:[`To operate the autopilot, set the course and acknowledge alarms from this station, approve Multihelm's request `,I(`code`,{children:e.controlAccess.request}),` under Security → Access Requests on the master, `,e.master?.name??`the master`,`.`]}),a?.state===`denied`&&I(`div`,{className:`alert alert-danger`,children:`The access request on this server was denied, so the vessel settings are not taken over from the master and no plugin is switched for the master. Save the settings below to ask again.`})]})}function K({status:e,busy:t,onPair:n,onUnpair:r}){let i=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Paired servers`}),I(`div`,{className:`card-body`,children:e.peers.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:e.role===`master`?`This server takes nothing over from another.`:`This server is not paired with another yet.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.peers.map(a=>{let o=k(a,e.discovered);return L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:o}),a.master&&I(`span`,{className:`badge text-bg-primary ms-2`,children:`master`}),I(`div`,{className:`small text-body-secondary`,children:a.url}),j(a)&&I(`div`,{className:`small text-body-secondary`,children:j(a)})]}),I(`td`,{children:I(q,{peer:a,name:o,status:e,now:i})}),L(`td`,{className:`text-end text-nowrap`,children:[a.state===`needs-pairing`&&I(`button`,{type:`button`,className:`btn btn-sm btn-primary me-2`,disabled:t!==null,onClick:()=>void n(a.url),children:`Pair again`}),I(`button`,{type:`button`,className:`btn btn-sm btn-outline-danger`,disabled:t!==null,onClick:()=>{r(a,o)},children:`Remove`})]})]},a.url)})})})})]})}function q({peer:e,name:t,status:n,now:r}){return L(F,{children:[e.state===`paired`&&L(F,{children:[I(J,{online:e.online===!0}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),e.state===`waiting-approval`&&L(F,{children:[I(`span`,{className:`badge text-bg-warning`,children:`Waiting for approval`}),L(`div`,{className:`small mt-1`,children:[`On `,t,`, approve “Multihelm on `,n.name,`” under`,` `,I(`a`,{href:M(e.url),target:`_blank`,rel:`noreferrer`,children:`Security → Access Requests`}),`.`]})]}),e.state===`needs-pairing`&&I(`span`,{className:`badge text-bg-danger`,children:`Not paired`}),e.lastError&&I(`div`,{className:`small text-danger mt-1`,children:e.lastError})]})}function J({online:e}){return e?I(`span`,{className:`badge text-bg-success`,children:`Online`}):I(`span`,{className:`badge text-bg-secondary`,children:`Offline`})}function Y({status:e,busy:t,onForget:n}){let r=Date.now();return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Servers paired with this one`}),I(`div`,{className:`card-body`,children:e.pairedBy.length===0?I(`p`,{className:`text-body-secondary mb-0`,children:`No other server is paired with this one yet. Pair the others with it in their Multihelm settings.`}):I(`table`,{className:`table table-sm align-middle mb-0`,children:I(`tbody`,{children:e.pairedBy.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),j(e)&&I(`div`,{className:`small text-body-secondary`,children:j(e)})]}),L(`td`,{children:[I(J,{online:e.online}),L(`span`,{className:`small text-body-secondary ms-2`,children:[`seen `,N(e.lastSeen,r)]})]}),I(`td`,{className:`text-end`,children:!e.online&&I(`button`,{type:`button`,className:`btn btn-sm btn-outline-secondary`,disabled:t!==null,onClick:()=>{n(e)},children:`Forget`})})]},e.id))})})})]})}function X({status:e,busy:t,onPair:n}){let r=O(e);return r.length===0?I(`p`,{className:`text-body-secondary`,children:`No other Signal K server that is not paired yet was found on the network.`}):I(`table`,{className:`table table-sm align-middle`,children:I(`tbody`,{children:r.map(e=>L(`tr`,{children:[L(`td`,{children:[I(`strong`,{children:e.name}),e.vessel&&L(`span`,{className:`text-body-secondary ms-2`,children:[`vessel `,e.vessel]}),I(`div`,{className:`small text-body-secondary`,children:e.url})]}),I(`td`,{className:`text-end`,children:I(`button`,{type:`button`,className:`btn btn-sm btn-primary`,disabled:t!==null,onClick:()=>void n(e.url),children:t===e.url?`Pairing…`:`Pair`})})]},e.url))})})}function Z(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`).filter(e=>e.id!==`signalk-multihelm`).map(e=>({id:e.id,name:typeof e.name==`string`&&e.name!==``?e.name:e.id})).sort((e,t)=>e.name.localeCompare(t.name)):[]}function Q({status:e,onSaved:t}){let[n,r]=C(null),[i,a]=C(null),[o,s]=C([]),[c,l]=C(!1),[u,d]=C(null);b(()=>{V(`/skServer/plugins`).then(e=>{r(Z(e))},e=>{d(`Cannot list the plugins: ${H(e)}`)})},[]);let f=i??e.masterPlugins,p=i===null||[...i].sort().join()===[...e.masterPlugins].sort().join(),m=[...new Set([...e.masterPlugins,...f,...o])].filter(e=>!n?.some(t=>t.id===e)),h=(e,t)=>{a(t?[...f,e]:f.filter(t=>t!==e)),t||s([...o,e])},g=async()=>{l(!0),d(null);try{await V(`${R}/master-plugins`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({plugins:f})}),a(null),s([]),await t()}catch(e){d(H(e))}finally{l(!1)}};return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Plugins that run on the master only`}),L(`div`,{className:`card-body`,children:[I(`p`,{className:`small text-body-secondary`,children:`These plugins run on the boat's master and are stopped on the other servers, for example an autopilot provider, so only one server sends its commands. The list is the same on every server; when another server becomes the master, they move there.`}),n===null&&!u&&I(`p`,{className:`text-body-secondary`,children:`Loading the plugins…`}),n?.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-master-plugin-${e.id}`,checked:f.includes(e.id),disabled:c,onChange:t=>{h(e.id,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-master-plugin-${e.id}`,children:e.name})]},e.id)),n!==null&&m.map(e=>L(`div`,{className:`form-check`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-master-plugin-${e}`,checked:f.includes(e),disabled:c,onChange:t=>{h(e,t.target.checked)}}),L(`label`,{className:`form-check-label`,htmlFor:`multihelm-master-plugin-${e}`,children:[e,` `,I(`span`,{className:`text-body-secondary`,children:`(not installed here)`})]})]},e)),I(`button`,{type:`button`,className:`btn btn-primary mt-3`,disabled:c||p,onClick:()=>void g(),children:c?`Saving…`:`Save list`}),u&&I(`div`,{className:`alert alert-danger mt-3 mb-0`,children:u})]})]})}function $({configuration:e,save:t}){let[n,r]=C(()=>U(e)),i=(e,t)=>{r(n=>({...n,[e]:t}))},a=(e,t,r,a=!1)=>L(`div`,{className:`form-check mb-3`,children:[I(`input`,{className:`form-check-input`,type:`checkbox`,id:`multihelm-${e}`,checked:n[e],disabled:a,onChange:t=>{i(e,t.target.checked)}}),I(`label`,{className:`form-check-label`,htmlFor:`multihelm-${e}`,children:t}),I(`div`,{className:`form-text`,children:r})]}),o=n.master;return L(`div`,{className:`card mb-3`,children:[I(`div`,{className:`card-header`,children:`Settings`}),L(`div`,{className:`card-body`,children:[a(`master`,`This server is the boat's master`,`Set this on one server only. Plugins that run on the master alone run here, and the other servers use them through this one.`),a(`syncResources`,`Keep routes and waypoints in step`,`Routes, waypoints, regions and notes, kept the same on every server of the boat: a change on one reaches the others, with no master.`),o&&I(`p`,{className:`small text-body-secondary`,children:`The options below apply to the servers that are not the master.`}),a(`followVessel`,`Take the vessel data over from the master`,`Name, MMSI, call sign, dimensions and ship type from Server → Settings. Changes made here are replaced by the master's.`,o),a(`followMetadata`,`Take the path metadata over from the master`,`Display names, units, zones and alarm limits set for paths. Changes made here are replaced by the master's.`,o),a(`followSourcePriorities`,`Take the source priorities over from the master`,`Which source wins for a path, from Data → Source Priorities. They name sources by connection, so give the NMEA 2000 bus the same connection name on every server. Changes made here are replaced by the master's.`,o),a(`historyFromMaster`,`Answer this server's History API from the master`,`While the master has a history provider (signalk-questdb, for example), history graphs on this server show the master's history, so it is kept once on the boat. Needs Signal K 2.32.0 or later.`,o),a(`autopilotFromMaster`,`Operate the master's autopilot from this server`,`A chartplotter here operates the master's autopilot, while only the master sends to it. Put the autopilot provider plugin on the list of plugins that run on the master only.`,o),a(`courseFromMaster`,`Keep the course the same as on the master`,`The active destination or route set at any station is taken over by all the others.`,o),a(`alarmsFromMaster`,`Show the master's alarms here`,`Silencing or acknowledging an alarm at any station does it at all the others. An alarm this server raises itself is not shown twice.`,o),I(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{t({...e,...n})},children:`Save settings`})]})]})}export{W as default};