From 9b035523440d317def0e539a055da54b3fe39db5 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 31 Mar 2020 14:14:49 +1100 Subject: [PATCH] Migrate to new Site registration approach --- assets/javascripts/wizard-custom-lib.js | 4 +--- assets/javascripts/wizard-custom.js | 3 +++ .../wizard/initializers/custom.js.es6 | 20 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/assets/javascripts/wizard-custom-lib.js b/assets/javascripts/wizard-custom-lib.js index ee775332..8edec114 100644 --- a/assets/javascripts/wizard-custom-lib.js +++ b/assets/javascripts/wizard-custom-lib.js @@ -4,6 +4,4 @@ Wizard.SiteSettings = {}; Wizard.RAW_TEMPLATES = {}; Discourse.__widget_helpers = {}; Discourse.RAW_TEMPLATES = {}; -Discourse.SiteSettings = Wizard.SiteSettings; -Discourse.Model = Ember.Object.extend(); -Discourse.Site = Ember.Object.extend(); \ No newline at end of file +Discourse.SiteSettings = Wizard.SiteSettings; \ No newline at end of file diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index e03cf6a8..3a8382e7 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -31,9 +31,12 @@ //= require discourse/lib/key-value-store //= require discourse/lib/settings //= require discourse/lib/user-presence +//= require discourse/lib/hash //= require discourse/mixins/singleton +//= require discourse/adapters/rest + //= require discourse/models/login-method //= require discourse/models/permission-type //= require discourse/models/archetype diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index 5797116e..9afd9128 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -5,7 +5,8 @@ export default { initialize(app) { if (window.location.pathname.indexOf('/w/') < 0) return; - + + const EmberObject = requirejs('@ember/object').default; const Router = requirejs('wizard/router').default; const ApplicationRoute = requirejs('wizard/routes/application').default; const ajax = requirejs('wizard/lib/ajax').ajax; @@ -22,7 +23,10 @@ export default { const Store = requirejs("discourse/models/store").default; const registerRawHelpers = requirejs("discourse-common/lib/raw-handlebars-helpers").registerRawHelpers; const RawHandlebars = requirejs("discourse-common/lib/raw-handlebars").default; + const Site = requirejs("discourse/models/site").default; + const RestAdapter = requirejs("discourse/adapters/rest").default; + Discourse.Model = EmberObject.extend(); Discourse.__container__ = app.__container__; Discourse.getURLWithCDN = getUrl; Discourse.getURL = getUrl; @@ -51,16 +55,16 @@ export default { app.register("service:store", Store); targets.forEach(t => app.inject(t, "store", "service:store")); - - const site = Discourse.Site; - app.register("site:main", site); - targets.forEach(t => app.inject(t, "site", "site:main")); - targets.forEach(t => app.inject(t, "appEvents", "service:app-events")); - site.reopenClass(Singleton); - site.currentProp('can_create_tag', false); + app.register("adapter:rest", RestAdapter); + const site = Site.current(); + app.register("site:main", site, { instantiate: false }); + targets.forEach(t => app.inject(t, "site", "site:main")); + + site.set('can_create_tag', false); + Router.reopen({ rootURL: getUrl('/w/') });