mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 08:45:05 +00:00
Move TopicTrackingState
to injected object
This commit is contained in:
parent
064b62199e
commit
8e776d0fd7
@ -54,23 +54,17 @@ export default Ember.Component.extend({
|
|||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
|
||||||
topicTrackingState() {
|
|
||||||
return Discourse.TopicTrackingState.current();
|
|
||||||
},
|
|
||||||
|
|
||||||
@observes('topicTrackingState.incomingCount')
|
@observes('topicTrackingState.incomingCount')
|
||||||
fetchLiveStats() {
|
fetchLiveStats() {
|
||||||
if (!this.get('enabled')) { return; }
|
if (!this.get('enabled')) { return; }
|
||||||
|
|
||||||
var self = this;
|
LivePostCounts.find().then((stats) => {
|
||||||
LivePostCounts.find().then(function(stats) {
|
|
||||||
if(stats) {
|
if(stats) {
|
||||||
self.set('publicTopicCount', stats.get('public_topic_count'));
|
this.set('publicTopicCount', stats.get('public_topic_count'));
|
||||||
self.set('publicPostCount', stats.get('public_post_count'));
|
this.set('publicPostCount', stats.get('public_post_count'));
|
||||||
if (self.get('publicTopicCount') >= self.get('requiredTopics')
|
if (this.get('publicTopicCount') >= this.get('requiredTopics')
|
||||||
&& self.get('publicPostCount') >= self.get('requiredPosts')) {
|
&& this.get('publicPostCount') >= this.get('requiredPosts')) {
|
||||||
self.set('enabled', false); // No more checks
|
this.set('enabled', false); // No more checks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import { buildCategoryPanel } from 'discourse/components/edit-category-panel';
|
import { buildCategoryPanel } from 'discourse/components/edit-category-panel';
|
||||||
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
||||||
|
import Category from 'discourse/models/category';
|
||||||
|
|
||||||
export default buildCategoryPanel('general', {
|
export default buildCategoryPanel('general', {
|
||||||
foregroundColors: ['FFFFFF', '000000'],
|
foregroundColors: ['FFFFFF', '000000'],
|
||||||
@ -31,7 +32,7 @@ export default buildCategoryPanel('general', {
|
|||||||
|
|
||||||
categoryBadgePreview: function() {
|
categoryBadgePreview: function() {
|
||||||
const category = this.get('category');
|
const category = this.get('category');
|
||||||
const c = Discourse.Category.create({
|
const c = Category.create({
|
||||||
name: category.get('categoryName'),
|
name: category.get('categoryName'),
|
||||||
color: category.get('color'),
|
color: category.get('color'),
|
||||||
text_color: category.get('text_color'),
|
text_color: category.get('text_color'),
|
||||||
@ -45,7 +46,7 @@ export default buildCategoryPanel('general', {
|
|||||||
// We can change the parent if there are no children
|
// We can change the parent if there are no children
|
||||||
subCategories: function() {
|
subCategories: function() {
|
||||||
if (Ember.isEmpty(this.get('category.id'))) { return null; }
|
if (Ember.isEmpty(this.get('category.id'))) { return null; }
|
||||||
return Discourse.Category.list().filterBy('parent_category_id', this.get('category.id'));
|
return Category.list().filterBy('parent_category_id', this.get('category.id'));
|
||||||
}.property('category.id'),
|
}.property('category.id'),
|
||||||
|
|
||||||
showDescription: function() {
|
showDescription: function() {
|
||||||
|
@ -22,11 +22,6 @@ export default Ember.Component.extend({
|
|||||||
return this.siteSettings.faq_url ? this.siteSettings.faq_url : Discourse.getURL('/faq');
|
return this.siteSettings.faq_url ? this.siteSettings.faq_url : Discourse.getURL('/faq');
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
|
||||||
topicTrackingState() {
|
|
||||||
return Discourse.TopicTrackingState.current();
|
|
||||||
},
|
|
||||||
|
|
||||||
_lookupCount(type) {
|
_lookupCount(type) {
|
||||||
const state = this.get('topicTrackingState');
|
const state = this.get('topicTrackingState');
|
||||||
return state ? state.lookupCount(type) : 0;
|
return state ? state.lookupCount(type) : 0;
|
||||||
|
@ -19,8 +19,8 @@ export default DiscoveryController.extend({
|
|||||||
this.set('controllers.discovery.loading', true);
|
this.set('controllers.discovery.loading', true);
|
||||||
|
|
||||||
const parentCategory = this.get('model.parentCategory');
|
const parentCategory = this.get('model.parentCategory');
|
||||||
const promise = parentCategory ? Discourse.CategoryList.listForParent(parentCategory) :
|
const promise = parentCategory ? Discourse.CategoryList.listForParent(this.store, parentCategory) :
|
||||||
Discourse.CategoryList.list();
|
Discourse.CategoryList.list(this.store);
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
promise.then(function(list) {
|
promise.then(function(list) {
|
||||||
|
@ -29,8 +29,8 @@ const controllerOpts = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Show newly inserted topics
|
// Show newly inserted topics
|
||||||
showInserted: function() {
|
showInserted() {
|
||||||
const tracker = Discourse.TopicTrackingState.current();
|
const tracker = this.topicTrackingState;
|
||||||
|
|
||||||
// Move inserted into topics
|
// Move inserted into topics
|
||||||
this.get('content').loadBefore(tracker.get('newIncoming'));
|
this.get('content').loadBefore(tracker.get('newIncoming'));
|
||||||
@ -38,9 +38,8 @@ const controllerOpts = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function() {
|
refresh() {
|
||||||
const filter = this.get('model.filter'),
|
const filter = this.get('model.filter');
|
||||||
self = this;
|
|
||||||
|
|
||||||
this.setProperties({ order: 'default', ascending: false });
|
this.setProperties({ order: 'default', ascending: false });
|
||||||
|
|
||||||
@ -52,36 +51,27 @@ const controllerOpts = {
|
|||||||
// Lesson learned: Don't call `loading` yourself.
|
// Lesson learned: Don't call `loading` yourself.
|
||||||
this.set('controllers.discovery.loading', true);
|
this.set('controllers.discovery.loading', true);
|
||||||
|
|
||||||
this.store.findFiltered('topicList', {filter}).then(function(list) {
|
this.store.findFiltered('topicList', {filter}).then((list) => {
|
||||||
Discourse.TopicList.hideUniformCategory(list, self.get('category'));
|
Discourse.TopicList.hideUniformCategory(list, this.get('category'));
|
||||||
|
|
||||||
self.setProperties({ model: list });
|
this.setProperties({ model: list });
|
||||||
self.resetSelected();
|
this.resetSelected();
|
||||||
|
|
||||||
const tracking = Discourse.TopicTrackingState.current();
|
if (this.topicTrackingState) {
|
||||||
if (tracking) {
|
this.topicTrackingState.sync(list, filter);
|
||||||
tracking.sync(list, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send('loadingComplete');
|
this.send('loadingComplete');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
resetNew: function() {
|
resetNew() {
|
||||||
const self = this;
|
this.topicTrackingState.resetNew();
|
||||||
|
Discourse.Topic.resetNew().then(() => this.send('refresh'));
|
||||||
Discourse.TopicTrackingState.current().resetNew();
|
|
||||||
Discourse.Topic.resetNew().then(function() {
|
|
||||||
self.send('refresh');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
topicTrackingState: function() {
|
|
||||||
return Discourse.TopicTrackingState.current();
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
isFilterPage: function(filter, filterType) {
|
isFilterPage: function(filter, filterType) {
|
||||||
if (!filter) { return false; }
|
if (!filter) { return false; }
|
||||||
return filter.match(new RegExp(filterType + '$', 'gi')) ? true : false;
|
return filter.match(new RegExp(filterType + '$', 'gi')) ? true : false;
|
||||||
@ -96,7 +86,7 @@ const controllerOpts = {
|
|||||||
}.property('model.filter', 'model.topics.length'),
|
}.property('model.filter', 'model.topics.length'),
|
||||||
|
|
||||||
tooManyTracked: function(){
|
tooManyTracked: function(){
|
||||||
return Discourse.TopicTrackingState.current().tooManyTracked();
|
return this.topicTrackingState.tooManyTracked();
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
showDismissAtTop: function() {
|
showDismissAtTop: function() {
|
||||||
|
@ -9,6 +9,9 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
|
||||||
|
// TODO: Move `ScreenTrack` to injection and remove this
|
||||||
|
this.set('topicTrackingState', Discourse.__container__.lookup('topic-tracking-state:main'));
|
||||||
},
|
},
|
||||||
|
|
||||||
start(topicId, topicController) {
|
start(topicId, topicController) {
|
||||||
@ -112,7 +115,7 @@ const ScreenTrack = Ember.Object.extend({
|
|||||||
highestSeenByTopic[topicId] = highestSeen;
|
highestSeenByTopic[topicId] = highestSeen;
|
||||||
}
|
}
|
||||||
|
|
||||||
Discourse.TopicTrackingState.current().updateSeen(topicId, highestSeen);
|
this.topicTrackingState.updateSeen(topicId, highestSeen);
|
||||||
|
|
||||||
if (!$.isEmptyObject(newTimings)) {
|
if (!$.isEmptyObject(newTimings)) {
|
||||||
Discourse.ajax('/topics/timings', {
|
Discourse.ajax('/topics/timings', {
|
||||||
|
@ -36,7 +36,7 @@ export default Ember.Mixin.create({
|
|||||||
}
|
}
|
||||||
promise.then(function(result) {
|
promise.then(function(result) {
|
||||||
if (result && result.topic_ids) {
|
if (result && result.topic_ids) {
|
||||||
const tracker = Discourse.TopicTrackingState.current();
|
const tracker = self.topicTrackingState;
|
||||||
result.topic_ids.forEach(function(t) {
|
result.topic_ids.forEach(function(t) {
|
||||||
tracker.removeTopic(t);
|
tracker.removeTopic(t);
|
||||||
});
|
});
|
||||||
|
60
app/assets/javascripts/discourse/models/category-list.js.es6
Normal file
60
app/assets/javascripts/discourse/models/category-list.js.es6
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
const CategoryList = Ember.ArrayProxy.extend({
|
||||||
|
init() {
|
||||||
|
this.set('content', []);
|
||||||
|
this._super();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CategoryList.reopenClass({
|
||||||
|
categoriesFrom(store, result) {
|
||||||
|
const categories = Discourse.CategoryList.create();
|
||||||
|
const users = Discourse.Model.extractByKey(result.featured_users, Discourse.User);
|
||||||
|
const list = Discourse.Category.list();
|
||||||
|
|
||||||
|
result.category_list.categories.forEach(function(c) {
|
||||||
|
if (c.parent_category_id) {
|
||||||
|
c.parentCategory = list.findBy('id', c.parent_category_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.subcategory_ids) {
|
||||||
|
c.subcategories = c.subcategory_ids.map(scid => list.findBy('id', parseInt(scid, 10)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.featured_user_ids) {
|
||||||
|
c.featured_users = c.featured_user_ids.map(u => users[u]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.topics) {
|
||||||
|
c.topics = c.topics.map(t => Discourse.Topic.create(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
categories.pushObject(store.createRecord('category', c));
|
||||||
|
});
|
||||||
|
return categories;
|
||||||
|
},
|
||||||
|
|
||||||
|
listForParent(store, category) {
|
||||||
|
return Discourse.ajax('/categories.json?parent_category_id=' + category.get('id')).then((result) => {
|
||||||
|
return Discourse.CategoryList.create({
|
||||||
|
categories: this.categoriesFrom(store, result),
|
||||||
|
parentCategory: category
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
list(store) {
|
||||||
|
const getCategories = () => Discourse.ajax("/categories.json");
|
||||||
|
return PreloadStore.getAndRemove("categories_list", getCategories).then((result) => {
|
||||||
|
return Discourse.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,
|
||||||
|
draft_key: result.category_list.draft_key,
|
||||||
|
draft: result.category_list.draft,
|
||||||
|
draft_sequence: result.category_list.draft_sequence
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default CategoryList;
|
@ -1,4 +1,6 @@
|
|||||||
Discourse.Category = Discourse.Model.extend({
|
import RestModel from 'discourse/models/rest';
|
||||||
|
|
||||||
|
const Category = RestModel.extend({
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
this._super();
|
this._super();
|
||||||
@ -26,7 +28,7 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
}.property('id'),
|
}.property('id'),
|
||||||
|
|
||||||
url: function() {
|
url: function() {
|
||||||
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
|
return Discourse.getURL("/c/") + Category.slugFor(this);
|
||||||
}.property('name'),
|
}.property('name'),
|
||||||
|
|
||||||
fullSlug: function() {
|
fullSlug: function() {
|
||||||
@ -129,16 +131,12 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
}.property('topics'),
|
}.property('topics'),
|
||||||
|
|
||||||
topicTrackingState: function(){
|
unreadTopics: function() {
|
||||||
return Discourse.TopicTrackingState.current();
|
return this.topicTrackingState.countUnread(this.get('id'));
|
||||||
}.property(),
|
|
||||||
|
|
||||||
unreadTopics: function(){
|
|
||||||
return this.get('topicTrackingState').countUnread(this.get('id'));
|
|
||||||
}.property('topicTrackingState.messageCount'),
|
}.property('topicTrackingState.messageCount'),
|
||||||
|
|
||||||
newTopics: function(){
|
newTopics: function() {
|
||||||
return this.get('topicTrackingState').countNew(this.get('id'));
|
return this.topicTrackingState.countNew(this.get('id'));
|
||||||
}.property('topicTrackingState.messageCount'),
|
}.property('topicTrackingState.messageCount'),
|
||||||
|
|
||||||
topicStatsTitle: function() {
|
topicStatsTitle: function() {
|
||||||
@ -193,10 +191,10 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
|
|
||||||
var _uncategorized;
|
var _uncategorized;
|
||||||
|
|
||||||
Discourse.Category.reopenClass({
|
Category.reopenClass({
|
||||||
|
|
||||||
findUncategorized: function() {
|
findUncategorized: function() {
|
||||||
_uncategorized = _uncategorized || Discourse.Category.list().findBy('id', Discourse.Site.currentProp('uncategorized_category_id'));
|
_uncategorized = _uncategorized || Category.list().findBy('id', Discourse.Site.currentProp('uncategorized_category_id'));
|
||||||
return _uncategorized;
|
return _uncategorized;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -207,7 +205,7 @@ Discourse.Category.reopenClass({
|
|||||||
result = "";
|
result = "";
|
||||||
|
|
||||||
if (parentCategory) {
|
if (parentCategory) {
|
||||||
result = Discourse.Category.slugFor(parentCategory) + "/";
|
result = Category.slugFor(parentCategory) + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = Em.get(category, 'id'),
|
var id = Em.get(category, 'id'),
|
||||||
@ -234,20 +232,20 @@ Discourse.Category.reopenClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
findSingleBySlug: function(slug) {
|
findSingleBySlug: function(slug) {
|
||||||
return Discourse.Category.list().find(function(c) {
|
return Category.list().find(function(c) {
|
||||||
return Discourse.Category.slugFor(c) === slug;
|
return Category.slugFor(c) === slug;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
findById: function(id) {
|
findById: function(id) {
|
||||||
if (!id) { return; }
|
if (!id) { return; }
|
||||||
return Discourse.Category.idMap()[id];
|
return Category.idMap()[id];
|
||||||
},
|
},
|
||||||
|
|
||||||
findByIds: function(ids){
|
findByIds: function(ids){
|
||||||
var categories = [];
|
var categories = [];
|
||||||
_.each(ids, function(id){
|
_.each(ids, function(id){
|
||||||
var found = Discourse.Category.findById(id);
|
var found = Category.findById(id);
|
||||||
if(found){
|
if(found){
|
||||||
categories.push(found);
|
categories.push(found);
|
||||||
}
|
}
|
||||||
@ -256,20 +254,20 @@ Discourse.Category.reopenClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
findBySlug: function(slug, parentSlug) {
|
findBySlug: function(slug, parentSlug) {
|
||||||
var categories = Discourse.Category.list(),
|
var categories = Category.list(),
|
||||||
category;
|
category;
|
||||||
|
|
||||||
if (parentSlug) {
|
if (parentSlug) {
|
||||||
var parentCategory = Discourse.Category.findSingleBySlug(parentSlug);
|
var parentCategory = Category.findSingleBySlug(parentSlug);
|
||||||
if (parentCategory) {
|
if (parentCategory) {
|
||||||
if (slug === 'none') { return parentCategory; }
|
if (slug === 'none') { return parentCategory; }
|
||||||
|
|
||||||
category = categories.find(function(item) {
|
category = categories.find(function(item) {
|
||||||
return item && item.get('parentCategory') === parentCategory && Discourse.Category.slugFor(item) === (parentSlug + "/" + slug);
|
return item && item.get('parentCategory') === parentCategory && Category.slugFor(item) === (parentSlug + "/" + slug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
category = Discourse.Category.findSingleBySlug(slug);
|
category = Category.findSingleBySlug(slug);
|
||||||
|
|
||||||
// If we have a parent category, we need to enforce it
|
// If we have a parent category, we need to enforce it
|
||||||
if (category && category.get('parentCategory')) return;
|
if (category && category.get('parentCategory')) return;
|
||||||
@ -283,9 +281,9 @@ Discourse.Category.reopenClass({
|
|||||||
return category;
|
return category;
|
||||||
},
|
},
|
||||||
|
|
||||||
reloadById: function(id) {
|
reloadById(id) {
|
||||||
return Discourse.ajax("/c/" + id + "/show.json").then(function (result) {
|
return Discourse.ajax("/c/" + id + "/show.json");
|
||||||
return Discourse.Category.create(result.category);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default Category;
|
@ -1,68 +0,0 @@
|
|||||||
Discourse.CategoryList = Ember.ArrayProxy.extend({
|
|
||||||
init: function() {
|
|
||||||
this.set('content', []);
|
|
||||||
this._super();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Discourse.CategoryList.reopenClass({
|
|
||||||
categoriesFrom: function(result) {
|
|
||||||
var categories = Discourse.CategoryList.create(),
|
|
||||||
users = Discourse.Model.extractByKey(result.featured_users, Discourse.User),
|
|
||||||
list = Discourse.Category.list();
|
|
||||||
|
|
||||||
result.category_list.categories.forEach(function(c) {
|
|
||||||
|
|
||||||
if (c.parent_category_id) {
|
|
||||||
c.parentCategory = list.findBy('id', c.parent_category_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c.subcategory_ids) {
|
|
||||||
c.subcategories = c.subcategory_ids.map(function(scid) { return list.findBy('id', parseInt(scid, 10)); });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c.featured_user_ids) {
|
|
||||||
c.featured_users = c.featured_user_ids.map(function(u) {
|
|
||||||
return users[u];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (c.topics) {
|
|
||||||
c.topics = c.topics.map(function(t) {
|
|
||||||
return Discourse.Topic.create(t);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
categories.pushObject(Discourse.Category.create(c));
|
|
||||||
|
|
||||||
});
|
|
||||||
return categories;
|
|
||||||
},
|
|
||||||
|
|
||||||
listForParent: function(category) {
|
|
||||||
var self = this;
|
|
||||||
return Discourse.ajax('/categories.json?parent_category_id=' + category.get('id')).then(function(result) {
|
|
||||||
return Discourse.CategoryList.create({
|
|
||||||
categories: self.categoriesFrom(result),
|
|
||||||
parentCategory: category
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
list: function() {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return PreloadStore.getAndRemove("categories_list", function() {
|
|
||||||
return Discourse.ajax("/categories.json");
|
|
||||||
}).then(function(result) {
|
|
||||||
return Discourse.CategoryList.create({
|
|
||||||
categories: self.categoriesFrom(result),
|
|
||||||
can_create_category: result.category_list.can_create_category,
|
|
||||||
can_create_topic: result.category_list.can_create_topic,
|
|
||||||
draft_key: result.category_list.draft_key,
|
|
||||||
draft: result.category_list.draft,
|
|
||||||
draft_sequence: result.category_list.draft_sequence
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
@ -689,13 +689,6 @@ const Composer = RestModel.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Composer.reopenClass({
|
Composer.reopenClass({
|
||||||
|
|
||||||
open(opts) {
|
|
||||||
const composer = Composer.create();
|
|
||||||
composer.open(opts);
|
|
||||||
return composer;
|
|
||||||
},
|
|
||||||
|
|
||||||
loadDraft(opts) {
|
loadDraft(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
|
@ -20,10 +20,6 @@ const NavItem = Discourse.Model.extend({
|
|||||||
return I18n.t("filters." + name.replace("/", ".") + ".title", extra);
|
return I18n.t("filters." + name.replace("/", ".") + ".title", extra);
|
||||||
}.property('categoryName', 'name', 'count'),
|
}.property('categoryName', 'name', 'count'),
|
||||||
|
|
||||||
topicTrackingState: function() {
|
|
||||||
return Discourse.TopicTrackingState.current();
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
categoryName: function() {
|
categoryName: function() {
|
||||||
var split = this.get('name').split('/');
|
var split = this.get('name').split('/');
|
||||||
return split[0] === 'category' ? split[1] : null;
|
return split[0] === 'category' ? split[1] : null;
|
||||||
@ -100,7 +96,9 @@ NavItem.reopenClass({
|
|||||||
extra = cb.call(self, text, opts);
|
extra = cb.call(self, text, opts);
|
||||||
_.merge(args, extra);
|
_.merge(args, extra);
|
||||||
});
|
});
|
||||||
return Discourse.NavItem.create(args);
|
|
||||||
|
const store = Discourse.__container__.lookup('store:main');
|
||||||
|
return store.createRecord('nav-item', args);
|
||||||
},
|
},
|
||||||
|
|
||||||
buildList(category, args) {
|
buildList(category, args) {
|
||||||
|
@ -78,13 +78,10 @@ RestModel.reopenClass({
|
|||||||
|
|
||||||
create(args) {
|
create(args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
if (!args.store || !args.keyValueStore) {
|
if (!args.store) {
|
||||||
const container = Discourse.__container__;
|
const container = Discourse.__container__;
|
||||||
// Ember.warn('Use `store.createRecord` to create records instead of `.create()`');
|
// Ember.warn('Use `store.createRecord` to create records instead of `.create()`');
|
||||||
args.store = container.lookup('store:main');
|
args.store = container.lookup('store:main');
|
||||||
|
|
||||||
// TODO: Remove this when composer is using the store fully
|
|
||||||
args.keyValueStore = container.lookup('key-value-store:main');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
args.__munge = this.munge;
|
args.__munge = this.munge;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import Archetype from 'discourse/models/archetype';
|
import Archetype from 'discourse/models/archetype';
|
||||||
import PostActionType from 'discourse/models/post-action-type';
|
import PostActionType from 'discourse/models/post-action-type';
|
||||||
import Singleton from 'discourse/mixins/singleton';
|
import Singleton from 'discourse/mixins/singleton';
|
||||||
|
import RestModel from 'discourse/models/rest';
|
||||||
|
|
||||||
const Site = Discourse.Model.extend({
|
const Site = RestModel.extend({
|
||||||
|
|
||||||
isReadOnly: Em.computed.alias('is_readonly'),
|
isReadOnly: Em.computed.alias('is_readonly'),
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ const Site = Discourse.Model.extend({
|
|||||||
existingCategory.setProperties(newCategory);
|
existingCategory.setProperties(newCategory);
|
||||||
} else {
|
} else {
|
||||||
// TODO insert in right order?
|
// TODO insert in right order?
|
||||||
newCategory = Discourse.Category.create(newCategory);
|
newCategory = this.store.createRecord('category', newCategory);
|
||||||
categories.pushObject(newCategory);
|
categories.pushObject(newCategory);
|
||||||
this.get('categoriesById')[categoryId] = newCategory;
|
this.get('categoriesById')[categoryId] = newCategory;
|
||||||
}
|
}
|
||||||
@ -91,16 +92,18 @@ Site.reopenClass(Singleton, {
|
|||||||
|
|
||||||
// The current singleton will retrieve its attributes from the `PreloadStore`.
|
// The current singleton will retrieve its attributes from the `PreloadStore`.
|
||||||
createCurrent() {
|
createCurrent() {
|
||||||
return Site.create(PreloadStore.get('site'));
|
const store = Discourse.__container__.lookup('store:main');
|
||||||
|
return store.createRecord('site', PreloadStore.get('site'));
|
||||||
},
|
},
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
const result = this._super.apply(this, arguments);
|
const result = this._super.apply(this, arguments);
|
||||||
|
|
||||||
|
const store = result.store;
|
||||||
if (result.categories) {
|
if (result.categories) {
|
||||||
result.categoriesById = {};
|
result.categoriesById = {};
|
||||||
result.categories = _.map(result.categories, function(c) {
|
result.categories = _.map(result.categories, function(c) {
|
||||||
return result.categoriesById[c.id] = Discourse.Category.create(c);
|
return result.categoriesById[c.id] = store.createRecord('category', c);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Associate the categories with their parents
|
// Associate the categories with their parents
|
||||||
|
@ -157,6 +157,10 @@ export default Ember.Object.extend({
|
|||||||
obj.__type = type;
|
obj.__type = type;
|
||||||
obj.__state = obj.id ? "created" : "new";
|
obj.__state = obj.id ? "created" : "new";
|
||||||
|
|
||||||
|
// TODO: Have injections be automatic
|
||||||
|
obj.topicTrackingState = this.container.lookup('topic-tracking-state:main');
|
||||||
|
obj.keyValueStore = this.container.lookup('key-value-store:main');
|
||||||
|
|
||||||
const klass = this.container.lookupFactory('model:' + type) || RestModel;
|
const klass = this.container.lookupFactory('model:' + type) || RestModel;
|
||||||
const model = klass.create(obj);
|
const model = klass.create(obj);
|
||||||
|
|
||||||
|
@ -147,9 +147,6 @@ TopicList.reopenClass({
|
|||||||
json.per_page = json.topic_list.per_page;
|
json.per_page = json.topic_list.per_page;
|
||||||
json.topics = topicsFrom(json, store);
|
json.topics = topicsFrom(json, store);
|
||||||
|
|
||||||
if (json.topic_list.filtered_category) {
|
|
||||||
json.category = Discourse.Category.create(json.topic_list.filtered_category);
|
|
||||||
}
|
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ TopicTrackingState.reopenClass({
|
|||||||
const container = Discourse.__container__,
|
const container = Discourse.__container__,
|
||||||
messageBus = container.lookup('message-bus:main'),
|
messageBus = container.lookup('message-bus:main'),
|
||||||
currentUser = container.lookup('current-user:main'),
|
currentUser = container.lookup('current-user:main'),
|
||||||
instance = Discourse.TopicTrackingState.create({ messageBus, currentUser });
|
instance = TopicTrackingState.create({ messageBus, currentUser });
|
||||||
|
|
||||||
instance.loadStates(data);
|
instance.loadStates(data);
|
||||||
instance.initialStatesLength = data && data.length;
|
instance.initialStatesLength = data && data.length;
|
||||||
|
@ -3,6 +3,7 @@ import buildTopicRoute from 'discourse/routes/build-topic-route';
|
|||||||
import DiscoverySortableController from 'discourse/controllers/discovery-sortable';
|
import DiscoverySortableController from 'discourse/controllers/discovery-sortable';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
after: 'inject-discourse-objects',
|
||||||
name: 'dynamic-route-builders',
|
name: 'dynamic-route-builders',
|
||||||
|
|
||||||
initialize(container, app) {
|
initialize(container, app) {
|
||||||
|
@ -5,6 +5,7 @@ import Store from 'discourse/models/store';
|
|||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import DiscourseLocation from 'discourse/lib/discourse-location';
|
import DiscourseLocation from 'discourse/lib/discourse-location';
|
||||||
import SearchService from 'discourse/services/search';
|
import SearchService from 'discourse/services/search';
|
||||||
|
import TopicTrackingState from 'discourse/models/topic-tracking-state';
|
||||||
|
|
||||||
function inject() {
|
function inject() {
|
||||||
const app = arguments[0],
|
const app = arguments[0],
|
||||||
@ -30,6 +31,12 @@ export default {
|
|||||||
app.register('store:main', Store);
|
app.register('store:main', Store);
|
||||||
inject(app, 'store', 'route', 'controller');
|
inject(app, 'store', 'route', 'controller');
|
||||||
|
|
||||||
|
app.register('message-bus:main', window.MessageBus, { instantiate: false });
|
||||||
|
injectAll(app, 'messageBus');
|
||||||
|
|
||||||
|
app.register('topic-tracking-state:main', TopicTrackingState.current(), { instantiate: false });
|
||||||
|
injectAll(app, 'topicTrackingState');
|
||||||
|
|
||||||
const site = Discourse.Site.current();
|
const site = Discourse.Site.current();
|
||||||
app.register('site:main', site, { instantiate: false });
|
app.register('site:main', site, { instantiate: false });
|
||||||
injectAll(app, 'site');
|
injectAll(app, 'site');
|
||||||
@ -46,9 +53,6 @@ export default {
|
|||||||
app.register('current-user:main', Discourse.User.current(), { instantiate: false });
|
app.register('current-user:main', Discourse.User.current(), { instantiate: false });
|
||||||
inject(app, 'currentUser', 'component', 'route', 'controller');
|
inject(app, 'currentUser', 'component', 'route', 'controller');
|
||||||
|
|
||||||
app.register('message-bus:main', window.MessageBus, { instantiate: false });
|
|
||||||
injectAll(app, 'messageBus');
|
|
||||||
|
|
||||||
app.register('location:discourse-location', DiscourseLocation);
|
app.register('location:discourse-location', DiscourseLocation);
|
||||||
|
|
||||||
const keyValueStore = new KeyValueStore("discourse_");
|
const keyValueStore = new KeyValueStore("discourse_");
|
||||||
|
@ -2,6 +2,7 @@ import { setting } from 'discourse/lib/computed';
|
|||||||
import logout from 'discourse/lib/logout';
|
import logout from 'discourse/lib/logout';
|
||||||
import showModal from 'discourse/lib/show-modal';
|
import showModal from 'discourse/lib/show-modal';
|
||||||
import OpenComposer from "discourse/mixins/open-composer";
|
import OpenComposer from "discourse/mixins/open-composer";
|
||||||
|
import Category from 'discourse/models/category';
|
||||||
|
|
||||||
function unlessReadOnly(method) {
|
function unlessReadOnly(method) {
|
||||||
return function() {
|
return function() {
|
||||||
@ -126,11 +127,11 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
editCategory(category) {
|
editCategory(category) {
|
||||||
const self = this;
|
Category.reloadById(category.get('id')).then((atts) => {
|
||||||
Discourse.Category.reloadById(category.get('id')).then(function (model) {
|
const model = this.store.createRecord('category', atts.category);
|
||||||
self.site.updateCategory(model);
|
this.site.updateCategory(model);
|
||||||
showModal('editCategory', { model });
|
showModal('editCategory', { model });
|
||||||
self.controllerFor('editCategory').set('selectedTab', 'general');
|
this.controllerFor('editCategory').set('selectedTab', 'general');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ export default function(filter, params) {
|
|||||||
this._categoryList = null;
|
this._categoryList = null;
|
||||||
if (Em.isNone(model.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
|
if (Em.isNone(model.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.CategoryList.listForParent(model).then(function(list) {
|
return Discourse.CategoryList.listForParent(this.store, model).then(function(list) {
|
||||||
self._categoryList = list;
|
self._categoryList = list;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ export default function(filter, params) {
|
|||||||
var findOpts = filterQueryParams(transition.queryParams, params),
|
var findOpts = filterQueryParams(transition.queryParams, params),
|
||||||
extras = { cached: this.isPoppedState(transition) };
|
extras = { cached: this.isPoppedState(transition) };
|
||||||
|
|
||||||
return findTopicList(this.store, listFilter, findOpts, extras).then(function(list) {
|
return findTopicList(this.store, this.topicTrackingState, listFilter, findOpts, extras).then(function(list) {
|
||||||
Discourse.TopicList.hideUniformCategory(list, model);
|
Discourse.TopicList.hideUniformCategory(list, model);
|
||||||
self.set('topics', list);
|
self.set('topics', list);
|
||||||
});
|
});
|
||||||
|
@ -12,9 +12,7 @@ function filterQueryParams(params, defaultParams) {
|
|||||||
return findOpts;
|
return findOpts;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTopicList(store, filter, filterParams, extras) {
|
function findTopicList(store, tracking, filter, filterParams, extras) {
|
||||||
const tracking = Discourse.TopicTrackingState.current();
|
|
||||||
|
|
||||||
extras = extras || {};
|
extras = extras || {};
|
||||||
return new Ember.RSVP.Promise(function(resolve) {
|
return new Ember.RSVP.Promise(function(resolve) {
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ export default function(filter, extras) {
|
|||||||
const findOpts = filterQueryParams(transition.queryParams),
|
const findOpts = filterQueryParams(transition.queryParams),
|
||||||
findExtras = { cached: this.isPoppedState(transition) };
|
findExtras = { cached: this.isPoppedState(transition) };
|
||||||
|
|
||||||
return findTopicList(this.store, filter, findOpts, findExtras);
|
return findTopicList(this.store, this.topicTrackingState, filter, findOpts, findExtras);
|
||||||
},
|
},
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
|
@ -16,8 +16,8 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
// if default page is categories
|
// if default page is categories
|
||||||
PreloadStore.remove("topic_list");
|
PreloadStore.remove("topic_list");
|
||||||
|
|
||||||
return Discourse.CategoryList.list("categories").then(function(list) {
|
return Discourse.CategoryList.list(this.store, 'categories').then((list) => {
|
||||||
const tracking = Discourse.TopicTrackingState.current();
|
const tracking = this.topicTrackingState;
|
||||||
if (tracking) {
|
if (tracking) {
|
||||||
tracking.sync(list, "categories");
|
tracking.sync(list, "categories");
|
||||||
tracking.trackIncoming("categories");
|
tracking.trackIncoming("categories");
|
||||||
@ -46,7 +46,7 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
const groups = this.site.groups,
|
const groups = this.site.groups,
|
||||||
everyoneName = groups.findBy("id", 0).name;
|
everyoneName = groups.findBy("id", 0).name;
|
||||||
|
|
||||||
const model = Discourse.Category.create({
|
const model = this.store.createRecord('category', {
|
||||||
color: "AB9364", text_color: "FFFFFF", group_permissions: [{group_name: everyoneName, permission_type: 1}],
|
color: "AB9364", text_color: "FFFFFF", group_permissions: [{group_name: everyoneName, permission_type: 1}],
|
||||||
available_groups: groups.map(g => g.name),
|
available_groups: groups.map(g => g.name),
|
||||||
allow_badges: true
|
allow_badges: true
|
||||||
|
@ -216,7 +216,7 @@ const TopicRoute = Discourse.Route.extend({
|
|||||||
this.controllerFor('topic-admin-menu').set('model', model);
|
this.controllerFor('topic-admin-menu').set('model', model);
|
||||||
|
|
||||||
this.controllerFor('composer').set('topic', model);
|
this.controllerFor('composer').set('topic', model);
|
||||||
Discourse.TopicTrackingState.current().trackIncoming('all');
|
this.topicTrackingState.trackIncoming('all');
|
||||||
controller.subscribe();
|
controller.subscribe();
|
||||||
|
|
||||||
this.controllerFor('topic-progress').set('model', model);
|
this.controllerFor('topic-progress').set('model', model);
|
||||||
|
@ -121,10 +121,6 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli
|
|||||||
this.appEvents.trigger('topic:scrolled', offset);
|
this.appEvents.trigger('topic:scrolled', offset);
|
||||||
},
|
},
|
||||||
|
|
||||||
topicTrackingState: function() {
|
|
||||||
return Discourse.TopicTrackingState.current();
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
browseMoreMessage: function() {
|
browseMoreMessage: function() {
|
||||||
var opts = { latestLink: "<a href=\"" + Discourse.getURL("/latest") + "\">" + I18n.t("topic.view_latest_topics") + "</a>" },
|
var opts = { latestLink: "<a href=\"" + Discourse.getURL("/latest") + "\">" + I18n.t("topic.view_latest_topics") + "</a>" },
|
||||||
category = this.get('controller.content.category');
|
category = this.get('controller.content.category');
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
//= require ./discourse/models/rest
|
//= require ./discourse/models/rest
|
||||||
//= require ./discourse/models/badge-grouping
|
//= require ./discourse/models/badge-grouping
|
||||||
//= require ./discourse/models/badge
|
//= require ./discourse/models/badge
|
||||||
|
//= require ./discourse/models/category
|
||||||
//= require_tree ./discourse/mixins
|
//= require_tree ./discourse/mixins
|
||||||
//= require ./discourse/lib/ajax-error
|
//= require ./discourse/lib/ajax-error
|
||||||
//= require ./discourse/lib/markdown
|
//= require ./discourse/lib/markdown
|
||||||
|
@ -1,16 +1,29 @@
|
|||||||
import Store from "discourse/models/store";
|
import Store from "discourse/models/store";
|
||||||
import RestAdapter from 'discourse/adapters/rest';
|
import RestAdapter from 'discourse/adapters/rest';
|
||||||
|
import KeyValueStore from 'discourse/lib/key-value-store';
|
||||||
|
import TopicTrackingState from 'discourse/models/topic-tracking-state';
|
||||||
import Resolver from 'discourse/ember/resolver';
|
import Resolver from 'discourse/ember/resolver';
|
||||||
|
|
||||||
let _restAdapter;
|
|
||||||
export default function() {
|
export default function() {
|
||||||
const resolver = Resolver.create();
|
const resolver = Resolver.create();
|
||||||
return Store.create({
|
return Store.create({
|
||||||
container: {
|
container: {
|
||||||
lookup(type) {
|
lookup(type) {
|
||||||
if (type === "adapter:rest") {
|
if (type === "adapter:rest") {
|
||||||
_restAdapter = _restAdapter || RestAdapter.create({ container: this });
|
this._restAdapter = this._restAdapter || RestAdapter.create({ container: this });
|
||||||
return (_restAdapter);
|
return (this._restAdapter);
|
||||||
|
}
|
||||||
|
if (type === "key-value-store:main") {
|
||||||
|
this._kvs = this._kvs || new KeyValueStore();
|
||||||
|
return (this._kvs);
|
||||||
|
}
|
||||||
|
if (type === "topic-tracking-state:main") {
|
||||||
|
this._tracker = this._tracker || TopicTrackingState.current();
|
||||||
|
return (this._tracker);
|
||||||
|
}
|
||||||
|
if (type === "site-settings:main") {
|
||||||
|
this._settings = this._settings || Discourse.SiteSettings.current();
|
||||||
|
return (this._settings);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ function acceptance(name, options) {
|
|||||||
options.teardown.call(this);
|
options.teardown.call(this);
|
||||||
}
|
}
|
||||||
Discourse.User.resetCurrent();
|
Discourse.User.resetCurrent();
|
||||||
Discourse.Site.resetCurrent(Discourse.Site.create(fixtures['site.json'].site));
|
Discourse.Site.resetCurrent(Discourse.Site.create(jQuery.extend(true, {}, fixtures['site.json'].site)));
|
||||||
|
|
||||||
Discourse.Utilities.avatarImg = oldAvatar;
|
Discourse.Utilities.avatarImg = oldAvatar;
|
||||||
Discourse.reset();
|
Discourse.reset();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import createStore from 'helpers/create-store';
|
||||||
import { blank, present } from 'helpers/qunit-helpers';
|
import { blank, present } from 'helpers/qunit-helpers';
|
||||||
|
|
||||||
module("lib:category-link");
|
module("lib:category-link");
|
||||||
@ -10,33 +11,36 @@ test("categoryBadge without a category", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Regular categoryBadge", function() {
|
test("Regular categoryBadge", function() {
|
||||||
var category = Discourse.Category.create({
|
const store = createStore();
|
||||||
name: 'hello',
|
const category = store.createRecord('category', {
|
||||||
id: 123,
|
name: 'hello',
|
||||||
description_text: 'cool description',
|
id: 123,
|
||||||
color: 'ff0',
|
description_text: 'cool description',
|
||||||
text_color: 'f00'
|
color: 'ff0',
|
||||||
}),
|
text_color: 'f00'
|
||||||
tag = parseHTML(categoryBadgeHTML(category))[0];
|
});
|
||||||
|
const tag = parseHTML(categoryBadgeHTML(category))[0];
|
||||||
|
|
||||||
equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
||||||
equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
||||||
|
|
||||||
var label = tag.children[1];
|
const label = tag.children[1];
|
||||||
equal(label.attributes.title, 'cool description', 'it has the correct title');
|
equal(label.attributes.title, 'cool description', 'it has the correct title');
|
||||||
|
|
||||||
equal(label.children[0].data, 'hello', 'it has the category name');
|
equal(label.children[0].data, 'hello', 'it has the category name');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("undefined color", function() {
|
test("undefined color", function() {
|
||||||
var noColor = Discourse.Category.create({ name: 'hello', id: 123 }),
|
const store = createStore();
|
||||||
tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
const noColor = store.createRecord('category', { name: 'hello', id: 123 });
|
||||||
|
const tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
||||||
|
|
||||||
blank(tag.attributes.style, "it has no color style because there are no colors");
|
blank(tag.attributes.style, "it has no color style because there are no colors");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("allowUncategorized", function() {
|
test("allowUncategorized", function() {
|
||||||
var uncategorized = Discourse.Category.create({name: 'uncategorized', id: 345});
|
const store = createStore();
|
||||||
|
const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345});
|
||||||
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
||||||
|
|
||||||
blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||||
|
@ -1,27 +1,30 @@
|
|||||||
module("Discourse.Category");
|
import createStore from 'helpers/create-store';
|
||||||
|
|
||||||
|
module("model:category");
|
||||||
|
|
||||||
test('slugFor', function(){
|
test('slugFor', function(){
|
||||||
|
const store = createStore();
|
||||||
|
|
||||||
var slugFor = function(cat, val, text) {
|
const slugFor = function(cat, val, text) {
|
||||||
equal(Discourse.Category.slugFor(cat), val, text);
|
equal(Discourse.Category.slugFor(cat), val, text);
|
||||||
};
|
};
|
||||||
|
|
||||||
slugFor(Discourse.Category.create({slug: 'hello'}), "hello", "It calculates the proper slug for hello");
|
slugFor(store.createRecord('category', {slug: 'hello'}), "hello", "It calculates the proper slug for hello");
|
||||||
slugFor(Discourse.Category.create({id: 123, slug: ''}), "123-category", "It returns id-category for empty strings");
|
slugFor(store.createRecord('category', {id: 123, slug: ''}), "123-category", "It returns id-category for empty strings");
|
||||||
slugFor(Discourse.Category.create({id: 456}), "456-category", "It returns id-category for undefined slugs");
|
slugFor(store.createRecord('category', {id: 456}), "456-category", "It returns id-category for undefined slugs");
|
||||||
slugFor(Discourse.Category.create({slug: '熱帶風暴畫眉'}), "熱帶風暴畫眉", "It can be non english characters");
|
slugFor(store.createRecord('category', {slug: '熱帶風暴畫眉'}), "熱帶風暴畫眉", "It can be non english characters");
|
||||||
|
|
||||||
var parentCategory = Discourse.Category.create({id: 345, slug: 'darth'});
|
const parentCategory = store.createRecord('category', {id: 345, slug: 'darth'});
|
||||||
slugFor(Discourse.Category.create({slug: 'luke', parentCategory: parentCategory}),
|
slugFor(store.createRecord('category', {slug: 'luke', parentCategory: parentCategory}),
|
||||||
"darth/luke",
|
"darth/luke",
|
||||||
"it uses the parent slug before the child");
|
"it uses the parent slug before the child");
|
||||||
|
|
||||||
slugFor(Discourse.Category.create({id: 555, parentCategory: parentCategory}),
|
slugFor(store.createRecord('category', {id: 555, parentCategory: parentCategory}),
|
||||||
"darth/555-category",
|
"darth/555-category",
|
||||||
"it uses the parent slug before the child and then uses id");
|
"it uses the parent slug before the child and then uses id");
|
||||||
|
|
||||||
parentCategory.set('slug', null);
|
parentCategory.set('slug', null);
|
||||||
slugFor(Discourse.Category.create({id: 555, parentCategory: parentCategory}),
|
slugFor(store.createRecord('category', {id: 555, parentCategory: parentCategory}),
|
||||||
"345-category/555-category",
|
"345-category/555-category",
|
||||||
"it uses the parent before the child and uses ids for both");
|
"it uses the parent before the child and uses ids for both");
|
||||||
});
|
});
|
||||||
@ -30,12 +33,13 @@ test('slugFor', function(){
|
|||||||
test('findBySlug', function() {
|
test('findBySlug', function() {
|
||||||
expect(6);
|
expect(6);
|
||||||
|
|
||||||
var darth = Discourse.Category.create({id: 1, slug: 'darth'}),
|
const store = createStore();
|
||||||
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
|
const darth = store.createRecord('category', {id: 1, slug: 'darth'}),
|
||||||
hurricane = Discourse.Category.create({id: 3, slug: '熱帶風暴畫眉'}),
|
luke = store.createRecord('category', {id: 2, slug: 'luke', parentCategory: darth}),
|
||||||
newsFeed = Discourse.Category.create({id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
hurricane = store.createRecord('category', {id: 3, slug: '熱帶風暴畫眉'}),
|
||||||
time = Discourse.Category.create({id: 5, slug: '时间', parentCategory: darth}),
|
newsFeed = store.createRecord('category', {id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
||||||
bah = Discourse.Category.create({id: 6, slug: 'bah', parentCategory: hurricane}),
|
time = store.createRecord('category', {id: 5, slug: '时间', parentCategory: darth}),
|
||||||
|
bah = store.createRecord('category', {id: 6, slug: 'bah', parentCategory: hurricane}),
|
||||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||||
|
|
||||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||||
@ -51,12 +55,13 @@ test('findBySlug', function() {
|
|||||||
test('findSingleBySlug', function() {
|
test('findSingleBySlug', function() {
|
||||||
expect(6);
|
expect(6);
|
||||||
|
|
||||||
var darth = Discourse.Category.create({id: 1, slug: 'darth'}),
|
const store = createStore();
|
||||||
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
|
const darth = store.createRecord('category', {id: 1, slug: 'darth'}),
|
||||||
hurricane = Discourse.Category.create({id: 3, slug: '熱帶風暴畫眉'}),
|
luke = store.createRecord('category', {id: 2, slug: 'luke', parentCategory: darth}),
|
||||||
newsFeed = Discourse.Category.create({id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
hurricane = store.createRecord('category', {id: 3, slug: '熱帶風暴畫眉'}),
|
||||||
time = Discourse.Category.create({id: 5, slug: '时间', parentCategory: darth}),
|
newsFeed = store.createRecord('category', {id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
||||||
bah = Discourse.Category.create({id: 6, slug: 'bah', parentCategory: hurricane}),
|
time = store.createRecord('category', {id: 5, slug: '时间', parentCategory: darth}),
|
||||||
|
bah = store.createRecord('category', {id: 6, slug: 'bah', parentCategory: hurricane}),
|
||||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||||
|
|
||||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||||
@ -70,9 +75,10 @@ test('findSingleBySlug', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('findByIds', function() {
|
test('findByIds', function() {
|
||||||
var categories = {
|
const store = createStore();
|
||||||
1: Discourse.Category.create({id: 1}),
|
const categories = {
|
||||||
2: Discourse.Category.create({id: 2})
|
1: store.createRecord('category', {id: 1}),
|
||||||
|
2: store.createRecord('category', {id: 2})
|
||||||
};
|
};
|
||||||
|
|
||||||
sandbox.stub(Discourse.Category, 'idMap').returns(categories);
|
sandbox.stub(Discourse.Category, 'idMap').returns(categories);
|
||||||
@ -80,13 +86,14 @@ test('findByIds', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('postCountStats', function() {
|
test('postCountStats', function() {
|
||||||
var category1 = Discourse.Category.create({id: 1, slug: 'unloved', posts_year: 2, posts_month: 0, posts_week: 0, posts_day: 0}),
|
const store = createStore();
|
||||||
category2 = Discourse.Category.create({id: 2, slug: 'hasbeen', posts_year: 50, posts_month: 4, posts_week: 0, posts_day: 0}),
|
const category1 = store.createRecord('category', {id: 1, slug: 'unloved', posts_year: 2, posts_month: 0, posts_week: 0, posts_day: 0}),
|
||||||
category3 = Discourse.Category.create({id: 3, slug: 'solastweek', posts_year: 250, posts_month: 200, posts_week: 50, posts_day: 0}),
|
category2 = store.createRecord('category', {id: 2, slug: 'hasbeen', posts_year: 50, posts_month: 4, posts_week: 0, posts_day: 0}),
|
||||||
category4 = Discourse.Category.create({id: 4, slug: 'hotstuff', posts_year: 500, posts_month: 280, posts_week: 100, posts_day: 22}),
|
category3 = store.createRecord('category', {id: 3, slug: 'solastweek', posts_year: 250, posts_month: 200, posts_week: 50, posts_day: 0}),
|
||||||
category5 = Discourse.Category.create({id: 6, slug: 'empty', posts_year: 0, posts_month: 0, posts_week: 0, posts_day: 0});
|
category4 = store.createRecord('category', {id: 4, slug: 'hotstuff', posts_year: 500, posts_month: 280, posts_week: 100, posts_day: 22}),
|
||||||
|
category5 = store.createRecord('category', {id: 6, slug: 'empty', posts_year: 0, posts_month: 0, posts_week: 0, posts_day: 0});
|
||||||
|
|
||||||
var result = category1.get('postCountStats');
|
let result = category1.get('postCountStats');
|
||||||
equal(result.length, 1, "should only show year");
|
equal(result.length, 1, "should only show year");
|
||||||
equal(result[0].value, 2);
|
equal(result[0].value, 2);
|
||||||
equal(result[0].unit, 'year');
|
equal(result[0].unit, 'year');
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { blank } from 'helpers/qunit-helpers';
|
import { blank } from 'helpers/qunit-helpers';
|
||||||
import { currentUser } from 'helpers/qunit-helpers';
|
import { currentUser } from 'helpers/qunit-helpers';
|
||||||
import KeyValueStore from 'discourse/lib/key-value-store';
|
import KeyValueStore from 'discourse/lib/key-value-store';
|
||||||
|
import Composer from 'discourse/models/composer';
|
||||||
|
import createStore from 'helpers/create-store';
|
||||||
|
|
||||||
module("model:composer");
|
module("model:composer");
|
||||||
|
|
||||||
@ -9,10 +11,13 @@ const keyValueStore = new KeyValueStore("_test_composer");
|
|||||||
function createComposer(opts) {
|
function createComposer(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.user = opts.user || currentUser();
|
opts.user = opts.user || currentUser();
|
||||||
opts.site = Discourse.Site.current();
|
return createStore().createRecord('composer', opts);
|
||||||
opts.siteSettings = Discourse.SiteSettings;
|
}
|
||||||
opts.keyValueStore = keyValueStore;
|
|
||||||
; return Discourse.Composer.create(opts);
|
function openComposer(opts) {
|
||||||
|
const composer = createComposer(opts);
|
||||||
|
composer.open(opts);
|
||||||
|
return composer;
|
||||||
}
|
}
|
||||||
|
|
||||||
test('replyLength', function() {
|
test('replyLength', function() {
|
||||||
@ -111,7 +116,7 @@ test("Title length for regular topics", function() {
|
|||||||
test("Title length for private messages", function() {
|
test("Title length for private messages", function() {
|
||||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||||
const composer = createComposer({action: Discourse.Composer.PRIVATE_MESSAGE});
|
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||||
|
|
||||||
composer.set('title', 'asdf');
|
composer.set('title', 'asdf');
|
||||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||||
@ -126,7 +131,7 @@ test("Title length for private messages", function() {
|
|||||||
test("Title length for private messages", function() {
|
test("Title length for private messages", function() {
|
||||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||||
const composer = createComposer({action: Discourse.Composer.PRIVATE_MESSAGE});
|
const composer = createComposer({action: Composer.PRIVATE_MESSAGE});
|
||||||
|
|
||||||
composer.set('title', 'asdf');
|
composer.set('title', 'asdf');
|
||||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||||
@ -143,7 +148,7 @@ test('editingFirstPost', function() {
|
|||||||
ok(!composer.get('editingFirstPost'), "it's false by default");
|
ok(!composer.get('editingFirstPost'), "it's false by default");
|
||||||
|
|
||||||
const post = Discourse.Post.create({id: 123, post_number: 2});
|
const post = Discourse.Post.create({id: 123, post_number: 2});
|
||||||
composer.setProperties({post: post, action: Discourse.Composer.EDIT });
|
composer.setProperties({post: post, action: Composer.EDIT });
|
||||||
ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
|
ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
|
||||||
|
|
||||||
post.set('post_number', 1);
|
post.set('post_number', 1);
|
||||||
@ -170,19 +175,19 @@ test('clearState', function() {
|
|||||||
|
|
||||||
test('initial category when uncategorized is allowed', function() {
|
test('initial category when uncategorized is allowed', function() {
|
||||||
Discourse.SiteSettings.allow_uncategorized_topics = true;
|
Discourse.SiteSettings.allow_uncategorized_topics = true;
|
||||||
const composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
||||||
equal(composer.get('categoryId'),undefined,"Uncategorized by default");
|
equal(composer.get('categoryId'),undefined,"Uncategorized by default");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('initial category when uncategorized is not allowed', function() {
|
test('initial category when uncategorized is not allowed', function() {
|
||||||
Discourse.SiteSettings.allow_uncategorized_topics = false;
|
Discourse.SiteSettings.allow_uncategorized_topics = false;
|
||||||
const composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
||||||
ok(composer.get('categoryId') === undefined, "Uncategorized by default. Must choose a category.");
|
ok(composer.get('categoryId') === undefined, "Uncategorized by default. Must choose a category.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('showPreview', function() {
|
test('showPreview', function() {
|
||||||
const newComposer = function() {
|
const newComposer = function() {
|
||||||
return Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
return openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
|
||||||
};
|
};
|
||||||
|
|
||||||
Discourse.Mobile.mobileView = true;
|
Discourse.Mobile.mobileView = true;
|
||||||
@ -199,7 +204,7 @@ test('showPreview', function() {
|
|||||||
test('open with a quote', function() {
|
test('open with a quote', function() {
|
||||||
const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
|
const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
|
||||||
const newComposer = function() {
|
const newComposer = function() {
|
||||||
return Discourse.Composer.open({action: Discourse.Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
|
return openComposer({action: Discourse.Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote});
|
||||||
};
|
};
|
||||||
|
|
||||||
equal(newComposer().get('originalText'), quote, "originalText is the quote" );
|
equal(newComposer().get('originalText'), quote, "originalText is the quote" );
|
||||||
@ -212,7 +217,7 @@ test("Title length for static page topics as admin", function() {
|
|||||||
const composer = createComposer();
|
const composer = createComposer();
|
||||||
|
|
||||||
const post = Discourse.Post.create({id: 123, post_number: 2, static_doc: true});
|
const post = Discourse.Post.create({id: 123, post_number: 2, static_doc: true});
|
||||||
composer.setProperties({post: post, action: Discourse.Composer.EDIT });
|
composer.setProperties({post: post, action: Composer.EDIT });
|
||||||
|
|
||||||
composer.set('title', 'asdf');
|
composer.set('title', 'asdf');
|
||||||
ok(composer.get('titleLengthValid'), "admins can use short titles");
|
ok(composer.get('titleLengthValid'), "admins can use short titles");
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
|
import createStore from 'helpers/create-store';
|
||||||
import { blank, present } from 'helpers/qunit-helpers';
|
import { blank, present } from 'helpers/qunit-helpers';
|
||||||
|
|
||||||
module("Discourse.Site");
|
module("model:site");
|
||||||
|
|
||||||
test('create', function() {
|
test('create', function() {
|
||||||
ok(Discourse.Site.create(), 'it can create with no parameters');
|
ok(Discourse.Site.create(), 'it can create with no parameters');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('instance', function() {
|
test('instance', function() {
|
||||||
|
const site = Discourse.Site.current();
|
||||||
var site = Discourse.Site.current();
|
|
||||||
|
|
||||||
present(site, "We have a current site singleton");
|
present(site, "We have a current site singleton");
|
||||||
present(site.get('categories'), "The instance has a list of categories");
|
present(site.get('categories'), "The instance has a list of categories");
|
||||||
@ -18,24 +18,24 @@ test('instance', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('create categories', function() {
|
test('create categories', function() {
|
||||||
|
const store = createStore();
|
||||||
var site = Discourse.Site.create({
|
const site = store.createRecord('site', {
|
||||||
categories: [{ id: 1234, name: 'Test'},
|
categories: [{ id: 1234, name: 'Test'},
|
||||||
{ id: 3456, name: 'Test Subcategory', parent_category_id: 1234},
|
{ id: 3456, name: 'Test Subcategory', parent_category_id: 1234},
|
||||||
{ id: 3456, name: 'Invalid Subcategory', parent_category_id: 6666}]
|
{ id: 3458, name: 'Invalid Subcategory', parent_category_id: 6666}]
|
||||||
});
|
});
|
||||||
|
|
||||||
var categories = site.get('categories');
|
const categories = site.get('categories');
|
||||||
site.get('sortedCategories');
|
site.get('sortedCategories');
|
||||||
|
|
||||||
present(categories, "The categories are present");
|
present(categories, "The categories are present");
|
||||||
equal(categories.length, 3, "it loaded all three categories");
|
equal(categories.length, 3, "it loaded all three categories");
|
||||||
|
|
||||||
var parent = categories.findBy('id', 1234);
|
const parent = categories.findBy('id', 1234);
|
||||||
present(parent, "it loaded the parent category");
|
present(parent, "it loaded the parent category");
|
||||||
blank(parent.get('parentCategory'), 'it has no parent category');
|
blank(parent.get('parentCategory'), 'it has no parent category');
|
||||||
|
|
||||||
var subcategory = categories.findBy('id', 3456);
|
const subcategory = categories.findBy('id', 3456);
|
||||||
present(subcategory, "it loaded the subcategory");
|
present(subcategory, "it loaded the subcategory");
|
||||||
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
||||||
|
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
module("Discourse.TopicTrackingState");
|
import TopicTrackingState from 'discourse/models/topic-tracking-state';
|
||||||
|
|
||||||
test("sync", function () {
|
module("model:topic-tracking-state");
|
||||||
|
|
||||||
var state = Discourse.TopicTrackingState.create();
|
test("sync", function (assert) {
|
||||||
// fake track it
|
const state = TopicTrackingState.create();
|
||||||
state.states["t111"] = {last_read_post_number: null};
|
state.states["t111"] = {last_read_post_number: null};
|
||||||
|
|
||||||
state.updateSeen(111, 7);
|
state.updateSeen(111, 7);
|
||||||
var list = {topics: [{
|
const list = {topics: [{
|
||||||
highest_post_number: null,
|
highest_post_number: null,
|
||||||
id: 111,
|
id: 111,
|
||||||
unread: 10,
|
unread: 10,
|
||||||
new_posts: 10
|
new_posts: 10
|
||||||
}]};
|
}]};
|
||||||
|
|
||||||
state.sync(list, "new");
|
state.sync(list, "new");
|
||||||
|
assert.equal(list.topics.length, 0, "expect new topic to be removed as it was seen");
|
||||||
equal(list.topics.length, 0, "expect new topic to be removed as it was seen");
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user