mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 22:34:44 +08:00
FEATURE: Demote muted categories on category list (#9226)
This commit is contained in:
@ -1,14 +1,16 @@
|
|||||||
{{#each categories as |c|}}
|
{{#each categories as |c|}}
|
||||||
<div class='category category-box category-box-{{c.slug}}' style={{border-color c.color}}>
|
<div data-notification-level={{c.notificationLevelString}} class='category category-box category-box-{{c.slug}} {{if c.isMuted "muted"}}' style={{border-color c.color}}>
|
||||||
<div class='category-box-inner'>
|
<div class='category-box-inner'>
|
||||||
<div class='category-box-heading'>
|
<div class='category-box-heading'>
|
||||||
<a href={{c.url}}>
|
<a href={{c.url}}>
|
||||||
|
{{#unless c.isMuted}}
|
||||||
{{#if c.uploaded_logo.url}}
|
{{#if c.uploaded_logo.url}}
|
||||||
{{cdn-img src=c.uploaded_logo.url
|
{{cdn-img src=c.uploaded_logo.url
|
||||||
class="logo"
|
class="logo"
|
||||||
width=c.uploaded_logo.width
|
width=c.uploaded_logo.width
|
||||||
height=c.uploaded_logo.height}}
|
height=c.uploaded_logo.height}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
{{category-title-before category=c}}
|
{{category-title-before category=c}}
|
||||||
@ -20,6 +22,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#unless c.isMuted}}
|
||||||
<div class='featured-topics'>
|
<div class='featured-topics'>
|
||||||
{{#if c.topics}}
|
{{#if c.topics}}
|
||||||
<ul>
|
<ul>
|
||||||
@ -29,6 +32,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
{{#each categories as |c|}}
|
{{#each categories as |c|}}
|
||||||
<div class='category category-box category-box-{{c.slug}}' style={{border-color c.color}} data-category-id={{c.id}} data-notification-level={{c.notificationLevelString}}
|
<div class='category category-box category-box-{{c.slug}} {{if c.isMuted "muted"}}' style={{border-color c.color}} data-category-id={{c.id}} data-notification-level={{c.notificationLevelString}}
|
||||||
data-url={{c.url}}>
|
data-url={{c.url}}>
|
||||||
<div class='category-box-inner'>
|
<div class='category-box-inner'>
|
||||||
|
{{#unless c.isMuted}}
|
||||||
<div class="category-logo">
|
<div class="category-logo">
|
||||||
{{#if c.uploaded_logo.url}}
|
{{#if c.uploaded_logo.url}}
|
||||||
{{cdn-img
|
{{cdn-img
|
||||||
@ -11,6 +12,7 @@
|
|||||||
height=c.uploaded_logo.height}}
|
height=c.uploaded_logo.height}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
{{/unless}}
|
||||||
<div class="category-details">
|
<div class="category-details">
|
||||||
<div class='category-box-heading'>
|
<div class='category-box-heading'>
|
||||||
<a class="parent-box-link" href={{c.url}}>
|
<a class="parent-box-link" href={{c.url}}>
|
||||||
@ -23,6 +25,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#unless c.isMuted}}
|
||||||
<div class='description'>
|
<div class='description'>
|
||||||
{{text-overflow class="overflow" text=c.description_excerpt}}
|
{{text-overflow class="overflow" text=c.description_excerpt}}
|
||||||
</div>
|
</div>
|
||||||
@ -62,6 +65,7 @@
|
|||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
<tbody aria-labelledby="categories-only-category">
|
<tbody aria-labelledby="categories-only-category">
|
||||||
{{#each categories as |c|}}
|
{{#each categories as |c|}}
|
||||||
<tr data-category-id={{c.id}} data-notification-level={{c.notificationLevelString}} class="{{if c.description_excerpt 'has-description' 'no-description'}} {{if c.uploaded_logo.url 'has-logo' 'no-logo'}}">
|
<tr data-category-id={{c.id}} data-notification-level={{c.notificationLevelString}} class="{{if c.description_excerpt 'has-description' 'no-description'}} {{if c.uploaded_logo.url 'has-logo' 'no-logo'}}">
|
||||||
<td class="category" style={{border-color c.color}}>
|
<td class="category {{if c.isMuted 'muted'}}" style={{border-color c.color}}>
|
||||||
{{category-title-link category=c}}
|
{{category-title-link category=c}}
|
||||||
|
{{#unless c.isMuted}}
|
||||||
{{#if c.description_excerpt}}
|
{{#if c.description_excerpt}}
|
||||||
<div class="category-description">
|
<div class="category-description">
|
||||||
{{dir-span c.description_excerpt}}
|
{{dir-span c.description_excerpt}}
|
||||||
@ -67,11 +68,13 @@
|
|||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
</td>
|
</td>
|
||||||
<td class="topics">
|
<td class="topics">
|
||||||
<div title={{c.statTitle}}>{{html-safe c.stat}}</div>
|
<div title={{c.statTitle}}>{{html-safe c.stat}}</div>
|
||||||
{{category-unread category=c tagName="div" class="unread-new"}}
|
{{category-unread category=c tagName="div" class="unread-new"}}
|
||||||
</td>
|
</td>
|
||||||
|
{{#unless c.isMuted}}
|
||||||
{{#if showTopics}}
|
{{#if showTopics}}
|
||||||
<td class="latest">
|
<td class="latest">
|
||||||
{{#each c.featuredTopics as |t|}}
|
{{#each c.featuredTopics as |t|}}
|
||||||
@ -79,6 +82,7 @@
|
|||||||
{{/each}}
|
{{/each}}
|
||||||
</td>
|
</td>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{{#if categories}}
|
{{#if categories}}
|
||||||
<div class="category-list {{if showTopics 'with-topics'}}">
|
<div class="category-list {{if showTopics 'with-topics'}}">
|
||||||
{{#each categories as |c|}}
|
{{#each categories as |c|}}
|
||||||
<div data-category-id={{c.id}} class='category-list-item category' style={{border-color c.color}}>
|
<div data-category-id={{c.id}} data-notification-level={{c.notificationLevelString}} class='category-list-item category {{if c.isMuted "muted"}}' style={{border-color c.color}}>
|
||||||
<table class='topic-list'>
|
<table class='topic-list'>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@ -10,6 +10,7 @@
|
|||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
{{#unless c.isMuted}}
|
||||||
{{#if c.description_excerpt}}
|
{{#if c.description_excerpt}}
|
||||||
<tr class="category-description">
|
<tr class="category-description">
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
@ -57,6 +58,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/unless}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<footer class="clearfix">
|
<footer class="clearfix">
|
||||||
|
@ -316,3 +316,11 @@
|
|||||||
--max-height: 75px;
|
--max-height: 75px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.categories-list .category.muted {
|
||||||
|
font-size: $font-down-1;
|
||||||
|
h3,
|
||||||
|
.category-name {
|
||||||
|
color: $primary-medium;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ class CategoryList
|
|||||||
find_user_data
|
find_user_data
|
||||||
sort_unpinned
|
sort_unpinned
|
||||||
trim_results
|
trim_results
|
||||||
|
demote_muted
|
||||||
|
|
||||||
if preloaded_topic_custom_fields.present?
|
if preloaded_topic_custom_fields.present?
|
||||||
displayable_topics = @categories.map(&:displayable_topics)
|
displayable_topics = @categories.map(&:displayable_topics)
|
||||||
@ -162,6 +163,12 @@ class CategoryList
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def demote_muted
|
||||||
|
muted_categories = @categories.select { |category| category.notification_level == 0 }
|
||||||
|
@categories = @categories.reject { |category| category.notification_level == 0 }
|
||||||
|
@categories.concat muted_categories
|
||||||
|
end
|
||||||
|
|
||||||
def trim_results
|
def trim_results
|
||||||
@categories.each do |c|
|
@categories.each do |c|
|
||||||
next if c.displayable_topics.blank?
|
next if c.displayable_topics.blank?
|
||||||
|
@ -220,6 +220,22 @@ describe CategoryList do
|
|||||||
expect(category_ids_admin).to eq([public_cat2.id, public_cat.id])
|
expect(category_ids_admin).to eq([public_cat2.id, public_cat.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'some categories are muted' do
|
||||||
|
let!(:cat1) { Fabricate(:category_with_definition) }
|
||||||
|
let!(:muted_cat) { Fabricate(:category_with_definition) }
|
||||||
|
let!(:cat3) { Fabricate(:category_with_definition) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:muted], muted_cat.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns muted categories at the end of the list" do
|
||||||
|
category_list = CategoryList.new(Guardian.new user).categories.pluck(:id)
|
||||||
|
|
||||||
|
expect(category_list).to eq([SiteSetting.uncategorized_category_id, cat1.id, cat3.id, muted_cat.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user