Skip to content

Migrate WCF.Moderation.Management to Typescript #6116

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

Merged
merged 2 commits into from
Nov 27, 2024
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
100 changes: 64 additions & 36 deletions com.woltlab.wcf/templates/moderationActivation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@
{capture assign='contentHeader'}
<header class="contentHeader">
<div class="contentHeaderTitle">
<h1 class="contentTitle">{$__wcf->getActivePage()->getTitle()}</h1>

{if $queue->lastChangeTime}
<dl class="plain inlineDataList">
<dt>{lang}wcf.moderation.lastChangeTime{/lang}</dt>
<dd>{@$queue->lastChangeTime|time}</dd>
</dl>
{/if}

<dl class="plain inlineDataList" id="moderationAssignedUserContainer">
<dt>{lang}wcf.moderation.assignedUser{/lang}</dt>
<dd id="moderationAssignedUser">
{if $queue->assignedUserID}
<a href="{link controller='User' id=$assignedUserID}{/link}" class="userLink" data-object-id="{@$assignedUserID}">{$queue->assignedUsername}</a>
{else}
{lang}wcf.moderation.assignedUser.nobody{/lang}
{/if}
</dd>
</dl>

<dl class="plain inlineDataList" id="moderationStatusContainer">
<dt>{lang}wcf.moderation.status{/lang}</dt>
<dd id="moderationQueueStatus">{$queue->getStatus()}</dd>
</dl>
<h1 class="contentTitle">{$__wcf->getActivePage()->getTitle()}: {$queue->getTitle()}</h1>
<ul class="inlineList contentHeaderMetaData">
{event name='beforeMetaData'}

{if $queue->lastChangeTime}
<li title="{lang}wcf.moderation.lastChangeTime{/lang}">
{icon name='clock'}
{time time=$queue->lastChangeTime}
</li>
{/if}

<li title="{lang}wcf.moderation.assignedUser{/lang}">
{icon name='user'}
<span id="moderationAssignedUser">
{if $queue->assignedUserID}
<a href="{link controller='User' id=$assignedUserID}{/link}" class="userLink" data-object-id="{$assignedUserID}">{$queue->assignedUsername}</a>
{else}
{lang}wcf.moderation.assignedUser.nobody{/lang}
{/if}
</span>
</li>

<li title="{lang}wcf.moderation.status{/lang}">
{icon name='arrows-rotate'}
<span id="moderationQueueStatus">{$queue->getStatus()}</span>
</li>

{event name='afterMetaData'}
</ul>
</div>

{hascontent}
Expand All @@ -53,8 +58,29 @@
<span>{lang}wcf.moderation.assignedUser.change{/lang}</span>
</button>
{if !$queue->isDone()}
<button type="button" id="enableContent" class="contentInteractionButton button small jsOnly">{icon name='check'} <span>{lang}wcf.moderation.activation.enableContent{/lang}</span></button>
{if $queueManager->canRemoveContent($queue->getDecoratedObject())}<button type="button" id="removeContent" class="contentInteractionButton button small jsOnly">{icon name='xmark'} <span>{lang}wcf.moderation.activation.removeContent{/lang}</span></button>{/if}
<button
type="button"
id="enableContent"
class="contentInteractionButton button small jsOnly"
data-object-id="{$queue->queueID}"
data-redirect-url="{link controller='ModerationList'}{/link}"
>
{icon name='check'}
<span>{lang}wcf.moderation.activation.enableContent{/lang}</span>
</button>
{if $queueManager->canRemoveContent($queue->getDecoratedObject())}
<button
type="button"
id="removeContent"
class="contentInteractionButton button small jsOnly"
data-object-id="{$queue->queueID}"
data-object-name="{$queue->getTitle()}"
data-redirect-url="{link controller='ModerationList'}{/link}"
>
{icon name='xmark'}
<span>{lang}wcf.moderation.activation.removeContent{/lang}</span>
</button>
{/if}
{/if}
{/capture}

Expand All @@ -65,10 +91,10 @@
<section class="section sectionContainerList">
<header class="sectionHeader">
<h2 class="sectionTitle">{lang}wcf.moderation.activation.content{/lang}</h2>
<p class="sectionDescription">{lang}wcf.moderation.type.{@$queue->getObjectTypeName()}{/lang}</p>
<p class="sectionDescription">{lang}wcf.moderation.type.{$queue->getObjectTypeName()}{/lang}</p>
</header>

{@$disabledContent}
{unsafe:$disabledContent}
</section>

<section id="comments" class="section sectionContainerList moderationComments">
Expand All @@ -86,15 +112,17 @@

setup(document.getElementById('moderationAssignUser'));
});

$(function() {
WCF.Language.addObject({
'wcf.moderation.activation.enableContent.confirmMessage': '{jslang}wcf.moderation.activation.enableContent.confirmMessage{/jslang}',
'wcf.moderation.activation.removeContent.confirmMessage': '{jslang}wcf.moderation.activation.removeContent.confirmMessage{/jslang}',

{if !$queue->isDone()}
require(['WoltLabSuite/Core/Controller/Moderation/Activation'], ({ setup }) => {
{jsphrase name='wcf.moderation.activation.enableContent.confirmMessage'}

setup(
document.getElementById('enableContent'),
document.getElementById('removeContent'),
);
});

new WCF.Moderation.Activation.Management({@$queue->queueID}, '{link controller='ModerationList' encode=false}{/link}');
});
{/if}
</script>

{include file='footer'}
110 changes: 65 additions & 45 deletions com.woltlab.wcf/templates/moderationReport.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@
{capture assign='contentHeader'}
<header class="contentHeader">
<div class="contentHeaderTitle">
<h1 class="contentTitle">{$__wcf->getActivePage()->getTitle()}</h1>

{if $queue->lastChangeTime}
<dl class="plain inlineDataList">
<dt>{lang}wcf.moderation.lastChangeTime{/lang}</dt>
<dd>{@$queue->lastChangeTime|time}</dd>
</dl>
{/if}

<dl class="plain inlineDataList" id="moderationAssignedUserContainer">
<dt>{lang}wcf.moderation.assignedUser{/lang}</dt>
<dd id="moderationAssignedUser">
{if $queue->assignedUserID}
<a href="{link controller='User' id=$assignedUserID}{/link}" class="userLink" data-object-id="{@$assignedUserID}">{$queue->assignedUsername}</a>
{else}
{lang}wcf.moderation.assignedUser.nobody{/lang}
{/if}
</dd>
</dl>

<dl class="plain inlineDataList" id="moderationStatusContainer">
<dt>{lang}wcf.moderation.status{/lang}</dt>
<dd id="moderationQueueStatus">{$queue->getStatus()}</dd>
</dl>
<h1 class="contentTitle">{$__wcf->getActivePage()->getTitle()}: {$queue->getTitle()}</h1>
<ul class="inlineList contentHeaderMetaData">
{event name='beforeMetaData'}

{if $queue->lastChangeTime}
<li title="{lang}wcf.moderation.lastChangeTime{/lang}">
{icon name='clock'}
{time time=$queue->lastChangeTime}
</li>
{/if}

<li title="{lang}wcf.moderation.assignedUser{/lang}">
{icon name='user'}
<span id="moderationAssignedUser">
{if $queue->assignedUserID}
<a href="{link controller='User' id=$assignedUserID}{/link}" class="userLink" data-object-id="{$assignedUserID}">{$queue->assignedUsername}</a>
{else}
{lang}wcf.moderation.assignedUser.nobody{/lang}
{/if}
</span>
</li>

<li title="{lang}wcf.moderation.status{/lang}">
{icon name='arrows-rotate'}
<span id="moderationQueueStatus">{$queue->getStatus()}</span>
</li>

{event name='afterMetaData'}
</ul>
</div>

{hascontent}
Expand Down Expand Up @@ -54,12 +59,32 @@
</button>
{if !$queue->isDone()}
{if $queueManager->canRemoveContent($queue->getDecoratedObject())}
<button type="button" id="removeContent" class="contentInteractionButton button small jsOnly">{icon name='xmark'} <span>{lang}wcf.moderation.activation.removeContent{/lang}</span></button>
<button
type="button"
id="removeContent"
class="contentInteractionButton button small jsOnly"
data-object-id="{$queue->queueID}"
data-object-name="{$queue->getTitle()}"
data-redirect-url="{link controller='ModerationList'}{/link}"
>{icon name='xmark'} <span>{lang}wcf.moderation.activation.removeContent{/lang}</span></button>
{/if}
<button type="button" id="removeReport" class="contentInteractionButton button small jsOnly">{icon name='square-check'} <span>{lang}wcf.moderation.report.removeReport{/lang}</span></button>
<button
type="button"
id="removeReport"
class="contentInteractionButton button small jsOnly"
data-object-id="{$queue->queueID}"
data-redirect-url="{link controller='ModerationList'}{/link}"
>{icon name='square-check'} <span>{lang}wcf.moderation.report.removeReport{/lang}</span></button>
{/if}
{if $queue->canChangeJustifiedStatus()}
<button type="button" id="changeJustifiedStatus" class="contentInteractionButton button small jsOnly">{icon name='arrows-rotate'} <span>{lang}wcf.moderation.report.changeJustifiedStatus{/lang}</span></button>
<button
type="button"
id="changeJustifiedStatus"
class="contentInteractionButton button small jsOnly"
data-object-id="{$queue->queueID}"
data-redirect-url="{link controller='ModerationReport' object=$queue}{/link}"
data-justified="{if $queue->markAsJustified}true{else}false{/if}"
>{icon name='arrows-rotate'} <span>{lang}wcf.moderation.report.changeJustifiedStatus{/lang}</span></button>
{/if}
{/capture}

Expand All @@ -81,22 +106,22 @@
{else}
{lang}wcf.user.guest{/lang}
{/if}
<small class="separatorLeft">{@$queue->time|time}</small>
<small class="separatorLeft">{time time=$queue->time}</small>
</h3>
</div>

<div class="containerContent">{@$queue->getFormattedMessage()}</div>
<div class="containerContent">{unsafe:$queue->getFormattedMessage()}</div>
</div>
</div>
</section>

<section class="section">
<header class="sectionHeader">
<h2 class="sectionTitle">{lang}wcf.moderation.report.reportedContent{/lang}</h2>
<p class="sectionDescription">{lang}wcf.moderation.type.{@$queue->getObjectTypeName()}{/lang}</p>
<p class="sectionDescription">{lang}wcf.moderation.type.{$queue->getObjectTypeName()}{/lang}</p>
</header>

{@$reportedContent}
{unsafe:$reportedContent}
</section>

<section id="comments" class="section sectionContainerList moderationComments">
Expand All @@ -115,21 +140,16 @@
setup(document.getElementById('moderationAssignUser'));
});

$(function() {
WCF.Language.addObject({
'wcf.moderation.report.removeContent.confirmMessage': '{jslang}wcf.moderation.report.removeContent.confirmMessage{/jslang}',
'wcf.moderation.report.removeContent.reason': '{jslang}wcf.moderation.report.removeContent.reason{/jslang}',
'wcf.moderation.report.removeReport.confirmMessage': '{jslang}wcf.moderation.report.removeReport.confirmMessage{/jslang}',
'wcf.moderation.report.removeReport.markAsJustified': '{jslang}wcf.moderation.report.removeReport.markAsJustified{/jslang}',
'wcf.moderation.report.removeReport.confirmMessage': '{jslang}wcf.moderation.report.removeReport.confirmMessage{/jslang}',
'wcf.moderation.report.changeJustifiedStatus.markAsJustified': '{jslang}wcf.moderation.report.changeJustifiedStatus.markAsJustified{/jslang}',
'wcf.moderation.report.changeJustifiedStatus.confirmMessage': '{jslang}wcf.moderation.report.changeJustifiedStatus.confirmMessage{/jslang}',
});
require(['WoltLabSuite/Core/Controller/Moderation/Report'], ({ setup }) => {
{jsphrase name='wcf.moderation.report.removeReport.confirmMessage'}
{jsphrase name='wcf.moderation.report.removeReport.markAsJustified'}
{jsphrase name='wcf.moderation.report.changeJustifiedStatus.confirmMessage'}
{jsphrase name='wcf.moderation.report.changeJustifiedStatus.markAsJustified'}

new WCF.Moderation.Report.Management(
{@$queue->queueID},
'{link controller='ModerationList' encode=false}{/link}',
{if $queue->markAsJustified}true{else}false{/if}
setup(
document.getElementById('removeContent'),
document.getElementById('removeReport'),
document.getElementById('changeJustifiedStatus')
);
});
</script>
Expand Down
26 changes: 26 additions & 0 deletions ts/WoltLabSuite/Core/Api/ModerationQueues/ChangeJustifiedStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Changes the justified status of a report.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
* @woltlabExcludeBundle tiny
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";

export async function changeJustifiedStatus(queueId: number, markAsJustified: boolean): Promise<ApiResult<[]>> {
try {
await prepareRequest(`${window.WSC_RPC_API_URL}core/moderation-queues/${queueId}/change-justified-status`)
.post({
markAsJustified,
})
.fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
}
26 changes: 26 additions & 0 deletions ts/WoltLabSuite/Core/Api/ModerationQueues/CloseReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Closes a report by marking it as done without further processing.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
* @woltlabExcludeBundle tiny
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";

export async function closeReport(queueId: number, markAsJustified: boolean): Promise<ApiResult<[]>> {
try {
await prepareRequest(`${window.WSC_RPC_API_URL}core/moderation-queues/${queueId}/close`)
.post({
markAsJustified,
})
.fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
}
26 changes: 26 additions & 0 deletions ts/WoltLabSuite/Core/Api/ModerationQueues/DeleteContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Deletes the content associated with a moderation queue entry.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
* @woltlabExcludeBundle tiny
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";

export async function deleteContent(queueId: number, message: string): Promise<ApiResult<[]>> {
try {
await prepareRequest(`${window.WSC_RPC_API_URL}core/moderation-queues/${queueId}/delete-content`)
.post({
message,
})
.fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
}
24 changes: 24 additions & 0 deletions ts/WoltLabSuite/Core/Api/ModerationQueues/EnableContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Enables the content associated with a moderation queue entry.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
* @woltlabExcludeBundle tiny
*/

import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
import { ApiResult, apiResultFromError, apiResultFromValue } from "../Result";

export async function enableContent(queueId: number): Promise<ApiResult<[]>> {
try {
await prepareRequest(`${window.WSC_RPC_API_URL}core/moderation-queues/${queueId}/enable-content`)
.post()
.fetchAsJson();
} catch (e) {
return apiResultFromError(e);
}

return apiResultFromValue([]);
}
Loading