Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: lets users favorite 2 badges to show on user-card (#13151)
- Loading branch information
Showing
17 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
app/assets/javascripts/discourse/app/controllers/user-badges.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import Controller, { inject as controller } from "@ember/controller"; | ||
import { alias, sort } from "@ember/object/computed"; | ||
import { action, computed } from "@ember/object"; | ||
import { alias, filterBy, sort } from "@ember/object/computed"; | ||
|
||
export default Controller.extend({ | ||
user: controller(), | ||
username: alias("user.model.username_lower"), | ||
sortedBadges: sort("model", "badgeSortOrder"), | ||
favoriteBadges: filterBy("model", "is_favorite", true), | ||
canFavoriteMoreBadges: computed( | ||
"favoriteBadges.length", | ||
"model.meta.max_favorites", | ||
function () { | ||
return this.favoriteBadges.length < this.model.meta.max_favorites; | ||
} | ||
), | ||
|
||
init() { | ||
this._super(...arguments); | ||
|
||
this.badgeSortOrder = ["badge.badge_type.sort_order:desc", "badge.name"]; | ||
}, | ||
|
||
@action | ||
favorite(badge) { | ||
return badge.favorite(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/assets/javascripts/discourse/app/templates/user/badges.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
{{#d-section pageClass="user-badges" class="user-content user-badges-list"}} | ||
<p class="favorite-count"> | ||
{{i18n "badges.favorite_count" count=this.favoriteBadges.length max=model.meta.max_favorites}} | ||
</p> | ||
{{#each sortedBadges as |ub|}} | ||
{{badge-card | ||
badge=ub.badge | ||
count=ub.count | ||
canFavorite=ub.can_favorite | ||
isFavorite=ub.is_favorite | ||
username=username | ||
canFavoriteMoreBadges=canFavoriteMoreBadges | ||
onFavoriteClick=(action "favorite" ub) | ||
filterUser="true"}} | ||
{{/each}} | ||
{{/d-section}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,10 @@ | |
flex-wrap: wrap; | ||
} | ||
|
||
&.user-badges-list .favorite-count { | ||
flex: 100%; | ||
} | ||
|
||
.btn.right { | ||
float: right; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddIsFavoriteToUserBadge < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :user_badges, :is_favorite, :boolean | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters