fix forum page of last post when some posts have been deleted

pull/1/merge
Thibault Duplessis 2012-06-05 23:04:03 +02:00
parent ac552594a2
commit 4880ffc66b
12 changed files with 52 additions and 54 deletions

View File

@ -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
)

View File

@ -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

View File

@ -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
}

View File

@ -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(

View File

@ -1,10 +0,0 @@
package lila
package forum
case class PostView(
post: Post,
topic: Topic,
categ: Categ,
pageOf: Post Int) {
}

View File

@ -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,

View File

@ -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
}

View File

@ -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)

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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
});