Implement graphql api client and update gui to display data
This commit is contained in:
+42
-8
@@ -3,11 +3,15 @@ package screens
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/widget"
|
||||
)
|
||||
|
||||
type CursoriusServer struct {
|
||||
@@ -16,8 +20,11 @@ type CursoriusServer struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
func (s CursoriusServer) Login() ScreenSwitchMsg {
|
||||
dashboard := createDashboard(s)
|
||||
func (s CursoriusServer) Login() tea.Msg {
|
||||
dashboard, err := createDashboard(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ScreenSwitchMsg{
|
||||
NewScreen: dashboard,
|
||||
}
|
||||
@@ -47,6 +54,7 @@ type Dashboard struct {
|
||||
activeTab int
|
||||
width int
|
||||
height int
|
||||
client graphql.Client
|
||||
}
|
||||
|
||||
func (m Dashboard) Init() tea.Cmd {
|
||||
@@ -147,14 +155,39 @@ func (d dashboardItemDelegate) Render(w io.Writer, m list.Model, index int, list
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
|
||||
func createDashboard(s CursoriusServer) Dashboard {
|
||||
func createDashboard(s CursoriusServer) (Dashboard, error) {
|
||||
|
||||
client := graphql.NewClient(s.Url, http.DefaultClient)
|
||||
|
||||
tabs := []string{"Pipelines", "Secrets", "Clone Credentials", "Runners"}
|
||||
content := []list.Item{dashboardItem("Pipelines"), dashboardItem("Secrets"), dashboardItem("Clone Credentials"), dashboardItem("Runners")}
|
||||
//testTabs := []list.Item{dashboardItem("Pipelines"), dashboardItem("Secrets"), dashboardItem("Clone Credentials"), dashboardItem("Runners")}
|
||||
|
||||
pipelineWidget, err := widget.CreatePipelineWidget(client)
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("Could not create Pipelines tab: %w", err)
|
||||
}
|
||||
|
||||
secretWidget, err := widget.CreateSecretWidget(client)
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("Could not create Secrets tab: %w", err)
|
||||
}
|
||||
|
||||
cloneCredentialWidget, err := widget.CreateCloneCredentialWidget(client)
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("Could not create Clone Credentials tab: %w", err)
|
||||
}
|
||||
|
||||
runnerWidget, err := widget.CreateRunnerWidget(client)
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("Could not create Runner tab: %w", err)
|
||||
}
|
||||
|
||||
tabContent := []list.Model{
|
||||
list.New(content, dashboardItemDelegate{}, 50, 50),
|
||||
list.New(content, dashboardItemDelegate{}, 50, 50),
|
||||
list.New(content, dashboardItemDelegate{}, 50, 50),
|
||||
//list.New(testTabs, dashboardItemDelegate{}, 50, 50),
|
||||
pipelineWidget,
|
||||
secretWidget,
|
||||
cloneCredentialWidget,
|
||||
runnerWidget,
|
||||
}
|
||||
|
||||
return Dashboard{
|
||||
@@ -162,7 +195,8 @@ func createDashboard(s CursoriusServer) Dashboard {
|
||||
TabContent: tabContent,
|
||||
width: 50,
|
||||
height: 50,
|
||||
}
|
||||
client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
|
||||
Reference in New Issue
Block a user