Skip to content
Snippets Groups Projects
Commit 69ec03b6 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

misc improvements

parent 176c00eb
Branches
No related tags found
No related merge requests found
...@@ -2,11 +2,11 @@ package models ...@@ -2,11 +2,11 @@ package models
import "github.com/eddieowens/go-enum" import "github.com/eddieowens/go-enum"
var possibleDeviceTypes = func() []enum.Const { var PossibleDeviceTypes = func() []enum.Const {
types := enum.New(new(DeviceType)).(*DeviceType) types := enum.New(new(DeviceType)).(*DeviceType)
return types.GetAll() return types.GetAll()
}() }()
var possibleLocations = func() []enum.Const { var PossibleLocations = func() []enum.Const {
types := enum.New(new(Location)).(*Location) types := enum.New(new(Location)).(*Location)
return types.GetAll() return types.GetAll()
}() }()
...@@ -29,11 +29,11 @@ var deviceSchema = jsonMap{ ...@@ -29,11 +29,11 @@ var deviceSchema = jsonMap{
}, },
"Type": jsonMap{ "Type": jsonMap{
"type": "string", "type": "string",
"enum": possibleDeviceTypes, "enum": PossibleDeviceTypes,
}, },
"Location": jsonMap{ "Location": jsonMap{
"type": "string", "type": "string",
"enum": possibleLocations, "enum": PossibleLocations,
}, },
"PowerConsumption": jsonMap{ "PowerConsumption": jsonMap{
"type": "number", "type": "number",
......
...@@ -37,6 +37,8 @@ func renderTemplate(c *gin.Context) { ...@@ -37,6 +37,8 @@ func renderTemplate(c *gin.Context) {
} }
c.HTML(http.StatusOK, "index.html", gin.H{ c.HTML(http.StatusOK, "index.html", gin.H{
"graph": graph, "graph": graph,
"types": models.PossibleDeviceTypes,
"locations": models.PossibleLocations,
"visjs": visjs, "visjs": visjs,
}) })
} }
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Power meme</title> <title>Power meme</title>
<script type="text/javascript" src="https://visjs.github.io/vis-network/standalone/umd/vis-network.min.js"></script> <script type="text/javascript" src="https://visjs.github.io/vis-network/standalone/umd/vis-network.min.js"></script>
</head>
<style> <style>
html, body, #canvas { html, body, #canvas {
width: 100%; width: 100%;
...@@ -26,6 +25,7 @@ ...@@ -26,6 +25,7 @@
cursor: pointer; cursor: pointer;
} }
</style> </style>
</head>
<body> <body>
<button id="reload" onclick="reload()">reload</button> <button id="reload" onclick="reload()">reload</button>
<div id="canvas"></div> <div id="canvas"></div>
...@@ -97,10 +97,10 @@ ...@@ -97,10 +97,10 @@
}, },
manipulation: { manipulation: {
addNode: async function(nodeData,callback) { addNode: async function(nodeData,callback) {
const type = prompt("Type? (server, powerstrip, uplink, ups, switch)", "server"); const type = prompt("Type? {{ .types }}", "server");
const name = prompt("Name?", "node69") const name = prompt("Name?", "node69")
const power = prompt("Power usage?", "420") const power = prompt("Power usage?", "420")
const location = prompt("Location?", "rack1") const location = prompt("Location? {{ .locations }}", "rack1")
const resp = await fetch("/api/devices", { const resp = await fetch("/api/devices", {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment