0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
Dieser Commit ist enthalten in:
angusmcleod 2021-11-17 20:48:11 +08:00
Ursprung 853634be27
Commit 49538d554d
16 geänderte Dateien mit 135 neuen und 112 gelöschten Zeilen

Datei anzeigen

@ -4,11 +4,16 @@ import NoticeMessage from "../mixins/notice-message";
export default Component.extend(NoticeMessage, { export default Component.extend(NoticeMessage, {
tagName: "tr", tagName: "tr",
attributeBindings: ["notice.id:data-notice-id"], 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: { actions: {
dismiss() { dismiss() {
this.notice.dismiss(); this.notice.dismiss();
} },
} },
}); });

Datei anzeigen

@ -3,7 +3,13 @@ import NoticeMessage from "../mixins/notice-message";
export default Component.extend(NoticeMessage, { export default Component.extend(NoticeMessage, {
attributeBindings: ["notice.id:data-notice-id"], 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: { actions: {
dismiss() { dismiss() {
@ -14,10 +20,10 @@ export default Component.extend(NoticeMessage, {
}, },
hide() { hide() {
this.set('hiding', true); this.set("hiding", true);
this.notice.hide().then(() => { this.notice.hide().then(() => {
this.set('hiding', false); this.set("hiding", false);
}); });
}, },
} },
}); });

Datei anzeigen

@ -6,14 +6,14 @@ export default {
}, },
setupComponent(attrs, component) { 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')); component.set("notices", controller.get("customWizardCriticalNotices"));
controller.addObserver('customWizardCriticalNotices.[]', () => { controller.addObserver("customWizardCriticalNotices.[]", () => {
if (this._state === "destroying") { if (this._state === "destroying") {
return; return;
} }
component.set('notices', controller.get('customWizardCriticalNotices')); component.set("notices", controller.get("customWizardCriticalNotices"));
}); });
} },
}; };

Datei anzeigen

@ -15,9 +15,9 @@ export default Controller.extend({
loadingMore: false, loadingMore: false,
canLoadMore: true, canLoadMore: true,
@discourseComputed('notices.[]', 'notices.@each.dismissed') @discourseComputed("notices.[]", "notices.@each.dismissed")
allDismisssed(notices) { allDismisssed(notices) {
return notices.every(n => !n.canDismiss || n.dismissed); return notices.every((n) => !n.canDismiss || n.dismissed);
}, },
loadMoreNotices() { loadMoreNotices() {
@ -35,7 +35,7 @@ export default Controller.extend({
} }
this.get("notices").pushObjects( 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)); .finally(() => this.set("loadingMore", false));
@ -56,12 +56,13 @@ export default Controller.extend({
I18n.t("yes_value"), I18n.t("yes_value"),
(result) => { (result) => {
if (result) { if (result) {
this.set('loadingMore', true); this.set("loadingMore", true);
CustomWizardNotice.dismissAll() CustomWizardNotice.dismissAll().finally(() =>
.finally(() => this.set("loadingMore", false)); this.set("loadingMore", false)
);
} }
} }
); );
} },
} },
}); });

Datei anzeigen

@ -17,10 +17,10 @@ export default Controller.extend({
this.adminWizardsNotices.setProperties({ this.adminWizardsNotices.setProperties({
notices: A(), notices: A(),
page: 0, page: 0,
canLoadMore: true canLoadMore: true,
}); });
this.adminWizardsNotices.loadMoreNotices(); this.adminWizardsNotices.loadMoreNotices();
} }
}); });
} },
}); });

Datei anzeigen

@ -4,34 +4,36 @@ import I18n from "I18n";
import { registerUnbound } from "discourse-common/lib/helpers"; import { registerUnbound } from "discourse-common/lib/helpers";
import { htmlSafe } from "@ember/template"; import { htmlSafe } from "@ember/template";
registerUnbound("notice-badge", function(attrs) { registerUnbound("notice-badge", function (attrs) {
let tag = attrs.url ? 'a' : 'div'; let tag = attrs.url ? "a" : "div";
let attrStr = ''; let attrStr = "";
if (attrs.title) { if (attrs.title) {
attrStr += `title='${I18n.t(attrs.title)}'`; attrStr += `title='${I18n.t(attrs.title)}'`;
} }
if (attrs.url) { if (attrs.url) {
attrStr += `href='${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) { if (attrs.icon) {
html += iconHTML(attrs.icon); html += iconHTML(attrs.icon);
} }
if (attrs.label) { if (attrs.label) {
if (attrs.icon) { if (attrs.icon) {
html += '&nbsp;'; html += "&nbsp;";
} }
html += `<span>${I18n.t(attrs.label)}</span>`; html += `<span>${I18n.t(attrs.label)}</span>`;
} }
if (attrs.date) { if (attrs.date) {
if (attrs.icon || attrs.label) { if (attrs.icon || attrs.label) {
html += '&nbsp;'; html += "&nbsp;";
} }
let dateAttrs = {}; let dateAttrs = {};
if (attrs.leaveAgo) { if (attrs.leaveAgo) {
dateAttrs = { dateAttrs = {
format: "medium", format: "medium",
leaveAgo: true leaveAgo: true,
}; };
} }
html += autoUpdatingRelativeAge(new Date(attrs.date), dateAttrs); html += autoUpdatingRelativeAge(new Date(attrs.date), dateAttrs);

Datei anzeigen

@ -22,16 +22,16 @@ export default {
}; };
withPluginApi("0.8.36", (api) => { withPluginApi("0.8.36", (api) => {
api.modifyClass('route:admin-dashboard', { api.modifyClass("route:admin-dashboard", {
setupController(controller) { setupController(controller) {
this._super(...arguments); this._super(...arguments);
controller.loadCriticalNotices(); controller.loadCriticalNotices();
controller.subscribe(); controller.subscribe();
} },
}); });
api.modifyClass('controller:admin-dashboard', { api.modifyClass("controller:admin-dashboard", {
criticalNotices: A(), criticalNotices: A(),
unsubscribe() { unsubscribe() {
@ -41,7 +41,6 @@ export default {
subscribe() { subscribe() {
this.unsubscribe(); this.unsubscribe();
this.messageBus.subscribe("/custom-wizard/notices", (data) => { this.messageBus.subscribe("/custom-wizard/notices", (data) => {
if (isPresent(data.active_notice_count)) { if (isPresent(data.active_notice_count)) {
this.loadCriticalNotices(); this.loadCriticalNotices();
} }
@ -50,19 +49,18 @@ export default {
loadCriticalNotices() { loadCriticalNotices() {
CustomWizardNotice.list({ CustomWizardNotice.list({
type: [ type: ["connection_error", "warning"],
'connection_error', archetype: "plugin_status",
'warning' visible: true,
], }).then((result) => {
archetype: 'plugin_status',
visible: true
}).then(result => {
if (result.notices && result.notices.length) { if (result.notices && result.notices.length) {
const criticalNotices = A(result.notices.map(n => CustomWizardNotice.create(n))); const criticalNotices = A(
this.set('customWizardCriticalNotices', criticalNotices); result.notices.map((n) => CustomWizardNotice.create(n))
);
this.set("customWizardCriticalNotices", criticalNotices);
} }
}); });
} },
}); });
}); });
}, },

Datei anzeigen

@ -6,7 +6,7 @@ import { createPopper } from "@popperjs/core";
export default Mixin.create({ export default Mixin.create({
showCookedMessage: false, showCookedMessage: false,
didReceiveAttrs(){ didReceiveAttrs() {
const message = this.notice.message; const message = this.notice.message;
cookAsync(message).then((cooked) => { cookAsync(message).then((cooked) => {
this.set("cookedMessage", cooked); this.set("cookedMessage", cooked);
@ -14,27 +14,24 @@ export default Mixin.create({
}, },
createMessageModal() { createMessageModal() {
let container = this.element.querySelector('.notice-message'); let container = this.element.querySelector(".notice-message");
let modal = this.element.querySelector('.cooked-notice-message'); let modal = this.element.querySelector(".cooked-notice-message");
this._popper = createPopper( this._popper = createPopper(container, modal, {
container, strategy: "absolute",
modal, { placement: "bottom-start",
strategy: "absolute", modifiers: [
placement: "bottom-start", {
modifiers: [ name: "preventOverflow",
{ },
name: "preventOverflow", {
name: "offset",
options: {
offset: [0, 5],
}, },
{ },
name: "offset", ],
options: { });
offset: [0, 5],
},
},
],
}
);
}, },
didInsertElement() { didInsertElement() {
@ -46,10 +43,16 @@ export default Mixin.create({
}, },
documentClick(event) { documentClick(event) {
if (this._state === "destroying") { return; } if (this._state === "destroying") {
return;
}
if (!event.target.closest(`[data-notice-id="${this.notice.id}"] .notice-message`)) { if (
this.set('showCookedMessage', false); !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) { if (this.showCookedMessage) {
scheduleOnce("afterRender", this, this.createMessageModal); scheduleOnce("afterRender", this, this.createMessageModal);
} }
} },
} },
}); });

Datei anzeigen

@ -7,62 +7,68 @@ import { dasherize } from "@ember/string";
import I18n from "I18n"; import I18n from "I18n";
const CustomWizardNotice = EmberObject.extend({ const CustomWizardNotice = EmberObject.extend({
expired: notEmpty('expired_at'), expired: notEmpty("expired_at"),
dismissed: notEmpty('dismissed_at'), dismissed: notEmpty("dismissed_at"),
hidden: notEmpty('hidden_at'), hidden: notEmpty("hidden_at"),
notHidden: not('hidden'), notHidden: not("hidden"),
notDismissed: not('dismissed'), notDismissed: not("dismissed"),
canDismiss: and('dismissable', 'notDismissed'), canDismiss: and("dismissable", "notDismissed"),
canHide: and('can_hide', 'notHidden'), canHide: and("can_hide", "notHidden"),
@discourseComputed('type') @discourseComputed("type")
typeClass(type) { typeClass(type) {
return dasherize(type); return dasherize(type);
}, },
@discourseComputed('type') @discourseComputed("type")
typeLabel(type) { typeLabel(type) {
return I18n.t(`admin.wizard.notice.type.${type}`); return I18n.t(`admin.wizard.notice.type.${type}`);
}, },
dismiss() { dismiss() {
if (!this.get('canDismiss')) { if (!this.get("canDismiss")) {
return; return;
} }
return ajax(`/admin/wizards/notice/${this.get('id')}/dismiss`, { type: 'PUT' }).then(result => { return ajax(`/admin/wizards/notice/${this.get("id")}/dismiss`, {
if (result.success) { type: "PUT",
this.set('dismissed_at', result.dismissed_at); })
} .then((result) => {
}).catch(popupAjaxError); if (result.success) {
this.set("dismissed_at", result.dismissed_at);
}
})
.catch(popupAjaxError);
}, },
hide() { hide() {
if (!this.get('canHide')) { if (!this.get("canHide")) {
return; return;
} }
return ajax(`/admin/wizards/notice/${this.get('id')}/hide`, { type: 'PUT' }).then(result => { return ajax(`/admin/wizards/notice/${this.get("id")}/hide`, { type: "PUT" })
if (result.success) { .then((result) => {
this.set('hidden_at', result.hidden_at); if (result.success) {
} this.set("hidden_at", result.hidden_at);
}).catch(popupAjaxError); }
} })
.catch(popupAjaxError);
},
}); });
CustomWizardNotice.reopenClass({ CustomWizardNotice.reopenClass({
list(data = {}) { list(data = {}) {
return ajax('/admin/wizards/notice', { return ajax("/admin/wizards/notice", {
type: "GET", type: "GET",
data data,
}).catch(popupAjaxError); }).catch(popupAjaxError);
}, },
dismissAll() { dismissAll() {
return ajax('/admin/wizards/notice/dismiss', { return ajax("/admin/wizards/notice/dismiss", {
type: "PUT" type: "PUT",
}).catch(popupAjaxError); }).catch(popupAjaxError);
} },
}); });
export default CustomWizardNotice; export default CustomWizardNotice;

Datei anzeigen

@ -9,7 +9,9 @@ export default DiscourseRoute.extend({
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ controller.setProperties({
notices: A(model.notices.map(notice => CustomWizardNotice.create(notice))), notices: A(
model.notices.map((notice) => CustomWizardNotice.create(notice))
),
}); });
}, },
}); });

Datei anzeigen

@ -23,5 +23,5 @@ export default DiscourseRoute.extend({
if (transition.targetName === "adminWizards.index") { if (transition.targetName === "adminWizards.index") {
this.transitionTo("adminWizardsWizard"); this.transitionTo("adminWizardsWizard");
} }
} },
}); });

Datei anzeigen

@ -926,7 +926,7 @@ $error: #ef1700;
} }
.wizard-notice { .wizard-notice {
padding: .75em; padding: 0.75em;
margin-bottom: 1em; margin-bottom: 1em;
border: 1px solid var(--primary-low); border: 1px solid var(--primary-low);
@ -941,7 +941,7 @@ $error: #ef1700;
} }
.notice-badge { .notice-badge {
padding: 0 .5em; padding: 0 0.5em;
} }
.notice-header { .notice-header {
@ -957,7 +957,7 @@ $error: #ef1700;
align-items: center; align-items: center;
.notice-badge { .notice-badge {
margin-left: .5em; margin-left: 0.5em;
} }
} }
} }
@ -1022,11 +1022,11 @@ $error: #ef1700;
position: absolute; position: absolute;
top: -8px; top: -8px;
right: -8px; right: -8px;
font-size: .7em; font-size: 0.7em;
} }
a.show-notice-message { a.show-notice-message {
padding: .25em .5em; padding: 0.25em 0.5em;
color: var(--primary); color: var(--primary);
} }

Datei anzeigen

@ -12,7 +12,7 @@ class CustomWizard::AdminNoticeController < CustomWizard::AdminController
if type if type
if type.is_a?(Array) 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 else
type = CustomWizard::Notice.types[type.to_sym] type = CustomWizard::Notice.types[type.to_sym]
end end
@ -20,7 +20,7 @@ class CustomWizard::AdminNoticeController < CustomWizard::AdminController
if archetype if archetype
if archetype.is_a?(Array) 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 else
archetype = CustomWizard::Notice.archetypes[archetype.to_sym] archetype = CustomWizard::Notice.archetypes[archetype.to_sym]
end end