REFACTOR: old ember patterns, deprecations, dead code (#42)

This commit is contained in:
Joffrey JAFFEUX 2019-07-19 09:56:39 +02:00 committed by GitHub
parent 8f92c5f9bd
commit 75c6cecfdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 50 additions and 51 deletions

View File

@ -18,10 +18,10 @@ export default {
actions: {
unassign() {
this.set("topic.assigned_to_user", null);
this.get("taskActions").unassign(this.get("topic.id"));
this.taskActions.unassign(this.get("topic.id"));
},
assign() {
this.get("taskActions").assign(this.topic);
this.taskActions.assign(this.topic);
}
}
};

View File

@ -1,19 +1,17 @@
//import { default as computed } from 'ember-addons/ember-computed-decorators';
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
assignSuggestions: null,
taskActions: Ember.inject.service(),
assignSuggestions: function() {
ajax("/assign/suggestions").then(users => {
this.set("assignSuggestions", users);
});
}.property(),
// @computed("username")
// disabled(username) {
// return Ember.isEmpty(username);
// },
init() {
this._super(...arguments);
ajax("/assign/suggestions").then(users =>
this.set("assignSuggestions", users)
);
},
onClose() {
if (this.get("model.onClose") && this.get("model.username")) {
@ -23,8 +21,10 @@ export default Ember.Controller.extend({
actions: {
assignUser(user) {
this.set("model.username", user.username);
this.set("model.allowedGroups", this.get("taskActions").allowedGroups);
this.setProperties({
"model.username": user.username,
"model.allowedGroups": this.taskActions.allowedGroups
});
this.send("assign");
},

View File

@ -6,12 +6,12 @@ export default UserTopicsList.extend({
actions: {
unassign(topic) {
this.get("taskActions")
this.taskActions
.unassign(topic.get("id"))
.then(() => this.send("changeAssigned"));
},
reassign(topic) {
const controller = this.get("taskActions").assign(topic);
const controller = this.taskActions.assign(topic);
controller.set("model.onSuccess", () => this.send("changeAssigned"));
}
}

View File

@ -35,13 +35,13 @@ function modifySelectKit(api) {
return;
}
const topic = context.get("topic");
const topic = context.topic;
const assignedUser = topic.get("assigned_to_user.username");
if (assignedUser) {
ajax("/assign/unassign", {
type: "PUT",
data: { topic_id: topic.get("id") }
data: { topic_id: topic.id }
})
.then(result => {
if (result.success && result.success === "OK") {
@ -87,13 +87,14 @@ function initialize(api) {
}
}
return this.get("actableFilter");
return this.actableFilter;
},
didInsertElement() {
this._super();
this._super(...arguments);
this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedPost = this.get("flaggedPost");
let flaggedPost = this.flaggedPost;
if (data.topic_id === flaggedPost.get("topic.id")) {
flaggedPost.set(
"topic.assigned_to_user_id",
@ -105,7 +106,8 @@ function initialize(api) {
},
willDestroyElement() {
this._super();
this._super(...arguments);
this.messageBus.unsubscribe("/staff/topic-assignment");
}
},
@ -140,14 +142,14 @@ function initialize(api) {
api.addTagsHtmlCallback(topic => {
const assignedTo = topic.get("assigned_to_user.username");
if (assignedTo) {
const assignedPath = topic.get("assignedToUserPath");
const assignedPath = topic.assignedToUserPath;
let assignLabels = `<a data-auto-route='true' class='assigned-to discourse-tag simple' href='${assignedPath}'>${iconHTML(
"user-plus"
)}${assignedTo}</a>`;
if (
ListItemDefaults === undefined &&
topic.get("archetype") === "private_message"
topic.archetype === "private_message"
) {
assignLabels += `<div>${iconHTML("envelope")} Message</div>`;
}
@ -157,12 +159,12 @@ function initialize(api) {
});
api.addUserMenuGlyph(widget => {
if (widget.currentUser && widget.currentUser.get("can_assign")) {
if (widget.currentUser && widget.currentUser.can_assign) {
return {
label: "discourse_assign.assigned",
className: "assigned",
icon: "user-plus",
href: `${widget.currentUser.get("path")}/activity/assigned`
href: `${widget.currentUser.path}/activity/assigned`
};
}
});
@ -185,10 +187,11 @@ function initialize(api) {
api.modifyClass("controller:topic", {
subscribe() {
this._super();
this._super(...arguments);
this.messageBus.subscribe("/staff/topic-assignment", data => {
const topic = this.get("model");
const topicId = topic.get("id");
const topic = this.model;
const topicId = topic.id;
if (data.topic_id === topicId) {
topic.set(
@ -233,7 +236,7 @@ function initialize(api) {
api.modifyClass("controller:preferences/notifications", {
actions: {
save() {
this.get("saveAttrNames").push("custom_fields");
this.saveAttrNames.push("custom_fields");
this._super(...arguments);
}
}

View File

@ -28,10 +28,10 @@ export default DropdownSelectBoxComponent.extend({
onSelect(id) {
switch (id) {
case "unassign":
this.unassign(this.get("topic"), this.get("user"));
this.unassign(this.topic, this.user);
break;
case "reassign":
this.reassign(this.get("topic"), this.get("user"));
this.reassign(this.topic, this.user);
break;
}
}

View File

@ -1,11 +1,5 @@
import computed from "ember-addons/ember-computed-decorators";
import { ListItemDefaults } from "discourse/components/topic-list-item";
const privateMessageHelper = {
@computed("topic.archetype")
isPrivateMessage(archetype) {
return archetype === "private_message";
}
};
export default Ember.Component.extend(ListItemDefaults, privateMessageHelper);
export default Ember.Component.extend(ListItemDefaults, {
isPrivateMessage: Ember.computed.equal("topic.archetype", "private_message")
});

View File

@ -25,7 +25,7 @@ export default Ember.Component.extend({
claim() {
this.set("claiming", true);
let topic = this.get("topic");
let topic = this.topic;
ajax(`/assign/claim/${topic.id}`, {
method: "PUT"
})

View File

@ -8,11 +8,11 @@ export default Ember.Component.extend({
didInsertElement() {
this._super();
this.messageBus.subscribe("/staff/topic-assignment", data => {
let flaggedTopics = this.get("flaggedTopics");
let flaggedTopics = this.flaggedTopics;
if (flaggedTopics) {
flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data));
} else {
assignIfEqual(this.get("topic"), data);
assignIfEqual(this.topic, data);
}
});
},

View File

@ -4,8 +4,8 @@ export default Ember.Component.extend({
selectedFrequency: null,
@computed("user.reminders_frequency")
availableFrequencies() {
return this.get("user.reminders_frequency").map(freq => {
availableFrequencies(userRemindersFrequency) {
return userRemindersFrequency.map(freq => {
return {
name: I18n.t(freq.name),
value: freq.value,
@ -15,15 +15,17 @@ export default Ember.Component.extend({
},
didInsertElement() {
let current_frequency = this.get(
this._super(...arguments);
let currentFrequency = this.get(
"user.custom_fields.remind_assigns_frequency"
);
if (current_frequency === undefined) {
current_frequency = this.get("siteSettings.remind_assigns_frequency");
if (currentFrequency === undefined) {
currentFrequency = this.get("siteSettings.remind_assigns_frequency");
}
this.set("selectedFrequency", current_frequency);
this.set("selectedFrequency", currentFrequency);
},
actions: {

View File

@ -21,7 +21,7 @@ export default Ember.Service.extend({
assign(topic) {
return showModal("assign-user", {
model: {
topic: topic,
topic,
username: topic.get("assigned_to_user.username"),
allowedGroups: this.allowedGroups
}