...
 
Commits (2)
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const GENERAL_ATTRIBUTES = [
"updated_at",
......@@ -6,7 +7,7 @@ const GENERAL_ATTRIBUTES = [
"release_notes_link"
];
const AdminDashboard = Discourse.Model.extend({});
const AdminDashboard = EmberObject.extend({});
AdminDashboard.reopenClass({
fetch() {
......
import discourseComputed from "discourse-common/utils/decorators";
import { not } from "@ember/object/computed";
import EmberObject from "@ember/object";
export default Discourse.Model.extend({
export default EmberObject.extend({
restoreDisabled: not("restoreEnabled"),
@discourseComputed("allowRestore", "isOperationRunning")
......
import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error";
import EmberObject from "@ember/object";
const Backup = Discourse.Model.extend({
const Backup = EmberObject.extend({
destroy() {
return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
},
......
......@@ -4,8 +4,9 @@ import {
on
} from "discourse-common/utils/decorators";
import { propertyNotEqual } from "discourse/lib/computed";
import EmberObject from "@ember/object";
const ColorSchemeColor = Discourse.Model.extend({
const ColorSchemeColor = EmberObject.extend({
@on("init")
startTrackingChanges() {
this.set("originals", { hex: this.hex || "FFFFFF" });
......
......@@ -2,8 +2,9 @@ import discourseComputed from "discourse-common/utils/decorators";
import { not } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
import ColorSchemeColor from "admin/models/color-scheme-color";
import EmberObject from "@ember/object";
const ColorScheme = Discourse.Model.extend(Ember.Copyable, {
const ColorScheme = EmberObject.extend(Ember.Copyable, {
init() {
this._super(...arguments);
......
import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";
const EmailLog = Discourse.Model.extend({});
const EmailLog = EmberObject.extend({});
EmailLog.reopenClass({
create(attrs) {
......
import { ajax } from "discourse/lib/ajax";
const EmailPreview = Discourse.Model.extend({});
import EmberObject from "@ember/object";
const EmailPreview = EmberObject.extend({});
export function oneWeekAgo() {
return moment()
......
import { ajax } from "discourse/lib/ajax";
const EmailSettings = Discourse.Model.extend({});
import EmberObject from "@ember/object";
const EmailSettings = EmberObject.extend({});
EmailSettings.reopenClass({
find: function() {
......
import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";
const IncomingEmail = Discourse.Model.extend({});
const IncomingEmail = EmberObject.extend({});
IncomingEmail.reopenClass({
create(attrs) {
......
import { ajax } from "discourse/lib/ajax";
const Permalink = Discourse.Model.extend({
import EmberObject from "@ember/object";
const Permalink = EmberObject.extend({
save: function() {
return ajax("/admin/permalinks.json", {
type: "POST",
......
......@@ -17,7 +17,7 @@ import { renderAvatar } from "discourse/helpers/user-avatar";
// and you want to ensure cache is reset
export const SCHEMA_VERSION = 4;
const Report = Discourse.Model.extend({
const Report = EmberObject.extend({
average: false,
percent: false,
higher_is_better: true,
......
import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const ScreenedEmail = Discourse.Model.extend({
const ScreenedEmail = EmberObject.extend({
@discourseComputed("action")
actionName(action) {
return I18n.t("admin.logs.screened_actions." + action);
......
import discourseComputed from "discourse-common/utils/decorators";
import { equal } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const ScreenedIpAddress = Discourse.Model.extend({
const ScreenedIpAddress = EmberObject.extend({
@discourseComputed("action_name")
actionName(actionName) {
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
......
import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const ScreenedUrl = Discourse.Model.extend({
const ScreenedUrl = EmberObject.extend({
@discourseComputed("action")
actionName(action) {
return I18n.t("admin.logs.screened_actions." + action);
......
import { ajax } from "discourse/lib/ajax";
import Setting from "admin/mixins/setting-object";
import EmberObject from "@ember/object";
const SiteSetting = Discourse.Model.extend(Setting, {});
const SiteSetting = EmberObject.extend(Setting, {});
SiteSetting.reopenClass({
findAll() {
......
import Setting from "admin/mixins/setting-object";
import EmberObject from "@ember/object";
export default Discourse.Model.extend(Setting, {});
export default EmberObject.extend(Setting, {});
import discourseComputed from "discourse-common/utils/decorators";
import EmberObject from "@ember/object";
export default Discourse.Model.extend({
export default EmberObject.extend({
@discourseComputed("days_visited", "time_period")
days_visited_percent(daysVisited, timePeriod) {
return Math.round((daysVisited * 100) / timePeriod);
......
import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const VersionCheck = Discourse.Model.extend({
const VersionCheck = EmberObject.extend({
@discourseComputed("updated_at")
noCheckPerformed(updatedAt) {
return updatedAt === null;
......
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
const WatchedWord = Discourse.Model.extend({
const WatchedWord = EmberObject.extend({
save() {
return ajax(
"/admin/logs/watched_words" + (this.id ? "/" + this.id : "") + ".json",
......
......@@ -36,7 +36,6 @@
//= require ./discourse/lib/show-modal
//= require ./discourse/mixins/scrolling
//= require ./discourse/lib/ajax-error
//= require ./discourse/models/model
//= require ./discourse/models/result-set
//= require ./discourse/models/store
//= require ./discourse/models/action-summary
......
......@@ -6,6 +6,8 @@ import {
} from "discourse-common/utils/decorators";
import computed from "@ember/object/computed";
import FocusEvent from "discourse-common/mixins/focus-event";
import EmberObject from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
const _pluginCallbacks = [];
......@@ -206,4 +208,14 @@ const Discourse = Ember.Application.extend(FocusEvent, {
})
}).create();
Object.defineProperty(Discourse, "Model", {
get() {
deprecated("Use an `@ember/object` instead of Discourse.Model", {
since: "2.4.0",
dropFrom: "2.5.0"
});
return EmberObject;
}
});
export default Discourse;
import { ajax } from "discourse/lib/ajax";
const Draft = Discourse.Model.extend();
import EmberObject from "@ember/object";
const Draft = EmberObject.extend();
Draft.reopenClass({
clear(key, sequence) {
......
import Model from "discourse/models/model";
// A trivial model we use to handle input validation
export default Model.extend();
import EmberObject from "@ember/object";
export default EmberObject.extend();
......@@ -4,7 +4,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import { userPath } from "discourse/lib/url";
import { Promise } from "rsvp";
const Invite = Discourse.Model.extend({
const Invite = EmberObject.extend({
rescind() {
ajax("/invites", {
type: "DELETE",
......
import { ajax } from "discourse/lib/ajax";
const LivePostCounts = Discourse.Model.extend({});
import EmberObject from "@ember/object";
const LivePostCounts = EmberObject.extend({});
LivePostCounts.reopenClass({
find() {
......
import { isEmpty } from "@ember/utils";
import EmberObject from "@ember/object";
const Model = EmberObject.extend();
Model.reopenClass({
extractByKey(collection, klass) {
const retval = {};
if (isEmpty(collection)) {
return retval;
}
collection.forEach(function(item) {
retval[item.id] = klass.create(item);
});
return retval;
}
});
export default Model;
......@@ -2,8 +2,10 @@ import discourseComputed from "discourse-common/utils/decorators";
import { toTitleCase } from "discourse/lib/formatter";
import { emojiUnescape } from "discourse/lib/text";
import Category from "discourse/models/category";
import EmberObject from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
const NavItem = Discourse.Model.extend({
const NavItem = EmberObject.extend({
@discourseComputed("categoryName", "name")
title(categoryName, name) {
const extra = {};
......@@ -254,3 +256,13 @@ export function addNavItem(item) {
NavItem.extraNavItems.push(navItem);
return navItem;
}
Object.defineProperty(Discourse, "NavItem", {
get() {
deprecated("Import the NavItem object instead of using Discourse.NavItem", {
since: "2.4.0",
dropFrom: "2.5.0"
});
return NavItem;
}
});
import discourseComputed from "discourse-common/utils/decorators";
import EmberObject from "@ember/object";
const PermissionType = Discourse.Model.extend({
const PermissionType = EmberObject.extend({
@discourseComputed("id")
description(id) {
var key = "";
......
......@@ -2,11 +2,24 @@ import { notEmpty } from "@ember/object/computed";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest";
import Model from "discourse/models/model";
import { getOwner } from "discourse-common/lib/get-owner";
import { Promise } from "rsvp";
import Category from "discourse/models/category";
import Session from "discourse/models/session";
import { isEmpty } from "@ember/utils";
import User from "discourse/models/user";
function extractByKey(collection, klass) {
const retval = {};
if (isEmpty(collection)) {
return retval;
}
collection.forEach(function(item) {
retval[item.id] = klass.create(item);
});
return retval;
}
// Whether to show the category badge in topic lists
function displayCategoryInList(site, category) {
......@@ -139,8 +152,8 @@ TopicList.reopenClass({
// Stitch together our side loaded data
const categories = Category.list(),
users = Model.extractByKey(result.users, Discourse.User),
groups = Model.extractByKey(result.primary_groups, EmberObject);
users = extractByKey(result.users, User),
groups = extractByKey(result.primary_groups, EmberObject);
return result.topic_list[listKey].map(t => {
t.category = categories.findBy("id", t.category_id);
......
......@@ -8,6 +8,7 @@ import {
import { defaultHomepage } from "discourse/lib/utilities";
import PreloadStore from "preload-store";
import Category from "discourse/models/category";
import EmberObject from "@ember/object";
function isNew(topic) {
return (
......@@ -25,7 +26,7 @@ function isUnread(topic) {
);
}
const TopicTrackingState = Discourse.Model.extend({
const TopicTrackingState = EmberObject.extend({
messageCount: 0,
@on("init")
......
/**
A data model representing a group of UserActions
**/
export default Discourse.Model.extend({
push: function(item) {
import EmberObject from "@ember/object";
export default EmberObject.extend({
push(item) {
if (!this.items) {
this.items = [];
}
......
......@@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
import { Promise } from "rsvp";
import Topic from "discourse/models/topic";
import EmberObject from "@ember/object";
const UserBadge = Discourse.Model.extend({
const UserBadge = EmberObject.extend({
@discourseComputed
postUrl: function() {
if (this.topic_title) {
......
......@@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
import { url } from "discourse/lib/computed";
import UserAction from "discourse/models/user-action";
import { Promise } from "rsvp";
import EmberObject from "@ember/object";
export default Discourse.Model.extend({
export default EmberObject.extend({
loaded: false,
@on("init")
......
......@@ -89,7 +89,6 @@ JS
"discourse/routes/discourse",
"discourse/models/site",
"discourse/models/user",
"discourse/models/model"
]
)
......
import EmberObject from "@ember/object";
import Model from "discourse/models/model";
QUnit.module("model:discourse");
QUnit.test(
"extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids",
assert => {
var firstObject = { id: "id_1", foo: "foo_1" };
var secondObject = { id: "id_2", foo: "foo_2" };
var actual = Model.extractByKey([firstObject, secondObject], EmberObject);
var expected = {
id_1: EmberObject.create(firstObject),
id_2: EmberObject.create(secondObject)
};
assert.ok(_.isEqual(actual, expected));
}
);
QUnit.test(
"extractByKey: returns an empty hash if there isn't anything to convert",
assert => {
assert.deepEqual(
Model.extractByKey(),
{},
"when called without parameters"
);
assert.deepEqual(
Model.extractByKey([]),
{},
"when called with an empty array"
);
}
);