mirror of
https://github.com/Spythere/stacjownik.git
synced 2026-05-03 05:18:11 +00:00
Usunięto requesty do bazy danych
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+87
-79
@@ -1,98 +1,106 @@
|
||||
// import * as functions from "firebase-functions";
|
||||
// import * as admin from "firebase-admin";
|
||||
import * as functions from "firebase-functions";
|
||||
import * as admin from "firebase-admin";
|
||||
|
||||
// admin.initializeApp();
|
||||
admin.initializeApp();
|
||||
// const db = admin.firestore();
|
||||
|
||||
// import axios from "axios";
|
||||
import axios from "axios";
|
||||
|
||||
// const stationJSONList: any[] = require("./stations.json");
|
||||
import stationJSONList from "./stations.json";
|
||||
|
||||
// let stationAPIData: {
|
||||
// stationName: string;
|
||||
// dispatcherName: string;
|
||||
// isOnline: boolean;
|
||||
// region: string;
|
||||
// }[];
|
||||
let stationAPIData: {
|
||||
stationName: string;
|
||||
dispatcherName: string;
|
||||
isOnline: boolean;
|
||||
region: string;
|
||||
}[] = [];
|
||||
|
||||
// let previousOnlineStations: {
|
||||
// stationName: string;
|
||||
// dispatcherName: string;
|
||||
// occupiedFrom: number;
|
||||
// }[] = [];
|
||||
let previousOnlineStations: {
|
||||
stationName: string;
|
||||
dispatcherName: string;
|
||||
occupiedFrom: number;
|
||||
}[] = [];
|
||||
|
||||
// // const test = functions.pubsub.schedule("0 * * * *").onRun(async (context) => {
|
||||
// // try {
|
||||
// // stationAPIData = await (
|
||||
// // await axios.get("https://api.td2.info.pl:9640/?method=getStationsOnline")
|
||||
// // ).data.message;
|
||||
// // } catch (error) {
|
||||
// // return;
|
||||
// // }
|
||||
const API_URL = "https://api.td2.info.pl:9640/?method=getStationsOnline";
|
||||
|
||||
// // if (previousOnlineStations.length == 0) {
|
||||
// // const historyRef = db.collection("dispatcherHistory");
|
||||
exports.updateHistory = functions.pubsub
|
||||
.schedule("*/5 * * * *")
|
||||
.onRun(async () => {
|
||||
try {
|
||||
stationAPIData = await (await axios.get(API_URL)).data.message;
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// // stationAPIData
|
||||
// // .filter((station) => station.isOnline && station.region === "eu")
|
||||
// // .forEach(async (station) => {
|
||||
// // const isOfficial: boolean = stationJSONList.some(
|
||||
// // (stationData) => stationData.stationName === station.stationName
|
||||
// // );
|
||||
// On server start
|
||||
if (previousOnlineStations.length == 0) {
|
||||
stationAPIData
|
||||
.filter(
|
||||
(station) =>
|
||||
station.isOnline &&
|
||||
station.region === "eu" &&
|
||||
stationJSONList.some(
|
||||
(data) => data.stationName === station.stationName
|
||||
)
|
||||
)
|
||||
.forEach((station) => {
|
||||
const occupiedFrom = Date.now();
|
||||
|
||||
// // if (!isOfficial) return;
|
||||
previousOnlineStations.push({
|
||||
stationName: station.stationName,
|
||||
dispatcherName: station.dispatcherName,
|
||||
occupiedFrom,
|
||||
});
|
||||
});
|
||||
|
||||
// // const docRef = historyRef.doc(station.stationName);
|
||||
// // const docSnap = await docRef.get();
|
||||
return;
|
||||
}
|
||||
|
||||
// // const occupiedFrom = Date.now();
|
||||
// When array with previous stations isn't empty
|
||||
previousOnlineStations.forEach((prevStation) => {
|
||||
const currStationData = stationAPIData.find(
|
||||
(currStation) => currStation.stationName === prevStation.stationName
|
||||
);
|
||||
|
||||
// // if (!docSnap.exists) {
|
||||
// // docRef.set({
|
||||
// // occupiedFrom,
|
||||
// // currentDispatcherName: station.dispatcherName,
|
||||
// // });
|
||||
// // } else {
|
||||
// // docRef.update({
|
||||
// // occupiedFrom,
|
||||
// // currentDispatcherName: station.dispatcherName,
|
||||
// // });
|
||||
// // }
|
||||
// Dispatcher left
|
||||
if (!currStationData) {
|
||||
previousOnlineStations = previousOnlineStations.filter(
|
||||
(s) => s.stationName !== prevStation.stationName
|
||||
);
|
||||
}
|
||||
// Dispatchers switched
|
||||
else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
|
||||
previousOnlineStations = previousOnlineStations.filter(
|
||||
(s) => s.stationName !== prevStation.stationName
|
||||
);
|
||||
|
||||
// // previousOnlineStations.push({
|
||||
// // dispatcherName: station.dispatcherName,
|
||||
// // occupiedFrom,
|
||||
// // stationName: station.stationName,
|
||||
// // });
|
||||
// // });
|
||||
// // } else {
|
||||
// // previousOnlineStations.forEach((prevStation) => {
|
||||
// // const currStationData = stationAPIData.find(
|
||||
// // (currStation) => currStation.stationName === prevStation.stationName
|
||||
// // );
|
||||
previousOnlineStations.push({
|
||||
stationName: currStationData.stationName,
|
||||
dispatcherName: currStationData.dispatcherName,
|
||||
occupiedFrom: Date.now(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// // // Dispatcher left
|
||||
// // if (!currStationData) {
|
||||
// // }
|
||||
// // // The same dispatcher is still online - do nothing
|
||||
// // else if (prevStation.dispatcherName === currStationData.dispatcherName) {
|
||||
// // }
|
||||
// // // Dispatchers switched
|
||||
// // else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
|
||||
// // }
|
||||
// // });
|
||||
stationAPIData
|
||||
.filter(
|
||||
(stationData) =>
|
||||
!previousOnlineStations.find(
|
||||
(prevStation) => prevStation.stationName === stationData.stationName
|
||||
)
|
||||
)
|
||||
.forEach((stationData) => {
|
||||
previousOnlineStations.push({
|
||||
stationName: stationData.stationName,
|
||||
dispatcherName: stationData.dispatcherName,
|
||||
occupiedFrom: Date.now(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// // stationAPIData.forEach((stationData) => {
|
||||
// // const isPrevious = previousOnlineStations.find(
|
||||
// // (prevStation) => prevStation.stationName === stationData.stationName
|
||||
// // );
|
||||
|
||||
// // // New station turned online
|
||||
// // if (!isPrevious) {
|
||||
// // }
|
||||
// // });
|
||||
// // }
|
||||
// // });
|
||||
exports.getHistoryData = functions.https.onCall((data, context) => {
|
||||
return { previousOnlineStations };
|
||||
});
|
||||
|
||||
// // const scheduledUpdate = functions.pubsub
|
||||
// // .schedule("0 * * * *")
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitReturns": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"noUnusedLocals": true,
|
||||
"outDir": "lib",
|
||||
"sourceMap": true,
|
||||
@@ -12,4 +14,4 @@
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -53,6 +53,8 @@ import Loading from "@/components/App/Loading.vue";
|
||||
|
||||
import Clock from "@/components/App/Clock.vue";
|
||||
|
||||
// import firebase from "@/scripts/firebase/firebaseInit";
|
||||
|
||||
@Component({
|
||||
components: { Error, Loading, Clock },
|
||||
})
|
||||
@@ -65,8 +67,11 @@ export default class App extends Vue {
|
||||
|
||||
errorMessage: string = "";
|
||||
|
||||
mounted() {
|
||||
async mounted() {
|
||||
this.initStations();
|
||||
|
||||
// const getData = firebase.functions.httpsCallable("getHistoryData");
|
||||
// getData().then((res) => console.log(res.data));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -4,57 +4,6 @@
|
||||
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
|
||||
</div>
|
||||
|
||||
<div class="card-history">
|
||||
<div class="history-title">
|
||||
<span class="title">DZIENNIK STACJI</span>
|
||||
|
|
||||
<span>Usługa czasowo wstrzymana ⏲</span>
|
||||
</div>
|
||||
|
||||
<ul class="history-list">
|
||||
<!-- <div
|
||||
class="history-info"
|
||||
>Wersja eksperymentalna! Dziennik aktualizuje się automatycznie co godzinę.</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">
|
||||
@@ -190,8 +139,6 @@
|
||||
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;
|
||||
@@ -283,8 +230,6 @@ export default class StationCard extends styleMixin {
|
||||
|
||||
gap: 1.5em;
|
||||
|
||||
margin-bottom: 2.5rem;
|
||||
|
||||
&.offline {
|
||||
.users,
|
||||
.spawns,
|
||||
@@ -300,91 +245,6 @@ export default class StationCard extends styleMixin {
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
|
||||
color: #999;
|
||||
}
|
||||
|
||||
&-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;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as firebase from "firebase/app";
|
||||
import "firebase/firestore";
|
||||
import "firebase/functions";
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
@@ -10,4 +11,7 @@ firebase.initializeApp({
|
||||
projectId: "stacjownik-td2",
|
||||
});
|
||||
|
||||
export default firebase.firestore();
|
||||
export default {
|
||||
db: firebase.firestore(),
|
||||
functions: firebase.functions(),
|
||||
};
|
||||
|
||||
@@ -4,12 +4,7 @@
|
||||
<Error v-if="connectionState == 1" />
|
||||
|
||||
<transition name="card-anim">
|
||||
<StationCard
|
||||
v-if="focusedStationInfo"
|
||||
:stationInfo="focusedStationInfo"
|
||||
:dispatcherHistory="dispatcherHistory()"
|
||||
:exit="closeCard"
|
||||
/>
|
||||
<StationCard v-if="focusedStationInfo" :stationInfo="focusedStationInfo" :exit="closeCard" />
|
||||
</transition>
|
||||
<!-- <div class="info" v-if="stations.length == 0">Ups! Brak stacji do wyświetlenia!</div> -->
|
||||
|
||||
@@ -35,7 +30,6 @@ import StationTable from "@/components/StationsView/StationTable.vue";
|
||||
import StationCard from "@/components/StationsView/StationCard.vue";
|
||||
import Options from "@/components/StationsView/Options.vue";
|
||||
|
||||
import db from "@/scripts/firebase/firebaseInit";
|
||||
import inputData from "@/data/options.json";
|
||||
|
||||
enum ConnState {
|
||||
@@ -109,24 +103,6 @@ export default class StationsView extends Vue {
|
||||
else this.focusedStationName = name;
|
||||
}
|
||||
|
||||
get dispatcherHistory() {
|
||||
return async () => {
|
||||
let history: any[] = [];
|
||||
|
||||
if (this.focusedStationName != "") {
|
||||
const historyRef = await db
|
||||
.collection("history")
|
||||
.doc(this.focusedStationName)
|
||||
.collection("dispatcherHistory")
|
||||
.get();
|
||||
|
||||
history = historyRef.docs.map((doc) => doc.data());
|
||||
}
|
||||
|
||||
return history;
|
||||
};
|
||||
}
|
||||
|
||||
get focusedStationInfo() {
|
||||
return this.stations.find(
|
||||
(station) => station.stationName === this.focusedStationName
|
||||
|
||||
Reference in New Issue
Block a user