REFACTOR: user route (#7704)
This commit is contained in:
parent
1178f4865b
commit
f506843074
|
@ -1,6 +1,6 @@
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
titleToken() {
|
titleToken() {
|
||||||
const username = this.modelFor("user").get("username");
|
const username = this.modelFor("user").username;
|
||||||
if (username) {
|
if (username) {
|
||||||
return [I18n.t("user.profile"), username];
|
return [I18n.t("user.profile"), username];
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,11 @@ export default Discourse.Route.extend({
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
// If we're viewing the currently logged in user, return that object instead
|
// If we're viewing the currently logged in user, return that object instead
|
||||||
const currentUser = this.currentUser;
|
|
||||||
if (
|
if (
|
||||||
currentUser &&
|
this.currentUser &&
|
||||||
params.username.toLowerCase() === currentUser.get("username_lower")
|
params.username.toLowerCase() === this.currentUser.username_lower
|
||||||
) {
|
) {
|
||||||
return currentUser;
|
return this.currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Discourse.User.create({ username: params.username });
|
return Discourse.User.create({ username: params.username });
|
||||||
|
@ -45,43 +44,38 @@ export default Discourse.Route.extend({
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
const user = this.modelFor("user");
|
const user = this.modelFor("user");
|
||||||
const self = this;
|
|
||||||
|
|
||||||
return user
|
return user
|
||||||
.findDetails()
|
.findDetails()
|
||||||
.then(function() {
|
.then(() => user.findStaffInfo())
|
||||||
return user.findStaffInfo();
|
.catch(() => this.replaceWith("/404"));
|
||||||
})
|
|
||||||
.catch(function() {
|
|
||||||
return self.replaceWith("/404");
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
serialize(model) {
|
serialize(model) {
|
||||||
if (!model) return {};
|
if (!model) return {};
|
||||||
return { username: (Ember.get(model, "username") || "").toLowerCase() };
|
|
||||||
|
return { username: (model.username || "").toLowerCase() };
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller, user) {
|
setupController(controller, user) {
|
||||||
controller.set("model", user);
|
controller.set("model", user);
|
||||||
this.searchService.set("searchContext", user.get("searchContext"));
|
this.searchService.set("searchContext", user.searchContext);
|
||||||
},
|
},
|
||||||
|
|
||||||
activate() {
|
activate() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
const user = this.modelFor("user");
|
const user = this.modelFor("user");
|
||||||
this.messageBus.subscribe("/u/" + user.get("username_lower"), function(
|
this.messageBus.subscribe(`/u/${user.username_lower}`, data =>
|
||||||
data
|
user.loadUserAction(data)
|
||||||
) {
|
);
|
||||||
user.loadUserAction(data);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
this.messageBus.unsubscribe(
|
|
||||||
"/u/" + this.modelFor("user").get("username_lower")
|
const user = this.modelFor("user");
|
||||||
);
|
this.messageBus.unsubscribe(`/u/${user.username_lower}`);
|
||||||
|
|
||||||
// Remove the search context
|
// Remove the search context
|
||||||
this.searchService.set("searchContext", null);
|
this.searchService.set("searchContext", null);
|
||||||
|
|
Loading…
Reference in New Issue