-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
News list improvements #1009
Open
imperosol
wants to merge
7
commits into
taiste
Choose a base branch
from
news-list
base: taiste
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
News list improvements #1009
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74385bd
API to moderate and delete news
imperosol df6fc48
Improve news list display
imperosol 4a2fdb8
News moderation buttons directly on the home page
imperosol 96f5874
Set the moderator when moderating news
imperosol 8f15641
remove alpine instructions for moderated news
imperosol 266cef3
remove Alpine import in moderation-alert-index.ts
imperosol b23c322
Add a disclaimer when moderating weekly news
imperosol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
com/static/bundled/com/components/moderation-alert-index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { exportToHtml } from "#core:utils/globals"; | ||
import { newsDeleteNews, newsModerateNews } from "#openapi"; | ||
|
||
// This will be used in jinja templates, | ||
// so we cannot use real enums as those are purely an abstraction of Typescript | ||
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, | ||
// biome-ignore lint/style/useNamingConvention: this feels more like an enum | ||
DELETED: 3, | ||
}; | ||
exportToHtml("AlertState", AlertState); | ||
|
||
document.addEventListener("alpine:init", () => { | ||
Alpine.data("moderationAlert", (newsId: number) => ({ | ||
state: AlertState.PENDING, | ||
newsId: newsId as number, | ||
loading: false, | ||
|
||
async moderateNews() { | ||
this.loading = true; | ||
// biome-ignore lint/style/useNamingConvention: api is snake case | ||
await newsModerateNews({ path: { news_id: this.newsId } }); | ||
this.state = AlertState.MODERATED; | ||
this.loading = false; | ||
}, | ||
|
||
async deleteNews() { | ||
this.loading = true; | ||
// biome-ignore lint/style/useNamingConvention: api is snake case | ||
await newsDeleteNews({ path: { news_id: this.newsId } }); | ||
this.state = AlertState.DELETED; | ||
this.loading = false; | ||
}, | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{% macro news_moderation_alert(news, user, alpineState = None) %} | ||
{# An alert to display on top of non moderated news, | ||
with actions to either moderate or delete them. | ||
|
||
The current state of the alert is accessible through | ||
the given `alpineState` variable. | ||
This state is a `AlertState`, as defined in `moderation-alert-index.ts` | ||
|
||
Example : | ||
```jinja | ||
<div x-data="{state: AlertState.PENDING}"> | ||
{{ news_moderation_alert(news, user, "state") }} | ||
</div> | ||
``` | ||
|
||
Args: | ||
news: The `News` object to which this alert is related | ||
user: The request.user | ||
alpineState: An alpine variable name | ||
|
||
Warning: | ||
If you use this macro, you must also include `moderation-alert-index.ts` | ||
in your template. | ||
#} | ||
<div | ||
x-data="moderationAlert({{ news.id }})" | ||
{% if alpineState %} | ||
x-modelable="{{ alpineState }}" | ||
x-model="state" | ||
{% endif %} | ||
> | ||
<template x-if="state === AlertState.PENDING"> | ||
<div class="alert alert-yellow"> | ||
<div class="alert-main"> | ||
<strong>{% trans %}Waiting moderation{% endtrans %}</strong> | ||
<p> | ||
{% trans trimmed %} | ||
This news isn't moderated and is visible | ||
only by its author and the communication admins. | ||
{% endtrans %} | ||
</p> | ||
<p> | ||
{% trans trimmed %} | ||
It will stay hidden for other users until it has been moderated. | ||
{% endtrans %} | ||
</p> | ||
{% if user.has_perm("com.moderate_news") %} | ||
{# This is an additional query for each non-moderated news, | ||
but it will be executed only for admin users, and only one time | ||
(if they do their job and moderated news as soon as they see them), | ||
so it's still reasonable #} | ||
{% set nb_event=news.dates.count() %} | ||
{% if nb_event > 1 %} | ||
<br> | ||
<strong>{% trans %}Weekly event{% endtrans %}</strong> | ||
<p> | ||
{% trans trimmed nb=nb_event %} | ||
This event will take place every week for {{ nb }} weeks. | ||
If you moderate or delete this event, | ||
it will also be moderated (or deleted) for the following weeks. | ||
{% endtrans %} | ||
</p> | ||
{% endif %} | ||
{% endif %} | ||
</div> | ||
{% if user.has_perm("com.moderate_news") %} | ||
<span class="alert-aside" :aria-busy="loading"> | ||
<button class="btn btn-green" @click="moderateNews()" :disabled="loading"> | ||
<i class="fa fa-check"></i> {% trans %}Moderate{% endtrans %} | ||
</button> | ||
{% endif %} | ||
{% if user.has_perm("com.delete_news") %} | ||
<button class="btn btn-red" @click="deleteNews()" :disabled="loading"> | ||
<i class="fa fa-trash-can"></i> {% trans %}Delete{% endtrans %} | ||
</button> | ||
</span> | ||
{% endif %} | ||
</div> | ||
</template> | ||
<template x-if="state === AlertState.MODERATED"> | ||
<div class="alert alert-green"> | ||
{% trans %}News moderated{% endtrans %} | ||
</div> | ||
</template> | ||
<template x-if="state === AlertState.DELETED"> | ||
<div class="alert alert-red"> | ||
{% trans %}News deleted{% endtrans %} | ||
</div> | ||
</template> | ||
</div> | ||
{% endmacro %} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ce serait bien de pouvoir forcer le reload du calendrier quand on fait ça pour avoir une expérience plus smooth.
Tu peux mettre un x-ref dessus et utiliser refetchEvents https://fullcalendar.io/docs/Calendar-refetchEvents