rebuild the query page
This commit is contained in:
parent
724da2f0a2
commit
3ec7f670b8
2 changed files with 176 additions and 0 deletions
|
|
@ -27,6 +27,11 @@ class SteamWorkshopController
|
|||
return;
|
||||
}
|
||||
|
||||
if ($action === 'monitor_search') {
|
||||
$this->handleMonitorSearch($userId, $isAdmin);
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<link rel="stylesheet" type="text/css" href="modules/steam_workshop/steam_workshop.css" />';
|
||||
echo '<script src="modules/steam_workshop/steam_workshop.js" defer></script>';
|
||||
|
||||
|
|
@ -67,6 +72,57 @@ class SteamWorkshopController
|
|||
$this->renderEdit($home, $config, $isAdmin, $adapterLocked);
|
||||
}
|
||||
|
||||
private function handleMonitorSearch(int $userId, bool $isAdmin): void
|
||||
{
|
||||
$homeId = isset($_GET['home_id']) ? (int)$_GET['home_id'] : 0;
|
||||
$query = trim((string)($_GET['q'] ?? ''));
|
||||
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
|
||||
$perPage = isset($_GET['per_page']) ? max(1, min(100, (int)$_GET['per_page'])) : 25;
|
||||
|
||||
$error = null;
|
||||
$results = [];
|
||||
$request = null;
|
||||
$requestSummary = null;
|
||||
|
||||
if ($homeId <= 0) {
|
||||
print_failure($this->lang['error_missing_home'] ?? 'Home ID missing.');
|
||||
return;
|
||||
}
|
||||
|
||||
$home = $this->service->getHome($homeId, $userId, $isAdmin);
|
||||
if ($home === null) {
|
||||
print_failure($this->lang['error_home_not_found'] ?? 'Home not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
$gameKey = (string)($home['game_key'] ?? '');
|
||||
$appId = $gameKey !== '' ? $this->service->getSteamAppIdForGameKey($gameKey) : null;
|
||||
|
||||
if ($query !== '' && $appId !== null) {
|
||||
$payload = $this->service->searchWorkshopItems($gameKey, $query, $perPage, $page);
|
||||
$results = $payload['results'];
|
||||
$error = $payload['error'];
|
||||
$request = $payload['request'];
|
||||
$requestSummary = $payload['request']['summary'] ?? null;
|
||||
} elseif ($query !== '' && $appId === null) {
|
||||
$error = $this->lang['error_home_not_found'] ?? 'Workshop search is unavailable for this server.';
|
||||
}
|
||||
|
||||
$this->render('monitor_search', [
|
||||
'lang' => $this->lang,
|
||||
'home' => $home,
|
||||
'homeId' => $homeId,
|
||||
'query' => $query,
|
||||
'page' => $page,
|
||||
'perPage' => $perPage,
|
||||
'results' => $results,
|
||||
'error' => $error,
|
||||
'request' => $request,
|
||||
'requestSummary' => $requestSummary,
|
||||
'appId' => $appId,
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleEdit(int $userId, bool $isAdmin): void
|
||||
{
|
||||
$homeId = isset($_GET['home_id']) ? (int)$_GET['home_id'] : 0;
|
||||
|
|
|
|||
120
modules/steam_workshop/views/monitor_search.php
Normal file
120
modules/steam_workshop/views/monitor_search.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/** @var array $home */
|
||||
/** @var array $lang */
|
||||
/** @var int $homeId */
|
||||
/** @var string $query */
|
||||
/** @var int $page */
|
||||
/** @var int $perPage */
|
||||
/** @var array $results */
|
||||
/** @var string|null $error */
|
||||
/** @var array|null $request */
|
||||
/** @var string|null $requestSummary */
|
||||
/** @var string|null $appId */
|
||||
|
||||
$homeName = htmlspecialchars($home['home_name'] ?? ('#' . $homeId), ENT_QUOTES, 'UTF-8');
|
||||
$backUrl = '?m=gamemanager&p=game_monitor';
|
||||
$requestSummaryText = $requestSummary ?? '';
|
||||
?>
|
||||
<div class="sw-monitor">
|
||||
<p><a class="sw-monitor__back" href="<?php echo $backUrl; ?>">← <?php echo htmlspecialchars($lang['simple_search_back'] ?? 'Back to Game Monitor'); ?></a></p>
|
||||
|
||||
<div class="sw-monitor__card">
|
||||
<h3><?php echo htmlspecialchars($lang['simple_search_heading'] ?? 'Steam Workshop quick search'); ?></h3>
|
||||
<p class="sw-monitor__intro">
|
||||
<?php echo htmlspecialchars(sprintf($lang['simple_search_intro'] ?? 'Look up Workshop mods for %s and copy the IDs into your config.', $homeName)); ?>
|
||||
</p>
|
||||
|
||||
<dl class="sw-monitor__meta">
|
||||
<div>
|
||||
<dt><?php echo htmlspecialchars($lang['simple_search_server'] ?? 'Server'); ?></dt>
|
||||
<dd><?php echo $homeName; ?></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt><?php echo htmlspecialchars($lang['simple_search_app'] ?? 'Steam App ID'); ?></dt>
|
||||
<dd><?php echo $appId !== null ? htmlspecialchars($appId, ENT_QUOTES, 'UTF-8') : ($lang['simple_search_app_missing'] ?? 'Not configured'); ?></dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<?php if ($appId === null): ?>
|
||||
<div class="sw-monitor__alert sw-monitor__alert--error">
|
||||
<?php echo htmlspecialchars($lang['simple_search_app_warning'] ?? 'This server is missing a Steam App ID. Ask an administrator to finish the Workshop adapter setup.'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="get" class="sw-monitor__form">
|
||||
<input type="hidden" name="m" value="steam_workshop" />
|
||||
<input type="hidden" name="p" value="main" />
|
||||
<input type="hidden" name="action" value="monitor_search" />
|
||||
<input type="hidden" name="home_id" value="<?php echo $homeId; ?>" />
|
||||
<label>
|
||||
<span><?php echo htmlspecialchars($lang['simple_search_label'] ?? 'Workshop keyword or ID'); ?></span>
|
||||
<input type="text" name="q" value="<?php echo htmlspecialchars($query ?? '', ENT_QUOTES, 'UTF-8'); ?>" placeholder="<?php echo htmlspecialchars($lang['simple_search_placeholder'] ?? 'Example: basebuilding or 2289460122'); ?>" <?php echo $appId === null ? 'disabled' : ''; ?> />
|
||||
</label>
|
||||
<div class="sw-monitor__form-row">
|
||||
<label>
|
||||
<span><?php echo htmlspecialchars($lang['simple_search_page'] ?? 'Page'); ?></span>
|
||||
<input type="number" min="1" name="page" value="<?php echo (int)$page; ?>" <?php echo $appId === null ? 'disabled' : ''; ?> />
|
||||
</label>
|
||||
<label>
|
||||
<span><?php echo htmlspecialchars($lang['simple_search_per_page'] ?? 'Items per page'); ?></span>
|
||||
<input type="number" min="1" max="100" name="per_page" value="<?php echo (int)$perPage; ?>" <?php echo $appId === null ? 'disabled' : ''; ?> />
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn primary" <?php echo $appId === null ? 'disabled' : ''; ?>><?php echo htmlspecialchars($lang['simple_search_submit'] ?? 'Search Workshop'); ?></button>
|
||||
</form>
|
||||
|
||||
<?php if ($requestSummaryText !== ''): ?>
|
||||
<div class="sw-monitor__summary">
|
||||
<strong><?php echo htmlspecialchars($lang['simple_search_request_label'] ?? 'Request summary'); ?>:</strong>
|
||||
<div class="sw-monitor__summary-text"><?php echo htmlspecialchars($requestSummaryText); ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($error !== null): ?>
|
||||
<div class="sw-monitor__alert sw-monitor__alert--error">
|
||||
<?php echo htmlspecialchars($error); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($query !== ''): ?>
|
||||
<?php if (!empty($results)): ?>
|
||||
<div class="sw-monitor__results">
|
||||
<h4><?php echo htmlspecialchars($lang['simple_search_results'] ?? 'Matching Workshop items'); ?></h4>
|
||||
<p class="sw-monitor__hint"><?php echo htmlspecialchars($lang['simple_search_copy_hint'] ?? 'Copy the Workshop ID for each mod you want to add.'); ?></p>
|
||||
<div class="sw-monitor__table-wrapper">
|
||||
<table class="sw-monitor__table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo htmlspecialchars($lang['mods_header_id'] ?? 'Workshop ID'); ?></th>
|
||||
<th><?php echo htmlspecialchars($lang['mods_header_label'] ?? 'Title'); ?></th>
|
||||
<th><?php echo htmlspecialchars($lang['mods_header_source'] ?? 'Source'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($results as $item): ?>
|
||||
<?php
|
||||
$itemId = htmlspecialchars($item['id'] ?? '', ENT_QUOTES, 'UTF-8');
|
||||
$label = htmlspecialchars($item['label'] ?? ('@' . $itemId), ENT_QUOTES, 'UTF-8');
|
||||
$source = htmlspecialchars($item['source'] ?? 'search', ENT_QUOTES, 'UTF-8');
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<code><?php echo $itemId; ?></code>
|
||||
</td>
|
||||
<td><?php echo $label; ?></td>
|
||||
<td><?php echo $source; ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($error === null): ?>
|
||||
<div class="sw-monitor__alert sw-monitor__alert--info">
|
||||
<?php echo htmlspecialchars($lang['simple_search_empty'] ?? 'No Workshop items matched that search.'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue