mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Convert a lot of Globals to ES6 modules
This commit is contained in:
parent
124f47529a
commit
f42a5c1ba3
15 changed files with 65 additions and 80 deletions
|
@ -4,15 +4,8 @@
|
|||
@param hexValue is a reference to the color's hex value.
|
||||
@param brightnessValue is a number from 0 to 255 representing the brightness of the color. See ColorSchemeColor.
|
||||
@params valid is a boolean indicating if the input field is a valid color.
|
||||
|
||||
@class Discourse.ColorInputComponent
|
||||
@extends Ember.Component
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.ColorInputComponent = Ember.Component.extend({
|
||||
layoutName: 'components/color-input',
|
||||
|
||||
**/
|
||||
export default Ember.Component.extend({
|
||||
hexValueChanged: function() {
|
||||
var hex = this.get('hexValue');
|
||||
if (this.get('valid')) {
|
||||
|
@ -22,11 +15,10 @@ Discourse.ColorInputComponent = Ember.Component.extend({
|
|||
}
|
||||
}.observes('hexValue', 'brightnessValue', 'valid'),
|
||||
|
||||
didInsertElement: function() {
|
||||
_triggerHexChanged: function() {
|
||||
var self = this;
|
||||
this._super();
|
||||
Em.run.schedule('afterRender', function() {
|
||||
self.hexValueChanged();
|
||||
});
|
||||
}
|
||||
}.on('didInsertElement')
|
||||
});
|
|
@ -3,16 +3,8 @@
|
|||
|
||||
@param settingValue is a reference to SiteSetting.value.
|
||||
@param choices is a reference to SiteSetting.choices
|
||||
|
||||
@class Discourse.ListSettingComponent
|
||||
@extends Ember.Component
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
|
||||
Discourse.ListSettingComponent = Ember.Component.extend({
|
||||
tagName: 'div',
|
||||
|
||||
**/
|
||||
export default Ember.Component.extend({
|
||||
|
||||
_select2FormatSelection: function(selectedObject, jqueryWrapper, htmlEscaper) {
|
||||
var text = selectedObject.text;
|
||||
|
@ -22,9 +14,8 @@ Discourse.ListSettingComponent = Ember.Component.extend({
|
|||
return htmlEscaper(text);
|
||||
},
|
||||
|
||||
didInsertElement: function(){
|
||||
|
||||
var select2_options = {
|
||||
_initializeSelect2: function(){
|
||||
var options = {
|
||||
multiple: false,
|
||||
separator: "|",
|
||||
tokenSeparators: ["|"],
|
||||
|
@ -35,24 +26,27 @@ Discourse.ListSettingComponent = Ember.Component.extend({
|
|||
|
||||
var settingName = this.get('settingName');
|
||||
if (typeof settingName === 'string' && settingName.indexOf('colors') > -1) {
|
||||
select2_options.formatSelection = this._select2FormatSelection;
|
||||
options.formatSelection = this._select2FormatSelection;
|
||||
}
|
||||
this.$("input").select2(select2_options).on("change", function(obj) {
|
||||
this.set("settingValue", obj.val.join("|"));
|
||||
this.refreshSortables();
|
||||
}.bind(this));
|
||||
|
||||
var self = this;
|
||||
this.$("input").select2(options).on("change", function(obj) {
|
||||
self.set("settingValue", obj.val.join("|"));
|
||||
self.refreshSortables();
|
||||
});
|
||||
|
||||
this.refreshSortables();
|
||||
},
|
||||
}.on('didInsertElement'),
|
||||
|
||||
refreshOnReset: function() {
|
||||
this.$("input").select2("val", this.get("settingValue").split("|"));
|
||||
}.observes("settingValue"),
|
||||
|
||||
refreshSortables: function() {
|
||||
var self = this;
|
||||
this.$("ul.select2-choices").sortable().on('sortupdate', function() {
|
||||
this.$("input").select2("onSortEnd");
|
||||
}.bind(this));
|
||||
self.$("input").select2("onSortEnd");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -53,12 +53,13 @@ export default Ember.ArrayController.extend({
|
|||
},
|
||||
|
||||
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){
|
||||
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});
|
||||
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: Discourse.SiteSettings.delete_user_max_post_age});
|
||||
message += ' ' + I18n.t("admin.user.delete_forbidden", {count: maxPostAge});
|
||||
}
|
||||
bootbox.alert(message);
|
||||
controller._refreshUsers();
|
||||
|
|
|
@ -2,6 +2,6 @@ import DiscourseController from 'discourse/controllers/controller';
|
|||
|
||||
export default DiscourseController.extend({
|
||||
showBadges: function() {
|
||||
return this.get('currentUser.admin') && Discourse.SiteSettings.enable_badges;
|
||||
return this.get('currentUser.admin') && this.siteSettings.enable_badges;
|
||||
}.property()
|
||||
});
|
||||
|
|
|
@ -1,12 +1,3 @@
|
|||
/**
|
||||
Handles the default admin route
|
||||
|
||||
@class AdminDashboardRoute
|
||||
@extends Discourse.Route
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
|
||||
setupController: function(c) {
|
||||
|
@ -16,8 +7,9 @@ export default Discourse.Route.extend({
|
|||
fetchDashboardData: function(c) {
|
||||
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) {
|
||||
if( Discourse.SiteSettings.version_checks ){
|
||||
if (versionChecks) {
|
||||
c.set('versionCheck', Discourse.VersionCheck.create(d.version_check));
|
||||
}
|
||||
_.each(d.reports,function(report){
|
||||
|
|
|
@ -22,9 +22,10 @@ export default Ember.Component.extend({
|
|||
ratioText: function() {
|
||||
var ratio = this.get('ratio');
|
||||
|
||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_high) { return 'high'; }
|
||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_medium) { return 'med'; }
|
||||
if (ratio > Discourse.SiteSettings.topic_post_like_heat_low) { return 'low'; }
|
||||
var settings = this.siteSettings;
|
||||
if (ratio > settings.topic_post_like_heat_high) { return 'high'; }
|
||||
if (ratio > settings.topic_post_like_heat_medium) { return 'med'; }
|
||||
if (ratio > settings.topic_post_like_heat_low) { return 'low'; }
|
||||
return '';
|
||||
}.property('ratio'),
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
/**
|
||||
Append our CSRF token to AJAX requests when necessary.
|
||||
**/
|
||||
// Append our CSRF token to AJAX requests when necessary.
|
||||
export default {
|
||||
name: "csrf-token",
|
||||
initialize: function() {
|
||||
var session = Discourse.Session;
|
||||
after: 'inject-objects',
|
||||
initialize: function(container) {
|
||||
|
||||
var session = container.lookup('session:main');
|
||||
|
||||
// Add a CSRF token to all AJAX requests
|
||||
session.currentProp('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
||||
session.set('csrfToken', $('meta[name=csrf-token]').attr('content'));
|
||||
|
||||
$.ajaxPrefilter(function(options, originalOptions, xhr) {
|
||||
if (!options.crossDomain) {
|
||||
xhr.setRequestHeader('X-CSRF-Token', session.currentProp('csrfToken'));
|
||||
xhr.setRequestHeader('X-CSRF-Token', session.get('csrfToken'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Session from 'discourse/models/session';
|
||||
|
||||
export default {
|
||||
name: "inject-objects",
|
||||
initialize: function(container, application) {
|
||||
|
@ -29,5 +31,13 @@ export default {
|
|||
application.inject('route', 'siteSettings', 'site-settings:main');
|
||||
application.inject('view', 'siteSettings', 'site-settings:main');
|
||||
application.inject('model', 'siteSettings', 'site-settings:main');
|
||||
|
||||
// Inject Session for transient data
|
||||
application.register('session:main', Session.current(), { instantiate: false });
|
||||
application.inject('controller', 'session', 'session:main');
|
||||
application.inject('component', 'session', 'session:main');
|
||||
application.inject('route', 'session', 'session:main');
|
||||
application.inject('view', 'session', 'session:main');
|
||||
application.inject('model', 'session', 'session:main');
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/**
|
||||
A data model representing current session data. You can put transient
|
||||
data here you might want later. It is not stored or serialized anywhere.
|
||||
|
||||
@class Session
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.Session = Discourse.Model.extend({
|
||||
init: function() {
|
||||
this.set('highestSeenByTopic', {});
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.Session.reopenClass(Discourse.Singleton);
|
11
app/assets/javascripts/discourse/models/session.js.es6
Normal file
11
app/assets/javascripts/discourse/models/session.js.es6
Normal file
|
@ -0,0 +1,11 @@
|
|||
// A data model representing current session data. You can put transient
|
||||
// data here you might want later. It is not stored or serialized anywhere.
|
||||
var Session = Discourse.Model.extend({
|
||||
init: function() {
|
||||
this.set('highestSeenByTopic', {});
|
||||
}
|
||||
});
|
||||
|
||||
Session.reopenClass(Discourse.Singleton);
|
||||
|
||||
export default Session;
|
|
@ -24,7 +24,7 @@ Discourse.DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, Discourse
|
|||
|
||||
loadingComplete: function() {
|
||||
this.controllerFor('discovery').set('loading', false);
|
||||
if (!Discourse.Session.currentProp('topicListScrollPosition')) {
|
||||
if (!this.session.get('topicListScrollPosition')) {
|
||||
this._scrollTop();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -172,7 +172,7 @@ var TopicRoute = Discourse.Route.extend(ShowFooter, {
|
|||
isTransitioning = false;
|
||||
|
||||
var topic = this.modelFor('topic');
|
||||
Discourse.Session.currentProp('lastTopicIdViewed', parseInt(topic.get('id'), 10));
|
||||
this.session.set('lastTopicIdViewed', parseInt(topic.get('id'), 10));
|
||||
this.controllerFor('search').set('searchContext', topic.get('searchContext'));
|
||||
},
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, {
|
|||
},
|
||||
|
||||
_readjustScrollPosition: function() {
|
||||
var scrollTo = Discourse.Session.currentProp('topicListScrollPosition');
|
||||
var scrollTo = this.session.get('topicListScrollPosition');
|
||||
|
||||
if (typeof scrollTo !== "undefined") {
|
||||
Em.run.schedule('afterRender', function() {
|
||||
|
@ -35,7 +35,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, {
|
|||
|
||||
// Remember where we were scrolled to
|
||||
saveScrollPosition: function() {
|
||||
Discourse.Session.current().set('topicListScrollPosition', $(window).scrollTop());
|
||||
this.session.set('topicListScrollPosition', $(window).scrollTop());
|
||||
},
|
||||
|
||||
// When the topic list is scrolled
|
||||
|
|
|
@ -17,11 +17,9 @@ export default Discourse.GroupedView.extend({
|
|||
},
|
||||
|
||||
_highlightIfNeeded: function() {
|
||||
var session = Discourse.Session.current();
|
||||
|
||||
// highlight the last topic viewed
|
||||
if (session.get('lastTopicIdViewed') === this.get('content.id')) {
|
||||
session.set('lastTopicIdViewed', null);
|
||||
if (this.session.get('lastTopicIdViewed') === this.get('content.id')) {
|
||||
this.session.set('lastTopicIdViewed', null);
|
||||
this.highlight();
|
||||
} else if (this.get('content.highlight')) {
|
||||
// highlight new topics that have been loaded from the server or the one we just created
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import Session from "discourse/models/session";
|
||||
|
||||
module("Discourse.Session");
|
||||
|
||||
test('highestSeenByTopic', function() {
|
||||
var session = Discourse.Session.current();
|
||||
var session = Session.current();
|
||||
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue