Restrukturyzacja kodu

This commit is contained in:
2020-08-22 15:18:59 +02:00
parent 3cc9381d83
commit c6e3e3f779
15 changed files with 371 additions and 788 deletions
+115
View File
@@ -0,0 +1,115 @@
<template>
<section class="legend-card card">
<div class="card-exit" @click="exit">
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
</div>
<div class="card-title flex">LEGENDA</div>
<div class="card-icons">
<div class="legend-icon" v-for="(icon, i) in icons" :key="i">
<img :src="require(`@/assets/icon-${icon.name}.svg`)" :alt="icon.name" />
<span>{{icon.desc}}</span>
</div>
</div>
</section>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
@Component
export default class LegendCard extends Vue {
@Prop() exit!: void;
icons: { name: string; desc: string }[] = [
{ name: "SPK", desc: "Sceneria sterowana za pomocą programu SPK" },
{ name: "SCS", desc: "Sceneria sterowana za pomocą programu SCS" },
{
name: "SCS-SPK",
desc: "Sceneria sterowana za pomocą programu SCS lub SPK"
},
{
name: "mechaniczne",
desc: "Sceneria posiadająca urządzenia sterowane mechanicznie"
},
{
name: "mechaniczne+SPK",
desc:
"Sceneria posiadająca urządzenia sterowane mechanicznie zintegrowane z SPK"
},
{
name: "mechaniczne+SCS",
desc:
"Sceneria posiadająca urządzenia sterowane mechanicznie zintegrowane z SCS"
},
{ name: "ręczne", desc: "Sceneria z ręcznie sterowanymi zwrotnicami" },
{
name: "ręczne+SPK",
desc: "Sceneria z ręcznie sterowanymi zwrotnicami zintegrowana z SPK"
},
{
name: "współczesna",
desc: "Sceneria ze współczesną sygnalizacją świetlną"
},
{ name: "kształtowa", desc: "Sceneria ze sygnalizacją kształtową" },
{ name: "historyczna", desc: "Sceneria ze sygnalizacją historyczną" },
{
name: "mieszana",
desc:
"Sceneria ze sygnalizacją mieszaną (kształtowe, historyczne lub/i współczesne)"
},
{
name: "SBL",
desc:
"Sceneria posiadająca samoczynną blokadę liniową na co najmniej jednym z jej szlaków"
}
];
}
</script>
<style lang="scss">
@import "../../styles/variables.scss";
@import "../../styles/responsive.scss";
.card {
&-exit {
position: absolute;
top: 0;
right: 0;
margin: 0.8em;
img {
width: 1.1em;
}
cursor: pointer;
}
&-title {
font-size: 3em;
font-weight: 700;
color: $accentCol;
margin: 0.3em 0;
}
}
.legend-icon {
display: flex;
align-items: center;
padding: 0.5em;
img {
width: 2.5em;
margin-right: 0.5em;
}
span {
font-size: 1.1em;
text-align: start;
}
}
</style>
+363
View File
@@ -0,0 +1,363 @@
<template>
<section class="option-card">
<div class="card-exit" @click="exit">
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
</div>
<div class="card-title flex">FILTRUJ STACJE</div>
<div class="card-options">
<div class="option" v-for="(option, i) in inputs.options" :key="i">
<label class="option-label">
<input
class="option-input"
type="checkbox"
:name="option.name"
:defaultValue="option.defaultValue"
:id="option.id"
v-model="option.value"
@change="handleChange"
/>
<span class="option-content" :class="option.section">{{option.content}}</span>
</label>
</div>
</div>
<div class="card-sorts">
<!-- <div class="sort" v-for="(sort, i) in inputs.sorts" :key="i">{{ sort.content }}</div> -->
</div>
<div class="card-sliders">
<div class="slider" v-for="(slider, i) in inputs.sliders" :key="i">
<input
class="slider-input"
type="range"
:name="slider.name"
:id="slider.id"
:min="slider.minRange"
:max="slider.maxRange"
v-model="slider.value"
@change="handleInput"
/>
<span class="slider-value">{{slider.value}}</span>
<div class="slider-content">{{slider.content}}</div>
</div>
</div>
<div class="card-actions flex">
<button class="button" @click="reset">RESET FILTRÓW</button>
<button class="button" @click="exit">ZAMKNIJ FILTRY</button>
</div>
</section>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { Action } from "vuex-class";
import inputData from "@/data/options.json";
@Component
export default class OptionCard extends Vue {
inputs = { ...inputData };
mounted() {}
@Prop() exit!: () => void;
@Action("setFilter") setFilter;
@Action("resetFilters") resetFilters;
handleChange(e: Event): void {
const target = <HTMLInputElement>e.target;
this.setFilter({
filterName: target.name,
value: !target.checked,
});
}
handleInput(e: Event): void {
const target = <HTMLInputElement>e.target;
this.setFilter({
filterName: target.name,
value: parseInt(target.value),
});
}
reset(): void {
this.inputs.options.forEach((option) => {
option.value = option.defaultValue;
});
this.inputs.sliders.forEach((slider) => {
slider.value = slider.defaultValue;
});
this.resetFilters();
}
closeCard(): void {
this.exit();
}
}
</script>
<style lang="scss" scoped>
@import "../../styles/responsive";
@import "../../styles/variables";
.option-card {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 3;
overflow: auto;
max-height: 95vh;
padding: 0.5em;
max-width: 600px;
width: 65%;
background: #262a2e;
font-size: calc(0.75rem + 0.4vw);
box-shadow: 0 0 15px 5px #474747;
@include smallScreen() {
width: 85vw;
font-size: 1em;
}
}
.card {
&-exit {
position: absolute;
top: 0;
right: 0;
margin: 0.8em;
img {
width: 1.1em;
}
cursor: pointer;
}
&-title {
font-size: 2em;
font-weight: 700;
color: $accentCol;
margin: 0.5em 0;
}
&-options {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(6em, 1fr));
padding: 0 1.5em;
}
&-sliders {
margin-top: 1em;
}
&-actions {
margin-top: 0.7em;
button {
margin: 0 0.3em;
}
}
}
.option {
margin: 0.3em;
&-input {
display: none;
&:not(:checked) + span {
background-color: #585858;
&::before {
box-shadow: none;
}
}
}
&-content {
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
width: 100%;
text-align: center;
cursor: pointer;
padding: 0.6em 0.5em;
border-radius: 0.4em;
font-size: 0.65em;
background-color: #333;
display: inline-block;
position: relative;
transition: all 0.2s;
&.access {
background-color: #e03b07;
&::before {
box-shadow: 0 0 6px 1px #e03b07;
}
}
&.control {
background-color: #0085ff;
&::before {
box-shadow: 0 0 6px 1px #0085ff;
}
}
&.signals {
background-color: #b000bf;
&::before {
box-shadow: 0 0 6px 1px #b000bf;
}
}
&.status {
background-color: #05b702;
&::before {
box-shadow: 0 0 6px 1px #05b702;
}
}
&::before {
position: absolute;
content: "";
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: inherit;
}
}
}
.slider {
display: flex;
padding: 0.5em;
&-value {
display: flex;
justify-content: center;
align-items: center;
color: $accentCol;
margin-right: 0.3em;
padding: 0.1em 0.2em;
font-size: 1.1em;
font-weight: 500;
border-radius: 0.2em;
}
&-content {
display: flex;
align-items: center;
font-size: 0.75em;
}
&-input {
-webkit-appearance: none;
appearance: none;
background: none;
border: none;
outline: none;
min-width: 25%;
&::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
margin-top: -7px;
border-radius: 50%;
background: white;
border: 4px solid $accentCol;
@include smallScreen() {
width: 15px;
height: 15px;
margin-top: -5px;
border: 3px solid $accentCol;
}
}
&::-moz-range-thumb {
height: 15px;
width: 15px;
border-radius: 50%;
background: white;
border: 4px solid $accentCol;
cursor: pointer;
@include smallScreen() {
width: 15px;
height: 15px;
border: 3px solid $accentCol;
}
}
&::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
cursor: pointer;
background: #ffffff;
border-radius: 1em;
}
&::-moz-range-track {
width: 100%;
height: 5px;
cursor: pointer;
background: #ffffff;
border-radius: 1em;
}
&::-ms-track {
width: 100%;
height: 5px;
cursor: pointer;
background: #ffffff;
border-radius: 1em;
}
}
}
</style>
+151
View File
@@ -0,0 +1,151 @@
<template>
<div class="options">
<div class="options-actions">
<button
class="action-btn"
:class="{'open': filterCardOpen}"
@click="() => toggleCardsState('filter')"
>
<img :src="require('@/assets/icon-filter2.svg')" alt="icon-filter" />
<p>FILTRY</p>
</button>
<button
class="action-btn"
:class="{'open': legendCardOpen}"
@click="() => toggleCardsState('legend')"
>
<img :src="require('@/assets/icon-legend.svg')" alt="icon legend" />
<p>LEGENDA</p>
</button>
</div>
<div class="options-content">
<transition name="card-anim">
<OptionCard v-if="filterCardOpen" :exit="() => toggleCardsState('filter')" />
</transition>
<transition name="card-anim">
<LegendCard v-if="legendCardOpen" :exit="() => toggleCardsState('legend')" />
</transition>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import OptionCard from "@/components/StationsView/OptionCard.vue";
import LegendCard from "@/components/StationsView/LegendCard.vue";
@Component({
components: { OptionCard, LegendCard },
})
export default class Options extends Vue {
filterCardOpen: boolean = false;
legendCardOpen: boolean = false;
toggleCardsState(name: string): void {
if (name == "filter") {
this.legendCardOpen = false;
this.filterCardOpen = !this.filterCardOpen;
}
if (name == "legend") {
this.filterCardOpen = false;
this.legendCardOpen = !this.legendCardOpen;
}
}
toggleCardState(): void {
this.filterCardOpen = !this.filterCardOpen;
}
toggleLegendCardState(): void {
this.legendCardOpen = !this.legendCardOpen;
}
}
</script>
<style lang="scss" scoped>
@import "../../styles/variables.scss";
@import "../../styles/responsive.scss";
.options {
display: flex;
z-index: 5;
}
.card-anim {
&-enter-active,
&-leave-active {
transition: all 0.25s ease-in-out;
}
&-enter,
&-leave-to {
transform: translate(-45%, -50%);
opacity: 0;
}
}
.options {
font-size: calc(0.6rem + 0.9vw);
&-actions {
display: flex;
}
}
.action-btn {
display: flex;
align-items: center;
background: #333;
border: none;
color: #e0e0e0;
font-size: 0.75em;
padding: 0.3em;
outline: none;
cursor: pointer;
transition: all 0.3s;
img {
width: 1.3em;
margin-right: 0.2em;
}
p {
max-width: 0;
font-size: 1em;
overflow: hidden;
transition: max-width 0.35s ease-in-out;
}
&:hover > p,
&.open > p {
max-width: 500px;
color: $accentCol;
}
&:hover {
background: rgba(#e0e0e0, 0.4);
}
}
@include smallScreen {
.options {
display: flex;
justify-content: center;
}
.action-btn {
font-size: 1rem;
}
}
</style>
+534
View File
@@ -0,0 +1,534 @@
<template>
<section class="card station-card">
<div class="card-exit" @click="exit">
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
</div>
<div class="card-history">
<div class="history-title title">DZIENNIK STACJI</div>
<ul class="history-list">
<div
class="history-info"
>Wersja eksperymentalna! Dziennik aktualizowany co 20 minut od 23:00 14 sierpnia 2020r.</div>
<li class="history-log" v-for="(log, i) in computedHistory" :key="i">
<div class="log-time">
<div class="from">
<span>
{{ new Date(log.occupiedFrom).toLocaleDateString('pl-PL', {
day: "2-digit",
month: "2-digit",
year: "2-digit",
}) }}
</span>
<span>
{{ new Date(log.occupiedFrom).toLocaleTimeString('pl-PL', {
hour: "2-digit",
minute: "2-digit"
}) }}
</span>
</div>
<div class="to">
<span>
{{ new Date(log.occupiedTo).toLocaleDateString('pl-PL', {
day: "2-digit",
month: "2-digit",
year: "2-digit",
}) }}
</span>
<span>
{{ new Date(log.occupiedTo).toLocaleTimeString('pl-PL', {
hour: "2-digit",
minute: "2-digit"
}) }}
</span>
</div>
</div>
<div class="log-dispatcher">{{log.dispatcher}}</div>
</li>
</ul>
</div>
<div class="card-content" :class="{'offline': !stationInfo.online}">
<div class="main">
<div class="main-content">
<span
class="main-level flex"
v-if="stationInfo.reqLevel > -1"
>{{parseInt(stationInfo.reqLevel) < 2 ? "L" : stationInfo.reqLevel}}</span>
<span class="main-general">
<div class="main-name">
<a
v-if="stationInfo.stationURL"
:href="stationInfo.stationURL"
target="_blank"
rel="noopener noreferrer"
>{{stationInfo.stationName}}</a>
<span v-else>{{stationInfo.stationName}}</span>
</div>
<div class="main-hash">{{stationInfo.stationHash}}</div>
</span>
</div>
</div>
<div class="icons">
<img
v-if="stationInfo.controlType"
:src="require(`@/assets/icon-${stationInfo.controlType}.svg`)"
:alt="stationInfo.controlType"
:title="'Sterowanie ' + stationInfo.controlType"
/>
<img
v-if="stationInfo.signalType"
:src="require(`@/assets/icon-${stationInfo.signalType}.svg`)"
:alt="stationInfo.signalType"
:title="'Sygnalizacja ' + stationInfo.signalType"
/>
<img
v-if="stationInfo.SBL && stationInfo.SBL !== ''"
:src="require(`@/assets/icon-SBL.svg`)"
alt="SBL"
title="Sceneria posiada SBL na przynajmniej jednym ze szlaków"
/>
<img
v-if="stationInfo.default"
:src="require(`@/assets/icon-td2.svg`)"
alt="default-pack"
title="Sceneria domyślnie dostępna w grze"
/>
<img
v-if="stationInfo.nonPublic || !stationInfo.reqLevel"
:src="require(`@/assets/icon-lock.svg`)"
alt="non-public"
title="Sceneria niepubliczna"
/>
</div>
<div class="dispatcher">
<div
class="dispatcher-level flex"
:style="calculateExpStyle(stationInfo.dispatcherExp)"
>{{stationInfo.online ? computedExp : ""}}</div>
<div class="dispatcher-info">
<div class="dispatcher-name">
<a
:href="'https://td2.info.pl/profile/?u=' + stationInfo.dispatcherId"
target="_blank"
rel="noopener noreferrer"
>{{stationInfo.dispatcherName || "---"}}</a>
</div>
<div class="dispatcher-rate">
<img :src="require(`@/assets/icon-like.svg`)" alt="like-icon" />
<span>{{stationInfo.dispatcherRate}}</span>
</div>
</div>
</div>
<div class="hours">
<div class="hours-title title">STATUS</div>
<span
class="status"
:class="statusClasses(stationInfo.occupiedTo)"
>{{stationInfo.occupiedTo}}</span>
</div>
<div class="spawns flex flex-column">
<h3 class="spawns-title title">OTWARTE SPAWNY</h3>
<div class="spawns-content">
<span
class="spawn"
v-for="(spawn, i) in stationInfo.spawnString"
:key="spawn + stationInfo.dispatcherName + i"
>{{spawn}}</span>
<span class="spawn" v-if="!stationInfo.spawnString">BRAK</span>
</div>
</div>
<div class="users flex flex-column">
<h3 class="users-title title">GRACZE NA STACJI</h3>
<div class="users-content">
<div
class="user"
v-for="train in stationInfo.trains"
:key="train.trainNo + train.driverName"
>
<a
:href="'https://rj.td2.info.pl/train#' + train.trainNo + ';eu'"
target="_blank"
rel="noopener noreferrer"
>
<span>{{train.trainNo}}</span>
|
<span>{{train.driverName}}</span>
</a>
</div>
<span
class="user borderless"
v-if="!stationInfo.trains || stationInfo.trains.length == 0"
>BRAK</span>
</div>
</div>
</div>
</section>
</template>
<script lang="ts">
import { Component, Prop, Watch } from "vue-property-decorator";
import styleMixin from "@/mixins/styleMixin";
import db from "@/scripts/firebase/firebaseInit";
@Component
export default class StationCard extends styleMixin {
@Prop() stationInfo;
@Prop() dispatcherHistory;
@Prop() exit!: void;
history: any[] = [];
get computedExp(): string {
return this.stationInfo.dispatcherExp < 2
? "L"
: `${this.stationInfo.dispatcherExp}`;
}
toLocaleDate(timestamp: number) {
return new Date(timestamp).toLocaleDateString("pl-PL", {
hour: "2-digit",
minute: "2-digit",
});
}
get computedHistory() {
return this.history.sort((a, b) => {
if (a.occupiedFrom < b.occupiedFrom) return 1;
else return -1;
});
}
async loadHistory() {
const historyRef = await db
.collection("history")
.doc(this.stationInfo.stationName)
.collection("dispatcherHistory")
.get();
this.history = historyRef.docs
.filter((doc) => doc.data().occupiedTo != 0)
.map((doc) => {
const occupiedFrom = doc.data().occupiedFrom;
const occupiedTo = doc.data().occupiedTo;
const sameDay =
new Date(occupiedFrom).getDate() == new Date(occupiedTo).getDate();
return {
occupiedFrom,
occupiedTo,
dispatcher:
doc.data().currentDispatcherName || doc.data().dispatcherName,
sameDay,
};
});
}
@Watch("stationInfo")
async onStationChange(val: any, oldVal: any) {
this.loadHistory();
}
created() {
this.loadHistory();
}
}
</script>
<style lang="scss">
@import "../../styles/variables.scss";
@import "../../styles/responsive.scss";
.title {
color: $accentCol;
font-weight: 600;
margin: 0.5em 0;
}
.card {
padding: 2em;
text-align: center;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
&-content {
display: grid;
grid-template-areas: "main main" "icons icons" "dispatcher hours" "users spawns" "history history";
grid-template-columns: repeat(2, minmax(0, 1fr));
min-width: 200px;
gap: 1.5em;
margin-bottom: 2.5rem;
&.offline {
.users,
.spawns,
.dispatcher {
filter: grayscale(1);
opacity: 0.5;
}
}
@include smallScreen() {
grid-template-areas: "main main" "icons icons" "dispatcher dispatcher" "hours hours" "users spawns";
}
}
}
.card-history {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
// height: 10%;
min-height: 0;
max-height: 90%;
min-width: 100%;
padding: 0.4rem;
// border-radius: 1em 1em 0 0;
z-index: 5;
background: rgba($color: #000000, $alpha: 0.9);
font-size: 1em;
transition: min-height 150ms ease-in, min-width 150ms ease-in,
font-size 150ms ease-in;
&:hover {
min-height: 90%;
& > .history-list {
opacity: 1;
max-height: 350px;
}
& > .history-title {
font-size: 2em;
}
}
}
.history {
&-title {
transition: font-size 150ms ease-in;
}
&-info {
font-size: 1em;
color: #999;
transition: all 150ms ease-in;
}
&-list {
max-height: 0;
opacity: 0;
transition: opacity 150ms;
font-size: 1em;
transition: max-height 150ms ease-in-out;
overflow: auto;
}
&-log {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5em;
margin: 1em;
background: #333;
&:nth-child(odd) {
background: rgb(92, 92, 92);
}
}
}
.main {
grid-area: main;
text-align: center;
&-content {
display: flex;
justify-content: center;
align-items: center;
@include smallScreen() {
flex-direction: column;
}
}
&-level {
background: $accentCol;
color: black;
font-size: 2.5em;
font-weight: 600;
border-radius: 50%;
width: 1.7em;
height: 1.7em;
margin: 0.3em 0.5em;
}
&-hash {
color: #9d9d9d;
}
&-name {
color: $accentCol;
font-weight: 600;
font-size: 2.3em;
text-transform: uppercase;
}
}
.icons {
grid-area: icons;
display: flex;
justify-content: center;
img {
max-width: 3em;
margin: 0 0.4em;
}
}
.dispatcher {
grid-area: dispatcher;
display: flex;
justify-content: center;
&-level {
font-size: 2.5em;
font-weight: bold;
margin-right: 0.3em;
max-width: 2em;
background: forestgreen;
}
&-info {
display: flex;
justify-content: space-between;
flex-direction: column;
padding: 0.5em;
}
&-name {
font-size: 1.35em;
font-weight: bold;
padding-bottom: 0.5em;
}
&-rate {
display: flex;
font-size: 1.3em;
span {
margin: 0 0.3em;
color: $accentCol;
}
img {
width: 1.2em;
}
}
}
.hours {
grid-area: hours;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
.status {
font-size: 1.1em;
}
}
.users {
grid-area: users;
&-content {
display: flex;
flex-wrap: wrap;
justify-content: center;
& > .user {
padding: 0.3rem;
margin: 0.3rem;
border: 1px solid white;
border-radius: 0.4em;
&.borderless {
border: none;
margin: 0;
padding: 0;
}
}
}
}
.spawns {
grid-area: spawns;
overflow: hidden;
&-content {
display: flex;
flex-wrap: wrap;
justify-content: center;
& > .spawn {
padding: 0.3em 0.4em;
margin: 0.3em;
background: #585858;
text-align: center;
}
}
}
</style>
@@ -0,0 +1,330 @@
<template>
<section class="station-table">
<div class="table-wrapper">
<table class="table">
<thead class="table-head">
<tr>
<th v-for="(head, i) in headTitles" :key="i" @click="() => changeSorter(i)">
<span>
<div>
<div>{{head[0]}}</div>
<div v-if="head.length > 1">{{head[1]}}</div>
</div>
<img
class="sort-icon"
v-if="sorterActive.index == i"
:src="sorterActive.dir == 1 ? icons.ascSVG : icons.descSVG"
alt
/>
</span>
</th>
</tr>
</thead>
<tr
class="table-item"
v-for="(station, i) in computedStations"
:key="i + station.stationHash"
@click="() => { setFocusedStation(station.stationName) }"
>
<td
class="item-station-name"
:class="{'default-station': station.default, 'online': station.online}"
>{{station.stationName}}</td>
<td class="item-station-level">
<span
v-if="station.reqLevel"
:style="calculateExpStyle(station.reqLevel)"
>{{ (station.reqLevel && station.reqLevel > -1) ? (parseInt(station.reqLevel) >= 2 ? station.reqLevel : "L") : "?" }}</span>
<span v-else>?</span>
</td>
<td class="item-station-status">
<span class="status" :class="statusClasses(station.occupiedTo)">{{station.occupiedTo}}</span>
</td>
<td class="item-dispatcher-name">{{station.online ? station.dispatcherName : ""}}</td>
<td class="item-dispatcher-exp">
<span
v-if="station.online"
:style="calculateExpStyle(station.dispatcherExp)"
>{{station.dispatcherExp < 2 ? 'L' : station.dispatcherExp}}</span>
</td>
<td
class="item-users"
>{{station.online ? (station.currentUsers + "/" + station.maxUsers) : ""}}</td>
<td class="item-info">
<img
class="icon-info"
v-if="station.controlType"
:src="require(`@/assets/icon-${station.controlType}.svg`)"
:alt="station.controlType"
:title="'Sterowanie ' + station.controlType"
/>
<img
class="icon-info"
v-if="station.signalType"
:src="require(`@/assets/icon-${station.signalType}.svg`)"
:alt="station.signalType"
:title="'Sygnalizacja ' + station.signalType"
/>
<img
class="icon-info"
v-if="station.SBL && station.SBL !== ''"
:src="require(`@/assets/icon-SBL.svg`)"
alt="SBL"
title="Sceneria posiada SBL na przynajmniej jednym ze szlaków"
/>
<img
class="icon-info"
v-if="!station.reqLevel || station.nonPublic"
:src="require(`@/assets/icon-lock.svg`)"
alt="non-public"
title="Sceneria niepubliczna"
/>
</td>
<td class="item-tracks twoway">
<span
v-if="station.routes && station.routes.twoWay.catenary > 0"
class="track catenary"
:title="'Liczba zelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.catenary"
>{{station.routes.twoWay.catenary}}</span>
<span
v-if="station.routes && station.routes.twoWay.noCatenary > 0"
class="track no-catenary"
:title="'Liczba niezelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.noCatenary"
>{{station.routes.twoWay.noCatenary}}</span>
</td>
<td class="item-tracks oneway">
<span
v-if="station.routes && station.routes.oneWay.catenary > 0"
class="track catenary"
:title="'Liczba zelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.catenary"
>{{station.routes.oneWay.catenary}}</span>
<span
v-if="station.routes && station.routes.oneWay.noCatenary > 0"
class="track no-catenary"
:title="'Liczba niezelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.noCatenary"
>{{station.routes.oneWay.noCatenary}}</span>
</td>
</tr>
</table>
</div>
</section>
</template>
<script lang="ts">
import Vue from "vue";
import { Component, Prop } from "vue-property-decorator";
import Station from "@/scripts/interfaces/Station";
import styleMixin from "@/mixins/styleMixin";
import Options from "@/components/StationsView/Options.vue";
const ascSVG = require("@/assets/icon-arrow-asc.svg");
const descSVG = require("@/assets/icon-arrow-desc.svg");
@Component({
components: { Options },
})
export default class StationTable extends styleMixin {
@Prop() readonly stations!: Station[];
@Prop() readonly setFocusedStation!: () => void;
icons: { ascSVG; descSVG } = { ascSVG, descSVG };
sorterActive: { index: number; dir: number } = { index: 0, dir: 1 };
headTitles: string[][] = [
["Stacja"],
["Wymagany poz.", "dyżurnego"],
["Status"],
["Dyżurny"],
["Poziom", "dyżurnego"],
["Maszyniści"],
["Informacje", "ogólne"],
["Szlaki", "dwutorowe"],
["Szlaki", "jednotorowe"],
];
changeSorter(index: number) {
if (index > 5) return;
if (index == this.sorterActive.index)
this.sorterActive.dir = -1 * this.sorterActive.dir;
else this.sorterActive.dir = 1;
this.sorterActive.index = index;
}
get computedStations() {
const dir: number = this.sorterActive.dir;
return this.stations.sort((a, b) => {
switch (this.sorterActive.index) {
case 1:
if (parseInt(a.reqLevel) > parseInt(b.reqLevel)) return dir;
if (parseInt(a.reqLevel) < parseInt(b.reqLevel)) return -dir;
break;
case 2:
if (a.statusTimestamp > b.statusTimestamp) return dir;
if (a.statusTimestamp < b.statusTimestamp) return -dir;
break;
case 3:
if (a.dispatcherName > b.dispatcherName) return dir;
if (a.dispatcherName < b.dispatcherName) return -dir;
break;
case 4:
if (a.dispatcherExp > b.dispatcherExp) return dir;
if (a.dispatcherExp < b.dispatcherExp) return -dir;
break;
case 5:
if (a.currentUsers > b.currentUsers) return dir;
if (a.currentUsers < b.currentUsers) return -dir;
if (a.maxUsers > b.maxUsers) return dir;
if (a.maxUsers < b.maxUsers) return -dir;
break;
default:
break;
}
if (a.stationName >= b.stationName) return dir;
return -dir;
});
}
}
</script>
<style lang="scss" scoped>
@import "../../styles/responsive.scss";
@import "../../styles/variables.scss";
@import "../../styles/global.scss";
.table {
&-wrapper {
overflow: auto;
}
white-space: nowrap;
border-collapse: collapse;
font-size: calc(0.6rem + 0.3vw);
@include smallScreen() {
font-size: 0.6rem;
}
&-head th {
padding: 0.3rem;
background-color: #444;
min-width: 120px;
position: sticky;
top: 0;
z-index: 2;
cursor: pointer;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
span {
display: flex;
align-items: center;
justify-content: center;
& > img {
width: 1.5em;
}
}
}
&-item {
background-color: #5c5b5b;
&:nth-child(even) {
background-color: rgb(102, 101, 101);
color: white;
}
&:hover,
&:focus {
background-color: #818181;
}
& > td {
padding: 0.3rem 1rem;
margin: 0 3rem;
text-align: center;
vertical-align: middle;
cursor: pointer;
@include smallScreen() {
margin: 0;
padding: 0.1rem 0.5rem;
}
}
}
}
.item {
&-station-level,
&-dispatcher-exp {
span {
display: block;
width: 2em;
height: 2em;
line-height: 2em;
margin: 0 auto;
}
}
&-station-level {
span {
background-color: #888;
border-radius: 50%;
}
}
&-info,
&-tracks {
img {
width: 2.2em;
margin: 0 0.2em;
vertical-align: middle;
}
}
&-tracks {
.no-catenary {
background-color: #939393;
}
.catenary {
background-color: #009dce;
}
.track {
margin: 0 0.3rem;
padding: 0.5em;
}
}
}
</style>
-370
View File
@@ -1,370 +0,0 @@
<template>
<div class="table-wrapper">
<table class="table">
<thead class="table-head">
<tr>
<th v-for="(head, i) in headTitles" :key="i" @click="() => changeSorter(i)">
<span>
<div>
<div>{{head[0]}}</div>
<div v-if="head.length > 1">{{head[1]}}</div>
</div>
<img
class="icon"
v-if="sorterActive.index == i"
:src="sorterActive.type == 1 ? icons.ascSVG : icons.descSVG"
alt
/>
</span>
</th>
</tr>
</thead>
<tr
class="table-item"
v-for="(station, i) in computedStations"
:key="i + station.stationHash"
@click="() => { setFocusedStation(station.stationName) }"
>
<td
class="item-station-name"
:class="{'default-station': station.default, 'online': station.online}"
>{{station.stationName}}</td>
<td class="item-station-level">
<span
v-if="station.reqLevel"
:style="calculateExpStyle(station.reqLevel)"
>{{ (station.reqLevel && station.reqLevel > -1) ? (parseInt(station.reqLevel) >= 2 ? station.reqLevel : "L") : "?" }}</span>
<span v-else>?</span>
</td>
<td class="item-station-status">
<span class="status" :class="statusClasses(station.occupiedTo)">{{station.occupiedTo}}</span>
</td>
<td class="item-dispatcher-name">{{station.online ? station.dispatcherName : ""}}</td>
<td class="item-dispatcher-exp">
<span
v-if="station.online"
:style="calculateExpStyle(station.dispatcherExp)"
>{{station.dispatcherExp < 2 ? 'L' : station.dispatcherExp}}</span>
</td>
<td
class="item-users"
>{{station.online ? (station.currentUsers + "/" + station.maxUsers) : ""}}</td>
<td class="item-info">
<img
class="icon-info"
v-if="station.controlType"
:src="require(`@/assets/icon-${station.controlType}.svg`)"
:alt="station.controlType"
:title="'Sterowanie ' + station.controlType"
/>
<img
class="icon-info"
v-if="station.signalType"
:src="require(`@/assets/icon-${station.signalType}.svg`)"
:alt="station.signalType"
:title="'Sygnalizacja ' + station.signalType"
/>
<img
class="icon-info"
v-if="station.SBL && station.SBL !== ''"
:src="require(`@/assets/icon-SBL.svg`)"
alt="SBL"
title="Sceneria posiada SBL na przynajmniej jednym ze szlaków"
/>
<img
class="icon-info"
v-if="!station.reqLevel || station.nonPublic"
:src="require(`@/assets/icon-lock.svg`)"
alt="non-public"
title="Sceneria niepubliczna"
/>
</td>
<td class="item-tracks twoway">
<span
v-if="station.routes && station.routes.twoWay.catenary > 0"
class="track catenary"
:title="'Liczba zelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.catenary"
>{{station.routes.twoWay.catenary}}</span>
<span
v-if="station.routes && station.routes.twoWay.noCatenary > 0"
class="track no-catenary"
:title="'Liczba niezelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.noCatenary"
>{{station.routes.twoWay.noCatenary}}</span>
</td>
<td class="item-tracks oneway">
<span
v-if="station.routes && station.routes.oneWay.catenary > 0"
class="track catenary"
:title="'Liczba zelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.catenary"
>{{station.routes.oneWay.catenary}}</span>
<span
v-if="station.routes && station.routes.oneWay.noCatenary > 0"
class="track no-catenary"
:title="'Liczba niezelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.noCatenary"
>{{station.routes.oneWay.noCatenary}}</span>
</td>
</tr>
</table>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import { Component, Prop } from "vue-property-decorator";
import Station from "@/scripts/interfaces/Station";
import styleMixin from "@/mixins/styleMixin";
const ascSVG = require("@/assets/icon-arrow-asc.svg");
const descSVG = require("@/assets/icon-arrow-desc.svg");
@Component({})
export default class Table extends styleMixin {
@Prop() readonly stations!: Station[];
@Prop() readonly setFocusedStation!: () => void;
icons: { ascSVG; descSVG } = { ascSVG, descSVG };
sorterActive: { index: number; type: number } = { index: 0, type: 1 };
headTitles: string[][] = [
["Stacja"],
["Wymagany poz.", "dyżurnego"],
["Status"],
["Dyżurny"],
["Poziom", "dyżurnego"],
["Maszyniści"],
["Informacje", "ogólne"],
["Szlaki", "dwutorowe"],
["Szlaki", "jednotorowe"],
];
changeSorter(index: number) {
if (index > 5) return;
if (index == this.sorterActive.index)
this.sorterActive.type = this.sorterActive.type == 1 ? -1 : 1;
else this.sorterActive.type = 1;
this.sorterActive.index = index;
}
get computedStations() {
const type: number = this.sorterActive.type;
const sortByName = (a: Station, b: Station) => {
if (a.stationName >= b.stationName) return type;
return -type;
};
if (this.sorterActive.index == 0)
return this.stations.sort((a, b) => {
if (a.stationName >= b.stationName) return type;
return -type;
});
let currentSort;
switch (this.sorterActive.index) {
case 0:
default:
return (currentSort = sortByName);
break;
case 1:
currentSort = (a, b) => {
if (parseInt(a.reqLevel) > parseInt(b.reqLevel)) return type;
if (parseInt(a.reqLevel) < parseInt(b.reqLevel)) return -type;
return sortByName(a, b);
};
break;
case 2:
currentSort = (a, b) => {
if (a.statusTimestamp > b.statusTimestamp) return type;
if (a.statusTimestamp < b.statusTimestamp) return -type;
if (a.occupiedTo > b.occupiedTo) return type;
if (a.occupiedTo < b.occupiedTo) return -type;
return sortByName(a, b);
};
break;
case 3:
currentSort = (a, b) => {
if (a.dispatcherName > b.dispatcherName) return type;
if (a.dispatcherName < b.dispatcherName) return -type;
return sortByName(a, b);
};
break;
case 4:
currentSort = (a, b) => {
if (a.dispatcherExp > b.dispatcherExp) return type;
if (a.dispatcherExp < b.dispatcherExp) return -type;
return sortByName(a, b);
};
break;
case 5:
currentSort = (a, b) => {
if (a.currentUsers > b.currentUsers) return type;
if (a.currentUsers < b.currentUsers) return -type;
return sortByName(a, b);
};
break;
case 6:
currentSort = (a, b) => {
if (a.currentUsers > b.currentUsers) return type;
if (a.currentUsers < b.currentUsers) return -type;
if (a.maxUsers > b.maxUsers) return type;
if (a.maxUsers < b.maxUsers) return -type;
};
break;
}
return this.stations.sort(currentSort);
}
mounted() {}
}
</script>
<style lang="scss" scoped>
@import "../../styles/responsive.scss";
@import "../../styles/variables.scss";
@import "../../styles/global.scss";
.table {
&-wrapper {
overflow: auto;
}
display: block;
white-space: nowrap;
border-collapse: collapse;
font-size: calc(0.6rem + 0.3vw);
@include smallScreen() {
font-size: 0.6rem;
}
&-head th {
padding: 0.3rem;
background-color: #444;
min-width: 120px;
position: sticky;
top: 0;
z-index: 2;
cursor: pointer;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
span {
display: flex;
align-items: center;
justify-content: center;
& > img {
width: 1.5em;
}
}
}
&-item {
background-color: #5c5b5b;
&:nth-child(even) {
background-color: rgb(102, 101, 101);
color: white;
}
&:hover,
&:focus {
background-color: #818181;
}
& > td {
padding: 0.3rem 1rem;
margin: 0 3rem;
text-align: center;
vertical-align: middle;
cursor: pointer;
@include smallScreen() {
margin: 0;
padding: 0.1rem 0.5rem;
}
}
}
}
.item {
&-station-level,
&-dispatcher-exp {
span {
display: block;
width: 2em;
height: 2em;
line-height: 2em;
margin: 0 auto;
}
}
&-station-level {
span {
background-color: #888;
border-radius: 50%;
}
}
&-info,
&-tracks {
img {
width: 2.2em;
margin: 0 0.2em;
vertical-align: middle;
}
}
&-tracks {
.no-catenary {
background-color: #939393;
}
.catenary {
background-color: #009dce;
}
.track {
margin: 0 0.3rem;
padding: 0.5em;
}
}
}
</style>