Skip to content

Commit

Permalink
A lot of things, plus initial search
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoOliveira committed Sep 8, 2024
1 parent 20169bf commit 5b97149
Show file tree
Hide file tree
Showing 27 changed files with 1,158 additions and 316 deletions.
688 changes: 625 additions & 63 deletions frontend/public/index.css

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion frontend/src/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createViewer3D } from "./viewer"
import Alpine from 'alpinejs'

import htmx from 'htmx.org'

Alpine.data('lib', () => ({
tab: '',
Expand Down Expand Up @@ -30,8 +30,18 @@ Alpine.data('lib', () => ({
this.tab = tab
},
addModel(model) {
if (this.models.includes(model)) {
return
}
this.models.push(model)
this.viewer.setModels(this.models.map(m => { return { id: m } }));
this.tab = 'viewer'

document.getElementsByTagName("body")[0].dispatchEvent(new CustomEvent('viewer-model-list-add', { detail: { assetID: model } }))
},
deleteModel(el, model) {
this.models = this.models.filter(m => m !== model)
this.viewer.setModels(this.models.map(m => { return { id: m } }));
el.parentElement.parentElement.remove()
}
}))
34 changes: 17 additions & 17 deletions v2/library/entities/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ const (
)

type Asset struct {
ID string `query:"id" form:"id" gorm:"primaryKey"`
Label *string `query:"label" form:"label"`
Description *string `query:"description" form:"description"`
Path *string `query:"path" form:"path"`
Root *string `query:"root" form:"root"`
FSKind *string `query:"fsKind" form:"fsKind"`
FSName *string `query:"fsName" form:"fsName"`
Extension *string `query:"extension" form:"extension"`
Kind *string `query:"kind" form:"kind"`
NodeKind *NodeKind `query:"nodeKind" form:"nodeKind"`
ParentID *string `query:"parentID" form:"parentID"`
Parent *Asset `form:"-"`
NestedAssets []*Asset `query:"nestedAssets" form:"nestedAssets" gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE;"`
Thumbnail *string `query:"thumbnail" form:"thumbnail"`
SeenOnScan *bool `query:"seenOnScan" form:"seenOnScan"`
Properties Properties `query:"properties" form:"properties"`
Tags []*Tag `query:"tags" form:"tags" gorm:"many2many:asset_tags"`
ID string `query:"id" in:"form=id" gorm:"primaryKey"`
Label *string `query:"label" in:"form=label"`
Description *string `query:"description" in:"form=description"`
Path *string `query:"path" in:"form=path"`
Root *string `query:"root" in:"form=root"`
FSKind *string `query:"fsKind" in:"form=fsKind"`
FSName *string `query:"fsName" in:"form=fsName"`
Extension *string `query:"extension" in:"form=extension"`
Kind *string `query:"kind" in:"form=kind"`
NodeKind *NodeKind `query:"nodeKind" in:"form=nodeKind"`
ParentID *string `query:"parentID" in:"form=parentID"`
Parent *Asset `in:"form=-"`
NestedAssets []*Asset `query:"nestedAssets" in:"form=nestedAssets" gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE;"`
Thumbnail *string `query:"thumbnail" in:"form=thumbnail"`
SeenOnScan *bool `query:"seenOnScan" in:"form=seenOnScan"`
Properties Properties `query:"properties" in:"form=properties"`
Tags []*Tag `query:"tags" in:"form=tags" gorm:"many2many:asset_tags"`
CreatedAt time.Time
UpdatedAt time.Time
}
Expand Down
6 changes: 3 additions & 3 deletions v2/library/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ func (p *Process) Run() error {
}

if p.enricher != nil {
/*if err := p.enricher.Enrich(p.Asset); err != nil {
if err := p.enricher.Enrich(p.Asset); err != nil {
p.enrichError = err
p.enrichState = "failed"
l.Error("failed to enrich asset", "error", err)
} else {
}*/
p.enrichState = "done"
p.enrichState = "done"
}
}
if p.renderState == "done" || p.enrichState == "done" {
if err := p.p.r.SaveAsset(*p.Asset); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions v2/library/repo/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package repo

import (
"errors"
"fmt"
"math"
"strings"

"github.com/eduardooliveira/stLib/v2/database"
"github.com/eduardooliveira/stLib/v2/library/entities"
Expand Down Expand Up @@ -98,3 +100,13 @@ func (r AssetRepo) DeleteUnSeenInRoot(root string) error {
func (r AssetRepo) UpdateAsset(a *entities.Asset) error {
return database.DB.Model(&entities.Asset{ID: a.ID}).Updates(a).Error
}

func (r AssetRepo) SearchAsset(label string, tags string) ([]*entities.Asset, error) {
var assets []*entities.Asset
q := database.DB.Debug().Model(&entities.Asset{}).Where("label LIKE ?", fmt.Sprintf("%%%s%%", label))
for i, t := range strings.Split(tags, ",") {
q.Joins(fmt.Sprintf("LEFT JOIN project_tags as project_tags%d on project_tags%d.project_uuid = projects.uuid", i, i)).
Where(fmt.Sprintf("project_tags%d.tag_value = ?", i), t)
}
return assets, q.Find(&assets).Error
}
10 changes: 8 additions & 2 deletions v2/library/web/comp/assetcard.templ
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ templ AssetCard(m *AssetCardModel) {
if utils.VoZ(m.Asset.Kind) == "model" {
<button
type="button"
class="btn btn-sm add-model"
class="btn btn-sm btn-square add-model"
@click={ fmt.Sprintf("addModel('%s')", m.Asset.ID) }
>v</button>
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
stroke="currentColor"
><title>cube-outline</title><path d="M21,16.5C21,16.88 20.79,17.21 20.47,17.38L12.57,21.82C12.41,21.94 12.21,22 12,22C11.79,22 11.59,21.94 11.43,21.82L3.53,17.38C3.21,17.21 3,16.88 3,16.5V7.5C3,7.12 3.21,6.79 3.53,6.62L11.43,2.18C11.59,2.06 11.79,2 12,2C12.21,2 12.41,2.06 12.57,2.18L20.47,6.62C20.79,6.79 21,7.12 21,7.5V16.5M12,4.15L6.04,7.5L12,10.85L17.96,7.5L12,4.15M5,15.91L11,19.29V12.58L5,9.21V15.91M19,15.91V9.21L13,12.58V19.29L19,15.91Z"></path></svg>
</button>
}
<div class="dropdown">
<div tabindex="0" role="button" class="btn btn-xs">menu</div>
Expand Down
41 changes: 39 additions & 2 deletions v2/library/web/comp/details.templ
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,45 @@ templ Details(m *DetailsModel) {
hx-vals="js:{assetID:event.detail.assetID}"
>
if m!=nil {
<h1>{ utils.VoZ(m.Asset.Label) }</h1>
<p>{ utils.VoZ(m.Asset.Kind) }</p>
<div
class={ "hero h-56 bg-gray-300", bgimg(utils.VoZ(m.Asset.Thumbnail)) }
>
<div class="hero-overlay bg-opacity-60"></div>
<div class="hero-content text-neutral-content text-left">
<div class="max-w-80">
<h1 class="mb-5 text-5xl font-bold truncate">{ utils.VoZ(m.Asset.Label) }</h1>
</div>
</div>
</div>
<div class="flex flex-col">
<div class="flex flex-row justify-between">
<p class="text-lg font-bold">Description</p>
</div>
<div class="flex flex-col">
<p>{ utils.VoZ(m.Asset.Description) }</p>
</div>
<div class="flex flex-row justify-between">
<p class="text-lg font-bold">Properties</p>
</div>
<div class="overflow-x-auto">
<table class="table table-xs">
<thead>
<tr>
<th>Name</th>
<th>value</th>
</tr>
</thead>
<tbody>
for k ,_ := range m.Asset.Properties {
<tr>
<td>{ k }</td>
<td>Quality Control Specialist</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
</div>
}
37 changes: 25 additions & 12 deletions v2/library/web/comp/edit.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@ package comp
import "github.com/eduardooliveira/stLib/v2/utils"

templ Edit(m *EditModel) {
<div>
<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>
</form>
<div
class="flex flex-col w-96"
:class="tab == 'edit' ? '' : 'hidden'"
hx-get="/lib/edit"
hx-trigger="tab-edit from:body"
hx-vals="js:{assetID:event.detail.assetID}"
>
if m!=nil {
<h1>Edit</h1>
<form hx-post="/lib/edit" hx-vals="unset">
<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" type="submit">Save</button>
</form>
}
</div>
if m.Action == "save" {
<div class="label" hx-swap-oob="innerHTML:.asset-view .header .label">
Expand Down
20 changes: 0 additions & 20 deletions v2/library/web/comp/expand_asset_btn.templ

This file was deleted.

32 changes: 17 additions & 15 deletions v2/library/web/comp/index.templ
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ templ Index(model IndexModel) {
</div>
@Pagination(model.Pagination)
<div class="flex-none">
<button
class="btn btn-square btn-ghost"
hx-get="/lib/details"
hx-include="#asset-id"
hx-target="#asset-sidebar"
if model.Asset.ID== "" {
disabled
}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
class="inline-block h-5 w-5x stroke-current"
><title>information-outline</title><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>
</button>
<div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-ghost btn-circle">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
class="inline-block h-5 w-5x stroke-current"
><title>file-search-outline</title><path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H13C12.59,21.75 12.2,21.44 11.86,21.1C11.53,20.77 11.25,20.4 11,20H6V4H13V9H18V10.18C18.71,10.34 19.39,10.61 20,11V8L14,2M20.31,18.9C21.64,16.79 21,14 18.91,12.68C16.8,11.35 14,12 12.69,14.08C11.35,16.19 12,18.97 14.09,20.3C15.55,21.23 17.41,21.23 18.88,20.32L22,23.39L23.39,22L20.31,18.9M16.5,19A2.5,2.5 0 0,1 14,16.5A2.5,2.5 0 0,1 16.5,14A2.5,2.5 0 0,1 19,16.5A2.5,2.5 0 0,1 16.5,19Z"></path></svg>
</div>
<div
tabindex="0"
class="card card-compact dropdown-content bg-base-200 z-20 mt-3 w-64 shadow"
>
<div class="card-body">
@Search(model.SearchModel)
</div>
</div>
</div>
<button
class="btn btn-square btn-ghost"
hx-get="/lib/new"
Expand Down
26 changes: 0 additions & 26 deletions v2/library/web/comp/kind_filter.templ

This file was deleted.

19 changes: 14 additions & 5 deletions v2/library/web/comp/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

type IndexModel struct {
Asset *entities.Asset
AssetTypes []config.AssetType
KindFilter KindFilterModel
Main templ.Component
Pagination PaginationModel
Asset *entities.Asset
AssetTypes []config.AssetType
KindFilter KindFilterModel
Main templ.Component
Pagination PaginationModel
SearchModel SearchModel
}

type ListModel struct {
Expand Down Expand Up @@ -50,3 +51,11 @@ type KindFilterModel struct {
AssetTypes []config.AssetType
Selected string
}

type SearchModel struct {
Search bool `in:"query=search"`
Global bool `in:"query=global"`
Parent string `in:"query=parent"`
Name string `in:"query=name"`
Tags string `in:"query=tags"`
}
50 changes: 50 additions & 0 deletions v2/library/web/comp/search.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package comp

templ Search(model SearchModel) {
<form
hx-get="/lib"
hx-target=".asset-view"
hx-swap="outerHTML"
>
<input type="hidden" name="search" value="true"/>
<h1 class="text-2xl font-semibold text-gray-900 dark:text-gray-300">Search</h1>
<div class="mt-6">
<label class="label cursor-pointer">
<span class="label-text">Global</span>
<input type="checkbox" class="toggle toggle-primary" checked="checked"/>
</label>
</div>
<div class="mt-6">
<label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Name</label>
<input
id="name"
name="name"
value={ model.Name }
rows="3"
class="mt-1 input input-bordered w-full max-w-xs"
/>
</div>
<div class="mt-6">
<label for="tags" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Tags</label>
<input
type="text"
id="tags"
name="tags"
value={ model.Tags }
class="mt-1 input input-bordered w-full max-w-xs"
/>
</div>
<div class="mt-6">
<button
type="reset"
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-gray-600 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
>Clear</button>
</div>
<div class="mt-6">
<button
type="submit"
class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
>Submit</button>
</div>
</form>
}
5 changes: 5 additions & 0 deletions v2/library/web/comp/searchresult.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package comp

templ SearchResult() {
<div>result</div>
}
Loading

0 comments on commit 5b97149

Please sign in to comment.