DEV: Remove badge-select-controller (#8207)

* DEV: Remove badge-select-controller

1. The `selectableUserBadges` computed property of `badge-title` was being incorrectly overwritten, which triggered computed-property.override deprecation.

2. The `badge-select-controller` mixin contained properties that were used either by `badge-title` component or `badges/show` controller, but none were being used by both. This change moves properties where they belong, and removes the mixin.

* Update app/assets/javascripts/discourse/controllers/badges/show.js.es6

Co-Authored-By: Robin Ward <robin.ward@gmail.com>

* Improve code brevity
This commit is contained in:
Jarek Radosz 2019-10-18 02:17:05 +02:00 committed by GitHub
parent 7de3e7b322
commit ac06c87b43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 44 deletions

View File

@ -1,12 +1,22 @@
import { ajax } from "discourse/lib/ajax";
import BadgeSelectController from "discourse/mixins/badge-select-controller";
import computed from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend(BadgeSelectController, {
export default Ember.Component.extend({
classNames: ["badge-title"],
saved: false,
saving: false,
@computed("saving")
savingStatus(saving) {
return saving ? I18n.t("saving") : I18n.t("save");
},
@computed("selectableUserBadges", "selectedUserBadgeId")
selectedUserBadge(selectableUserBadges, selectedUserBadgeId) {
return selectableUserBadges.findBy("id", parseInt(selectedUserBadgeId));
},
actions: {
save() {
this.setProperties({ saved: false, saving: true });

View File

@ -1,11 +1,11 @@
import Badge from "discourse/models/badge";
import UserBadge from "discourse/models/user-badge";
import {
default as computed,
observes
} from "ember-addons/ember-computed-decorators";
import BadgeSelectController from "discourse/mixins/badge-select-controller";
export default Ember.Controller.extend(BadgeSelectController, {
export default Ember.Controller.extend({
queryParams: ["username"],
noMoreBadges: false,
userBadges: null,
@ -17,6 +17,16 @@ export default Ember.Controller.extend(BadgeSelectController, {
return userBadgesAll.filterBy("badge.allow_title", true);
},
@computed("filteredList")
selectableUserBadges(filteredList) {
return [
Ember.Object.create({
badge: Badge.create({ name: I18n.t("badges.none") })
}),
...filteredList.uniqBy("badge.name")
];
},
@computed("username")
user(username) {
if (username) {

View File

@ -1,39 +0,0 @@
import Badge from "discourse/models/badge";
import computed from "ember-addons/ember-computed-decorators";
export default Ember.Mixin.create({
saving: false,
saved: false,
@computed("filteredList")
selectableUserBadges(items) {
items = _.uniq(items, false, function(e) {
return e.get("badge.name");
});
items.unshiftObject(
Ember.Object.create({
badge: Badge.create({ name: I18n.t("badges.none") })
})
);
return items;
},
@computed("saving")
savingStatus(saving) {
return saving ? I18n.t("saving") : I18n.t("save");
},
@computed("selectedUserBadgeId")
selectedUserBadge(selectedUserBadgeId) {
selectedUserBadgeId = parseInt(selectedUserBadgeId);
let selectedUserBadge = null;
this.selectableUserBadges.forEach(function(userBadge) {
if (userBadge.get("id") === selectedUserBadgeId) {
selectedUserBadge = userBadge;
}
});
return selectedUserBadge;
},
disableSave: Ember.computed.alias("saving")
});

View File

@ -18,7 +18,7 @@
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" disabled={{disableSave}} {{action "save"}}> {{savingStatus}} </button>
<button class="btn btn-primary" disabled={{saving}} {{action "save"}}> {{savingStatus}} </button>
{{#if saved}}{{i18n 'saved'}}{{/if}}
</div>
</div>