Rename news moderate to publish

This commit is contained in:
2025-02-25 18:08:16 +01:00
parent 2e71275f5b
commit 4890fcf0e1
21 changed files with 186 additions and 153 deletions

View File

@ -10,10 +10,10 @@ import listPlugin from "@fullcalendar/list";
import {
calendarCalendarExternal,
calendarCalendarInternal,
calendarCalendarUnmoderated,
calendarCalendarUnpublished,
newsDeleteNews,
newsModerateNews,
newsRemoveNews,
newsPublishNews,
newsUnpublishNews,
} from "#openapi";
@registerComponent("ics-calendar")
@ -89,15 +89,15 @@ export class IcsCalendar extends inheritHtmlElement("div") {
this.calendar.refetchEvents();
}
async moderateNews(id: number) {
await newsModerateNews({
async publishNews(id: number) {
await newsPublishNews({
path: {
// biome-ignore lint/style/useNamingConvention: python API
news_id: id,
},
});
this.dispatchEvent(
new CustomEvent("calendar-moderate", {
new CustomEvent("calendar-publish", {
bubbles: true,
detail: {
id: id,
@ -107,15 +107,15 @@ export class IcsCalendar extends inheritHtmlElement("div") {
await this.refreshEvents();
}
async removeNews(id: number) {
await newsRemoveNews({
async unpublishNews(id: number) {
await newsUnpublishNews({
path: {
// biome-ignore lint/style/useNamingConvention: python API
news_id: id,
},
});
this.dispatchEvent(
new CustomEvent("calendar-remove", {
new CustomEvent("calendar-unpublish", {
bubbles: true,
detail: {
id: id,
@ -157,10 +157,10 @@ export class IcsCalendar extends inheritHtmlElement("div") {
className: "external",
},
{
url: `${await makeUrl(calendarCalendarUnmoderated)}${cacheInvalidate}`,
url: `${await makeUrl(calendarCalendarUnpublished)}${cacheInvalidate}`,
format: "ics",
color: "red",
className: "unmoderated",
className: "unpublished",
},
];
}
@ -233,20 +233,20 @@ export class IcsCalendar extends inheritHtmlElement("div") {
const newsId = this.getNewsId(event);
const div = document.createElement("div");
if (this.canModerate) {
if (event.source.internalEventSource.ui.classNames.includes("unmoderated")) {
if (event.source.internalEventSource.ui.classNames.includes("unpublished")) {
const button = document.createElement("button");
button.innerHTML = `<i class="fa fa-check"></i>${gettext("Moderate")}`;
button.innerHTML = `<i class="fa fa-check"></i>${gettext("Publish")}`;
button.setAttribute("class", "btn btn-green");
button.onclick = () => {
this.moderateNews(newsId);
this.publishNews(newsId);
};
div.appendChild(button);
} else {
const button = document.createElement("button");
button.innerHTML = `<i class="fa fa-times"></i>${gettext("Remove")}`;
button.innerHTML = `<i class="fa fa-times"></i>${gettext("Unpublish")}`;
button.setAttribute("class", "btn btn-orange");
button.onclick = () => {
this.removeNews(newsId);
this.unpublishNews(newsId);
};
div.appendChild(button);
}

View File

@ -1,5 +1,5 @@
import { exportToHtml } from "#core:utils/globals";
import { newsDeleteNews, newsFetchNewsDates, newsModerateNews } from "#openapi";
import { newsDeleteNews, newsFetchNewsDates, newsPublishNews } from "#openapi";
// This will be used in jinja templates,
// so we cannot use real enums as those are purely an abstraction of Typescript
@ -7,7 +7,7 @@ const AlertState = {
// biome-ignore lint/style/useNamingConvention: this feels more like an enum
PENDING: 1,
// biome-ignore lint/style/useNamingConvention: this feels more like an enum
MODERATED: 2,
PUBLISHED: 2,
// biome-ignore lint/style/useNamingConvention: this feels more like an enum
DELETED: 3,
};
@ -19,11 +19,11 @@ document.addEventListener("alpine:init", () => {
newsId: newsId as number,
loading: false,
async moderateNews() {
async publishNews() {
this.loading = true;
// biome-ignore lint/style/useNamingConvention: api is snake case
await newsModerateNews({ path: { news_id: this.newsId } });
this.state = AlertState.MODERATED;
await newsPublishNews({ path: { news_id: this.newsId } });
this.state = AlertState.PUBLISHED;
this.$dispatch("news-moderated", { newsId: this.newsId, state: this.state });
this.loading = false;
},
@ -54,7 +54,7 @@ document.addEventListener("alpine:init", () => {
* Query the server to know the number of news dates that would be moderated
* if this one is moderated.
*/
async nbToModerate(): Promise<number> {
async nbToPublish(): Promise<number> {
// What we want here is the count attribute of the response.
// We don't care about the actual results,
// so we ask for the minimum page size possible.
@ -69,8 +69,8 @@ document.addEventListener("alpine:init", () => {
return interpolate(
gettext(
"This event will take place every week for %s weeks. " +
"If you moderate or delete this event, " +
"it will also be moderated (or deleted) for the following weeks.",
"If you publish or delete this event, " +
"it will also be published (or deleted) for the following weeks.",
),
[nbEvents],
);