summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-05-25 13:27:37 +0200
committerMichał Górny <mgorny@gentoo.org>2018-05-25 13:32:41 +0200
commit38079f86567d47c443375d620eec5daf0b8e43e7 (patch)
tree07f51ba1c95c1177b2f4b60cca02711eb7a53fbe
parentAdd redirects for plain /threads and /messages URL (diff)
downloadfrontend-38079f86567d47c443375d620eec5daf0b8e43e7.tar.gz
frontend-38079f86567d47c443375d620eec5daf0b8e43e7.tar.bz2
frontend-38079f86567d47c443375d620eec5daf0b8e43e7.zip
Replace redirect on no threads with inline display
Instead of redirecting from thread to message URL when no threads are found, just display the messages inline. This prevents the irritating URL rewrite while the result is the same. Bug: https://bugs.gentoo.org/656386
-rw-r--r--ag-web.rb14
-rw-r--r--views/listmonth.erb4
2 files changed, 12 insertions, 6 deletions
diff --git a/ag-web.rb b/ag-web.rb
index 2dc8fe7..701a951 100644
--- a/ag-web.rb
+++ b/ag-web.rb
@@ -120,19 +120,25 @@ get '/:list/threads/:year-:month/:page?' do
@title = params[:list]
current_page = [(params[:page] || 1).to_i, 1].max
result = threads_in_month(params[:list], params[:year], params[:month], current_page)
- max_pages = (result['hits']['total'].to_f / PER_PAGE).ceil
+ no_threads = false
if result['hits']['total'] == 0
- redirect '/%s/messages/%s-%s/?no_threads=1' % [params[:list], params[:year], params[:month]]
- return
+ result = messages_in_month(params[:list], params[:year], params[:month], current_page)
+ no_threads = true
+ if result['hits']['total'] == 0
+ redirect '/%s/?no_messages=1' % params[:list]
+ return
+ end
end
+ max_pages = (result['hits']['total'].to_f / PER_PAGE).ceil
erb :listmonth, locals: {
results: result,
list: params[:list],
current_page: current_page,
max_pages: max_pages,
- mode: :threads
+ mode: :threads,
+ no_threads: no_threads
}
rescue => e
$stderr.puts e.to_s
diff --git a/views/listmonth.erb b/views/listmonth.erb
index 9f137f0..b7ef11c 100644
--- a/views/listmonth.erb
+++ b/views/listmonth.erb
@@ -6,7 +6,7 @@
<%= partial :views, locals: { list: list, mode: mode } %>
-<% if params[:no_threads] %>
+<% if no_threads %>
<div class="alert alert-info">
There were no threads that started this month, showing you all messages instead.
</div>
@@ -29,4 +29,4 @@
</table>
</div>
-<%= partial :pagination, locals: { current_page: current_page, max_pages: max_pages } %> \ No newline at end of file
+<%= partial :pagination, locals: { current_page: current_page, max_pages: max_pages } %>