From f3d0d8fe7ddd1130d835ecdad86b7cd1cd4bc45e Mon Sep 17 00:00:00 2001 From: Maja Komel Date: Wed, 20 Mar 2019 12:50:13 +0100 Subject: [PATCH] Upgrade to Ember 3.7.0 --- Gemfile | 2 +- Gemfile.lock | 4 +- .../admin/components/ace-editor.js.es6 | 2 +- .../admin/routes/admin-users-list-show.js.es6 | 7 +- .../discourse/components/d-editor.js.es6 | 26 +++---- .../discourse/components/d-modal-body.js.es6 | 8 +-- .../components/discourse-topic.js.es6 | 46 +++++++------ .../discourse/components/emoji-picker.js.es6 | 8 ++- .../discourse/components/login-modal.js.es6 | 2 +- .../discourse/components/nav-item.js.es6 | 22 +++--- .../components/scrolling-post-stream.js.es6 | 68 +++++++++++-------- .../discourse/components/site-header.js.es6 | 24 ++++--- .../components/topic-entrance.js.es6 | 4 +- .../discourse/components/watch-read.js.es6 | 2 +- .../discourse/helpers/route-action.js.es6 | 9 ++- .../initializers/page-tracking.js.es6 | 6 +- .../discourse/initializers/show-footer.js.es6 | 2 +- .../discourse/lib/app-events.js.es6 | 49 ++++++++++++- .../discourse/lib/page-tracker.js.es6 | 8 +-- .../mixins/card-contents-base.js.es6 | 12 ++-- .../discourse/mixins/url-refresh.js.es6 | 4 +- .../discourse/routes/badges-show.js.es6 | 3 +- .../routes/build-category-route.js.es6 | 2 +- .../routes/group-activity-posts.js.es6 | 2 +- .../discourse/routes/new-message.js.es6 | 3 +- .../discourse/routes/new-topic.js.es6 | 20 +++--- .../discourse/routes/tags-show.js.es6 | 4 +- .../javascripts/discourse/routes/topic.js.es6 | 2 +- .../routes/user-activity-stream.js.es6 | 2 +- .../components/category-chooser.js.es6 | 11 --- .../components/group-members-dropdown.js.es6 | 2 +- .../select-kit/components/select-kit.js.es6 | 6 +- .../topic-notifications-options.js.es6 | 16 ++--- 33 files changed, 222 insertions(+), 166 deletions(-) diff --git a/Gemfile b/Gemfile index 5ee5675cf35..44c6dc8a695 100644 --- a/Gemfile +++ b/Gemfile @@ -49,7 +49,7 @@ gem 'onebox', '1.8.82' gem 'http_accept_language', '~>2.0.5', require: false gem 'ember-rails', '0.18.5' -gem 'discourse-ember-source', '~> 3.5.1' +gem 'discourse-ember-source', '~> 3.7.0' gem 'ember-handlebars-template', '0.8.0' gem 'barber' diff --git a/Gemfile.lock b/Gemfile.lock index ea2e1aa9e4a..f145e0914ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,7 +108,7 @@ GEM terminal-table (~> 1) debug_inspector (0.0.3) diff-lcs (1.3) - discourse-ember-source (3.5.1.3) + discourse-ember-source (3.7.0.2) discourse_image_optim (0.26.2) exifr (~> 1.2, >= 1.2.2) fspath (~> 3.0) @@ -466,7 +466,7 @@ DEPENDENCIES colored2 cppjieba_rb danger - discourse-ember-source (~> 3.5.1) + discourse-ember-source (~> 3.7.0) discourse_image_optim email_reply_trimmer (~> 0.1) ember-handlebars-template (= 0.8.0) diff --git a/app/assets/javascripts/admin/components/ace-editor.js.es6 b/app/assets/javascripts/admin/components/ace-editor.js.es6 index b86c0e4cd70..b3576c8bea1 100644 --- a/app/assets/javascripts/admin/components/ace-editor.js.es6 +++ b/app/assets/javascripts/admin/components/ace-editor.js.es6 @@ -100,7 +100,7 @@ export default Ember.Component.extend({ if (this.appEvents) { // xxx: don't run during qunit tests - this.appEvents.on("ace:resize", () => this.resize()); + this.appEvents.on("ace:resize", this, "resize"); } if (this.get("autofocus")) { diff --git a/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 b/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 index e893139fc48..fba32bec282 100644 --- a/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-users-list-show.js.es6 @@ -10,12 +10,13 @@ export default Discourse.Route.extend({ const routeName = "adminUsersList.show"; if (transition.targetName === routeName) { - const params = transition.params[routeName]; + const params = transition.routeInfos.find(a => a.name === routeName) + .params; const controller = this.controllerFor(routeName); if (controller) { controller.setProperties({ - order: transition.queryParams.order, - ascending: transition.queryParams.ascending, + order: transition.to.queryParams.order, + ascending: transition.to.queryParams.ascending, query: params.filter, showEmails: false, refreshing: false diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 9987cf5ec70..2b82d2ea17e 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -290,25 +290,27 @@ export default Ember.Component.extend({ }); if (this.get("composerEvents")) { - this.appEvents.on("composer:insert-block", text => - this._addBlock(this._getSelected(), text) - ); - this.appEvents.on("composer:insert-text", (text, options) => - this._addText(this._getSelected(), text, options) - ); - this.appEvents.on("composer:replace-text", (oldVal, newVal, opts) => - this._replaceText(oldVal, newVal, opts) - ); + this.appEvents.on("composer:insert-block", this, "_insertBlock"); + this.appEvents.on("composer:insert-text", this, "_insertText"); + this.appEvents.on("composer:replace-text", this, "_replaceText"); } this._mouseTrap = mouseTrap; }, + _insertBlock(text) { + this._addBlock(this._getSelected(), text); + }, + + _insertText(text, options) { + this._addText(this._getSelected(), text, options); + }, + @on("willDestroyElement") _shutDown() { if (this.get("composerEvents")) { - this.appEvents.off("composer:insert-block"); - this.appEvents.off("composer:insert-text"); - this.appEvents.off("composer:replace-text"); + this.appEvents.off("composer:insert-block", this, "_insertBlock"); + this.appEvents.off("composer:insert-text", this, "_insertText"); + this.appEvents.off("composer:replace-text", this, "_replaceText"); } const mouseTrap = this._mouseTrap; diff --git a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 index 60f0d9a82a4..a49887519c2 100644 --- a/app/assets/javascripts/discourse/components/d-modal-body.js.es6 +++ b/app/assets/javascripts/discourse/components/d-modal-body.js.es6 @@ -14,14 +14,14 @@ export default Ember.Component.extend({ } Ember.run.scheduleOnce("afterRender", this, this._afterFirstRender); - this.appEvents.on("modal-body:flash", msg => this._flash(msg)); - this.appEvents.on("modal-body:clearFlash", () => this._clearFlash()); + this.appEvents.on("modal-body:flash", this, "_flash"); + this.appEvents.on("modal-body:clearFlash", this, "_clearFlash"); }, willDestroyElement() { this._super(...arguments); - this.appEvents.off("modal-body:flash"); - this.appEvents.off("modal-body:clearFlash"); + this.appEvents.off("modal-body:flash", this, "_flash"); + this.appEvents.off("modal-body:clearFlash", this, "_clearFlash"); }, _afterFirstRender() { diff --git a/app/assets/javascripts/discourse/components/discourse-topic.js.es6 b/app/assets/javascripts/discourse/components/discourse-topic.js.es6 index fd4ce8fc1c7..ff7c5ea6875 100644 --- a/app/assets/javascripts/discourse/components/discourse-topic.js.es6 +++ b/app/assets/javascripts/discourse/components/discourse-topic.js.es6 @@ -51,6 +51,27 @@ export default Ember.Component.extend(AddArchetypeClass, Scrolling, { } }, + _highlightPost(postNumber) { + Ember.run.scheduleOnce("afterRender", null, highlight, postNumber); + }, + + _updateTopic(topic) { + if (topic === null) { + this._lastShowTopic = false; + this.appEvents.trigger("header:hide-topic"); + return; + } + + const offset = window.pageYOffset || $("html").scrollTop(); + this._lastShowTopic = this.showTopicInHeader(topic, offset); + + if (this._lastShowTopic) { + this.appEvents.trigger("header:show-topic", topic); + } else { + this.appEvents.trigger("header:hide-topic"); + } + }, + didInsertElement() { this._super(...arguments); this.bindScrolling({ name: "topic-view" }); @@ -81,26 +102,9 @@ export default Ember.Component.extend(AddArchetypeClass, Scrolling, { } ); - this.appEvents.on("post:highlight", postNumber => { - Ember.run.scheduleOnce("afterRender", null, highlight, postNumber); - }); + this.appEvents.on("post:highlight", this, "_highlightPost"); - this.appEvents.on("header:update-topic", topic => { - if (topic === null) { - this._lastShowTopic = false; - this.appEvents.trigger("header:hide-topic"); - return; - } - - const offset = window.pageYOffset || $("html").scrollTop(); - this._lastShowTopic = this.showTopicInHeader(topic, offset); - - if (this._lastShowTopic) { - this.appEvents.trigger("header:show-topic", topic); - } else { - this.appEvents.trigger("header:hide-topic"); - } - }); + this.appEvents.on("header:update-topic", this, "_updateTopic"); }, willDestroyElement() { @@ -115,8 +119,8 @@ export default Ember.Component.extend(AddArchetypeClass, Scrolling, { // this happens after route exit, stuff could have trickled in this.appEvents.trigger("header:hide-topic"); - this.appEvents.off("post:highlight"); - this.appEvents.off("header:update-topic"); + this.appEvents.off("post:highlight", this, "_highlightPost"); + this.appEvents.off("header:update-topic", this, "_updateTopic"); }, @observes("Discourse.hasFocus") diff --git a/app/assets/javascripts/discourse/components/emoji-picker.js.es6 b/app/assets/javascripts/discourse/components/emoji-picker.js.es6 index ad588faf65e..e8bdc4fb433 100644 --- a/app/assets/javascripts/discourse/components/emoji-picker.js.es6 +++ b/app/assets/javascripts/discourse/components/emoji-picker.js.es6 @@ -77,7 +77,11 @@ export default Ember.Component.extend({ @on("willDestroyElement") _unbindGlobalEvents() { - this.appEvents.off("emoji-picker:close"); + this.appEvents.off("emoji-picker:close", this, "_closeEmojiPicker"); + }, + + _closeEmojiPicker() { + this.set("active", false); }, @on("didInsertElement") @@ -85,7 +89,7 @@ export default Ember.Component.extend({ this.$picker = this.$(".emoji-picker"); this.$modal = this.$(".emoji-picker-modal"); - this.appEvents.on("emoji-picker:close", () => this.set("active", false)); + this.appEvents.on("emoji-picker:close", this, "_closeEmojiPicker"); if (!keyValueStore.getObject(EMOJI_USAGE)) { keyValueStore.setObject({ key: EMOJI_USAGE, value: [] }); diff --git a/app/assets/javascripts/discourse/components/login-modal.js.es6 b/app/assets/javascripts/discourse/components/login-modal.js.es6 index c1c452f6634..59939542cb9 100644 --- a/app/assets/javascripts/discourse/components/login-modal.js.es6 +++ b/app/assets/javascripts/discourse/components/login-modal.js.es6 @@ -18,7 +18,7 @@ export default Ember.Component.extend({ "#login-account-password, #login-account-name, #login-second-factor" ).keydown(e => { if (e.keyCode === 13) { - this.sendAction(); + this.action(); } }); }); diff --git a/app/assets/javascripts/discourse/components/nav-item.js.es6 b/app/assets/javascripts/discourse/components/nav-item.js.es6 index 3910ad6b648..d83952cab6f 100644 --- a/app/assets/javascripts/discourse/components/nav-item.js.es6 +++ b/app/assets/javascripts/discourse/components/nav-item.js.es6 @@ -1,33 +1,27 @@ /* You might be looking for navigation-item. */ - import computed from "ember-addons/ember-computed-decorators"; -import { getOwner } from "discourse-common/lib/get-owner"; export default Ember.Component.extend({ tagName: "li", classNameBindings: ["active"], - - @computed() - router() { - return getOwner(this).lookup("router:main"); - }, + router: Ember.inject.service(), @computed("path") fullPath(path) { return Discourse.getURL(path); }, - @computed("route", "router.url") - active(route) { + @computed("route", "router.currentRoute") + active(route, currentRoute) { if (!route) { return; } - const routeParam = this.get("routeParam"), - router = this.get("router"); + const routeParam = this.get("routeParam"); + if (routeParam && currentRoute) { + return currentRoute.params["filter"] === routeParam; + } - return routeParam - ? router.isActive(route, routeParam) - : router.isActive(route); + return this.get("router").isActive(route); } }); diff --git a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 index fc5f0a413a9..94779cdebe9 100644 --- a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 +++ b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 @@ -262,6 +262,38 @@ export default MountWidget.extend({ Ember.run.scheduleOnce("afterRender", this, this.scrolled); }, + _posted(staged) { + const disableJumpReply = this.currentUser.get("disable_jump_reply"); + + this.queueRerender(() => { + if (staged && !disableJumpReply) { + const postNumber = staged.get("post_number"); + DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true }); + } + }); + }, + + _refresh(args) { + if (args) { + if (args.id) { + this.dirtyKeys.keyDirty(`post-${args.id}`); + + if (args.refreshLikes) { + this.dirtyKeys.keyDirty(`post-menu-${args.id}`, { + onRefresh: "refreshLikes" + }); + } + } else if (args.force) { + this.dirtyKeys.forceAll(); + } + } + this.queueRerender(); + }, + + _debouncedScroll() { + Ember.run.debounce(this, this._scrollTriggered, 10); + }, + didInsertElement() { this._super(...arguments); const debouncedScroll = () => @@ -269,21 +301,12 @@ export default MountWidget.extend({ this._previouslyNearby = {}; - this.appEvents.on("post-stream:refresh", debouncedScroll); + this.appEvents.on("post-stream:refresh", this, "_debouncedScroll"); $(document).bind("touchmove.post-stream", debouncedScroll); $(window).bind("scroll.post-stream", debouncedScroll); this._scrollTriggered(); - this.appEvents.on("post-stream:posted", staged => { - const disableJumpReply = this.currentUser.get("disable_jump_reply"); - - this.queueRerender(() => { - if (staged && !disableJumpReply) { - const postNumber = staged.get("post_number"); - DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true }); - } - }); - }); + this.appEvents.on("post-stream:posted", this, "_posted"); this.$().on("mouseenter.post-stream", "button.widget-button", e => { $("button.widget-button").removeClass("d-hover"); @@ -294,33 +317,18 @@ export default MountWidget.extend({ $("button.widget-button").removeClass("d-hover"); }); - this.appEvents.on("post-stream:refresh", args => { - if (args) { - if (args.id) { - this.dirtyKeys.keyDirty(`post-${args.id}`); - - if (args.refreshLikes) { - this.dirtyKeys.keyDirty(`post-menu-${args.id}`, { - onRefresh: "refreshLikes" - }); - } - } else if (args.force) { - this.dirtyKeys.forceAll(); - } - } - this.queueRerender(); - }); + this.appEvents.on("post-stream:refresh", this, "_refresh"); }, willDestroyElement() { this._super(...arguments); $(document).unbind("touchmove.post-stream"); $(window).unbind("scroll.post-stream"); - this.appEvents.off("post-stream:refresh"); + this.appEvents.off("post-stream:refresh", this, "_debouncedScroll"); this.$().off("mouseenter.post-stream"); this.$().off("mouseleave.post-stream"); - this.appEvents.off("post-stream:refresh"); - this.appEvents.off("post-stream:posted"); + this.appEvents.off("post-stream:refresh", this, "_refresh"); + this.appEvents.off("post-stream:posted", this, "_posted"); }, showModerationHistory(post) { diff --git a/app/assets/javascripts/discourse/components/site-header.js.es6 b/app/assets/javascripts/discourse/components/site-header.js.es6 index 28627bff785..898ebcce2dd 100644 --- a/app/assets/javascripts/discourse/components/site-header.js.es6 +++ b/app/assets/javascripts/discourse/components/site-header.js.es6 @@ -231,19 +231,14 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, { const { isAndroid } = this.capabilities; $(window).on("resize.discourse-menu-panel", () => this.afterRender()); - this.appEvents.on("header:show-topic", topic => this.setTopic(topic)); - this.appEvents.on("header:hide-topic", () => this.setTopic(null)); + this.appEvents.on("header:show-topic", this, "setTopic"); + this.appEvents.on("header:hide-topic", this, "setTopic"); this.dispatch("notifications:changed", "user-notifications"); this.dispatch("header:keyboard-trigger", "header"); this.dispatch("search-autocomplete:after-complete", "search-term"); - this.appEvents.on("dom:clean", () => { - // For performance, only trigger a re-render if any menu panels are visible - if (this.$(".menu-panel").length) { - this.eventDispatched("dom:clean", "header"); - } - }); + this.appEvents.on("dom:clean", this, "_cleanDom"); // Only add listeners for opening menus by swiping them in on Android devices // iOS will respond to these events, but also does swiping for back/forward @@ -252,15 +247,22 @@ const SiteHeaderComponent = MountWidget.extend(Docking, PanEvents, { } }, + _cleanDom() { + // For performance, only trigger a re-render if any menu panels are visible + if (this.$(".menu-panel").length) { + this.eventDispatched("dom:clean", "header"); + } + }, + willDestroyElement() { this._super(...arguments); const { isAndroid } = this.capabilities; $("body").off("keydown.header"); $(window).off("resize.discourse-menu-panel"); - this.appEvents.off("header:show-topic"); - this.appEvents.off("header:hide-topic"); - this.appEvents.off("dom:clean"); + this.appEvents.off("header:show-topic", this, "setTopic"); + this.appEvents.off("header:hide-topic", this, "setTopic"); + this.appEvents.off("dom:clean", this, "_cleanDom"); if (isAndroid) { this.removeTouchListeners($("body")); diff --git a/app/assets/javascripts/discourse/components/topic-entrance.js.es6 b/app/assets/javascripts/discourse/components/topic-entrance.js.es6 index 2ded0e7314e..fa25a528a7b 100644 --- a/app/assets/javascripts/discourse/components/topic-entrance.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-entrance.js.es6 @@ -53,7 +53,7 @@ export default Ember.Component.extend(CleansUp, { didInsertElement() { this._super(...arguments); - this.appEvents.on("topic-entrance:show", data => this._show(data)); + this.appEvents.on("topic-entrance:show", this, "_show"); }, _setCSS() { @@ -100,7 +100,7 @@ export default Ember.Component.extend(CleansUp, { }, willDestroyElement() { - this.appEvents.off("topic-entrance:show"); + this.appEvents.off("topic-entrance:show", this, "_show"); }, _jumpTo(destination) { diff --git a/app/assets/javascripts/discourse/components/watch-read.js.es6 b/app/assets/javascripts/discourse/components/watch-read.js.es6 index 7cca41ab8b5..4b149d371c9 100644 --- a/app/assets/javascripts/discourse/components/watch-read.js.es6 +++ b/app/assets/javascripts/discourse/components/watch-read.js.es6 @@ -13,7 +13,7 @@ export default Ember.Component.extend({ $(window).on("load.faq resize.faq scroll.faq", () => { const faqUnread = !currentUser.get("read_faq"); if (faqUnread && isElementInViewport($(".contents p").last())) { - this.sendAction(); + this.action(); } }); } diff --git a/app/assets/javascripts/discourse/helpers/route-action.js.es6 b/app/assets/javascripts/discourse/helpers/route-action.js.es6 index 946dd69ac89..4e010498bd1 100644 --- a/app/assets/javascripts/discourse/helpers/route-action.js.es6 +++ b/app/assets/javascripts/discourse/helpers/route-action.js.es6 @@ -9,15 +9,14 @@ const { runInDebug } = Ember; -function getCurrentHandlerInfos(router) { +function getCurrentRouteInfos(router) { let routerLib = router._routerMicrolib || router.router; - - return routerLib.currentHandlerInfos; + return routerLib.currentRouteInfos; } function getRoutes(router) { - return emberArray(getCurrentHandlerInfos(router)) - .mapBy("handler") + return emberArray(getCurrentRouteInfos(router)) + .mapBy("_route") .reverse(); } diff --git a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 index b10cbe9b7de..84a9d51de79 100644 --- a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 +++ b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 @@ -12,10 +12,12 @@ export default { initialize(container) { // Tell our AJAX system to track a page transition const router = container.lookup("router:main"); - router.on("willTransition", viewTrackingRequired); - router.on("didTransition", cleanDOM); + + router.on("routeWillChange", viewTrackingRequired); + router.on("routeDidChange", cleanDOM); let appEvents = container.lookup("app-events:main"); + startPageTracking(router, appEvents); // Out of the box, Discourse tries to track google analytics diff --git a/app/assets/javascripts/discourse/initializers/show-footer.js.es6 b/app/assets/javascripts/discourse/initializers/show-footer.js.es6 index ce58457774e..77040e907f5 100644 --- a/app/assets/javascripts/discourse/initializers/show-footer.js.es6 +++ b/app/assets/javascripts/discourse/initializers/show-footer.js.es6 @@ -7,7 +7,7 @@ export default { // only take care of hiding the footer here // controllers MUST take care of displaying it - router.on("willTransition", () => { + router.on("routeWillChange", () => { application.set("showFooter", false); return true; }); diff --git a/app/assets/javascripts/discourse/lib/app-events.js.es6 b/app/assets/javascripts/discourse/lib/app-events.js.es6 index 59257700fdf..aff71a2a40f 100644 --- a/app/assets/javascripts/discourse/lib/app-events.js.es6 +++ b/app/assets/javascripts/discourse/lib/app-events.js.es6 @@ -1 +1,48 @@ -export default Ember.Object.extend(Ember.Evented); +import deprecated from "discourse-common/lib/deprecated"; + +export default Ember.Object.extend(Ember.Evented, { + _events: {}, + + on() { + if (arguments.length === 2) { + let [name, fn] = arguments; + let target = {}; + this._events[name] = this._events[name] || []; + this._events[name].push({ target, fn }); + + this._super(name, target, fn); + } else if (arguments.length === 3) { + let [name, target, fn] = arguments; + this._events[name] = this._events[name] || []; + this._events[name].push({ target, fn }); + + this._super(...arguments); + } + return this; + }, + + off() { + let name = arguments[0]; + let fn = arguments[2]; + + if (this._events[name]) { + if (arguments.length === 1) { + deprecated( + "Removing all event listeners at once is deprecated, please remove each listener individually." + ); + + this._events[name].forEach(ref => { + this._super(name, ref.target, ref.fn); + }); + delete this._events[name]; + } else if (arguments.length === 3) { + this._super(...arguments); + + this._events[name] = this._events[name].filter(e => e.fn !== fn); + if (this._events[name].length === 0) delete this._events[name]; + } + } + + return this; + } +}); diff --git a/app/assets/javascripts/discourse/lib/page-tracker.js.es6 b/app/assets/javascripts/discourse/lib/page-tracker.js.es6 index 0765ad50b16..6a36cc7cbc6 100644 --- a/app/assets/javascripts/discourse/lib/page-tracker.js.es6 +++ b/app/assets/javascripts/discourse/lib/page-tracker.js.es6 @@ -15,10 +15,9 @@ export function startPageTracking(router, appEvents) { if (_started) { return; } - - router.on("didTransition", function() { - this.send("refreshTitle"); - const url = Discourse.getURL(this.get("url")); + router.on("routeDidChange", () => { + router.send("refreshTitle"); + const url = Discourse.getURL(router.get("url")); // Refreshing the title is debounced, so we need to trigger this in the // next runloop to have the correct title. @@ -39,6 +38,7 @@ export function startPageTracking(router, appEvents) { } }); }); + _started = true; } diff --git a/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 b/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 index ce110da855c..756a24930f8 100644 --- a/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 +++ b/app/assets/javascripts/discourse/mixins/card-contents-base.js.es6 @@ -122,10 +122,7 @@ export default Ember.Mixin.create({ return this._show($target.text().replace(/^@/, ""), $target); }); - this.appEvents.on(previewClickEvent, $target => { - this.set("isFixed", true); - return this._show($target.text().replace(/^@/, ""), $target); - }); + this.appEvents.on(previewClickEvent, this, "_previewClick"); this.appEvents.on(`topic-header:trigger-${id}`, (username, $target) => { this.setProperties({ isFixed: true, isDocked: true }); @@ -133,6 +130,11 @@ export default Ember.Mixin.create({ }); }, + _previewClick($target) { + this.set("isFixed", true); + return this._show($target.text().replace(/^@/, ""), $target); + }, + _positionCard(target) { const rtl = $("html").css("direction") === "rtl"; if (!target) { @@ -239,7 +241,7 @@ export default Ember.Mixin.create({ $("#main") .off(clickDataExpand) .off(clickMention); - this.appEvents.off(previewClickEvent); + this.appEvents.off(previewClickEvent, this, "_previewClick"); }, keyUp(e) { diff --git a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 index 4b30762941e..bf39cd084a8 100644 --- a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 +++ b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 @@ -7,12 +7,12 @@ export default { didInsertElement() { this._super(...arguments); - this.appEvents.on("url:refresh", this.refresh); + this.appEvents.on("url:refresh", this, "refresh"); }, willDestroyElement() { this._super(...arguments); - this.appEvents.off("url:refresh"); + this.appEvents.off("url:refresh", this, "refresh"); } }; diff --git a/app/assets/javascripts/discourse/routes/badges-show.js.es6 b/app/assets/javascripts/discourse/routes/badges-show.js.es6 index e2330c3ac81..7a5b7f7830e 100644 --- a/app/assets/javascripts/discourse/routes/badges-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/badges-show.js.es6 @@ -30,7 +30,8 @@ export default Discourse.Route.extend({ }, afterModel(model, transition) { - const username = transition.queryParams && transition.queryParams.username; + const username = + transition.to.queryParams && transition.to.queryParams.username; const userBadgesGrant = UserBadge.findByBadgeId(model.get("id"), { username diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index eac9ea20175..182571cb8e3 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -93,7 +93,7 @@ export default (filterArg, params) => { const listFilter = `c/${Discourse.Category.slugFor( category )}/l/${this.filter(category)}`, - findOpts = filterQueryParams(transition.queryParams, params), + findOpts = filterQueryParams(transition.to.queryParams, params), extras = { cached: this.isPoppedState(transition) }; return findTopicList( diff --git a/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6 b/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6 index bb8a600ab54..62aad289456 100644 --- a/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-activity-posts.js.es6 @@ -7,7 +7,7 @@ export function buildGroupPage(type) { }, model(params, transition) { - let categoryId = Ember.get(transition, "queryParams.category_id"); + let categoryId = Ember.get(transition.to, "queryParams.category_id"); return this.modelFor("group").findPosts({ type, categoryId }); }, diff --git a/app/assets/javascripts/discourse/routes/new-message.js.es6 b/app/assets/javascripts/discourse/routes/new-message.js.es6 index 70691518829..f926ba3967b 100644 --- a/app/assets/javascripts/discourse/routes/new-message.js.es6 +++ b/app/assets/javascripts/discourse/routes/new-message.js.es6 @@ -3,7 +3,8 @@ import Group from "discourse/models/group"; export default Discourse.Route.extend({ beforeModel(transition) { - const params = transition.queryParams; + const params = transition.to.queryParams; + const groupName = params.groupname || params.group_name; if (this.currentUser) { diff --git a/app/assets/javascripts/discourse/routes/new-topic.js.es6 b/app/assets/javascripts/discourse/routes/new-topic.js.es6 index 46f38d4ef39..947193be388 100644 --- a/app/assets/javascripts/discourse/routes/new-topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/new-topic.js.es6 @@ -6,11 +6,11 @@ export default Discourse.Route.extend({ if (Discourse.User.current()) { let category, category_id; - if (transition.queryParams.category_id) { - category_id = transition.queryParams.category_id; + if (transition.to.queryParams.category_id) { + category_id = transition.to.queryParams.category_id; category = Category.findById(category_id); - } else if (transition.queryParams.category) { - const splitCategory = transition.queryParams.category.split("/"); + } else if (transition.to.queryParams.category) { + const splitCategory = transition.to.queryParams.category.split("/"); category = this._getCategory( splitCategory[0], splitCategory[1], @@ -46,10 +46,10 @@ export default Discourse.Route.extend({ Ember.run.next(function() { e.send( "createNewTopicViaParams", - transition.queryParams.title, - transition.queryParams.body, + transition.to.queryParams.title, + transition.to.queryParams.body, category_id, - transition.queryParams.tags + transition.to.queryParams.tags ); }); } @@ -60,10 +60,10 @@ export default Discourse.Route.extend({ Ember.run.next(function() { e.send( "createNewTopicViaParams", - transition.queryParams.title, - transition.queryParams.body, + transition.to.queryParams.title, + transition.to.queryParams.body, null, - transition.queryParams.tags + transition.to.queryParams.tags ); }); } diff --git a/app/assets/javascripts/discourse/routes/tags-show.js.es6 b/app/assets/javascripts/discourse/routes/tags-show.js.es6 index 978816b7df4..db3c2eb4f3c 100644 --- a/app/assets/javascripts/discourse/routes/tags-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/tags-show.js.es6 @@ -70,8 +70,8 @@ export default Discourse.Route.extend({ controller.set("loading", true); const params = controller.getProperties("order", "ascending"); - params.order = transition.queryParams.order || params.order; - params.ascending = transition.queryParams.ascending || params.ascending; + params.order = transition.to.queryParams.order || params.order; + params.ascending = transition.to.queryParams.ascending || params.ascending; const categorySlug = this.get("categorySlug"); const parentCategorySlug = this.get("parentCategorySlug"); diff --git a/app/assets/javascripts/discourse/routes/topic.js.es6 b/app/assets/javascripts/discourse/routes/topic.js.es6 index 06518c1e160..4e4865e1657 100644 --- a/app/assets/javascripts/discourse/routes/topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/topic.js.es6 @@ -231,7 +231,7 @@ const TopicRoute = Discourse.Route.extend({ }); } - const queryParams = transition.queryParams; + const queryParams = transition.to.queryParams; let topic = this.modelFor("topic"); if (topic && topic.get("id") === parseInt(params.id, 10)) { diff --git a/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 b/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 index e10629077d7..5da6e94dc04 100644 --- a/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 +++ b/app/assets/javascripts/discourse/routes/user-activity-stream.js.es6 @@ -14,7 +14,7 @@ export default Discourse.Route.extend(ViewingActionType, { filter: this.get("userActionType"), noContentHelpKey: this.get("noContentHelpKey") || "user_activity.no_default", - actingUsername: transition.queryParams.acting_username + actingUsername: transition.to.queryParams.acting_username }); }, diff --git a/app/assets/javascripts/select-kit/components/category-chooser.js.es6 b/app/assets/javascripts/select-kit/components/category-chooser.js.es6 index 34cd38b0f82..f0ae60f6931 100644 --- a/app/assets/javascripts/select-kit/components/category-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/category-chooser.js.es6 @@ -1,5 +1,4 @@ import ComboBoxComponent from "select-kit/components/combo-box"; -import { on } from "ember-addons/ember-computed-decorators"; import computed from "ember-addons/ember-computed-decorators"; import PermissionType from "discourse/models/permission-type"; import Category from "discourse/models/category"; @@ -100,16 +99,6 @@ export default ComboBoxComponent.extend({ return content; }, - @on("didRender") - _bindComposerResizing() { - this.appEvents.on("composer:resized", this, this.applyDirection); - }, - - @on("willDestroyElement") - _unbindComposerResizing() { - this.appEvents.off("composer:resized"); - }, - didSelect(computedContentItem) { if (this.attrs.onChooseCategory) { this.attrs.onChooseCategory(computedContentItem.originalContent); diff --git a/app/assets/javascripts/select-kit/components/group-members-dropdown.js.es6 b/app/assets/javascripts/select-kit/components/group-members-dropdown.js.es6 index 01b1f6906d2..41e54458474 100644 --- a/app/assets/javascripts/select-kit/components/group-members-dropdown.js.es6 +++ b/app/assets/javascripts/select-kit/components/group-members-dropdown.js.es6 @@ -28,6 +28,6 @@ export default DropdownSelectBoxComponent.extend({ }, mutateValue(value) { - this.sendAction(value); + this.get(value)(); } }); diff --git a/app/assets/javascripts/select-kit/components/select-kit.js.es6 b/app/assets/javascripts/select-kit/components/select-kit.js.es6 index ccc5f49f8d0..cad55bf463f 100644 --- a/app/assets/javascripts/select-kit/components/select-kit.js.es6 +++ b/app/assets/javascripts/select-kit/components/select-kit.js.es6 @@ -134,10 +134,10 @@ export default Ember.Component.extend( this.removeObserver( `content.@each.${this.get("nameProperty")}`, this, - this._compute + "_compute" ); - this.removeObserver(`content.[]`, this, this._compute); - this.removeObserver(`asyncContent.[]`, this, this._compute); + this.removeObserver(`content.[]`, this, "_compute"); + this.removeObserver(`asyncContent.[]`, this, "_compute"); }, willComputeAttributes() {}, diff --git a/app/assets/javascripts/select-kit/components/topic-notifications-options.js.es6 b/app/assets/javascripts/select-kit/components/topic-notifications-options.js.es6 index 1bcd7df3fb6..b15b688faa9 100644 --- a/app/assets/javascripts/select-kit/components/topic-notifications-options.js.es6 +++ b/app/assets/javascripts/select-kit/components/topic-notifications-options.js.es6 @@ -17,20 +17,20 @@ export default NotificationOptionsComponent.extend({ return archetype === "private_message" ? "_pm" : ""; }, + _changed(msg) { + if (this.get("computedValue") !== msg.id) { + this.get("topic.details").updateNotifications(msg.id); + } + }, + @on("didInsertElement") _bindGlobalLevelChanged() { - this.appEvents.on("topic-notifications-button:changed", msg => { - if (msg.type === "notification") { - if (this.get("computedValue") !== msg.id) { - this.get("topic.details").updateNotifications(msg.id); - } - } - }); + this.appEvents.on("topic-notifications-button:changed", this, "_changed"); }, @on("willDestroyElement") _unbindGlobalLevelChanged() { - this.appEvents.off("topic-notifications-button:changed"); + this.appEvents.off("topic-notifications-button:changed", this, "_changed"); }, mutateValue(value) {