Fixes some Ember Deprecations for 1.13:

- Remove ArrayController
- Remove {{view}} from templates
- Replace many cases of needs: [‘controller’] with inject
- Enable Ember Legacy Views
This commit is contained in:
Robin Ward 2016-10-20 13:26:41 -04:00
parent 2a61cc8c88
commit bf91532260
50 changed files with 255 additions and 336 deletions

View File

@ -2,17 +2,20 @@ import debounce from 'discourse/lib/debounce';
import { renderSpinner } from 'discourse/helpers/loading-spinner';
import { escapeExpression } from 'discourse/lib/utilities';
export default Ember.View.extend({
export default Ember.Component.extend({
classNames: ["admin-backups-logs"],
_initialize: function() { this._reset(); }.on("init"),
init() {
this._super();
this._reset();
},
_reset() {
this.setProperties({ formattedLogs: "", index: 0 });
},
_updateFormattedLogs: debounce(function() {
const logs = this.get("controller.model");
const logs = this.get("logs");
if (logs.length === 0) {
this._reset(); // reset the cached logs whenever the model is reset
} else {
@ -28,7 +31,7 @@ export default Ember.View.extend({
// force rerender
this.rerender();
}
}, 150).observes("controller.model.[]"),
}, 150).observes("logs.[]").on('init'),
render(buffer) {
const formattedLogs = this.get("formattedLogs");
@ -40,14 +43,14 @@ export default Ember.View.extend({
buffer.push("<p>" + I18n.t("admin.backups.logs.none") + "</p>");
}
// add a loading indicator
if (this.get("controller.status.model.isOperationRunning")) {
if (this.get("status.isOperationRunning")) {
buffer.push(renderSpinner('small'));
}
},
_forceScrollToBottom: function() {
didInsertElement() {
this._super();
const $div = this.$()[0];
$div.scrollTop = $div.scrollHeight;
}.on("didInsertElement")
},
});

View File

@ -1,66 +1,30 @@
import ApiKey from 'admin/models/api-key';
/**
This controller supports the interface for dealing with API keys
@class AdminApiController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
actions: {
/**
Generates a master api key
@method generateMasterKey
**/
generateMasterKey: function() {
var self = this;
ApiKey.generateMasterKey().then(function (key) {
self.get('model').pushObject(key);
});
generateMasterKey() {
ApiKey.generateMasterKey().then(key => this.get('model').pushObject(key));
},
/**
Creates an API key instance with internal user object
@method regenerateKey
@param {ApiKey} key the key to regenerate
**/
regenerateKey: function(key) {
bootbox.confirm(I18n.t("admin.api.confirm_regen"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
regenerateKey(key) {
bootbox.confirm(I18n.t("admin.api.confirm_regen"), I18n.t("no_value"), I18n.t("yes_value"), result => {
if (result) {
key.regenerate();
}
});
},
/**
Revokes an API key
@method revokeKey
@param {ApiKey} key the key to revoke
**/
revokeKey: function(key) {
var self = this;
bootbox.confirm(I18n.t("admin.api.confirm_revoke"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
revokeKey(key) {
bootbox.confirm(I18n.t("admin.api.confirm_revoke"), I18n.t("no_value"), I18n.t("yes_value"), result => {
if (result) {
key.revoke().then(function() {
self.get('model').removeObject(key);
});
key.revoke().then(() => this.get('model').removeObject(key));
}
});
}
},
/**
Has a master key already been generated?
@property hasMasterKey
@type {Boolean}
**/
// Has a master key already been generated?
hasMasterKey: function() {
return !!this.get('model').findBy('user', null);
}.property('model.[]')

View File

@ -1,19 +1,20 @@
import { ajax } from 'discourse/lib/ajax';
export default Ember.ArrayController.extend({
needs: ["adminBackups"],
status: Ember.computed.alias("controllers.adminBackups"),
export default Ember.Controller.extend({
adminBackups: Ember.inject.controller(),
status: Ember.computed.alias('adminBackups.model'),
uploadLabel: function() { return I18n.t("admin.backups.upload.label"); }.property(),
restoreTitle: function() {
if (!this.get('status.model.allowRestore')) {
if (!this.get('status.allowRestore')) {
return "admin.backups.operations.restore.is_disabled";
} else if (this.get("status.model.isOperationRunning")) {
} else if (this.get("status.isOperationRunning")) {
return "admin.backups.operations.is_running";
} else {
return "admin.backups.operations.restore.title";
}
}.property("status.model.{allowRestore,isOperationRunning}"),
}.property("status.{allowRestore,isOperationRunning}"),
actions: {

View File

@ -1,4 +1,5 @@
export default Ember.ArrayController.extend({
needs: ["adminBackups"],
status: Em.computed.alias("controllers.adminBackups")
export default Ember.Controller.extend({
logs: [],
adminBackups: Ember.inject.controller(),
status: Em.computed.alias("adminBackups.model")
});

View File

@ -3,14 +3,14 @@ import BufferedContent from 'discourse/mixins/buffered-content';
import { propertyNotEqual } from 'discourse/lib/computed';
export default Ember.Controller.extend(BufferedContent, {
needs: ['admin-badges'],
adminBadges: Ember.inject.controller(),
saving: false,
savingStatus: '',
badgeTypes: Em.computed.alias('controllers.admin-badges.badgeTypes'),
badgeGroupings: Em.computed.alias('controllers.admin-badges.badgeGroupings'),
badgeTriggers: Em.computed.alias('controllers.admin-badges.badgeTriggers'),
protectedSystemFields: Em.computed.alias('controllers.admin-badges.protectedSystemFields'),
badgeTypes: Em.computed.alias('adminBadges.badgeTypes'),
badgeGroupings: Em.computed.alias('adminBadges.badgeGroupings'),
badgeTriggers: Em.computed.alias('adminBadges.badgeTriggers'),
protectedSystemFields: Em.computed.alias('adminBadges.protectedSystemFields'),
readOnly: Ember.computed.alias('buffered.system'),
showDisplayName: propertyNotEqual('name', 'displayName'),
@ -30,16 +30,15 @@ export default Ember.Controller.extend(BufferedContent, {
}.observes('model.id'),
actions: {
save: function() {
save() {
if (!this.get('saving')) {
var fields = ['allow_title', 'multiple_grant',
let fields = ['allow_title', 'multiple_grant',
'listable', 'auto_revoke',
'enabled', 'show_posts',
'target_posts', 'name', 'description',
'long_description',
'icon', 'image', 'query', 'badge_grouping_id',
'trigger', 'badge_type_id'],
self = this;
'trigger', 'badge_type_id'];
if (this.get('buffered.system')){
var protectedFields = this.get('protectedSystemFields');
@ -51,54 +50,55 @@ export default Ember.Controller.extend(BufferedContent, {
this.set('saving', true);
this.set('savingStatus', I18n.t('saving'));
var boolFields = ['allow_title', 'multiple_grant',
const boolFields = ['allow_title', 'multiple_grant',
'listable', 'auto_revoke',
'enabled', 'show_posts',
'target_posts' ];
var data = {},
buffered = this.get('buffered');
const data = {};
const buffered = this.get('buffered');
fields.forEach(function(field){
var d = buffered.get(field);
if (_.include(boolFields, field)) { d = !!d; }
data[field] = d;
});
var newBadge = !this.get('id'),
model = this.get('model');
this.get('model').save(data).then(function() {
const newBadge = !this.get('id');
const model = this.get('model');
this.get('model').save(data).then(() => {
if (newBadge) {
var adminBadgesController = self.get('controllers.admin-badges');
if (!adminBadgesController.contains(model)) adminBadgesController.pushObject(model);
self.transitionToRoute('adminBadges.show', model.get('id'));
const adminBadges = this.get('adminBadges.model');
if (!adminBadges.contains(model)) {
adminBadges.pushObject(model);
}
this.transitionToRoute('adminBadges.show', model.get('id'));
} else {
self.commitBuffer();
self.set('savingStatus', I18n.t('saved'));
this.commitBuffer();
this.set('savingStatus', I18n.t('saved'));
}
}).catch(popupAjaxError).finally(function() {
self.set('saving', false);
self.set('savingStatus', '');
}).catch(popupAjaxError).finally(() => {
this.set('saving', false);
this.set('savingStatus', '');
});
}
},
destroy: function() {
var self = this,
adminBadgesController = this.get('controllers.admin-badges'),
model = this.get('model');
destroy() {
const adminBadges = this.get('adminBadges.model');
const model = this.get('model');
if (!model.get('id')) {
self.transitionToRoute('adminBadges.index');
this.transitionToRoute('adminBadges.index');
return;
}
return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
return bootbox.confirm(I18n.t("admin.badges.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => {
if (result) {
model.destroy().then(function() {
adminBadgesController.removeObject(model);
self.transitionToRoute('adminBadges.index');
}).catch(function() {
model.destroy().then(() => {
adminBadges.removeObject(model);
this.transitionToRoute('adminBadges.index');
}).catch(() => {
bootbox.alert(I18n.t('generic_error'));
});
}

View File

@ -1 +1 @@
export default Ember.ArrayController.extend();
export default Ember.Controller.extend();

View File

@ -1,4 +1,4 @@
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
onlyOverridden: false,
baseColorScheme: function() {
@ -13,8 +13,8 @@ export default Ember.ArrayController.extend({
return baseColorsHash;
}.property('baseColorScheme'),
removeSelected: function() {
this.removeObject(this.get('selectedItem'));
removeSelected() {
this.get('model').removeObject(this.get('selectedItem'));
this.set('selectedItem', null);
},
@ -26,8 +26,7 @@ export default Ember.ArrayController.extend({
return;
}
var matches = Em.A();
const matches = [];
_.each(this.get('selectedItem.colors'), function(color){
if (color.get('overridden')) matches.pushObject(color);
});
@ -58,10 +57,10 @@ export default Ember.ArrayController.extend({
this.filterContent();
},
newColorScheme: function() {
var newColorScheme = Em.copy(this.get('baseColorScheme'), true);
newColorScheme() {
const newColorScheme = Em.copy(this.get('baseColorScheme'), true);
newColorScheme.set('name', I18n.t('admin.customize.colors.new_name'));
this.pushObject(newColorScheme);
this.get('model').pushObject(newColorScheme);
this.send('selectColorScheme', newColorScheme);
this.set('onlyOverridden', false);
},
@ -86,10 +85,10 @@ export default Ember.ArrayController.extend({
this.updateEnabled();
},
copy: function(colorScheme) {
copy(colorScheme) {
var newColorScheme = Em.copy(colorScheme, true);
newColorScheme.set('name', I18n.t('admin.customize.colors.copy_name_prefix') + ' ' + colorScheme.get('name'));
this.pushObject(newColorScheme);
this.get('model').pushObject(newColorScheme);
this.send('selectColorScheme', newColorScheme);
},

View File

@ -1,23 +1,23 @@
import { ajax } from 'discourse/lib/ajax';
export default Ember.ArrayController.extend({
sortProperties: ["name"],
export default Ember.Controller.extend({
sortedEmojis: Ember.computed.sort('model', 'emojiSorting'),
emojiSorting: ['name'],
actions: {
emojiUploaded(emoji) {
emoji.url += "?t=" + new Date().getTime();
this.pushObject(Ember.Object.create(emoji));
this.get('model').pushObject(Ember.Object.create(emoji));
},
destroy(emoji) {
const self = this;
return bootbox.confirm(
I18n.t("admin.emoji.delete_confirm", { name: emoji.get("name") }),
I18n.t("no_value"),
I18n.t("yes_value"),
function(destroy) {
destroy => {
if (destroy) {
return ajax("/admin/customize/emojis/" + emoji.get("name"), { type: "DELETE" }).then(function() {
self.removeObject(emoji);
return ajax("/admin/customize/emojis/" + emoji.get("name"), { type: "DELETE" }).then(() => {
this.get('model').removeObject(emoji);
});
}
}

View File

@ -1,6 +1,6 @@
import FlaggedPost from 'admin/models/flagged-post';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
query: null,
adminOldFlagsView: Em.computed.equal("query", "old"),
@ -8,18 +8,16 @@ export default Ember.ArrayController.extend({
actions: {
disagreeFlags(flaggedPost) {
var self = this;
flaggedPost.disagreeFlags().then(function () {
self.removeObject(flaggedPost);
flaggedPost.disagreeFlags().then(() => {
this.get('model').removeObject(flaggedPost);
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
deferFlags(flaggedPost) {
var self = this;
flaggedPost.deferFlags().then(function () {
self.removeObject(flaggedPost);
flaggedPost.deferFlags().then(() => {
this.get('model').removeObject(flaggedPost);
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});

View File

@ -4,7 +4,7 @@ import { escapeExpression } from 'discourse/lib/utilities';
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
needs: ['adminGroupsType'],
adminGroupsType: Ember.inject.controller(),
disableSave: false,
savingStatus: '',
@ -131,13 +131,13 @@ export default Ember.Controller.extend({
save() {
const group = this.get('model'),
groupsController = this.get("controllers.adminGroupsType"),
groupsController = this.get("adminGroupsType"),
groupType = groupsController.get("type");
this.set('disableSave', true);
this.set('savingStatus', I18n.t('saving'));
let promise = group.get("id") ? group.save() : group.create().then(() => groupsController.addObject(group));
let promise = group.get("id") ? group.save() : group.create().then(() => groupsController.get('model').addObject(group));
promise.then(() => {
this.transitionToRoute("adminGroup", groupType, group.get('name'));
@ -148,7 +148,7 @@ export default Ember.Controller.extend({
destroy() {
const group = this.get('model'),
groupsController = this.get('controllers.adminGroupsType'),
groupsController = this.get('adminGroupsType'),
self = this;
if (!group.get('id')) {

View File

@ -1,18 +1,18 @@
import { ajax } from 'discourse/lib/ajax';
export default Ember.ArrayController.extend({
sortProperties: ['name'],
export default Ember.Controller.extend({
sortedGroups: Ember.computed.sort('model', 'groupSorting'),
groupSorting: ['name'],
refreshingAutoGroups: false,
isAuto: function(){
return this.get('type') === 'automatic';
}.property('type'),
isAuto: Ember.computed.equal('type', 'automatic'),
actions: {
refreshAutoGroups: function(){
var self = this;
refreshAutoGroups() {
this.set('refreshingAutoGroups', true);
ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function() {
self.transitionToRoute("adminGroupsType", "automatic").then(function() {
self.set('refreshingAutoGroups', false);
ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(() => {
this.transitionToRoute("adminGroupsType", "automatic").then(() => {
this.set('refreshingAutoGroups', false);
});
});
}

View File

@ -2,7 +2,7 @@ import { exportEntity } from 'discourse/lib/export-csv';
import { outputExportResult } from 'discourse/lib/export-result';
import ScreenedEmail from 'admin/models/screened-email';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
loading: false,
actions: {
@ -19,11 +19,10 @@ export default Ember.ArrayController.extend({
},
show() {
var self = this;
self.set('loading', true);
ScreenedEmail.findAll().then(function(result) {
self.set('model', result);
self.set('loading', false);
this.set('loading', true);
ScreenedEmail.findAll().then(result => {
this.set('model', result);
this.set('loading', false);
});
}
});

View File

@ -3,7 +3,7 @@ import { outputExportResult } from 'discourse/lib/export-result';
import { exportEntity } from 'discourse/lib/export-csv';
import ScreenedIpAddress from 'admin/models/screened-ip-address';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
loading: false,
filter: null,
savedIpAddress: null,
@ -63,16 +63,15 @@ export default Ember.ArrayController.extend({
},
destroy(record) {
const self = this;
return bootbox.confirm(
I18n.t("admin.logs.screened_ips.delete_confirm", { ip_address: record.get('ip_address') }),
I18n.t("no_value"),
I18n.t("yes_value"),
function (result) {
result => {
if (result) {
record.destroy().then(deleted => {
if (deleted) {
self.get("content").removeObject(record);
this.get("model").removeObject(record);
} else {
bootbox.alert(I18n.t("generic_error"));
}

View File

@ -2,15 +2,14 @@ import { exportEntity } from 'discourse/lib/export-csv';
import { outputExportResult } from 'discourse/lib/export-result';
import ScreenedUrl from 'admin/models/screened-url';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
loading: false,
show() {
const self = this;
self.set('loading', true);
ScreenedUrl.findAll().then(function(result) {
self.set('model', result);
self.set('loading', false);
this.set('loading', true);
ScreenedUrl.findAll().then(result => {
this.set('model', result);
this.set('loading', false);
});
},

View File

@ -2,7 +2,7 @@ import { exportEntity } from 'discourse/lib/export-csv';
import { outputExportResult } from 'discourse/lib/export-result';
import StaffActionLog from 'admin/models/staff-action-log';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
loading: false,
filters: null,

View File

@ -1,16 +1,14 @@
import debounce from 'discourse/lib/debounce';
import Permalink from 'admin/models/permalink';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
loading: false,
filter: null,
show: debounce(function() {
var self = this;
self.set('loading', true);
Permalink.findAll(self.get("filter")).then(function(result) {
self.set('model', result);
self.set('loading', false);
Permalink.findAll(this.get("filter")).then(result => {
this.set('model', result);
this.set('loading', false);
});
}, 250).observes("filter"),
@ -20,12 +18,11 @@ export default Ember.ArrayController.extend({
},
destroy: function(record) {
const self = this;
return bootbox.confirm(I18n.t("admin.permalink.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
return bootbox.confirm(I18n.t("admin.permalink.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => {
if (result) {
record.destroy().then(function(deleted) {
record.destroy().then(deleted => {
if (deleted) {
self.removeObject(record);
this.get('model').removeObject(record);
} else {
bootbox.alert(I18n.t("generic_error"));
}

View File

@ -1,7 +1,6 @@
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
adminRoutes: function() {
return this.get('model').map(function(p) {
return this.get('model').map(p => {
if (p.get('enabled')) {
return p.admin_route;
}

View File

@ -1,11 +1,11 @@
export default Ember.Controller.extend({
categoryNameKey: null,
needs: ['adminSiteSettings'],
adminSiteSettings: Ember.inject.controller(),
filteredContent: function() {
if (!this.get('categoryNameKey')) { return []; }
const category = this.get('controllers.adminSiteSettings.content').findProperty('nameKey', this.get('categoryNameKey'));
const category = this.get('adminSiteSettings.allSiteSettings').findProperty('nameKey', this.get('categoryNameKey'));
if (category) {
return category.siteSettings;
} else {

View File

@ -1,6 +1,6 @@
import debounce from 'discourse/lib/debounce';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
filter: null,
onlyOverridden: false,
filtered: Ember.computed.notEmpty('filter'),

View File

@ -1,10 +1,11 @@
import UserBadge from 'discourse/models/user-badge';
export default Ember.ArrayController.extend({
needs: ["adminUser"],
user: Em.computed.alias('controllers.adminUser.model'),
sortProperties: ['granted_at'],
sortAscending: false,
export default Ember.Controller.extend({
adminUser: Ember.inject.controller(),
user: Ember.computed.alias('adminUser.model'),
sortedBadges: Ember.computed.sort('model', 'badgeSortOrder'),
badgeSortOrder: ['granted_at:desc'],
groupedBadges: function(){
const allBadges = this.get('model');
@ -38,8 +39,6 @@ export default Ember.ArrayController.extend({
});
return _(expanded).sortBy(group => group.granted_at).reverse().value();
}.property('model', 'model.[]', 'model.expandedBadges.[]'),
/**
@ -80,22 +79,15 @@ export default Ember.ArrayController.extend({
model.get('expandedBadges').pushObject(userBadge.badge.id);
},
/**
Grant the selected badge to the user.
@method grantBadge
@param {Integer} badgeId id of the badge we want to grant.
**/
grantBadge: function(badgeId) {
var self = this;
UserBadge.grant(badgeId, this.get('user.username'), this.get('badgeReason')).then(function(userBadge) {
self.set('badgeReason', '');
self.pushObject(userBadge);
Ember.run.next(function() {
grantBadge(badgeId) {
UserBadge.grant(badgeId, this.get('user.username'), this.get('badgeReason')).then(userBadge => {
this.set('badgeReason', '');
this.get('model').pushObject(userBadge);
Ember.run.next(() => {
// Update the selected badge ID after the combobox has re-rendered.
var newSelectedBadge = self.get('grantableBadges')[0];
const newSelectedBadge = this.get('grantableBadges')[0];
if (newSelectedBadge) {
self.set('selectedBadgeId', newSelectedBadge.get('id'));
this.set('selectedBadgeId', newSelectedBadge.get('id'));
}
});
}, function() {
@ -104,12 +96,11 @@ export default Ember.ArrayController.extend({
});
},
revokeBadge: function(userBadge) {
var self = this;
return bootbox.confirm(I18n.t("admin.badges.revoke_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
revokeBadge(userBadge) {
return bootbox.confirm(I18n.t("admin.badges.revoke_confirm"), I18n.t("no_value"), I18n.t("yes_value"), result => {
if (result) {
userBadge.revoke().then(function() {
self.get('model').removeObject(userBadge);
userBadge.revoke().then(() => {
this.get('model').removeObject(userBadge);
});
}
});

View File

@ -2,7 +2,7 @@ import debounce from 'discourse/lib/debounce';
import { i18n } from 'discourse/lib/computed';
import AdminUser from 'admin/models/admin-user';
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
query: null,
showEmails: false,
refreshing: false,

View File

@ -1,16 +1,15 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
export default Ember.Controller.extend(ModalFunctionality, {
needs: ["admin-flags-list"],
adminFlagsList: Ember.inject.controller(),
_agreeFlag: function (actionOnPost) {
var adminFlagController = this.get("controllers.admin-flags-list");
var post = this.get("content");
var self = this;
const adminFlagController = this.get("adminFlagsList");
const post = this.get("content");
return post.agreeFlags(actionOnPost).then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
return post.agreeFlags(actionOnPost).then(() => {
adminFlagController.get('model').removeObject(post);
this.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});

View File

@ -1,36 +1,31 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
export default Ember.Controller.extend(ModalFunctionality, {
needs: ["admin-flags-list"],
adminFlagsList: Ember.inject.controller(),
actions: {
deletePostDeferFlag() {
const adminFlagController = this.get("adminFlagsList");
const post = this.get("content");
deletePostDeferFlag: function () {
var adminFlagController = this.get("controllers.admin-flags-list");
var post = this.get("content");
var self = this;
return post.deferFlags(true).then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
return post.deferFlags(true).then(() => {
adminFlagController.get('model').removeObject(post);
this.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
deletePostAgreeFlag: function () {
var adminFlagController = this.get("controllers.admin-flags-list");
var post = this.get("content");
var self = this;
deletePostAgreeFlag() {
const adminFlagController = this.get("adminFlagsList");
const post = this.get("content");
return post.agreeFlags("delete").then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
return post.agreeFlags("delete").then(() => {
adminFlagController.get('model').removeObject(post);
this.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
}
}
});

View File

@ -2,7 +2,6 @@ import { ajax } from 'discourse/lib/ajax';
import PreloadStore from 'preload-store';
const Backup = Discourse.Model.extend({
destroy() {
return ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
},
@ -13,11 +12,9 @@ const Backup = Discourse.Model.extend({
data: { client_id: window.MessageBus.clientId }
});
}
});
Backup.reopenClass({
find() {
return PreloadStore.getAndRemove("backups", () => ajax("/admin/backups.json"))
.then(backups => backups.map(backup => Backup.create(backup)));

View File

@ -5,17 +5,17 @@ export default Ember.Route.extend({
// since the logs are pushed via the message bus
// we only want to preload them (hence the beforeModel hook)
beforeModel() {
const logsController = this.controllerFor("adminBackupsLogs");
const logs = this.controllerFor("adminBackupsLogs").get('logs');
// preload the logs if any
PreloadStore.getAndRemove("logs").then(function (preloadedLogs) {
if (preloadedLogs && preloadedLogs.length) {
// we need to filter out message like: "[SUCCESS]"
// and convert POJOs to Ember Objects
const logs = _.chain(preloadedLogs)
const newLogs = _.chain(preloadedLogs)
.reject(function (log) { return log.message.length === 0 || log.message[0] === "["; })
.map(function (log) { return Em.Object.create(log); })
.value();
logsController.pushObjects(logs);
logs.pushObjects(newLogs);
}
});
},

View File

@ -15,7 +15,7 @@ export default Discourse.Route.extend({
_processLogMessage(log) {
if (log.message === "[STARTED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", true);
this.controllerFor("adminBackupsLogs").clear();
this.controllerFor("adminBackupsLogs").get('logs').clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set("model.isOperationRunning", false);
bootbox.alert(I18n.t("admin.backups.operations.failed", { operation: log.operation }));
@ -27,7 +27,7 @@ export default Discourse.Route.extend({
window.location.pathname = Discourse.getURL("/");
}
} else {
this.controllerFor("adminBackupsLogs").pushObject(Em.Object.create(log));
this.controllerFor("adminBackupsLogs").get('logs').pushObject(Em.Object.create(log));
}
},

View File

@ -5,21 +5,20 @@ import BadgeGrouping from 'discourse/models/badge-grouping';
export default Discourse.Route.extend({
_json: null,
model: function() {
var self = this;
return ajax('/admin/badges.json').then(function(json) {
self._json = json;
model() {
return ajax('/admin/badges.json').then(json => {
this._json = json;
return Badge.createFromJson(json);
});
},
setupController: function(controller, model) {
var json = this._json,
triggers = [],
badgeGroupings = [];
setupController(controller, model) {
const json = this._json;
const badgeTriggers = [];
const badgeGroupings = [];
_.each(json.admin_badges.triggers,function(v,k){
triggers.push({id: v, name: I18n.t('admin.badges.trigger_type.'+k)});
badgeTriggers.push({id: v, name: I18n.t('admin.badges.trigger_type.'+k)});
});
json.badge_groupings.forEach(function(badgeGroupingJson) {
@ -30,8 +29,8 @@ export default Discourse.Route.extend({
badgeGroupings: badgeGroupings,
badgeTypes: json.badge_types,
protectedSystemFields: json.admin_badges.protected_system_fields,
badgeTriggers: triggers,
model: model
badgeTriggers,
model
});
}
});

View File

@ -31,4 +31,3 @@
{{#unless hasMasterKey}}
<button class='btn' {{action "generateMasterKey"}}><i class="fa fa-key"></i>{{i18n 'admin.api.generate_master'}}</button>
{{/unless}}

View File

@ -0,0 +1 @@
{{admin-backups-logs logs=logs status=status}}

View File

@ -6,9 +6,9 @@
<div class="pull-right">
{{resumable-upload target="/admin/backups/upload" success="uploadSuccess" error="uploadError" uploadText=uploadLabel title="admin.backups.upload.title"}}
{{#if site.isReadOnly}}
{{d-button icon="eye" action="toggleReadOnlyMode" disabled=status.model.isOperationRunning title="admin.backups.read_only.disable.title" label="admin.backups.read_only.disable.label"}}
{{d-button icon="eye" action="toggleReadOnlyMode" disabled=status.isOperationRunning title="admin.backups.read_only.disable.title" label="admin.backups.read_only.disable.label"}}
{{else}}
{{d-button icon="eye" action="toggleReadOnlyMode" disabled=status.model.isOperationRunning title="admin.backups.read_only.enable.title" label="admin.backups.read_only.enable.label"}}
{{d-button icon="eye" action="toggleReadOnlyMode" disabled=status.isOperationRunning title="admin.backups.read_only.enable.title" label="admin.backups.read_only.enable.label"}}
{{/if}}
</div>
</th>
@ -20,12 +20,12 @@
<td>
<div class="pull-right">
<a href={{backup.link}} class="btn download" title="{{i18n 'admin.backups.operations.download.title'}}">{{fa-icon "download"}}{{i18n 'admin.backups.operations.download.label'}}</a>
{{#if status.model.isOperationRunning}}
{{#if status.isOperationRunning}}
{{d-button icon="trash-o" action="destroyBackup" actionParam=backup class="btn-danger" disabled="true" title="admin.backups.operations.is_running"}}
{{d-button icon="play" action="startRestore" actionParam=backup disabled=status.model.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}}
{{d-button icon="play" action="startRestore" actionParam=backup disabled=status.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}}
{{else}}
{{d-button icon="trash-o" action="destroyBackup" actionParam=backup class="btn-danger" title="admin.backups.operations.destroy.title"}}
{{d-button icon="play" action="startRestore" actionParam=backup disabled=status.model.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}}
{{d-button icon="play" action="startRestore" actionParam=backup disabled=status.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}}
{{/if}}
</div>
</td>

View File

@ -5,7 +5,7 @@
<p>{{emoji-uploader done="emojiUploaded"}}</p>
{{#if model}}
{{#if sortedEmojis}}
<div class="span8">
<table id="custom_emoji">
<thead>
@ -16,7 +16,7 @@
</tr>
</thead>
<tbody>
{{#each model as |e|}}
{{#each sortedEmojis as |e|}}
<tr>
<th><img class="emoji" src="{{unbound e.url}}" title="{{unbound e.name}}"></th>
<th>:{{e.name}}:</th>

View File

@ -2,7 +2,7 @@
<div class='content-list span6'>
<h3>{{i18n 'admin.groups.edit'}}</h3>
<ul>
{{#each model as |group|}}
{{#each sortedGroups as |group|}}
<li>
{{#link-to "adminGroup" group.type group.name}}{{group.name}}
{{#if group.userCountDisplay}}

View File

@ -3,7 +3,7 @@ import { topicLevels } from 'discourse/lib/notification-levels';
// Support for changing the notification level of various topics
export default Ember.Controller.extend({
needs: ['topic-bulk-actions'],
topicBulkActions: Ember.inject.controller(),
notificationLevelId: null,
@computed
@ -21,7 +21,7 @@ export default Ember.Controller.extend({
actions: {
changeNotificationLevel() {
this.get('controllers.topic-bulk-actions').performAndRefresh({
this.get('topicBulkActions').performAndRefresh({
type: 'change_notification_level',
notification_level_id: this.get('notificationLevelId')
});

View File

@ -1,19 +1,18 @@
import { fmt } from 'discourse/lib/computed';
export default Ember.ArrayController.extend({
needs: ['group'],
export default Ember.Controller.extend({
group: Ember.inject.controller(),
loading: false,
emptyText: fmt('type', 'groups.empty.%@'),
actions: {
loadMore() {
if (this.get('loading')) { return; }
this.set('loading', true);
const posts = this.get('model');
if (posts && posts.length) {
const beforePostId = posts[posts.length-1].get('id');
const group = this.get('controllers.group.model');
const group = this.get('group.model');
const opts = { beforePostId, type: this.get('type') };
group.findPosts(opts).then(newPosts => {

View File

@ -1,27 +1,26 @@
import { ajax } from 'discourse/lib/ajax';
import BadgeSelectController from "discourse/mixins/badge-select-controller";
export default Ember.ArrayController.extend(BadgeSelectController, {
export default Ember.Controller.extend(BadgeSelectController, {
filteredList: function() {
return this.get('model').filterBy('badge.allow_title', true);
}.property('model'),
actions: {
save: function() {
save() {
this.setProperties({ saved: false, saving: true });
var self = this;
ajax(this.get('user.path') + "/preferences/badge_title", {
type: "PUT",
data: { user_badge_id: self.get('selectedUserBadgeId') }
}).then(function() {
self.setProperties({
data: { user_badge_id: this.get('selectedUserBadgeId') }
}).then(() => {
this.setProperties({
saved: true,
saving: false,
"user.title": self.get('selectedUserBadge.badge.name')
"user.title": this.get('selectedUserBadge.badge.name')
});
}, function() {
}, () => {
bootbox.alert(I18n.t('generic_error'));
});
}

View File

@ -1,7 +1,7 @@
import { ajax } from 'discourse/lib/ajax';
import BadgeSelectController from "discourse/mixins/badge-select-controller";
export default Ember.ArrayController.extend(BadgeSelectController, {
export default Ember.Controller.extend(BadgeSelectController, {
filteredList: function() {
return this.get('model').filter(function(b) {
return !Ember.isEmpty(b.get('badge.image'));
@ -12,18 +12,17 @@ export default Ember.ArrayController.extend(BadgeSelectController, {
save: function() {
this.setProperties({ saved: false, saving: true });
var self = this;
ajax(this.get('user.path') + "/preferences/card-badge", {
type: "PUT",
data: { user_badge_id: self.get('selectedUserBadgeId') }
}).then(function() {
self.setProperties({
data: { user_badge_id: this.get('selectedUserBadgeId') }
}).then(() => {
this.setProperties({
saved: true,
saving: false,
"user.card_image_badge": self.get('selectedUserBadge.badge.image')
"user.card_image_badge": this.get('selectedUserBadge.badge.image')
});
}).catch(function() {
self.set('saving', false);
}).catch(() => {
this.set('saving', false);
bootbox.alert(I18n.t('generic_error'));
});
}

View File

@ -1,5 +1,5 @@
export default Ember.Controller.extend({
needs: ['tagGroups'],
tagGroups: Ember.inject.controller(),
actions: {
save() {
@ -7,17 +7,16 @@ export default Ember.Controller.extend({
},
destroy() {
const self = this;
return bootbox.confirm(
I18n.t("tagging.groups.confirm_delete"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(destroy) {
destroy => {
if (destroy) {
const c = self.controllerFor('tagGroups');
return self.get('model').destroy().then(function() {
c.removeObject(self.get('model'));
self.transitionToRoute('tagGroups');
const c = this.get('tagGroups.model');
return this.get('model').destroy().then(() => {
c.removeObject(this.get('model'));
this.transitionToRoute('tagGroups');
});
}
}

View File

@ -1,6 +1,6 @@
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
actions: {
selectTagGroup: function(tagGroup) {
selectTagGroup(tagGroup) {
if (this.get('selectedItem')) { this.get('selectedItem').set('selected', false); }
this.set('selectedItem', tagGroup);
tagGroup.set('selected', true);
@ -8,10 +8,10 @@ export default Ember.ArrayController.extend({
this.transitionToRoute('tagGroups.show', tagGroup);
},
newTagGroup: function() {
newTagGroup() {
const newTagGroup = this.store.createRecord('tag-group');
newTagGroup.set('name', I18n.t('tagging.groups.new_name'));
this.pushObject(newTagGroup);
this.get('model').pushObject(newTagGroup);
this.send('selectTagGroup', newTagGroup);
}
}

View File

@ -17,7 +17,7 @@ addBulkButton('unlistTopics', 'unlist_topics');
addBulkButton('showTagTopics', 'change_tags');
// Modal for performing bulk actions on topics
export default Ember.ArrayController.extend(ModalFunctionality, {
export default Ember.Controller.extend(ModalFunctionality, {
tags: null,
buttonRows: null,

View File

@ -24,6 +24,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
retrying: false,
userTriggeredProgress: null,
_progressIndex: null,
hasScrolled: null,
topicDelegated: [
'toggleMultiSelect',

View File

@ -1,20 +1,6 @@
export default Ember.ArrayController.extend({
needs: ["user"],
user: Em.computed.alias("controllers.user.model"),
sortProperties: ['badge.badge_type.sort_order', 'badge.name'],
orderBy: function(ub1, ub2){
var sr1 = ub1.get('badge.badge_type.sort_order');
var sr2 = ub2.get('badge.badge_type.sort_order');
if(sr1 > sr2) {
return -1;
}
if(sr2 > sr1) {
return 1;
}
return ub1.get('badge.name') < ub2.get('badge.name') ? -1 : 1;
}
export default Ember.Controller.extend({
user: Ember.inject.controller(),
username: Ember.computed.alias('user.model.username_lower'),
sortedBadges: Ember.computed.sort('model', 'badgeSortOrder'),
badgeSortOrder: ['badge.badge_type.sort_order', 'badge.name'],
});

View File

@ -1,12 +1,12 @@
import { ajax } from 'discourse/lib/ajax';
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
export default Ember.ArrayController.extend({
needs: ['application'],
export default Ember.Controller.extend({
application: Ember.inject.controller(),
@observes('model.canLoadMore')
_showFooter() {
this.set("controllers.application.showFooter", !this.get("model.canLoadMore"));
this.set("application.showFooter", !this.get("model.canLoadMore"));
},
@computed('model.content.length')
@ -16,11 +16,9 @@ export default Ember.ArrayController.extend({
@computed('model.content.@each.read')
allNotificationsRead() {
return !this.get('model.content').some((notification) => !notification.get('read'));
return !this.get('model.content').some(notification => !notification.get('read'));
},
currentPath: Em.computed.alias('controllers.application.currentPath'),
actions: {
resetNew() {
ajax('/notifications/mark-read', { method: 'PUT' }).then(() => {

View File

@ -1,6 +1,6 @@
{{#discovery-categories refresh="refresh"}}
{{component controller.categoryPageStyle
{{component categoryPageStyle
categories=model.categories
latestTopicOnly=controller.latestTopicOnly
latestTopicOnly=latestTopicOnly
topics=model.topics}}
{{/discovery-categories}}

View File

@ -1,6 +1,6 @@
<div class='modal-body'>
<p>{{{i18n 'topics.bulk.selected' count=length}}}</p>
<p>{{{i18n 'topics.bulk.selected' count=model.length}}}</p>
{{outlet "bulkOutlet"}}

View File

@ -1,6 +1,6 @@
{{#if model}}
<div class="container">
{{discourse-banner user=currentUser banner=site.banner overlay=view.hasScrolled hide=model.errorLoading}}
{{discourse-banner user=currentUser banner=site.banner overlay=hasScrolled hide=model.errorLoading}}
</div>
{{/if}}

View File

@ -1,5 +1,5 @@
<section class='user-content user-badges-list'>
{{#each model as |ub|}}
{{badge-card badge=ub.badge count=ub.count navigateOnClick="true" username=user.username_lower}}
{{#each sortedBadges as |ub|}}
{{badge-card badge=ub.badge count=ub.count navigateOnClick="true" username=username}}
{{/each}}
</section>

View File

@ -1,5 +1,5 @@
<section class='user-navigation'>
{{#mobile-nav class='notifications-nav' desktopClass='notification-list action-list nav-stacked' currentPath=currentPath}}
{{#mobile-nav class='notifications-nav' desktopClass='notification-list action-list nav-stacked' currentPath=application.currentPath}}
<li class='no-glyph'>
{{#link-to 'userNotifications.index'}}{{i18n 'user.filters.all'}}{{/link-to}}
</li>

View File

@ -93,9 +93,6 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli
this.set('docAt', false);
},
offset: 0,
hasScrolled: Em.computed.gt("offset", 0),
showTopicInHeader(topic, offset) {
if (this.get('docAt')) {
return offset >= this.get('docAt') || topic.get('postStream.firstPostNotLoaded');
@ -118,7 +115,7 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli
}
}
this.set("offset", offset);
this.set('controller.hasScrolled', offset > 0);
const topic = this.get('topic');
const showTopic = this.showTopicInHeader(topic, offset);

View File

@ -1,3 +1,4 @@
window.ENV = { };
window.EmberENV = window.EmberENV || {};
window.EmberENV['FORCE_JQUERY'] = true;
window.EmberENV.FORCE_JQUERY = true;
window.EmberENV._ENABLE_LEGACY_VIEW_SUPPORT = true;

View File

@ -9,7 +9,7 @@ test("grantableBadges", function() {
const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true});
const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true});
const badgeDisabled = Badge.create({id: 4, name: "Disabled Badge", enabled: false});
const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] });
const controller = this.subject({ model: [], badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] });
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
const badgeNames = controller.get('grantableBadges').map(function(badge) {
return badge.name;