REFACTOR: old ember patterns, deprecations, dead code (#42)
This commit is contained in:
parent
8f92c5f9bd
commit
75c6cecfdb
|
@ -18,10 +18,10 @@ export default {
|
||||||
actions: {
|
actions: {
|
||||||
unassign() {
|
unassign() {
|
||||||
this.set("topic.assigned_to_user", null);
|
this.set("topic.assigned_to_user", null);
|
||||||
this.get("taskActions").unassign(this.get("topic.id"));
|
this.taskActions.unassign(this.get("topic.id"));
|
||||||
},
|
},
|
||||||
assign() {
|
assign() {
|
||||||
this.get("taskActions").assign(this.topic);
|
this.taskActions.assign(this.topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
//import { default as computed } from 'ember-addons/ember-computed-decorators';
|
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
assignSuggestions: null,
|
||||||
taskActions: Ember.inject.service(),
|
taskActions: Ember.inject.service(),
|
||||||
assignSuggestions: function() {
|
|
||||||
ajax("/assign/suggestions").then(users => {
|
|
||||||
this.set("assignSuggestions", users);
|
|
||||||
});
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
// @computed("username")
|
init() {
|
||||||
// disabled(username) {
|
this._super(...arguments);
|
||||||
// return Ember.isEmpty(username);
|
|
||||||
// },
|
ajax("/assign/suggestions").then(users =>
|
||||||
|
this.set("assignSuggestions", users)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
if (this.get("model.onClose") && this.get("model.username")) {
|
if (this.get("model.onClose") && this.get("model.username")) {
|
||||||
|
@ -23,8 +21,10 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
assignUser(user) {
|
assignUser(user) {
|
||||||
this.set("model.username", user.username);
|
this.setProperties({
|
||||||
this.set("model.allowedGroups", this.get("taskActions").allowedGroups);
|
"model.username": user.username,
|
||||||
|
"model.allowedGroups": this.taskActions.allowedGroups
|
||||||
|
});
|
||||||
this.send("assign");
|
this.send("assign");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ export default UserTopicsList.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
unassign(topic) {
|
unassign(topic) {
|
||||||
this.get("taskActions")
|
this.taskActions
|
||||||
.unassign(topic.get("id"))
|
.unassign(topic.get("id"))
|
||||||
.then(() => this.send("changeAssigned"));
|
.then(() => this.send("changeAssigned"));
|
||||||
},
|
},
|
||||||
reassign(topic) {
|
reassign(topic) {
|
||||||
const controller = this.get("taskActions").assign(topic);
|
const controller = this.taskActions.assign(topic);
|
||||||
controller.set("model.onSuccess", () => this.send("changeAssigned"));
|
controller.set("model.onSuccess", () => this.send("changeAssigned"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,13 +35,13 @@ function modifySelectKit(api) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const topic = context.get("topic");
|
const topic = context.topic;
|
||||||
const assignedUser = topic.get("assigned_to_user.username");
|
const assignedUser = topic.get("assigned_to_user.username");
|
||||||
|
|
||||||
if (assignedUser) {
|
if (assignedUser) {
|
||||||
ajax("/assign/unassign", {
|
ajax("/assign/unassign", {
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: { topic_id: topic.get("id") }
|
data: { topic_id: topic.id }
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.success && result.success === "OK") {
|
if (result.success && result.success === "OK") {
|
||||||
|
@ -87,13 +87,14 @@ function initialize(api) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.get("actableFilter");
|
return this.actableFilter;
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super();
|
this._super(...arguments);
|
||||||
|
|
||||||
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
||||||
let flaggedPost = this.get("flaggedPost");
|
let flaggedPost = this.flaggedPost;
|
||||||
if (data.topic_id === flaggedPost.get("topic.id")) {
|
if (data.topic_id === flaggedPost.get("topic.id")) {
|
||||||
flaggedPost.set(
|
flaggedPost.set(
|
||||||
"topic.assigned_to_user_id",
|
"topic.assigned_to_user_id",
|
||||||
|
@ -105,7 +106,8 @@ function initialize(api) {
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this._super();
|
this._super(...arguments);
|
||||||
|
|
||||||
this.messageBus.unsubscribe("/staff/topic-assignment");
|
this.messageBus.unsubscribe("/staff/topic-assignment");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -140,14 +142,14 @@ function initialize(api) {
|
||||||
api.addTagsHtmlCallback(topic => {
|
api.addTagsHtmlCallback(topic => {
|
||||||
const assignedTo = topic.get("assigned_to_user.username");
|
const assignedTo = topic.get("assigned_to_user.username");
|
||||||
if (assignedTo) {
|
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(
|
let assignLabels = `<a data-auto-route='true' class='assigned-to discourse-tag simple' href='${assignedPath}'>${iconHTML(
|
||||||
"user-plus"
|
"user-plus"
|
||||||
)}${assignedTo}</a>`;
|
)}${assignedTo}</a>`;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
ListItemDefaults === undefined &&
|
ListItemDefaults === undefined &&
|
||||||
topic.get("archetype") === "private_message"
|
topic.archetype === "private_message"
|
||||||
) {
|
) {
|
||||||
assignLabels += `<div>${iconHTML("envelope")} Message</div>`;
|
assignLabels += `<div>${iconHTML("envelope")} Message</div>`;
|
||||||
}
|
}
|
||||||
|
@ -157,12 +159,12 @@ function initialize(api) {
|
||||||
});
|
});
|
||||||
|
|
||||||
api.addUserMenuGlyph(widget => {
|
api.addUserMenuGlyph(widget => {
|
||||||
if (widget.currentUser && widget.currentUser.get("can_assign")) {
|
if (widget.currentUser && widget.currentUser.can_assign) {
|
||||||
return {
|
return {
|
||||||
label: "discourse_assign.assigned",
|
label: "discourse_assign.assigned",
|
||||||
className: "assigned",
|
className: "assigned",
|
||||||
icon: "user-plus",
|
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", {
|
api.modifyClass("controller:topic", {
|
||||||
subscribe() {
|
subscribe() {
|
||||||
this._super();
|
this._super(...arguments);
|
||||||
|
|
||||||
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
||||||
const topic = this.get("model");
|
const topic = this.model;
|
||||||
const topicId = topic.get("id");
|
const topicId = topic.id;
|
||||||
|
|
||||||
if (data.topic_id === topicId) {
|
if (data.topic_id === topicId) {
|
||||||
topic.set(
|
topic.set(
|
||||||
|
@ -233,7 +236,7 @@ function initialize(api) {
|
||||||
api.modifyClass("controller:preferences/notifications", {
|
api.modifyClass("controller:preferences/notifications", {
|
||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
this.get("saveAttrNames").push("custom_fields");
|
this.saveAttrNames.push("custom_fields");
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,10 @@ export default DropdownSelectBoxComponent.extend({
|
||||||
onSelect(id) {
|
onSelect(id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case "unassign":
|
case "unassign":
|
||||||
this.unassign(this.get("topic"), this.get("user"));
|
this.unassign(this.topic, this.user);
|
||||||
break;
|
break;
|
||||||
case "reassign":
|
case "reassign":
|
||||||
this.reassign(this.get("topic"), this.get("user"));
|
this.reassign(this.topic, this.user);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
|
||||||
import { ListItemDefaults } from "discourse/components/topic-list-item";
|
import { ListItemDefaults } from "discourse/components/topic-list-item";
|
||||||
|
|
||||||
const privateMessageHelper = {
|
export default Ember.Component.extend(ListItemDefaults, {
|
||||||
@computed("topic.archetype")
|
isPrivateMessage: Ember.computed.equal("topic.archetype", "private_message")
|
||||||
isPrivateMessage(archetype) {
|
});
|
||||||
return archetype === "private_message";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Ember.Component.extend(ListItemDefaults, privateMessageHelper);
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ export default Ember.Component.extend({
|
||||||
claim() {
|
claim() {
|
||||||
this.set("claiming", true);
|
this.set("claiming", true);
|
||||||
|
|
||||||
let topic = this.get("topic");
|
let topic = this.topic;
|
||||||
ajax(`/assign/claim/${topic.id}`, {
|
ajax(`/assign/claim/${topic.id}`, {
|
||||||
method: "PUT"
|
method: "PUT"
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,11 +8,11 @@ export default Ember.Component.extend({
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super();
|
this._super();
|
||||||
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
this.messageBus.subscribe("/staff/topic-assignment", data => {
|
||||||
let flaggedTopics = this.get("flaggedTopics");
|
let flaggedTopics = this.flaggedTopics;
|
||||||
if (flaggedTopics) {
|
if (flaggedTopics) {
|
||||||
flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data));
|
flaggedTopics.forEach(ft => assignIfEqual(ft.topic, data));
|
||||||
} else {
|
} else {
|
||||||
assignIfEqual(this.get("topic"), data);
|
assignIfEqual(this.topic, data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,8 +4,8 @@ export default Ember.Component.extend({
|
||||||
selectedFrequency: null,
|
selectedFrequency: null,
|
||||||
|
|
||||||
@computed("user.reminders_frequency")
|
@computed("user.reminders_frequency")
|
||||||
availableFrequencies() {
|
availableFrequencies(userRemindersFrequency) {
|
||||||
return this.get("user.reminders_frequency").map(freq => {
|
return userRemindersFrequency.map(freq => {
|
||||||
return {
|
return {
|
||||||
name: I18n.t(freq.name),
|
name: I18n.t(freq.name),
|
||||||
value: freq.value,
|
value: freq.value,
|
||||||
|
@ -15,15 +15,17 @@ export default Ember.Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
let current_frequency = this.get(
|
this._super(...arguments);
|
||||||
|
|
||||||
|
let currentFrequency = this.get(
|
||||||
"user.custom_fields.remind_assigns_frequency"
|
"user.custom_fields.remind_assigns_frequency"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (current_frequency === undefined) {
|
if (currentFrequency === undefined) {
|
||||||
current_frequency = this.get("siteSettings.remind_assigns_frequency");
|
currentFrequency = this.get("siteSettings.remind_assigns_frequency");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("selectedFrequency", current_frequency);
|
this.set("selectedFrequency", currentFrequency);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default Ember.Service.extend({
|
||||||
assign(topic) {
|
assign(topic) {
|
||||||
return showModal("assign-user", {
|
return showModal("assign-user", {
|
||||||
model: {
|
model: {
|
||||||
topic: topic,
|
topic,
|
||||||
username: topic.get("assigned_to_user.username"),
|
username: topic.get("assigned_to_user.username"),
|
||||||
allowedGroups: this.allowedGroups
|
allowedGroups: this.allowedGroups
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue