-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,273 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
node_modules | ||
/node_modules | ||
/.parcel-cache | ||
/dist | ||
.DS_Store | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local interfaces = {} | ||
local uci = require('simple-uci').cursor() | ||
local json = require 'jsonc' | ||
local ethernet = require 'gluon.ethernet' | ||
|
||
uci:foreach('gluon', 'interface', function(interface) | ||
table.insert(interfaces, interface) | ||
end) | ||
|
||
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -- You will need this for encoding/decoding | ||
-- encoding | ||
function enc(data) | ||
return ((data:gsub('.', function(x) | ||
local r,b='',x:byte() | ||
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end | ||
return r; | ||
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) | ||
if (#x < 6) then return '' end | ||
local c=0 | ||
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end | ||
return b:sub(c+1,c+1) | ||
end)..({ '', '==', '=' })[#data%3+1]) | ||
end | ||
|
||
-- decoding | ||
function dec(data) | ||
data = string.gsub(data, '[^'..b..'=]', '') | ||
return (data:gsub('.', function(x) | ||
if (x == '=') then return '' end | ||
local r,f='',(b:find(x)-1) | ||
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end | ||
return r; | ||
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) | ||
if (#x ~= 8) then return '' end | ||
local c=0 | ||
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end | ||
return string.char(c) | ||
end)) | ||
end | ||
|
||
print(enc(json.stringify({ | ||
phy_interfaces = ethernet.interfaces(), | ||
uci = interfaces | ||
}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Fragment, h } from "preact"; | ||
import { useState } from 'preact/hooks'; | ||
|
||
import Components from "./components" | ||
|
||
const GluonWeb2 = ({ id, component, data: initialData }: { id: string, component: string, data: any }) => { | ||
const { data, setData } = useState<any>(initialData) | ||
|
||
return ( | ||
<Fragment> | ||
<input type="text" style="display: none" name={id} value={JSON.stringify(data)} />, | ||
{ | ||
h(Components[component], { | ||
data, | ||
setData | ||
}) | ||
} | ||
</Fragment> | ||
) | ||
} | ||
|
||
export default GluonWeb2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import VlanUI from "./vlan-ui" | ||
export default { | ||
"vlan-ui": VlanUI | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { h } from "preact"; | ||
|
||
const ROLES = { | ||
'uplink': 'Uplink', | ||
'mesh': 'Mesh', | ||
'client': 'Client' | ||
} | ||
|
||
const VlanUI = ({ data, setData }: { data: any, setData: (data: any) => void }) => { | ||
/* return data.uci.map(intf => { | ||
( | ||
<div> | ||
<label class="gluon-value-title" for="id.1.4.iface_wan_vlan11">{intf.name}</label> | ||
<div class="gluon-value-field"> | ||
<div> | ||
<label data-index="1"> | ||
{(intf.roles ?? [])} | ||
<input data-update="click change" type="checkbox" id="id.1.4.iface_wan_vlan11.uplink" name="id.1.4.iface_wan_vlan11" value="uplink" data-exclusive-with="["client"]" data-update="change"> | ||
<label for="id.1.4.iface_wan_vlan11.uplink"></label> | ||
<span class="gluon-multi-list-option-descr">Uplink</span> | ||
</label> | ||
    | ||
<label data-index="2"> | ||
<input data-update="click change" type="checkbox" id="id.1.4.iface_wan_vlan11.mesh" name="id.1.4.iface_wan_vlan11" value="mesh" checked="checked" data-exclusive-with="["client"]" data-update="change"> | ||
<label for="id.1.4.iface_wan_vlan11.mesh"></label> | ||
<span class="gluon-multi-list-option-descr">Mesh</span> | ||
</label> | ||
    | ||
<label data-index="3"> | ||
<input data-update="click change" type="checkbox" id="id.1.4.iface_wan_vlan11.client" name="id.1.4.iface_wan_vlan11" value="client" data-exclusive-with="["uplink","mesh"]" data-update="change"> | ||
<label for="id.1.4.iface_wan_vlan11.client"></label> | ||
<span class="gluon-multi-list-option-descr">Client</span> | ||
</label> | ||
</div> | ||
) | ||
}) */ | ||
|
||
return <h1>VLANUI {JSON.stringify(data)}</h1> | ||
}; | ||
|
||
export default VlanUI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,65 @@ | ||
import { h, render } from "preact"; | ||
import App from "./App"; | ||
/* import App from "./App"; | ||
render(<App />, document.getElementById("root")!); | ||
render(<App />, document.getElementById("root")!); */ | ||
|
||
import GluonWeb2 from "./GluonWeb2"; | ||
|
||
const INSTANCES: Record<string, GluonWeb2Instance> = {} | ||
|
||
class GluonWeb2Instance { | ||
readonly el: HTMLElement; | ||
readonly rendered: any; | ||
|
||
constructor(el: HTMLElement) { | ||
this.el = el; | ||
const dataset = this.el.dataset | ||
|
||
try { | ||
let parsedData = JSON.parse(atob(dataset.componentData)) | ||
|
||
this.rendered = render(<GluonWeb2 | ||
id={dataset.gluonWeb2} | ||
component={dataset.component} | ||
data={parsedData} | ||
/>, this.el) | ||
} catch (error) { | ||
const errEl = document.createElement('p') | ||
errEl.classList.add('web2-error') | ||
el.appendChild(errEl) | ||
errEl.appendChild(document.createTextNode( | ||
JSON.stringify(dataset, null, 2) + ' ' + String(error) | ||
)) | ||
} | ||
} | ||
|
||
teardown() { | ||
|
||
} | ||
} | ||
|
||
function findGluonWeb2() { | ||
const nodes = document.querySelectorAll('gluon-web2') | ||
|
||
let seen: Record<string, boolean> = {} | ||
|
||
for (let i = 0; i < nodes.length; i++) { | ||
let node = nodes[i] as HTMLElement | ||
|
||
if (!node.dataset.gluonWeb2) { | ||
node.dataset.gluonWeb2 = String(Math.random()) | ||
INSTANCES[node.dataset.gluonWeb2] = new GluonWeb2Instance(node) | ||
} | ||
|
||
seen[node.dataset.gluonWeb2] = true | ||
} | ||
|
||
for (const key of Object.keys(INSTANCES).filter(k => !seen[k])) { | ||
INSTANCES[key].teardown() | ||
delete INSTANCES[key] | ||
} | ||
} | ||
|
||
window.GluonWeb2Refresh = findGluonWeb2 | ||
|
||
findGluonWeb2() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.web2-error { | ||
background: #ff000080; | ||
color: black; | ||
padding: 1em; | ||
} |
Oops, something went wrong.