-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from tunnels-is/datacenter-updates
Show datacenters in frontend, generate rows, GET Rows route
- Loading branch information
Showing
19 changed files
with
305 additions
and
51 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
args_bin = [] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ." | ||
delay = 1000 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
poll = false | ||
poll_interval = 0 | ||
post_cmd = [] | ||
pre_cmd = [] | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = false | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = false | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[proxy] | ||
app_port = 0 | ||
enabled = false | ||
proxy_port = 0 | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
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 @@ | ||
/tmp |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 +1,54 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import ky from 'ky'; | ||
import { useEffect, useState } from 'react'; | ||
import { API_URL, DatacenterType } from './config/config'; | ||
import DatacenterComponent from './components/Datacenter'; | ||
|
||
const WS_URL = 'ws://localhost:1323/v1/json/dynamic'; | ||
|
||
function App() { | ||
const [message, setMessage] = useState(''); | ||
const [socket, setSocket] = useState<WebSocket | null>(null); | ||
|
||
useEffect(() => { | ||
const socket = new WebSocket(WS_URL); | ||
setSocket(socket); | ||
|
||
socket.addEventListener('open', () => { | ||
console.log('Connected to server'); | ||
socket.send('{"disk":0,"cpu":10,"memory":50,"sub":{"key1":1377}}'); | ||
}); | ||
|
||
socket.addEventListener('message', (event) => { | ||
console.log('Message from server ', event.data); | ||
setMessage(event.data); | ||
}); | ||
|
||
socket.addEventListener('error', (error) => { | ||
console.error('WebSocket error: ', error); | ||
}); | ||
|
||
return () => { | ||
socket.close(); | ||
}; | ||
}, []); | ||
|
||
const sendMessage = () => { | ||
if (socket && socket.readyState === WebSocket.OPEN) { | ||
socket.send('Hello World!'); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>WebSocket Example</h1> | ||
<p>Message from server: {message}</p> | ||
<button onClick={sendMessage}>Send Message</button> | ||
</div> | ||
); | ||
const [socket, setSocket] = useState<WebSocket | null>(null); | ||
|
||
useEffect(() => { | ||
const socket = new WebSocket(WS_URL); | ||
setSocket(socket); | ||
|
||
socket.addEventListener('open', () => { | ||
console.log('Connected to server'); | ||
socket.send('{"disk":0,"cpu":10,"memory":50,"sub":{"key1":1377}}'); | ||
}); | ||
|
||
socket.addEventListener('message', (event) => { | ||
console.log('Message from server ', event.data); | ||
}); | ||
|
||
socket.addEventListener('error', (error) => { | ||
console.error('WebSocket error: ', error); | ||
}); | ||
|
||
return () => { | ||
socket.close(); | ||
}; | ||
}, []); | ||
|
||
const [dataCenters, setDataCenters] = useState<Array<DatacenterType>>(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const json = await ky.get(`${API_URL}/datacenters`).json(); | ||
setDataCenters(json as Array<DatacenterType>); | ||
}; | ||
console.log(dataCenters); | ||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<div className="m-3"> | ||
<h1 className="text-3xl my-3">Name?? Dashboard Stats Logo??</h1> | ||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4"> | ||
{dataCenters?.map((item) => <DatacenterComponent dataCenter={item} />)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
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,30 @@ | ||
import { API_URL, DatacenterType, RowType } from '@/config/config'; | ||
import ky from 'ky'; | ||
import { useEffect, useState } from 'react'; | ||
import Row from './Row'; | ||
|
||
const Datacenter = ({ dataCenter }: { dataCenter: DatacenterType }) => { | ||
const [rows, setRows] = useState<RowType[]>(); | ||
|
||
useEffect(() => { | ||
const getRows = async () => { | ||
const json = await ky | ||
.get(`${API_URL}/rows/datacenter/${dataCenter.ID}`) | ||
.json(); | ||
setRows(json as RowType[]); | ||
console.log(json); | ||
}; | ||
getRows(); | ||
}, []); | ||
|
||
return ( | ||
<div className="m-3"> | ||
Datacenter {dataCenter.Tag}/{dataCenter.ID} | ||
<div className="w-fit p-3 min-h-56 min-w-72 w-full border-2 border-gray-600"> | ||
{rows?.map((row) => <Row Row={row} />)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Datacenter; |
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,12 @@ | ||
import { RowType } from '@/config/config'; | ||
|
||
const Row = ({ Row }: { Row: RowType }) => { | ||
return ( | ||
<div className="my-5 w-full"> | ||
Row {Row.Tag}/{Row.ID} | ||
<div className="w-full h-10 border-2 border-gray-600 "></div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Row; |
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,14 @@ | ||
export const API_URL = 'http://localhost:1323/v1/api'; | ||
|
||
export interface DatacenterType { | ||
ID: number; | ||
Tag: string; | ||
Info: string; | ||
} | ||
|
||
export interface RowType { | ||
ID: number; | ||
Tag: string; | ||
Info: string; | ||
DatacenterID: number; | ||
} |
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
Oops, something went wrong.