FEATURE: add query to list all assigned topics

This lists all the topics assigned to all users ordered by user / topic id
This commit is contained in:
Sam Saffron 2019-04-15 16:11:05 +10:00
parent 859021bb3c
commit 5f3bcab2f8
1 changed files with 15 additions and 0 deletions

View File

@ -68,6 +68,11 @@ class Queries
"id": -12, "id": -12,
"name": "List of topics a user is watching/tracking/muted", "name": "List of topics a user is watching/tracking/muted",
"description": "The query requires a notification_level parameter. Use 0 for muted, 1 for regular, 2 for tracked and 3 for watched topics." "description": "The query requires a notification_level parameter. Use 0 for muted, 1 for regular, 2 for tracked and 3 for watched topics."
},
"assigned-topics-report": {
"id": -13,
"name": "List of assigned topics by user",
"description": "This report requires the assign plugin, it will find all assigned topics"
} }
}.with_indifferent_access }.with_indifferent_access
@ -373,6 +378,16 @@ class Queries
ORDER BY tu.last_visited_at DESC ORDER BY tu.last_visited_at DESC
SQL SQL
queries["assigned-topics-report"]["sql"] = <<~SQL
SELECT value::int user_id, topic_id
FROM topic_custom_fields tf
JOIN topics t on t.id = topic_id
JOIN users u on u.id = value::int
WHERE tf.name = 'assigned_to_id'
AND t.deleted_at IS NULL
ORDER BY username, topic_id
SQL
# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc. # convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" } queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
queries queries