Convert admin section controllers to ES6 modules

This commit is contained in:
Joshua Gorner 2014-07-22 23:20:45 -04:00 committed by Robin Ward
parent 2358d13d49
commit e242368266
45 changed files with 146 additions and 123 deletions

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminApiController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
actions: {
/**

View File

@ -1,4 +1,4 @@
Discourse.AdminBackupsIndexController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
needs: ["adminBackups"],
status: Em.computed.alias("controllers.adminBackups"),

View File

@ -1,4 +1,4 @@
Discourse.AdminBackupsLogsController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
needs: ["adminBackups"],
status: Em.computed.alias("controllers.adminBackups")
});

View File

@ -1,4 +1,4 @@
Discourse.AdminBackupsController = Ember.ObjectController.extend({
export default Ember.ObjectController.extend({
noOperationIsRunning: Em.computed.not("isOperationRunning"),
rollbackEnabled: Em.computed.and("canRollback", "restoreEnabled", "noOperationIsRunning"),
rollbackDisabled: Em.computed.not("rollbackEnabled")

View File

@ -8,7 +8,7 @@
@module Discourse
**/
Discourse.AdminBadgeController = Discourse.ObjectController.extend({
export default Discourse.ObjectController.extend({
/**
Whether this badge has been selected.

View File

@ -6,8 +6,8 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminBadgesController = Ember.ArrayController.extend({
itemController: 'adminBadge',
export default Ember.ArrayController.extend({
itemController: 'admin-badge',
queryParams: ['badgeId'],
badgeId: Em.computed.alias('selectedId'),

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminCustomizeColorsController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
onlyOverridden: false,

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminCustomizeCssHtmlController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
actions: {

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminDashboardController = Ember.Controller.extend({
export default Ember.Controller.extend({
loading: true,
versionCheck: null,
problemsCheckMinutes: 1,

View File

@ -0,0 +1,3 @@
import AdminEmailSkippedController from "admin/controllers/admin-email-skipped"
export default AdminEmailSkippedController.extend({});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminEmailIndexController = Discourse.Controller.extend({
export default Discourse.Controller.extend({
/**
Is the "send test email" button disabled?

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminEmailPreviewDigestController = Discourse.ObjectController.extend({
export default Discourse.ObjectController.extend({
actions: {
refresh: function() {

View File

@ -0,0 +1,17 @@
/**
This controller supports email logs functionality.
@class AdminEmailSentController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
export default Discourse.Controller.extend({
filterEmailLogs: Discourse.debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
self.set("model", logs);
});
}, 250).observes("filter.user", "filter.address", "filter.type", "filter.reply_key")
});

View File

@ -0,0 +1,17 @@
/**
This controller supports email logs functionality.
@class AdminEmailSkippedController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
export default Discourse.Controller.extend({
filterEmailLogs: Discourse.debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
self.set("model", logs);
});
}, 250).observes("filter.user", "filter.address", "filter.type", "filter.skipped_reason")
});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminFlagsController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
actions: {
/**

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminGithubCommitsController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
goToGithub: function() {
window.open('https://github.com/discourse/discourse');
}

View File

@ -1,4 +1,4 @@
Discourse.AdminGroupController = Em.ObjectController.extend({
export default Em.ObjectController.extend({
needs: ['adminGroups'],
members: null,
disableSave: false,

View File

@ -1,4 +1,4 @@
Discourse.AdminGroupsController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
sortProperties: ['name'],
refreshingAutoGroups: false,

View File

@ -1,33 +1,4 @@
/**
This controller supports the interface for listing screened IP addresses in the admin section.
@class AdminLogsScreenedIpAddressesController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedIpAddressesController = Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
content: [],
itemController: 'adminLogsScreenedIpAddress',
show: function() {
var self = this;
this.set('loading', true);
Discourse.ScreenedIpAddress.findAll().then(function(result) {
self.set('content', result);
self.set('loading', false);
});
},
actions: {
recordAdded: function(arg) {
this.get("content").unshiftObject(arg);
}
}
});
Discourse.AdminLogsScreenedIpAddressController = Ember.ObjectController.extend({
export default Ember.ObjectController.extend({
editing: false,
savedIpAddress: null,

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedEmailsController = Ember.ArrayController.extend(Discourse.Presence, {
export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
content: [],

View File

@ -0,0 +1,28 @@
/**
This controller supports the interface for listing screened IP addresses in the admin section.
@class AdminLogsScreenedIpAddressesController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
content: [],
itemController: 'adminLogsScreenedIpAddress',
show: function() {
var self = this;
this.set('loading', true);
Discourse.ScreenedIpAddress.findAll().then(function(result) {
self.set('content', result);
self.set('loading', false);
});
},
actions: {
recordAdded: function(arg) {
this.get("content").unshiftObject(arg);
}
}
});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedUrlsController = Ember.ArrayController.extend(Discourse.Presence, {
export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
content: [],

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsStaffActionLogsController = Ember.ArrayController.extend(Discourse.Presence, {
export default Ember.ArrayController.extend(Discourse.Presence, {
loading: false,
filters: {},

View File

@ -1,4 +1,4 @@
Discourse.AdminReportsController = Ember.ObjectController.extend({
export default Ember.ObjectController.extend({
viewMode: 'table',
viewingTable: Em.computed.equal('viewMode', 'table'),

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminSiteContentEditController = Discourse.Controller.extend({
export default Discourse.Controller.extend({
saveDisabled: function() {
if (this.get('saving')) { return true; }
@ -24,5 +24,3 @@ Discourse.AdminSiteContentEditController = Discourse.Controller.extend({
}
}
});
Discourse.AdminSiteContentsController = Ember.ArrayController.extend({});

View File

@ -0,0 +1 @@
export default Ember.ArrayController.extend({});

View File

@ -1,4 +1,4 @@
Discourse.AdminSiteSettingsCategoryController = Ember.ObjectController.extend({
export default Ember.ObjectController.extend({
categoryNameKey: null,
needs: ['adminSiteSettings'],

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.Presence, {
export default Ember.ArrayController.extend(Discourse.Presence, {
filter: null,
onlyOverridden: false,
filtered: Ember.computed.notEmpty('filter'),

View File

@ -7,4 +7,4 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.AdminStaffActionLogDetailsController = Discourse.ObjectController.extend(Discourse.ModalFunctionality, {});
export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, {});

View File

@ -7,7 +7,7 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.AdminSuspendUserController = Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
submitDisabled: function() {
return (!this.get('reason') || this.get('reason').length < 1);

View File

@ -7,7 +7,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserBadgesController = Ember.ArrayController.extend({
export default Ember.ArrayController.extend({
needs: ["adminUser"],
user: Em.computed.alias('controllers.adminUser'),
sortProperties: ['granted_at'],

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
export default Discourse.ObjectController.extend({
editingTitle: false,
originalPrimaryGroupId: null,
availableGroups: null,
@ -88,4 +88,3 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
}
});

View File

@ -0,0 +1,10 @@
/**
The top-level controller for user pages in admin.
Ember assertion says that this class needs to be defined even if it's empty.
@class AdminUserController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
export default Discourse.ObjectController.extend({});

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminUsersListController = Ember.ArrayController.extend(Discourse.Presence, {
export default Ember.ArrayController.extend(Discourse.Presence, {
username: null,
query: null,
selectAll: false,

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminController = Discourse.Controller.extend({
export default Discourse.Controller.extend({
showBadges: function() {
return this.get('currentUser.admin') && Discourse.SiteSettings.enable_badges;
}.property()

View File

@ -1,38 +0,0 @@
/**
This controller supports email logs functionality.
@class AdminEmailSentController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
Discourse.AdminEmailSentController = Discourse.Controller.extend({
filterEmailLogs: Discourse.debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
self.set("model", logs);
});
}, 250).observes("filter.user", "filter.address", "filter.type", "filter.reply_key")
});
/**
This controller supports email logs functionality.
@class AdminEmailSkippedController
@extends Discourse.Controller
@namespace Discourse
@module Discourse
**/
Discourse.AdminEmailSkippedController = Discourse.Controller.extend({
filterEmailLogs: Discourse.debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
self.set("model", logs);
});
}, 250).observes("filter.user", "filter.address", "filter.type", "filter.skipped_reason")
});
Discourse.AdminEmailAllController = Discourse.AdminEmailSkippedController.extend({});

View File

@ -8,7 +8,7 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.ChangeSiteCustomizationDetailsController = Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, {
previousSelected: Ember.computed.equal('selectedTab', 'previous'),
newSelected: Ember.computed.equal('selectedTab', 'new'),

View File

@ -8,7 +8,9 @@
@uses Discourse.ModalFunctionality
@module Discourse
**/
Discourse.DeleteSiteCustomizationDetailsController = Discourse.ChangeSiteCustomizationDetailsController.extend({
import ChangeSiteCustomizationDetailsController from "admin/controllers/change-site-customization-details-controller";
export default ChangeSiteCustomizationDetailsController.extend({
onShow: function() {
this.selectPrevious();
}

View File

@ -6,7 +6,8 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminDashboardRoute = Discourse.Route.extend({
export default Discourse.Route.extend({
setupController: function(c) {
this.fetchDashboardData(c);

View File

@ -37,16 +37,20 @@ Discourse.Resolver = Ember.DefaultResolver.extend({
normalize: function(fullName) {
var split = fullName.split(':');
if (split.length > 1) {
var discourseBase = 'discourse/' + split[0] + 's/';
var adminBase = 'admin/' + split[0] + 's/';
// Try slashes
var dashed = Ember.String.dasherize(split[1].replace(/\./g, '/')),
moduleName = 'discourse/' + split[0] + 's/' + dashed;
if (requirejs.entries[moduleName]) { return split[0] + ":" + dashed; }
var dashed = Ember.String.dasherize(split[1].replace(/\./g, '/'));
if (requirejs.entries[discourseBase + dashed] || requirejs.entries[adminBase + dashed]) {
return split[0] + ":" + dashed;
}
// Try with dashes instead of slashes
dashed = Ember.String.dasherize(split[1].replace(/\./g, '-'));
moduleName = 'discourse/' + split[0] + 's/' + dashed;
if (requirejs.entries[moduleName]) { return split[0] + ":" + dashed; }
if (requirejs.entries[discourseBase + dashed] || requirejs.entries[adminBase + dashed]) {
return split[0] + ":" + dashed;
}
}
return this._super(fullName);
},

View File

@ -1,29 +1,29 @@
module("Discourse.AdminBadgesController");
module("controller:admin-badges");
test("canEditDescription", function() {
var badge, controller;
badge = Discourse.Badge.create({id: 101, name: "Test Badge"});
controller = testController(Discourse.AdminBadgesController, [badge]);
controller = testController("admin-badges", [badge]);
controller.send('selectBadge', badge);
ok(controller.get('canEditDescription'), "allows editing description when a translation exists for the badge name");
this.stub(I18n, "t").returns("translated string");
badge = Discourse.Badge.create({id: 102, name: "Test Badge"});
controller = testController(Discourse.AdminBadgesController, [badge]);
controller = testController("admin-badges", [badge]);
controller.send('selectBadge', badge);
ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name");
});
test("createNewBadge", function() {
var controller = testController(Discourse.AdminBadgesController, []);
var controller = testController("admin-badges", []);
controller.send('createNewBadge');
equal(controller.get('model.length'), 1, "adds a new badge to the list of badges");
});
test("selectBadge", function() {
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
controller = testController(Discourse.AdminBadgesController, [badge]);
controller = testController("admin-badges", [badge]);
controller.send('selectBadge', badge);
equal(controller.get('selectedItem'), badge, "the badge is selected");
@ -32,7 +32,7 @@ test("selectBadge", function() {
test("save", function() {
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]);
controller = testController("admin-badges", [badge, otherBadge]);
controller.send('selectBadge', badge);
this.stub(badge, "save").returns(Ember.RSVP.resolve({}));
@ -43,7 +43,7 @@ test("save", function() {
test("destroy", function() {
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]);
controller = testController("admin-badges", [badge, otherBadge]);
this.stub(badge, 'destroy').returns(Ember.RSVP.resolve({}));

View File

@ -1,5 +1,5 @@
module("Discourse.AdminEmailIndexController");
module("controller:admin-email-index");
test("mixes in Discourse.Presence", function() {
ok(Discourse.Presence.detect(Discourse.AdminEmailIndexController.create()));
ok(Discourse.Presence.detect(controllerFor("admin-email-index")));
});

View File

@ -1,5 +1,5 @@
module("Discourse.AdminEmailPreviewDigestController");
module("controller:admin-email-preview-digest");
test("mixes in Discourse.Presence", function() {
ok(Discourse.Presence.detect(Discourse.AdminEmailPreviewDigestController.create()));
ok(Discourse.Presence.detect(controllerFor("admin-email-preview-digest")));
});

View File

@ -1,4 +1,4 @@
module("Discourse.AdminSiteSettingsController", {
module("controller:admin-site-settings", {
setup: function() {
sinon.stub(Ember.run, "debounce").callsArg(1);
},
@ -16,7 +16,7 @@ test("filter", function() {
nameKey: 'posting', name: 'posting',
siteSettings: [Discourse.SiteSetting.create({"setting":"display_name_on_posts","description":"x","default":false,"type":"bool","value":"true","category":"posting"})]
})]);
var adminSiteSettingsController = testController(Discourse.AdminSiteSettingsController, allSettings);
var adminSiteSettingsController = testController("admin-site-settings", allSettings);
adminSiteSettingsController.set('allSiteSettings', allSettings);
equal(adminSiteSettingsController.get('content')[0].nameKey, 'users', "Can get first site setting category's name key.");

View File

@ -27,8 +27,18 @@ function integration(name, lifecycle) {
function testController(klass, model) {
// HAX until we get ES6 everywhere:
if (typeof klass === "string") {
var moduleName = 'discourse/controllers/' + klass,
module = requirejs.entries[moduleName];
var base = "discourse",
moduleName,
module;
// maybe a bit too hacky? (all of the "admin-*" controllers are in the "admin" directory)
if (klass.indexOf("admin") == 0) {
base = "admin";
}
moduleName = base + '/controllers/' + klass;
module = requirejs.entries[moduleName];
if (module) {
klass = require(moduleName, null, null, true).default;
}