DEV: Remove Discourse.Site in favor of import (#8344)

* DEV: Remove Discourse.Site in favor of importing Site

* Ran prettier
This commit is contained in:
Mark VanLandingham 2019-11-13 11:13:47 -06:00 committed by Robin Ward
parent d2b3ac1282
commit 3c5df82590
20 changed files with 54 additions and 36 deletions

View File

@ -6,6 +6,7 @@ import {
default as discourseComputed,
observes
} from "discourse-common/utils/decorators";
import Site from "discourse/models/site";
export default RestModel.extend({
content_type: 1, // json
@ -36,7 +37,7 @@ export default RestModel.extend({
const groupIds = this.group_ids;
this.set(
"groupsFilterInName",
Discourse.Site.currentProp("groups").reduce((groupNames, g) => {
Site.currentProp("groups").reduce((groupNames, g) => {
if (groupIds.includes(g.id)) {
groupNames.push(g.name);
}
@ -87,7 +88,7 @@ export default RestModel.extend({
group_ids:
isEmpty(groupNames) || isEmpty(groupNames[0])
? [null]
: Discourse.Site.currentProp("groups").reduce((groupIds, g) => {
: Site.currentProp("groups").reduce((groupIds, g) => {
if (groupNames.includes(g.name)) {
groupIds.push(g.id);
}

View File

@ -3,6 +3,7 @@ import { get } from "@ember/object";
import Component from "@ember/component";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
import { iconHTML } from "discourse-common/lib/icon-library";
import Site from "discourse/models/site";
export default Component.extend({
elementId: "suggested-topics",
@ -36,8 +37,7 @@ export default Component.extend({
if (
category &&
get(category, "id") ===
Discourse.Site.currentProp("uncategorized_category_id")
get(category, "id") === Site.currentProp("uncategorized_category_id")
) {
category = null;
}

View File

@ -11,13 +11,14 @@ import {
customNavItemHref
} from "discourse/models/nav-item";
import Category from "discourse/models/category";
import Site from "discourse/models/site";
if (customNavItemHref) {
customNavItemHref(function(navItem) {
if (navItem.get("tagId")) {
const name = navItem.get("name");
if (!Discourse.Site.currentProp("filters").includes(name)) {
if (!Site.currentProp("filters").includes(name)) {
return null;
}

View File

@ -3,6 +3,7 @@ import { registerUnbound } from "discourse-common/lib/helpers";
import { isRTL } from "discourse/lib/text-direction";
import { iconHTML } from "discourse-common/lib/icon-library";
import Category from "discourse/models/category";
import Site from "discourse/models/site";
let escapeExpression = Handlebars.Utils.escapeExpression;
let _renderer = defaultCategoryLinkRenderer;
@ -32,8 +33,7 @@ export function categoryBadgeHTML(category, opts) {
if (
!category ||
(!opts.allowUncategorized &&
get(category, "id") ===
Discourse.Site.currentProp("uncategorized_category_id") &&
get(category, "id") === Site.currentProp("uncategorized_category_id") &&
Discourse.SiteSettings.suppress_uncategorized_badge)
)
return "";

View File

@ -3,6 +3,7 @@ import pageVisible from "discourse/lib/page-visible";
import logout from "discourse/lib/logout";
import Session from "discourse/models/session";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
let _trackView = false;
let _transientHeader = null;
@ -100,7 +101,7 @@ export function ajax() {
handleLogoff(xhr);
run(() => {
Discourse.Site.currentProp(
Site.currentProp(
"isReadOnly",
!!xhr.getResponseHeader("Discourse-Readonly")
);

View File

@ -1,14 +1,16 @@
import { cancel } from "@ember/runloop";
import { later } from "@ember/runloop";
import { iconHTML } from "discourse-common/lib/icon-library";
import { setCaretPosition, caretPosition } from "discourse/lib/utilities";
import Site from "discourse/models/site";
/**
This is a jQuery plugin to support autocompleting values in our text fields.
@module $.fn.autocomplete
**/
import { iconHTML } from "discourse-common/lib/icon-library";
export const CANCELLED_STATUS = "__CANCELLED";
import { setCaretPosition, caretPosition } from "discourse/lib/utilities";
export const CANCELLED_STATUS = "__CANCELLED";
const allowedLettersRegex = /[\s\t\[\{\(\/]/;
const keys = {
@ -319,7 +321,7 @@ export default function(options) {
vOffset = BELOW;
}
if (Discourse.Site.currentProp("mobileView")) {
if (Site.currentProp("mobileView")) {
if (me.height() / 2 >= pos.top) {
vOffset = BELOW;
}

View File

@ -3,6 +3,7 @@ import DiscourseURL from "discourse/lib/url";
import KeyValueStore from "discourse/lib/key-value-store";
import { formatUsername } from "discourse/lib/utilities";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
let primaryTab = false;
let liveEnabled = false;
@ -213,7 +214,7 @@ function requestPermission() {
function i18nKey(notification_type) {
return (
"notifications.popup." +
Discourse.Site.current().get("notificationLookup")[notification_type]
Site.current().get("notificationLookup")[notification_type]
);
}

View File

@ -1,3 +1,5 @@
import Site from "discourse/models/site";
let _connectorCache;
let _rawConnectorCache;
let _extraConnectorClasses = {};
@ -22,7 +24,7 @@ const DefaultConnectorClass = {
};
function findOutlets(collection, callback) {
const disabledPlugins = Discourse.Site.currentProp("disabled_plugins") || [];
const disabledPlugins = Site.currentProp("disabled_plugins") || [];
Object.keys(collection).forEach(function(res) {
if (res.indexOf("/connectors/") !== -1) {

View File

@ -1,6 +1,7 @@
import { defaultHomepage } from "discourse/lib/utilities";
import { rewritePath } from "discourse/lib/url";
import ENV from "discourse-common/config/environment";
import Site from "discourse/models/site";
const rootURL = Discourse.BaseUri;
@ -33,7 +34,7 @@ class RouteNode {
this.children = [];
this.childrenByName = {};
this.paths = {};
this.site = Discourse.Site.current();
this.site = Site.current();
if (!opts.path) {
opts.path = name;

View File

@ -19,6 +19,7 @@ import { propertyNotEqual } from "discourse/lib/computed";
import { throttle } from "@ember/runloop";
import { Promise } from "rsvp";
import { set } from "@ember/object";
import Site from "discourse/models/site";
// The actions the composer can take
export const CREATE_TOPIC = "createTopic",
@ -1146,7 +1147,7 @@ Composer.reopenClass({
create(args) {
args = args || {};
args.user = args.user || Discourse.User.current();
args.site = args.site || Discourse.Site.current();
args.site = args.site || Site.current();
args.siteSettings = args.siteSettings || Discourse.SiteSettings;
return this._super(args);
},

View File

@ -3,6 +3,7 @@ import EmberObject from "@ember/object";
import { updateCsrfToken } from "discourse/lib/ajax";
import { Promise } from "rsvp";
import Session from "discourse/models/session";
import Site from "discourse/models/site";
const LoginMethod = EmberObject.extend({
@discourseComputed
@ -70,7 +71,7 @@ export function findAll() {
methods = [];
Discourse.Site.currentProp("auth_providers").forEach(provider =>
Site.currentProp("auth_providers").forEach(provider =>
methods.pushObject(LoginMethod.create(provider))
);

View File

@ -3,6 +3,7 @@ import { emojiUnescape } from "discourse/lib/text";
import Category from "discourse/models/category";
import EmberObject from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
import Site from "discourse/models/site";
const NavItem = EmberObject.extend({
@discourseComputed("name")
@ -18,7 +19,7 @@ const NavItem = EmberObject.extend({
if (
name === "latest" &&
(!Discourse.Site.currentProp("mobileView") || this.tagId !== undefined)
(!Site.currentProp("mobileView") || this.tagId !== undefined)
) {
count = 0;
}
@ -106,13 +107,12 @@ NavItem.reopenClass({
if (
anonymous &&
!Discourse.Site.currentProp("anonymous_top_menu_items").includes(testName)
!Site.currentProp("anonymous_top_menu_items").includes(testName)
)
return null;
if (!Category.list() && testName === "categories") return null;
if (!Discourse.Site.currentProp("top_menu_items").includes(testName))
return null;
if (!Site.currentProp("top_menu_items").includes(testName)) return null;
var args = { name: text, hasIcon: text === "unread" };
if (opts.category) {

View File

@ -14,6 +14,7 @@ import { cookAsync } from "discourse/lib/text";
import { userPath } from "discourse/lib/url";
import Composer from "discourse/models/composer";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
const Post = RestModel.extend({
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
@ -355,7 +356,7 @@ Post.reopenClass({
// this area should be optimized, it is creating way too many objects per post
json.actions_summary = json.actions_summary.map(a => {
a.actionType = Discourse.Site.current().postActionTypeById(a.id);
a.actionType = Site.current().postActionTypeById(a.id);
a.count = a.count || 0;
const actionSummary = ActionSummary.create(a);
lookup[a.actionType.name_key] = actionSummary;

View File

@ -9,6 +9,7 @@ import { defaultHomepage } from "discourse/lib/utilities";
import PreloadStore from "preload-store";
import Category from "discourse/models/category";
import EmberObject from "@ember/object";
import Site from "discourse/models/site";
function isNew(topic) {
return (
@ -145,7 +146,7 @@ const TopicTrackingState = EmberObject.extend({
}
if (filter === defaultHomepage()) {
const suppressed_from_latest_category_ids = Discourse.Site.currentProp(
const suppressed_from_latest_category_ids = Site.currentProp(
"suppressed_from_latest_category_ids"
);
if (

View File

@ -21,6 +21,7 @@ import {
import Category from "discourse/models/category";
import Session from "discourse/models/session";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
export function loadTopicView(topic, args) {
const data = _.merge({}, args);
@ -102,7 +103,7 @@ const Topic = RestModel.extend({
fancyTitle(title) {
let fancyTitle = censor(
emojiUnescape(title || ""),
Discourse.Site.currentProp("censored_regexp")
Site.currentProp("censored_regexp")
);
if (Discourse.SiteSettings.support_mixed_text_direction) {
@ -338,7 +339,7 @@ const Topic = RestModel.extend({
@discourseComputed("archetype")
archetypeObject(archetype) {
return Discourse.Site.currentProp("archetypes").findBy("id", archetype);
return Site.currentProp("archetypes").findBy("id", archetype);
},
isPrivateMessage: equal("archetype", "private_message"),
@ -641,7 +642,7 @@ Topic.reopenClass({
const lookup = EmberObject.create();
result.actions_summary = result.actions_summary.map(a => {
a.post = result;
a.actionType = Discourse.Site.current().postActionTypeById(a.id);
a.actionType = Site.current().postActionTypeById(a.id);
const actionSummary = ActionSummary.create(a);
lookup.set(a.actionType.get("name_key"), actionSummary);
return actionSummary;

View File

@ -26,6 +26,7 @@ import Category from "discourse/models/category";
import { Promise } from "rsvp";
import { getProperties } from "@ember/object";
import deprecated from "discourse-common/lib/deprecated";
import Site from "discourse/models/site";
export const SECOND_FACTOR_METHODS = {
TOTP: 1,
@ -200,7 +201,7 @@ const User = RestModel.extend({
@discourseComputed("trust_level")
trustLevel(trustLevel) {
return Discourse.Site.currentProp("trustLevels").findBy(
return Site.currentProp("trustLevels").findBy(
"id",
parseInt(trustLevel, 10)
);

View File

@ -2,6 +2,7 @@ import buildCategoryRoute from "discourse/routes/build-category-route";
import buildTopicRoute from "discourse/routes/build-topic-route";
import DiscoverySortableController from "discourse/controllers/discovery-sortable";
import TagsShowRoute from "discourse/routes/tags-show";
import Site from "discourse/models/site";
export default {
after: "inject-discourse-objects",
@ -19,7 +20,7 @@ export default {
no_subcategories: true
});
const site = Discourse.Site.current();
const site = Site.current();
site.get("filters").forEach(filter => {
const filterCapitalized = filter.capitalize();
app[

View File

@ -1,3 +1,5 @@
import Site from "discourse/models/site";
export default function() {
// Error page
this.route("exception", { path: "/exception" });
@ -27,7 +29,7 @@ export default function() {
this.route("topCategory", { path: "/c/:parentSlug/:slug/l/top" });
// top by periods
Discourse.Site.currentProp("periods").forEach(period => {
Site.currentProp("periods").forEach(period => {
const top = "top" + period.capitalize();
this.route(top, { path: "/top/" + period });
this.route(top + "ParentCategory", { path: "/c/:slug/l/top/" + period });
@ -40,7 +42,7 @@ export default function() {
});
// filters
Discourse.Site.currentProp("filters").forEach(filter => {
Site.currentProp("filters").forEach(filter => {
this.route(filter, { path: "/" + filter });
this.route(filter + "ParentCategory", { path: "/c/:slug/l/" + filter });
this.route(filter + "CategoryNone", {
@ -204,7 +206,7 @@ export default function() {
path: "/c/:parent_category/:category/:tag_id"
});
Discourse.Site.currentProp("filters").forEach(filter => {
Site.currentProp("filters").forEach(filter => {
this.route("show" + filter.capitalize(), {
path: "/:tag_id/l/" + filter
});

View File

@ -3,6 +3,7 @@ import { queryParams } from "discourse/controllers/discovery-sortable";
import { defaultHomepage } from "discourse/lib/utilities";
import Session from "discourse/models/session";
import { Promise } from "rsvp";
import Site from "discourse/models/site";
// A helper to build a topic route for a filter
function filterQueryParams(params, defaultParams) {
@ -66,7 +67,7 @@ function findTopicList(store, tracking, filter, filterParams, extras) {
}
Session.currentProp("topicList", list);
if (list.topic_list && list.topic_list.top_tags) {
Discourse.Site.currentProp("top_tags", list.topic_list.top_tags);
Site.currentProp("top_tags", list.topic_list.top_tags);
}
return list;
});

View File

@ -4,6 +4,8 @@ import DiscourseURL from "discourse/lib/url";
import { default as discourseComputed } from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
import Site from "discourse/models/site";
const { isEmpty } = Ember;
export default ComboBoxComponent.extend({
@ -168,10 +170,7 @@ export default ComboBoxComponent.extend({
if (!this.siteSettings.allow_uncategorized_topics) {
results = results.filter(result => {
return (
result.id !==
Discourse.Site.currentProp("uncategorized_category_id")
);
return result.id !== Site.currentProp("uncategorized_category_id");
});
}