Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions com.woltlab.wcf/templates/moderationList.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@
{/capture}

{capture assign='contentInteractionButtons'}
<button type="button" class="markAllAsReadButton contentInteractionButton button small jsOnly">{icon name='check'} <span>{lang}wcf.global.button.markAllAsRead{/lang}</span></button>
{if $gridView->canMarkAsRead()}
<button type="button" class="markAllModerationQueuesAsReadButton contentInteractionButton button small jsOnly">
{icon name='check'}
<span>{lang}wcf.global.button.markAllAsRead{/lang}</span>
</button>

<script data-relocate="true">
require(['WoltLabSuite/Core/Component/Moderation/MarkAllModerationQueuesAsRead'], ({ setup }) => {
setup(
document.querySelector('.markAllModerationQueuesAsReadButton'),
document.getElementById('{unsafe:$gridView->getID()|encodeJS}_table')
);
});
</script>
{/if}
<a href="{link controller='DeletedContentList'}{/link}" class="contentInteractionButton button small">{icon name='trash-can'} <span>{lang}wcf.moderation.showDeletedContent{/lang}</span></a>
{/capture}

Expand All @@ -16,10 +30,4 @@
{unsafe:$gridView->render()}
</div>

<script data-relocate="true">
require(['WoltLabSuite/Core/Ui/Moderation/MarkAllAsRead'], (MarkAllAsRead) => {
MarkAllAsRead.setup();
});
</script>

{include file='footer'}
11 changes: 11 additions & 0 deletions ts/WoltLabSuite/Core/Component/GridView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { getRow } from "../Api/GridViews/GetRow";
import { getRows } from "../Api/GridViews/GetRows";
import { getBulkContextMenuOptions } from "../Api/Interactions/GetBulkContextMenuOptions";
import { postObject } from "../Api/PostObject";
import DomChangeListener from "../Dom/Change/Listener";
import DomUtil from "../Dom/Util";
import { promiseMutex } from "../Helper/PromiseMutex";
Expand Down Expand Up @@ -104,6 +105,16 @@ export class GridView {
});
}
});

wheneverFirstSeen(`#${this.#table.id} tbody tr .gridView__row__markAsRead`, (button: HTMLButtonElement) => {
button.addEventListener(
"click",
promiseMutex(async () => {
await postObject(button.dataset.endpoint!);
button.closest("tr")?.dispatchEvent(new CustomEvent("interaction:invalidate", { bubbles: true }));
}),
);
});
}

#initEventListeners(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Handles the 'mark as read' action for moderation queues.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
* @woltlabExcludeBundle tiny
*/

import { showDefaultSuccessSnackbar } from "WoltLabSuite/Core/Component/Snackbar";
import { markAllModerationQueuesAsRead } from "WoltLabSuite/Core/Api/ModerationQueues/MarkAllModerationQueuesAsRead";
import { promiseMutex } from "WoltLabSuite/Core/Helper/PromiseMutex";

async function markAllAsRead(button: HTMLElement, gridView?: HTMLElement): Promise<void> {
(await markAllModerationQueuesAsRead()).unwrap();

if (gridView !== undefined) {
gridView.dispatchEvent(new CustomEvent("interaction:invalidate-all"));
}

button.remove();

showDefaultSuccessSnackbar();
}

export function setup(button: HTMLElement, gridView?: HTMLElement): void {
button.addEventListener(
"click",
promiseMutex(async () => {
await markAllAsRead(button, gridView);
}),
);
}
26 changes: 0 additions & 26 deletions ts/WoltLabSuite/Core/Ui/Moderation/MarkAllAsRead.ts

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace wcf\system\gridView;

use wcf\action\ApiAction;
use wcf\action\GridViewFilterAction;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
Expand Down Expand Up @@ -64,6 +65,7 @@ abstract class AbstractGridView
private ?IInteractionProvider $interactionProvider = null;
private ?IBulkInteractionProvider $bulkInteractionProvider = null;
private InteractionContextMenuComponent $interactionContextMenuComponent;
private string $markAsReadEndpoint = '';

/**
* @var array<string, string|int>
Expand Down Expand Up @@ -313,6 +315,10 @@ public function renderColumn(GridViewColumn $column, DatabaseObject $row): strin
$value = $this->rowLink->render($value, $row, $column->isTitleColumn());
}

if ($column->hasMarkAsReadButton() && $this->rowIsNew($row)) {
$value = $this->renderMarkAsReadButton($row) . $value;
}

return $value;
}

Expand Down Expand Up @@ -952,6 +958,49 @@ public function getAvailableFilters(): array
return $this->availableFilters;
}

/**
* @since 6.3
*/
public function setMarkAsReadEndpoint(string $endpoint): void
{
$this->markAsReadEndpoint = $endpoint;
}

/**
* @since 6.3
*/
public function renderMarkAsReadButton(DatabaseObject $object): string
{
if (!$this->markAsReadEndpoint) {
throw new \BadMethodCallException("No mark as read endpoint has been specified.");
}

$endpoint = StringUtil::encodeHTML(
LinkHandler::getInstance()->getControllerLink(ApiAction::class, ['id' => 'rpc']) .
\sprintf($this->markAsReadEndpoint, $object->getObjectID())
);
$title = WCF::getLanguage()->get('wcf.global.button.markAsRead');

return <<<HTML
<button
type="button"
class="gridView__row__markAsRead jsTooltip"
title="{$title}"
data-endpoint="{$endpoint}"
>
<span class="gridView__row__unread__indicator" aria-hidden="true"></span>
</button>
HTML;
}

/**
* @since 6.3
*/
public function rowIsNew(DatabaseObject $row): bool
{
return false;
}

private function init(): void
{
if (!isset($this->objectList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class GridViewColumn
private bool $hidden = false;
private bool $unsafeDisableEncoding = false;
private bool $titleColumn = false;
private bool $markAsReadButton = false;

private function __construct(private readonly string $id) {}

Expand Down Expand Up @@ -302,6 +303,28 @@ public function applyRowLink(): bool
)) === 0;
}

/**
* Sets whether the mark as read button is rendered in this column for unread rows.
*
* @since 6.3
*/
public function markAsReadButton(bool $markAsReadButton = true): static
{
$this->markAsReadButton = $markAsReadButton;

return $this;
}

/**
* Returns true if the mark as read button is rendered in this column for unread rows.
*
* @since 6.3
*/
public function hasMarkAsReadButton(): bool
{
return $this->markAsReadButton;
}

/**
* Returns the default renderer for the rendering of columns.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,15 @@ public function __construct()
GridViewColumn::for('title')
->label('wcf.global.title')
->titleColumn()
->markAsReadButton()
->renderer(
new class extends DefaultColumnRenderer {
#[\Override]
public function render(mixed $value, DatabaseObject $row): string
{
\assert($row instanceof ViewableModerationQueue);
$title = StringUtil::encodeHTML($row->getTitle());

if ($row->isNew()) {
$badgeLabel = WCF::getLanguage()->get('wcf.message.new');
$badge = <<<HTML
<span class="badge label newMessageBadge">{$badgeLabel}</span>
HTML;
} else {
$badge = '';
}

return <<<HTML
{$title}{$badge}
HTML;
return StringUtil::encodeHTML($row->getTitle());
}
}
),
Expand Down Expand Up @@ -216,6 +205,16 @@ public function render(mixed $value, DatabaseObject $row): string
$this->setDefaultSortField("lastChangeTime");
$this->setDefaultSortOrder("DESC");
$this->addRowLink(new GridViewRowLink(isLinkableObject: true));
$this->setMarkAsReadEndpoint('core/moderation-queues/%s/mark-as-read');
}

public function canMarkAsRead(): bool
{
if (!WCF::getUser()->userID) {
return false;
}

return ModerationQueueManager::getInstance()->getUnreadModerationCount() > 0;
}

private function getDefinitionFilter(): SelectFilter
Expand Down Expand Up @@ -275,4 +274,12 @@ protected function getInitializedEvent(): ModerationQueueGridViewInitialized
{
return new ModerationQueueGridViewInitialized($this);
}

#[\Override]
public function rowIsNew(DatabaseObject $row): bool
{
\assert($row instanceof ViewableModerationQueue);

return $row->isNew();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ final class ModerationQueueInteractions extends AbstractInteractionProvider
public function __construct()
{
$this->addInteractions([
new RpcInteraction(
"mark-as-read",
"core/moderation-queues/%s/mark-as-read",
"wcf.global.button.markAsRead",
isAvailableCallback: static function (ViewableModerationQueue $queue) {
return $queue->isNew();
}
),
new FormBuilderDialogInteraction(
"assign-user",
LinkHandler::getInstance()->getControllerLink(ModerationQueueAssignUserAction::class, ["id" => "%s"]),
Expand Down
Loading
Loading