1
0
Fork 0
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, {
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();
}
}
});
},
},
});

Datei anzeigen

@ -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);
});
},
}
},
});

Datei anzeigen

@ -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"));
});
}
};
},
};

Datei anzeigen

@ -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)
);
}
}
);
}
}
},
},
});

Datei anzeigen

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

Datei anzeigen

@ -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 += '&nbsp;';
html += "&nbsp;";
}
html += `<span>${I18n.t(attrs.label)}</span>`;
}
if (attrs.date) {
if (attrs.icon || attrs.label) {
html += '&nbsp;';
html += "&nbsp;";
}
let dateAttrs = {};
if (attrs.leaveAgo) {
dateAttrs = {
format: "medium",
leaveAgo: true
leaveAgo: true,
};
}
html += autoUpdatingRelativeAge(new Date(attrs.date), dateAttrs);
}
html += `</${tag}>`;
return htmlSafe(html);
});
});

Datei anzeigen

@ -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);
}
});
}
},
});
});
},

Datei anzeigen

@ -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);
}
}
}
});
},
},
});

Datei anzeigen

@ -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;

Datei anzeigen

@ -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))
),
});
},
});

Datei anzeigen

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

Datei anzeigen

@ -46,4 +46,4 @@
{{conditional-loading-spinner condition=loadingMore}}
{{/load-more}}
</div>
</div>

Datei anzeigen

@ -27,4 +27,4 @@
{{else}}
<span>{{i18n "admin.wizard.notice.active"}}</span>
{{/if}}
</td>
</td>

Datei anzeigen

@ -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;
}
}
}
}

Datei anzeigen

@ -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

Datei anzeigen

@ -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