forked from zmc/pulpito-ng
-
Notifications
You must be signed in to change notification settings - Fork 9
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
9 changed files
with
165 additions
and
116 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
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,35 @@ | ||
import { usePageContext } from 'vike-react/usePageContext' | ||
import { navigate } from 'vike/client/router' | ||
|
||
const machineTypes = [ | ||
"smithi", | ||
"mira", | ||
] | ||
|
||
export default function MachineTypeSelector() { | ||
const context = usePageContext(); | ||
const selected = context.urlParsed.search.machine_type; | ||
|
||
const getUrl = (machine_type: string) => { | ||
const newUrl = new URL(context.urlPathname, window.location.origin); | ||
newUrl.searchParams.set("machine_type", machine_type); | ||
return newUrl; | ||
}; | ||
const onChange = (value: string) => { | ||
const newUrl = getUrl(value); | ||
navigate(newUrl.pathname + newUrl.search); | ||
|
||
}; | ||
return ( | ||
<> | ||
<span>Machine Type</span> | ||
<select onChange={e => onChange(e.target.value)}> | ||
{ machineTypes.includes(selected)? null : <option value={selected}>{selected}</option> } | ||
{ machineTypes.map(value => { | ||
const isSelected = value === selected? {"selected": true} : {} | ||
return <option value={value} key={value} {...isSelected}>{value}</option> | ||
}) } | ||
</select> | ||
</> | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useData } from 'vike-react/useData' | ||
import { Config } from 'vike-react/Config' | ||
|
||
import Typography from "@mui/material/Typography"; | ||
|
||
import MachineTypeSelector from "#src/components/MachineTypeSelector"; | ||
import NodeList from "../../components/NodeList"; | ||
|
||
import type { NodesResponse } from "./+data" | ||
|
||
|
||
export default function Nodes() { | ||
const data = useData<NodesResponse>(); | ||
return ( | ||
<div> | ||
<Config title="Nodes - Pulpito" /> | ||
<Typography variant="h5" style={{ margin: "20px" }}> | ||
Nodes | ||
</Typography> | ||
<div style={{ height: "auto", display: "flex" }}> | ||
<div style={{ display: "flex", flexWrap: "wrap", marginLeft: "auto" }}> | ||
<div> | ||
<Typography style={{ padding: "10px" }}> | ||
Filter by: | ||
</Typography> | ||
</div> | ||
<MachineTypeSelector /> | ||
</div> | ||
</div> | ||
<NodeList nodes={data.nodes}/> | ||
</div> | ||
); | ||
} |
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,16 @@ | ||
import type { PageContext } from 'vike/types' | ||
|
||
import { getURL } from "#src/lib/paddles"; | ||
import type { Node } from "#src/lib/paddles.d"; | ||
|
||
export type NodesResponse = { | ||
nodes: Node[]; | ||
} | ||
|
||
export default async function data(pageContext: PageContext): Promise<NodesResponse> { | ||
const url = getURL('/nodes/', pageContext.urlParsed.search); | ||
const response = await fetch(url); | ||
if ( response.ok ) return {nodes: await response.json()}; | ||
return {nodes: []}; | ||
} | ||
|
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,31 @@ | ||
import { useData } from 'vike-react/useData' | ||
import { usePageContext } from 'vike-react/usePageContext' | ||
import { Config } from 'vike-react/Config' | ||
|
||
import Typography from "@mui/material/Typography"; | ||
|
||
import JobList from "#src/components/JobList"; | ||
import NodeList from "#src/components/NodeList"; | ||
|
||
import { type NodeResponse } from "./+data" | ||
|
||
export default function Node() { | ||
const data = useData<NodeResponse>(); | ||
const context = usePageContext(); | ||
const name = context.routeParams.name; | ||
return ( | ||
<div> | ||
<Config title={`${name} - Pulpito`} /> | ||
<Typography variant="h6" style={{ marginBottom: "20px" }}> | ||
Node: {name} | ||
</Typography> | ||
|
||
<div> | ||
<div> | ||
<NodeList nodes={data.nodes}/> | ||
<JobList sortMode={"time"} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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,25 @@ | ||
import type { PageContext } from 'vike/types' | ||
import { render } from 'vike/abort' | ||
|
||
import { getURL } from "#src/lib/paddles"; | ||
import type { Job, Node } from "#src/lib/paddles.d"; | ||
|
||
export type NodeResponse = { | ||
jobs: Job[]; | ||
nodes: Node[]; | ||
} | ||
|
||
export default async function data(pageContext: PageContext): Promise<NodeResponse> { | ||
const nodeUrl = getURL(`/nodes/${pageContext.routeParams.name}`, pageContext.urlParsed.search); | ||
const jobsUrl = getURL(`/nodes/${pageContext.routeParams.name}/jobs`, pageContext.urlParsed.search); | ||
const [nodeResponse, jobsResponse] = await Promise.all([fetch(nodeUrl), fetch(jobsUrl)]); | ||
const result: NodeResponse = {jobs: [], nodes: []}; | ||
if ( nodeResponse.status === 404 ) throw render( | ||
nodeResponse.status, | ||
`Node "${pageContext.routeParams.name}" does not exist` | ||
); | ||
else if ( nodeResponse.ok ) result.nodes = [await nodeResponse.json()]; | ||
if ( jobsResponse.ok ) result.jobs = await jobsResponse.json(); | ||
return result; | ||
} | ||
|