REFACTOR: support booting discourse with DISCOURSE_NO_CONSTANTS

This change is discussed here: https://meta.discourse.org/t/deprecating-es6-compatibility-layer/35821

Prior to this change we were not booting correctly with DISCOURSE_NO_CONSTANTS
This commit is contained in:
Sam 2015-11-21 00:14:50 +11:00
parent f5b34d5f53
commit c0b277d273
98 changed files with 380 additions and 379 deletions

View File

@ -1,3 +1,5 @@
import AdminUser from 'admin/models/admin-user';
export default Ember.Component.extend({
classNames: ["ip-lookup"],
@ -42,7 +44,7 @@ export default Ember.Component.extend({
self.set("totalOthersWithSameIP", result.total);
});
Discourse.AdminUser.findAll("active", data).then(function (users) {
AdminUser.findAll("active", data).then(function (users) {
self.setProperties({
other_accounts: users,
otherAccountsLoading: false,

View File

@ -1,3 +1,5 @@
import Permalink from 'admin/models/permalink';
export default Ember.Component.extend({
classNames: ['permalink-form'],
formSubmitted: false,
@ -21,12 +23,12 @@ export default Ember.Component.extend({
if (!this.get('formSubmitted')) {
const self = this;
self.set('formSubmitted', true);
const permalink = Discourse.Permalink.create({url: self.get('url'), permalink_type: self.get('permalinkType'), permalink_type_value: self.get('permalink_type_value')});
const permalink = Permalink.create({url: self.get('url'), permalink_type: self.get('permalinkType'), permalink_type_value: self.get('permalink_type_value')});
permalink.save().then(function(result) {
self.set('url', '');
self.set('permalink_type_value', '');
self.set('formSubmitted', false);
self.sendAction('action', Discourse.Permalink.create(result.permalink));
self.sendAction('action', Permalink.create(result.permalink));
Em.run.schedule('afterRender', function() { self.$('.permalink-url').focus(); });
}, function(e) {
self.set('formSubmitted', false);

View File

@ -10,7 +10,7 @@
uploadText="UPLOAD"
}}
**/
Discourse.ResumableUploadComponent = Ember.Component.extend(Discourse.StringBuffer, {
const ResumableUploadComponent = Ember.Component.extend(Discourse.StringBuffer, {
tagName: "button",
classNames: ["btn", "ru"],
classNameBindings: ["isUploading"],
@ -118,3 +118,5 @@ Discourse.ResumableUploadComponent = Ember.Component.extend(Discourse.StringBuff
}.on("willDestroyElement")
});
export default ResumableUploadComponent;

View File

@ -1,3 +1,4 @@
import ScreenedIpAddress from 'admin/models/screened_ip_address';
/**
A form to create an IP address that will be blocked or whitelisted.
Example usage:
@ -13,7 +14,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.ScreenedIpAddressFormComponent = Ember.Component.extend({
const ScreenedIpAddressFormComponent = Ember.Component.extend({
classNames: ['screened-ip-address-form'],
formSubmitted: false,
actionName: 'block',
@ -42,11 +43,11 @@ Discourse.ScreenedIpAddressFormComponent = Ember.Component.extend({
if (!this.get('formSubmitted')) {
var self = this;
this.set('formSubmitted', true);
var screenedIpAddress = Discourse.ScreenedIpAddress.create({ip_address: this.get('ip_address'), action_name: this.get('actionName')});
var screenedIpAddress = ScreenedIpAddress.create({ip_address: this.get('ip_address'), action_name: this.get('actionName')});
screenedIpAddress.save().then(function(result) {
self.set('ip_address', '');
self.set('formSubmitted', false);
self.sendAction('action', Discourse.ScreenedIpAddress.create(result.screened_ip_address));
self.sendAction('action', ScreenedIpAddress.create(result.screened_ip_address));
Em.run.schedule('afterRender', function() { self.$('.ip-address-input').focus(); });
}, function(e) {
self.set('formSubmitted', false);
@ -74,3 +75,5 @@ Discourse.ScreenedIpAddressFormComponent = Ember.Component.extend({
});
}
});
export default ScreenedIpAddressFormComponent;

View File

@ -1,3 +1,5 @@
import ApiKey from 'admin/models/api-key';
/**
This controller supports the interface for dealing with API keys
@ -16,7 +18,7 @@ export default Ember.ArrayController.extend({
**/
generateMasterKey: function() {
var self = this;
Discourse.ApiKey.generateMasterKey().then(function (key) {
ApiKey.generateMasterKey().then(function (key) {
self.get('model').pushObject(key);
});
},
@ -25,7 +27,7 @@ export default Ember.ArrayController.extend({
Creates an API key instance with internal user object
@method regenerateKey
@param {Discourse.ApiKey} key the key to regenerate
@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) {
@ -39,7 +41,7 @@ export default Ember.ArrayController.extend({
Revokes an API key
@method revokeKey
@param {Discourse.ApiKey} key the key to revoke
@param {ApiKey} key the key to revoke
**/
revokeKey: function(key) {
var self = this;

View File

@ -1,4 +1,5 @@
import { setting } from 'discourse/lib/computed';
import AdminDashboard from 'admin/models/admin-dashboard';
// This controller supports the default interface when you enter the admin section.
export default Ember.Controller.extend({
@ -26,7 +27,7 @@ export default Ember.Controller.extend({
this.set('loadingProblems', true);
this.set('problemsFetchedAt', new Date());
var c = this;
Discourse.AdminDashboard.fetchProblems().then(function(d) {
AdminDashboard.fetchProblems().then(function(d) {
c.set('problems', d.problems);
c.set('loadingProblems', false);
if( d.problems && d.problems.length > 0 ) {

View File

@ -1,3 +1,5 @@
import EmailPreview from 'admin/models/email-preview';
export default Ember.Controller.extend({
actions: {
@ -5,7 +7,7 @@ export default Ember.Controller.extend({
const model = this.get('model');
this.set('loading', true);
Discourse.EmailPreview.findDigest(this.get('lastSeen'), this.get('username')).then(email => {
EmailPreview.findDigest(this.get('lastSeen'), this.get('username')).then(email => {
model.setProperties(email.getProperties('html_content', 'text_content'));
this.set('loading', false);
});

View File

@ -1,10 +1,11 @@
import debounce from 'discourse/lib/debounce';
import EmailLog from 'admin/models/email-log';
export default Ember.Controller.extend({
filterEmailLogs: debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
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

@ -1,9 +1,10 @@
import debounce from 'discourse/lib/debounce';
import EmailLog from 'admin/models/email-log';
export default Ember.Controller.extend({
filterEmailLogs: debounce(function() {
var self = this;
Discourse.EmailLog.findAll(this.get("filter")).then(function(logs) {
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

@ -1,3 +1,5 @@
import FlaggedPost from 'admin/models/flagged-post';
export default Ember.ArrayController.extend({
query: null,
@ -30,7 +32,7 @@ export default Ember.ArrayController.extend({
loadMore(){
var flags = this.get("model");
return Discourse.FlaggedPost.findAll(this.get("query"),flags.length+1).then(function(data){
return FlaggedPost.findAll(this.get("query"),flags.length+1).then(function(data){
if(data.length===0){
flags.set("allLoaded",true);
}

View File

@ -1,5 +1,6 @@
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({
loading: false,
@ -20,7 +21,7 @@ export default Ember.ArrayController.extend({
show() {
var self = this;
self.set('loading', true);
Discourse.ScreenedEmail.findAll().then(function(result) {
ScreenedEmail.findAll().then(function(result) {
self.set('model', result);
self.set('loading', false);
});

View File

@ -1,6 +1,7 @@
import debounce from 'discourse/lib/debounce';
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({
loading: false,
@ -10,7 +11,7 @@ export default Ember.ArrayController.extend({
show: debounce(function() {
var self = this;
self.set('loading', true);
Discourse.ScreenedIpAddress.findAll(this.get("filter")).then(function(result) {
ScreenedIpAddress.findAll(this.get("filter")).then(function(result) {
self.set('model', result);
self.set('loading', false);
});
@ -26,7 +27,7 @@ export default Ember.ArrayController.extend({
return bootbox.confirm(I18n.t("admin.logs.screened_ips.roll_up_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function (confirmed) {
if (confirmed) {
self.set("loading", true);
return Discourse.ScreenedIpAddress.rollUp().then(function(results) {
return ScreenedIpAddress.rollUp().then(function(results) {
if (results && results.subnets) {
if (results.subnets.length > 0) {
self.send("show");

View File

@ -1,5 +1,6 @@
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({
loading: false,
@ -7,7 +8,7 @@ export default Ember.ArrayController.extend({
show() {
const self = this;
self.set('loading', true);
Discourse.ScreenedUrl.findAll().then(function(result) {
ScreenedUrl.findAll().then(function(result) {
self.set('model', result);
self.set('loading', false);
});

View File

@ -1,5 +1,6 @@
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({
loading: false,
@ -36,7 +37,7 @@ export default Ember.ArrayController.extend({
});
this.set('filterCount', count);
Discourse.StaffActionLog.findAll(params).then(function(result) {
StaffActionLog.findAll(params).then(function(result) {
self.set('model', result);
}).finally(function() {
self.set('loading', false);

View File

@ -1,4 +1,5 @@
import debounce from 'discourse/lib/debounce';
import Permalink from 'admin/models/permalink';
export default Ember.ArrayController.extend({
loading: false,
@ -7,7 +8,7 @@ export default Ember.ArrayController.extend({
show: debounce(function() {
var self = this;
self.set('loading', true);
Discourse.Permalink.findAll(self.get("filter")).then(function(result) {
Permalink.findAll(self.get("filter")).then(function(result) {
self.set('model', result);
self.set('loading', false);
});

View File

@ -1,5 +1,6 @@
import debounce from 'discourse/lib/debounce';
import { i18n } from 'discourse/lib/computed';
import AdminUser from 'admin/models/admin-user';
export default Ember.ArrayController.extend({
query: null,
@ -42,7 +43,7 @@ export default Ember.ArrayController.extend({
var self = this;
this.set('refreshing', true);
Discourse.AdminUser.findAll(this.get('query'), { filter: this.get('listFilter'), show_emails: this.get('showEmails') }).then(function (result) {
AdminUser.findAll(this.get('query'), { filter: this.get('listFilter'), show_emails: this.get('showEmails') }).then(function (result) {
self.set('model', result);
}).finally(function() {
self.set('refreshing', false);
@ -51,14 +52,14 @@ export default Ember.ArrayController.extend({
actions: {
approveUsers: function() {
Discourse.AdminUser.bulkApprove(this.get('model').filterProperty('selected'));
AdminUser.bulkApprove(this.get('model').filterProperty('selected'));
this._refreshUsers();
},
rejectUsers: function() {
var maxPostAge = this.siteSettings.delete_user_max_post_age;
var controller = this;
Discourse.AdminUser.bulkReject(this.get('model').filterProperty('selected')).then(function(result){
AdminUser.bulkReject(this.get('model').filterProperty('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

@ -1,4 +1,5 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import Backup from 'admin/models/backup';
export default Ember.Controller.extend(ModalFunctionality, {
needs: ["adminBackupsLogs"],
@ -6,7 +7,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
_startBackup: function (withUploads) {
var self = this;
Discourse.User.currentProp("hideReadOnlyAlert", true);
Discourse.Backup.start(withUploads).then(function() {
Backup.start(withUploads).then(function() {
self.get("controllers.adminBackupsLogs").clear();
self.send("backupStarted");
});

View File

@ -1,15 +1,7 @@
/**
A model that stores all or some data that is displayed on the dashboard.
@class AdminDashboard
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
const AdminDashboard = Discourse.Model.extend({});
Discourse.AdminDashboard = Discourse.Model.extend({});
Discourse.AdminDashboard.reopenClass({
AdminDashboard.reopenClass({
/**
Fetch all dashboard data. This can be an expensive request when the cached data
@ -20,7 +12,7 @@ Discourse.AdminDashboard.reopenClass({
**/
find: function() {
return Discourse.ajax("/admin/dashboard.json").then(function(json) {
var model = Discourse.AdminDashboard.create(json);
var model = AdminDashboard.create(json);
model.set('loaded', true);
return model;
});
@ -38,9 +30,11 @@ Discourse.AdminDashboard.reopenClass({
type: 'GET',
dataType: 'json'
}).then(function(json) {
var model = Discourse.AdminDashboard.create(json);
var model = AdminDashboard.create(json);
model.set('loaded', true);
return model;
});
}
});
export default AdminDashboard;

View File

@ -1,17 +1,20 @@
import { propertyNotEqual } from 'discourse/lib/computed';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import ApiKey from 'admin/models/api-key';
import Group from 'discourse/models/group';
import TL3Requirements from 'admin/models/tl3-requirements';
const AdminUser = Discourse.User.extend({
customGroups: Em.computed.filter("groups", (g) => !g.automatic && Discourse.Group.create(g)),
automaticGroups: Em.computed.filter("groups", (g) => g.automatic && Discourse.Group.create(g)),
customGroups: Em.computed.filter("groups", (g) => !g.automatic && Group.create(g)),
automaticGroups: Em.computed.filter("groups", (g) => g.automatic && Group.create(g)),
generateApiKey() {
const self = this;
return Discourse.ajax("/admin/users/" + this.get('id') + "/generate_api_key", {
type: 'POST'
}).then(function (result) {
const apiKey = Discourse.ApiKey.create(result.api_key);
const apiKey = ApiKey.create(result.api_key);
self.set('api_key', apiKey);
return apiKey;
});
@ -377,7 +380,7 @@ const AdminUser = Discourse.User.extend({
}
}
}).catch(function() {
Discourse.AdminUser.find( user.get('username') ).then(function(u){ user.setProperties(u); });
AdminUser.find( user.get('username') ).then(function(u){ user.setProperties(u); });
bootbox.alert(I18n.t("admin.user.delete_failed"));
});
};
@ -450,7 +453,7 @@ const AdminUser = Discourse.User.extend({
if (user.get('loadedDetails')) { return Ember.RSVP.resolve(user); }
return Discourse.AdminUser.find(user.get('username_lower')).then(function (result) {
return AdminUser.find(user.get('username_lower')).then(function (result) {
user.setProperties(result);
user.set('loadedDetails', true);
});
@ -458,19 +461,19 @@ const AdminUser = Discourse.User.extend({
tl3Requirements: function() {
if (this.get('tl3_requirements')) {
return Discourse.TL3Requirements.create(this.get('tl3_requirements'));
return TL3Requirements.create(this.get('tl3_requirements'));
}
}.property('tl3_requirements'),
suspendedBy: function() {
if (this.get('suspended_by')) {
return Discourse.AdminUser.create(this.get('suspended_by'));
return AdminUser.create(this.get('suspended_by'));
}
}.property('suspended_by'),
approvedBy: function() {
if (this.get('approved_by')) {
return Discourse.AdminUser.create(this.get('approved_by'));
return AdminUser.create(this.get('approved_by'));
}
}.property('approved_by')
@ -511,7 +514,7 @@ AdminUser.reopenClass({
find(username) {
return Discourse.ajax("/admin/users/" + username + ".json").then(function (result) {
result.loadedDetails = true;
return Discourse.AdminUser.create(result);
return AdminUser.create(result);
});
},
@ -519,7 +522,7 @@ AdminUser.reopenClass({
return Discourse.ajax("/admin/users/list/" + query + ".json", {
data: filter
}).then(function(users) {
return users.map((u) => Discourse.AdminUser.create(u));
return users.map((u) => AdminUser.create(u));
});
}
});

View File

@ -1,12 +1,4 @@
/**
Our data model for representing an API key in the system
@class ApiKey
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.ApiKey = Discourse.Model.extend({
const ApiKey = Discourse.Model.extend({
/**
Regenerates the api key
@ -34,19 +26,20 @@ Discourse.ApiKey = Discourse.Model.extend({
});
Discourse.ApiKey.reopenClass({
ApiKey.reopenClass({
/**
Creates an API key instance with internal user object
@method create
@param {...} var_args the properties to initialize this with
@returns {Discourse.ApiKey} the ApiKey instance
@returns {ApiKey} the ApiKey instance
**/
create: function() {
const AdminUser = require('admin/models/admin-user').default;
var result = this._super.apply(this, arguments);
if (result.user) {
result.user = Discourse.AdminUser.create(result.user);
result.user = AdminUser.create(result.user);
}
return result;
},
@ -55,12 +48,12 @@ Discourse.ApiKey.reopenClass({
Finds a list of API keys
@method find
@returns {Promise} a promise that resolves to the array of `Discourse.ApiKey` instances
@returns {Promise} a promise that resolves to the array of `ApiKey` instances
**/
find: function() {
return Discourse.ajax("/admin/api").then(function(keys) {
return keys.map(function (key) {
return Discourse.ApiKey.create(key);
return ApiKey.create(key);
});
});
},
@ -69,12 +62,14 @@ Discourse.ApiKey.reopenClass({
Generates a master api key and returns it.
@method generateMasterKey
@returns {Promise} a promise that resolves to a master `Discourse.ApiKey`
@returns {Promise} a promise that resolves to a master `ApiKey`
**/
generateMasterKey: function() {
return Discourse.ajax("/admin/api/key", {type: 'POST'}).then(function (result) {
return Discourse.ApiKey.create(result.api_key);
return ApiKey.create(result.api_key);
});
}
});
export default ApiKey;

View File

@ -1,13 +1,4 @@
/**
Our data model for a color within a color scheme.
(It's a funny name for a class, but Color seemed too generic for what this class is.)
@class ColorSchemeColor
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.ColorSchemeColor = Discourse.Model.extend({
const ColorSchemeColor = Discourse.Model.extend({
init: function() {
this._super();
@ -78,3 +69,5 @@ Discourse.ColorSchemeColor = Discourse.Model.extend({
return this.get('hex').match(/^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/) !== null;
}.property('hex')
});
export default ColorSchemeColor;

View File

@ -1,12 +1,6 @@
/**
Our data model for a color scheme.
import ColorSchemeColor from 'admin/models/color-scheme-color';
@class ColorScheme
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
init: function() {
this._super();
@ -25,9 +19,9 @@ Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
},
copy: function() {
var newScheme = Discourse.ColorScheme.create({name: this.get('name'), enabled: false, can_edit: true, colors: Em.A()});
var newScheme = ColorScheme.create({name: this.get('name'), enabled: false, can_edit: true, colors: Em.A()});
_.each(this.get('colors'), function(c){
newScheme.colors.pushObject(Discourse.ColorSchemeColor.create({name: c.get('name'), hex: c.get('hex'), default_hex: c.get('default_hex')}));
newScheme.colors.pushObject(ColorSchemeColor.create({name: c.get('name'), hex: c.get('hex'), default_hex: c.get('default_hex')}));
});
return newScheme;
},
@ -109,17 +103,17 @@ var ColorSchemes = Ember.ArrayProxy.extend({
}.observes('selectedItem')
});
Discourse.ColorScheme.reopenClass({
ColorScheme.reopenClass({
findAll: function() {
var colorSchemes = ColorSchemes.create({ content: [], loading: true });
Discourse.ajax('/admin/color_schemes').then(function(all) {
_.each(all, function(colorScheme){
colorSchemes.pushObject(Discourse.ColorScheme.create({
colorSchemes.pushObject(ColorScheme.create({
id: colorScheme.id,
name: colorScheme.name,
enabled: colorScheme.enabled,
is_base: colorScheme.is_base,
colors: colorScheme.colors.map(function(c) { return Discourse.ColorSchemeColor.create({name: c.name, hex: c.hex, default_hex: c.default_hex}); })
colors: colorScheme.colors.map(function(c) { return ColorSchemeColor.create({name: c.name, hex: c.hex, default_hex: c.default_hex}); })
}));
});
colorSchemes.set('loading', false);
@ -127,3 +121,5 @@ Discourse.ColorScheme.reopenClass({
return colorSchemes;
}
});
export default ColorScheme;

View File

@ -1,20 +1,14 @@
/**
Our data model for representing an email log.
import AdminUser from 'admin/models/admin-user';
@class EmailLog
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.EmailLog = Discourse.Model.extend({});
const EmailLog = Discourse.Model.extend({});
Discourse.EmailLog.reopenClass({
EmailLog.reopenClass({
create: function(attrs) {
attrs = attrs || {};
if (attrs.user) {
attrs.user = Discourse.AdminUser.create(attrs.user);
attrs.user = AdminUser.create(attrs.user);
}
return this._super(attrs);
@ -27,10 +21,10 @@ Discourse.EmailLog.reopenClass({
return Discourse.ajax("/admin/email/" + status + ".json", { data: filter }).then(function(logs) {
return _.map(logs, function (log) {
return Discourse.EmailLog.create(log);
return EmailLog.create(log);
});
});
}
});
export default EmailLog;

View File

@ -1,14 +1,6 @@
/**
Our data model for showing a preview of an email
const EmailPreview = Discourse.Model.extend({});
@class EmailPreview
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.EmailPreview = Discourse.Model.extend({});
Discourse.EmailPreview.reopenClass({
EmailPreview.reopenClass({
findDigest: function(lastSeenAt, username) {
if (Em.isEmpty(lastSeenAt)) {
@ -22,7 +14,9 @@ Discourse.EmailPreview.reopenClass({
return Discourse.ajax("/admin/email/preview-digest.json", {
data: { last_seen_at: lastSeenAt, username: username }
}).then(function (result) {
return Discourse.EmailPreview.create(result);
return EmailPreview.create(result);
});
}
});
export default EmailPreview;

View File

@ -0,0 +1,11 @@
const EmailSettings = Discourse.Model.extend({});
EmailSettings.reopenClass({
find: function() {
return Discourse.ajax("/admin/email.json").then(function (settings) {
return EmailSettings.create(settings);
});
}
});
export default EmailSettings;

View File

@ -1,17 +0,0 @@
/**
Our data model for representing the current email settings
@class EmailSettings
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.EmailSettings = Discourse.Model.extend({});
Discourse.EmailSettings.reopenClass({
find: function() {
return Discourse.ajax("/admin/email.json").then(function (settings) {
return Discourse.EmailSettings.create(settings);
});
}
});

View File

@ -1,12 +1,9 @@
/**
Our data model for interacting with flagged posts.
import AdminUser from 'admin/models/admin-user';
import Topic from 'discourse/models/topic';
import Post from 'discourse/models/post';
@class FlaggedPost
@extends Discourse.Post
@namespace Discourse
@module Discourse
**/
Discourse.FlaggedPost = Discourse.Post.extend({
const FlaggedPost = Post.extend({
summary: function () {
return _(this.post_actions)
@ -140,7 +137,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
});
Discourse.FlaggedPost.reopenClass({
FlaggedPost.reopenClass({
findAll: function (filter, offset) {
offset = offset || 0;
@ -151,18 +148,18 @@ Discourse.FlaggedPost.reopenClass({
// users
var userLookup = {};
_.each(data.users, function (user) {
userLookup[user.id] = Discourse.AdminUser.create(user);
userLookup[user.id] = AdminUser.create(user);
});
// topics
var topicLookup = {};
_.each(data.topics, function (topic) {
topicLookup[topic.id] = Discourse.Topic.create(topic);
topicLookup[topic.id] = Topic.create(topic);
});
// posts
_.each(data.posts, function (post) {
var f = Discourse.FlaggedPost.create(post);
var f = FlaggedPost.create(post);
f.userLookup = userLookup;
f.topicLookup = topicLookup;
result.pushObject(f);
@ -174,3 +171,5 @@ Discourse.FlaggedPost.reopenClass({
});
}
});
export default FlaggedPost;

View File

@ -14,7 +14,7 @@ const Permalink = Discourse.Model.extend({
Permalink.reopenClass({
findAll: function(filter) {
return Discourse.ajax("/admin/permalinks.json", { data: { filter: filter } }).then(function(permalinks) {
return permalinks.map(p => Discourse.Permalink.create(p));
return permalinks.map(p => Permalink.create(p));
});
}
});

View File

@ -1,13 +1,4 @@
/**
Represents an email address that is watched for during account registration,
and an action is taken.
@class ScreenedEmail
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.ScreenedEmail = Discourse.Model.extend({
const ScreenedEmail = Discourse.Model.extend({
actionName: function() {
return I18n.t("admin.logs.screened_actions." + this.get('action'));
}.property('action'),
@ -17,12 +8,14 @@ Discourse.ScreenedEmail = Discourse.Model.extend({
}
});
Discourse.ScreenedEmail.reopenClass({
ScreenedEmail.reopenClass({
findAll: function() {
return Discourse.ajax("/admin/logs/screened_emails.json").then(function(screened_emails) {
return screened_emails.map(function(b) {
return Discourse.ScreenedEmail.create(b);
return ScreenedEmail.create(b);
});
});
}
});
export default ScreenedEmail;

View File

@ -1,8 +1,4 @@
/**
Represents an IP address that is watched for during account registration
(and possibly other times), and an action is taken.
**/
Discourse.ScreenedIpAddress = Discourse.Model.extend({
const ScreenedIpAddress = Discourse.Model.extend({
actionName: function() {
return I18n.t("admin.logs.screened_ips.actions." + this.get('action_name'));
}.property('action_name'),
@ -27,11 +23,11 @@ Discourse.ScreenedIpAddress = Discourse.Model.extend({
}
});
Discourse.ScreenedIpAddress.reopenClass({
ScreenedIpAddress.reopenClass({
findAll: function(filter) {
return Discourse.ajax("/admin/logs/screened_ip_addresses.json", { data: { filter: filter } }).then(function(screened_ips) {
return screened_ips.map(function(b) {
return Discourse.ScreenedIpAddress.create(b);
return ScreenedIpAddress.create(b);
});
});
},
@ -40,3 +36,5 @@ Discourse.ScreenedIpAddress.reopenClass({
return Discourse.ajax("/admin/logs/screened_ip_addresses/roll_up", { type: "POST" });
}
});
export default ScreenedIpAddress;

View File

@ -1,23 +1,17 @@
/**
Represents a URL that is watched for, and an action may be taken.
@class ScreenedUrl
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.ScreenedUrl = Discourse.Model.extend({
const ScreenedUrl = Discourse.Model.extend({
actionName: function() {
return I18n.t("admin.logs.screened_actions." + this.get('action'));
}.property('action')
});
Discourse.ScreenedUrl.reopenClass({
ScreenedUrl.reopenClass({
findAll: function() {
return Discourse.ajax("/admin/logs/screened_urls.json").then(function(screened_urls) {
return screened_urls.map(function(b) {
return Discourse.ScreenedUrl.create(b);
return ScreenedUrl.create(b);
});
});
}
});
export default ScreenedUrl;

View File

@ -35,7 +35,7 @@ SiteSetting.reopenClass({
if (!categories[s.category]) {
categories[s.category] = [];
}
categories[s.category].pushObject(Discourse.SiteSetting.create(s));
categories[s.category].pushObject(SiteSetting.create(s));
});
return Object.keys(categories).map(function(n) {

View File

@ -1,4 +1,6 @@
Discourse.StaffActionLog = Discourse.Model.extend({
import AdminUser from 'admin/models/admin-user';
const StaffActionLog = Discourse.Model.extend({
showFullDetails: false,
actionName: function() {
@ -39,15 +41,15 @@ Discourse.StaffActionLog = Discourse.Model.extend({
}.property('action_name')
});
Discourse.StaffActionLog.reopenClass({
StaffActionLog.reopenClass({
create: function(attrs) {
attrs = attrs || {};
if (attrs.acting_user) {
attrs.acting_user = Discourse.AdminUser.create(attrs.acting_user);
attrs.acting_user = AdminUser.create(attrs.acting_user);
}
if (attrs.target_user) {
attrs.target_user = Discourse.AdminUser.create(attrs.target_user);
attrs.target_user = AdminUser.create(attrs.target_user);
}
return this._super(attrs);
},
@ -55,8 +57,10 @@ Discourse.StaffActionLog.reopenClass({
findAll: function(filters) {
return Discourse.ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) {
return staff_actions.map(function(s) {
return Discourse.StaffActionLog.create(s);
return StaffActionLog.create(s);
});
});
}
});
export default StaffActionLog;

View File

@ -1,4 +1,4 @@
Discourse.TL3Requirements = Discourse.Model.extend({
const TL3Requirements = Discourse.Model.extend({
days_visited_percent: function() {
return ((this.get('days_visited') * 100) / this.get('time_period'));
}.property('days_visited', 'time_period'),
@ -38,3 +38,5 @@ Discourse.TL3Requirements = Discourse.Model.extend({
'num_likes_received_users', 'min_likes_received_users',
'trust_level_locked')
});
export default TL3Requirements;

View File

@ -1,12 +1,4 @@
/**
Our data model for determining whether there's a new version of Discourse
@class VersionCheck
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.VersionCheck = Discourse.Model.extend({
const VersionCheck = Discourse.Model.extend({
noCheckPerformed: function() {
return this.get('updated_at') === null;
@ -39,10 +31,12 @@ Discourse.VersionCheck = Discourse.Model.extend({
}.property('installed_sha')
});
Discourse.VersionCheck.reopenClass({
VersionCheck.reopenClass({
find: function() {
return Discourse.ajax('/admin/version_check').then(function(json) {
return Discourse.VersionCheck.create(json);
return VersionCheck.create(json);
});
}
});
export default VersionCheck;

View File

@ -1,5 +1,7 @@
import ApiKey from 'admin/models/api-key';
export default Ember.Route.extend({
model() {
return Discourse.ApiKey.find();
return ApiKey.find();
}
});

View File

@ -1,5 +1,7 @@
import Backup from 'admin/models/backup';
export default Ember.Route.extend({
model() {
return Discourse.Backup.find();
return Backup.find();
}
});

View File

@ -1,4 +1,6 @@
import showModal from 'discourse/lib/show-modal';
import BackupStatus from 'admin/models/backup-status';
import Backup from 'admin/models/backup';
const LOG_CHANNEL = "/admin/backups/logs";
@ -31,7 +33,7 @@ export default Discourse.Route.extend({
return PreloadStore.getAndRemove("operations_status", function() {
return Discourse.ajax("/admin/backups/status.json");
}).then(status => {
return Discourse.BackupStatus.create({
return BackupStatus.create({
isOperationRunning: status.is_operation_running,
canRollback: status.can_rollback,
allowRestore: status.allow_restore
@ -98,7 +100,7 @@ export default Discourse.Route.extend({
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
Discourse.Backup.cancel().then(function() {
Backup.cancel().then(function() {
self.controllerFor("adminBackups").set("model.isOperationRunning", false);
});
}
@ -112,7 +114,7 @@ export default Discourse.Route.extend({
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) { Discourse.Backup.rollback(); }
if (confirmed) { Backup.rollback(); }
}
);
},
@ -120,7 +122,7 @@ export default Discourse.Route.extend({
uploadSuccess(filename) {
const self = this;
bootbox.alert(I18n.t("admin.backups.upload.success", { filename: filename }), function() {
Discourse.Backup.find().then(function (backups) {
Backup.find().then(function (backups) {
self.controllerFor("adminBackupsIndex").set("model", backups);
});
});

View File

@ -1,7 +1,9 @@
import ColorScheme from 'admin/models/color-scheme';
export default Ember.Route.extend({
model() {
return Discourse.ColorScheme.findAll();
return ColorScheme.findAll();
},
deactivate() {

View File

@ -1,3 +1,8 @@
import AdminDashboard from 'admin/models/admin-dashboard';
import VersionCheck from 'admin/models/version-check';
import Report from 'admin/models/report';
import AdminUser from 'admin/models/admin-user';
export default Discourse.Route.extend({
setupController: function(c) {
@ -8,19 +13,19 @@ export default Discourse.Route.extend({
if( !c.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > c.get('dashboardFetchedAt') ) {
c.set('dashboardFetchedAt', new Date());
var versionChecks = this.siteSettings.version_checks;
Discourse.AdminDashboard.find().then(function(d) {
AdminDashboard.find().then(function(d) {
if (versionChecks) {
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
c.set('versionCheck', VersionCheck.create(d.version_check));
}
['global_reports', 'page_view_reports', 'private_message_reports', 'http_reports', 'user_reports', 'mobile_reports'].forEach(name => {
c.set(name, d[name].map(r => Discourse.Report.create(r)));
c.set(name, d[name].map(r => Report.create(r)));
});
var topReferrers = d.top_referrers;
if (topReferrers && topReferrers.data) {
d.top_referrers.data = topReferrers.data.map(function (user) {
return Discourse.AdminUser.create(user);
return AdminUser.create(user);
});
c.set('top_referrers', topReferrers);
}

View File

@ -0,0 +1,2 @@
import AdminEmailLogs from 'admin/routes/admin-email-logs';
export default AdminEmailLogs.extend({ status: "all" });

View File

@ -1,6 +1,8 @@
Discourse.AdminEmailIndexRoute = Discourse.Route.extend({
import EmailSettings from 'admin/models/email-settings';
export default Discourse.Route.extend({
model: function() {
return Discourse.EmailSettings.find();
return EmailSettings.find();
},
renderTemplate: function() {

View File

@ -1,3 +1,5 @@
import EmailLog from 'admin/models/email-log';
/**
Handles routes related to viewing email logs.
@ -6,10 +8,10 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminEmailLogsRoute = Discourse.Route.extend({
export default Discourse.Route.extend({
model: function() {
return Discourse.EmailLog.findAll({ status: this.get("status") });
return EmailLog.findAll({ status: this.get("status") });
},
setupController: function(controller, model) {
@ -23,7 +25,3 @@ Discourse.AdminEmailLogsRoute = Discourse.Route.extend({
}
});
Discourse.AdminEmailAllRoute = Discourse.AdminEmailLogsRoute.extend({ status: "all" });
Discourse.AdminEmailSentRoute = Discourse.AdminEmailLogsRoute.extend({ status: "sent" });
Discourse.AdminEmailSkippedRoute = Discourse.AdminEmailLogsRoute.extend({ status: "skipped" });

View File

@ -1,7 +1,9 @@
import EmailPreview from 'admin/models/email-preview';
export default Discourse.Route.extend({
model() {
return Discourse.EmailPreview.findDigest();
return EmailPreview.findDigest();
},
afterModel(model) {

View File

@ -0,0 +1,2 @@
import AdminEmailLogs from 'admin/routes/admin-email-logs';
export default AdminEmailLogs.extend({ status: "sent" });

View File

@ -0,0 +1,2 @@
import AdminEmailLogs from 'admin/routes/admin-email-logs';
export default AdminEmailLogs.extend({ status: "skipped" });

View File

@ -1,9 +1,10 @@
import showModal from 'discourse/lib/show-modal';
import FlaggedPost from 'admin/models/flagged-post';
export default Discourse.Route.extend({
model(params) {
this.filter = params.filter;
return Discourse.FlaggedPost.findAll(params.filter);
return FlaggedPost.findAll(params.filter);
},
setupController(controller, model) {

View File

@ -1,7 +1,9 @@
import Group from 'discourse/models/group';
export default Discourse.Route.extend({
model(params) {
this.set("type", params.type);
return Discourse.Group.findAll().then(function(groups) {
return Group.findAll().then(function(groups) {
return groups.filterBy("type", params.type);
});
},

View File

@ -0,0 +1,5 @@
export default Discourse.Route.extend({
redirect: function() {
this.transitionTo('adminLogs.staffActionLogs');
}
});

View File

@ -0,0 +1,9 @@
export default Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_emails', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedEmails').show();
}
});

View File

@ -0,0 +1,9 @@
export default Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedIpAddresses').show();
}
});

View File

@ -0,0 +1,9 @@
export default Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_urls', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedUrls').show();
}
});

View File

@ -1,6 +1,8 @@
import Permalink from 'admin/models/permalink';
export default Discourse.Route.extend({
model() {
return Discourse.Permalink.findAll();
return Permalink.findAll();
},
setupController(controller, model) {

View File

@ -6,7 +6,7 @@
@namespace Discourse
@module Discourse
**/
Discourse.AdminReportsRoute = Discourse.Route.extend({
export default Discourse.Route.extend({
model: function(params) {
return Discourse.Report.find(params.type);
},

View File

@ -1,4 +1,5 @@
import showModal from 'discourse/lib/show-modal';
import Group from 'discourse/models/group';
export default Discourse.Route.extend({
model() {
@ -8,7 +9,7 @@ export default Discourse.Route.extend({
afterModel(model) {
if (this.currentUser.get('admin')) {
const self = this;
return Discourse.Group.findAll().then(function(groups){
return Group.findAll().then(function(groups){
self._availableGroups = groups.filterBy('automatic', false);
return model;
});

View File

@ -0,0 +1,5 @@
export default Discourse.Route.extend({
model: function() {
return this.modelFor('adminUser');
}
});

View File

@ -1,10 +1,12 @@
import AdminUser from 'admin/models/admin-user';
export default Discourse.Route.extend({
serialize(model) {
return { username: model.get('username').toLowerCase() };
},
model(params) {
return Discourse.AdminUser.find(Em.get(params, 'username').toLowerCase());
return AdminUser.find(Em.get(params, 'username').toLowerCase());
},
renderTemplate() {

View File

@ -1,7 +1,9 @@
import AdminUser from 'admin/models/admin-user';
export default Discourse.Route.extend({
model: function(params) {
this.userFilter = params.filter;
return Discourse.AdminUser.findAll(params.filter);
return AdminUser.findAll(params.filter);
},
setupController: function(controller, model) {

View File

@ -1,5 +1,6 @@
import { exportEntity } from 'discourse/lib/export-csv';
import { outputExportResult } from 'discourse/lib/export-result';
import AdminUser from 'admin/models/admin-user';
export default Discourse.Route.extend({
@ -13,7 +14,7 @@ export default Discourse.Route.extend({
},
deleteUser: function(user) {
Discourse.AdminUser.create(user).destroy({ deletePosts: true });
AdminUser.create(user).destroy({ deletePosts: true });
}
}

View File

@ -1,67 +0,0 @@
/**
Index redirects to a default logs index.
@class AdminLogsIndexRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsIndexRoute = Discourse.Route.extend({
redirect: function() {
this.transitionTo('adminLogs.staffActionLogs');
}
});
/**
The route that lists blocked email addresses.
@class AdminLogsScreenedEmailsRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedEmailsRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_emails', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedEmails').show();
}
});
/**
The route that lists screened IP addresses.
@class AdminLogsScreenedIpAddresses
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedIpAddressesRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_ip_addresses', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedIpAddresses').show();
}
});
/**
The route that lists screened URLs.
@class AdminLogsScreenedUrlsRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminLogsScreenedUrlsRoute = Discourse.Route.extend({
renderTemplate: function() {
this.render('admin/templates/logs/screened_urls', {into: 'adminLogs'});
},
setupController: function() {
return this.controllerFor('adminLogsScreenedUrls').show();
}
});

View File

@ -1,14 +0,0 @@
/**
Shows all the requirements for being at trust level 3 and if the
given user is meeting them.
@class AdminUserLeaderRequirementsRoute
@extends Discourse.Route
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserTl3RequirementsRoute = Discourse.Route.extend({
model: function() {
return this.modelFor('adminUser');
}
});

View File

@ -0,0 +1,3 @@
export default Ember.View.extend({
templateName: 'admin/templates/customize_colors'
});

View File

@ -0,0 +1 @@
export default Ember.View.extend(Discourse.ScrollTop);

View File

@ -1,3 +0,0 @@
Discourse.AdminCustomizeColorsView = Ember.View.extend({
templateName: 'admin/templates/customize_colors'
});

View File

@ -1 +0,0 @@
Discourse.AdminUserView = Ember.View.extend(Discourse.ScrollTop);

View File

@ -3,6 +3,7 @@ import { queryParams } from 'discourse/controllers/discovery-sortable';
import BulkTopicSelection from 'discourse/mixins/bulk-topic-selection';
import { endWith } from 'discourse/lib/computed';
import showModal from 'discourse/lib/show-modal';
import TopicList from 'discourse/models/topic-list';
const controllerOpts = {
needs: ['discovery'],
@ -54,7 +55,7 @@ const controllerOpts = {
this.set('controllers.discovery.loading', true);
this.store.findFiltered('topicList', {filter}).then(list => {
Discourse.TopicList.hideUniformCategory(list, this.get('category'));
TopicList.hideUniformCategory(list, this.get('category'));
this.setProperties({ model: list });
this.resetSelected();

View File

@ -1,5 +1,6 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { MAX_MESSAGE_LENGTH } from 'discourse/models/post-action-type';
import AdminUser from 'admin/models/admin-user';
export default Ember.Controller.extend(ModalFunctionality, {
userDetails: null,
@ -124,7 +125,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
fetchUserDetails() {
if (Discourse.User.currentProp('staff') && this.get('model.username')) {
Discourse.AdminUser.find(this.get('model.username').toLowerCase())
AdminUser.find(this.get('model.username').toLowerCase())
.then(user => this.set('userDetails', user));
}
}

View File

@ -1,4 +1,5 @@
import { popupAjaxError } from 'discourse/lib/ajax-error';
import Group from 'discourse/models/group';
export default Ember.Controller.extend({
loading: false,
@ -35,7 +36,7 @@ export default Ember.Controller.extend({
this.set("loading", true);
Discourse.Group.loadMembers(this.get("model.name"), this.get("model.members.length"), this.get("limit")).then(result => {
Group.loadMembers(this.get("model.name"), this.get("model.members.length"), this.get("limit")).then(result => {
this.get("model.members").addObjects(result.members.map(member => Discourse.User.create(member)));
this.setProperties({
loading: false,

View File

@ -1,5 +1,6 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import Invite from 'discourse/models/invite';
import Group from 'discourse/models/group';
export default Ember.Controller.extend(ModalFunctionality, {
needs: ['user-invited-show'],
@ -108,7 +109,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
}.property('isPrivateTopic'),
groupFinder(term) {
return Discourse.Group.findAll({search: term, ignore_automatic: true});
return Group.findAll({search: term, ignore_automatic: true});
},
successMessage: function() {

View File

@ -95,6 +95,7 @@ export default Ember.Controller.extend({
},
quoteText() {
const Composer = require('discourse/models/composer').default;
const postId = this.get('postId');
const post = this.get('post');
@ -115,7 +116,7 @@ export default Ember.Controller.extend({
const composerController = this.get('controllers.composer');
const composerOpts = {
action: Discourse.Composer.REPLY,
action: Composer.REPLY,
draftKey: post.get('topic.draft_key')
};

View File

@ -5,6 +5,7 @@ import Topic from 'discourse/models/topic';
import Quote from 'discourse/lib/quote';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import computed from 'ember-addons/ember-computed-decorators';
import Composer from 'discourse/models/composer';
export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
needs: ['header', 'modal', 'composer', 'quote-button', 'topic-progress', 'application'],
@ -100,14 +101,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
quoteController.set('buffer', '');
if (composerController.get('content.topic.id') === topic.get('id') &&
composerController.get('content.action') === Discourse.Composer.REPLY) {
composerController.get('content.action') === Composer.REPLY) {
composerController.set('content.post', post);
composerController.set('content.composeState', Discourse.Composer.OPEN);
composerController.set('content.composeState', Composer.OPEN);
this.appEvents.trigger('composer:insert-text', quotedText.trim());
} else {
const opts = {
action: Discourse.Composer.REPLY,
action: Composer.REPLY,
draftKey: topic.get('draft_key'),
draftSequence: topic.get('draft_sequence')
};
@ -185,7 +186,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
composerModel = composer.get('model'),
opts = {
post: post,
action: Discourse.Composer.EDIT,
action: Composer.EDIT,
draftKey: post.get('topic.draft_key'),
draftSequence: post.get('topic.draft_sequence')
};
@ -389,8 +390,8 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
quoteController.deselectText();
composerController.open({
action: Discourse.Composer.CREATE_TOPIC,
draftKey: Discourse.Composer.REPLY_AS_NEW_TOPIC_KEY,
action: Composer.CREATE_TOPIC,
draftKey: Composer.REPLY_AS_NEW_TOPIC_KEY,
categoryId: this.get('category.id')
}).then(() => {
return Em.isEmpty(quotedText) ? Discourse.Post.loadQuote(post.get('id')) : quotedText;

View File

@ -1,4 +1,5 @@
import DiscourseURL from 'discourse/lib/url';
import Composer from 'discourse/models/composer';
const bindings = {
'!': {postAction: 'showFlags'},
@ -170,7 +171,7 @@ export default {
},
createTopic() {
this.container.lookup('controller:composer').open({action: Discourse.Composer.CREATE_TOPIC, draftKey: Discourse.Composer.CREATE_TOPIC});
this.container.lookup('controller:composer').open({action: Composer.CREATE_TOPIC, draftKey: Composer.CREATE_TOPIC});
},
pinUnpinTopic() {

View File

@ -1,4 +1,7 @@
import Topic from 'discourse/models/topic';
import Post from 'discourse/models/post';
import Category from 'discourse/models/category';
import User from 'discourse/models/user';
export function translateResults(results, opts) {
if (!opts) opts = {};
@ -17,18 +20,18 @@ export function translateResults(results, opts) {
});
results.posts = results.posts.map(function(post){
post = Discourse.Post.create(post);
post = Post.create(post);
post.set('topic', topicMap[post.topic_id]);
return post;
});
results.users = results.users.map(function(user){
user = Discourse.User.create(user);
user = User.create(user);
return user;
});
results.categories = results.categories.map(function(category){
return Discourse.Category.list().findProperty('id', category.id);
return Category.list().findProperty('id', category.id);
}).compact();
const r = results.grouped_search_result;

View File

@ -3,17 +3,19 @@
export default Ember.Mixin.create({
openComposer(controller) {
const Composer = require('discourse/models/composer').default;
this.controllerFor('composer').open({
categoryId: controller.get('category.id'),
action: Discourse.Composer.CREATE_TOPIC,
action: Composer.CREATE_TOPIC,
draftKey: controller.get('model.draft_key'),
draftSequence: controller.get('model.draft_sequence')
});
},
openComposerWithParams(controller, topicTitle, topicBody, topicCategoryId, topicCategory) {
const Composer = require('discourse/models/composer').default;
this.controllerFor('composer').open({
action: Discourse.Composer.CREATE_TOPIC,
action: Composer.CREATE_TOPIC,
topicTitle,
topicBody,
topicCategoryId,

View File

@ -93,7 +93,7 @@ const Badge = RestModel.extend({
Save and update the badge from the server's response.
@method save
@returns {Promise} A promise that resolves to the updated `Discourse.Badge`
@returns {Promise} A promise that resolves to the updated `Badge`
**/
save: function(data) {
let url = "/admin/badges",
@ -133,11 +133,11 @@ const Badge = RestModel.extend({
Badge.reopenClass({
/**
Create `Discourse.Badge` instances from the server JSON response.
Create `Badge` instances from the server JSON response.
@method createFromJson
@param {Object} json The JSON returned by the server
@returns Array or instance of `Discourse.Badge` depending on the input JSON
@returns Array or instance of `Badge` depending on the input JSON
**/
createFromJson: function(json) {
// Create BadgeType objects.
@ -163,7 +163,7 @@ Badge.reopenClass({
badges = json.badges;
}
badges = badges.map(function(badgeJson) {
const badge = Discourse.Badge.create(badgeJson);
const badge = Badge.create(badgeJson);
badge.set('badge_type', badgeTypes[badge.get('badge_type_id')]);
badge.set('badge_grouping', badgeGroupings[badge.get('badge_grouping_id')]);
return badge;
@ -177,10 +177,10 @@ Badge.reopenClass({
},
/**
Find all `Discourse.Badge` instances that have been defined.
Find all `Badge` instances that have been defined.
@method findAll
@returns {Promise} a promise that resolves to an array of `Discourse.Badge`
@returns {Promise} a promise that resolves to an array of `Badge`
**/
findAll: function(opts) {
let listable = "";
@ -188,20 +188,20 @@ Badge.reopenClass({
listable = "?only_listable=true";
}
return Discourse.ajax('/badges.json' + listable).then(function(badgesJson) {
return Discourse.Badge.createFromJson(badgesJson);
return Badge.createFromJson(badgesJson);
});
},
/**
Returns a `Discourse.Badge` that has the given ID.
Returns a `Badge` that has the given ID.
@method findById
@param {Number} id ID of the badge
@returns {Promise} a promise that resolves to a `Discourse.Badge`
@returns {Promise} a promise that resolves to a `Badge`
**/
findById: function(id) {
return Discourse.ajax("/badges/" + id).then(function(badgeJson) {
return Discourse.Badge.createFromJson(badgeJson);
return Badge.createFromJson(badgeJson);
});
}
});

View File

@ -7,7 +7,7 @@ const CategoryList = Ember.ArrayProxy.extend({
CategoryList.reopenClass({
categoriesFrom(store, result) {
const categories = Discourse.CategoryList.create();
const categories = CategoryList.create();
const users = Discourse.Model.extractByKey(result.featured_users, Discourse.User);
const list = Discourse.Category.list();
@ -35,7 +35,7 @@ CategoryList.reopenClass({
listForParent(store, category) {
return Discourse.ajax(`/categories.json?parent_category_id=${category.get("id")}`).then(result => {
return Discourse.CategoryList.create({
return CategoryList.create({
categories: this.categoriesFrom(store, result),
parentCategory: category
});
@ -45,7 +45,7 @@ CategoryList.reopenClass({
list(store) {
const getCategories = () => Discourse.ajax("/categories.json");
return PreloadStore.getAndRemove("categories_list", getCategories).then(result => {
return Discourse.CategoryList.create({
return CategoryList.create({
categories: this.categoriesFrom(store, result),
can_create_category: result.category_list.can_create_category,
can_create_topic: result.category_list.can_create_topic,

View File

@ -28,7 +28,7 @@ const Group = Discourse.Model.extend({
const self = this, offset = Math.min(this.get("user_count"), Math.max(this.get("offset"), 0));
return Discourse.Group.loadMembers(this.get("name"), offset, this.get("limit")).then(function (result) {
return Group.loadMembers(this.get("name"), offset, this.get("limit")).then(function (result) {
var ownerIds = {};
result.owners.forEach(owner => ownerIds[owner.id] = true);
@ -136,7 +136,7 @@ const Group = Discourse.Model.extend({
Group.reopenClass({
findAll(opts) {
return Discourse.ajax("/admin/groups.json", { data: opts }).then(function (groups){
return groups.map(g => Discourse.Group.create(g));
return groups.map(g => Group.create(g));
});
},
@ -145,7 +145,7 @@ Group.reopenClass({
},
find(name) {
return Discourse.ajax("/groups/" + name + ".json").then(result => Discourse.Group.create(result.basic_group));
return Discourse.ajax("/groups/" + name + ".json").then(result => Group.create(result.basic_group));
},
loadMembers(name, offset, limit) {

View File

@ -205,7 +205,7 @@ const PostStream = RestModel.extend({
opts = _.merge(opts, self.get('streamFilters'));
// Request a topicView
return Discourse.PostStream.loadTopicView(topic.get('id'), opts).then(function (json) {
return PostStream.loadTopicView(topic.get('id'), opts).then(function (json) {
topic.updateFromJson(json);
self.updateFromJson(json.post_stream);
self.setProperties({ loadingFilter: false, loaded: true });

View File

@ -132,7 +132,9 @@ const Post = RestModel.extend({
},
createProperties() {
const data = this.getProperties(Discourse.Composer.serializedFieldsForCreate());
// composer only used once, defer the dependency
const Composer = require('discourse/models/composer').default;
const data = this.getProperties(Composer.serializedFieldsForCreate());
data.reply_to_post_number = this.get('reply_to_post_number');
data.image_sizes = this.get('imageSizes');

View File

@ -52,7 +52,7 @@ UserBadge.reopenClass({
}
userBadges = userBadges.map(function(userBadgeJson) {
var userBadge = Discourse.UserBadge.create(userBadgeJson);
var userBadge = UserBadge.create(userBadgeJson);
var grantedAtDate = Date.parse(userBadge.get('granted_at'));
userBadge.set('grantedAt', grantedAtDate);
@ -83,7 +83,7 @@ UserBadge.reopenClass({
@method findByUsername
@param {String} username
@param {Object} options
@returns {Promise} a promise that resolves to an array of `Discourse.UserBadge`.
@returns {Promise} a promise that resolves to an array of `UserBadge`.
**/
findByUsername: function(username, options) {
var url = "/user-badges/" + username + ".json";
@ -91,7 +91,7 @@ UserBadge.reopenClass({
url += "?grouped=true";
}
return Discourse.ajax(url).then(function(json) {
return Discourse.UserBadge.createFromJson(json);
return UserBadge.createFromJson(json);
});
},
@ -100,7 +100,7 @@ UserBadge.reopenClass({
@method findById
@param {String} badgeId
@returns {Promise} a promise that resolves to an array of `Discourse.UserBadge`.
@returns {Promise} a promise that resolves to an array of `UserBadge`.
**/
findByBadgeId: function(badgeId, options) {
if (!options) { options = {}; }
@ -109,7 +109,7 @@ UserBadge.reopenClass({
return Discourse.ajax("/user_badges.json", {
data: options
}).then(function(json) {
return Discourse.UserBadge.createFromJson(json);
return UserBadge.createFromJson(json);
});
},
@ -119,7 +119,7 @@ UserBadge.reopenClass({
@method grant
@param {Integer} badgeId id of the badge to be granted.
@param {String} username username of the user to be granted the badge.
@returns {Promise} a promise that resolves to an instance of `Discourse.UserBadge`.
@returns {Promise} a promise that resolves to an instance of `UserBadge`.
**/
grant: function(badgeId, username, reason) {
return Discourse.ajax("/user_badges", {
@ -130,7 +130,7 @@ UserBadge.reopenClass({
reason: reason
}
}).then(function(json) {
return Discourse.UserBadge.createFromJson(json);
return UserBadge.createFromJson(json);
});
}
});

View File

@ -7,6 +7,9 @@ import { longDate } from 'discourse/lib/formatter';
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
import Badge from 'discourse/models/badge';
import UserBadge from 'discourse/models/user-badge';
import UserActionStat from 'discourse/models/user-action-stat';
import UserAction from 'discourse/models/user-action';
import Group from 'discourse/models/group';
const User = RestModel.extend({
@ -184,7 +187,7 @@ const User = RestModel.extend({
if ((this.get('stream.filter') || ua.action_type) !== ua.action_type) return;
if (!this.get('stream.filter') && !this.inAllStream(ua)) return;
const action = Discourse.UserAction.collapseStream([Discourse.UserAction.create(ua)]);
const action = UserAction.collapseStream([UserAction.create(ua)]);
stream.set('itemsLoaded', stream.get('itemsLoaded') + 1);
stream.get('content').insertAt(0, action[0]);
}
@ -192,8 +195,8 @@ const User = RestModel.extend({
},
inAllStream(ua) {
return ua.action_type === Discourse.UserAction.TYPES.posts ||
ua.action_type === Discourse.UserAction.TYPES.topics;
return ua.action_type === UserAction.TYPES.posts ||
ua.action_type === UserAction.TYPES.topics;
},
// The user's stat count, excluding PMs.
@ -226,12 +229,12 @@ const User = RestModel.extend({
if (!Em.isEmpty(json.user.stats)) {
json.user.stats = Discourse.User.groupStats(_.map(json.user.stats, s => {
if (s.count) s.count = parseInt(s.count, 10);
return Discourse.UserActionStat.create(s);
return UserActionStat.create(s);
}));
}
if (!Em.isEmpty(json.user.custom_groups)) {
json.user.custom_groups = json.user.custom_groups.map(g => Discourse.Group.create(g));
json.user.custom_groups = json.user.custom_groups.map(g => Group.create(g));
}
if (json.user.invited_by) {
@ -372,9 +375,9 @@ User.reopenClass(Singleton, {
},
groupStats(stats) {
const responses = Discourse.UserActionStat.create({
const responses = UserActionStat.create({
count: 0,
action_type: Discourse.UserAction.TYPES.replies
action_type: UserAction.TYPES.replies
});
stats.filterProperty('isResponse').forEach(stat => {
@ -386,7 +389,7 @@ User.reopenClass(Singleton, {
let insertAt = 0;
result.forEach((item, index) => {
if (item.action_type === Discourse.UserAction.TYPES.topics || item.action_type === Discourse.UserAction.TYPES.posts) {
if (item.action_type === UserAction.TYPES.topics || item.action_type === UserAction.TYPES.posts) {
insertAt = index + 1;
}
});

View File

@ -1,5 +1,6 @@
import { filterQueryParams, findTopicList } from 'discourse/routes/build-topic-route';
import { queryParams } from 'discourse/controllers/discovery-sortable';
import TopicList from 'discourse/models/topic-list';
// A helper function to create a category route with parameters
export default (filter, params) => {
@ -50,7 +51,7 @@ export default (filter, params) => {
extras = { cached: this.isPoppedState(transition) };
return findTopicList(this.store, this.topicTrackingState, listFilter, findOpts, extras).then(list => {
Discourse.TopicList.hideUniformCategory(list, category);
TopicList.hideUniformCategory(list, category);
this.set('topics', list);
return list;
});

View File

@ -1,3 +1,5 @@
import Composer from 'discourse/models/composer';
const DiscourseRoute = Ember.Route.extend({
// Set to true to refresh a model without a transition if a query param
@ -58,7 +60,7 @@ const DiscourseRoute = Ember.Route.extend({
const composer = this.controllerFor('composer');
if (!composer.get('model.viewOpen')) {
composer.open({
action: Discourse.Composer.CREATE_TOPIC,
action: Composer.CREATE_TOPIC,
draft: model.draft,
draftKey: model.draft_key,
draftSequence: model.draft_sequence

View File

@ -1,5 +1,6 @@
import showModal from "discourse/lib/show-modal";
import OpenComposer from "discourse/mixins/open-composer";
import CategoryList from "discourse/models/category-list";
const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, {
renderTemplate() {
@ -16,7 +17,7 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, {
// if default page is categories
PreloadStore.remove("topic_list");
return Discourse.CategoryList.list(this.store, 'categories').then(list => {
return CategoryList.list(this.store, 'categories').then(list => {
const tracking = this.topicTrackingState;
if (tracking) {
tracking.sync(list, "categories");

View File

@ -1,7 +1,9 @@
import Group from 'discourse/models/group';
export default Discourse.Route.extend({
model: function(params) {
return Discourse.Group.find(params.name);
return Group.find(params.name);
},
serialize: function(model) {
@ -10,7 +12,7 @@ export default Discourse.Route.extend({
afterModel: function(model) {
var self = this;
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
return Group.findGroupCounts(model.get('name')).then(function (counts) {
self.set('counts', counts);
});
},

View File

@ -97,7 +97,7 @@ const TopicRoute = Discourse.Route.extend({
// Use replaceState to update the URL once it changes
postChangedRoute(currentPost) {
// do nothing if we are transitioning to another route
if (isTransitioning || Discourse.TopicRoute.disableReplaceState) { return; }
if (isTransitioning || TopicRoute.disableReplaceState) { return; }
const topic = this.modelFor('topic');
if (topic && currentPost) {
@ -205,7 +205,7 @@ const TopicRoute = Discourse.Route.extend({
firstPostExpanded: false
});
Discourse.TopicRoute.trigger('setupTopicController', this);
TopicRoute.trigger('setupTopicController', this);
this.controllerFor('header').setProperties({ topic: model, showExtraInfo: false });
this.searchService.set('searchContext', model.get('searchContext'));

View File

@ -15,8 +15,10 @@ export default Discourse.Route.extend({
const recipient = user ? user.get('username') : '',
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null;
// used only once, one less dependency
const Composer = require('discourse/models/composer').default;
return this.controllerFor('composer').open({
action: Discourse.Composer.PRIVATE_MESSAGE,
action: Composer.PRIVATE_MESSAGE,
usernames: recipient,
archetypeId: 'private_message',
draftKey: 'new_private_message',

View File

@ -86,6 +86,8 @@ module Tilt
"discourse/models/user",
"discourse/models/session",
"discourse/models/model",
"discourse/models/topic",
"discourse/models/post",
"discourse/views/grouped"]
)

View File

@ -1,11 +1,13 @@
import { blank, present } from 'helpers/qunit-helpers';
import AdminUser from 'admin/models/admin-user';
import ApiKey from 'admin/models/api-key';
module("Discourse.AdminUser");
asyncTestDiscourse('generate key', function() {
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 1234, key: 'asdfasdf'}}));
var adminUser = Discourse.AdminUser.create({id: 333});
var adminUser = AdminUser.create({id: 333});
blank(adminUser.get('api_key'), 'it has no api key by default');
adminUser.generateApiKey().then(function() {
@ -17,8 +19,8 @@ asyncTestDiscourse('generate key', function() {
asyncTestDiscourse('revoke key', function() {
var apiKey = Discourse.ApiKey.create({id: 1234, key: 'asdfasdf'}),
adminUser = Discourse.AdminUser.create({id: 333, api_key: apiKey});
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
adminUser = AdminUser.create({id: 333, api_key: apiKey});
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve());

View File

@ -1,9 +1,10 @@
import { present } from 'helpers/qunit-helpers';
import ApiKey from 'admin/models/api-key';
module("Discourse.ApiKey");
test('create', function() {
var apiKey = Discourse.ApiKey.create({id: 123, user: {id: 345}});
var apiKey = ApiKey.create({id: 123, user: {id: 345}});
present(apiKey, 'it creates the api key');
present(apiKey.get('user'), 'it creates the user inside');
@ -12,7 +13,7 @@ test('create', function() {
asyncTestDiscourse('find', function() {
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
Discourse.ApiKey.find().then(function() {
ApiKey.find().then(function() {
start();
ok(Discourse.ajax.calledWith("/admin/api"), "it GETs the keys");
});
@ -20,14 +21,14 @@ asyncTestDiscourse('find', function() {
asyncTestDiscourse('generateMasterKey', function() {
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {}}));
Discourse.ApiKey.generateMasterKey().then(function() {
ApiKey.generateMasterKey().then(function() {
start();
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'POST'}), "it POSTs to create a master key");
});
});
asyncTestDiscourse('regenerate', function() {
var apiKey = Discourse.ApiKey.create({id: 3456});
var apiKey = ApiKey.create({id: 3456});
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 3456}}));
apiKey.regenerate().then(function() {
@ -37,7 +38,7 @@ asyncTestDiscourse('regenerate', function() {
});
asyncTestDiscourse('revoke', function() {
var apiKey = Discourse.ApiKey.create({id: 3456});
var apiKey = ApiKey.create({id: 3456});
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
apiKey.revoke().then(function() {

View File

@ -1,9 +1,11 @@
import FlaggedPost from 'admin/models/flagged-post';
module("Discourse.FlaggedPost");
test('delete first post', function() {
sandbox.stub(Discourse, 'ajax');
Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 })
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 })
.deletePost();
ok(Discourse.ajax.calledWith("/t/2", { type: 'DELETE', cache: false }), "it deleted the topic");
@ -12,7 +14,7 @@ test('delete first post', function() {
test('delete second post', function() {
sandbox.stub(Discourse, 'ajax');
Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 })
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 })
.deletePost();
ok(Discourse.ajax.calledWith("/posts/1", { type: 'DELETE', cache: false }), "it deleted the post");

View File

@ -1,4 +1,5 @@
import createStore from 'helpers/create-store';
import AdminUser from 'admin/models/admin-user';
var buildPost = function(args) {
return Discourse.Post.create(_.merge({
@ -9,7 +10,7 @@ var buildPost = function(args) {
};
var buildAdminUser = function(args) {
return Discourse.AdminUser.create(_.merge({
return AdminUser.create(_.merge({
id: 11,
username: 'urist'
}, args || {}));

View File

@ -1,4 +1,5 @@
import Quote from 'discourse/lib/quote';
import Post from 'discourse/models/post';
module("Discourse.BBCode");
@ -78,7 +79,7 @@ test("size tags", function() {
test("quotes", function() {
var post = Discourse.Post.create({
var post = Post.create({
cooked: "<p><b>lorem</b> ipsum</p>",
username: "eviltrout",
post_number: 1,

View File

@ -185,7 +185,7 @@ test('initial category when uncategorized is not allowed', function() {
test('open with a quote', function() {
const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
const newComposer = function() {
return openComposer({action: Discourse.Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
return openComposer({action: Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
};
equal(newComposer().get('originalText'), quote, "originalText is the quote" );

View File

@ -1,5 +1,7 @@
import EmailLog from 'admin/models/email-log';
module("Discourse.EmailLog");
test("create", function() {
ok(Discourse.EmailLog.create(), "it can be created without arguments");
ok(EmailLog.create(), "it can be created without arguments");
});

View File

@ -1,9 +1,10 @@
import { blank } from 'helpers/qunit-helpers';
import Report from 'admin/models/report';
module("Discourse.Report");
module("Report");
function reportWithData(data) {
return Discourse.Report.create({
return Report.create({
type: 'topics',
data: _.map(data, function(val, index) {
return { x: moment().subtract(index, "days").format('YYYY-MM-DD'), y: val };

View File

@ -1,5 +1,7 @@
module("Discourse.StaffActionLog");
import StaffActionLog from 'admin/models/staff-action-log';
module("StaffActionLog");
test("create", function() {
ok(Discourse.StaffActionLog.create(), "it can be created without arguments");
ok(StaffActionLog.create(), "it can be created without arguments");
});

View File

@ -1,8 +1,10 @@
module("Discourse.VersionCheck");
import VersionCheck from 'admin/models/version-check';
module("VersionCheck");
test('dataIsOld', function() {
var dataIsOld = function(args, expected, message) {
equal(Discourse.VersionCheck.create(args).get('dataIsOld'), expected, message);
equal(VersionCheck.create(args).get('dataIsOld'), expected, message);
};
dataIsOld({updated_at: moment().subtract(2, 'hours').toJSON()}, false, '2 hours ago');
@ -15,7 +17,7 @@ test('staleData', function() {
return moment().subtract(hoursAgo, 'hours').toJSON();
};
var staleData = function(args, expected, message) {
equal(Discourse.VersionCheck.create(args).get('staleData'), expected, message);
equal(VersionCheck.create(args).get('staleData'), expected, message);
};
staleData({missing_versions_count: 0, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(2)}, false, 'up to date');