diff --git a/app/common/meta.go b/app/common/meta.go index f8d7092..6d36b65 100644 --- a/app/common/meta.go +++ b/app/common/meta.go @@ -47,115 +47,3 @@ var MimeTypes = map[string]MimeType{ Minifier: nil, }, } - -type Icon struct { - ID string - Src string - Alt string - Clickable bool -} - -var Icons = map[string]map[string]Icon{ - "running": { - "status": { - Src: "images/status/active.svg", - Alt: "Instance is running", - Clickable: false, - }, - "power": { - Src: "images/actions/instance/stop.svg", - Alt: "Shutdown Instance", - Clickable: true, - }, - "config": { - Src: "images/actions/instance/config-inactive.svg", - Alt: "Change Configuration (Inactive)", - Clickable: false, - }, - "console": { - Src: "images/actions/instance/console-active.svg", - Alt: "Open Console", - Clickable: true, - }, - "delete": { - Src: "images/actions/delete-inactive.svg", - Alt: "Delete Instance (Inactive)", - Clickable: false, - }, - }, - "stopped": { - "status": { - Src: "images/status/inactive.svg", - Alt: "Instance is stopped", - Clickable: false, - }, - "power": { - Src: "images/actions/instance/start.svg", - Alt: "Start Instance", - Clickable: true, - }, - "config": { - Src: "images/actions/instance/config-active.svg", - Alt: "Change Configuration", - Clickable: true, - }, - "console": { - Src: "images/actions/instance/console-inactive.svg", - Alt: "Open Console (Inactive)", - Clickable: false, - }, - "delete": { - Src: "images/actions/delete-active.svg", - Alt: "Delete Instance", - Clickable: true, - }, - }, - "loading": { - "status": { - Src: "images/status/loading.svg", - Alt: "Instance is loading", - Clickable: false, - }, - "power": { - Src: "images/status/loading.svg", - Alt: "Loading Instance", - Clickable: false, - }, - "config": { - Src: "images/actions/instance/config-inactive.svg", - Alt: "Change Configuration (Inactive)", - Clickable: false, - }, - "console": { - Src: "images/actions/instance/console-inactive.svg", - Alt: "Open Console (Inactive)", - Clickable: false, - }, - "delete": { - Src: "images/actions/delete-inactive.svg", - Alt: "Delete Instance (Inactive)", - Clickable: false, - }, - }, - "online": { - "status": { - Src: "images/status/active.svg", - Alt: "Node is online", - Clickable: false, - }, - }, - "offline": { - "status": { - Src: "images/status/inactive.svg", - Alt: "Node is offline", - Clickable: false, - }, - }, - "unknown": { - "status": { - Src: "images/status/inactive.svg", - Alt: "Node is offline", - Clickable: false, - }, - }, -} diff --git a/app/common/types.go b/app/common/types.go index 1edf2fa..96b37fb 100644 --- a/app/common/types.go +++ b/app/common/types.go @@ -38,3 +38,10 @@ type Auth struct { Token string CSRF string } + +type Icon struct { + ID string + Src string + Alt string + Clickable bool +} diff --git a/app/routes/index.go b/app/routes/index.go index cae435f..246430f 100644 --- a/app/routes/index.go +++ b/app/routes/index.go @@ -16,22 +16,16 @@ type Node struct { } // used in constructing instance cards in index -type Instance struct { - VMID uint - Name string - Type string - Status string - Node string - StatusIcon common.Icon - NodeStatus string - NodeStatusIcon common.Icon - PowerBtnIcon common.Icon - ConsoleBtnIcon common.Icon - ConfigureBtnIcon common.Icon - DeleteBtnIcon common.Icon +type InstanceCard struct { + VMID uint + Name string + Type string + Status string + Node string + NodeStatus string } -func GetClusterResources(auth common.Auth) (map[uint]Instance, map[string]Node, error) { +func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]Node, error) { ctx := common.RequestContext{ Cookies: map[string]string{ "PVEAuthCookie": auth.Token, @@ -47,7 +41,7 @@ func GetClusterResources(auth common.Auth) (map[uint]Instance, map[string]Node, return nil, nil, fmt.Errorf("request to /cluster/resources/ resulted in %+v", res) } - instances := map[uint]Instance{} + instances := map[uint]InstanceCard{} nodes := map[string]Node{} // if we successfully retrieved the resources, then process it and return index @@ -61,7 +55,7 @@ func GetClusterResources(auth common.Auth) (map[uint]Instance, map[string]Node, } nodes[node.Node] = node } else if m["type"] == "lxc" || m["type"] == "qemu" { - instance := Instance{} + instance := InstanceCard{} err := mapstructure.Decode(v, &instance) if err != nil { return nil, nil, err @@ -70,21 +64,8 @@ func GetClusterResources(auth common.Auth) (map[uint]Instance, map[string]Node, } } for vmid, instance := range instances { - status := instance.Status - icons := common.Icons[status] - instance.StatusIcon = icons["status"] - instance.PowerBtnIcon = icons["power"] - instance.PowerBtnIcon.ID = "power-btn" - instance.ConfigureBtnIcon = icons["config"] - instance.ConfigureBtnIcon.ID = "configure-btn" - instance.ConsoleBtnIcon = icons["console"] - instance.ConsoleBtnIcon.ID = "console-btn" - instance.DeleteBtnIcon = icons["delete"] - instance.DeleteBtnIcon.ID = "delete-btn" nodestatus := nodes[instance.Node].Status - icons = common.Icons[nodestatus] instance.NodeStatus = nodestatus - instance.NodeStatusIcon = icons["status"] instances[vmid] = instance } return instances, nodes, nil diff --git a/web/images/actions/disk/delete-active.svg b/web/images/actions/disk/delete-active.svg new file mode 120000 index 0000000..edf683e --- /dev/null +++ b/web/images/actions/disk/delete-active.svg @@ -0,0 +1 @@ +../../common/delete-active.svg \ No newline at end of file diff --git a/web/images/actions/disk/delete-inactive.svg b/web/images/actions/disk/delete-inactive.svg new file mode 120000 index 0000000..9596a07 --- /dev/null +++ b/web/images/actions/disk/delete-inactive.svg @@ -0,0 +1 @@ +../../common/delete-inactive.svg \ No newline at end of file diff --git a/web/images/actions/instance/delete-active.svg b/web/images/actions/instance/delete-active.svg new file mode 120000 index 0000000..edf683e --- /dev/null +++ b/web/images/actions/instance/delete-active.svg @@ -0,0 +1 @@ +../../common/delete-active.svg \ No newline at end of file diff --git a/web/images/actions/instance/delete-inactive.svg b/web/images/actions/instance/delete-inactive.svg new file mode 120000 index 0000000..9596a07 --- /dev/null +++ b/web/images/actions/instance/delete-inactive.svg @@ -0,0 +1 @@ +../../common/delete-inactive.svg \ No newline at end of file diff --git a/web/images/actions/delete-active.svg b/web/images/common/delete-active.svg similarity index 100% rename from web/images/actions/delete-active.svg rename to web/images/common/delete-active.svg diff --git a/web/images/actions/delete-inactive.svg b/web/images/common/delete-inactive.svg similarity index 100% rename from web/images/actions/delete-inactive.svg rename to web/images/common/delete-inactive.svg diff --git a/web/templates/instance-card.tmpl b/web/templates/instance-card.tmpl index 76d558e..818365e 100644 --- a/web/templates/instance-card.tmpl +++ b/web/templates/instance-card.tmpl @@ -15,19 +15,46 @@
{{.Name}}
{{.Status}}