REFACTOR: Migrate `Discourse.Post` to imports
This commit is contained in:
parent
932c169d46
commit
7e44065bcb
|
@ -7,6 +7,7 @@ import { propertyGreaterThan, propertyLessThan } from "discourse/lib/computed";
|
|||
import { on, observes } from "discourse-common/utils/decorators";
|
||||
import { sanitizeAsync } from "discourse/lib/text";
|
||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||
import Post from "discourse/models/post";
|
||||
|
||||
function customTagArray(fieldName) {
|
||||
return Ember.computed(fieldName, function() {
|
||||
|
@ -59,19 +60,19 @@ export default Controller.extend(ModalFunctionality, {
|
|||
refresh(postId, postVersion) {
|
||||
this.set("loading", true);
|
||||
|
||||
Discourse.Post.loadRevision(postId, postVersion).then(result => {
|
||||
Post.loadRevision(postId, postVersion).then(result => {
|
||||
this.setProperties({ loading: false, model: result });
|
||||
});
|
||||
},
|
||||
|
||||
hide(postId, postVersion) {
|
||||
Discourse.Post.hideRevision(postId, postVersion).then(() =>
|
||||
Post.hideRevision(postId, postVersion).then(() =>
|
||||
this.refresh(postId, postVersion)
|
||||
);
|
||||
},
|
||||
|
||||
show(postId, postVersion) {
|
||||
Discourse.Post.showRevision(postId, postVersion).then(() =>
|
||||
Post.showRevision(postId, postVersion).then(() =>
|
||||
this.refresh(postId, postVersion)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -16,7 +16,7 @@ import Composer from "discourse/models/composer";
|
|||
import { Promise } from "rsvp";
|
||||
|
||||
const Post = RestModel.extend({
|
||||
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
|
||||
// TODO: Remove this once one instantiate all `Post` models via the store.
|
||||
siteSettings: Ember.computed({
|
||||
get() {
|
||||
return Discourse.SiteSettings;
|
||||
|
@ -320,7 +320,7 @@ const Post = RestModel.extend({
|
|||
|
||||
// need to wait to hear back from server (stuff may not be loaded)
|
||||
|
||||
return Discourse.Post.updateBookmark(this.id, this.bookmarked)
|
||||
return Post.updateBookmark(this.id, this.bookmarked)
|
||||
.then(result => {
|
||||
this.set("topic.bookmarked", result.topic_bookmarked);
|
||||
this.appEvents.trigger("page:bookmark-post-toggled", this);
|
||||
|
@ -417,7 +417,7 @@ Post.reopenClass({
|
|||
|
||||
loadQuote(postId) {
|
||||
return ajax(`/posts/${postId}.json`).then(result => {
|
||||
const post = Discourse.Post.create(result);
|
||||
const post = Post.create(result);
|
||||
return Quote.build(post, post.raw, { raw: true, full: true });
|
||||
});
|
||||
},
|
||||
|
|
|
@ -91,8 +91,7 @@ JS
|
|||
"discourse/models/site",
|
||||
"discourse/models/user",
|
||||
"discourse/models/session",
|
||||
"discourse/models/model",
|
||||
"discourse/models/post"
|
||||
"discourse/models/model"
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import EmberObject from "@ember/object";
|
|||
import { currentUser } from "helpers/qunit-helpers";
|
||||
import AppEvents from "discourse/services/app-events";
|
||||
import Composer from "discourse/models/composer";
|
||||
import Post from "discourse/models/post";
|
||||
import createStore from "helpers/create-store";
|
||||
|
||||
QUnit.module("model:composer");
|
||||
|
@ -247,7 +248,7 @@ QUnit.test("editingFirstPost", assert => {
|
|||
const composer = createComposer();
|
||||
assert.ok(!composer.get("editingFirstPost"), "it's false by default");
|
||||
|
||||
const post = Discourse.Post.create({ id: 123, post_number: 2 });
|
||||
const post = Post.create({ id: 123, post_number: 2 });
|
||||
composer.setProperties({ post: post, action: Composer.EDIT });
|
||||
assert.ok(
|
||||
!composer.get("editingFirstPost"),
|
||||
|
@ -265,7 +266,7 @@ QUnit.test("clearState", assert => {
|
|||
const composer = createComposer({
|
||||
originalText: "asdf",
|
||||
reply: "asdf2",
|
||||
post: Discourse.Post.create({ id: 1 }),
|
||||
post: Post.create({ id: 1 }),
|
||||
title: "wat"
|
||||
});
|
||||
|
||||
|
@ -329,7 +330,7 @@ QUnit.test("Title length for static page topics as admin", assert => {
|
|||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
const composer = createComposer();
|
||||
|
||||
const post = Discourse.Post.create({
|
||||
const post = Post.create({
|
||||
id: 123,
|
||||
post_number: 2,
|
||||
static_doc: true
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
QUnit.module("model:post-stream");
|
||||
|
||||
import Post from "discourse/models/post";
|
||||
import createStore from "helpers/create-store";
|
||||
|
||||
QUnit.module("model:post-stream");
|
||||
|
||||
const buildStream = function(id, stream) {
|
||||
const store = createStore();
|
||||
const topic = store.createRecord("topic", { id, chunk_size: 5 });
|
||||
|
@ -173,7 +174,7 @@ QUnit.test("updateFromJson", assert => {
|
|||
});
|
||||
|
||||
assert.equal(postStream.get("posts.length"), 1, "it loaded the posts");
|
||||
assert.containsInstance(postStream.get("posts"), Discourse.Post);
|
||||
assert.containsInstance(postStream.get("posts"), Post);
|
||||
|
||||
assert.equal(postStream.get("extra_property"), 12);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
QUnit.module("Discourse.Post");
|
||||
import Post from "discourse/models/post";
|
||||
|
||||
QUnit.module("model: Post");
|
||||
|
||||
var buildPost = function(args) {
|
||||
return Discourse.Post.create(
|
||||
return Post.create(
|
||||
_.merge(
|
||||
{
|
||||
id: 1,
|
||||
|
@ -14,13 +16,13 @@ var buildPost = function(args) {
|
|||
};
|
||||
|
||||
QUnit.test("defaults", assert => {
|
||||
var post = Discourse.Post.create({ id: 1 });
|
||||
var post = Post.create({ id: 1 });
|
||||
assert.blank(post.get("deleted_at"), "it has no deleted_at by default");
|
||||
assert.blank(post.get("deleted_by"), "there is no deleted_by by default");
|
||||
});
|
||||
|
||||
QUnit.test("new_user", assert => {
|
||||
var post = Discourse.Post.create({ trust_level: 0 });
|
||||
var post = Post.create({ trust_level: 0 });
|
||||
assert.ok(post.get("new_user"), "post is from a new user");
|
||||
|
||||
post.set("trust_level", 1);
|
||||
|
@ -28,7 +30,7 @@ QUnit.test("new_user", assert => {
|
|||
});
|
||||
|
||||
QUnit.test("firstPost", assert => {
|
||||
var post = Discourse.Post.create({ post_number: 1 });
|
||||
var post = Post.create({ post_number: 1 });
|
||||
assert.ok(post.get("firstPost"), "it's the first post");
|
||||
|
||||
post.set("post_number", 10);
|
||||
|
@ -36,13 +38,13 @@ QUnit.test("firstPost", assert => {
|
|||
});
|
||||
|
||||
QUnit.test("updateFromPost", assert => {
|
||||
var post = Discourse.Post.create({
|
||||
var post = Post.create({
|
||||
post_number: 1,
|
||||
raw: "hello world"
|
||||
});
|
||||
|
||||
post.updateFromPost(
|
||||
Discourse.Post.create({
|
||||
Post.create({
|
||||
raw: "different raw",
|
||||
wat: function() {
|
||||
return 123;
|
||||
|
|
Loading…
Reference in New Issue