chore(driver): removed analysis box, replaced with additional cargo & stock info

This commit is contained in:
2026-05-07 14:10:59 +02:00
parent 0793285de8
commit 72a80577f0
5 changed files with 140 additions and 246 deletions
+102 -201
View File
@@ -1,6 +1,6 @@
<template> <template>
<div class="analysis-box"> <div class="analysis-box">
<div class="driver-propositions"> <div class="analysis-propositions">
<h3>{{ t('analysis.propositions.header') }}</h3> <h3>{{ t('analysis.propositions.header') }}</h3>
<div class="categories-select"> <div class="categories-select">
@@ -57,79 +57,38 @@
class="train-badge" class="train-badge"
:class="warningKey.split('-')[2]" :class="warningKey.split('-')[2]"
> >
{{ t('analysis.warnings.' + warningKey) }} {{ t('analysis.warnings.' + warningKey, cargoWarnings[warningKey]) }}
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="cargo-warnings no-warnings" v-else>
<hr class="divider" /> <hr class="divider" />
{{ t('analysis.warnings.no-warnings') }}
<div class="analysis-content"> </div>
<div class="analysis-header">
<h3>
{{ t('analysis.title') }}
</h3>
<button
class="btn btn--image"
:data-checked="analysisi18n.global.locale == 'pl'"
@click="changeAnalysisLanguage('pl')"
>
<img src="/images/flags/pl.svg" alt="flag pl" width="25" />
</button>
<button
class="btn btn--image"
:data-checked="analysisi18n.global.locale == 'en'"
@click="changeAnalysisLanguage('en')"
>
<img src="/images/flags/en.svg" alt="flag eng" width="25" />
</button>
</div> </div>
<div class="analysis-html" v-html="analysisHtml"></div>
<hr class="divider" />
<div class="analysis-actions"> <div class="analysis-actions">
<button class="btn btn--action" @click="copyAnalysisToClipboard()">
<i class="fa-regular fa-copy"></i>{{ t('analysis.button-copy') }} ({{
analysisi18n.global.locale.toUpperCase()
}})
</button>
<button class="btn btn--action" @click="copyStockToClipboard()"> <button class="btn btn--action" @click="copyStockToClipboard()">
<i class="fa-regular fa-copy"></i> {{ t('analysis.stock-copy') }} <i class="fa-regular fa-copy"></i> {{ t('analysis.stock-copy') }}
</button> </button>
</div>
<p class="number-info"><i>$number</i> {{ t('analysis.number-info') }}</p> <button class="btn btn--action" @click="copyNumberToClipboard()">
<i class="fa-regular fa-copy"></i> {{ t('analysis.number-copy') }}
</button>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, PropType, watch, onMounted } from 'vue'; import { ref, computed, PropType, watch, onMounted } from 'vue';
import { createI18n, useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Train } from '../../typings/common'; import { Train } from '../../typings/common';
import rulesJSON from '../../data/trainNumberRules.json'; import rulesJSON from '../../data/trainNumberRules.json';
import { useApiStore } from '../../store/apiStore'; import { useApiStore } from '../../store/apiStore';
import enLang from '../../locales/analysis/en.json';
import plLang from '../../locales/analysis/pl.json';
const { t } = useI18n(); const { t } = useI18n();
const analysisi18n = createI18n({
locale: 'pl',
messages: {
en: enLang,
pl: plLang
},
sync: false
});
const apiStore = useApiStore(); const apiStore = useApiStore();
const props = defineProps({ const props = defineProps({
@@ -157,107 +116,6 @@ onMounted(() => {
generateNumberPropositions(); generateNumberPropositions();
}); });
function selectCategory(i: number) {
chosenCategoryIndex.value = i;
generateNumberPropositions();
}
function generateNumberPropositions() {
const categoryCode = chosenCategory.value?.slice(0, 2);
const trainNoStr = props.chosenTrain.trainNo.toString();
// Get category rules
const rules = categoryCode
? ((rulesJSON.categoriesRules as any)[categoryCode] as any[])
: undefined;
if (!categoryCode || !rules) {
numberPropositions.value.length = 0;
chosenCategoryRules.value.length = 0;
return;
}
const [thirdNumber, minRange, maxRange] = rules;
const propositionsArr: string[] = [];
for (let i = 0; i < 5; i++) {
let generatedNumStr = '';
generatedNumStr += trainNoStr[0] ?? Math.floor(Math.random() * 10);
generatedNumStr += trainNoStr[1] ?? Math.floor(Math.random() * 10);
// Third number
generatedNumStr += thirdNumber ?? '';
// Remaining numbers
const rangeNums = minRange?.length ?? 3;
const randRange = Math.floor(
Math.random() * (Number(maxRange) - Number(minRange)) + Number(minRange)
).toString();
const leadingZeros = new Array(Math.abs(randRange.toString().length - rangeNums))
.fill('0')
.join('');
generatedNumStr += `${leadingZeros}${randRange}`;
const isNumberTaken =
apiStore.activeData?.trains?.some((t) => t.trainNo.toString() == generatedNumStr) ?? false;
if (!isNumberTaken) {
propositionsArr.push(generatedNumStr);
} else {
i--;
}
if (Number(randRange) > Number(maxRange)) break;
}
numberPropositions.value = propositionsArr;
chosenCategoryRules.value = rules;
}
function copyStockToClipboard() {
const stockString = props.chosenTrain.stockList.join(';');
if (!stockString) {
alert(t('analysis.stock-clipboard-failure'));
return;
}
navigator.clipboard
.writeText(stockString)
.then(() => {
prompt(t('analysis.stock-clipboard-success'), stockString);
})
.catch(() => {
alert(t('analysis.stock-clipboard-failure'));
});
}
function copyAnalysisToClipboard() {
let content = `\n${analysisi18n.global.t('title')}`;
content += analysisHtml.value;
content = content.replace(/<br>/g, '\n');
navigator.clipboard
.writeText(content)
.then(() => {
prompt(t('analysis.stock-clipboard-success'), content);
})
.catch(() => {
alert(t('analysis.stock-clipboard-failure'));
});
}
function changeAnalysisLanguage(langId: 'pl' | 'en') {
analysisi18n.global.locale = langId;
}
const chosenCategory = computed(() => { const chosenCategory = computed(() => {
return availableCategories.value[chosenCategoryIndex.value]; return availableCategories.value[chosenCategoryIndex.value];
}); });
@@ -371,39 +229,100 @@ const availableCategories = computed(() => {
return availableCategories.map((c) => `${c}${categoryTraction}`); return availableCategories.map((c) => `${c}${categoryTraction}`);
}); });
const analysisHtml = computed(() => { function selectCategory(i: number) {
let analysisStr = `<b>${chosenCategory.value} $number </b> (${props.chosenTrain.stockList[0]}, ${(props.chosenTrain.mass / 1000).toFixed(1)}t, ${props.chosenTrain.length}m)`; chosenCategoryIndex.value = i;
generateNumberPropositions();
if (Object.keys(cargoWarnings.value).length > 0) {
if (Object.keys(cargoWarnings.value).some((k) => k.includes('-twr')))
analysisStr += `<br>${analysisi18n.global.t('has-twr')}`;
if (Object.keys(cargoWarnings.value).some((k) => k.includes('-tn')))
analysisStr += `<br>${analysisi18n.global.t('has-tn')}`;
if (cargoWarnings.value['zags-loaded-twr'] || cargoWarnings.value['zags-empty-tn']) {
analysisStr += `<br><i>33UN1965 ${cargoWarnings.value['zags-loaded-twr'] || 0}/${cargoWarnings.value['zags-empty-tn'] || 0} Zags</i>`;
} }
if (cargoWarnings.value['zans-loaded-tn'] || cargoWarnings.value['zans-empty-tn']) { function generateNumberPropositions() {
analysisStr += `<br><i>33UN1203 ${cargoWarnings.value['zans-loaded-tn'] || 0}/${cargoWarnings.value['zans-empty-tn'] || 0} Zans</i>`; const categoryCode = chosenCategory.value?.slice(0, 2);
const trainNoStr = props.chosenTrain.trainNo.toString();
// Get category rules
const rules = categoryCode
? ((rulesJSON.categoriesRules as any)[categoryCode] as any[])
: undefined;
if (!categoryCode || !rules) {
numberPropositions.value.length = 0;
chosenCategoryRules.value.length = 0;
return;
} }
if (Object.keys(cargoWarnings.value).some((k) => k.includes('-pn'))) { const [thirdNumber, minRange, maxRange] = rules;
analysisStr += `${analysisi18n.global.t('has-pn')}:`;
if (cargoWarnings.value['innofreight-all-pn']) { const propositionsArr: string[] = [];
analysisStr += `<br> - Innofreight - przekroczona skrajnia`;
for (let i = 0; i < 5; i++) {
let generatedNumStr = '';
generatedNumStr += trainNoStr[0] ?? Math.floor(Math.random() * 10);
generatedNumStr += trainNoStr[1] ?? Math.floor(Math.random() * 10);
// Third number
generatedNumStr += thirdNumber ?? '';
// Remaining numbers
const rangeNums = minRange?.length ?? 3;
const randRange = Math.floor(
Math.random() * (Number(maxRange) - Number(minRange)) + Number(minRange)
).toString();
const leadingZeros = new Array(Math.abs(randRange.toString().length - rangeNums))
.fill('0')
.join('');
generatedNumStr += `${leadingZeros}${randRange}`;
const isNumberTaken =
apiStore.activeData?.trains?.some((t) => t.trainNo.toString() == generatedNumStr) ?? false;
if (!isNumberTaken) {
propositionsArr.push(generatedNumStr);
} else {
i--;
} }
if (cargoWarnings.value['military-all-pn']) { if (Number(randRange) > Number(maxRange)) break;
analysisStr += `<br> - transport wojskowy`;
}
}
} }
return analysisStr; numberPropositions.value = propositionsArr;
chosenCategoryRules.value = rules;
}
function copyStockToClipboard() {
const stockString = props.chosenTrain.stockList.join(';');
if (!stockString) {
alert(t('analysis.stock-clipboard-failure'));
return;
}
navigator.clipboard
.writeText(stockString)
.then(() => {
prompt(t('analysis.stock-clipboard-success'), stockString);
})
.catch(() => {
alert(t('analysis.stock-clipboard-failure'));
}); });
}
function copyNumberToClipboard() {
const randomProposition =
numberPropositions.value[Math.floor(Math.random() * numberPropositions.value.length)];
navigator.clipboard
.writeText(randomProposition)
.then(() => {
prompt(t('analysis.number-clipboard-success'), randomProposition);
})
.catch(() => {
alert(t('analysis.number-clipboard-failure'));
});
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -457,38 +376,16 @@ hr.divider {
margin-top: 0.5em; margin-top: 0.5em;
} }
.analysis-html {
display: inline-block;
padding: 0.5em;
background-color: #2e2e2e;
margin-top: 0.5em;
user-select: none;
}
.analysis-header {
display: flex;
align-items: center;
gap: 0.5em;
& > .btn {
padding: 0;
opacity: 0.6;
&[data-checked='true'] {
opacity: 1;
}
}
}
.analysis-actions { .analysis-actions {
display: flex; display: flex;
gap: 0.5em; gap: 0.5em;
margin: 0.5em 0; flex-wrap: wrap;
margin-top: 1em;
} }
.number-info { .no-warnings {
font-size: 0.85em; color: #ccc;
color: #aaa;
} }
@include responsive.smallScreen { @include responsive.smallScreen {
@@ -503,5 +400,9 @@ hr.divider {
.warnings-container { .warnings-container {
justify-content: center; justify-content: center;
} }
.analysis-actions {
justify-content: center;
}
} }
</style> </style>
-10
View File
@@ -1,10 +0,0 @@
{
"title": "Analysis for: ",
"has-pn": "* contains extraordinary deliveries (PN)",
"has-tn": "* contains dangerous cargo (TN)",
"has-twr": "* contains high risk dangerous cargo (TWR)",
"empty": "empty",
"loaded": "loaded"
}
-10
View File
@@ -1,10 +0,0 @@
{
"title": "Analiza dla: ",
"has-pn": "* przejazd z przesyłkami nadzwyczajnymi (PN)",
"has-tn": "* przewozi towary niebezpieczne (TN)",
"has-twr": "* przewozi towary niebezpieczne wysokiego ryzyka (TWR)",
"empty": "puste",
"loaded": "pełne"
}
+15 -7
View File
@@ -443,11 +443,16 @@
"analysis": { "analysis": {
"button-show": "ANALYSIS & STOCK", "button-show": "ANALYSIS & STOCK",
"number-info": "will be automatically updated to the current train number chosen in the simulator after the analysis is sent in the chat.", "number-info": "will be automatically updated to the current train number chosen in the simulator after the analysis is sent in the chat.",
"button-copy": "COPY THE ANALYSIS",
"stock-copy": "COPY THE STOCK", "stock-copy": "COPY THE STOCK",
"stock-clipboard-success": "Successfully copied the railway stock in a text form to your clipboard!", "stock-clipboard-success": "Successfully copied the railway stock in a text form to your clipboard:",
"stock-clipboard-failure": "Oops! Something happened and the railway stock couldn't be copied to your clipboard! :/", "stock-clipboard-failure": "Oops! Something happened and the railway stock couldn't be copied to your clipboard! :/",
"number-copy": "COPY A NUMBER",
"cargo-copy": "COPY CARGO WARNINGS",
"number-clipboard-success": "Successfully copied the number in a text form to your clipboard:",
"number-clipboard-failure": "Oops! Something happened and the number couldn't be copied to your clipboard! :/",
"propositions": { "propositions": {
"title": "Number propositions:", "title": "Number propositions:",
"header": "Generate number examples for the chosen train category:", "header": "Generate number examples for the chosen train category:",
@@ -458,13 +463,16 @@
"warnings": { "warnings": {
"title": "Additional cargo warnings:", "title": "Additional cargo warnings:",
"zags-loaded-twr": "TWR: UN1965 (LPG)",
"zags-empty-tn": "TN: unclean tanks after UN1965", "zags-loaded-twr": "TWR: 33UN1965 (LPG), {0}x Zags",
"zans-loaded-tn": "TN: UN1202 (diesel fuel)", "zags-empty-tn": "TN: 33UN1965 (LPG), {0}x Zags (empty)",
"zans-empty-tn": "TN: unclean tanks after UN1202", "zans-loaded-tn": "TN: 33UN1202 (diesel), {0}x Zans",
"zans-empty-tn": "TN: 33UN1202 (diesel), {0}x Zans (empty)",
"military-all-pn": "PN: military transport", "military-all-pn": "PN: military transport",
"edk80-all-pn": "PN: EDK80 railway crane", "edk80-all-pn": "PN: EDK80 railway crane",
"innofreight-all-pn": "PN: Innofreight C45: exceeded gauge" "innofreight-all-pn": "PN: Innofreight C45: (exceeded gauge)",
"no-warnings": "No additional cargo warnings"
} }
}, },
+13 -8
View File
@@ -433,16 +433,19 @@
"analysis": { "analysis": {
"button-show": "ANALIZA I SKŁAD", "button-show": "ANALIZA I SKŁAD",
"number-info": "zostanie automatycznie zaktualizowany na obecny numer wybrany w symulatorze po wysłaniu wiadomości na czacie.", "number-info": "zostanie automatycznie zaktualizowany na obecny numer wybrany w symulatorze po wysłaniu wiadomości na czacie.",
"button-copy": "SKOPIUJ ANALIZĘ",
"title": "Treść analizy:", "title": "Treść analizy:",
"stock-copy": "SKOPIUJ SKŁAD", "stock-copy": "SKOPIUJ SKŁAD",
"stock-clipboard-success": "Pomyślnie skopiowano skład w postaci tekstowej do schowka:", "stock-clipboard-success": "Pomyślnie skopiowano do schowka skład w postaci tekstowej:",
"stock-clipboard-failure": "Ups! Nie udało się skopiować składu do schowka! :/", "stock-clipboard-failure": "Ups! Nie udało się skopiować składu do schowka! :/",
"number-copy": "SKOPIUJ NUMER",
"number-clipboard-success": "Pomyślnie skopiowano do schowka numer:",
"number-clipboard-failure": "Ups! Nie udało się skopiować numeru do schowka! :/",
"propositions": { "propositions": {
"title": "Propozycje numerów:", "title": "Propozycje numerów:",
"header": "Wygeneruj analizę dla pociągu wybranej kategorii:", "header": "Wygeneruj propozycje numerów dla pociągu wybranej kategorii:",
"third-number": "Trzecia cyfra:", "third-number": "Trzecia cyfra:",
"last-nums": "{count} ostatnie cyfry z przedziału:", "last-nums": "{count} ostatnie cyfry z przedziału:",
"empty": "Brak propozycji dla wybranej kategorii!" "empty": "Brak propozycji dla wybranej kategorii!"
@@ -450,13 +453,15 @@
"warnings": { "warnings": {
"title": "Dodatkowe uwagi przewozowe:", "title": "Dodatkowe uwagi przewozowe:",
"zags-loaded-twr": "TWR: UN1965 (LPG)", "zags-loaded-twr": "TWR: 33UN1965 (LPG), {0}x Zags",
"zags-empty-tn": "TN: brudne cysterny po UN1965", "zags-empty-tn": "TN: 33UN1965 (LPG), {0}x Zags (puste)",
"zans-loaded-tn": "TN: UN1202 (olej napędowy)", "zans-loaded-tn": "TN: 33UN1202 (ON), {0}x Zans",
"zans-empty-tn": "TN: brudne cysterny po UN1202", "zans-empty-tn": "TN: 33UN1202 (ON), {0}x Zans (puste)",
"military-all-pn": "PN: transport wojskowy", "military-all-pn": "PN: transport wojskowy",
"edk80-all-pn": "PN: żuraw kolejowy EDK80", "edk80-all-pn": "PN: żuraw kolejowy EDK80",
"innofreight-all-pn": "PN: Innofreight C45: przekroczona skrajnia" "innofreight-all-pn": "PN: Innofreight C45 (przekroczona skrajnia)",
"no-warnings": "Brak dodatkowych uwag przewozowych"
} }
}, },
"train-stats": { "train-stats": {