Skip to content

Commit

Permalink
wip: render choices
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jun 11, 2024
1 parent 79aa8d1 commit 79e07bd
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ linters-settings:
# with golangci-lint call it on a directory with the changed file.
check-exported: false

unparam:
unparams:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
Expand Down
1 change: 1 addition & 0 deletions cmd/server/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.R
app.Get("/workloads/partials/profiles", handlers.ListProfilesPartial())
app.Get("/workloads/:id/lenses/:lens", handlers.ShowWorkloadLens())
app.Get("/workloads/:id/lenses/:lens/edit", handlers.EditWorkloadLens())
app.Get("/workloads/:workload/lenses/:lens/question/:question", handlers.ShowLensQuestion())

err = app.Listen(s.cfg.Flags.Addr)
if err != nil {
Expand Down
154 changes: 154 additions & 0 deletions examples/sap.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,160 @@
"condition": "default"
}
]
},
{
"ref": "question_2",
"title": "Question 2 - A longer title for the lens.",
"description": "Question 1 asks about operational exelence",
"resources": [
{
"url": "https://de.wikipedia.org/wiki/Operational_Excellence",
"description": "Operational excellence is a mindset that embraces certain principles and tools to create a culture of excellence within an organization. Operational excellence means every employee can see, deliver, and improve the flow of value to a customer."
}
],
"choices": [
{
"ref": "choice_1",
"title": "Choice 1",
"description": "Choice 1 is provding a good choice."
},
{
"ref": "choice_2",
"title": "Choice 2",
"description": "Choice 2 is provding a good choice."
},
{
"ref": "choice_3",
"title": "Choice 3",
"description": "Choice 3 is provding a good choice."
},
{
"ref": "none_of_these",
"title": "None of these",
"description": "None of these"
}
],
"risks": [
{
"risk": "NO_RISK",
"condition": "choice_1 && choice_2 && choice_3"
},
{
"risk": "MEDIUM_RISK",
"condition": "(choice_1 || choice_2) && choice_3"
},
{
"risk": "HIGH_RISK",
"condition": "default"
}
]
}
],
"resources": [
{
"url": "https://de.wikipedia.org/wiki/Operational_Excellence",
"description": "Operational excellence is a mindset that embraces certain principles and tools to create a culture of excellence within an organization. Operational excellence means every employee can see, deliver, and improve the flow of value to a customer."
}
]
},
{
"ref": "cost_optimization",
"name": "Cost Optimization",
"description": "This is the evalution against optimizing for costs",
"questions": [
{
"ref": "question_1",
"title": "Question 1 - A longer title for the lens.",
"description": "Question 1 asks about operational exelence",
"resources": [
{
"url": "https://de.wikipedia.org/wiki/Operational_Excellence",
"description": "Operational excellence is a mindset that embraces certain principles and tools to create a culture of excellence within an organization. Operational excellence means every employee can see, deliver, and improve the flow of value to a customer."
}
],
"choices": [
{
"ref": "choice_1",
"title": "Choice 1",
"description": "Choice 1 is provding a good choice."
},
{
"ref": "choice_2",
"title": "Choice 2",
"description": "Choice 2 is provding a good choice."
},
{
"ref": "choice_3",
"title": "Choice 3",
"description": "Choice 3 is provding a good choice."
},
{
"ref": "none_of_these",
"title": "None of these",
"description": "None of these"
}
],
"risks": [
{
"risk": "NO_RISK",
"condition": "choice_1 && choice_2 && choice_3"
},
{
"risk": "MEDIUM_RISK",
"condition": "(choice_1 || choice_2) && choice_3"
},
{
"risk": "HIGH_RISK",
"condition": "default"
}
]
},
{
"ref": "question_2",
"title": "Question 2 - A longer title for the lens.",
"description": "Question 1 asks about operational exelence",
"resources": [
{
"url": "https://de.wikipedia.org/wiki/Operational_Excellence",
"description": "Operational excellence is a mindset that embraces certain principles and tools to create a culture of excellence within an organization. Operational excellence means every employee can see, deliver, and improve the flow of value to a customer."
}
],
"choices": [
{
"ref": "choice_1",
"title": "Choice 1",
"description": "Choice 1 is provding a good choice."
},
{
"ref": "choice_2",
"title": "Choice 2",
"description": "Choice 2 is provding a good choice."
},
{
"ref": "choice_3",
"title": "Choice 3",
"description": "Choice 3 is provding a good choice."
},
{
"ref": "none_of_these",
"title": "None of these",
"description": "None of these"
}
],
"risks": [
{
"risk": "NO_RISK",
"condition": "choice_1 && choice_2 && choice_3"
},
{
"risk": "MEDIUM_RISK",
"condition": "(choice_1 || choice_2) && choice_3"
},
{
"risk": "HIGH_RISK",
"condition": "default"
}
]
}
],
"resources": [
Expand Down
5 changes: 5 additions & 0 deletions internal/adapters/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func (t *datastoreTx) GetLens(ctx context.Context, lens *models.Lens) error {
First(lens).Error
}

// GetLensQuestion is a method that returns a lens question by ID
func (t *datastoreTx) GetLensQuestion(ctx context.Context, question *models.Question) error {
return t.tx.Preload("Choices").First(question).Error
}

// CreateLens is a method that creates a lens
func (t *datastoreTx) CreateLens(ctx context.Context, lens *models.Lens) error {
return t.tx.Create(lens).Error
Expand Down
7 changes: 7 additions & 0 deletions internal/adapters/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,10 @@ func (a *handlers) EditWorkloadLens() fiber.Handler {
return workloads.NewWorkloadLensEditController(a.store)
})
}

// ShowLensQuestion ...
func (a *handlers) ShowLensQuestion() fiber.Handler {
return htmx.NewHxControllerHandler(func() htmx.Controller {
return workloads.NewWorkloadLensEditQuestionController(a.store)
})
}
18 changes: 0 additions & 18 deletions internal/controllers/accounts/accounts.go

This file was deleted.

14 changes: 14 additions & 0 deletions internal/controllers/lenses/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func (l *LensShowControllerImpl) Get() error {
htmx.P(
htmx.Text(l.lens.Description),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
},
htmx.H4(
htmx.ClassNames{
"text-gray-500": true,
},
htmx.Text("ID"),
),
htmx.H3(htmx.Text(l.lens.ID.String())),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
Expand Down
15 changes: 10 additions & 5 deletions internal/controllers/workloads/lens-edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package workloads

import (
"context"
"fmt"

"github.com/google/uuid"
"github.com/zeiss/fiber-htmx/components/cards"
Expand All @@ -10,11 +11,14 @@ import (
"github.com/zeiss/service-lens/internal/components"
"github.com/zeiss/service-lens/internal/models"
"github.com/zeiss/service-lens/internal/ports"
"github.com/zeiss/service-lens/internal/utils"

htmx "github.com/zeiss/fiber-htmx"
)

const (
showLensQuestionURL = "/workloads/%s/lenses/%s/question/%d"
)

// WorkloadLensEditControllerImpl ...
type WorkloadLensEditControllerImpl struct {
workload models.Workload
Expand Down Expand Up @@ -76,11 +80,11 @@ func (w *WorkloadLensEditControllerImpl) Get() error {
},
drawers.DrawerContent(
drawers.DrawerContentProps{
ID: "pillars-drawer",
ClassNames: htmx.ClassNames{
"px-8": true,
},
},
htmx.ID("pillars-drawer-content"),
cards.CardBordered(
cards.CardProps{
ClassNames: htmx.ClassNames{
Expand Down Expand Up @@ -149,10 +153,11 @@ func (w *WorkloadLensEditControllerImpl) Get() error {
return menus.MenuItem(
menus.MenuItemProps{},
menus.MenuLink(
menus.MenuLinkProps{
Href: "/workloads/" + w.workload.ID.String() + "/lens/" + w.lens.ID.String() + "/question/" + utils.IntStr(q.ID),
},
menus.MenuLinkProps{},
htmx.Text(q.Title),
htmx.HxTarget("#pillars-drawer-content"),
htmx.HxGet(fmt.Sprintf(showLensQuestionURL, w.workload.ID, w.lens.ID, q.ID)),
htmx.HxSwap("innerHTML"),
),
)
})...,
Expand Down
Loading

0 comments on commit 79e07bd

Please sign in to comment.