mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:57:29 +08:00
FEATURE: Support filtering of groups page by category if in url
This commit is contained in:
parent
ca8922e6f8
commit
076df104dc
|
@ -0,0 +1,3 @@
|
|||
export default Ember.Component.extend({
|
||||
tagName: 'li'
|
||||
});
|
|
@ -2,6 +2,7 @@ import { fmt } from 'discourse/lib/computed';
|
|||
|
||||
export default Ember.Controller.extend({
|
||||
group: Ember.inject.controller(),
|
||||
groupActivity: Ember.inject.controller(),
|
||||
loading: false,
|
||||
emptyText: fmt('type', 'groups.empty.%@'),
|
||||
|
||||
|
@ -14,7 +15,9 @@ export default Ember.Controller.extend({
|
|||
const beforePostId = posts[posts.length-1].get('id');
|
||||
const group = this.get('group.model');
|
||||
|
||||
const opts = { beforePostId, type: this.get('type') };
|
||||
let categoryId = this.get('groupActivity.category_id');
|
||||
const opts = { beforePostId, type: this.get('type'), categoryId };
|
||||
|
||||
group.findPosts(opts).then(newPosts => {
|
||||
posts.addObjects(newPosts);
|
||||
this.set('loading', false);
|
||||
|
|
|
@ -2,6 +2,7 @@ import computed from 'ember-addons/ember-computed-decorators';
|
|||
|
||||
export default Ember.Controller.extend({
|
||||
application: Ember.inject.controller(),
|
||||
queryParams: ['category_id'],
|
||||
|
||||
@computed('model.is_group_user')
|
||||
showGroupMessages(isGroupUser) {
|
||||
|
|
|
@ -203,12 +203,13 @@ const Group = RestModel.extend({
|
|||
findPosts(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
const type = opts['type'] || 'posts';
|
||||
const type = opts.type || 'posts';
|
||||
|
||||
var data = {};
|
||||
if (opts.beforePostId) { data.before_post_id = opts.beforePostId; }
|
||||
if (opts.categoryId) { data.category_id = parseInt(opts.categoryId); }
|
||||
|
||||
return ajax(`/groups/${this.get('name')}/${type}.json`, { data: data }).then(posts => {
|
||||
return ajax(`/groups/${this.get('name')}/${type}.json`, { data }).then(posts => {
|
||||
return posts.map(p => {
|
||||
p.user = User.create(p.user);
|
||||
p.topic = Topic.create(p.topic);
|
||||
|
|
|
@ -6,8 +6,9 @@ export function buildGroupPage(type) {
|
|||
return I18n.t(`groups.${type}`);
|
||||
},
|
||||
|
||||
model() {
|
||||
return this.modelFor("group").findPosts({ type });
|
||||
model(params, transition) {
|
||||
let categoryId = Ember.get(transition, 'queryParams.category_id');
|
||||
return this.modelFor("group").findPosts({ type, categoryId });
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{{#link-to (concat 'group.activity.' filter) (query-params category_id=categoryId)}}
|
||||
{{i18n (concat 'groups.' filter)}}
|
||||
{{/link-to}}
|
|
@ -1,21 +1,10 @@
|
|||
<div class='group-activity container'>
|
||||
{{#mobile-nav class='group-activity-nav' desktopClass="pull-left nav nav-stacked" currentPath=application.currentPath}}
|
||||
<li>
|
||||
{{#link-to 'group.activity.posts'}}{{i18n 'groups.posts'}}{{/link-to}}
|
||||
</li>
|
||||
|
||||
<li>
|
||||
{{#link-to 'group.activity.topics'}}{{i18n 'groups.topics'}}{{/link-to}}
|
||||
</li>
|
||||
|
||||
<li>
|
||||
{{#link-to 'group.activity.mentions'}}{{i18n 'groups.mentions'}}{{/link-to}}
|
||||
</li>
|
||||
|
||||
{{group-activity-filter filter="posts" categoryId=category_id}}
|
||||
{{group-activity-filter filter="topics" categoryId=category_id}}
|
||||
{{group-activity-filter filter="mentions" categoryId=category_id}}
|
||||
{{#if showGroupMessages}}
|
||||
<li>
|
||||
{{#link-to 'group.activity.messages'}}{{i18n 'groups.messages'}}{{/link-to}}
|
||||
</li>
|
||||
{{group-activity-filter filter="messages"}}
|
||||
{{/if}}
|
||||
{{/mobile-nav}}
|
||||
|
||||
|
|
|
@ -69,13 +69,19 @@ class GroupsController < ApplicationController
|
|||
|
||||
def posts
|
||||
group = find_group(:group_id)
|
||||
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
|
||||
posts = group.posts_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).limit(20)
|
||||
render_serialized posts.to_a, GroupPostSerializer
|
||||
end
|
||||
|
||||
def posts_feed
|
||||
group = find_group(:group_id)
|
||||
@posts = group.posts_for(guardian).limit(50)
|
||||
@posts = group.posts_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).limit(50)
|
||||
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.group_posts", group_name: group.name)}"
|
||||
@link = Discourse.base_url
|
||||
@description = I18n.t("rss_description.group_posts", group_name: group.name)
|
||||
|
@ -84,19 +90,28 @@ class GroupsController < ApplicationController
|
|||
|
||||
def topics
|
||||
group = find_group(:group_id)
|
||||
posts = group.posts_for(guardian, params[:before_post_id]).where(post_number: 1).limit(20)
|
||||
posts = group.posts_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).where(post_number: 1).limit(20)
|
||||
render_serialized posts.to_a, GroupPostSerializer
|
||||
end
|
||||
|
||||
def mentions
|
||||
group = find_group(:group_id)
|
||||
posts = group.mentioned_posts_for(guardian, params[:before_post_id]).limit(20)
|
||||
posts = group.mentioned_posts_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).limit(20)
|
||||
render_serialized posts.to_a, GroupPostSerializer
|
||||
end
|
||||
|
||||
def mentions_feed
|
||||
group = find_group(:group_id)
|
||||
@posts = group.mentioned_posts_for(guardian).limit(50)
|
||||
@posts = group.mentioned_posts_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).limit(50)
|
||||
@title = "#{SiteSetting.title} - #{I18n.t("rss_description.group_mentions", group_name: group.name)}"
|
||||
@link = Discourse.base_url
|
||||
@description = I18n.t("rss_description.group_mentions", group_name: group.name)
|
||||
|
@ -106,7 +121,10 @@ class GroupsController < ApplicationController
|
|||
def messages
|
||||
group = find_group(:group_id)
|
||||
posts = if guardian.can_see_group_messages?(group)
|
||||
group.messages_for(guardian, params[:before_post_id]).where(post_number: 1).limit(20).to_a
|
||||
group.messages_for(
|
||||
guardian,
|
||||
params.permit(:before_post_id, :category_id)
|
||||
).where(post_number: 1).limit(20).to_a
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
|
|
@ -185,7 +185,8 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def posts_for(guardian, before_post_id = nil)
|
||||
def posts_for(guardian, opts = nil)
|
||||
opts ||= {}
|
||||
user_ids = group_users.map { |gu| gu.user_id }
|
||||
result = Post.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
|
@ -193,24 +194,35 @@ class Group < ActiveRecord::Base
|
|||
.where('topics.archetype <> ?', Archetype.private_message)
|
||||
.where(post_type: Post.types[:regular])
|
||||
|
||||
if opts[:category_id].present?
|
||||
result = result.where('topics.category_id = ?', opts[:category_id].to_i)
|
||||
end
|
||||
|
||||
result = guardian.filter_allowed_categories(result)
|
||||
result = result.where('posts.id < ?', before_post_id) if before_post_id
|
||||
result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
|
||||
result.order('posts.created_at desc')
|
||||
end
|
||||
|
||||
def messages_for(guardian, before_post_id = nil)
|
||||
def messages_for(guardian, opts = nil)
|
||||
opts ||= {}
|
||||
|
||||
result = Post.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
.where('topics.archetype = ?', Archetype.private_message)
|
||||
.where(post_type: Post.types[:regular])
|
||||
.where('topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)', self.id)
|
||||
|
||||
if opts[:category_id].present?
|
||||
result = result.where('topics.category_id = ?', opts[:category_id].to_i)
|
||||
end
|
||||
|
||||
result = guardian.filter_allowed_categories(result)
|
||||
result = result.where('posts.id < ?', before_post_id) if before_post_id
|
||||
result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
|
||||
result.order('posts.created_at desc')
|
||||
end
|
||||
|
||||
def mentioned_posts_for(guardian, before_post_id = nil)
|
||||
def mentioned_posts_for(guardian, opts = nil)
|
||||
opts ||= {}
|
||||
result = Post.joins(:group_mentions)
|
||||
.includes(:user, :topic, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
|
@ -218,8 +230,12 @@ class Group < ActiveRecord::Base
|
|||
.where(post_type: Post.types[:regular])
|
||||
.where('group_mentions.group_id = ?', self.id)
|
||||
|
||||
if opts[:category_id].present?
|
||||
result = result.where('topics.category_id = ?', opts[:category_id].to_i)
|
||||
end
|
||||
|
||||
result = guardian.filter_allowed_categories(result)
|
||||
result = result.where('posts.id < ?', before_post_id) if before_post_id
|
||||
result = result.where('posts.id < ?', opts[:before_post_id].to_i) if opts[:before_post_id]
|
||||
result.order('posts.created_at desc')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user