Skip to content

Commit

Permalink
Various admin panel fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Aug 14, 2024
1 parent b30e76e commit 8d75f26
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
</td>

<td class="select-event">
<Input @type="checkbox" @checked={{selected}} />
<Input @type="checkbox" @checked={{this.selected}} />
</td>
23 changes: 2 additions & 21 deletions assets/javascripts/discourse/components/events-event-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,16 @@ import { observes } from "discourse-common/utils/decorators";

export default Component.extend({
tagName: "tr",
classNameBindings: [":events-event-row", "showSelect", "selected"],
classNameBindings: [":events-event-row", "selected"],
selected: false,

@observes("showSelect")
toggleWhenShowSelect() {
if (!this.showSelect) {
this.set("selected", false);
}
},

@observes("selectAll")
toggleWhenSelectAll() {
this.set("selected", this.selectAll);
},

click() {
if (this.showSelect) {
this.selectEvent();
}
},

@observes("selected")
selectEvent() {
this.toggleProperty("selected");
this.modifySelection([this.event], this.selected);
},

actions: {
selectEvent() {
this.selectEvent();
},
},
});
21 changes: 11 additions & 10 deletions assets/javascripts/discourse/components/events-event-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@
@automatic={{true}}
/>
<th>{{i18n "admin.events.event.topics"}}</th>
{{#if showSelect}}
<th class="event-actions">
{{d-button
icon="check-square"
title="admin.events.event.select_all"
action=(action "toggleSelectAll")
}}
</th>
{{/if}}
<th class="event-actions">
<DButton
@action={{action "toggleSelectAll"}}
@title="admin.events.event.select_all"
>
<span class="d-button-label">
{{i18n "admin.events.event.select_all"}}
</span>
{{d-icon "check-square"}}
</DButton>
</th>
</tr>
</thead>
<tbody>
{{#each events as |event|}}
{{events-event-row
event=event
modifySelection=modifySelection
showSelect=showSelect
selectAll=selectAll
}}
{{/each}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<DModal
class="delete-event-modal"
@title={{i18n "admin.events.event.delete.title"}}
@closeModal={{@closeModal}}
@flash={{this.flash}}
>
<:body>
<ul class="events">
{{#each model.events as |event|}}
<li class="event">{{event.name}}</li>
{{/each}}
</ul>
<div class="target-control">
<ComboBox
@content={{deleteTargets}}
@value={{deleteTarget}}
@onChange={{action (mut deleteTarget)}}
/>
</div>
</:body>
<:footer>
<DButton
@class="btn-primary"
@action={{action "delete"}}
@label={{btnLabel}}
disabled={{destroying}}
/>
<DButton
@class="btn-danger"
@label="cancel"
@action={{action "cancel"}}
disabled={{destroying}}
/>
{{conditional-loading-spinner condition=destroying size="small"}}
</:footer>
</DModal>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
import Event from "../models/event";
import Event from "../../models/event";

const DELETE_TARGETS = ["events_only", "events_and_topics", "topics_only"];

export default Controller.extend(ModalFunctionality, {
export default Component.extend({
deleteTargets: DELETE_TARGETS.map((t) => ({
id: t,
name: I18n.t(`admin.events.event.delete.${t}`),
Expand Down Expand Up @@ -39,14 +38,13 @@ export default Controller.extend(ModalFunctionality, {
Event.destroy(opts)
.then((result) => {
if (result.success) {
this.onDestroyEvents(
this.model.onDestroyEvents(
events.filter((e) => result.destroyed_event_ids.includes(e.id)),
events.filter((e) =>
result.destroyed_topics_event_ids.includes(e.id)
)
);
this.onCloseModal();
this.send("closeModal");
this.closeModal();
} else {
this.set("model.error", result.error);
}
Expand All @@ -55,8 +53,7 @@ export default Controller.extend(ModalFunctionality, {
},

cancel() {
this.onCloseModal();
this.send("closeModal");
this.closeModal();
},
},
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { A } from "@ember/array";
import Controller from "@ember/controller";
import { notEmpty } from "@ember/object/computed";
import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service";
import discourseComputed from "discourse-common/utils/decorators";
import ConfirmEventDeletion from "../components/modal/events-confirm-event-deletion";
import Message from "../mixins/message";

export default Controller.extend(Message, {
hasEvents: notEmpty("events"),
selectedEvents: A(),
modal: service(),
selectAll: false,
order: null,
asc: null,
Expand All @@ -24,17 +26,6 @@ export default Controller.extend(Message, {
},

actions: {
showSelect() {
this.toggleProperty("showSelect");

if (!this.showSelect) {
this.setProperties({
selectedEvents: A(),
selectAll: false,
});
}
},

modifySelection(events, checked) {
if (checked) {
this.get("selectedEvents").pushObjects(events);
Expand All @@ -44,35 +35,31 @@ export default Controller.extend(Message, {
},

openDelete() {
const modal = showModal("events-confirm-event-deletion", {
this.modal.show(ConfirmEventDeletion, {
model: {
events: this.selectedEvents,
},
});
onDestroyEvents: (
destroyedEvents = null,
destroyedTopicsEvents = null
) => {
this.set("selectedEvents", A());

modal.setProperties({
onDestroyEvents: (
destroyedEvents = null,
destroyedTopicsEvents = null
) => {
if (destroyedEvents) {
this.get("events").removeObjects(destroyedEvents);
}
if (destroyedEvents) {
this.get("events").removeObjects(destroyedEvents);
}

if (destroyedTopicsEvents) {
const destroyedTopicsEventIds = destroyedTopicsEvents.map(
(e) => e.id
);
if (destroyedTopicsEvents) {
const destroyedTopicsEventIds = destroyedTopicsEvents.map(
(e) => e.id
);

this.get("events").forEach((event) => {
if (destroyedTopicsEventIds.includes(event.id)) {
event.set("topics", null);
}
});
}
},
onCloseModal: () => {
this.send("showSelect");
this.get("events").forEach((event) => {
if (destroyedTopicsEventIds.includes(event.id)) {
event.set("topics", null);
}
});
}
},
},
});
},
Expand Down
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/routes/admin-plugins-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import DiscourseRoute from "discourse/routes/discourse";

export default DiscourseRoute.extend({
afterModel(model, transition) {
if (transition.to.name === "admin.events.index") {
this.router.transitionTo("admin.events.provider");
if (transition.to.name === "adminPlugins.events.index") {
this.router.transitionTo("adminPlugins.events.event");
}
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<EventsHeader @viewName={{viewName}} @message={{message}}>
{{d-button
icon="cog"
title="admin.events.event.show_select"
action=(action "showSelect")
disabled=selectDisabled
}}
{{d-button
action=(action "openDelete")
label="admin.events.event.delete.label"
Expand All @@ -22,7 +16,6 @@
page=page
order=order
asc=asc
showSelect=showSelect
modifySelection=(action "modifySelection")
selectAll=selectAll
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<AdminNav>
{{nav-item
route="adminPlugins.events.event"
label="admin.events.event.title"
}}
{{nav-item
route="adminPlugins.events.connection"
label="admin.events.connection.title"
Expand All @@ -11,10 +15,6 @@
route="adminPlugins.events.provider"
label="admin.events.provider.title"
}}
{{nav-item
route="adminPlugins.events.event"
label="admin.events.event.title"
}}
{{nav-item route="adminPlugins.events.log" label="admin.events.log.title"}}

<li class="settings">
Expand Down

This file was deleted.

Loading

0 comments on commit 8d75f26

Please sign in to comment.