Skip to content

Commit cb2b042

Browse files
committed
Fix broken pending entries functionality in admin.
- Fix `/api/entries/pending` API that was missing the `relations[]` block. - Clean up and refactor pending.html template to match with admin search results.
1 parent b813f24 commit cb2b042

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

admin/pending.html

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
{% extends "admin/base.html" %}
22

33
{% block content %}
4-
<section x-data="searchResultsComponent('pending')" x-init="onLoad" @search.window="onSearch">
4+
<section x-data="searchResultsComponent('pending')" x-init="onLoad" @search.window="onSearch" class="entries">
55
<template x-if="!id && loading['entries.search'] !== true">
6-
<header class="pending-header">
7-
<hgroup>
8-
<h2><span x-text="total"></span> pending entries</h2>
9-
<p>Entries awaiting review</p>
10-
</hgroup>
6+
<hgroup>
7+
<h2><span x-text="total"></span> pending entries</h2>
118
<template x-if="total > 0">
129
<a href="#" role="button" class="outline contrast" @click.prevent="onClearPending()">Clear all</a>
1310
</template>
14-
</header>
11+
</hgroup>
1512
</template>
1613
<template x-if="loading['entries.search'] === true">
1714
<article aria-busy="true"></article>
@@ -28,41 +25,42 @@ <h3>
2825
<span><span x-text="item"></span><span x-show="idx < e.content.length - 1">, </span></span>
2926
</template>
3027
</a>
28+
<template x-if="e.phones.length > 0">
29+
<div class="phones"><em x-text="e.phones.join(', ')"></em></div>
30+
</template>
3131
</h3>
32-
<p x-text="config.languages[e.lang].name"></p>
32+
<span x-text="config.languages[e.lang].name" class="tag"></span>
3333
</hgroup>
3434
<nav>
3535
<ul>
36-
<li><a href="#" @click.prevent="onEditEntry(e)" class="secondary">Edit</a></li>
37-
<li><a href="#" @click.prevent="onDeleteEntry(e.id)" class="contrast">Delete</a></li>
36+
<li><a href="#" @click.prevent="onEditEntry(e)" class="icon-link"><img class="icon icon-primary" src="/admin/static/edit.svg?v={{ asset_ver }}" alt="" /> Edit</a></li>
37+
<li><a href="#" @click.prevent="onDeleteEntry(e.id)" class="icon-link"><img class="icon icon-primary" src="/admin/static/delete.svg?v={{ asset_ver }}" alt="" /> Delete</a></li>
3838
</ul>
3939
</nav>
4040
</header>
4141

4242
<template x-if="e.id in comments && 'null' in comments[e.id]">
4343
<template x-for="(c, n) in comments[e.id]['null']" :key="c.id">
44-
<blockquote>
45-
<p x-text="c.comments"></p>
44+
<blockquote class="comment">
45+
<strong>User comment:</strong>
46+
<div x-text="c.comments"></div>
4647
<footer>
4748
<button class="outline secondary small" @click.prevent="onClearComments(c.id)">Clear</button>
4849
</footer>
4950
</blockquote>
5051
</template>
5152
</template>
5253

53-
<template x-if="e.phones.length > 0">
54-
<p><em x-text="e.phones.join(', ')"></em></p>
55-
</template>
56-
57-
<div class="definitions-list">
54+
<ol class="definitions-list">
5855
<template x-for="(r, n) in e.relations" :key="r.id">
59-
<div class="definition-row" :class="{ 'is-reordered': order[e.id] && order[e.id].changedRels[r.id] }">
56+
<li class="definition-row" :class="{ 'is-reordered': order[e.id] && order[e.id].changedRels[r.id] }">
6057
<div>
61-
<small class="secondary">
58+
<div class="meta secondary">
6259
<template x-if="r.status === 'pending'"><mark>New</mark></template>
6360
<template x-if="r.relation.status === 'pending'"><ins>Pending</ins></template>
64-
<span x-text="config.languages[r.lang].name + (r.relation.types ? ' · ' + r.relation.types : '')"></span>
65-
</small>
61+
<span x-text="config.languages[r.lang].name" class="tag"></span>
62+
<span x-text="(r.relation.types ? ' · ' + r.relation.types : '')"></span>
63+
</div>
6664
<p>
6765
<template x-for="(item, idx) in r.content" :key="idx">
6866
<span><span x-text="item"></span><span x-show="idx < r.content.length - 1">, </span></span>
@@ -71,27 +69,28 @@ <h3>
7169
</div>
7270
<template x-if="e.id in comments && r.id in comments[e.id]">
7371
<template x-for="(c, n) in comments[e.id][r.id]" :key="c.id">
74-
<blockquote>
75-
<p x-text="c.comments"></p>
72+
<blockquote class="comment">
73+
<strong>User comment:</strong>
74+
<div x-text="c.comments"></div>
7675
<footer>
7776
<button class="outline secondary small" @click.prevent="onClearComments(c.id)">Clear</button>
7877
</footer>
7978
</blockquote>
8079
</template>
8180
</template>
8281
<nav class="def-actions">
83-
<a href="#" @click.prevent="onEditRelation(r, e)">Relation</a>
84-
<a href="#" @click.prevent="onEditEntry(r, e)">Edit</a>
85-
<a href="#" @click.prevent="onDetatchRelation(e.id, r.relation.id)">Detach</a>
86-
<a href="#" @click.prevent="onDeleteRelationEntry(r.id)" class="contrast">Delete</a>
87-
<span role="group">
82+
<a href="#" @click.prevent="onEditEntry(r, e)" class="icon-link"><img class="icon icon-primary" src="/admin/static/edit.svg?v={{ asset_ver }}" alt="" /> Edit definition</a>
83+
<a href="#" @click.prevent="onEditRelation(r, e)" class="icon-link"><img class="icon icon-primary" src="/admin/static/edit.svg?v={{ asset_ver }}" alt="" /> Edit relation</a>
84+
<a href="#" @click.prevent="onDetatchRelation(e.id, r.relation.id)" class="icon-link"><img class="icon icon-primary" src="/admin/static/link.svg?v={{ asset_ver }}" alt="" /> Detach relation</a>
85+
<a href="#" @click.prevent="onDeleteRelationEntry(r.id)" class="icon-link"><img class="icon icon-primary" src="/admin/static/delete.svg?v={{ asset_ver }}" alt="" /> Delete</a>
86+
<span role="group" class="buttons">
8887
<button class="outline secondary" @click.prevent="onReorderRelation(e, r, n, -1)">&uarr;</button>
8988
<button class="outline secondary" @click.prevent="onReorderRelation(e, r, n, 1)">&darr;</button>
9089
</span>
9190
</nav>
92-
</div>
91+
</li>
9392
</template>
94-
</div>
93+
</ol>
9594

9695
<footer>
9796
<a href="#" role="button" class="outline" @click.prevent="onAddDefinition(e)">+ Add definition</a>

src/handlers/submissions.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use axum::{
77
};
88

99
use super::{json, paginate, total_pages, ApiErr, ApiResp, Ctx, PaginationQuery, Result};
10-
use crate::models::{Comment, Entry, Relation, SearchResults, StringArray, STATUS_PENDING};
10+
use crate::models::{
11+
Comment, Entry, Relation, RelationsQuery, SearchResults, StringArray, STATUS_PENDING,
12+
};
1113

1214
/// Public submission request.
1315
#[derive(Debug, serde::Deserialize)]
@@ -155,7 +157,12 @@ pub async fn get_pending_entries(
155157
ctx.consts.api_default_per_page,
156158
);
157159

158-
let (entries, total) = ctx.mgr.get_pending_entries("", offset, per_page).await?;
160+
let (mut entries, total) = ctx.mgr.get_pending_entries("", offset, per_page).await?;
161+
162+
// Load relations for pending entries.
163+
ctx.mgr
164+
.load_relations(&mut entries, &RelationsQuery::default())
165+
.await?;
159166

160167
Ok(json(SearchResults {
161168
entries,

static/admin/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function searchResultsComponent(typ) {
200200
out[d.from_id] = {};
201201
}
202202

203-
if (!out.hasOwnProperty(d.from_id[d.to_id])) {
203+
if (!out[d.from_id].hasOwnProperty(d.to_id)) {
204204
out[d.from_id][d.to_id] = [];
205205
}
206206

static/admin/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ article .meta {
295295
margin-bottom: var(--pico-block-spacing-vertical);
296296
}
297297

298+
blockquote.comment {
299+
background: #fff5a0;
300+
border-radius: 3px;
301+
border-left: 6px solid var(--pico-primary);
302+
padding: 10px;
303+
}
304+
298305
/* side panel form */
299306
.side-panel {
300307
position: fixed;

0 commit comments

Comments
 (0)