diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index 4855c384f7..772951a2e3 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -525,6 +525,17 @@ def comments render 'show' end + def subtopics + # here, we look for this special tag marking a node as having a parent + # collect the "slugs" i.e. the unique part of the URL, which should correspond to a tagname + subtopic_names = Tag.find_by(name: "parent:#{params[:topic]}") + &.nodes + &.collect(&:slug) + @subtopics = Tag.find_by(name: subtopic_names) + render "tag/_subtopics", layout: false + end + + private def order_string @@ -568,4 +579,5 @@ def fetch_counts end def topic_tree; end + end diff --git a/app/views/tag/_subtopics.html.erb b/app/views/tag/_subtopics.html.erb new file mode 100644 index 0000000000..c896a3adf6 --- /dev/null +++ b/app/views/tag/_subtopics.html.erb @@ -0,0 +1,3 @@ +<% @subtopics&.each do |subtopic| %> +

<%= subtopic %>

+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 88baa62445..75e9e450ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -383,6 +383,7 @@ post 'comment/react/update/:id' => 'comment#react_update' get 'topic-tree' => 'tag#topic_tree' + get 'tags/subtopic/:topic' => 'tag#subtopics' # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products diff --git a/test/fixtures/node_tags.yml b/test/fixtures/node_tags.yml index 4f2be77509..68f92f40e2 100644 --- a/test/fixtures/node_tags.yml +++ b/test/fixtures/node_tags.yml @@ -284,3 +284,9 @@ sub_tag: tid: 37 nid: 1 uid: 2 + +subtopic_tag: + tid: 38 + uid: 2 + nid: 41 + date: <%= DateTime.now.to_i %> \ No newline at end of file diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index 0fc023fc87..780b5faf68 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -150,3 +150,7 @@ hidden_response_tag: subscribed_tag: tid: 37 name: sub:tag + +subtopic_tag: + tid: 38 + name: parent:one \ No newline at end of file diff --git a/test/functional/tag_controller_test.rb b/test/functional/tag_controller_test.rb index 0c60755709..0070e04925 100644 --- a/test/functional/tag_controller_test.rb +++ b/test/functional/tag_controller_test.rb @@ -458,6 +458,15 @@ def setup assert_not_nil assigns(:notes) assert (notes & expected).present? end + + test 'subtopics partial' do + get :subtopics, + params: { + topic: 'test' + } + assert :success + assert_not_nil assigns(:subtopics) + end test 'shows suggested tags' do get :suggested, params: { id: 'spectr' }