mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Convert global-notice to a native class (#23582)
This commit is contained in:
parent
a60d7a2bc7
commit
4571197e06
@ -5,6 +5,7 @@ import I18n from "I18n";
|
|||||||
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
import discourseComputed, { bind } from "discourse-common/utils/decorators";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
|
import { tagName } from "@ember-decorators/component";
|
||||||
|
|
||||||
const _pluginNotices = [];
|
const _pluginNotices = [];
|
||||||
|
|
||||||
@ -48,32 +49,34 @@ const Notice = EmberObject.extend({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Component.extend({
|
@tagName("")
|
||||||
tagName: "",
|
export default class GlobalNotice extends Component {
|
||||||
router: service(),
|
@service keyValueStore;
|
||||||
logsNoticeService: service("logsNotice"),
|
@service("logsNotice") logsNoticeService;
|
||||||
logNotice: null,
|
@service router;
|
||||||
|
|
||||||
init() {
|
logNotice = null;
|
||||||
this._super(...arguments);
|
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
|
||||||
this.logsNoticeService.addObserver("hidden", this._handleLogsNoticeUpdate);
|
this.logsNoticeService.addObserver("hidden", this._handleLogsNoticeUpdate);
|
||||||
this.logsNoticeService.addObserver("text", this._handleLogsNoticeUpdate);
|
this.logsNoticeService.addObserver("text", this._handleLogsNoticeUpdate);
|
||||||
},
|
}
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
this._super(...arguments);
|
super.willDestroyElement(...arguments);
|
||||||
|
|
||||||
this.logsNoticeService.removeObserver("text", this._handleLogsNoticeUpdate);
|
this.logsNoticeService.removeObserver("text", this._handleLogsNoticeUpdate);
|
||||||
this.logsNoticeService.removeObserver(
|
this.logsNoticeService.removeObserver(
|
||||||
"hidden",
|
"hidden",
|
||||||
this._handleLogsNoticeUpdate
|
this._handleLogsNoticeUpdate
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
get visible() {
|
get visible() {
|
||||||
return !this.router.currentRouteName.startsWith("wizard.");
|
return !this.router.currentRouteName.startsWith("wizard.");
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed(
|
@discourseComputed(
|
||||||
"site.isReadOnly",
|
"site.isReadOnly",
|
||||||
@ -183,13 +186,11 @@ export default Component.extend({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
dismissNotice(notice) {
|
dismissNotice(notice) {
|
||||||
if (notice.options.onDismiss) {
|
notice.options.onDismiss?.(notice);
|
||||||
notice.options.onDismiss(notice);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notice.options.persistentDismiss) {
|
if (notice.options.persistentDismiss) {
|
||||||
this.keyValueStore.set({
|
this.keyValueStore.set({
|
||||||
@ -202,26 +203,21 @@ export default Component.extend({
|
|||||||
if (alert) {
|
if (alert) {
|
||||||
alert.style.display = "none";
|
alert.style.display = "none";
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_handleLogsNoticeUpdate() {
|
_handleLogsNoticeUpdate() {
|
||||||
const { logsNoticeService } = this;
|
|
||||||
const logNotice = Notice.create({
|
const logNotice = Notice.create({
|
||||||
text: htmlSafe(this.logsNoticeService.message),
|
text: htmlSafe(this.logsNoticeService.message),
|
||||||
id: "alert-logs-notice",
|
id: "alert-logs-notice",
|
||||||
options: {
|
options: {
|
||||||
dismissable: true,
|
dismissable: true,
|
||||||
persistentDismiss: false,
|
persistentDismiss: false,
|
||||||
visibility() {
|
visibility: () => !this.logsNoticeService.hidden,
|
||||||
return !logsNoticeService.hidden;
|
onDismiss: () => this.logsNoticeService.set("text", ""),
|
||||||
},
|
|
||||||
onDismiss() {
|
|
||||||
logsNoticeService.set("text", "");
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set("logNotice", logNotice);
|
this.set("logNotice", logNotice);
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user