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 functions from "firebase-functions";
|
||||||
// import * as admin from "firebase-admin";
|
import * as admin from "firebase-admin";
|
||||||
|
|
||||||
// admin.initializeApp();
|
admin.initializeApp();
|
||||||
// const db = admin.firestore();
|
// 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: {
|
let stationAPIData: {
|
||||||
// stationName: string;
|
stationName: string;
|
||||||
// dispatcherName: string;
|
dispatcherName: string;
|
||||||
// isOnline: boolean;
|
isOnline: boolean;
|
||||||
// region: string;
|
region: string;
|
||||||
// }[];
|
}[] = [];
|
||||||
|
|
||||||
// let previousOnlineStations: {
|
let previousOnlineStations: {
|
||||||
// stationName: string;
|
stationName: string;
|
||||||
// dispatcherName: string;
|
dispatcherName: string;
|
||||||
// occupiedFrom: number;
|
occupiedFrom: number;
|
||||||
// }[] = [];
|
}[] = [];
|
||||||
|
|
||||||
// // const test = functions.pubsub.schedule("0 * * * *").onRun(async (context) => {
|
const API_URL = "https://api.td2.info.pl:9640/?method=getStationsOnline";
|
||||||
// // try {
|
|
||||||
// // stationAPIData = await (
|
|
||||||
// // await axios.get("https://api.td2.info.pl:9640/?method=getStationsOnline")
|
|
||||||
// // ).data.message;
|
|
||||||
// // } catch (error) {
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // if (previousOnlineStations.length == 0) {
|
exports.updateHistory = functions.pubsub
|
||||||
// // const historyRef = db.collection("dispatcherHistory");
|
.schedule("*/5 * * * *")
|
||||||
|
.onRun(async () => {
|
||||||
|
try {
|
||||||
|
stationAPIData = await (await axios.get(API_URL)).data.message;
|
||||||
|
} catch (error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// // stationAPIData
|
// On server start
|
||||||
// // .filter((station) => station.isOnline && station.region === "eu")
|
if (previousOnlineStations.length == 0) {
|
||||||
// // .forEach(async (station) => {
|
stationAPIData
|
||||||
// // const isOfficial: boolean = stationJSONList.some(
|
.filter(
|
||||||
// // (stationData) => stationData.stationName === station.stationName
|
(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);
|
return;
|
||||||
// // const docSnap = await docRef.get();
|
}
|
||||||
|
|
||||||
// // 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) {
|
// Dispatcher left
|
||||||
// // docRef.set({
|
if (!currStationData) {
|
||||||
// // occupiedFrom,
|
previousOnlineStations = previousOnlineStations.filter(
|
||||||
// // currentDispatcherName: station.dispatcherName,
|
(s) => s.stationName !== prevStation.stationName
|
||||||
// // });
|
);
|
||||||
// // } else {
|
}
|
||||||
// // docRef.update({
|
// Dispatchers switched
|
||||||
// // occupiedFrom,
|
else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
|
||||||
// // currentDispatcherName: station.dispatcherName,
|
previousOnlineStations = previousOnlineStations.filter(
|
||||||
// // });
|
(s) => s.stationName !== prevStation.stationName
|
||||||
// // }
|
);
|
||||||
|
|
||||||
// // previousOnlineStations.push({
|
previousOnlineStations.push({
|
||||||
// // dispatcherName: station.dispatcherName,
|
stationName: currStationData.stationName,
|
||||||
// // occupiedFrom,
|
dispatcherName: currStationData.dispatcherName,
|
||||||
// // stationName: station.stationName,
|
occupiedFrom: Date.now(),
|
||||||
// // });
|
});
|
||||||
// // });
|
}
|
||||||
// // } else {
|
});
|
||||||
// // previousOnlineStations.forEach((prevStation) => {
|
|
||||||
// // const currStationData = stationAPIData.find(
|
|
||||||
// // (currStation) => currStation.stationName === prevStation.stationName
|
|
||||||
// // );
|
|
||||||
|
|
||||||
// // // Dispatcher left
|
stationAPIData
|
||||||
// // if (!currStationData) {
|
.filter(
|
||||||
// // }
|
(stationData) =>
|
||||||
// // // The same dispatcher is still online - do nothing
|
!previousOnlineStations.find(
|
||||||
// // else if (prevStation.dispatcherName === currStationData.dispatcherName) {
|
(prevStation) => prevStation.stationName === stationData.stationName
|
||||||
// // }
|
)
|
||||||
// // // Dispatchers switched
|
)
|
||||||
// // else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
|
.forEach((stationData) => {
|
||||||
// // }
|
previousOnlineStations.push({
|
||||||
// // });
|
stationName: stationData.stationName,
|
||||||
|
dispatcherName: stationData.dispatcherName,
|
||||||
|
occupiedFrom: Date.now(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// // stationAPIData.forEach((stationData) => {
|
exports.getHistoryData = functions.https.onCall((data, context) => {
|
||||||
// // const isPrevious = previousOnlineStations.find(
|
return { previousOnlineStations };
|
||||||
// // (prevStation) => prevStation.stationName === stationData.stationName
|
});
|
||||||
// // );
|
|
||||||
|
|
||||||
// // // New station turned online
|
|
||||||
// // if (!isPrevious) {
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
// // }
|
|
||||||
// // });
|
|
||||||
|
|
||||||
// // const scheduledUpdate = functions.pubsub
|
// // const scheduledUpdate = functions.pubsub
|
||||||
// // .schedule("0 * * * *")
|
// // .schedule("0 * * * *")
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"outDir": "lib",
|
"outDir": "lib",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
|||||||
+6
-1
@@ -53,6 +53,8 @@ import Loading from "@/components/App/Loading.vue";
|
|||||||
|
|
||||||
import Clock from "@/components/App/Clock.vue";
|
import Clock from "@/components/App/Clock.vue";
|
||||||
|
|
||||||
|
// import firebase from "@/scripts/firebase/firebaseInit";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: { Error, Loading, Clock },
|
components: { Error, Loading, Clock },
|
||||||
})
|
})
|
||||||
@@ -65,8 +67,11 @@ export default class App extends Vue {
|
|||||||
|
|
||||||
errorMessage: string = "";
|
errorMessage: string = "";
|
||||||
|
|
||||||
mounted() {
|
async mounted() {
|
||||||
this.initStations();
|
this.initStations();
|
||||||
|
|
||||||
|
// const getData = firebase.functions.httpsCallable("getHistoryData");
|
||||||
|
// getData().then((res) => console.log(res.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,57 +4,6 @@
|
|||||||
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
|
<img :src="require('@/assets/icon-exit.svg')" alt="exit icon" />
|
||||||
</div>
|
</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="card-content" :class="{'offline': !stationInfo.online}">
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
@@ -190,8 +139,6 @@
|
|||||||
import { Component, Prop, Watch } from "vue-property-decorator";
|
import { Component, Prop, Watch } from "vue-property-decorator";
|
||||||
import styleMixin from "@/mixins/styleMixin";
|
import styleMixin from "@/mixins/styleMixin";
|
||||||
|
|
||||||
import db from "@/scripts/firebase/firebaseInit";
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class StationCard extends styleMixin {
|
export default class StationCard extends styleMixin {
|
||||||
@Prop() stationInfo;
|
@Prop() stationInfo;
|
||||||
@@ -283,8 +230,6 @@ export default class StationCard extends styleMixin {
|
|||||||
|
|
||||||
gap: 1.5em;
|
gap: 1.5em;
|
||||||
|
|
||||||
margin-bottom: 2.5rem;
|
|
||||||
|
|
||||||
&.offline {
|
&.offline {
|
||||||
.users,
|
.users,
|
||||||
.spawns,
|
.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 {
|
.main {
|
||||||
grid-area: main;
|
grid-area: main;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as firebase from "firebase/app";
|
import * as firebase from "firebase/app";
|
||||||
import "firebase/firestore";
|
import "firebase/firestore";
|
||||||
|
import "firebase/functions";
|
||||||
|
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
@@ -10,4 +11,7 @@ firebase.initializeApp({
|
|||||||
projectId: "stacjownik-td2",
|
projectId: "stacjownik-td2",
|
||||||
});
|
});
|
||||||
|
|
||||||
export default firebase.firestore();
|
export default {
|
||||||
|
db: firebase.firestore(),
|
||||||
|
functions: firebase.functions(),
|
||||||
|
};
|
||||||
|
|||||||
@@ -4,12 +4,7 @@
|
|||||||
<Error v-if="connectionState == 1" />
|
<Error v-if="connectionState == 1" />
|
||||||
|
|
||||||
<transition name="card-anim">
|
<transition name="card-anim">
|
||||||
<StationCard
|
<StationCard v-if="focusedStationInfo" :stationInfo="focusedStationInfo" :exit="closeCard" />
|
||||||
v-if="focusedStationInfo"
|
|
||||||
:stationInfo="focusedStationInfo"
|
|
||||||
:dispatcherHistory="dispatcherHistory()"
|
|
||||||
:exit="closeCard"
|
|
||||||
/>
|
|
||||||
</transition>
|
</transition>
|
||||||
<!-- <div class="info" v-if="stations.length == 0">Ups! Brak stacji do wyświetlenia!</div> -->
|
<!-- <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 StationCard from "@/components/StationsView/StationCard.vue";
|
||||||
import Options from "@/components/StationsView/Options.vue";
|
import Options from "@/components/StationsView/Options.vue";
|
||||||
|
|
||||||
import db from "@/scripts/firebase/firebaseInit";
|
|
||||||
import inputData from "@/data/options.json";
|
import inputData from "@/data/options.json";
|
||||||
|
|
||||||
enum ConnState {
|
enum ConnState {
|
||||||
@@ -109,24 +103,6 @@ export default class StationsView extends Vue {
|
|||||||
else this.focusedStationName = name;
|
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() {
|
get focusedStationInfo() {
|
||||||
return this.stations.find(
|
return this.stations.find(
|
||||||
(station) => station.stationName === this.focusedStationName
|
(station) => station.stationName === this.focusedStationName
|
||||||
|
|||||||
Reference in New Issue
Block a user