Add first/last pool post to pool navigator
This commit is contained in:
parent
e1c97049da
commit
28eaf53dfd
8 changed files with 80 additions and 14 deletions
|
@ -18,7 +18,7 @@ $message-error-border-color = #FCC
|
||||||
$message-error-background-color = #FFF5F5
|
$message-error-background-color = #FFF5F5
|
||||||
$message-success-border-color = #D3E3D3
|
$message-success-border-color = #D3E3D3
|
||||||
$message-success-background-color = #F5FFF5
|
$message-success-background-color = #F5FFF5
|
||||||
$pool-navigator-border-color = #888
|
$pool-navigator-border-color = #AAA
|
||||||
$pool-navigator-background-color = #EEE
|
$pool-navigator-background-color = #EEE
|
||||||
$input-bad-border-color = #FCC
|
$input-bad-border-color = #FCC
|
||||||
$input-bad-background-color = #FFF5F5
|
$input-bad-background-color = #FFF5F5
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@import colors
|
@import colors
|
||||||
|
|
||||||
.pool-navigator-container
|
.pool-navigator-container
|
||||||
padding: 0 0.50em 0 0.50em
|
padding: 0
|
||||||
margin: 0 auto
|
margin: 0 auto
|
||||||
|
|
||||||
.pool-info-wrapper
|
.pool-info-wrapper
|
||||||
|
@ -14,6 +14,8 @@
|
||||||
background: $pool-navigator-background-color
|
background: $pool-navigator-background-color
|
||||||
&.active
|
&.active
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
|
font-size: 1.10em;
|
||||||
|
padding: 0.58em 1em
|
||||||
|
|
||||||
.pool-name
|
.pool-name
|
||||||
flex: 1 1;
|
flex: 1 1;
|
||||||
|
@ -23,7 +25,10 @@
|
||||||
-o-text-overflow: ellipsis;
|
-o-text-overflow: ellipsis;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
.prev, .next
|
.first, .last
|
||||||
|
flex-basis: 1em;
|
||||||
|
|
||||||
|
.first, .prev, .next, .last
|
||||||
flex: 0 1;
|
flex: 0 1;
|
||||||
margin: 0 .25em;
|
margin: 0 .25em;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
|
@ -40,11 +40,14 @@
|
||||||
width: 100%
|
width: 100%
|
||||||
|
|
||||||
.post-container
|
.post-container
|
||||||
margin-bottom: 2em
|
margin-bottom: 1em
|
||||||
|
|
||||||
.post-content
|
.post-content
|
||||||
margin: 0
|
margin: 0
|
||||||
|
|
||||||
|
.pool-navigators-container
|
||||||
|
margin-bottom: 2em
|
||||||
|
|
||||||
@media (max-width: 800px)
|
@media (max-width: 800px)
|
||||||
.post-view
|
.post-view
|
||||||
flex-wrap: wrap
|
flex-wrap: wrap
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
<div class='pool-navigator-container'>
|
<div class='pool-navigator-container'>
|
||||||
<div class='pool-info-wrapper <%= ctx.isActivePool ? "active" : "" %>'>
|
<div class='pool-info-wrapper <%= ctx.isActivePool ? "active" : "" %>'>
|
||||||
|
<span class='first'>
|
||||||
|
<% if (ctx.canViewPosts && ctx.firstPost) { %>
|
||||||
|
<a class='<%- ctx.linkClass %>' href='<%= ctx.getPostUrl(ctx.firstPost.id, ctx.parameters) %>'>
|
||||||
|
<% } %>
|
||||||
|
«
|
||||||
|
<% if (ctx.canViewPosts && ctx.firstPost) { %>
|
||||||
|
</a>
|
||||||
|
<% } %>
|
||||||
|
</span>
|
||||||
<span class='prev'>
|
<span class='prev'>
|
||||||
<% if (ctx.canViewPosts && ctx.prevPost) { %>
|
<% if (ctx.canViewPosts && ctx.prevPost) { %>
|
||||||
<a class='<%- ctx.linkClass %>' href='<%= ctx.getPostUrl(ctx.prevPost.id, ctx.parameters) %>'>
|
<a class='<%- ctx.linkClass %>' href='<%= ctx.getPostUrl(ctx.prevPost.id, ctx.parameters) %>'>
|
||||||
|
@ -27,5 +36,14 @@
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</span>
|
</span>
|
||||||
|
<span class='last'>
|
||||||
|
<% if (ctx.canViewPosts && ctx.lastPost) { %>
|
||||||
|
<a class='<%- ctx.linkClass %>' href='<%= ctx.getPostUrl(ctx.lastPost.id, ctx.parameters) %>'>
|
||||||
|
<% } %>
|
||||||
|
»
|
||||||
|
<% if (ctx.canViewPosts && ctx.lastPost) { %>
|
||||||
|
</a>
|
||||||
|
<% } %>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,8 +22,10 @@ class PoolNavigatorControl extends events.EventTarget {
|
||||||
linkClass: misc.makeCssName(poolPostAround.pool.category, "pool"),
|
linkClass: misc.makeCssName(poolPostAround.pool.category, "pool"),
|
||||||
canViewPosts: api.hasPrivilege("posts:view"),
|
canViewPosts: api.hasPrivilege("posts:view"),
|
||||||
canViewPools: api.hasPrivilege("pools:view"),
|
canViewPools: api.hasPrivilege("pools:view"),
|
||||||
|
firstPost: poolPostAround.firstPost,
|
||||||
prevPost: poolPostAround.prevPost,
|
prevPost: poolPostAround.prevPost,
|
||||||
nextPost: poolPostAround.nextPost,
|
nextPost: poolPostAround.nextPost,
|
||||||
|
lastPost: poolPostAround.lastPost,
|
||||||
isActivePool: isActivePool
|
isActivePool: isActivePool
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -974,7 +974,7 @@ def search_by_image(image_content: bytes) -> List[Tuple[float, model.Post]]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
PoolPostsAround = namedtuple('PoolPostsAround', 'pool prev_post next_post')
|
PoolPostsAround = namedtuple('PoolPostsAround', 'pool first_post prev_post next_post last_post')
|
||||||
|
|
||||||
def get_pool_posts_around(post: model.Post) -> List[PoolPostsAround]:
|
def get_pool_posts_around(post: model.Post) -> List[PoolPostsAround]:
|
||||||
around = dict()
|
around = dict()
|
||||||
|
@ -990,11 +990,15 @@ def get_pool_posts_around(post: model.Post) -> List[PoolPostsAround]:
|
||||||
|
|
||||||
for order, pool_id, post_id, delta in db.session.execute(dbquery, {"post_id": post.post_id}):
|
for order, pool_id, post_id, delta in db.session.execute(dbquery, {"post_id": post.post_id}):
|
||||||
if pool_id not in around:
|
if pool_id not in around:
|
||||||
around[pool_id] = [None, None]
|
around[pool_id] = [None, None, None, None]
|
||||||
if delta < 0:
|
if delta == -2:
|
||||||
around[pool_id][0] = post_id
|
around[pool_id][0] = post_id
|
||||||
elif delta > 0:
|
elif delta == -1:
|
||||||
around[pool_id][1] = post_id
|
around[pool_id][1] = post_id
|
||||||
|
elif delta == 1:
|
||||||
|
around[pool_id][2] = post_id
|
||||||
|
elif delta == 2:
|
||||||
|
around[pool_id][3] = post_id
|
||||||
pool_ids.add(pool_id)
|
pool_ids.add(pool_id)
|
||||||
post_ids.add(post_id)
|
post_ids.add(post_id)
|
||||||
|
|
||||||
|
@ -1011,13 +1015,19 @@ def get_pool_posts_around(post: model.Post) -> List[PoolPostsAround]:
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for pool_id, entry in around.items():
|
for pool_id, entry in around.items():
|
||||||
|
first_post = None
|
||||||
prev_post = None
|
prev_post = None
|
||||||
next_post = None
|
next_post = None
|
||||||
if entry[0] is not None:
|
last_post = None
|
||||||
prev_post = posts[entry[0]]
|
|
||||||
if entry[1] is not None:
|
if entry[1] is not None:
|
||||||
next_post = posts[entry[1]]
|
prev_post = posts[entry[1]]
|
||||||
results.append(PoolPostsAround(pools[pool_id], prev_post, next_post))
|
if entry[0] is not None:
|
||||||
|
first_post = posts[entry[0]]
|
||||||
|
if entry[2] is not None:
|
||||||
|
next_post = posts[entry[2]]
|
||||||
|
if entry[3] is not None:
|
||||||
|
last_post = posts[entry[3]]
|
||||||
|
results.append(PoolPostsAround(pools[pool_id], first_post, prev_post, next_post, last_post))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@ -1033,8 +1043,10 @@ def serialize_pool_posts_around(around: List[PoolPostsAround]) -> Optional[rest.
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"pool": pools.serialize_micro_pool(entry.pool),
|
"pool": pools.serialize_micro_pool(entry.pool),
|
||||||
|
"firstPost": entry.first_post,
|
||||||
"prevPost": entry.prev_post,
|
"prevPost": entry.prev_post,
|
||||||
"nextPost": entry.next_post
|
"nextPost": entry.next_post,
|
||||||
|
"lastPost": entry.last_post
|
||||||
}
|
}
|
||||||
for entry in sort_pool_posts_around(around)
|
for entry in sort_pool_posts_around(around)
|
||||||
]
|
]
|
||||||
|
|
|
@ -39,8 +39,30 @@ BEGIN
|
||||||
WHERE pool_post.ord < main.ord
|
WHERE pool_post.ord < main.ord
|
||||||
AND pool_post.pool_id = main.pool_id
|
AND pool_post.pool_id = main.pool_id
|
||||||
ORDER BY pool_post.ord DESC LIMIT 1)
|
ORDER BY pool_post.ord DESC LIMIT 1)
|
||||||
|
UNION
|
||||||
|
(SELECT pool_post.ord,
|
||||||
|
pool_post.pool_id,
|
||||||
|
pool_post.post_id,
|
||||||
|
2 as delta,
|
||||||
|
main.ord AS target_ord,
|
||||||
|
main.pool_id AS target_pool_id
|
||||||
|
FROM pool_post, main
|
||||||
|
WHERE pool_post.ord = (SELECT MAX(pool_post.ord) FROM pool_post)
|
||||||
|
AND pool_post.pool_id = main.pool_id
|
||||||
|
ORDER BY pool_post.ord DESC LIMIT 1)
|
||||||
|
UNION
|
||||||
|
(SELECT pool_post.ord,
|
||||||
|
pool_post.pool_id,
|
||||||
|
pool_post.post_id,
|
||||||
|
-2 as delta,
|
||||||
|
main.ord AS target_ord,
|
||||||
|
main.pool_id AS target_pool_id
|
||||||
|
FROM pool_post, main
|
||||||
|
WHERE pool_post.ord = (SELECT MIN(pool_post.ord) FROM pool_post)
|
||||||
|
AND pool_post.pool_id = main.pool_id
|
||||||
|
ORDER BY pool_post.ord DESC LIMIT 1)
|
||||||
)
|
)
|
||||||
SELECT around.ord, around.pool_id, around.post_id, around.delta FROM around;
|
SELECT around.ord, around.pool_id, around.post_id, around.delta FROM around;
|
||||||
END
|
END
|
||||||
$$
|
$$
|
||||||
""")
|
""")
|
||||||
|
|
|
@ -1166,7 +1166,11 @@ def test_get_pool_posts_around(post_factory, pool_factory, config_injector):
|
||||||
db.session.add_all([post1, post2, post3, post4, pool1, pool2])
|
db.session.add_all([post1, post2, post3, post4, pool1, pool2])
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
around = posts.get_pool_posts_around(post2)
|
around = posts.get_pool_posts_around(post2)
|
||||||
|
assert around[0].first_post["id"] == post1.post_id
|
||||||
assert around[0].prev_post["id"] == post1.post_id
|
assert around[0].prev_post["id"] == post1.post_id
|
||||||
assert around[0].next_post["id"] == post3.post_id
|
assert around[0].next_post["id"] == post3.post_id
|
||||||
|
assert around[0].last_post["id"] == post4.post_id
|
||||||
|
assert around[1].first_post["id"] == post3.post_id
|
||||||
assert around[1].prev_post["id"] == post4.post_id
|
assert around[1].prev_post["id"] == post4.post_id
|
||||||
assert around[1].next_post == None
|
assert around[1].next_post == None
|
||||||
|
assert around[1].last_post == None
|
||||||
|
|
Loading…
Reference in a new issue