Skip to content

Commit 6c972c5

Browse files
authored
Merge pull request #188 from HanashiDev/feat/grid-view
Feat/grid view
2 parents 0cba12e + a5de0cc commit 6c972c5

19 files changed

Lines changed: 377 additions & 262 deletions

.github/workflows/codestyle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup PHP with tools
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: '8.0'
16+
php-version: '8.3'
1717
extensions: ctype, dom, exif, gd, gmp, hash, intl, json, libxml, mbstring, opcache, pcre, pdo, pdo_mysql, zlib
1818
tools: cs2pr, phpcs, php-cs-fixer
1919
- name: phpcs

.github/workflows/php.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- '8.1'
1616
- '8.2'
1717
- '8.3'
18+
- '8.4'
1819
steps:
1920
- name: Set up PHP
2021
uses: shivammathur/setup-php@v2

acpMenu.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

acpTemplateDelete.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

acptemplates/discordBotList.tpl

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,80 +13,8 @@
1313
</nav>
1414
</header>
1515

16-
{hascontent}
17-
<div class="paginationTop">
18-
{content}
19-
{pages print=true assign=pagesLinks controller='DiscordBotList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}
20-
{/content}
21-
</div>
22-
{/hascontent}
23-
24-
{if $objects|count}
25-
<div class="section tabularBox">
26-
<table class="table jsObjectActionContainer" data-object-action-class-name="wcf\data\discord\bot\DiscordBotAction">
27-
<thead>
28-
<tr>
29-
<th class="columnIcon"></th>
30-
<th class="columnID columnBotID{if $sortField == 'botID'} active {$sortOrder}{/if}"><a href="{link controller='DiscordBotList'}pageNo={$pageNo}&sortField=botID&sortOrder={if $sortField == 'botID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
31-
<th class="columnTitle columnBotName{if $sortField == 'botName'} active {$sortOrder}{/if}"><a href="{link controller='DiscordBotList'}pageNo={$pageNo}&sortField=botName&sortOrder={if $sortField == 'botName' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordBotList.botName{/lang}</a></th>
32-
<th class="columnText columnGuildName{if $sortField == 'guildName'} active {$sortOrder}{/if}"><a href="{link controller='DiscordBotList'}pageNo={$pageNo}&sortField=guildName&sortOrder={if $sortField == 'guildName' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordBotList.server{/lang}</a></th>
33-
<th class="columnDate columnBotTime{if $sortField == 'botTime'} active {$sortOrder}{/if}"><a href="{link controller='DiscordBotList'}pageNo={$pageNo}&sortField=botTime&sortOrder={if $sortField == 'botTime' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.date{/lang}</a></th>
34-
35-
{event name='columns'}
36-
</tr>
37-
</thead>
38-
39-
<tbody>
40-
{foreach from=$objects item=discordBot}
41-
<tr class="jsObjectActionObject" data-object-id="{$discordBot->botID}">
42-
<td class="columnIcon">
43-
<a href="{link controller='DiscordBotEdit' id=$discordBot->botID}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip">{icon size=16 name='pencil'}</a>
44-
{objectAction action="delete" objectTitle=$discordBot->botName}
45-
46-
{event name='icons'}
47-
</td>
48-
<td class="columnID">
49-
{#$discordBot->botID}
50-
</td>
51-
<td class="columnTitle">
52-
{$discordBot->botName}
53-
</td>
54-
<td class="columnText">
55-
{if !$discordBot->guildIcon|empty}
56-
<img src="https://cdn.discordapp.com/icons/{$discordBot->guildID}/{$discordBot->guildIcon}.png" style="max-width: 32px; border-radius: 50%; margin-right: 10px;">
57-
{/if}
58-
{$discordBot->guildName}
59-
</td>
60-
<td class="columnDate">
61-
{time time=$discordBot->botTime}
62-
</td>
63-
64-
{event name='columnsItem'}
65-
</tr>
66-
{/foreach}
67-
</tbody>
68-
</table>
69-
</div>
70-
71-
<footer class="contentFooter">
72-
{hascontent}
73-
<div class="paginationBottom">
74-
{content}{unsafe:$pagesLinks}{/content}
75-
</div>
76-
{/hascontent}
77-
78-
{hascontent}
79-
<nav class="contentFooterNavigation">
80-
<ul>
81-
{content}
82-
{event name='contentFooterNavigation'}
83-
{/content}
84-
</ul>
85-
</nav>
86-
{/hascontent}
87-
</footer>
88-
{else}
89-
<p class="info">{lang}wcf.global.noItems{/lang}</p>
90-
{/if}
16+
<div class="section">
17+
{unsafe:$gridView->render()}
18+
</div>
9119

9220
{include file='footer'}

acptemplates/discordWebhookList.tpl

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,91 +6,8 @@
66
</div>
77
</header>
88

9-
{hascontent}
10-
<div class="paginationTop">
11-
{content}
12-
{pages print=true assign=pagesLinks controller='DiscordWebhookList' link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}
13-
{/content}
14-
</div>
15-
{/hascontent}
16-
17-
{if $objects|count}
18-
<div class="section tabularBox">
19-
<table class="table jsObjectActionContainer" data-object-action-class-name="wcf\data\discord\webhook\DiscordWebhookAction">
20-
<thead>
21-
<tr>
22-
<th class="columnIcon"></th>
23-
<th class="columnText columnWebhookID{if $sortField == 'webhookID'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=webhookID&sortOrder={if $sortField == 'webhookID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
24-
<th class="columnText columnChannelID{if $sortField == 'channelID'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=channelID&sortOrder={if $sortField == 'channelID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordWebhookList.channelID{/lang}</a></th>
25-
<th class="columnText columnWebhookTitle{if $sortField == 'webhookTitle'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=webhookTitle&sortOrder={if $sortField == 'webhookTitle' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordWebhookList.webhookTitle{/lang}</a></th>
26-
<th class="columnText columnWebhook-Name{if $sortField == 'webhookName'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=webhookName&sortOrder={if $sortField == 'webhookName' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordWebhookList.webhookName{/lang}</a></th>
27-
<th class="columnText columnBotID{if $sortField == 'botID'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=botID&sortOrder={if $sortField == 'botID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.discordBotList.server{/lang}</a></th>
28-
<th class="columnDate columnWebhookTime{if $sortField == 'webhookTime'} active {$sortOrder}{/if}"><a href="{link controller='DiscordWebhookList'}pageNo={$pageNo}&sortField=webhookTime&sortOrder={if $sortField == 'webhookTime' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.date{/lang}</a></th>
29-
30-
{event name='columns'}
31-
</tr>
32-
</thead>
33-
34-
<tbody>
35-
{foreach from=$objects item=webhook}
36-
<tr class="jsObjectActionObject" data-object-id="{$webhook->webhookID}">
37-
<td class="columnIcon">
38-
{objectAction action="delete" objectTitle=$webhook->webhookName}
39-
40-
{event name='icons'}
41-
</td>
42-
<td class="webhookID">
43-
{$webhook->webhookID}
44-
</td>
45-
<td class="webhookID">
46-
{if $channels[$webhook->botID][$webhook->channelID]|isset}
47-
{$channels[$webhook->botID][$webhook->channelID]['name']}<br>({$webhook->channelID})
48-
{else}
49-
{$webhook->channelID}
50-
{/if}
51-
</td>
52-
<td class="columnText">
53-
{$webhook->webhookTitle}
54-
</td>
55-
<td class="columnText">
56-
{$webhook->webhookName}
57-
</td>
58-
<td class="columnText">
59-
{if !$webhook->getDiscordBot()->guildIcon|empty}
60-
<img src="https://cdn.discordapp.com/icons/{$webhook->getDiscordBot()->guildID}/{$webhook->getDiscordBot()->guildIcon}.png" style="max-width: 32px; border-radius: 50%; margin-right: 10px;">
61-
{/if}
62-
{$webhook->getDiscordBot()->guildName}
63-
</td>
64-
<td class="columnDate">
65-
{time time=$webhook->webhookTime}
66-
</td>
67-
68-
{event name='columnsItem'}
69-
</tr>
70-
{/foreach}
71-
</tbody>
72-
</table>
73-
</div>
74-
75-
<footer class="contentFooter">
76-
{hascontent}
77-
<div class="paginationBottom">
78-
{content}{unsafe:$pagesLinks}{/content}
79-
</div>
80-
{/hascontent}
81-
82-
{hascontent}
83-
<nav class="contentFooterNavigation">
84-
<ul>
85-
{content}
86-
{event name='contentFooterNavigation'}
87-
{/content}
88-
</ul>
89-
</nav>
90-
{/hascontent}
91-
</footer>
92-
{else}
93-
<p class="info">{lang}wcf.global.noItems{/lang}</p>
94-
{/if}
9+
<div class="section">
10+
{unsafe:$gridView->render()}
11+
</div>
9512

9613
{include file='footer'}

fileDelete.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

files/lib/acp/page/DiscordBotListPage.class.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace wcf\acp\page;
44

5-
use wcf\data\discord\bot\DiscordBotList;
6-
use wcf\page\SortablePage;
5+
use Override;
6+
use wcf\page\AbstractGridViewPage;
7+
use wcf\system\gridView\AbstractGridView;
8+
use wcf\system\gridView\admin\DiscordBotGridView;
79

810
/**
911
* Übersicht aller Discord-Bots
@@ -13,7 +15,7 @@
1315
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
1416
* @package WoltLabSuite\Core\Acp\Page
1517
*/
16-
class DiscordBotListPage extends SortablePage
18+
final class DiscordBotListPage extends AbstractGridViewPage
1719
{
1820
/**
1921
* @inheritDoc
@@ -25,23 +27,9 @@ class DiscordBotListPage extends SortablePage
2527
*/
2628
public $activeMenuItem = 'wcf.acp.menu.link.configuration.discord.discordBotList';
2729

28-
/**
29-
* @inheritDoc
30-
*/
31-
public $objectListClassName = DiscordBotList::class;
32-
33-
/**
34-
* @inheritDoc
35-
*/
36-
public $defaultSortField = 'botID';
37-
38-
/**
39-
* @inheritDoc
40-
*/
41-
public $defaultSortOrder = 'ASC';
42-
43-
/**
44-
* @inheritDoc
45-
*/
46-
public $validSortFields = ['botID', 'botName', 'guildID', 'guildName', 'botTime'];
30+
#[Override]
31+
protected function createGridView(): AbstractGridView
32+
{
33+
return new DiscordBotGridView();
34+
}
4735
}

files/lib/acp/page/DiscordWebhookListPage.class.php

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
namespace wcf\acp\page;
44

55
use Override;
6-
use wcf\data\discord\webhook\DiscordWebhookList;
7-
use wcf\page\SortablePage;
8-
use wcf\system\cache\builder\DiscordGuildChannelsCacheBuilder;
9-
use wcf\system\WCF;
6+
use wcf\page\AbstractGridViewPage;
7+
use wcf\system\gridView\AbstractGridView;
8+
use wcf\system\gridView\admin\DiscordWebhookGridView;
109

1110
/**
1211
* Übersicht der erstellten Discord-Webhooks
@@ -16,7 +15,7 @@
1615
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
1716
* @package WoltLabSuite\Core\Acp\Page
1817
*/
19-
class DiscordWebhookListPage extends SortablePage
18+
final class DiscordWebhookListPage extends AbstractGridViewPage
2019
{
2120
/**
2221
* @inheritDoc
@@ -28,43 +27,9 @@ class DiscordWebhookListPage extends SortablePage
2827
*/
2928
public $activeMenuItem = 'wcf.acp.menu.link.configuration.discord.discordWebhookList';
3029

31-
/**
32-
* @inheritDoc
33-
*/
34-
public $objectListClassName = DiscordWebhookList::class;
35-
36-
/**
37-
* @inheritDoc
38-
*/
39-
public $defaultSortField = 'webhookID';
40-
41-
/**
42-
* @inheritDoc
43-
*/
44-
public $defaultSortOrder = 'ASC';
45-
46-
/**
47-
* @inheritDoc
48-
*/
49-
public $validSortFields = ['channelID', 'botID', 'webhookID', 'webhookName', 'webhookTitle', 'webhookTime'];
50-
51-
protected array $channels = [];
52-
5330
#[Override]
54-
public function readData()
31+
protected function createGridView(): AbstractGridView
5532
{
56-
parent::readData();
57-
58-
$this->channels = DiscordGuildChannelsCacheBuilder::getInstance()->getData();
59-
}
60-
61-
#[Override]
62-
public function assignVariables()
63-
{
64-
parent::assignVariables();
65-
66-
WCF::getTPL()->assign([
67-
'channels' => $this->channels,
68-
]);
33+
return new DiscordWebhookGridView();
6934
}
7035
}

files/lib/bootstrap/dev.hanashi.wsc.discord-api.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use wcf\acp\page\DiscordWebhookListPage;
66
use wcf\event\acp\dashboard\box\PHPExtensionCollecting;
77
use wcf\event\acp\menu\item\ItemCollecting;
8+
use wcf\event\endpoint\ControllerCollecting;
89
use wcf\event\worker\RebuildWorkerCollecting;
10+
use wcf\system\endpoint\controller\hanashi\discord\bot\DeleteBot;
11+
use wcf\system\endpoint\controller\hanashi\discord\webhook\DeleteWebhook;
912
use wcf\system\event\EventHandler;
1013
use wcf\system\menu\acp\AcpMenuItem;
1114
use wcf\system\request\LinkHandler;
@@ -77,4 +80,12 @@ static function (RebuildWorkerCollecting $event) {
7780
$event->register(DiscordWebhookAvatarRebuildDataWorker::class, 0);
7881
}
7982
);
83+
84+
EventHandler::getInstance()->register(
85+
ControllerCollecting::class,
86+
static function (ControllerCollecting $event) {
87+
$event->register(new DeleteBot());
88+
$event->register(new DeleteWebhook());
89+
}
90+
);
8091
};

0 commit comments

Comments
 (0)