mirror of
https://github.com/discourse/discourse.git
synced 2025-02-08 04:18:23 +00:00
FIX: Update site data when we receive a list of categories
When we receive a list of categories, we should store them so that we are able to query them in the browser without a page refresh. This removes a previous fix for the same issue that was much less general.
This commit is contained in:
parent
5c5d8a307a
commit
720101b3ee
@ -2,6 +2,7 @@ import PreloadStore from "preload-store";
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import Topic from "discourse/models/topic";
|
import Topic from "discourse/models/topic";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
|
import Site from "discourse/models/site";
|
||||||
|
|
||||||
const CategoryList = Ember.ArrayProxy.extend({
|
const CategoryList = Ember.ArrayProxy.extend({
|
||||||
init() {
|
init() {
|
||||||
@ -76,7 +77,9 @@ CategoryList.reopenClass({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
categories.pushObject(store.createRecord("category", c));
|
const record = Site.current().updateCategory(c);
|
||||||
|
record.setupGroupsAndPermissions();
|
||||||
|
categories.pushObject(record);
|
||||||
});
|
});
|
||||||
return categories;
|
return categories;
|
||||||
},
|
},
|
||||||
|
@ -87,7 +87,7 @@ const Site = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Returns it in the correct order, by setting
|
// Returns it in the correct order, by setting
|
||||||
@discourseComputed
|
@discourseComputed("categories.[]")
|
||||||
categoriesList() {
|
categoriesList() {
|
||||||
return this.siteSettings.fixed_category_positions
|
return this.siteSettings.fixed_category_positions
|
||||||
? this.categories
|
? this.categories
|
||||||
@ -123,11 +123,13 @@ const Site = RestModel.extend({
|
|||||||
|
|
||||||
if (existingCategory) {
|
if (existingCategory) {
|
||||||
existingCategory.setProperties(newCategory);
|
existingCategory.setProperties(newCategory);
|
||||||
|
return existingCategory;
|
||||||
} else {
|
} else {
|
||||||
// TODO insert in right order?
|
// TODO insert in right order?
|
||||||
newCategory = this.store.createRecord("category", newCategory);
|
newCategory = this.store.createRecord("category", newCategory);
|
||||||
categories.pushObject(newCategory);
|
categories.pushObject(newCategory);
|
||||||
this.categoriesById[categoryId] = newCategory;
|
this.categoriesById[categoryId] = newCategory;
|
||||||
|
return newCategory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -21,28 +21,9 @@ export default (filterArg, params) => {
|
|||||||
modelParams.slug,
|
modelParams.slug,
|
||||||
modelParams.parentSlug
|
modelParams.parentSlug
|
||||||
);
|
);
|
||||||
if (!category) {
|
if (category) {
|
||||||
return Category.reloadBySlug(
|
return { category };
|
||||||
modelParams.slug,
|
|
||||||
modelParams.parentSlug
|
|
||||||
).then(atts => {
|
|
||||||
if (modelParams.parentSlug) {
|
|
||||||
atts.category.parentCategory = Category.findBySlug(
|
|
||||||
modelParams.parentSlug
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const record = this.store.createRecord("category", atts.category);
|
|
||||||
record.setupGroupsAndPermissions();
|
|
||||||
this.site.updateCategory(record);
|
|
||||||
return {
|
|
||||||
category: Category.findBySlug(
|
|
||||||
modelParams.slug,
|
|
||||||
modelParams.parentSlug
|
|
||||||
)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return { category };
|
|
||||||
},
|
},
|
||||||
|
|
||||||
afterModel(model, transition) {
|
afterModel(model, transition) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user