diff --git a/assets/javascripts/discourse/components/wizard-notice-row.js.es6 b/assets/javascripts/discourse/components/wizard-notice-row.js.es6 index 9c099b39..ada4384d 100644 --- a/assets/javascripts/discourse/components/wizard-notice-row.js.es6 +++ b/assets/javascripts/discourse/components/wizard-notice-row.js.es6 @@ -4,11 +4,16 @@ import NoticeMessage from "../mixins/notice-message"; export default Component.extend(NoticeMessage, { tagName: "tr", attributeBindings: ["notice.id:data-notice-id"], - classNameBindings: [":wizard-notice-row", "notice.typeClass", "notice.expired:expired", "notice.dismissed:dismissed"], + classNameBindings: [ + ":wizard-notice-row", + "notice.typeClass", + "notice.expired:expired", + "notice.dismissed:dismissed", + ], actions: { dismiss() { this.notice.dismiss(); - } - } -}); \ No newline at end of file + }, + }, +}); diff --git a/assets/javascripts/discourse/components/wizard-notice.js.es6 b/assets/javascripts/discourse/components/wizard-notice.js.es6 index cac3e4eb..ca6b7658 100644 --- a/assets/javascripts/discourse/components/wizard-notice.js.es6 +++ b/assets/javascripts/discourse/components/wizard-notice.js.es6 @@ -3,7 +3,13 @@ import NoticeMessage from "../mixins/notice-message"; export default Component.extend(NoticeMessage, { attributeBindings: ["notice.id:data-notice-id"], - classNameBindings: [':wizard-notice', 'notice.typeClass', 'notice.dismissed:dismissed', 'notice.expired:expired', 'notice.hidden:hidden'], + classNameBindings: [ + ":wizard-notice", + "notice.typeClass", + "notice.dismissed:dismissed", + "notice.expired:expired", + "notice.hidden:hidden", + ], actions: { dismiss() { @@ -14,10 +20,10 @@ export default Component.extend(NoticeMessage, { }, hide() { - this.set('hiding', true); + this.set("hiding", true); this.notice.hide().then(() => { - this.set('hiding', false); + this.set("hiding", false); }); }, - } + }, }); diff --git a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-critical-notice.js.es6 b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-critical-notice.js.es6 index 0bb252e9..803e58a4 100644 --- a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-critical-notice.js.es6 +++ b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-critical-notice.js.es6 @@ -6,14 +6,14 @@ export default { }, setupComponent(attrs, component) { - const controller = getOwner(this).lookup('controller:admin-dashboard'); + const controller = getOwner(this).lookup("controller:admin-dashboard"); - component.set('notices', controller.get('customWizardCriticalNotices')); - controller.addObserver('customWizardCriticalNotices.[]', () => { + component.set("notices", controller.get("customWizardCriticalNotices")); + controller.addObserver("customWizardCriticalNotices.[]", () => { if (this._state === "destroying") { return; } - component.set('notices', controller.get('customWizardCriticalNotices')); + component.set("notices", controller.get("customWizardCriticalNotices")); }); - } -}; \ No newline at end of file + }, +}; diff --git a/assets/javascripts/discourse/controllers/admin-wizards-notices.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-notices.js.es6 index 0f67f878..1721e699 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-notices.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-notices.js.es6 @@ -15,9 +15,9 @@ export default Controller.extend({ loadingMore: false, canLoadMore: true, - @discourseComputed('notices.[]', 'notices.@each.dismissed') + @discourseComputed("notices.[]", "notices.@each.dismissed") allDismisssed(notices) { - return notices.every(n => !n.canDismiss || n.dismissed); + return notices.every((n) => !n.canDismiss || n.dismissed); }, loadMoreNotices() { @@ -35,7 +35,7 @@ export default Controller.extend({ } this.get("notices").pushObjects( - A(result.notices.map(notice => CustomWizardNotice.create(notice))) + A(result.notices.map((notice) => CustomWizardNotice.create(notice))) ); }) .finally(() => this.set("loadingMore", false)); @@ -56,12 +56,13 @@ export default Controller.extend({ I18n.t("yes_value"), (result) => { if (result) { - this.set('loadingMore', true); - CustomWizardNotice.dismissAll() - .finally(() => this.set("loadingMore", false)); + this.set("loadingMore", true); + CustomWizardNotice.dismissAll().finally(() => + this.set("loadingMore", false) + ); } } ); - } - } + }, + }, }); diff --git a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 index e2672fe4..33841460 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 @@ -17,10 +17,10 @@ export default Controller.extend({ this.adminWizardsNotices.setProperties({ notices: A(), page: 0, - canLoadMore: true + canLoadMore: true, }); this.adminWizardsNotices.loadMoreNotices(); } }); - } + }, }); diff --git a/assets/javascripts/discourse/helpers/notice-badge.js.es6 b/assets/javascripts/discourse/helpers/notice-badge.js.es6 index bc5df4a6..ea32b462 100644 --- a/assets/javascripts/discourse/helpers/notice-badge.js.es6 +++ b/assets/javascripts/discourse/helpers/notice-badge.js.es6 @@ -4,38 +4,40 @@ import I18n from "I18n"; import { registerUnbound } from "discourse-common/lib/helpers"; import { htmlSafe } from "@ember/template"; -registerUnbound("notice-badge", function(attrs) { - let tag = attrs.url ? 'a' : 'div'; - let attrStr = ''; +registerUnbound("notice-badge", function (attrs) { + let tag = attrs.url ? "a" : "div"; + let attrStr = ""; if (attrs.title) { attrStr += `title='${I18n.t(attrs.title)}'`; } if (attrs.url) { attrStr += `href='${attrs.url}'`; } - let html = `<${tag} class="${attrs.class ? `${attrs.class} ` : ''}notice-badge" ${attrStr}>`; + let html = `<${tag} class="${ + attrs.class ? `${attrs.class} ` : "" + }notice-badge" ${attrStr}>`; if (attrs.icon) { html += iconHTML(attrs.icon); } if (attrs.label) { if (attrs.icon) { - html += ' '; + html += " "; } html += `${I18n.t(attrs.label)}`; } if (attrs.date) { if (attrs.icon || attrs.label) { - html += ' '; + html += " "; } let dateAttrs = {}; if (attrs.leaveAgo) { dateAttrs = { format: "medium", - leaveAgo: true + leaveAgo: true, }; } html += autoUpdatingRelativeAge(new Date(attrs.date), dateAttrs); } html += ``; return htmlSafe(html); -}); \ No newline at end of file +}); diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 774acca3..e67f1ebd 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -22,16 +22,16 @@ export default { }; withPluginApi("0.8.36", (api) => { - api.modifyClass('route:admin-dashboard', { + api.modifyClass("route:admin-dashboard", { setupController(controller) { this._super(...arguments); controller.loadCriticalNotices(); controller.subscribe(); - } + }, }); - api.modifyClass('controller:admin-dashboard', { + api.modifyClass("controller:admin-dashboard", { criticalNotices: A(), unsubscribe() { @@ -41,7 +41,6 @@ export default { subscribe() { this.unsubscribe(); this.messageBus.subscribe("/custom-wizard/notices", (data) => { - if (isPresent(data.active_notice_count)) { this.loadCriticalNotices(); } @@ -50,19 +49,18 @@ export default { loadCriticalNotices() { CustomWizardNotice.list({ - type: [ - 'connection_error', - 'warning' - ], - archetype: 'plugin_status', - visible: true - }).then(result => { + type: ["connection_error", "warning"], + archetype: "plugin_status", + visible: true, + }).then((result) => { if (result.notices && result.notices.length) { - const criticalNotices = A(result.notices.map(n => CustomWizardNotice.create(n))); - this.set('customWizardCriticalNotices', criticalNotices); + const criticalNotices = A( + result.notices.map((n) => CustomWizardNotice.create(n)) + ); + this.set("customWizardCriticalNotices", criticalNotices); } }); - } + }, }); }); }, diff --git a/assets/javascripts/discourse/mixins/notice-message.js.es6 b/assets/javascripts/discourse/mixins/notice-message.js.es6 index 492df643..76e311bb 100644 --- a/assets/javascripts/discourse/mixins/notice-message.js.es6 +++ b/assets/javascripts/discourse/mixins/notice-message.js.es6 @@ -6,7 +6,7 @@ import { createPopper } from "@popperjs/core"; export default Mixin.create({ showCookedMessage: false, - didReceiveAttrs(){ + didReceiveAttrs() { const message = this.notice.message; cookAsync(message).then((cooked) => { this.set("cookedMessage", cooked); @@ -14,27 +14,24 @@ export default Mixin.create({ }, createMessageModal() { - let container = this.element.querySelector('.notice-message'); - let modal = this.element.querySelector('.cooked-notice-message'); + let container = this.element.querySelector(".notice-message"); + let modal = this.element.querySelector(".cooked-notice-message"); - this._popper = createPopper( - container, - modal, { - strategy: "absolute", - placement: "bottom-start", - modifiers: [ - { - name: "preventOverflow", + this._popper = createPopper(container, modal, { + strategy: "absolute", + placement: "bottom-start", + modifiers: [ + { + name: "preventOverflow", + }, + { + name: "offset", + options: { + offset: [0, 5], }, - { - name: "offset", - options: { - offset: [0, 5], - }, - }, - ], - } - ); + }, + ], + }); }, didInsertElement() { @@ -46,10 +43,16 @@ export default Mixin.create({ }, documentClick(event) { - if (this._state === "destroying") { return; } + if (this._state === "destroying") { + return; + } - if (!event.target.closest(`[data-notice-id="${this.notice.id}"] .notice-message`)) { - this.set('showCookedMessage', false); + if ( + !event.target.closest( + `[data-notice-id="${this.notice.id}"] .notice-message` + ) + ) { + this.set("showCookedMessage", false); } }, @@ -60,6 +63,6 @@ export default Mixin.create({ if (this.showCookedMessage) { scheduleOnce("afterRender", this, this.createMessageModal); } - } - } -}); \ No newline at end of file + }, + }, +}); diff --git a/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 index 29e30628..035e2ad5 100644 --- a/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 @@ -7,62 +7,68 @@ import { dasherize } from "@ember/string"; import I18n from "I18n"; const CustomWizardNotice = EmberObject.extend({ - expired: notEmpty('expired_at'), - dismissed: notEmpty('dismissed_at'), - hidden: notEmpty('hidden_at'), - notHidden: not('hidden'), - notDismissed: not('dismissed'), - canDismiss: and('dismissable', 'notDismissed'), - canHide: and('can_hide', 'notHidden'), + expired: notEmpty("expired_at"), + dismissed: notEmpty("dismissed_at"), + hidden: notEmpty("hidden_at"), + notHidden: not("hidden"), + notDismissed: not("dismissed"), + canDismiss: and("dismissable", "notDismissed"), + canHide: and("can_hide", "notHidden"), - @discourseComputed('type') + @discourseComputed("type") typeClass(type) { return dasherize(type); }, - @discourseComputed('type') + @discourseComputed("type") typeLabel(type) { return I18n.t(`admin.wizard.notice.type.${type}`); }, dismiss() { - if (!this.get('canDismiss')) { + if (!this.get("canDismiss")) { return; } - return ajax(`/admin/wizards/notice/${this.get('id')}/dismiss`, { type: 'PUT' }).then(result => { - if (result.success) { - this.set('dismissed_at', result.dismissed_at); - } - }).catch(popupAjaxError); + return ajax(`/admin/wizards/notice/${this.get("id")}/dismiss`, { + type: "PUT", + }) + .then((result) => { + if (result.success) { + this.set("dismissed_at", result.dismissed_at); + } + }) + .catch(popupAjaxError); }, hide() { - if (!this.get('canHide')) { + if (!this.get("canHide")) { return; } - return ajax(`/admin/wizards/notice/${this.get('id')}/hide`, { type: 'PUT' }).then(result => { - if (result.success) { - this.set('hidden_at', result.hidden_at); - } - }).catch(popupAjaxError); - } + return ajax(`/admin/wizards/notice/${this.get("id")}/hide`, { type: "PUT" }) + .then((result) => { + if (result.success) { + this.set("hidden_at", result.hidden_at); + } + }) + .catch(popupAjaxError); + }, }); CustomWizardNotice.reopenClass({ list(data = {}) { - return ajax('/admin/wizards/notice', { + return ajax("/admin/wizards/notice", { type: "GET", - data + data, }).catch(popupAjaxError); }, dismissAll() { - return ajax('/admin/wizards/notice/dismiss', { - type: "PUT" + return ajax("/admin/wizards/notice/dismiss", { + type: "PUT", }).catch(popupAjaxError); - } + }, }); export default CustomWizardNotice; diff --git a/assets/javascripts/discourse/routes/admin-wizards-notices.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-notices.js.es6 index a329ce95..1d8b7cc8 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-notices.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-notices.js.es6 @@ -9,7 +9,9 @@ export default DiscourseRoute.extend({ setupController(controller, model) { controller.setProperties({ - notices: A(model.notices.map(notice => CustomWizardNotice.create(notice))), + notices: A( + model.notices.map((notice) => CustomWizardNotice.create(notice)) + ), }); }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index 2bbc73a9..5c39c0d6 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -23,5 +23,5 @@ export default DiscourseRoute.extend({ if (transition.targetName === "adminWizards.index") { this.transitionTo("adminWizardsWizard"); } - } + }, }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-notices.hbs b/assets/javascripts/discourse/templates/admin-wizards-notices.hbs index d522c1a5..039afe49 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-notices.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-notices.hbs @@ -46,4 +46,4 @@ {{conditional-loading-spinner condition=loadingMore}} {{/load-more}} - \ No newline at end of file + diff --git a/assets/javascripts/discourse/templates/components/wizard-notice-row.hbs b/assets/javascripts/discourse/templates/components/wizard-notice-row.hbs index 7f97b250..cc22a42e 100644 --- a/assets/javascripts/discourse/templates/components/wizard-notice-row.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-notice-row.hbs @@ -27,4 +27,4 @@ {{else}} {{i18n "admin.wizard.notice.active"}} {{/if}} - \ No newline at end of file + diff --git a/assets/stylesheets/admin/admin.scss b/assets/stylesheets/admin/admin.scss index e3790465..36184088 100644 --- a/assets/stylesheets/admin/admin.scss +++ b/assets/stylesheets/admin/admin.scss @@ -926,7 +926,7 @@ $error: #ef1700; } .wizard-notice { - padding: .75em; + padding: 0.75em; margin-bottom: 1em; border: 1px solid var(--primary-low); @@ -941,7 +941,7 @@ $error: #ef1700; } .notice-badge { - padding: 0 .5em; + padding: 0 0.5em; } .notice-header { @@ -957,7 +957,7 @@ $error: #ef1700; align-items: center; .notice-badge { - margin-left: .5em; + margin-left: 0.5em; } } } @@ -1022,11 +1022,11 @@ $error: #ef1700; position: absolute; top: -8px; right: -8px; - font-size: .7em; + font-size: 0.7em; } a.show-notice-message { - padding: .25em .5em; + padding: 0.25em 0.5em; color: var(--primary); } @@ -1057,4 +1057,4 @@ a.show-notice-message { margin: 0; } } -} \ No newline at end of file +} diff --git a/controllers/custom_wizard/admin/notice.rb b/controllers/custom_wizard/admin/notice.rb index d6c43b5f..81ae00da 100644 --- a/controllers/custom_wizard/admin/notice.rb +++ b/controllers/custom_wizard/admin/notice.rb @@ -12,7 +12,7 @@ class CustomWizard::AdminNoticeController < CustomWizard::AdminController if type if type.is_a?(Array) - type = type.map { |type| CustomWizard::Notice.types[type.to_sym] } + type = type.map { |t| CustomWizard::Notice.types[t.to_sym] } else type = CustomWizard::Notice.types[type.to_sym] end @@ -20,7 +20,7 @@ class CustomWizard::AdminNoticeController < CustomWizard::AdminController if archetype if archetype.is_a?(Array) - archetype = archetype.map { |type| CustomWizard::Notice.archetypes[archetype.to_sym] } + archetype = archetype.map { |t| CustomWizard::Notice.archetypes[archetype.to_sym] } else archetype = CustomWizard::Notice.archetypes[archetype.to_sym] end diff --git a/lib/custom_wizard/notice.rb b/lib/custom_wizard/notice.rb index a07e1443..1fcb5041 100644 --- a/lib/custom_wizard/notice.rb +++ b/lib/custom_wizard/notice.rb @@ -308,7 +308,7 @@ class CustomWizard::Notice query = query.where("(value::json->>'expired_at') IS NULL") unless include_all query = query.where("(value::json->>'archetype')::integer = ?", archetype) if archetype if type - type_query_str = type.is_a?(Array) ? "(value::json->>'type')::integer IN (?)" : "(value::json->>'type')::integer = ?" + type_query_str = type.is_a?(Array) ? "(value::json->>'type')::integer IN (?)" : "(value::json->>'type')::integer = ?" query = query.where(type_query_str, type) end query = query.where("(value::json->>'title')::text = ?", title) if title