Discourse Docs is the primary reason that I chose to use Discourse vs other forum software. However, it has one major shortcoming for me - by default it sorts by activity. I’d like to remove the ability to sort by activity altogether, but can’t figure out how to do so.
I’ve found this section of code, and removed the elsif statement for activity sorting and it doesn’t help.
if @filters[:order] == "title"
if @filters[:ascending].present?
results = results.reorder('topics.title')
else
results = results.reorder('topics.title DESC')
end
elsif @filters[:order] == "activity"
if @filters[:ascending].present?
results = results.reorder('topics.last_posted_at')
else
results = results.reorder('topics.last_posted_at DESC')
end
end
I’ve also done the same in this file and it also still provides the same sorting abilities.
context 'when ordering results' do
context 'by title' do
it 'should return the list ordered descending' do
get "/docs.json?order=title"
expect(response.status).to eq(200)
json = response.parsed_body
topics = json['topics']['topic_list']['topics']
expect(topics[0]['id']).to eq(topic2.id)
expect(topics[1]['id']).to eq(topic.id)
end
it 'should return the list ordered ascending with an additional parameter' do
get "/docs.json?order=title&ascending=true"
expect(response.status).to eq(200)
json = response.parsed_body
topics = json['topics']['topic_list']['topics']
expect(topics[0]['id']).to eq(topic.id)
expect(topics[1]['id']).to eq(topic2.id)
end
end
context 'by date' do
before do
topic2.update(last_posted_at: Time.zone.now + 100)
end
it 'should return the list ordered descending' do
get "/docs.json?order=activity"
expect(response.status).to eq(200)
json = response.parsed_body
topics = json['topics']['topic_list']['topics']
expect(topics[0]['id']).to eq(topic.id)
expect(topics[1]['id']).to eq(topic2.id)
end
it 'should return the list ordered ascending with an additional parameter' do
get "/docs.json?order=activity&ascending=true"
expect(response.status).to eq(200)
json = response.parsed_body
topics = json['topics']['topic_list']['topics']
expect(topics[0]['id']).to eq(topic2.id)
expect(topics[1]['id']).to eq(topic.id)
end
end
end
I did the edits both directly in the file on the server, as well as in a fork of Discourse Docs which i then installed.
Does anyone have any tips? I really thought it would be a 3 minute job but have spent many hours on this now…
Thanks!