Fixes deprecations on user routes

This commit is contained in:
Robin Ward 2015-05-04 16:41:06 -04:00
parent 72b6c86564
commit aab9706b7a
15 changed files with 102 additions and 95 deletions

View File

@ -15,21 +15,21 @@ export default Ember.Component.extend(StringBuffer, {
if (this.get('isIndexStream')) {
return !this.get('userActionType');
}
var content = this.get('content');
const content = this.get('content');
if (content) {
return parseInt(this.get('userActionType'), 10) === parseInt(Em.get(content, 'action_type'), 10);
}
}.property('userActionType', 'indexStream'),
}.property('userActionType', 'isIndexStream'),
activityCount: function() {
return this.get('content.count') || this.get('count') || 0;
}.property('content.count', 'count'),
typeKey: function() {
var actionType = this.get('content.action_type');
const actionType = this.get('content.action_type');
if (actionType === Discourse.UserAction.TYPES.messages_received) { return ""; }
var result = Discourse.UserAction.TYPES_INVERTED[actionType];
const result = Discourse.UserAction.TYPES_INVERTED[actionType];
if (!result) { return ""; }
// We like our URLS to have hyphens, not underscores
@ -44,9 +44,9 @@ export default Ember.Component.extend(StringBuffer, {
return this.get('content.description') || I18n.t("user.filters.all");
}.property('content.description'),
renderString: function(buffer) {
renderString(buffer) {
buffer.push("<a href='" + this.get('url') + "'>");
var icon = this.get('icon');
const icon = this.get('icon');
if (icon) {
buffer.push("<i class='glyph fa fa-" + icon + "'></i> ");
}

View File

@ -1,15 +1,16 @@
export default Ember.ObjectController.extend({
userActionType: null,
needs: ["application"],
_showFooter: function() {
var showFooter;
if (this.get("userActionType")) {
var stat = _.find(this.get("stats"), { action_type: this.get("userActionType") });
showFooter = stat && stat.count <= this.get("stream.itemsLoaded");
var stat = _.find(this.get("model.stats"), { action_type: this.get("userActionType") });
showFooter = stat && stat.count <= this.get("model.stream.itemsLoaded");
} else {
showFooter = this.get("statsCountNonPM") <= this.get("stream.itemsLoaded");
showFooter = this.get("model.statsCountNonPM") <= this.get("model.stream.itemsLoaded");
}
this.set("controllers.application.showFooter", showFooter);
}.observes("userActionType", "stream.itemsLoaded")
}.observes("userActionType", "model.stream.itemsLoaded")
});

View File

@ -7,8 +7,8 @@ export default ObjectController.extend({
showParticipants: false,
_showFooter: function() {
this.set("controllers.application.showFooter", !this.get("canLoadMore"));
}.observes("canLoadMore"),
this.set("controllers.application.showFooter", !this.get("model.canLoadMore"));
}.observes("model.canLoadMore"),
actions: {
loadMore: function() {

View File

@ -3,7 +3,9 @@ import CanCheckEmails from 'discourse/mixins/can-check-emails';
export default ObjectController.extend(CanCheckEmails, {
indexStream: false,
needs: ['user-notifications', 'user_topics_list'],
pmView: false,
userActionType: null,
needs: ['user-notifications', 'user-topics-list'],
viewingSelf: function() {
return this.get('content.username') === Discourse.User.currentProp('username');
@ -12,16 +14,16 @@ export default ObjectController.extend(CanCheckEmails, {
collapsedInfo: Em.computed.not('indexStream'),
websiteName: function() {
var website = this.get('website');
var website = this.get('model.website');
if (Em.isEmpty(website)) { return; }
return this.get('website').split("/")[2];
}.property('website'),
return website.split("/")[2];
}.property('model.website'),
linkWebsite: Em.computed.not('isBasic'),
linkWebsite: Em.computed.not('model.isBasic'),
removeNoFollow: function() {
return this.get('trust_level') > 2 && !this.siteSettings.tl3_links_no_follow;
}.property('trust_level'),
return this.get('model.trust_level') > 2 && !this.siteSettings.tl3_links_no_follow;
}.property('model.trust_level'),
canSeePrivateMessages: Ember.computed.or('viewingSelf', 'currentUser.admin'),
canSeeNotificationHistory: Em.computed.alias('canSeePrivateMessages'),
@ -40,13 +42,13 @@ export default ObjectController.extend(CanCheckEmails, {
}.property(),
canDeleteUser: function() {
return this.get('can_be_deleted') && this.get('can_delete_all_posts');
}.property('can_be_deleted', 'can_delete_all_posts'),
return this.get('model.can_be_deleted') && this.get('model.can_delete_all_posts');
}.property('model.can_be_deleted', 'model.can_delete_all_posts'),
publicUserFields: function() {
var siteUserFields = this.site.get('user_fields');
var siteUserFields = this.site.get('model.user_fields');
if (!Ember.isEmpty(siteUserFields)) {
var userFields = this.get('user_fields');
var userFields = this.get('model.user_fields');
return siteUserFields.filterProperty('show_on_profile', true).sortBy('id').map(function(uf) {
var val = userFields ? userFields[uf.get('id').toString()] : null;
if (Ember.isEmpty(val)) {
@ -56,7 +58,7 @@ export default ObjectController.extend(CanCheckEmails, {
}
}).compact();
}
}.property('user_fields.@each.value'),
}.property('model.user_fields.@each.value'),
privateMessagesActive: Em.computed.equal('pmView', 'index'),
privateMessagesMineActive: Em.computed.equal('pmView', 'mine'),

View File

@ -1,6 +1,6 @@
export default Ember.Mixin.create({
isOwnEmail: Discourse.computed.propertyEqual("id", "currentUser.id"),
showEmailOnProfile: Discourse.computed.setting("show_email_on_profile"),
isOwnEmail: Discourse.computed.propertyEqual("model.id", "currentUser.id"),
showEmailOnProfile: Discourse.computed.setting("model.show_email_on_profile"),
canStaffCheckEmails: Em.computed.and("showEmailOnProfile", "currentUser.staff"),
canAdminCheckEmails: Em.computed.alias("currentUser.admin"),
canCheckEmails: Em.computed.or("isOwnEmail", "canStaffCheckEmails", "canAdminCheckEmails"),

View File

@ -0,0 +1,6 @@
export default {
viewingActionType(userActionType) {
this.controllerFor('user').set('userActionType', userActionType);
this.controllerFor('user-activity').set('userActionType', userActionType);
}
};

View File

@ -20,7 +20,7 @@ export default function (viewName, path) {
setupController: function() {
this._super.apply(this, arguments);
this.controllerFor('user_topics_list').setProperties({
this.controllerFor('user-topics-list').setProperties({
hideCategory: true,
showParticipants: true
});

View File

@ -1,6 +1,7 @@
import ShowFooter from "discourse/mixins/show-footer";
import ViewingActionType from "discourse/mixins/viewing-action-type";
export default Discourse.Route.extend(ShowFooter, {
export default Discourse.Route.extend(ShowFooter, ViewingActionType, {
model: function() {
return this.modelFor('user').get('stream');
},
@ -15,7 +16,7 @@ export default Discourse.Route.extend(ShowFooter, {
setupController: function(controller, model) {
controller.set('model', model);
this.controllerFor('user-activity').set('userActionType', this.get('userActionType'));
this.viewingActionType(this.get('userActionType'));
},
actions: {

View File

@ -1,14 +1,13 @@
import ShowFooter from "discourse/mixins/show-footer";
import ViewingActionType from "discourse/mixins/viewing-action-type";
export default Discourse.Route.extend(ShowFooter, {
export default Discourse.Route.extend(ShowFooter, ViewingActionType, {
model: function() {
return Discourse.UserBadge.findByUsername(this.modelFor('user').get('username_lower'), {grouped: true});
},
setupController: function(controller, model) {
if (this.controllerFor('user_activity').get('content')) {
this.controllerFor('user_activity').set('userActionType', -1);
}
this.viewingActionType(-1);
controller.set('model', model);
},

View File

@ -1,12 +1,16 @@
export default Discourse.Route.extend({
renderTemplate: function() {
this.render('user_topics_list');
import ViewingActionType from "discourse/mixins/viewing-action-type";
export default Discourse.Route.extend(ViewingActionType, {
renderTemplate() {
this.render('user-topics-list');
},
setupController: function(controller, model) {
this.controllerFor('user-activity').set('userActionType', this.get('userActionType'));
setupController(controller, model) {
const userActionType = this.get('userActionType');
this.controllerFor('user').set('userActionType', userActionType);
this.controllerFor('user-activity').set('userActionType', userActionType);
this.controllerFor('user-topics-list').setProperties({
model: model,
model,
hideCategory: false,
showParticipants: false
});

View File

@ -50,9 +50,9 @@
{{#if canCheckEmails}}
<div class="control-group pref-email">
<label class="control-label">{{i18n 'user.email.title'}}</label>
{{#if email}}
{{#if model.email}}
<div class="controls">
<span class='static'>{{email}}</span>
<span class='static'>{{model.email}}</span>
{{#if can_edit_email}}
{{#link-to "preferences.email" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
{{/if}}

View File

@ -5,30 +5,30 @@
<div class="container">
<section class='user-main'>
<section {{bind-attr class="collapsedInfo :about profileBackground:has-background:no-background"}} {{bind-attr style="profileBackground"}}>
<section {{bind-attr class="collapsedInfo :about model.profileBackground:has-background:no-background"}} style={{model.profileBackground}}>
<div class='staff-counters'>
{{#if number_of_flags_given}}
<div><span class="helpful-flags">{{number_of_flags_given}}</span>&nbsp;{{i18n 'user.staff_counters.flags_given'}}</div>
{{#if model.number_of_flags_given}}
<div><span class="helpful-flags">{{model.number_of_flags_given}}</span>&nbsp;{{i18n 'user.staff_counters.flags_given'}}</div>
{{/if}}
{{#if number_of_flagged_posts}}
{{#if model.number_of_flagged_posts}}
<div>
{{#link-to 'user.flaggedPosts' this}}
<span class="flagged-posts">{{number_of_flagged_posts}}</span>&nbsp;{{i18n 'user.staff_counters.flagged_posts'}}
{{#link-to 'user.flaggedPosts' model}}
<span class="flagged-posts">{{model.number_of_flagged_posts}}</span>&nbsp;{{i18n 'user.staff_counters.flagged_posts'}}
{{/link-to}}
</div>
{{/if}}
{{#if number_of_deleted_posts}}
{{#if model.number_of_deleted_posts}}
<div>
{{#link-to 'user.deletedPosts' this}}
<span class="deleted-posts">{{number_of_deleted_posts}}</span>&nbsp;{{i18n 'user.staff_counters.deleted_posts'}}
{{#link-to 'user.deletedPosts' model}}
<span class="deleted-posts">{{model.number_of_deleted_posts}}</span>&nbsp;{{i18n 'user.staff_counters.deleted_posts'}}
{{/link-to}}
</div>
{{/if}}
{{#if number_of_suspensions}}
<div><span class="suspensions">{{number_of_suspensions}}</span>&nbsp;{{i18n 'user.staff_counters.suspensions'}}</div>
{{#if model.number_of_suspensions}}
<div><span class="suspensions">{{model.number_of_suspensions}}</span>&nbsp;{{i18n 'user.staff_counters.suspensions'}}</div>
{{/if}}
{{#if number_of_warnings}}
<div><span class="warnings-received">{{number_of_warnings}}</span>&nbsp;{{i18n 'user.staff_counters.warnings_received'}}</div>
{{#if model.number_of_warnings}}
<div><span class="warnings-received">{{model.number_of_warnings}}</span>&nbsp;{{i18n 'user.staff_counters.warnings_received'}}</div>
{{/if}}
</div>
<div class='profile-image'></div>
@ -37,7 +37,7 @@
{{bound-avatar model "huge"}}
<section class='controls'>
<ul>
{{#if can_send_private_message_to_user}}
{{#if model.can_send_private_message_to_user}}
<li>
<a class='btn btn-primary right' {{action "composePrivateMessage" model}}>
{{fa-icon "envelope"}}
@ -49,9 +49,9 @@
<li><a {{action "logout"}} class='btn btn-danger right'>{{fa-icon "sign-out"}}{{i18n 'user.log_out'}}</a></li>
{{/if}}
{{#if currentUser.staff}}
<li><a {{bind-attr href="adminPath"}} class='btn right'>{{fa-icon "wrench"}}{{i18n 'admin.user.show_admin_profile'}}</a></li>
<li><a href={{model.adminPath}} class='btn right'>{{fa-icon "wrench"}}{{i18n 'admin.user.show_admin_profile'}}</a></li>
{{/if}}
{{#if can_edit}}
{{#if model.can_edit}}
<li>{{#link-to 'preferences' class="btn right"}}{{fa-icon "cog"}}{{i18n 'user.preferences'}}{{/link-to}}</li>
{{/if}}
{{#if canInviteToForum}}
@ -61,36 +61,32 @@
</section>
<div class="primary-textual">
<h1>{{username}} {{user-status model currentUser=currentUser}}</h1>
<h2>{{name}}</h2>
{{#if title}}
<h3>{{title}}</h3>
<h1>{{model.username}} {{user-status model currentUser=currentUser}}</h1>
<h2>{{model.name}}</h2>
{{#if model.title}}
<h3>{{model.title}}</h3>
{{/if}}
<h3>
{{#if location}}{{fa-icon "map-marker"}}{{location}}{{/if}}
{{#if model.location}}{{fa-icon "map-marker"}}{{model.location}}{{/if}}
{{#if websiteName}}
{{fa-icon "globe"}}
{{#if linkWebsite}}
{{#if removeNoFollow}}
<a {{bind-attr href="website"}} target="_blank">{{websiteName}}</a>
{{else}}
<a {{bind-attr href="website"}} rel="nofollow" target="_blank">{{websiteName}}</a>
{{/if}}
<a href={{model.website}} rel={{unless removeNoFollow 'nofollow'}} target="_blank">{{websiteName}}</a>
{{else}}
<span {{bind-attr title="website"}}>{{websiteName}}</span>
<span title={{model.website}}>{{websiteName}}</span>
{{/if}}
{{/if}}
</h3>
<div class='bio'>
{{#if isSuspended}}
{{#if model.isSuspended}}
<div class='suspended'>
{{fa-icon "ban"}}
<b>{{i18n 'user.suspended_notice' date=suspendedTillDate}}</b><br/>
<b>{{i18n 'user.suspended_reason'}}</b> {{suspend_reason}}
</div>
{{/if}}
{{{bio_cooked}}}
{{{model.bio_cooked}}}
</div>
{{#if publicUserFields}}
@ -115,33 +111,33 @@
<div class='secondary'>
<dl>
{{#if created_at}}
<dt>{{i18n 'user.created'}}</dt><dd>{{bound-date created_at}}</dd>
{{#if model.created_at}}
<dt>{{i18n 'user.created'}}</dt><dd>{{bound-date model.created_at}}</dd>
{{/if}}
{{#if last_posted_at}}
<dt>{{i18n 'user.last_posted'}}</dt><dd>{{bound-date last_posted_at}}</dd>
{{#if model.last_posted_at}}
<dt>{{i18n 'user.last_posted'}}</dt><dd>{{bound-date model.last_posted_at}}</dd>
{{/if}}
{{#if last_seen_at}}
<dt>{{i18n 'user.last_seen'}}</dt><dd>{{bound-date last_seen_at}}</dd>
{{#if model.last_seen_at}}
<dt>{{i18n 'user.last_seen'}}</dt><dd>{{bound-date model.last_seen_at}}</dd>
{{/if}}
{{#if invited_by}}
<dt>{{i18n 'user.invited_by'}}</dt><dd>{{#link-to 'user' invited_by}}{{invited_by.username}}{{/link-to}}</dd>
{{#if model.invited_by}}
<dt>{{i18n 'user.invited_by'}}</dt><dd>{{#link-to 'user' model.invited_by}}{{model.invited_by.username}}{{/link-to}}</dd>
{{/if}}
<dt>{{i18n 'user.trust_level'}}</dt><dd>{{trustLevel.name}}</dd>
<dt>{{i18n 'user.trust_level'}}</dt><dd>{{model.trustLevel.name}}</dd>
{{#if canCheckEmails}}
<dt>{{i18n 'user.email.title'}}</dt>
<dd {{bind-attr title="email"}}>
{{#if email}}
{{email}}
<dd title={{model.email}}>
{{#if model.email}}
{{model.email}}
{{else}}
{{d-button action="checkEmail" actionParam=model icon="envelope-o" label="admin.users.check_email.text" class="btn-primary"}}
{{/if}}
</dd>
{{/if}}
{{#if custom_groups}}
<dt>{{i18n 'groups.title' count=custom_groups.length}}</dt>
{{#if model.custom_groups}}
<dt>{{i18n 'groups.title' count=model.custom_groups.length}}</dt>
<dd class='groups'>
{{#each group in custom_groups}}
{{#each group in model.custom_groups}}
<span>{{#link-to 'group' group class="group-link"}}{{group.name}}{{/link-to}}</span>
{{/each}}
</dd>
@ -156,8 +152,8 @@
<section class='user-navigation'>
<ul class='action-list nav-stacked'>
{{activity-filter count=statsCountNonPM user=model userActionType=userActionType indexStream=indexStream}}
{{#each stat in statsExcludingPms}}
{{activity-filter count=model.statsCountNonPM user=model userActionType=userActionType indexStream=indexStream}}
{{#each stat in model.statsExcludingPms}}
{{activity-filter content=stat user=model userActionType=userActionType indexStream=indexStream}}
{{/each}}
{{#if showBadges}}
@ -165,7 +161,7 @@
{{#link-to 'user.badges'}}
<i class='glyph fa fa-certificate'></i>
{{i18n 'badges.title'}}
<span class='count'>({{badge_count}})</span>
<span class='count'>({{model.badge_count}})</span>
{{/link-to}}
{{/link-to}}
{{/if}}
@ -174,7 +170,7 @@
{{#link-to 'user.notifications'}}
{{fa-icon "comment" class="glyph"}}
{{i18n 'user.notifications'}}
<span class='count'>({{notification_count}})</span>
<span class='count'>({{model.notification_count}})</span>
{{/link-to}}
{{/link-to}}
{{/if}}
@ -186,19 +182,19 @@
<li {{bind-attr class=":noGlyph privateMessagesActive:active"}}>
{{#link-to 'userPrivateMessages.index' model}}
{{i18n 'user.messages.all'}}
{{#if hasPMs}}<span class='count'>({{private_messages_stats.all}})</span>{{/if}}
{{#if model.hasPMs}}<span class='count'>({{model.private_messages_stats.all}})</span>{{/if}}
{{/link-to}}
</li>
<li {{bind-attr class=":noGlyph privateMessagesMineActive:active"}}>
{{#link-to 'userPrivateMessages.mine' model}}
{{i18n 'user.messages.mine'}}
{{#if hasStartedPMs}}<span class='count'>({{private_messages_stats.mine}})</span>{{/if}}
{{#if model.hasStartedPMs}}<span class='count'>({{model.private_messages_stats.mine}})</span>{{/if}}
{{/link-to}}
</li>
<li {{bind-attr class=":noGlyph privateMessagesUnreadActive:active"}}>
{{#link-to 'userPrivateMessages.unread' model}}
{{i18n 'user.messages.unread'}}
{{#if hasUnreadPMs}}<span class='badge-notification unread-private-messages'>{{private_messages_stats.unread}}</span>{{/if}}
{{#if model.hasUnreadPMs}}<span class='badge-notification unread-private-messages'>{{model.private_messages_stats.unread}}</span>{{/if}}
{{/link-to}}
</li>
</ul>

View File

@ -3,5 +3,4 @@ import LoadMore from "discourse/mixins/load-more";
export default Discourse.View.extend(LoadMore, {
classNames: ['paginated-topics-list'],
eyelineSelector: '.paginated-topics-list .topic-list tr',
templateName: 'list/user_topics_list'
});

View File

@ -20,8 +20,7 @@ test("unreadTotal default", function() {
test("unreadTotal with values", function() {
var controller = this.subject({
currentUser: Discourse.User.create(),
unreadTopics: 1,
newTopics: 3
model: { unreadTopics: 1, newTopics: 3 }
});
equal(controller.get('unreadTotal'), 4);
});