커스텀 필드 기준으로 주제 가져오기?

업데이트: 이제 (대부분) 작동하는 것 같습니다(!). 이제 커스텀 필드 값에 해당하는 “최신” 주제들이 표시됩니다. (config/routes.rb 파일에서 가장 합리적으로 느껴지는 메서드가 #latest였기 때문입니다).

실제로 해당 커스텀 필드 fun_level 값을 가진 모든 주제가 페이지에 로드되는 것이 중요합니다. 이를 위해 추가로 해야 할 일이 있을까요?


참고로, 제 기록을 위해 그리고 다른 분들에게 도움이 될 수 있도록 코드를 공유합니다:

– :fun_level 커스텀 필드를 생성했습니다. 그리고:

plugin.rb

TopicQuery.add_custom_filter(:fun_level) do |topics, query|
  if query.options[:fun_level]
    topics.where("topics.id in (
      SELECT topic_id FROM topic_custom_fields
      WHERE (name = 'fun_level')
      AND value = '#{query.options[:fun_level]}'
    )")
  else
    topics
  end
end

/connectors/my-plugin-outlet/fun-level.js.es6 (해당 페이지로 이동할 때 활성화되는 자바스크립트 파일입니다. 따라서 이 자바스크립트는 초기화 파일이나 플러그인 아웃렛에 연결된 커넥터에 있을 수 있습니다. 커넥터와 함께 사용되는 코드를 선호하므로, 여기서는 setup 컴포넌트를 사용하겠습니다):

const ajax = require('discourse/lib/ajax')

export default {
    setupComponent(args, component) {
      let parsedResultArray = []
      var endPoint = '/latest?fun_level=' + funLevel  //funLevel = params에서 가져온 값을 가진 변수   
      ajax(endPoint).then(function (result) {
            console.log('topic list result for topics matching that fun level = ')
            console.log(result.topic_list.topics)
            //결과를 파싱하고 parsedResultArray에 로드
            component.set('showTopics', parsedResultArray        
      })
   }
}

이제 해당 주제들이 my-plugin-outlet을 통해 템플릿에 배치된, 해당 컴포넌트에 있는 {{topic-list topics=showTopics}}에 로드됩니다.

큰 진전이었습니다. @angus, 정말 감사합니다.