Replace `findProperty` and `filterProperty` with `findBy` and `filterBy`

This commit is contained in:
Robin Ward 2016-10-26 15:44:36 -04:00
parent 68b559d501
commit 7953a53cc5
35 changed files with 53 additions and 54 deletions

View File

@ -9,7 +9,7 @@ export default Ember.Controller.extend({
@computed('embedding.embeddable_hosts.@each.isCreated')
showSecondary() {
const hosts = this.get('embedding.embeddable_hosts');
return hosts.length && hosts.findProperty('isCreated');
return hosts.length && hosts.findBy('isCreated');
},
@computed('embedding.base_url')

View File

@ -5,7 +5,7 @@ export default Ember.Controller.extend({
filteredContent: function() {
if (!this.get('categoryNameKey')) { return []; }
const category = (this.get('adminSiteSettings.model') || []).findProperty('nameKey', this.get('categoryNameKey'));
const category = (this.get('adminSiteSettings.model') || []).findBy('nameKey', this.get('categoryNameKey'));
if (category) {
return category.siteSettings;
} else {

View File

@ -19,7 +19,7 @@ export default Ember.Controller.extend({
selectedCount: function() {
var model = this.get('model');
if (!model || !model.length) return 0;
return model.filterProperty('selected').length;
return model.filterBy('selected').length;
}.property('model.@each.selected'),
selectAllChanged: function() {
@ -52,14 +52,14 @@ export default Ember.Controller.extend({
actions: {
approveUsers: function() {
AdminUser.bulkApprove(this.get('model').filterProperty('selected'));
AdminUser.bulkApprove(this.get('model').filterBy('selected'));
this._refreshUsers();
},
rejectUsers: function() {
var maxPostAge = this.siteSettings.delete_user_max_post_age;
var controller = this;
AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){
AdminUser.bulkReject(this.get('model').filterBy('selected')).then(function(result){
var message = I18n.t("admin.users.reject_successful", {count: result.success});
if (result.failed > 0) {
message += ' ' + I18n.t("admin.users.reject_failures", {count: result.failed});

View File

@ -13,7 +13,7 @@ export default Ember.Route.extend({
name: I18n.t('admin.badges.new_badge')
});
}
return this.modelFor('adminBadges').findProperty('id', parseInt(params.badge_id));
return this.modelFor('adminBadges').findBy('id', parseInt(params.badge_id));
},
actions: {

View File

@ -1,7 +1,7 @@
export default Ember.Route.extend({
model(params) {
const all = this.modelFor('adminCustomizeCssHtml');
const model = all.findProperty('id', parseInt(params.site_customization_id));
const model = all.findBy('id', parseInt(params.site_customization_id));
return model ? { model, section: params.section } : this.replaceWith('adminCustomizeCssHtml.index');
},

View File

@ -3,7 +3,7 @@ import { scrollTop } from 'discourse/mixins/scroll-top';
export default Ember.Route.extend({
model(params) {
const all = this.modelFor('adminCustomizeEmailTemplates');
return all.findProperty('id', params.id);
return all.findBy('id', params.id);
},
setupController(controller, emailTemplate) {

View File

@ -7,8 +7,7 @@ export default Discourse.Route.extend({
return Group.create({ automatic: false, visible: true });
}
const group = this.modelFor('adminGroupsType')
.findProperty('name', params.name);
const group = this.modelFor('adminGroupsType').findBy('name', params.name);
if (!group) { return this.transitionTo('adminGroups.index'); }

View File

@ -47,7 +47,7 @@ export default Ember.Component.extend({
target = target.find('a');
}
const topic = this.get('topics').findProperty('id', parseInt(topicId));
const topic = this.get('topics').findBy('id', parseInt(topicId));
this.sendAction('postsAction', {topic, position: target.offset()});
}
return false;

View File

@ -50,7 +50,7 @@ export default Ember.Component.extend({
const posts = topic.get('postStream.posts');
if (posts && topicId === topic.get('id')) {
const quotedPost = posts.findProperty("post_number", postNumber);
const quotedPost = posts.findBy("post_number", postNumber);
if (quotedPost) {
return tinyAvatar(quotedPost.get('avatar_template'));
}

View File

@ -123,7 +123,7 @@ class Toolbar {
}
addButton(button) {
const g = this.groups.findProperty('group', button.group);
const g = this.groups.findBy('group', button.group);
if (!g) {
throw `Couldn't find toolbar group ${button.group}`;
}

View File

@ -27,7 +27,7 @@ export default Combobox.extend({
}
this.comboTemplate = (item) => {
const contentItem = content.findProperty('id', item.id);
const contentItem = content.findBy('id', item.id);
if (!contentItem) { return item.text; }
return `${iconHTML(contentItem.icon)}  ${item.text}`;
};

View File

@ -618,10 +618,10 @@ export default Ember.Controller.extend({
let category;
if (!splitCategory[1]) {
category = this.site.get('categories').findProperty('nameLower', splitCategory[0].toLowerCase());
category = this.site.get('categories').findBy('nameLower', splitCategory[0].toLowerCase());
} else {
const categories = Discourse.Category.list();
const mainCategory = categories.findProperty('nameLower', splitCategory[0].toLowerCase());
const mainCategory = categories.findBy('nameLower', splitCategory[0].toLowerCase());
category = categories.find(function(item) {
return item && item.get('nameLower') === splitCategory[1].toLowerCase() && item.get('parent_category_id') === mainCategory.id;
});

View File

@ -56,7 +56,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
// Validate required fields
let userFields = this.get('userFields');
if (userFields) { userFields = userFields.filterProperty('field.required'); }
if (userFields) { userFields = userFields.filterBy('field.required'); }
if (!Ember.isEmpty(userFields)) {
const anyEmpty = userFields.any(function(uf) {
const val = uf.get('value');

View File

@ -20,7 +20,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
let flagsAvailable = this.get('model.flagsAvailable');
// "message user" option should be at the top
const notifyUserIndex = flagsAvailable.indexOf(flagsAvailable.filterProperty('name_key', 'notify_user')[0]);
const notifyUserIndex = flagsAvailable.indexOf(flagsAvailable.filterBy('name_key', 'notify_user')[0]);
if (notifyUserIndex !== -1) {
const notifyUser = flagsAvailable[notifyUserIndex];
flagsAvailable.splice(notifyUserIndex, 1);
@ -93,7 +93,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
let postAction; // an instance of ActionSummary
if (!this.get('flagTopic')) {
postAction = this.get('model.actions_summary').findProperty('id', this.get('selected.id'));
postAction = this.get('model.actions_summary').findBy('id', this.get('selected.id'));
} else {
postAction = this.get('topicActionByName.' + this.get('selected.name_key'));
}

View File

@ -186,7 +186,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
authMessage: (function() {
if (Ember.isEmpty(this.get('authenticate'))) return "";
const method = findAll(this.siteSettings, this.capabilities, this.isMobileDevice).findProperty("name", this.get("authenticate"));
const method = findAll(this.siteSettings, this.capabilities, this.isMobileDevice).findBy("name", this.get("authenticate"));
if(method){
return method.get('message');
}

View File

@ -25,7 +25,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
// Staff can edit fields that are not `editable`
if (!this.get('currentUser.staff')) {
siteUserFields = siteUserFields.filterProperty('editable', true);
siteUserFields = siteUserFields.filterBy('editable', true);
}
return siteUserFields.sortBy('position').map(function(field) {
const value = userFields ? userFields[field.get('id').toString()] : null;

View File

@ -765,7 +765,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
const selectedReplies = this.get('selectedReplies');
selectedReplies.removeObject(post);
const selectedReply = selectedReplies.findProperty('post_number', post.get('reply_to_post_number'));
const selectedReply = selectedReplies.findBy('post_number', post.get('reply_to_post_number'));
if (selectedReply) { selectedReplies.removeObject(selectedReply); }
this.set('allPostsSelected', false);
@ -774,7 +774,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
postSelected(post) {
if (this.get('allPostsSelected')) { return true; }
if (this.get('selectedPosts').contains(post)) { return true; }
if (this.get('selectedReplies').findProperty('post_number', post.get('reply_to_post_number'))) { return true; }
if (this.get('selectedReplies').findBy('post_number', post.get('reply_to_post_number'))) { return true; }
return false;
},

View File

@ -41,7 +41,7 @@ export default Ember.Controller.extend({
const siteUserFields = this.site.get('user_fields');
if (!Ember.isEmpty(siteUserFields)) {
const userFields = this.get('user.user_fields');
return siteUserFields.filterProperty('show_on_user_card', true).sortBy('position').map(field => {
return siteUserFields.filterBy('show_on_user_card', true).sortBy('position').map(field => {
Ember.set(field, 'dasherized_name', field.get('name').dasherize());
const value = userFields ? userFields[field.get('id')] : null;
return Ember.isEmpty(value) ? null : Ember.Object.create({ value, field });

View File

@ -76,7 +76,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
const siteUserFields = this.site.get('user_fields');
if (!Ember.isEmpty(siteUserFields)) {
const userFields = this.get('model.user_fields');
return siteUserFields.filterProperty('show_on_profile', true).sortBy('position').map(field => {
return siteUserFields.filterBy('show_on_profile', true).sortBy('position').map(field => {
field.dasherized_name = field.get('name').dasherize();
const value = userFields ? userFields[field.get('id').toString()] : null;
return Ember.isEmpty(value) ? null : Ember.Object.create({ value, field });

View File

@ -68,7 +68,7 @@ function initializeRecentlyUsedIcons() {
recent.forEach(emoji => recentlyUsedIcons.push(emoji.title));
const recentGroup = groups.findProperty('name', 'recent');
const recentGroup = groups.findBy('name', 'recent');
if (recentGroup) {
recentGroup.icons = recentlyUsedIcons;
} else {

View File

@ -37,7 +37,7 @@ export function translateResults(results, opts) {
});
results.categories = results.categories.map(function(category){
return Category.list().findProperty('id', category.id);
return Category.list().findBy('id', category.id);
}).compact();
const r = results.grouped_search_result;

View File

@ -118,7 +118,7 @@ const Composer = RestModel.extend({
}.property().volatile(),
archetype: function() {
return this.get('archetypes').findProperty('id', this.get('archetypeId'));
return this.get('archetypes').findBy('id', this.get('archetypeId'));
}.property('archetypeId'),
archetypeChanged: function() {
@ -378,14 +378,14 @@ const Composer = RestModel.extend({
// If the user didn't change the template, clear it
if (oldCategoryId) {
const oldCat = this.site.categories.findProperty('id', oldCategoryId);
const oldCat = this.site.categories.findBy('id', oldCategoryId);
if (oldCat && (oldCat.get('topic_template') === reply)) {
reply = "";
}
}
if (!Ember.isEmpty(reply)) { return; }
const category = this.site.categories.findProperty('id', categoryId);
const category = this.site.categories.findBy('id', categoryId);
if (category) {
this.set('reply', category.get('topic_template') || "");
}

View File

@ -29,7 +29,7 @@ const NavItem = Discourse.Model.extend({
categorySlug: function() {
var split = this.get('name').split('/');
if (split[0] === 'category' && split[1]) {
var cat = Discourse.Site.current().categories.findProperty('nameLower', split[1].toLowerCase());
var cat = Discourse.Site.current().categories.findBy('nameLower', split[1].toLowerCase());
return cat ? Discourse.Category.slugFor(cat) : null;
}
return null;

View File

@ -59,7 +59,7 @@ export default RestModel.extend({
@computed('hasLoadedData', 'firstPostId', 'posts.[]')
firstPostPresent(hasLoadedData, firstPostId) {
if (!hasLoadedData) { return false; }
return !!this.get('posts').findProperty('id', firstPostId);
return !!this.get('posts').findBy('id', firstPostId);
},
firstPostNotLoaded: Ember.computed.not('firstPostPresent'),
@ -71,7 +71,7 @@ export default RestModel.extend({
if (!hasLoadedData) { return false; }
if (lastPostId === -1) { return true; }
return !!this.get('posts').findProperty('id', lastPostId);
return !!this.get('posts').findBy('id', lastPostId);
},
lastPostNotLoaded: Ember.computed.not('loadedAllPosts'),
@ -208,7 +208,7 @@ export default RestModel.extend({
if (opts.forceLoad) {
this.set('loaded', false);
} else {
const postWeWant = this.get('posts').findProperty('post_number', opts.nearPost);
const postWeWant = this.get('posts').findBy('post_number', opts.nearPost);
if (postWeWant) { return Ember.RSVP.resolve(); }
}

View File

@ -76,7 +76,7 @@ const Post = RestModel.extend({
internalLinks: function() {
if (Ember.isEmpty(this.get('link_counts'))) return null;
return this.get('link_counts').filterProperty('internal').filterProperty('title');
return this.get('link_counts').filterBy('internal').filterBy('title');
}.property('link_counts.@each.internal'),
flagsAvailable: function() {

View File

@ -20,7 +20,7 @@ const Site = RestModel.extend({
flagTypes() {
const postActionTypes = this.get('post_action_types');
if (!postActionTypes) return [];
return postActionTypes.filterProperty('is_flag', true);
return postActionTypes.filterBy('is_flag', true);
},
topicCountDesc: ['topic_count:desc'],
@ -64,7 +64,7 @@ const Site = RestModel.extend({
removeCategory(id) {
const categories = this.get('categories');
const existingCategory = categories.findProperty('id', id);
const existingCategory = categories.findBy('id', id);
if (existingCategory) {
categories.removeObject(existingCategory);
delete this.get('categoriesById').categoryId;
@ -74,7 +74,7 @@ const Site = RestModel.extend({
updateCategory(newCategory) {
const categories = this.get('categories');
const categoryId = Em.get(newCategory, 'id');
const existingCategory = categories.findProperty('id', categoryId);
const existingCategory = categories.findBy('id', categoryId);
// Don't update null permissions
if (newCategory.permission === null) { delete newCategory.permission; }

View File

@ -72,7 +72,7 @@ const TopicDetails = RestModel.extend({
type: 'PUT',
data: { name: name }
}).then(() => {
groups.removeObject(groups.findProperty('name', name));
groups.removeObject(groups.findBy('name', name));
});
},
@ -84,7 +84,7 @@ const TopicDetails = RestModel.extend({
type: 'PUT',
data: { username: username }
}).then(() => {
users.removeObject(users.findProperty('username', username));
users.removeObject(users.findBy('username', username));
});
}
});

View File

@ -120,7 +120,7 @@ const Topic = RestModel.extend({
const categoryName = this.get('categoryName');
let category;
if (categoryName) {
category = Discourse.Category.list().findProperty('name', categoryName);
category = Discourse.Category.list().findBy('name', categoryName);
}
this.set('category', category);
}.observes('categoryName'),
@ -213,7 +213,7 @@ const Topic = RestModel.extend({
}.property('views'),
archetypeObject: function() {
return Discourse.Site.currentProp('archetypes').findProperty('id', this.get('archetype'));
return Discourse.Site.currentProp('archetypes').findBy('id', this.get('archetype'));
}.property('archetype'),
isPrivateMessage: Em.computed.equal('archetype', 'private_message'),

View File

@ -153,7 +153,7 @@ const User = RestModel.extend({
@computed("trust_level")
trustLevel(trustLevel) {
return Discourse.Site.currentProp('trustLevels').findProperty('id', parseInt(trustLevel, 10));
return Discourse.Site.currentProp('trustLevels').findBy('id', parseInt(trustLevel, 10));
},
isBasic: Em.computed.equal('trust_level', 0),
@ -525,7 +525,7 @@ User.reopenClass(Singleton, {
action_type: UserAction.TYPES.replies
});
stats.filterProperty('isResponse').forEach(stat => {
stats.filterBy('isResponse').forEach(stat => {
responses.set('count', responses.get('count') + stat.get('count'));
});

View File

@ -463,11 +463,11 @@ export default createWidget('post', {
undoPostAction(typeId) {
const post = this.model;
return post.get('actions_summary').findProperty('id', typeId).undo(post);
return post.get('actions_summary').findBy('id', typeId).undo(post);
},
deferPostActionFlags(typeId) {
const post = this.model;
return post.get('actions_summary').findProperty('id', typeId).deferFlags(post);
return post.get('actions_summary').findBy('id', typeId).deferFlags(post);
}
});

View File

@ -5,7 +5,7 @@ export default Ember.Component.extend({
@computed('user.role')
roleName(role) {
return this.get('roles').findProperty('id', role).label;
return this.get('roles').findBy('id', role).label;
},
actions: {

View File

@ -48,7 +48,7 @@ export default Ember.Component.extend({
}
const users = this.get('users');
if (users.findProperty('email', user.email)) {
if (users.findBy('email', user.email)) {
return this.set('invalid', true);
}

View File

@ -33,7 +33,7 @@ export default Ember.Object.extend(ValidState, {
},
fieldError(id, description) {
const field = this.get('fields').findProperty('id', id);
const field = this.get('fields').findBy('id', id);
if (field) {
field.setValid(false, description);
}

View File

@ -8,13 +8,13 @@ const Wizard = Ember.Object.extend({
totalSteps: length => length,
getTitle() {
const titleStep = this.get('steps').findProperty('id', 'forum-title');
const titleStep = this.get('steps').findBy('id', 'forum-title');
if (!titleStep) { return; }
return titleStep.get('fieldsById.title.value');
},
getLogoUrl() {
const logoStep = this.get('steps').findProperty('id', 'logos');
const logoStep = this.get('steps').findBy('id', 'logos');
if (!logoStep) { return; }
return logoStep.get('fieldsById.logo_url.value');
@ -22,7 +22,7 @@ const Wizard = Ember.Object.extend({
// A bit clunky, but get the current colors from the appropriate step
getCurrentColors() {
const colorStep = this.get('steps').findProperty('id', 'colors');
const colorStep = this.get('steps').findBy('id', 'colors');
if (!colorStep) { return; }
const themeChoice = colorStep.get('fieldsById.theme_id');
@ -34,7 +34,7 @@ const Wizard = Ember.Object.extend({
const choices = themeChoice.get('choices');
if (!choices) { return; }
const option = choices.findProperty('id', themeId);
const option = choices.findBy('id', themeId);
if (!option) { return; }
return option.data.colors;

View File

@ -1,7 +1,7 @@
export default Ember.Route.extend({
model(params) {
const allSteps = this.modelFor('application').steps;
const step = allSteps.findProperty('id', params.step_id);
const step = allSteps.findBy('id', params.step_id);
return step ? step : allSteps[0];
},