mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-09 00:00:59 +00:00
chore(driver): removed analysis box, replaced with additional cargo & stock info
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="analysis-box">
|
||||
<div class="driver-propositions">
|
||||
<div class="analysis-propositions">
|
||||
<h3>{{ t('analysis.propositions.header') }}</h3>
|
||||
|
||||
<div class="categories-select">
|
||||
@@ -57,79 +57,38 @@
|
||||
class="train-badge"
|
||||
:class="warningKey.split('-')[2]"
|
||||
>
|
||||
{{ t('analysis.warnings.' + warningKey) }}
|
||||
</div>
|
||||
{{ t('analysis.warnings.' + warningKey, cargoWarnings[warningKey]) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="cargo-warnings no-warnings" v-else>
|
||||
<hr class="divider" />
|
||||
|
||||
<div class="analysis-content">
|
||||
<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>
|
||||
{{ t('analysis.warnings.no-warnings') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="analysis-html" v-html="analysisHtml"></div>
|
||||
|
||||
<hr class="divider" />
|
||||
|
||||
<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()">
|
||||
<i class="fa-regular fa-copy"></i> {{ t('analysis.stock-copy') }}
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
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 rulesJSON from '../../data/trainNumberRules.json';
|
||||
import { useApiStore } from '../../store/apiStore';
|
||||
|
||||
import enLang from '../../locales/analysis/en.json';
|
||||
import plLang from '../../locales/analysis/pl.json';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const analysisi18n = createI18n({
|
||||
locale: 'pl',
|
||||
messages: {
|
||||
en: enLang,
|
||||
pl: plLang
|
||||
},
|
||||
sync: false
|
||||
});
|
||||
|
||||
const apiStore = useApiStore();
|
||||
|
||||
const props = defineProps({
|
||||
@@ -157,107 +116,6 @@ onMounted(() => {
|
||||
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(() => {
|
||||
return availableCategories.value[chosenCategoryIndex.value];
|
||||
});
|
||||
@@ -371,39 +229,100 @@ const availableCategories = computed(() => {
|
||||
return availableCategories.map((c) => `${c}${categoryTraction}`);
|
||||
});
|
||||
|
||||
const analysisHtml = computed(() => {
|
||||
let analysisStr = `<b>${chosenCategory.value} $number </b> (${props.chosenTrain.stockList[0]}, ${(props.chosenTrain.mass / 1000).toFixed(1)}t, ${props.chosenTrain.length}m)`;
|
||||
|
||||
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>`;
|
||||
function selectCategory(i: number) {
|
||||
chosenCategoryIndex.value = i;
|
||||
generateNumberPropositions();
|
||||
}
|
||||
|
||||
if (cargoWarnings.value['zans-loaded-tn'] || cargoWarnings.value['zans-empty-tn']) {
|
||||
analysisStr += `<br><i>33UN1203 ${cargoWarnings.value['zans-loaded-tn'] || 0}/${cargoWarnings.value['zans-empty-tn'] || 0} Zans</i>`;
|
||||
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;
|
||||
}
|
||||
|
||||
if (Object.keys(cargoWarnings.value).some((k) => k.includes('-pn'))) {
|
||||
analysisStr += `${analysisi18n.global.t('has-pn')}:`;
|
||||
const [thirdNumber, minRange, maxRange] = rules;
|
||||
|
||||
if (cargoWarnings.value['innofreight-all-pn']) {
|
||||
analysisStr += `<br> - Innofreight - przekroczona skrajnia`;
|
||||
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 (cargoWarnings.value['military-all-pn']) {
|
||||
analysisStr += `<br> - transport wojskowy`;
|
||||
}
|
||||
}
|
||||
if (Number(randRange) > Number(maxRange)) break;
|
||||
}
|
||||
|
||||
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>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -457,38 +376,16 @@ hr.divider {
|
||||
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 {
|
||||
display: flex;
|
||||
gap: 0.5em;
|
||||
margin: 0.5em 0;
|
||||
flex-wrap: wrap;
|
||||
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.number-info {
|
||||
font-size: 0.85em;
|
||||
color: #aaa;
|
||||
.no-warnings {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
@include responsive.smallScreen {
|
||||
@@ -503,5 +400,9 @@ hr.divider {
|
||||
.warnings-container {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.analysis-actions {
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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
@@ -443,11 +443,16 @@
|
||||
"analysis": {
|
||||
"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.",
|
||||
"button-copy": "COPY THE ANALYSIS",
|
||||
|
||||
"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! :/",
|
||||
|
||||
"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": {
|
||||
"title": "Number propositions:",
|
||||
"header": "Generate number examples for the chosen train category:",
|
||||
@@ -458,13 +463,16 @@
|
||||
|
||||
"warnings": {
|
||||
"title": "Additional cargo warnings:",
|
||||
"zags-loaded-twr": "TWR: UN1965 (LPG)",
|
||||
"zags-empty-tn": "TN: unclean tanks after UN1965",
|
||||
"zans-loaded-tn": "TN: UN1202 (diesel fuel)",
|
||||
"zans-empty-tn": "TN: unclean tanks after UN1202",
|
||||
|
||||
"zags-loaded-twr": "TWR: 33UN1965 (LPG), {0}x Zags",
|
||||
"zags-empty-tn": "TN: 33UN1965 (LPG), {0}x Zags (empty)",
|
||||
"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",
|
||||
"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
@@ -433,16 +433,19 @@
|
||||
"analysis": {
|
||||
"button-show": "ANALIZA I SKŁAD",
|
||||
"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:",
|
||||
|
||||
"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! :/",
|
||||
|
||||
"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": {
|
||||
"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:",
|
||||
"last-nums": "{count} ostatnie cyfry z przedziału:",
|
||||
"empty": "Brak propozycji dla wybranej kategorii!"
|
||||
@@ -450,13 +453,15 @@
|
||||
|
||||
"warnings": {
|
||||
"title": "Dodatkowe uwagi przewozowe:",
|
||||
"zags-loaded-twr": "TWR: UN1965 (LPG)",
|
||||
"zags-empty-tn": "TN: brudne cysterny po UN1965",
|
||||
"zans-loaded-tn": "TN: UN1202 (olej napędowy)",
|
||||
"zans-empty-tn": "TN: brudne cysterny po UN1202",
|
||||
"zags-loaded-twr": "TWR: 33UN1965 (LPG), {0}x Zags",
|
||||
"zags-empty-tn": "TN: 33UN1965 (LPG), {0}x Zags (puste)",
|
||||
"zans-loaded-tn": "TN: 33UN1202 (ON), {0}x Zans",
|
||||
"zans-empty-tn": "TN: 33UN1202 (ON), {0}x Zans (puste)",
|
||||
"military-all-pn": "PN: transport wojskowy",
|
||||
"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": {
|
||||
|
||||
Reference in New Issue
Block a user