Skip to content
Permalink
Browse files

REFACTOR: Remove `Discourse.Model`

  • Loading branch information
eviltrout committed Nov 8, 2019
1 parent fa71919 commit f03edb36bee1842ffabc0b502ee680fa20cad00a
Showing with 90 additions and 96 deletions.
  1. +2 −1 app/assets/javascripts/admin/models/admin-dashboard.js.es6
  2. +2 −1 app/assets/javascripts/admin/models/backup-status.js.es6
  3. +2 −1 app/assets/javascripts/admin/models/backup.js.es6
  4. +2 −1 app/assets/javascripts/admin/models/color-scheme-color.js.es6
  5. +2 −1 app/assets/javascripts/admin/models/color-scheme.js.es6
  6. +2 −1 app/assets/javascripts/admin/models/email-log.js.es6
  7. +3 −1 app/assets/javascripts/admin/models/email-preview.js.es6
  8. +3 −1 app/assets/javascripts/admin/models/email-settings.js.es6
  9. +2 −1 app/assets/javascripts/admin/models/incoming-email.js.es6
  10. +3 −1 app/assets/javascripts/admin/models/permalink.js.es6
  11. +1 −1 app/assets/javascripts/admin/models/report.js.es6
  12. +2 −1 app/assets/javascripts/admin/models/screened-email.js.es6
  13. +2 −1 app/assets/javascripts/admin/models/screened-ip-address.js.es6
  14. +2 −1 app/assets/javascripts/admin/models/screened-url.js.es6
  15. +2 −1 app/assets/javascripts/admin/models/site-setting.js.es6
  16. +2 −1 app/assets/javascripts/admin/models/theme-settings.js.es6
  17. +2 −1 app/assets/javascripts/admin/models/tl3-requirements.js.es6
  18. +2 −1 app/assets/javascripts/admin/models/version-check.js.es6
  19. +1 −1 app/assets/javascripts/admin/models/watched-word.js.es6
  20. +0 −1 app/assets/javascripts/application.js
  21. +12 −0 app/assets/javascripts/discourse.js.es6
  22. +3 −1 app/assets/javascripts/discourse/models/draft.js.es6
  23. +2 −4 app/assets/javascripts/discourse/models/input-validation.js.es6
  24. +1 −1 app/assets/javascripts/discourse/models/invite.js.es6
  25. +3 −1 app/assets/javascripts/discourse/models/live-post-counts.es6
  26. +0 −19 app/assets/javascripts/discourse/models/model.js.es6
  27. +2 −1 app/assets/javascripts/discourse/models/nav-item.js.es6
  28. +2 −1 app/assets/javascripts/discourse/models/permission-type.js.es6
  29. +16 −3 app/assets/javascripts/discourse/models/topic-list.js.es6
  30. +2 −1 app/assets/javascripts/discourse/models/topic-tracking-state.js.es6
  31. +4 −5 app/assets/javascripts/discourse/models/user-action-group.js.es6
  32. +2 −1 app/assets/javascripts/discourse/models/user-badge.js.es6
  33. +2 −1 app/assets/javascripts/discourse/models/user-posts-stream.js.es6
  34. +0 −1 lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb
  35. +0 −36 test/javascripts/models/model-test.js.es6
@@ -1,12 +1,13 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";


const GENERAL_ATTRIBUTES = [ const GENERAL_ATTRIBUTES = [
"updated_at", "updated_at",
"discourse_updated_at", "discourse_updated_at",
"release_notes_link" "release_notes_link"
]; ];


const AdminDashboard = Discourse.Model.extend({}); const AdminDashboard = EmberObject.extend({});


AdminDashboard.reopenClass({ AdminDashboard.reopenClass({
fetch() { fetch() {
@@ -1,7 +1,8 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { not } from "@ember/object/computed"; import { not } from "@ember/object/computed";
import EmberObject from "@ember/object";


export default Discourse.Model.extend({ export default EmberObject.extend({
restoreDisabled: not("restoreEnabled"), restoreDisabled: not("restoreEnabled"),


@discourseComputed("allowRestore", "isOperationRunning") @discourseComputed("allowRestore", "isOperationRunning")
@@ -1,7 +1,8 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import EmberObject from "@ember/object";


const Backup = Discourse.Model.extend({ const Backup = EmberObject.extend({
destroy() { destroy() {
return ajax("/admin/backups/" + this.filename, { type: "DELETE" }); return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
}, },
@@ -4,8 +4,9 @@ import {
on on
} from "discourse-common/utils/decorators"; } from "discourse-common/utils/decorators";
import { propertyNotEqual } from "discourse/lib/computed"; import { propertyNotEqual } from "discourse/lib/computed";
import EmberObject from "@ember/object";


const ColorSchemeColor = Discourse.Model.extend({ const ColorSchemeColor = EmberObject.extend({
@on("init") @on("init")
startTrackingChanges() { startTrackingChanges() {
this.set("originals", { hex: this.hex || "FFFFFF" }); 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 { not } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import ColorSchemeColor from "admin/models/color-scheme-color"; 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() { init() {
this._super(...arguments); this._super(...arguments);


@@ -1,7 +1,8 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user"; import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";


const EmailLog = Discourse.Model.extend({}); const EmailLog = EmberObject.extend({});


EmailLog.reopenClass({ EmailLog.reopenClass({
create(attrs) { create(attrs) {
@@ -1,5 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
const EmailPreview = Discourse.Model.extend({}); import EmberObject from "@ember/object";

const EmailPreview = EmberObject.extend({});


export function oneWeekAgo() { export function oneWeekAgo() {
return moment() return moment()
@@ -1,5 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
const EmailSettings = Discourse.Model.extend({}); import EmberObject from "@ember/object";

const EmailSettings = EmberObject.extend({});


EmailSettings.reopenClass({ EmailSettings.reopenClass({
find: function() { find: function() {
@@ -1,7 +1,8 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user"; import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";


const IncomingEmail = Discourse.Model.extend({}); const IncomingEmail = EmberObject.extend({});


IncomingEmail.reopenClass({ IncomingEmail.reopenClass({
create(attrs) { create(attrs) {
@@ -1,5 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
const Permalink = Discourse.Model.extend({ import EmberObject from "@ember/object";

const Permalink = EmberObject.extend({
save: function() { save: function() {
return ajax("/admin/permalinks.json", { return ajax("/admin/permalinks.json", {
type: "POST", type: "POST",
@@ -17,7 +17,7 @@ import { renderAvatar } from "discourse/helpers/user-avatar";
// and you want to ensure cache is reset // and you want to ensure cache is reset
export const SCHEMA_VERSION = 4; export const SCHEMA_VERSION = 4;


const Report = Discourse.Model.extend({ const Report = EmberObject.extend({
average: false, average: false,
percent: false, percent: false,
higher_is_better: true, higher_is_better: true,
@@ -1,7 +1,8 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";


const ScreenedEmail = Discourse.Model.extend({ const ScreenedEmail = EmberObject.extend({
@discourseComputed("action") @discourseComputed("action")
actionName(action) { actionName(action) {
return I18n.t("admin.logs.screened_actions." + action); return I18n.t("admin.logs.screened_actions." + action);
@@ -1,8 +1,9 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { equal } from "@ember/object/computed"; import { equal } from "@ember/object/computed";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";


const ScreenedIpAddress = Discourse.Model.extend({ const ScreenedIpAddress = EmberObject.extend({
@discourseComputed("action_name") @discourseComputed("action_name")
actionName(actionName) { actionName(actionName) {
return I18n.t(`admin.logs.screened_ips.actions.${actionName}`); return I18n.t(`admin.logs.screened_ips.actions.${actionName}`);
@@ -1,7 +1,8 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";


const ScreenedUrl = Discourse.Model.extend({ const ScreenedUrl = EmberObject.extend({
@discourseComputed("action") @discourseComputed("action")
actionName(action) { actionName(action) {
return I18n.t("admin.logs.screened_actions." + action); return I18n.t("admin.logs.screened_actions." + action);
@@ -1,7 +1,8 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import Setting from "admin/mixins/setting-object"; 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({ SiteSetting.reopenClass({
findAll() { findAll() {
@@ -1,3 +1,4 @@
import Setting from "admin/mixins/setting-object"; import Setting from "admin/mixins/setting-object";
import EmberObject from "@ember/object";


export default Discourse.Model.extend(Setting, {}); export default EmberObject.extend(Setting, {});
@@ -1,6 +1,7 @@
import discourseComputed from "discourse-common/utils/decorators"; 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") @discourseComputed("days_visited", "time_period")
days_visited_percent(daysVisited, timePeriod) { days_visited_percent(daysVisited, timePeriod) {
return Math.round((daysVisited * 100) / timePeriod); return Math.round((daysVisited * 100) / timePeriod);
@@ -1,7 +1,8 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";


const VersionCheck = Discourse.Model.extend({ const VersionCheck = EmberObject.extend({
@discourseComputed("updated_at") @discourseComputed("updated_at")
noCheckPerformed(updatedAt) { noCheckPerformed(updatedAt) {
return updatedAt === null; return updatedAt === null;
@@ -1,7 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";


const WatchedWord = Discourse.Model.extend({ const WatchedWord = EmberObject.extend({
save() { save() {
return ajax( return ajax(
"/admin/logs/watched_words" + (this.id ? "/" + this.id : "") + ".json", "/admin/logs/watched_words" + (this.id ? "/" + this.id : "") + ".json",
@@ -36,7 +36,6 @@
//= require ./discourse/lib/show-modal //= require ./discourse/lib/show-modal
//= require ./discourse/mixins/scrolling //= require ./discourse/mixins/scrolling
//= require ./discourse/lib/ajax-error //= require ./discourse/lib/ajax-error
//= require ./discourse/models/model
//= require ./discourse/models/result-set //= require ./discourse/models/result-set
//= require ./discourse/models/store //= require ./discourse/models/store
//= require ./discourse/models/action-summary //= require ./discourse/models/action-summary
@@ -6,6 +6,8 @@ import {
} from "discourse-common/utils/decorators"; } from "discourse-common/utils/decorators";
import computed from "@ember/object/computed"; import computed from "@ember/object/computed";
import FocusEvent from "discourse-common/mixins/focus-event"; import FocusEvent from "discourse-common/mixins/focus-event";
import EmberObject from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";


const _pluginCallbacks = []; const _pluginCallbacks = [];


@@ -206,4 +208,14 @@ const Discourse = Ember.Application.extend(FocusEvent, {
}) })
}).create(); }).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; export default Discourse;
@@ -1,5 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
const Draft = Discourse.Model.extend(); import EmberObject from "@ember/object";

const Draft = EmberObject.extend();


Draft.reopenClass({ Draft.reopenClass({
clear(key, sequence) { clear(key, sequence) {
@@ -1,4 +1,2 @@
import Model from "discourse/models/model"; import EmberObject from "@ember/object";

export default EmberObject.extend();
// A trivial model we use to handle input validation
export default Model.extend();
@@ -4,7 +4,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import { userPath } from "discourse/lib/url"; import { userPath } from "discourse/lib/url";
import { Promise } from "rsvp"; import { Promise } from "rsvp";


const Invite = Discourse.Model.extend({ const Invite = EmberObject.extend({
rescind() { rescind() {
ajax("/invites", { ajax("/invites", {
type: "DELETE", type: "DELETE",
@@ -1,5 +1,7 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
const LivePostCounts = Discourse.Model.extend({}); import EmberObject from "@ember/object";

const LivePostCounts = EmberObject.extend({});


LivePostCounts.reopenClass({ LivePostCounts.reopenClass({
find() { find() {

This file was deleted.

@@ -2,8 +2,9 @@ import discourseComputed from "discourse-common/utils/decorators";
import { toTitleCase } from "discourse/lib/formatter"; import { toTitleCase } from "discourse/lib/formatter";
import { emojiUnescape } from "discourse/lib/text"; import { emojiUnescape } from "discourse/lib/text";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import EmberObject from "@ember/object";


const NavItem = Discourse.Model.extend({ const NavItem = EmberObject.extend({
@discourseComputed("categoryName", "name") @discourseComputed("categoryName", "name")
title(categoryName, name) { title(categoryName, name) {
const extra = {}; const extra = {};
@@ -1,6 +1,7 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import EmberObject from "@ember/object";


const PermissionType = Discourse.Model.extend({ const PermissionType = EmberObject.extend({
@discourseComputed("id") @discourseComputed("id")
description(id) { description(id) {
var key = ""; var key = "";
@@ -2,11 +2,24 @@ import { notEmpty } from "@ember/object/computed";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest"; import RestModel from "discourse/models/rest";
import Model from "discourse/models/model";
import { getOwner } from "discourse-common/lib/get-owner"; import { getOwner } from "discourse-common/lib/get-owner";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import Session from "discourse/models/session"; 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 // Whether to show the category badge in topic lists
function displayCategoryInList(site, category) { function displayCategoryInList(site, category) {
@@ -139,8 +152,8 @@ TopicList.reopenClass({
// Stitch together our side loaded data // Stitch together our side loaded data


const categories = Category.list(), const categories = Category.list(),
users = Model.extractByKey(result.users, Discourse.User), users = extractByKey(result.users, User),
groups = Model.extractByKey(result.primary_groups, EmberObject); groups = extractByKey(result.primary_groups, EmberObject);


return result.topic_list[listKey].map(t => { return result.topic_list[listKey].map(t => {
t.category = categories.findBy("id", t.category_id); t.category = categories.findBy("id", t.category_id);
@@ -8,6 +8,7 @@ import {
import { defaultHomepage } from "discourse/lib/utilities"; import { defaultHomepage } from "discourse/lib/utilities";
import PreloadStore from "preload-store"; import PreloadStore from "preload-store";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import EmberObject from "@ember/object";


function isNew(topic) { function isNew(topic) {
return ( return (
@@ -25,7 +26,7 @@ function isUnread(topic) {
); );
} }


const TopicTrackingState = Discourse.Model.extend({ const TopicTrackingState = EmberObject.extend({
messageCount: 0, messageCount: 0,


@on("init") @on("init")
@@ -1,8 +1,7 @@
/** import EmberObject from "@ember/object";
A data model representing a group of UserActions
**/ export default EmberObject.extend({
export default Discourse.Model.extend({ push(item) {
push: function(item) {
if (!this.items) { if (!this.items) {
this.items = []; this.items = [];
} }
@@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge"; import Badge from "discourse/models/badge";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import Topic from "discourse/models/topic"; import Topic from "discourse/models/topic";
import EmberObject from "@ember/object";


const UserBadge = Discourse.Model.extend({ const UserBadge = EmberObject.extend({
@discourseComputed @discourseComputed
postUrl: function() { postUrl: function() {
if (this.topic_title) { if (this.topic_title) {
@@ -3,8 +3,9 @@ import { ajax } from "discourse/lib/ajax";
import { url } from "discourse/lib/computed"; import { url } from "discourse/lib/computed";
import UserAction from "discourse/models/user-action"; import UserAction from "discourse/models/user-action";
import { Promise } from "rsvp"; import { Promise } from "rsvp";
import EmberObject from "@ember/object";


export default Discourse.Model.extend({ export default EmberObject.extend({
loaded: false, loaded: false,


@on("init") @on("init")
@@ -89,7 +89,6 @@ def whitelisted?(path)
"discourse/routes/discourse", "discourse/routes/discourse",
"discourse/models/site", "discourse/models/site",
"discourse/models/user", "discourse/models/user",
"discourse/models/model"
] ]
) )


0 comments on commit f03edb3

Please sign in to comment.
You can’t perform that action at this time.