Implement graphql api client and update gui to display data
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/queries"
|
||||
)
|
||||
|
||||
type cloneCredentialListItem struct {
|
||||
name string
|
||||
widgetType string
|
||||
id string
|
||||
}
|
||||
|
||||
type cloneCredentialCreateListItem string
|
||||
|
||||
func (i cloneCredentialListItem) FilterValue() string { return "" }
|
||||
func (i cloneCredentialCreateListItem) FilterValue() string { return "" }
|
||||
|
||||
type cloneCredentialListItemDelegate struct{}
|
||||
|
||||
func (d cloneCredentialListItemDelegate) Height() int { return 1 }
|
||||
func (d cloneCredentialListItemDelegate) Spacing() int { return 0 }
|
||||
func (d cloneCredentialListItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
|
||||
func (d cloneCredentialListItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
|
||||
switch i := listItem.(type) {
|
||||
case cloneCredentialListItem:
|
||||
fn := itemStyle.Render
|
||||
faintFn := faintItemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
faintFn = faintSelectedItemStyle.Render
|
||||
}
|
||||
|
||||
str := fn(i.name) + faintFn(" ("+i.id+")")
|
||||
fmt.Fprint(w, str)
|
||||
case cloneCredentialCreateListItem:
|
||||
fn := itemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
}
|
||||
|
||||
str := string(i)
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
}
|
||||
|
||||
func CreateCloneCredentialWidget(client graphql.Client) (list.Model, error) {
|
||||
content := []list.Item{}
|
||||
|
||||
getCloneCredentialResp, err := queries.GetCloneCredentials(context.Background(), client)
|
||||
if err != nil {
|
||||
return list.Model{}, fmt.Errorf("Could not connect to server: %w", err)
|
||||
}
|
||||
|
||||
if getCloneCredentialResp.CloneCredentials == nil {
|
||||
|
||||
for _, cloneCredential := range getCloneCredentialResp.CloneCredentials {
|
||||
content = append(content, cloneCredentialListItem{
|
||||
name: cloneCredential.Name,
|
||||
id: cloneCredential.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
content = append(content, cloneCredentialCreateListItem("> Create Clone Credential <"))
|
||||
|
||||
model := list.New(content, cloneCredentialListItemDelegate{}, 50, 50)
|
||||
model.SetShowStatusBar(false)
|
||||
model.Title = "Clone Credentials"
|
||||
|
||||
return model, nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var (
|
||||
titleStyle = lipgloss.NewStyle().MarginLeft(2)
|
||||
itemStyle = lipgloss.NewStyle().PaddingLeft(4)
|
||||
faintItemStyle = lipgloss.NewStyle().Faint(true)
|
||||
selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("170"))
|
||||
faintSelectedItemStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("170")).Faint(true)
|
||||
paginationStyle = list.DefaultStyles().PaginationStyle.PaddingLeft(4)
|
||||
helpStyle = list.DefaultStyles().HelpStyle.PaddingLeft(4).PaddingBottom(1)
|
||||
quitTextStyle = lipgloss.NewStyle().Margin(1, 0, 2, 4)
|
||||
)
|
||||
@@ -0,0 +1,81 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/queries"
|
||||
)
|
||||
|
||||
type pipelineListItem struct {
|
||||
name string
|
||||
id string
|
||||
}
|
||||
|
||||
type pipelineCreateListItem string
|
||||
|
||||
func (i pipelineListItem) FilterValue() string { return "" }
|
||||
func (i pipelineCreateListItem) FilterValue() string { return "" }
|
||||
|
||||
type pipelineListItemDelegate struct{}
|
||||
|
||||
func (d pipelineListItemDelegate) Height() int { return 1 }
|
||||
func (d pipelineListItemDelegate) Spacing() int { return 0 }
|
||||
func (d pipelineListItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
|
||||
func (d pipelineListItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
|
||||
switch i := listItem.(type) {
|
||||
case pipelineListItem:
|
||||
fn := itemStyle.Render
|
||||
faintFn := faintItemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
faintFn = faintSelectedItemStyle.Render
|
||||
}
|
||||
|
||||
str := fn(i.name) + faintFn(" ("+i.id+")")
|
||||
fmt.Fprint(w, str)
|
||||
case pipelineCreateListItem:
|
||||
fn := itemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
}
|
||||
|
||||
str := string(i)
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePipelineWidget(client graphql.Client) (list.Model, error) {
|
||||
content := []list.Item{}
|
||||
|
||||
getPipelineResp, err := queries.GetPipelines(context.Background(), client)
|
||||
if err != nil {
|
||||
return list.Model{}, fmt.Errorf("Could not connect to server: %w", err)
|
||||
}
|
||||
|
||||
if getPipelineResp.Pipelines != nil {
|
||||
for _, pipeline := range getPipelineResp.Pipelines {
|
||||
content = append(content, pipelineListItem{
|
||||
name: pipeline.Name,
|
||||
id: pipeline.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
content = append(content, pipelineCreateListItem("> Create Pipeline <"))
|
||||
|
||||
model := list.New(content, pipelineListItemDelegate{}, 50, 50)
|
||||
model.SetShowStatusBar(false)
|
||||
model.Title = "Pipelines"
|
||||
|
||||
return model, nil
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/queries"
|
||||
)
|
||||
|
||||
type runnerListItem struct {
|
||||
name string
|
||||
id string
|
||||
}
|
||||
|
||||
type runnerCreateListItem string
|
||||
|
||||
func (i runnerListItem) FilterValue() string { return "" }
|
||||
func (i runnerCreateListItem) FilterValue() string { return "" }
|
||||
|
||||
type runnerListItemDelegate struct{}
|
||||
|
||||
func (d runnerListItemDelegate) Height() int { return 1 }
|
||||
func (d runnerListItemDelegate) Spacing() int { return 0 }
|
||||
func (d runnerListItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
|
||||
func (d runnerListItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
|
||||
switch i := listItem.(type) {
|
||||
case runnerListItem:
|
||||
fn := itemStyle.Render
|
||||
faintFn := faintItemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
faintFn = faintSelectedItemStyle.Render
|
||||
}
|
||||
|
||||
str := fn(i.name) + faintFn(" ("+i.id+")")
|
||||
fmt.Fprint(w, str)
|
||||
case runnerCreateListItem:
|
||||
fn := itemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
}
|
||||
|
||||
str := string(i)
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
}
|
||||
|
||||
func CreateRunnerWidget(client graphql.Client) (list.Model, error) {
|
||||
content := []list.Item{}
|
||||
|
||||
getRunnerResp, err := queries.GetRunners(context.Background(), client)
|
||||
if err != nil {
|
||||
return list.Model{}, fmt.Errorf("Could not connect to server: %w", err)
|
||||
}
|
||||
|
||||
if getRunnerResp.Runners == nil {
|
||||
|
||||
for _, cloneCredential := range getRunnerResp.Runners {
|
||||
content = append(content, runnerCreateListItem(cloneCredential.Name))
|
||||
}
|
||||
}
|
||||
|
||||
content = append(content, runnerCreateListItem("> Create Runner <"))
|
||||
|
||||
model := list.New(content, runnerListItemDelegate{}, 50, 50)
|
||||
model.SetShowStatusBar(false)
|
||||
model.Title = "Runners"
|
||||
|
||||
return model, nil
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/queries"
|
||||
)
|
||||
|
||||
type secretListItem struct {
|
||||
name string
|
||||
id string
|
||||
}
|
||||
|
||||
type secretCreateListItem string
|
||||
|
||||
func (i secretListItem) FilterValue() string { return "" }
|
||||
func (i secretCreateListItem) FilterValue() string { return "" }
|
||||
|
||||
type secretListItemDelegate struct{}
|
||||
|
||||
func (d secretListItemDelegate) Height() int { return 1 }
|
||||
func (d secretListItemDelegate) Spacing() int { return 0 }
|
||||
func (d secretListItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
|
||||
func (d secretListItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
|
||||
switch i := listItem.(type) {
|
||||
case secretListItem:
|
||||
fn := itemStyle.Render
|
||||
faintFn := faintItemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
faintFn = faintSelectedItemStyle.Render
|
||||
}
|
||||
|
||||
str := fn(i.name) + faintFn(" ("+i.id+")")
|
||||
fmt.Fprint(w, str)
|
||||
case secretCreateListItem:
|
||||
fn := itemStyle.Render
|
||||
if index == m.Index() {
|
||||
fn = func(s string) string {
|
||||
return selectedItemStyle.Render("> " + s)
|
||||
}
|
||||
}
|
||||
|
||||
str := string(i)
|
||||
fmt.Fprint(w, fn(str))
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSecretWidget(client graphql.Client) (list.Model, error) {
|
||||
content := []list.Item{}
|
||||
|
||||
getSecretResp, err := queries.GetSecrets(context.Background(), client)
|
||||
if err != nil {
|
||||
return list.Model{}, fmt.Errorf("Could not connect to server: %w", err)
|
||||
}
|
||||
|
||||
if getSecretResp.Secrets == nil {
|
||||
|
||||
for _, secret := range getSecretResp.Secrets {
|
||||
content = append(content, secretListItem{
|
||||
name: secret.Name,
|
||||
id: secret.Id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
content = append(content, secretCreateListItem("> Create Secret <"))
|
||||
|
||||
model := list.New(content, secretListItemDelegate{}, 50, 50)
|
||||
model.SetShowStatusBar(false)
|
||||
model.Title = "Secrets"
|
||||
|
||||
return model, nil
|
||||
}
|
||||
Reference in New Issue
Block a user