Skip to content

Commit

Permalink
Refactor search tags
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Jan 9, 2025
1 parent e8a92b4 commit 34d9b01
Show file tree
Hide file tree
Showing 23 changed files with 349 additions and 214 deletions.
24 changes: 10 additions & 14 deletions _embed/templates/admin-searchTags/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
{{- $parent := .QueryParam "parent" -}}
{{- $name := .QueryParam "name" -}}
{{- $stateID := .QueryParam "stateId" -}}
{{- $groupID := .QueryParam "group" -}}

<div class="page" hx-get="/admin/tags/index" hx-trigger="refreshPage from:window">
<div class="page">

{{template "menubar" .}}

<form hx-get="/admin/tags/list" hx-trigger="change, keyup throttle:500ms" hx-target="#results" hx-swap="innerHTML" hx-push-url="false">
<form hx-get="/admin/tags/list" hx-trigger="refreshPage from:window, change, keyup throttle:500ms" hx-target="#results" hx-swap="innerHTML" hx-push-url="false">
<div class="flex-row">

{{- if ne "" $parent -}}
<div>
<label class="text-xs text-gray">Parent Tag</label>
<a href="/admin/tags/?name={{$name}}&stateId={{$stateID}}" class="block tag"><span class="text-lg bold">{{$parent}} &nbsp; {{icon "delete"}}</span></a>
</div>
{{- end -}}
<div>
<label for="search" class="text-xs text-gray">Tag</label>
<input id="search" name="name" value="{{$name}}" autocomplete="off">
</div>
<div>
<label for="search" class="text-xs text-gray">Group</label>
<select name="group" script="install select(value:'{{$groupID}}', options:{{.Groups |json }})">
<option value="">(All Groups)</option>
</select>
</div>
<div>
<label for="search" class="text-xs text-gray">Status</label>
<select name="stateId" script="install select(value:'{{$stateID}}')">
<select name="stateId" script="install select(value:'{{$stateID}}', options:{{.States | json}})">
<option value="">(All)</option>
<option value="2">Featured</option>
<option value="1">Allowed</option>
<option value="0">Waiting</option>
<option value="-1">Blocked</option>
</select>
</div>
</div>
Expand Down
72 changes: 0 additions & 72 deletions _embed/templates/admin-searchTags/index.zhtml

This file was deleted.

24 changes: 17 additions & 7 deletions _embed/templates/admin-searchTags/list.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
{{- $tags := .SearchTags.Top60.ByName.Slice -}}
{{- $builder := . -}}
{{- $groupID := .QueryParam "group" -}}
{{- $allowSort := ne "" $groupID -}}
{{- $tags := .SearchTags.Top600.ByName.Slice -}}

{{- if not $tags.IsEmpty }}

{{- range $index, $tag := $tags -}}
<tr class="clickable">
<td role="link" hx-get="/admin/tags/{{$tag.SearchTagID.Hex}}/edit">
{{icon "tag"}} {{$tag.Name}}
</td>
<td role="link" hx-get="/admin/tags/{{$tag.SearchTagID.Hex}}/edit">
{{- $tag.StatusText -}}
{{- if $allowSort -}}
<td>
{{icon "drag-handle"}}
</td>
{{- end -}}

<td class="width-100%" role="link" hx-get="/admin/tags/{{$tag.SearchTagID.Hex}}/edit">
{{- if not $allowSort -}}
{{icon "tag"}}
{{- end }}
{{$tag.Name}}
</td>
<td nowrap class="text-xs width-128 text-align-right">
<td nowrap role="link">
{{$tag.StatusText}}
</td>
</tr>
{{- end -}}
Expand Down
13 changes: 13 additions & 0 deletions _embed/templates/admin-searchTags/status-widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- $builder := index . 0 -}}
{{- $tag := index . 1 -}}

<div class="text-sm">
{{$stateID := string $tag.StateID}}
{{- range $index, $lookupCode := $builder.States -}}
{{- if eq $lookupCode.Value $stateID -}}
<button class="primary">{{$lookupCode.Label}}</button>
{{- else -}}
<button hx-post="/admin/tags/{{$tag.ID}}/edit" hx-vals="{'stateId':{{$stateID}}}">{{$lookupCode.Label}}</button>
{{- end -}}
{{- end -}}
</div>
43 changes: 32 additions & 11 deletions _embed/templates/admin-searchTags/template.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
label:General
children: [
{type:"text", label:"Tag Name", path:"name", description:"Case insensitive. Don't include # symbol"}
{type:"text", label:"Group", path:"group", options:{provider:"searchTag-groups"}}
{type:"select", label:"Status", path:"stateId", options:{provider: "searchTag-states"}}
{type:"text", label:"Rank", path:"rank", options:{style:"width:6em;"}}
{type:"toggle", path:"isFeatured", options:{true-text:"Featured. Show on search directory.", false-text:"Featured?"}}
{type:"text", label:"Sort/Rank", path:"rank", options:{style:"width:6em;"}}
]
}
{
type:layout-vertical
label:Related
children: [
{type:"textarea", path:"related", description:"Enter related #Hashtags separated by spaces", options:{rows:6}}
]
}
{
type:layout-vertical
label:Custom Banner
children: [
{type:"toggle", path:"isCustomBanner", options:{true-text:"Custom Banner. Display a custom banner when searching this tag.", false-text:"Custom Banner?"}}
{type:"textarea", label:"Related Tags", path:"related", description:"Enter #Hashtags separated by spaces"}
{type:"colorpicker", label:"Background (Left)", path:"colors.0"}
{type:"colorpicker", label:"Background (Right)", path:"colors.1"}
]
Expand All @@ -48,8 +53,7 @@
children: [
{type:"textarea", path:"notes", description:"Notes are only visible by administrators", options:{rows:8}}
]
}
]
} ]
}
}
{do:"save"}
Expand All @@ -75,19 +79,25 @@
label:General
children: [
{type:"text", label:"Tag Name", path:"name", description:"Case insensitive. Don't include # symbol"}
{type:"text", label:"Group", path:"group", options:{provider:"searchTag-groups"}}
{type:"select", label:"Status", path:"stateId", options:{provider: "searchTag-states"}}
{type:"text", label:"Rank", path:"rank", options:{style:"width:6em;"}}
{type:"toggle", path:"isFeatured", options:{true-text:"Featured. Show on search directory.", false-text:"Featured?"}}
]
}
{
type:layout-vertical
label:Custom Banner
label:Display
children: [
{type:"toggle", path:"isCustomBanner", options:{true-text:"Custom Banner. Display a custom banner when searching this tag.", false-text:"Custom Banner?"}}
{type:"textarea", label:"Related Tags", path:"related", description:"Enter #Hashtags separated by spaces"}
{type:"colorpicker", label:"Background (Left)", path:"colors.0"}
{type:"colorpicker", label:"Background (Right)", path:"colors.1"}
{type:"upload", label:"Image", path:"imageUrl", options:{accept:"image/*", delete:"/admin/tag/{{.SearchTagID}}/delete-image"}}
{type:"text", label:"Sort/Rank", path:"rank", options:{style:"width:6em;"}}
]
}
{
type:layout-vertical
label:Related
children: [
{type:"textarea", path:"related", description:"Enter related #Hashtags separated by spaces", options:{rows:8}}
]
}
{
Expand All @@ -101,6 +111,7 @@
}
options:["delete:/admin/tags/{{.SearchTagID}}/delete"]
},
{do:"upload-attachments", category:"image", fieldname:"imageUrl", attachment-path:"imageId", accept-type:"image/*", maximum:1, rules:{width:800, height:600}}
{do:"save"}
{do:"refresh-page"}
]
Expand All @@ -114,5 +125,15 @@
{do:"refresh-page"}
]
}

delete-image: {
roles:["self"]
steps:[
{do:"delete-attachments", field:"iconId"}
{do:"save", comment:"Deleted Image"}
{do:"reload-page"}
]
}

}
}
16 changes: 16 additions & 0 deletions _embed/templates/theme-global/stylesheet/05-positioning.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
position:sticky;
}

.pos-absolute-top {
-webkit-position:absolute;
position:absolute;
top:var(--rhythm);
left:var(--rhythm);
right: var(--rhythm);
}

.pos-absolute-top-left {
-webkit-position:absolute;
position:absolute;
Expand All @@ -36,6 +44,14 @@
right:var(--rhythm);
}

.pos-absolute-bottom {
-webkit-position:absolute;
position:absolute;
bottom:var(--rhythm);
left:var(--rhythm);
right: var(--rhythm);
}

.pos-absolute-bottom-left {
-webkit-position:absolute;
position:absolute;
Expand Down
10 changes: 10 additions & 0 deletions build/builder_admin_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/benpate/derp"
"github.com/benpate/exp"
builder "github.com/benpate/exp-builder"
"github.com/benpate/form"
"github.com/benpate/rosetta/schema"
"github.com/rs/zerolog/log"
"go.mongodb.org/mongo-driver/bson/primitive"
Expand Down Expand Up @@ -155,6 +156,7 @@ func (w SearchTag) SearchTags() *QueryBuilder[model.SearchTag] {

query := builder.NewBuilder().
String("name", builder.WithDefaultOpBeginsWith()).
String("group").
Int("stateId")

criteria := exp.And(
Expand All @@ -168,6 +170,14 @@ func (w SearchTag) SearchTags() *QueryBuilder[model.SearchTag] {
return &result
}

func (w SearchTag) States() []form.LookupCode {
return w.lookupProvider().Group("searchTag-states").Get()
}

func (w SearchTag) Groups() []form.LookupCode {
return w._factory.SearchTag().ListGroups()
}

func (w SearchTag) debug() {
log.Debug().Interface("object", w.object()).Msg("builder_admin_searchTag")
}
3 changes: 1 addition & 2 deletions build/builder_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ func (w Common) SearchTag(name string) model.SearchTag {
func (w Common) FeaturedSearchTags() *QueryBuilder[model.SearchTag] {

criteria := exp.And(
exp.Equal("stateId", model.SearchTagStateAllowed),
exp.Equal("isFeatured", true),
exp.Equal("stateId", model.SearchTagStateFeatured),
exp.Equal("deleteDate", 0),
)

Expand Down
13 changes: 4 additions & 9 deletions build/step_IfCondition.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package build

import (
"bytes"
"html/template"
"io"
"strings"

"github.com/EmissarySocial/emissary/model/step"
"github.com/benpate/derp"
"github.com/benpate/rosetta/convert"
)

// StepIfCondition is a Step that can update the data.DataMap custom data stored in a Stream
Expand Down Expand Up @@ -47,12 +47,7 @@ func (step StepIfCondition) execute(builder Builder, buffer io.Writer, method Ac

// evaluateCondition executes the conditional template and
func (step StepIfCondition) evaluateCondition(builder Builder) bool {

var result bytes.Buffer

if err := step.Condition.Execute(&result, builder); err != nil {
return false
}

return (strings.TrimSpace(result.String()) == "true")
condition := executeTemplate(step.Condition, builder)
condition = strings.TrimSpace(condition)
return convert.Bool(condition)
}
11 changes: 10 additions & 1 deletion domain/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,16 @@ func (factory *Factory) Steranko() *steranko.Steranko {

// LookupProvider returns a fully populated LookupProvider service
func (factory *Factory) LookupProvider(userID primitive.ObjectID) form.LookupProvider {
return service.NewLookupProvider(factory.Domain(), factory.Folder(), factory.Group(), factory.Registration(), factory.Template(), factory.Theme(), userID)
return service.NewLookupProvider(
factory.Domain(),
factory.Folder(),
factory.Group(),
factory.Registration(),
factory.SearchTag(),
factory.Template(),
factory.Theme(),
userID,
)
}

/******************************************
Expand Down
Loading

0 comments on commit 34d9b01

Please sign in to comment.