Removed a bunch of `Discourse.Site` globals
This commit is contained in:
parent
e684d7689e
commit
9264a7914f
|
@ -1,18 +1,11 @@
|
|||
/**
|
||||
A breadcrumb including category drop downs
|
||||
|
||||
@class BreadCrumbsComponent
|
||||
@extends Ember.Component
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
// A breadcrumb including category drop downs
|
||||
export default Ember.Component.extend({
|
||||
classNames: ['category-breadcrumb'],
|
||||
tagName: 'ol',
|
||||
parentCategory: Em.computed.alias('category.parentCategory'),
|
||||
|
||||
parentCategories: Em.computed.filter('categories', function(c) {
|
||||
if (c.id === Discourse.Site.currentProp("uncategorized_category_id") && !Discourse.SiteSettings.allow_uncategorized_topics) {
|
||||
if (c.id === this.site.get("uncategorized_category_id") && !this.siteSettings.allow_uncategorized_topics) {
|
||||
// Don't show "uncategorized" if allow_uncategorized_topics setting is false.
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ export default ObjectController.extend({
|
|||
this.set("controllers.application.showFooter", this.get("loadedAllItems"));
|
||||
}.observes("loadedAllItems"),
|
||||
|
||||
showMoreUrl: function(period) {
|
||||
showMoreUrl(period) {
|
||||
var url = '', category = this.get('category');
|
||||
if (category) {
|
||||
url = '/c/' + Discourse.Category.slugFor(category) + (this.get('noSubcategories') ? '/none' : '') + '/l';
|
||||
|
@ -24,12 +24,12 @@ export default ObjectController.extend({
|
|||
},
|
||||
|
||||
periods: function() {
|
||||
var self = this,
|
||||
periods = [];
|
||||
Discourse.Site.currentProp('periods').forEach(function(p) {
|
||||
const self = this,
|
||||
periods = [];
|
||||
this.site.get('periods').forEach(function(p) {
|
||||
periods.pushObject(TopPeriod.create({ id: p,
|
||||
showMoreUrl: self.showMoreUrl(p),
|
||||
periods: periods }));
|
||||
periods }));
|
||||
});
|
||||
return periods;
|
||||
}.property('category', 'noSubcategories'),
|
||||
|
|
|
@ -17,13 +17,13 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||
_.each(this.get("actions_summary"),function(a) {
|
||||
var actionSummary;
|
||||
a.flagTopic = self.get('model');
|
||||
a.actionType = Discourse.Site.current().topicFlagTypeById(a.id);
|
||||
a.actionType = self.site.topicFlagTypeById(a.id);
|
||||
actionSummary = Discourse.ActionSummary.create(a);
|
||||
lookup.set(a.actionType.get('name_key'), actionSummary);
|
||||
});
|
||||
this.set('topicActionByName', lookup);
|
||||
|
||||
return Discourse.Site.currentProp('topic_flag_types').filter(function(item) {
|
||||
return this.site.get('topic_flag_types').filter(function(item) {
|
||||
return _.any(self.get("actions_summary"), function(a) {
|
||||
return (a.id === item.get('id') && a.can_act);
|
||||
});
|
||||
|
|
|
@ -16,10 +16,6 @@ export default DiscourseController.extend(ModalFunctionality, {
|
|||
this.set('loggedIn', false);
|
||||
},
|
||||
|
||||
site: function() {
|
||||
return Discourse.Site.current();
|
||||
}.property(),
|
||||
|
||||
/**
|
||||
Determines whether at least one login button is enabled
|
||||
**/
|
||||
|
|
|
@ -5,7 +5,7 @@ var INVITED_TYPE= 8;
|
|||
export default ObjectController.extend({
|
||||
|
||||
scope: function () {
|
||||
return "notifications." + Discourse.Site.currentProp("notificationLookup")[this.get("notification_type")];
|
||||
return "notifications." + this.site.get("notificationLookup")[this.get("notification_type")];
|
||||
}.property("notification_type"),
|
||||
|
||||
username: Em.computed.alias("data.display_username"),
|
||||
|
|
|
@ -435,10 +435,10 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
|||
post.toggleProperty('wiki');
|
||||
},
|
||||
|
||||
togglePostType: function (post) {
|
||||
togglePostType(post) {
|
||||
// the request to the server is made in an observer in the post class
|
||||
var regular = Discourse.Site.currentProp('post_types.regular'),
|
||||
moderator = Discourse.Site.currentProp('post_types.moderator_action');
|
||||
const regular = this.site.get('post_types.regular'),
|
||||
moderator = this.site.get('post_types.moderator_action');
|
||||
|
||||
if (post.get("post_type") === moderator) {
|
||||
post.set("post_type", regular);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
Discourse.Site = Discourse.Model.extend({
|
||||
const Site = Discourse.Model.extend({
|
||||
|
||||
isReadOnly: Em.computed.alias('is_readonly'),
|
||||
|
||||
notificationLookup: function() {
|
||||
var result = [];
|
||||
const result = [];
|
||||
_.each(this.get('notification_types'), function(v,k) {
|
||||
result[v] = k;
|
||||
});
|
||||
|
@ -11,23 +11,23 @@ Discourse.Site = Discourse.Model.extend({
|
|||
}.property('notification_types'),
|
||||
|
||||
flagTypes: function() {
|
||||
var postActionTypes = this.get('post_action_types');
|
||||
const postActionTypes = this.get('post_action_types');
|
||||
if (!postActionTypes) return [];
|
||||
return postActionTypes.filterProperty('is_flag', true);
|
||||
}.property('post_action_types.@each'),
|
||||
|
||||
categoriesByCount: Em.computed.sort('categories', function(a, b) {
|
||||
categoriesByCount: Ember.computed.sort('categories', function(a, b) {
|
||||
return (b.get('topic_count') || 0) - (a.get('topic_count') || 0);
|
||||
}),
|
||||
|
||||
// Sort subcategories under parents
|
||||
sortedCategories: function() {
|
||||
var cats = this.get('categoriesByCount'),
|
||||
const cats = this.get('categoriesByCount'),
|
||||
result = [],
|
||||
remaining = {};
|
||||
|
||||
cats.forEach(function(c) {
|
||||
var parentCategoryId = parseInt(c.get('parent_category_id'), 10);
|
||||
const parentCategoryId = parseInt(c.get('parent_category_id'), 10);
|
||||
if (!parentCategoryId) {
|
||||
result.pushObject(c);
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ Discourse.Site = Discourse.Model.extend({
|
|||
});
|
||||
|
||||
Ember.keys(remaining).forEach(function(parentCategoryId) {
|
||||
var category = result.findBy('id', parseInt(parentCategoryId, 10)),
|
||||
const category = result.findBy('id', parseInt(parentCategoryId, 10)),
|
||||
index = result.indexOf(category);
|
||||
|
||||
if (index !== -1) {
|
||||
|
@ -48,16 +48,16 @@ Discourse.Site = Discourse.Model.extend({
|
|||
return result;
|
||||
}.property(),
|
||||
|
||||
postActionTypeById: function(id) {
|
||||
postActionTypeById(id) {
|
||||
return this.get("postActionByIdLookup.action" + id);
|
||||
},
|
||||
|
||||
topicFlagTypeById: function(id) {
|
||||
topicFlagTypeById(id) {
|
||||
return this.get("topicFlagByIdLookup.action" + id);
|
||||
},
|
||||
|
||||
updateCategory: function(newCategory) {
|
||||
var existingCategory = this.get('categories').findProperty('id', Em.get(newCategory, 'id'));
|
||||
updateCategory(newCategory) {
|
||||
const existingCategory = this.get('categories').findProperty('id', Em.get(newCategory, 'id'));
|
||||
if (existingCategory) {
|
||||
// Don't update null permissions
|
||||
if (newCategory.permission === null) { delete newCategory.permission; }
|
||||
|
@ -67,20 +67,15 @@ Discourse.Site = Discourse.Model.extend({
|
|||
}
|
||||
});
|
||||
|
||||
Discourse.Site.reopenClass(Discourse.Singleton, {
|
||||
Site.reopenClass(Discourse.Singleton, {
|
||||
|
||||
/**
|
||||
The current singleton will retrieve its attributes from the `PreloadStore`.
|
||||
|
||||
@method createCurrent
|
||||
@returns {Discourse.Site} the site
|
||||
**/
|
||||
createCurrent: function() {
|
||||
// The current singleton will retrieve its attributes from the `PreloadStore`.
|
||||
createCurrent() {
|
||||
return Discourse.Site.create(PreloadStore.get('site'));
|
||||
},
|
||||
|
||||
create: function() {
|
||||
var result = this._super.apply(this, arguments);
|
||||
create() {
|
||||
const result = this._super.apply(this, arguments);
|
||||
|
||||
if (result.categories) {
|
||||
result.categoriesById = {};
|
||||
|
@ -107,7 +102,7 @@ Discourse.Site.reopenClass(Discourse.Singleton, {
|
|||
if (result.post_action_types) {
|
||||
result.postActionByIdLookup = Em.Object.create();
|
||||
result.post_action_types = _.map(result.post_action_types,function(p) {
|
||||
var actionType = Discourse.PostActionType.create(p);
|
||||
const actionType = Discourse.PostActionType.create(p);
|
||||
result.postActionByIdLookup.set("action" + p.id, actionType);
|
||||
return actionType;
|
||||
});
|
||||
|
@ -116,7 +111,7 @@ Discourse.Site.reopenClass(Discourse.Singleton, {
|
|||
if (result.topic_flag_types) {
|
||||
result.topicFlagByIdLookup = Em.Object.create();
|
||||
result.topic_flag_types = _.map(result.topic_flag_types,function(p) {
|
||||
var actionType = Discourse.PostActionType.create(p);
|
||||
const actionType = Discourse.PostActionType.create(p);
|
||||
result.topicFlagByIdLookup.set("action" + p.id, actionType);
|
||||
return actionType;
|
||||
});
|
||||
|
@ -138,4 +133,4 @@ Discourse.Site.reopenClass(Discourse.Singleton, {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
export default Site;
|
|
@ -1,51 +1,54 @@
|
|||
var notificationFixture = {
|
||||
import Site from 'discourse/models/site';
|
||||
|
||||
const notificationFixture = {
|
||||
notification_type: 1, //mentioned
|
||||
post_number: 1,
|
||||
topic_id: 1234,
|
||||
slug: "a-slug",
|
||||
data: {
|
||||
topic_title: "some title",
|
||||
topic_title: "some title",
|
||||
display_username: "velesin"
|
||||
}
|
||||
},
|
||||
site: Site.current()
|
||||
};
|
||||
|
||||
moduleFor("controller:notification");
|
||||
|
||||
test("scope property is correct", function() {
|
||||
var controller = this.subject(notificationFixture);
|
||||
const controller = this.subject(notificationFixture);
|
||||
equal(controller.get("scope"), "notifications.mentioned");
|
||||
});
|
||||
|
||||
test("username property is correct", function() {
|
||||
var controller = this.subject(notificationFixture);
|
||||
const controller = this.subject(notificationFixture);
|
||||
equal(controller.get("username"), "velesin");
|
||||
});
|
||||
|
||||
test("description property returns badge name when there is one", function() {
|
||||
var fixtureWithBadgeName = _.extend({}, notificationFixture, { data: { badge_name: "badge" } });
|
||||
var controller = this.subject(fixtureWithBadgeName);
|
||||
const fixtureWithBadgeName = _.extend({}, notificationFixture, { data: { badge_name: "badge" } });
|
||||
const controller = this.subject(fixtureWithBadgeName);
|
||||
equal(controller.get("description"), "badge");
|
||||
});
|
||||
|
||||
test("description property returns empty string when there is no topic title", function() {
|
||||
var fixtureWithEmptyTopicTitle = _.extend({}, notificationFixture, { data: { topic_title: "" } });
|
||||
var controller = this.subject(fixtureWithEmptyTopicTitle);
|
||||
const fixtureWithEmptyTopicTitle = _.extend({}, notificationFixture, { data: { topic_title: "" } });
|
||||
const controller = this.subject(fixtureWithEmptyTopicTitle);
|
||||
equal(controller.get("description"), "");
|
||||
});
|
||||
|
||||
test("description property returns topic title", function() {
|
||||
var fixtureWithTopicTitle = _.extend({}, notificationFixture, { data: { topic_title: "topic" } });
|
||||
var controller = this.subject(fixtureWithTopicTitle);
|
||||
const fixtureWithTopicTitle = _.extend({}, notificationFixture, { data: { topic_title: "topic" } });
|
||||
const controller = this.subject(fixtureWithTopicTitle);
|
||||
equal(controller.get("description"), "topic");
|
||||
});
|
||||
|
||||
test("url property returns badge's url when there is a badge", function() {
|
||||
var fixtureWithBadge = _.extend({}, notificationFixture, { data: { badge_id: 1, badge_name: "Badge Name"} });
|
||||
var controller = this.subject(fixtureWithBadge);
|
||||
const fixtureWithBadge = _.extend({}, notificationFixture, { data: { badge_id: 1, badge_name: "Badge Name"} });
|
||||
const controller = this.subject(fixtureWithBadge);
|
||||
equal(controller.get("url"), "/badges/1/badge-name");
|
||||
});
|
||||
|
||||
test("url property returns topic's url when there is a topic", function() {
|
||||
var controller = this.subject(notificationFixture);
|
||||
const controller = this.subject(notificationFixture);
|
||||
equal(controller.get("url"), "/t/a-slug/1234");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue