Skip to content

Commit

Permalink
ES6ify some of the remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Aug 10, 2015
1 parent 3780877 commit b7e6eaa
Show file tree
Hide file tree
Showing 96 changed files with 687 additions and 723 deletions.
@@ -1,13 +1,14 @@
import { bufferedProperty } from 'discourse/mixins/buffered-content';
import UserField from 'admin/models/user-field';
import { bufferedProperty } from 'discourse/mixins/buffered-content';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { propertyEqual } from 'discourse/lib/computed';

export default Ember.Component.extend(bufferedProperty('userField'), {
editing: Ember.computed.empty('userField.id'),
classNameBindings: [':user-field'],

cantMoveUp: Discourse.computed.propertyEqual('userField', 'firstField'),
cantMoveDown: Discourse.computed.propertyEqual('userField', 'lastField'),
cantMoveUp: propertyEqual('userField', 'firstField'),
cantMoveDown: propertyEqual('userField', 'lastField'),

userFieldsDescription: function() {
return I18n.t('admin.user_fields.description');
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/admin/components/site-setting.js.es6
@@ -1,13 +1,14 @@
import BufferedContent from 'discourse/mixins/buffered-content';
import ScrollTop from 'discourse/mixins/scroll-top';
import SiteSetting from 'admin/models/site-setting';
import { propertyNotEqual } from 'discourse/lib/computed';

const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list'];

export default Ember.Component.extend(BufferedContent, ScrollTop, {
classNameBindings: [':row', ':setting', 'setting.overridden', 'typeClass'],
content: Ember.computed.alias('setting'),
dirty: Discourse.computed.propertyNotEqual('buffered.value', 'setting.value'),
dirty: propertyNotEqual('buffered.value', 'setting.value'),
validationMessage: null,

preview: function() {
Expand Down
@@ -1,5 +1,6 @@
import { popupAjaxError } from 'discourse/lib/ajax-error';
import BufferedContent from 'discourse/mixins/buffered-content';
import { propertyNotEqual } from 'discourse/lib/computed';

export default Ember.ObjectController.extend(BufferedContent, {
needs: ['admin-badges'],
Expand All @@ -12,7 +13,7 @@ export default Ember.ObjectController.extend(BufferedContent, {
protectedSystemFields: Em.computed.alias('controllers.admin-badges.protectedSystemFields'),

readOnly: Ember.computed.alias('buffered.system'),
showDisplayName: Discourse.computed.propertyNotEqual('name', 'displayName'),
showDisplayName: propertyNotEqual('name', 'displayName'),
canEditDescription: Em.computed.none('buffered.translatedDescription'),

_resetSaving: function() {
Expand Down
@@ -1,3 +1,5 @@
import { url } from 'discourse/lib/computed';

const sections = ['css', 'header', 'top', 'footer', 'head-tag', 'body-tag',
'mobile-css', 'mobile-header', 'mobile-top', 'mobile-footer',
'embedded-css'];
Expand All @@ -12,8 +14,8 @@ export default Ember.Controller.extend(activeSections, {
maximized: false,
section: null,

previewUrl: Discourse.computed.url("model.key", "/?preview-style=%@"),
downloadUrl: Discourse.computed.url('model.id', '/admin/size_customizations/%@'),
previewUrl: url("model.key", "/?preview-style=%@"),
downloadUrl: url('model.id', '/admin/size_customizations/%@'),

mobile: function() {
return this.get('section').startsWith('mobile-');
Expand All @@ -33,8 +35,8 @@ export default Ember.Controller.extend(activeSections, {

needs: ['adminCustomizeCssHtml'],

undoPreviewUrl: Discourse.computed.url('/?preview-style='),
defaultStyleUrl: Discourse.computed.url('/?preview-style=default'),
undoPreviewUrl: url('/?preview-style='),
defaultStyleUrl: url('/?preview-style=default'),

actions: {
save() {
Expand Down
13 changes: 4 additions & 9 deletions app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
@@ -1,17 +1,12 @@
/**
This controller supports the default interface when you enter the admin section.
@class AdminDashboardController
@extends Ember.Controller
@namespace Discourse
@module Discourse
**/
import { setting } from 'discourse/lib/computed';

// This controller supports the default interface when you enter the admin section.
export default Ember.Controller.extend({
loading: true,
versionCheck: null,
problemsCheckMinutes: 1,

showVersionChecks: Discourse.computed.setting('version_checks'),
showVersionChecks: setting('version_checks'),

foundProblems: function() {
return(Discourse.User.currentProp('admin') && this.get('problems') && this.get('problems').length > 0);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/admin/controllers/admin-group.js.es6
@@ -1,4 +1,5 @@
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { propertyEqual } from 'discourse/lib/computed';

export default Em.ObjectController.extend({
needs: ['adminGroupsType'],
Expand All @@ -15,7 +16,7 @@ export default Em.ObjectController.extend({
}.property("limit", "user_count"),

showingFirst: Em.computed.lte("currentPage", 1),
showingLast: Discourse.computed.propertyEqual("currentPage", "totalPages"),
showingLast: propertyEqual("currentPage", "totalPages"),

aliasLevelOptions: function() {
return [
Expand Down
@@ -1,15 +1,16 @@
import ObjectController from 'discourse/controllers/object';
import CanCheckEmails from 'discourse/mixins/can-check-emails';
import { propertyNotEqual, setting } from 'discourse/lib/computed';

export default ObjectController.extend(CanCheckEmails, {
editingTitle: false,
originalPrimaryGroupId: null,
availableGroups: null,

showApproval: Discourse.computed.setting('must_approve_users'),
showBadges: Discourse.computed.setting('enable_badges'),
showApproval: setting('must_approve_users'),
showBadges: setting('enable_badges'),

primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'model.primary_group_id'),
primaryGroupDirty: propertyNotEqual('originalPrimaryGroupId', 'model.primary_group_id'),

automaticGroups: function() {
return this.get("model.automaticGroups").map((g) => g.name).join(", ");
Expand Down
@@ -1,3 +1,5 @@
import { i18n } from 'discourse/lib/computed';

export default Ember.ArrayController.extend({
query: null,
showEmails: false,
Expand All @@ -9,7 +11,7 @@ export default Ember.ArrayController.extend({
queryPending: Em.computed.equal('query', 'pending'),
queryHasApproval: Em.computed.or('queryNew', 'queryPending'),
showApproval: Em.computed.and('siteSettings.must_approve_users', 'queryHasApproval'),
searchHint: Discourse.computed.i18n('search_hint'),
searchHint: i18n('search_hint'),
hasSelection: Em.computed.gt('selectedCount', 0),

selectedCount: function() {
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/admin/models/admin-user.js.es6
@@ -1,3 +1,4 @@
import { propertyNotEqual } from 'discourse/lib/computed';
import { popupAjaxError } from 'discourse/lib/ajax-error';

const AdminUser = Discourse.User.extend({
Expand Down Expand Up @@ -144,7 +145,7 @@ const AdminUser = Discourse.User.extend({
this.set('originalTrustLevel', this.get('trust_level'));
},

dirty: Discourse.computed.propertyNotEqual('originalTrustLevel', 'trustLevel.id'),
dirty: propertyNotEqual('originalTrustLevel', 'trustLevel.id'),

saveTrustLevel() {
return Discourse.ajax("/admin/users/" + this.id + "/trust_level", {
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/admin/models/report.js.es6
@@ -1,7 +1,8 @@
import round from "discourse/lib/round";
import { fmt } from 'discourse/lib/computed';

const Report = Discourse.Model.extend({
reportUrl: Discourse.computed.fmt("type", "/admin/reports/%@"),
reportUrl: fmt("type", "/admin/reports/%@"),

valueAt(numDaysAgo) {
if (this.data) {
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/admin/models/user-field.js.es6
@@ -1,9 +1,10 @@
import RestModel from 'discourse/models/rest';
import { i18n } from 'discourse/lib/computed';

const UserField = RestModel.extend();

const UserFieldType = Ember.Object.extend({
name: Discourse.computed.i18n('id', 'admin.user_fields.field_types.%@')
name: i18n('id', 'admin.user_fields.field_types.%@')
});

UserField.reopenClass({
Expand Down
@@ -1,5 +1,6 @@
import StringBuffer from 'discourse/mixins/string-buffer';
import { iconHTML } from 'discourse/helpers/fa-icon';
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';

export default Ember.Component.extend(StringBuffer, {
tagName: 'section',
Expand Down Expand Up @@ -57,7 +58,7 @@ export default Ember.Component.extend(StringBuffer, {
buffer.push("<div class='post-action'>" +
iconHTML('fa-trash-o') + '&nbsp;' +
Discourse.Utilities.tinyAvatar(post.get('postDeletedBy.avatar_template'), {title: post.get('postDeletedBy.username')}) +
Discourse.Formatter.autoUpdatingRelativeAge(new Date(post.get('postDeletedAt'))) +
autoUpdatingRelativeAge(new Date(post.get('postDeletedAt'))) +
"</div>");
}
},
Expand Down
@@ -1,8 +1,9 @@
import { setting } from 'discourse/lib/computed';
var get = Ember.get;

export default Ember.Component.extend({
classNameBindings: ['category::no-category', 'categories:has-drop','categoryStyle'],
categoryStyle: Discourse.computed.setting('category_style'),
categoryStyle: setting('category_style'),

tagName: 'li',

Expand Down
@@ -1,6 +1,7 @@
import { setting } from 'discourse/lib/computed';
import { buildCategoryPanel } from 'discourse/components/edit-category-panel';

export default buildCategoryPanel('settings', {
emailInEnabled: Discourse.computed.setting('email_in'),
showPositionInput: Discourse.computed.setting('fixed_category_positions'),
emailInEnabled: setting('email_in'),
showPositionInput: setting('fixed_category_positions'),
});
@@ -1,3 +1,5 @@
import { propertyEqual } from 'discourse/lib/computed';

export default Em.Component.extend({
tagName: 'li',
classNameBindings: ['active', 'tabClassName'],
Expand All @@ -6,7 +8,7 @@ export default Em.Component.extend({
return 'edit-category-' + this.get('tab');
}.property('tab'),

active: Discourse.computed.propertyEqual('selectedTab', 'tab'),
active: propertyEqual('selectedTab', 'tab'),

title: function() {
return I18n.t('category.' + this.get('tab').replace('-', '_'));
Expand Down
10 changes: 6 additions & 4 deletions app/assets/javascripts/discourse/components/home-logo.js.es6
@@ -1,3 +1,5 @@
import { setting } from 'discourse/lib/computed';

export default Ember.Component.extend({
classNames: ["title"],

Expand All @@ -13,10 +15,10 @@ export default Ember.Component.extend({
return Discourse.Mobile.mobileView && !Ember.isBlank(this.get('mobileBigLogoUrl'));
}.property(),

smallLogoUrl: Discourse.computed.setting('logo_small_url'),
bigLogoUrl: Discourse.computed.setting('logo_url'),
mobileBigLogoUrl: Discourse.computed.setting('mobile_logo_url'),
title: Discourse.computed.setting('title'),
smallLogoUrl: setting('logo_small_url'),
bigLogoUrl: setting('logo_url'),
mobileBigLogoUrl: setting('mobile_logo_url'),
title: setting('title'),

click: function(e) {
// if they want to open in a new tab, let it so
Expand Down
@@ -1,6 +1,8 @@
import { setting } from 'discourse/lib/computed';

const PosterNameComponent = Em.Component.extend({
classNames: ['names', 'trigger-user-card'],
displayNameOnPosts: Discourse.computed.setting('display_name_on_posts'),
displayNameOnPosts: setting('display_name_on_posts'),

// sanitize name for comparison
sanitizeName(name){
Expand Down
@@ -1,3 +1,5 @@
import { relativeAge } from 'discourse/lib/formatter';

const icons = {
'closed.enabled': 'lock',
'closed.disabled': 'unlock-alt',
Expand All @@ -19,7 +21,7 @@ export function actionDescription(actionCode, createdAt) {
const ac = this.get(actionCode);
if (ac) {
const dt = new Date(this.get(createdAt));
const when = Discourse.Formatter.relativeAge(dt, {format: 'medium-with-ago'});
const when = relativeAge(dt, {format: 'medium-with-ago'});
return I18n.t(`action_codes.${ac}`, {when}).htmlSafe();
}
}.property(actionCode, createdAt);
Expand Down
@@ -1,8 +1,9 @@
import { propertyEqual } from 'discourse/lib/computed';
import { actionDescription } from "discourse/components/small-action";

export default Ember.Component.extend({
classNameBindings: [":item", "item.hidden", "item.deleted", "moderatorAction"],
moderatorAction: Discourse.computed.propertyEqual("item.post_type", "site.post_types.moderator_action"),
moderatorAction: propertyEqual("item.post_type", "site.post_types.moderator_action"),
actionDescription: actionDescription("item.action_code", "item.created_at"),

actions: {
Expand Down
@@ -1,6 +1,8 @@
import { fmt } from 'discourse/lib/computed';

export default Ember.Component.extend({
classNameBindings: [':user-field', 'field.field_type'],
layoutName: Discourse.computed.fmt('field.field_type', 'components/user-fields/%@'),
layoutName: fmt('field.field_type', 'components/user-fields/%@'),

noneLabel: function() {
if (!this.get('field.required')) {
Expand Down
@@ -1,7 +1,9 @@
import { url } from 'discourse/lib/computed';

export default Ember.Component.extend({
classNames: ['user-small'],

userPath: Discourse.computed.url('user.username', '/users/%@'),
userPath: url('user.username', '/users/%@'),

name: function() {
const name = this.get('user.name');
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -1,3 +1,4 @@
import { setting } from 'discourse/lib/computed';
import Presence from 'discourse/mixins/presence';

export default Ember.ObjectController.extend(Presence, {
Expand All @@ -8,7 +9,7 @@ export default Ember.ObjectController.extend(Presence, {

showEditReason: false,
editReason: null,
maxTitleLength: Discourse.computed.setting('max_topic_title_length'),
maxTitleLength: setting('max_topic_title_length'),
scopedCategoryId: null,
similarTopics: null,
similarTopicsMessage: null,
Expand Down
@@ -1,5 +1,6 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import DiscourseController from 'discourse/controllers/controller';
import { setting } from 'discourse/lib/computed';

export default DiscourseController.extend(ModalFunctionality, {
needs: ['login'],
Expand All @@ -16,10 +17,10 @@ export default DiscourseController.extend(ModalFunctionality, {
userFields: null,

hasAuthOptions: Em.computed.notEmpty('authOptions'),
canCreateLocal: Discourse.computed.setting('enable_local_logins'),
canCreateLocal: setting('enable_local_logins'),
showCreateForm: Em.computed.or('hasAuthOptions', 'canCreateLocal'),
maxUsernameLength: Discourse.computed.setting('max_username_length'),
minUsernameLength: Discourse.computed.setting('min_username_length'),
maxUsernameLength: setting('max_username_length'),
minUsernameLength: setting('min_username_length'),

resetForm() {
// We wrap the fields in a structure so we can assign a value
Expand Down
@@ -1,3 +1,5 @@
import { propertyEqual } from 'discourse/lib/computed';

export default Ember.Controller.extend({
me: Discourse.computed.propertyEqual('model.user.id', 'currentUser.id')
me: propertyEqual('model.user.id', 'currentUser.id')
});
@@ -1,6 +1,7 @@
import DiscoveryController from 'discourse/controllers/discovery';
import { queryParams } from 'discourse/controllers/discovery-sortable';
import BulkTopicSelection from 'discourse/mixins/bulk-topic-selection';
import { endWith } from 'discourse/lib/computed';

const controllerOpts = {
needs: ['discovery'],
Expand Down Expand Up @@ -102,8 +103,8 @@ const controllerOpts = {

hasTopics: Em.computed.gt('model.topics.length', 0),
allLoaded: Em.computed.empty('model.more_topics_url'),
latest: Discourse.computed.endWith('model.filter', 'latest'),
new: Discourse.computed.endWith('model.filter', 'new'),
latest: endWith('model.filter', 'latest'),
new: endWith('model.filter', 'new'),
top: Em.computed.notEmpty('period'),
yearly: Em.computed.equal('period', 'yearly'),
quarterly: Em.computed.equal('period', 'quarterly'),
Expand Down
6 changes: 1 addition & 5 deletions app/assets/javascripts/discourse/controllers/group.js.es6
@@ -1,7 +1,4 @@
import ObjectController from 'discourse/controllers/object';

// The basic controller for a group
export default ObjectController.extend({
export default Ember.Controller.extend({
counts: null,
showing: null,

Expand All @@ -10,4 +7,3 @@ export default ObjectController.extend({
showingIndex: Em.computed.equal('showing', 'index'),
showingMembers: Em.computed.equal('showing', 'members')
});

1 comment on commit b7e6eaa

@ZogStriP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.