forked from xziino/ff14-mitigator
add translation of element, share page due to url params and default to analyse page
This commit is contained in:
parent
85d83e79a0
commit
1753b1d2ee
@ -15,7 +15,7 @@ $startTime = (float)($_POST['start_time'] ?? 0);
|
|||||||
$endTime = (float)($_POST['end_time'] ?? 0);
|
$endTime = (float)($_POST['end_time'] ?? 0);
|
||||||
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
||||||
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
||||||
$translate = $language === 'en' ? 'false' : 'true';
|
$translate = 'true';
|
||||||
|
|
||||||
if (!$reportCode || !$fightId || !$endTime) { http_response_code(400); echo json_encode(['error' => 'Missing params']); exit; }
|
if (!$reportCode || !$fightId || !$endTime) { http_response_code(400); echo json_encode(['error' => 'Missing params']); exit; }
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ $startTime = (float)($_POST['start_time'] ?? 0);
|
|||||||
$endTime = (float)($_POST['end_time'] ?? 0);
|
$endTime = (float)($_POST['end_time'] ?? 0);
|
||||||
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
||||||
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
||||||
$translate = $language === 'en' ? 'false' : 'true';
|
$translate = 'true';
|
||||||
|
|
||||||
if (!$reportCode || !$fightId || !$endTime) {
|
if (!$reportCode || !$fightId || !$endTime) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
|
|||||||
@ -17,6 +17,9 @@ $playerName = trim($_POST['player_name'] ?? '');
|
|||||||
$eventType = trim($_POST['event_type'] ?? '');
|
$eventType = trim($_POST['event_type'] ?? '');
|
||||||
$abilityId = (int)($_POST['ability_id'] ?? 0);
|
$abilityId = (int)($_POST['ability_id'] ?? 0);
|
||||||
$limit = max(1, min(500, (int)($_POST['limit'] ?? 20)));
|
$limit = max(1, min(500, (int)($_POST['limit'] ?? 20)));
|
||||||
|
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
||||||
|
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
||||||
|
$translate = 'true';
|
||||||
$startOffset = (float)($_POST['start_offset'] ?? 0) * 1000; // s → ms
|
$startOffset = (float)($_POST['start_offset'] ?? 0) * 1000; // s → ms
|
||||||
$endOffset = isset($_POST['end_offset']) && $_POST['end_offset'] !== ''
|
$endOffset = isset($_POST['end_offset']) && $_POST['end_offset'] !== ''
|
||||||
? (float)$_POST['end_offset'] * 1000
|
? (float)$_POST['end_offset'] * 1000
|
||||||
@ -33,14 +36,24 @@ $queryEnd = min($queryEnd, $endTime);
|
|||||||
|
|
||||||
$token = $_SESSION['access_token'];
|
$token = $_SESSION['access_token'];
|
||||||
|
|
||||||
|
function localized_graphql_uri(string $language): string {
|
||||||
|
$host = [
|
||||||
|
'de' => 'de.fflogs.com',
|
||||||
|
'fr' => 'fr.fflogs.com',
|
||||||
|
'jp' => 'ja.fflogs.com',
|
||||||
|
][$language] ?? 'www.fflogs.com';
|
||||||
|
return preg_replace('#https://[^/]+#', 'https://' . $host, GRAPHQL_URI);
|
||||||
|
}
|
||||||
|
|
||||||
function dbg_gql(string $query): array {
|
function dbg_gql(string $query): array {
|
||||||
global $token;
|
global $token, $language;
|
||||||
$ch = curl_init(GRAPHQL_URI);
|
$acceptLanguage = $language === 'jp' ? 'ja' : $language;
|
||||||
|
$ch = curl_init(localized_graphql_uri($language));
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_POST => true,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_POSTFIELDS => json_encode(['query' => $query]),
|
CURLOPT_POSTFIELDS => json_encode(['query' => $query]),
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token],
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token, 'Accept-Language: ' . $acceptLanguage],
|
||||||
CURLOPT_SSL_VERIFYPEER => !DEV_MODE,
|
CURLOPT_SSL_VERIFYPEER => !DEV_MODE,
|
||||||
]);
|
]);
|
||||||
$body = curl_exec($ch);
|
$body = curl_exec($ch);
|
||||||
@ -85,6 +98,7 @@ $result = dbg_gql(<<<GQL
|
|||||||
fightIDs: [$fightId],
|
fightIDs: [$fightId],
|
||||||
dataType: $dataType,
|
dataType: $dataType,
|
||||||
$includeResources
|
$includeResources
|
||||||
|
translate: $translate,
|
||||||
startTime: $queryStart,
|
startTime: $queryStart,
|
||||||
endTime: $queryEnd
|
endTime: $queryEnd
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -12,6 +12,8 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$reportCode = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['report_code'] ?? '');
|
$reportCode = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['report_code'] ?? '');
|
||||||
|
$language = strtolower(trim($_POST['language'] ?? 'en'));
|
||||||
|
$language = in_array($language, ['en', 'de', 'fr', 'jp'], true) ? $language : 'en';
|
||||||
|
|
||||||
if (strlen($reportCode) < 1) {
|
if (strlen($reportCode) < 1) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
@ -64,7 +66,17 @@ $payload = json_encode([
|
|||||||
'variables' => ['reportCode' => $reportCode],
|
'variables' => ['reportCode' => $reportCode],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$ch = curl_init(GRAPHQL_URI);
|
function localized_graphql_uri(string $language): string {
|
||||||
|
$host = [
|
||||||
|
'de' => 'de.fflogs.com',
|
||||||
|
'fr' => 'fr.fflogs.com',
|
||||||
|
'jp' => 'ja.fflogs.com',
|
||||||
|
][$language] ?? 'www.fflogs.com';
|
||||||
|
return preg_replace('#https://[^/]+#', 'https://' . $host, GRAPHQL_URI);
|
||||||
|
}
|
||||||
|
|
||||||
|
$acceptLanguage = $language === 'jp' ? 'ja' : $language;
|
||||||
|
$ch = curl_init(localized_graphql_uri($language));
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_POST => true,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_POSTFIELDS => $payload,
|
CURLOPT_POSTFIELDS => $payload,
|
||||||
@ -72,6 +84,7 @@ curl_setopt_array($ch, [
|
|||||||
CURLOPT_HTTPHEADER => [
|
CURLOPT_HTTPHEADER => [
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/json',
|
||||||
'Authorization: Bearer ' . $_SESSION['access_token'],
|
'Authorization: Bearer ' . $_SESSION['access_token'],
|
||||||
|
'Accept-Language: ' . $acceptLanguage,
|
||||||
],
|
],
|
||||||
CURLOPT_SSL_VERIFYPEER => !DEV_MODE,
|
CURLOPT_SSL_VERIFYPEER => !DEV_MODE,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -265,10 +265,7 @@
|
|||||||
let allSameReportFights = [];
|
let allSameReportFights = [];
|
||||||
|
|
||||||
function populateRefFightSelect() {
|
function populateRefFightSelect() {
|
||||||
const currentName = (window.App.fights ?? []).find(f => f.id === window.App.fightId)?.name;
|
const visible = allSameReportFights.filter(f => f.id !== window.App.fightId);
|
||||||
const visible = allSameReportFights.filter(f =>
|
|
||||||
f.id !== window.App.fightId && (!currentName || f.name === currentName)
|
|
||||||
);
|
|
||||||
refFightSelect.innerHTML = '<option value="">Kein Vergleich</option>';
|
refFightSelect.innerHTML = '<option value="">Kein Vergleich</option>';
|
||||||
visible.forEach(f => {
|
visible.forEach(f => {
|
||||||
const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?');
|
const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?');
|
||||||
@ -322,8 +319,7 @@
|
|||||||
extFights = fights;
|
extFights = fights;
|
||||||
extReportCode = code;
|
extReportCode = code;
|
||||||
|
|
||||||
const currentName = (window.App.fights ?? []).find(f => f.id === window.App.fightId)?.name;
|
const visibleExt = fights;
|
||||||
const visibleExt = currentName ? fights.filter(f => f.name === currentName) : fights;
|
|
||||||
refExtFightSelect.innerHTML = '<option value="">— Fight auswählen —</option>';
|
refExtFightSelect.innerHTML = '<option value="">— Fight auswählen —</option>';
|
||||||
visibleExt.forEach(f => {
|
visibleExt.forEach(f => {
|
||||||
const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?');
|
const hp = f.kill ? 'Kill' : (f.fightPercentage != null ? f.fightPercentage.toFixed(2) + '%' : '?');
|
||||||
|
|||||||
10
js/app.js
10
js/app.js
@ -72,6 +72,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
window.App.language = normalizeLanguage(languageSelect.value);
|
window.App.language = normalizeLanguage(languageSelect.value);
|
||||||
localStorage.setItem('ff14-mitigator-language', window.App.language);
|
localStorage.setItem('ff14-mitigator-language', window.App.language);
|
||||||
setUrlState({ language: window.App.language });
|
setUrlState({ language: window.App.language });
|
||||||
|
if (window.App.reportCode) {
|
||||||
|
loadReport(window.App.reportCode, window.App.fightId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const codeInput = form.elements['report_code'];
|
const codeInput = form.elements['report_code'];
|
||||||
@ -98,6 +101,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
outputCard.style.display = 'block';
|
outputCard.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openAnalysisTab() {
|
||||||
|
document.querySelector('.tabs .tab[data-tab="analysis"]')?.click();
|
||||||
|
}
|
||||||
|
|
||||||
function selectFight(id, updateUrl = true) {
|
function selectFight(id, updateUrl = true) {
|
||||||
const fight = allFights.find(f => f.id === id);
|
const fight = allFights.find(f => f.id === id);
|
||||||
if (!fight) return false;
|
if (!fight) return false;
|
||||||
@ -298,6 +305,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (initialUrlState.reportCode) {
|
if (initialUrlState.reportCode) {
|
||||||
form.elements['report_code'].value = initialUrlState.reportCode;
|
form.elements['report_code'].value = initialUrlState.reportCode;
|
||||||
loadReport(initialUrlState.reportCode, initialUrlState.fightId).then(() => {
|
loadReport(initialUrlState.reportCode, initialUrlState.fightId).then(() => {
|
||||||
|
if (initialUrlState.fightId) {
|
||||||
|
openAnalysisTab();
|
||||||
|
}
|
||||||
if (initialUrlState.compareFightId) {
|
if (initialUrlState.compareFightId) {
|
||||||
window.analysisTab?.selectSharedCompare?.(initialUrlState.compareFightId, initialUrlState.compareReportCode);
|
window.analysisTab?.selectSharedCompare?.(initialUrlState.compareFightId, initialUrlState.compareReportCode);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user