mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 13:28:11 +00:00
Restrukturyzacja filtrów scenerii i local storage
This commit is contained in:
+18
-167
@@ -40,7 +40,7 @@
|
||||
<div class="body_table">
|
||||
<StationTable
|
||||
:stations="computedStations"
|
||||
:sorterActive="sorterActive"
|
||||
:sorterActive="filterManager.getSorter()"
|
||||
:setFocusedStation="setFocusedStation"
|
||||
:changeSorter="changeSorter"
|
||||
/>
|
||||
@@ -70,36 +70,15 @@ import { Getter } from "vuex-class";
|
||||
import Station from "@/scripts/interfaces/Station";
|
||||
import Train from "@/scripts/interfaces/Train";
|
||||
|
||||
import StorageManager from "@/scripts/storageManager";
|
||||
import StationFilterManager from "@/scripts/stationFilterManager";
|
||||
|
||||
import inputData from "@/data/options.json";
|
||||
|
||||
import StationTable from "@/components/StationsView/StationTable.vue";
|
||||
import StationCard from "@/components/StationsView/StationCard.vue";
|
||||
import FilterCard from "@/components/StationsView/FilterCard.vue";
|
||||
|
||||
const filterInitStates = {
|
||||
default: false,
|
||||
notDefault: false,
|
||||
nonPublic: false,
|
||||
SPK: false,
|
||||
SCS: false,
|
||||
ręczne: false,
|
||||
mechaniczne: false,
|
||||
współczesna: false,
|
||||
kształtowa: false,
|
||||
historyczna: false,
|
||||
mieszana: false,
|
||||
minLevel: 0,
|
||||
minOneWayCatenary: 0,
|
||||
minOneWay: 0,
|
||||
minTwoWayCatenary: 0,
|
||||
minTwoWay: 0,
|
||||
"no-1track": false,
|
||||
"no-2track": false,
|
||||
free: true,
|
||||
occupied: false,
|
||||
ending: false,
|
||||
};
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
StationCard,
|
||||
@@ -113,10 +92,10 @@ export default class StationsView extends Vue {
|
||||
trainIcon: string = require("@/assets/icon-train.svg");
|
||||
timetableIcon: string = require("@/assets/icon-timetable.svg");
|
||||
|
||||
sorterActive: { index: number; dir: number } = { index: 0, dir: 1 };
|
||||
filterManager: StationFilterManager = new StationFilterManager();
|
||||
|
||||
focusedStationName: string = "";
|
||||
filterCardOpen: boolean = false;
|
||||
filters = { ...filterInitStates };
|
||||
|
||||
inputs = inputData;
|
||||
|
||||
@@ -137,24 +116,26 @@ export default class StationsView extends Vue {
|
||||
return "success";
|
||||
}
|
||||
|
||||
mounted() {
|
||||
const storage = window.localStorage;
|
||||
|
||||
if (storage.getItem(this.STORAGE_KEY) !== "true") return;
|
||||
initializeStorage() {
|
||||
if (!StorageManager.isRegistered(this.STORAGE_KEY)) return;
|
||||
|
||||
this.inputs.options.forEach((option) => {
|
||||
const value = storage.getItem(option.name) === "true" ? true : false;
|
||||
const value = StorageManager.getBooleanValue(option.name);
|
||||
|
||||
this.changeFilterValue({ name: option.name, value: value ? 0 : 1 });
|
||||
option.value = value;
|
||||
});
|
||||
|
||||
this.inputs.sliders.forEach((slider) => {
|
||||
const value = parseInt(storage.getItem(slider.name) || "0");
|
||||
const value = StorageManager.getNumericValue(slider.name);
|
||||
|
||||
this.changeFilterValue({ name: slider.name, value });
|
||||
slider.value = value;
|
||||
});
|
||||
}
|
||||
|
||||
mounted() {
|
||||
this.initializeStorage();
|
||||
|
||||
window.addEventListener("keydown", (e: KeyboardEvent) => {
|
||||
if (e.keyCode == 27 && this.focusedStationName != "") {
|
||||
@@ -170,149 +151,19 @@ export default class StationsView extends Vue {
|
||||
}
|
||||
|
||||
changeSorter(index: number) {
|
||||
if (index > 4) return;
|
||||
|
||||
if (index == this.sorterActive.index)
|
||||
this.sorterActive.dir = -1 * this.sorterActive.dir;
|
||||
else this.sorterActive.dir = 1;
|
||||
|
||||
this.sorterActive.index = index;
|
||||
this.filterManager.changeSorter(index);
|
||||
}
|
||||
|
||||
changeFilterValue(filter: { name: string; value: number }) {
|
||||
this.filters[filter.name] = filter.value;
|
||||
this.filterManager.changeFilterValue(filter);
|
||||
}
|
||||
|
||||
resetFilters() {
|
||||
this.filters = { ...filterInitStates };
|
||||
this.filterManager.resetFilters();
|
||||
}
|
||||
|
||||
get computedStations() {
|
||||
const dir: number = this.sorterActive.dir;
|
||||
// const scheduledTrainList = this.scheduledTrains;
|
||||
|
||||
return this.stationList
|
||||
.filter((station) => {
|
||||
if (!station.reqLevel || station.reqLevel == "-1") return true;
|
||||
|
||||
if (
|
||||
(station.nonPublic || !station.reqLevel) &&
|
||||
this.filters["nonPublic"]
|
||||
)
|
||||
return false;
|
||||
|
||||
if (
|
||||
station.online &&
|
||||
station.occupiedTo == "KOŃCZY" &&
|
||||
this.filters["ending"]
|
||||
)
|
||||
return false;
|
||||
|
||||
if (station.online && this.filters["occupied"]) return false;
|
||||
if (!station.online && this.filters["free"]) return false;
|
||||
|
||||
if (station.default && this.filters["default"]) return false;
|
||||
if (!station.default && this.filters["notDefault"]) return false;
|
||||
|
||||
if (parseInt(station.reqLevel) < this.filters["minLevel"]) return false;
|
||||
|
||||
if (
|
||||
this.filters["no-1track"] &&
|
||||
(station.routes.oneWay.catenary != 0 ||
|
||||
station.routes.oneWay.noCatenary != 0)
|
||||
)
|
||||
return false;
|
||||
if (
|
||||
this.filters["no-2track"] &&
|
||||
(station.routes.twoWay.catenary != 0 ||
|
||||
station.routes.twoWay.noCatenary != 0)
|
||||
)
|
||||
return false;
|
||||
|
||||
if (station.routes.oneWay.catenary < this.filters["minOneWayCatenary"])
|
||||
return false;
|
||||
if (station.routes.oneWay.noCatenary < this.filters["minOneWay"])
|
||||
return false;
|
||||
|
||||
if (station.routes.twoWay.catenary < this.filters["minTwoWayCatenary"])
|
||||
return false;
|
||||
if (station.routes.twoWay.noCatenary < this.filters["minTwoWay"])
|
||||
return false;
|
||||
|
||||
if (this.filters[station.controlType]) return false;
|
||||
if (this.filters[station.signalType]) return false;
|
||||
|
||||
if (
|
||||
this.filters["SPK"] &&
|
||||
(station.controlType === "SPK" ||
|
||||
station.controlType.includes("+SPK"))
|
||||
)
|
||||
return false;
|
||||
if (
|
||||
this.filters["SCS"] &&
|
||||
(station.controlType === "SCS" ||
|
||||
station.controlType.includes("+SCS"))
|
||||
)
|
||||
return false;
|
||||
|
||||
if (
|
||||
this.filters["SCS"] &&
|
||||
this.filters["SPK"] &&
|
||||
(station.controlType.includes("SPK") ||
|
||||
station.controlType.includes("SCS"))
|
||||
)
|
||||
return false;
|
||||
|
||||
if (
|
||||
this.filters["mechaniczne"] &&
|
||||
station.controlType.includes("mechaniczne")
|
||||
)
|
||||
return false;
|
||||
|
||||
if (this.filters["ręczne"] && station.controlType.includes("ręczne"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
})
|
||||
.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.toLowerCase() > b.dispatcherName.toLowerCase())
|
||||
return dir;
|
||||
if (a.dispatcherName.toLowerCase() < b.dispatcherName.toLowerCase())
|
||||
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.toLowerCase() >= b.stationName.toLowerCase())
|
||||
return dir;
|
||||
return -dir;
|
||||
});
|
||||
return this.filterManager.filteredStationList(this.stationList);
|
||||
}
|
||||
|
||||
closeCard() {
|
||||
|
||||
Reference in New Issue
Block a user