Upgrade to Ember 3.7.0

This commit is contained in:
Maja Komel
2019-03-20 12:50:13 +01:00
parent f2c6a160e5
commit f3d0d8fe7d
33 changed files with 222 additions and 166 deletions
@@ -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;
@@ -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() {
@@ -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")
@@ -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: [] });
@@ -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();
}
});
});
@@ -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);
}
});
@@ -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) {
@@ -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"));
@@ -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) {
@@ -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();
}
});
}