Skip to content

Commit

Permalink
types tabs, and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoOliveira committed Jul 15, 2024
1 parent 2d95e9f commit 8bfa3b0
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 25 deletions.
6 changes: 3 additions & 3 deletions cmd/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func main() {
server.Use(mw.CtxMiddleware())
server.Use(middleware.CORS())
server.Use(middleware.Logger())
//server.Use(middleware.Recover())
server.Use(middleware.Recover())

_, err := library.New(server.Group("/lib"))
l, err := library.New(server.Group("/lib"))
if err != nil {
log.Fatalf("Error initializing library: %v", err)
}

//l.ScanAsync()
l.ScanAsync()

slog.Info("Starting agent")
log.Fatal(server.Start(fmt.Sprintf(":%d", config.Cfg.Server.Port)))
Expand Down
4 changes: 4 additions & 0 deletions v2/config/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ type AssetType struct {
Extensions []string `json:"extensions" mapstructure:"extensions"`
Order int `json:"order" mapstructure:"order"`
}

func (a AssetType) Compare(b AssetType) int {
return a.Order - b.Order
}
1 change: 1 addition & 0 deletions v2/library/entities/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewAssetFromRootPath(root, path string, isDir bool, parent *Asset) *Asset {
} else {
asset.NodeKind = utils.Ptr(NodeKindDir)
}
asset.Kind = utils.Ptr("dir")
return asset
}

Expand Down
20 changes: 12 additions & 8 deletions v2/library/web/comp/assetcard.templ
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ css bgimg(url string) {
templ AssetCard(m *AssetCardModel) {
//https://merakiui.com/components/application-ui/cards
<div class="flex flex-col items-center justify-center w-full max-w-sm mx-auto m-1 w-max-128">
<div
class={ "w-full h-64 bg-gray-300 bg-center bg-cover rounded-lg shadow-md", bgimg(utils.VoZ(m.Asset.Thumbnail)) }
hx-get={ fmt.Sprintf("/lib/%s", m.Asset.ID) }
hx-target=".asset-view"
hx-trigger="click"
hx-push-url="true"
></div>
if utils.VoZ(m.Asset.NodeKind) == "dir" || utils.VoZ(m.Asset.NodeKind) == "bundle" {
<div
class={ "w-full h-64 bg-gray-300 bg-center bg-cover rounded-lg shadow-md", bgimg(utils.VoZ(m.Asset.Thumbnail)) }
hx-get={ fmt.Sprintf("/lib/%s", m.Asset.ID) }
hx-target=".asset-view"
hx-trigger="click"
hx-push-url="true"
></div>
} else {
<div class={ "w-full h-64 bg-gray-300 bg-center bg-cover rounded-lg shadow-md", bgimg(utils.VoZ(m.Asset.Thumbnail)) }></div>
}
<div class="w-56 -mt-10 overflow-hidden bg-white rounded-lg shadow-lg md:w-64 dark:bg-gray-800">
<h3 class="p-2 font-bold tracking-wide text-center text-gray-800 uppercase dark:text-white trucate whitespace-nowrap">{ *m.Asset.Label }</h3>
<div class="flex items-center justify-between px-3 py-2 bg-gray-200 dark:bg-gray-700">
<span class="font-bold text-gray-800 dark:text-gray-200">$129</span>
<span class="font-bold text-gray-800 dark:text-gray-200">{ utils.VoZ(m.Asset.Kind) }</span>
<button class="px-2 py-1 text-xs font-semibold text-white uppercase transition-colors duration-300 transform bg-gray-800 rounded hover:bg-gray-700 dark:hover:bg-gray-600 focus:bg-gray-700 dark:focus:bg-gray-600 focus:outline-none">Add to cart</button>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion v2/library/web/comp/edit.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import "github.com/eduardooliveira/stLib/v2/utils"

templ Edit(m *EditModel) {
<div>
<h1>Edit { m.Action }</h1>
<h1>Edit</h1>
<form hx-post="/lib/edit" hx-target="#asset-sidebar">
<input type="hidden" name="id" value={ m.Asset.ID }/>
<div>
<label class="text-gray-700 dark:text-gray-200" for="label">Label</label>
<input value={ utils.VoZ(m.Asset.Label) } id="label" type="text" class="block w-full px-4 py-2 mt-2 text-gray-700 bg-white border border-gray-200 rounded-md dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:border-blue-400 focus:ring-blue-300 focus:ring-opacity-40 dark:focus:border-blue-300 focus:outline-none focus:ring"/>
</div>
<input type="text" name="label" value={ utils.VoZ(m.Asset.Label) }/>
<input type="text" name="description" value={ utils.VoZ(m.Asset.Description) }/>
<button class="btn btn-sm">Save</button>
Expand Down
12 changes: 9 additions & 3 deletions v2/library/web/comp/index.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package comp
import "github.com/eduardooliveira/stLib/v2/utils"

templ Index(model IndexModel) {
<div class="h-full w-full flex flex-col asset-view">
<div class="h-full w-full flex flex-col asset-view p-2">
<div class="header">
<h1 class="label">{ utils.VoZ(model.Asset.Label) }</h1>
<input type="text" id="asset-id" name="assetID" value={ model.Asset.ID }/>
<h1 class="label text-lg font-semibold text-gray-700 capitalize dark:text-white">{ utils.VoZ(model.Asset.Label) }</h1>
<input class="hidden" type="text" id="asset-id" name="assetID" value={ model.Asset.ID }/>
</div>
<div class="flex-initial">
@BreadCrumbs(model.Asset.Parent)
</div>
<div role="tablist" class="tabs tabs-boxed">
<a role="tab" class="tab tab-active">All</a>
for _, t := range model.AssetTypes {
<a role="tab" class="tab">{ t.Label }</a>
}
</div>
<div class="flex-auto overflow-y-auto main">
@model.Main
</div>
Expand Down
6 changes: 4 additions & 2 deletions v2/library/web/comp/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package comp

import (
"github.com/a-h/templ"
"github.com/eduardooliveira/stLib/v2/config"
"github.com/eduardooliveira/stLib/v2/library/entities"
"github.com/eduardooliveira/stLib/v2/web/helpers"

corecomp "github.com/eduardooliveira/stLib/v2/web/comp"
)

type IndexModel struct {
Asset *entities.Asset
Main templ.Component
Asset *entities.Asset
AssetTypes []config.AssetType
Main templ.Component
}

type ListModel struct {
Expand Down
6 changes: 2 additions & 4 deletions v2/library/web/comp/sidebar.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package comp

templ SideBar() {
<div class="flex flex-row-reverse">
<div class="flex flex-row-reverse mt-1">
<div class="flex flex-col bg-blue-400">
<button
class="btn btn-sm"
Expand All @@ -18,8 +18,6 @@ templ SideBar() {
<button class="btn btn-sm">b</button>
<button class="btn btn-sm">b</button>
</div>
<div class="flex bg-green-900" id="asset-sidebar">
settings
</div>
<div class="flex" id="asset-sidebar"></div>
</div>
}
6 changes: 4 additions & 2 deletions v2/library/web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"net/http"

"github.com/duke-git/lancet/v2/maputil"
"github.com/eduardooliveira/stLib/v2/config"
"github.com/eduardooliveira/stLib/v2/library/entities"
"github.com/eduardooliveira/stLib/v2/library/web/comp"
Expand Down Expand Up @@ -51,8 +52,9 @@ func (h webHandler) indexHandler(c echo.Context) error {
S: http.StatusOK,
WrapperModel: corecomp.WrapperModel{
Main: comp.Index(comp.IndexModel{
Asset: &asset,
Main: listComp,
Asset: &asset,
Main: listComp,
AssetTypes: maputil.Values(config.Cfg.Library.AssetTypes),
}),
AsideR: comp.SideBar(),
},
Expand Down
2 changes: 1 addition & 1 deletion v2/web/comp/navbar.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package comp

templ navBar() {
<div class="navbar glass bg-base-300 shadow-2xl rounded-box">
<div class="navbar bg-base-300 shadow-2xl rounded-box">
<div class="navbar-start">
<div class="dropdown">
<div tabindex="0" role="button" class="btn btn-ghost btn-circle">
Expand Down
2 changes: 1 addition & 1 deletion v2/web/comp/wrapper.templ
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ templ WrapperComponent(model WrapperModel) {
<main class="flex-auto overflow-y-auto">
@model.Main
</main>
<aside class="flex right bg-yellow-800">
<aside class="flex right">
if model.AsideR != nil {
@model.AsideR
}
Expand Down

0 comments on commit 8bfa3b0

Please sign in to comment.