Skip to content

Commit

Permalink
Refactor Blocks
Browse files Browse the repository at this point in the history
- Remove block actions
- Add block.IsActive
- Rework business rules
- Rework block UX

- Progress on site-wide blocks
  • Loading branch information
benpate committed Apr 27, 2023
1 parent 94c0c7e commit 84615a6
Show file tree
Hide file tree
Showing 37 changed files with 431 additions and 252 deletions.
16 changes: 16 additions & 0 deletions _embed/templates/admin-blocks/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="page" hx-get="/admin/blocks/index" hx-trigger="refreshPage from:window">

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

<div class="table">
<div role="button" hx-get="/admin/blocks/add" class="link">
{{icon "add"}} &nbsp;<span>Add a Server-wide Block</span>
</div>
{{.View "list"}}
</div>
</div>
7 changes: 7 additions & 0 deletions _embed/templates/admin-blocks/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- $blocks := .ServerWideBlocks.Slice -}}

{{- range $blocks -}}
<div hx-get="/admin/blocks/{{.BlockID.Hex}}/edit" role="button">
{{.Type}}: {{.Trigger}}
</div>
{{- end -}}
37 changes: 37 additions & 0 deletions _embed/templates/admin-blocks/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"templateId":"admin-blocks",
"templateRole":"admin",
"model":"block",
"containedBy":["admin"],
"label": "Blocks",
"description": "Domain Owners only. Site Admin",
"actions": {
"index": {"step": "view-html"},
"list": {"step": "view-html"},
"add": {"steps":[
{"step":"as-modal", "background":"/admin/blocks", "steps":[
{"step": "edit", "form":{
"type":"layout-vertical",
"label":"Server-Wide Block",
"children":[
{"type":"select", "path":"type", "label":"Type", "options":{"provider":"block-types"}},
{"type":"text", "path":"trigger", "label":"Trigger Text"}
]
}}
]}
]},
"edit": {"steps":[
{"step":"as-modal", "background":"/admin/blocks", "steps":[
{"step": "edit", "form":{
"type":"layout-vertical",
"label":"Server-Wide Block",
"children":[
{"type":"select", "path":"type", "label":"Type", "options":{"provider":"block-types"}},
{"type":"text", "path":"trigger", "label":"Trigger Text"}
]
}, "options":["delete:/admin/blocks/{{.BlockID}}/delete"]}
]}
]},
"delete": {"step": "delete"}
}
}
4 changes: 1 addition & 3 deletions _embed/templates/admin-connections/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

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

<h1>Settings</h1>

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="{{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

Expand Down
4 changes: 1 addition & 3 deletions _embed/templates/admin-domain/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script src="/static/nebula/autosize._hs" type="text/hyperscript"></script>

<h1>Settings</h1>

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="{{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

Expand Down
4 changes: 1 addition & 3 deletions _embed/templates/admin-groups/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script src="/static/nebula/autosize._hs" type="text/hyperscript"></script>

<h1>Settings</h1>

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="{{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

Expand Down
2 changes: 1 addition & 1 deletion _embed/templates/admin-groups/list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $groups := .Groups.Top60.ByLabel.Slice -}}
{{- if not $groups.IsEmpty -}}
<tbody hx-get="/admin/groups/list?label=gt:{{$groups.Last.Label}}" hx-trigger="revealed" hx-target="#groups" hx-swap="beforeend">
<tbody hx-get="/admin/groups/list?label=gt:{{$groups.Last.Label}}" hx-trigger="revealed" hx-target="#groups" hx-swap="beforeend" hx-push-url="false">
{{- range $groups -}}
<tr class="clickable">
<td role="link" hx-get="/admin/groups/{{.GroupID.Hex}}/edit" class="width-100">
Expand Down
14 changes: 6 additions & 8 deletions _embed/templates/admin-navigation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script src="/static/nebula/autosize._hs" type="text/hyperscript"></script>

<h1>Settings</h1>

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="{{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

{{ $navigation := .Navigation}}
{{- if not $navigation.IsEmpty -}}

<div class="space-below text-sm">
<button hx-get="/admin/navigation/add" class="primary">{{icon "add"}}&nbsp;Add a Top-Level Stream</button>
</div>


<form class="sortable space-below" hx-post="/admin/navigation/sort" hx-swap="none" hx-push-url="false" hx-trigger="end">
{{- range $navigation -}}
<div class="draggable">
Expand All @@ -33,11 +36,6 @@ <h1>Settings</h1>
<i>Drag and Drop Items to Sort.</i>
</div>

<div class="space-below">
<button hx-get="/admin/navigation/add">{{icon "add"}}&nbsp;Add a Top-Level Stream</button>
</div>


{{- else -}}

<h2>Let's Set Up Your Site</h2>
Expand Down
4 changes: 1 addition & 3 deletions _embed/templates/admin-users/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
<script src="/static/nebula/autosize._hs" type="text/hyperscript"></script>

<h1>Settings</h1>

<div id="menu-bar" hx-push-url="true">
{{- $token := .Token -}}
{{- range .AdminSections -}}
<a hx-get="/admin/{{.Value}}" class="{{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
<a hx-get="/admin/{{.Value}}" class="turboclick {{if eq $token .Value}}selected{{end}}">{{.Label}}</a>
{{- end -}}
</div>

Expand Down
2 changes: 1 addition & 1 deletion _embed/templates/admin-users/list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $users := .Users.Top12.ByDisplayName.Slice -}}
{{- if not $users.IsEmpty }}

<tbody hx-trigger="revealed" hx-get="/admin/users/list?groupId=&amp;displayName=gt:{{ $users.Last.DisplayName }}" hx-target="#users" hx-swap="beforeend">
<tbody hx-trigger="revealed" hx-get="/admin/users/list?groupId=&amp;displayName=gt:{{ $users.Last.DisplayName }}" hx-target="#users" hx-swap="beforeend" hx-push-url="false">
{{- range $index, $user := $users -}}
<tr class="clickable">
<td role="link" hx-get="/admin/users/{{$user.UserID.Hex}}/edit" class="width-100">
Expand Down
5 changes: 1 addition & 4 deletions _embed/templates/base-block-editor/blocks-editor-actor.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

<table class="table">
<tr hx-get="/@me/block-actor" role="button" class="link">
<td class="text-lg">
<td colspan="2">
{{icon "add"}}
</td>
<td style="vertical-align:middle; width:100%;">
Block a Person
</td>
<td>&nbsp;</td>
</tr>

{{- template "blocks-list" $blocks -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

<table class="table">
<tr hx-get="/@me/block-keywords" role="button" class="link">
<td class="text-lg">
<td colspan="2">
{{icon "add"}}
</td>
<td style="vertical-align:middle; width:100%;">
Block Tags &amp; Keywords
</td>
<td>&nbsp;</td>
</tr>

{{- template "blocks-list" $blocks -}}
Expand Down
5 changes: 1 addition & 4 deletions _embed/templates/base-block-editor/blocks-editor-domain.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

<table class="table">
<tr hx-get="/@me/block-domain" role="button" class="link">
<td class="text-lg">
<td colspan="2">
{{icon "add"}}
</td>
<td style="vertical-align:middle; width:100%;">
Block a Domain
</td>
<td>&nbsp;</td>
</tr>

{{- template "blocks-list" $blocks -}}
Expand Down
32 changes: 13 additions & 19 deletions _embed/templates/base-block-editor/blocks-list.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
{{- range . -}}
<tr hx-get="/@me/block-edit?blockId={{.BlockID.Hex}}" role="button">
<td class="text-xl">
{{- if eq "BLOCK" .Behavior -}}
<span title="Block">{{icon "block"}}</span>
{{- else if eq "MUTE" .Behavior -}}
<span title="Mute">{{icon "mute"}}</span>
{{- else if eq "ALLOW" .Behavior -}}
<span title="Allow">{{icon "thumbs-up"}}</span>
{{- end }}
</td>
<td style="width:100%; vertical-align: middle;">
<div class="ellipsis">
{{.Trigger}} &nbsp;
<span class="text-sm text-gray">{{.Comment}}</span>
</div>
</td>
<td class="text-xl align-right" nowrap>
&nbsp;
{{- if ne "ALLOW" .Behavior -}}
{{ if .IsPublic -}}
<span title="Published">{{icon "visible-fill"}}</span>
{{- else -}}
<span title="Not Published">{{icon "invisible"}}</span>
{{- end -}}
<td class="align-right" nowrap>
{{- if .IsActive -}}
<span class="text-green">
{{- if .IsPublic -}}
<span title="Published">{{icon "visible-fill"}}</span>
{{- else -}}
<span title="Not Published">{{icon "invisible"}}</span>
{{- end -}}
&nbsp;
Active
</span>
{{- else -}}
Inactive
{{- end -}}

&nbsp;
</td>
</tr>
{{- end -}}
16 changes: 8 additions & 8 deletions _embed/templates/base-block-editor/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
{"type":"hidden", "path":"type", "options":{"value":"ACTOR"}},
{"type":"text", "path":"trigger", "label":"Enter the Person's Fediverse Address", "description":"Something like @blocked-user@domain.com or https://domain.com/@blocked-user"},
{"type":"textarea", "path":"comment", "label":"Notes", "description":"OPTIONAL. Explains WHY your are blocking this person"},
{"type":"select", "path":"behavior", "label":"Action", "options":{"provider":"block-behaviors"}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me."}}
{"type":"toggle", "path":"isActive", "label":"Active?", "options":{"true-text":"YES: Block this Person", "false-text":"NO: Do not enforce this block."}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me.", "show-if":"isActive is true"}}
]
}}
]}
Expand All @@ -41,8 +41,8 @@
{"type":"hidden", "path":"type", "options":{"value":"DOMAIN"}},
{"type":"text", "path":"trigger", "label":"Enter the Domain to Block", "description":"Something like blocked-domain.com"},
{"type":"textarea", "path":"comment", "label":"Notes", "description":"OPTIONAL. Explains WHY your are blocking this domain"},
{"type":"select", "path":"behavior", "label":"Action", "options":{"provider":"block-behaviors"}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me."}}
{"type":"toggle", "path":"isActive", "label":"Active?", "options":{"true-text":"YES: Block this Domain", "false-text":"NO: Do not enforce this block."}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me.", "show-if":"isActive is true"}}
]
}}
]}
Expand All @@ -63,8 +63,8 @@
{"type":"hidden", "path":"type", "options":{"value":"CONTENT"}},
{"type":"text", "path":"trigger", "label":"Enter the Tags and Keywords to Block", "description":"Enter one or more words, separated by spaces."},
{"type":"textarea", "path":"comment", "label":"Notes", "description":"OPTIONAL. Explains WHY your are blocking these tag or keyword"},
{"type":"select", "path":"behavior", "label":"Action", "options":{"provider":"block-behaviors"}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me."}}
{"type":"toggle", "path":"isActive", "label":"Active?", "options":{"true-text":"YES: Block this Keyword", "false-text":"NO: Do not enforce this block."}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me.", "show-if":"isActive is true"}}
]
}}
]}
Expand Down Expand Up @@ -101,8 +101,8 @@
"children":[
{"type":"text", "path":"trigger", "label":"Blocking", "readOnly":true, "options":{"class":"bold"}},
{"type":"textarea", "path":"comment", "label":"Notes", "description":"OPTIONAL. Explains WHY your are blocking this person"},
{"type":"select", "path":"behavior", "label":"Action", "options":{"provider":"block-behaviors"}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me."}}
{"type":"toggle", "path":"isActive", "label":"Active?", "options":{"true-text":"YES: Enforce this Block", "false-text":"NO: Do not enforce this block."}},
{"type":"toggle", "path":"isPublic", "label":"Publish?", "options":{"true-text":"YES: Followers' accounts may use this block automatically", "false-text":"NO: This block is only visible to me.", "show-if":"isActive is true"}}
]
}, "options":["delete:/@me/block-delete?blockId={{.ObjectID}}"]}
]}
Expand Down
1 change: 1 addition & 0 deletions _embed/templates/profile-default/inbox-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{{- end -}}

</form>

<div role="button" hx-get="/@me/inbox-folder-add" class="menu-item turboclick">{{icon "add"}} Add a Folder</div>

<hr>
Expand Down
4 changes: 2 additions & 2 deletions _embed/templates/theme-default/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

{{- if .IsOwner -}}
{{- if eq $topID "admin" -}}
<a href="/admin/domain" class="selected turboclick">{{icon "settings-fill"}} Settings</a>
<a href="/admin/domain" class="selected turboclick">{{icon "settings-fill"}} Server</a>
{{- else -}}
<a href="/admin/domain" class="turboclick">{{icon "settings"}} Settings</a>
<a href="/admin/domain" class="turboclick">{{icon "settings"}} Server</a>
{{- end -}}
{{- end -}}

Expand Down
16 changes: 15 additions & 1 deletion handler/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ func renderAdmin_GetRenderer(factory *domain.Factory, ctx *steranko.Context, tem
// Create the correct renderer for this controller
switch template.Model {

case "block":

blockService := factory.Block()
block := model.NewBlock()

if !objectID.IsZero() {
authorization := getAuthorization(ctx)
if err := blockService.LoadByID(authorization, objectID, &block); err != nil {
return nil, derp.Wrap(err, location, "Error loading Block", objectID)
}
}

return render.NewBlock(factory, ctx, &block, template, actionID)

case "domain":
domain := factory.Domain().Get()
return render.NewDomain(factory, ctx, factory.Provider(), template, &domain, actionID)
Expand Down Expand Up @@ -130,6 +144,6 @@ func renderAdmin_GetRenderer(factory *domain.Factory, ctx *steranko.Context, tem
return render.NewUser(factory, ctx, template, &user, actionID)

default:
return nil, derp.NewNotFoundError(location, "Template MODEL must be one of: 'domain', 'group', 'stream', or 'user'", template.Model)
return nil, derp.NewNotFoundError(location, "Template MODEL must be one of: 'block', 'domain', 'group', 'stream', or 'user'", template.Model)
}
}
10 changes: 6 additions & 4 deletions model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Block struct {
Type string `json:"type" bson:"type"` // Type of Block (e.g. "ACTOR", "ACTIVITY", "OBJECT")
Label string `json:"label" bson:"label"` // Human-friendly label for this block
Trigger string `json:"trigger" bson:"trigger"` // Parameter for this block type)
Behavior string `json:"behavior" bson:"behavior"` // Behavior for this block type (e.g. "BLOCK", "MUTE", "ALLOW")
Comment string `json:"comment" bson:"comment"` // Optional comment describing why this block exists
IsActive bool `json:"isActive" bson:"isActive"` // If TRUE, this block is active and should be applied to incoming messages
IsPublic bool `json:"isPublic" bson:"isPublic"` // If TRUE, this record is visible publicly
Origin OriginLink `json:"origin" bson:"origin"` // Internal or External service where this block originated (used for subscriptions)
PublishDate int64 `json:"publishDate" bson:"publishDate"` // Date when this block was published to followers
Expand All @@ -27,7 +27,9 @@ type Block struct {

func NewBlock() Block {
return Block{
BlockID: primitive.NewObjectID(),
BlockID: primitive.NewObjectID(),
IsActive: true,
IsPublic: true,
}
}

Expand All @@ -42,10 +44,10 @@ func (block Block) ID() string {
func (block Block) Fields() []string {
return []string{
"_id",
"type",
"trigger",
"behavior",
"comment",
"isPublic",
"isActive",
}
}

Expand Down
Loading

0 comments on commit 84615a6

Please sign in to comment.