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