-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
56b8a84
commit b1e7709
Showing
13 changed files
with
905 additions
and
196 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
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,43 @@ | ||
package components | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"io" | ||
"os" | ||
|
||
"github.com/glasskube/glasskube/pkg/client" | ||
"github.com/glasskube/glasskube/pkg/list" | ||
) | ||
|
||
func GetButtonId(pkgName string) string { | ||
return fmt.Sprintf("install-%v", pkgName) | ||
} | ||
|
||
func GetSwap(buttonId string) string { | ||
return fmt.Sprintf("outerHTML:#%s", buttonId) | ||
} | ||
|
||
func RenderInstallButton(w io.Writer, tmpl *template.Template, pkgName string, status *client.PackageStatus) { | ||
buttonId := GetButtonId(pkgName) | ||
err := tmpl.ExecuteTemplate(w, "installbutton", &map[string]any{ | ||
"ButtonId": buttonId, | ||
"Swap": GetSwap(buttonId), | ||
"PackageName": pkgName, | ||
"Status": status, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "An error occurred rendering the install button for %v: \n%v\n"+ | ||
"This is most likely a BUG!", pkgName, err) | ||
} | ||
} | ||
|
||
func ToInstallButtonInput(pkgTeaser list.PackageTeaserWithStatus) map[string]any { | ||
buttonId := GetButtonId(pkgTeaser.PackageName) | ||
return map[string]any{ | ||
"ButtonId": buttonId, | ||
"Swap": GetSwap(buttonId), | ||
"PackageName": pkgTeaser.PackageName, | ||
"Status": pkgTeaser.Status, | ||
} | ||
} |
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,45 @@ | ||
package web | ||
|
||
// Hub maintains the set of active clients and broadcasts messages to the clients. | ||
type Hub struct { | ||
// Inbound messages from the clients. | ||
Broadcast chan []byte | ||
|
||
// Register requests from the clients. | ||
Register chan *WsClient | ||
|
||
// Unregister requests from clients. | ||
Unregister chan *WsClient | ||
|
||
// Registered clients. | ||
clients map[*WsClient]bool | ||
} | ||
|
||
// NewHub creates new Hub | ||
func NewHub() *Hub { | ||
return &Hub{ | ||
Broadcast: make(chan []byte), | ||
Register: make(chan *WsClient), | ||
Unregister: make(chan *WsClient), | ||
clients: make(map[*WsClient]bool), | ||
} | ||
} | ||
|
||
// Run handles communication operations with Hub | ||
func (h *Hub) Run() { | ||
for { | ||
select { | ||
case client := <-h.Register: | ||
h.clients[client] = true | ||
case client := <-h.Unregister: | ||
if _, ok := h.clients[client]; ok { | ||
delete(h.clients, client) | ||
close(client.send) | ||
} | ||
case message := <-h.Broadcast: | ||
for client := range h.clients { | ||
client.send <- message | ||
} | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.