fix forum page of last post when some posts have been deleted
parent
ac552594a2
commit
4880ffc66b
|
@ -24,7 +24,7 @@ object ForumPost extends LilaController with forum.Controller {
|
|||
data ⇒ (for {
|
||||
post ← postApi.makePost(categ, topic, data, ctx.me)
|
||||
} yield Redirect("%s#%d".format(
|
||||
routes.ForumTopic.show(categ.slug, topic.slug, postApi pageOf post),
|
||||
routes.ForumTopic.show(categ.slug, topic.slug, postApi lastPageOf topic),
|
||||
post.number)
|
||||
)).unsafePerformIO
|
||||
)
|
||||
|
|
|
@ -9,8 +9,12 @@ final class CategApi(env: ForumEnv) {
|
|||
val list: IO[List[CategView]] = for {
|
||||
categs ← env.categRepo.all
|
||||
views ← (categs map { categ ⇒
|
||||
env.postApi get categ.lastPostId map { post ⇒
|
||||
CategView(categ, post, env.postApi.pageOf)
|
||||
env.postApi get categ.lastPostId map { topicPost ⇒
|
||||
CategView(categ, topicPost map {
|
||||
_ match {
|
||||
case (topic, post) ⇒ (topic, post, env.postApi lastPageOf topic)
|
||||
}
|
||||
})
|
||||
}
|
||||
}).sequence
|
||||
} yield views
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
case class CategView(
|
||||
categ: Categ,
|
||||
lastPost: Option[(Topic, Post)],
|
||||
pageOf: Post ⇒ Int) {
|
||||
|
||||
def slug = categ.slug
|
||||
def name = categ.name
|
||||
def desc = categ.desc
|
||||
def nbTopics = categ.nbTopics
|
||||
def nbPosts = categ.nbPosts
|
||||
}
|
|
@ -57,13 +57,14 @@ final class PostApi(env: ForumEnv, maxPerPage: Int) {
|
|||
io(none[Categ])
|
||||
)
|
||||
} yield topicOption |@| categOption apply {
|
||||
case (topic, categ) ⇒ PostView(post, topic, categ, pageOf)
|
||||
case (topic, categ) ⇒ PostView(post, topic, categ, lastPageOf(topic))
|
||||
}
|
||||
|
||||
def lastNumberOf(topic: Topic): IO[Int] =
|
||||
env.postRepo lastByTopics List(topic) map (_.number)
|
||||
|
||||
def pageOf(post: Post) = ceil(post.number / maxPerPage.toFloat).toInt
|
||||
def lastPageOf(topic: Topic) =
|
||||
ceil(topic.nbPosts / maxPerPage.toFloat).toInt
|
||||
|
||||
def paginator(topic: Topic, page: Int): Paginator[Post] =
|
||||
Paginator(
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
case class PostView(
|
||||
post: Post,
|
||||
topic: Topic,
|
||||
categ: Categ,
|
||||
pageOf: Post ⇒ Int) {
|
||||
|
||||
}
|
|
@ -59,7 +59,7 @@ final class TopicApi(env: ForumEnv, maxPerPage: Int) {
|
|||
query = env.topicRepo byCategQuery categ,
|
||||
sort = env.topicRepo.sortQuery) map { topic ⇒
|
||||
env.postRepo byId topic.lastPostId map { post ⇒
|
||||
TopicView(categ, topic, post, env.postApi.pageOf)
|
||||
TopicView(categ, topic, post, env.postApi lastPageOf topic)
|
||||
} unsafePerformIO
|
||||
},
|
||||
currentPage = page,
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
case class TopicView(
|
||||
categ: Categ,
|
||||
topic: Topic,
|
||||
lastPost: Option[Post],
|
||||
pageOf: Post ⇒ Int) {
|
||||
|
||||
def id = topic.id
|
||||
def slug = topic.slug
|
||||
def name = topic.name
|
||||
def views = topic.views
|
||||
def createdAt = topic.createdAt
|
||||
def nbPosts = topic.nbPosts
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
case class CategView(
|
||||
categ: Categ,
|
||||
lastPost: Option[(Topic, Post, Int)]) {
|
||||
|
||||
def slug = categ.slug
|
||||
def name = categ.name
|
||||
def desc = categ.desc
|
||||
def nbTopics = categ.nbTopics
|
||||
def nbPosts = categ.nbPosts
|
||||
}
|
||||
|
||||
case class TopicView(
|
||||
categ: Categ,
|
||||
topic: Topic,
|
||||
lastPost: Option[Post],
|
||||
lastPage: Int) {
|
||||
|
||||
def id = topic.id
|
||||
def slug = topic.slug
|
||||
def name = topic.name
|
||||
def views = topic.views
|
||||
def createdAt = topic.createdAt
|
||||
def nbPosts = topic.nbPosts
|
||||
}
|
||||
|
||||
case class PostView(
|
||||
post: Post,
|
||||
topic: Topic,
|
||||
categ: Categ,
|
||||
topicLastPage: Int)
|
|
@ -27,8 +27,8 @@ title = trans.forum.str()) {
|
|||
<td class="right">@categ.nbPosts</td>
|
||||
<td class="last_post">
|
||||
@categ.lastPost.map {
|
||||
case (topic, post) => {
|
||||
<a href="@routes.ForumTopic.show(categ.slug, topic.slug, categ pageOf post)#@post.number">@showDate(post.createdAt)</a><br />by @Html(authorName(post))
|
||||
case (topic, post, page) => {
|
||||
<a href="@routes.ForumTopic.show(categ.slug, topic.slug, page)#@post.number">@showDate(post.createdAt)</a><br />by @Html(authorName(post))
|
||||
}
|
||||
}
|
||||
</td>
|
||||
|
|
|
@ -33,7 +33,7 @@ title = categ.name) {
|
|||
<td class="right">@(topic.nbPosts - 1)</td>
|
||||
<td class="last_post">
|
||||
@topic.lastPost.map { post =>
|
||||
<a href="@routes.ForumTopic.show(categ.slug, topic.slug, topic pageOf post)#@post.number">@showDate(post.createdAt)</a><br />by @Html(authorName(post))
|
||||
<a href="@routes.ForumTopic.show(categ.slug, topic.slug, topic.lastPage)#@post.number">@showDate(post.createdAt)</a><br />by @Html(authorName(post))
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@(posts: List[lila.forum.PostView])(implicit ctx: Context)
|
||||
@for(v <- posts) {
|
||||
@defining(routes.ForumTopic.show(v.categ.slug, v.topic.slug, v pageOf v.post) + "#" + v.post.number) { postUrl =>
|
||||
@defining(routes.ForumTopic.show(v.categ.slug, v.topic.slug, v.topicLastPage) + "#" + v.post.number) { postUrl =>
|
||||
<li>
|
||||
<a class="post_link" href="@postUrl">@v.topic.name</a>
|
||||
<span>@authorLink(v.post, withOnline = false)</span>
|
||||
|
|
|
@ -60,8 +60,8 @@
|
|||
|
||||
var container = window.document.getElementById("monitors")
|
||||
|
||||
app.rps = new SpeedOMeter({
|
||||
name : "RPS",
|
||||
app.rps = new SpeedOMeter({
|
||||
name : "RPS",
|
||||
maxVal : 100,
|
||||
threshold: 0.9,
|
||||
container : container
|
||||
|
@ -85,14 +85,14 @@
|
|||
app.thread = new SpeedOMeter({
|
||||
name : "THREAD",
|
||||
maxVal : 300,
|
||||
threshold: 0.5,
|
||||
threshold: 0.8,
|
||||
container : container
|
||||
});
|
||||
|
||||
app.load = new SpeedOMeter({
|
||||
name : "LOAD",
|
||||
maxVal : 1,
|
||||
threshold: 0.3,
|
||||
threshold: 0.5,
|
||||
container : container
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue