Zmiany w wyglądzie tabelki, połączenie kolumn ze szlakami

This commit is contained in:
2020-08-24 19:45:52 +02:00
parent b5b5cb6f85
commit 520a1083dc
4 changed files with 246 additions and 159 deletions
+228 -149
View File
@@ -1,175 +1,254 @@
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";
import stationJSONList from "./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 API_URL = "https://api.td2.info.pl:9640/?method=getStationsOnline"; // const API_URL = "https://api.td2.info.pl:9640/?method=getStationsOnline";
exports.updateHistory = functions.pubsub // exports.updateHistory = functions.pubsub
.schedule("*/5 * * * *") // .schedule("*/5 * * * *")
.onRun(async () => { // .onRun(async (context) => {
try { // try {
stationAPIData = await (await axios.get(API_URL)).data.message; // stationAPIData = await (await axios.get(API_URL)).data.message;
} catch (error) { // } catch (error) {
return; // return;
} // }
// On server start // // On server start
if (previousOnlineStations.length == 0) { // if (previousOnlineStations.length == 0) {
stationAPIData // stationAPIData
.filter( // .filter(
(station) => // (station) =>
station.isOnline && // station.isOnline &&
station.region === "eu" && // station.region === "eu" &&
stationJSONList.some( // stationJSONList.some(
(data) => data.stationName === station.stationName // (data) => data.stationName === station.stationName
) // )
) // )
.forEach((station) => { // .forEach((station) => {
const occupiedFrom = Date.now(); // const occupiedFrom = Date.now();
previousOnlineStations.push({ // previousOnlineStations.push({
stationName: station.stationName, // stationName: station.stationName,
dispatcherName: station.dispatcherName, // dispatcherName: station.dispatcherName,
occupiedFrom, // occupiedFrom,
}); // });
}); // });
return; // return;
} // }
// When array with previous stations isn't empty // // When array with previous stations isn't empty
previousOnlineStations.forEach((prevStation) => { // previousOnlineStations.forEach((prevStation) => {
const currStationData = stationAPIData.find( // const currStationData = stationAPIData.find(
(currStation) => currStation.stationName === prevStation.stationName // (currStation) => currStation.stationName === prevStation.stationName
); // );
// Dispatcher left // // Dispatcher left
if (!currStationData) { // if (!currStationData) {
previousOnlineStations = previousOnlineStations.filter( // previousOnlineStations = previousOnlineStations.filter(
(s) => s.stationName !== prevStation.stationName // (s) => s.stationName !== prevStation.stationName
); // );
} // }
// Dispatchers switched // // Dispatchers switched
else if (prevStation.dispatcherName !== currStationData.dispatcherName) { // else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
previousOnlineStations = previousOnlineStations.filter( // previousOnlineStations = previousOnlineStations.filter(
(s) => s.stationName !== prevStation.stationName // (s) => s.stationName !== prevStation.stationName
); // );
previousOnlineStations.push({ // previousOnlineStations.push({
stationName: currStationData.stationName, // stationName: currStationData.stationName,
dispatcherName: currStationData.dispatcherName, // dispatcherName: currStationData.dispatcherName,
occupiedFrom: Date.now(), // occupiedFrom: Date.now(),
}); // });
} // }
}); // });
stationAPIData // stationAPIData
.filter( // .filter(
(stationData) => // (stationData) =>
!previousOnlineStations.find( // !previousOnlineStations.find(
(prevStation) => prevStation.stationName === stationData.stationName // (prevStation) => prevStation.stationName === stationData.stationName
) // )
) // )
.forEach((stationData) => { // .forEach((stationData) => {
previousOnlineStations.push({ // previousOnlineStations.push({
stationName: stationData.stationName, // stationName: stationData.stationName,
dispatcherName: stationData.dispatcherName, // dispatcherName: stationData.dispatcherName,
occupiedFrom: Date.now(), // occupiedFrom: Date.now(),
}); // });
}); // });
});
exports.getHistoryData = functions.https.onCall((data, context) => { // const stationsDoc = db.collection("stations").doc("previous");
return { previousOnlineStations };
});
// // const scheduledUpdate = functions.pubsub // stationsDoc.set({ previousOnlineStations });
// // .schedule("0 * * * *") // });
// // .onRun(async (context) => {
// // let stationData: {
// // stationName: string;
// // dispatcherName: string;
// // isOnline: boolean;
// // region: string;
// // }[];
// // try { // exports.test = functions.https.onRequest(async (req, res) => {
// // stationData = await ( // try {
// // await axios.get( // stationAPIData = await (await axios.get(API_URL)).data.message;
// // "https://api.td2.info.pl:9640/?method=getStationsOnline" // } catch (error) {
// // ) // return;
// // ).data.message; // }
// // } catch (error) {
// // return;
// // }
// // const historyRef = db.collection("history"); // // 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();
// // stationData.forEach(async (station) => { // previousOnlineStations.push({
// // const docRef = historyRef.doc(station.stationName); // stationName: station.stationName,
// // const docSnapshot = await docRef.get(); // dispatcherName: station.dispatcherName,
// occupiedFrom,
// });
// });
// // if (!docSnapshot.exists) { // return;
// // docRef.set({ // }
// // occupiedFrom: Date.now(),
// // currentDispatcherName: station.dispatcherName,
// // });
// // return;
// // }
// // });
// // const snapshot = await historyRef.get(); // // When array with previous stations isn't empty
// previousOnlineStations.forEach((prevStation) => {
// const currStationData = stationAPIData.find(
// (currStation) => currStation.stationName === prevStation.stationName
// );
// // snapshot.forEach(async (doc) => { // // Dispatcher left
// // const docData = doc.data(); // if (!currStationData) {
// // const docRef = historyRef.doc(doc.id); // previousOnlineStations = previousOnlineStations.filter(
// (s) => s.stationName !== prevStation.stationName
// );
// }
// // Dispatchers switched
// else if (prevStation.dispatcherName !== currStationData.dispatcherName) {
// previousOnlineStations = previousOnlineStations.filter(
// (s) => s.stationName !== prevStation.stationName
// );
// // const APIStationData = stationData // previousOnlineStations.push({
// // .filter((station) => station.isOnline && station.region === "eu") // stationName: currStationData.stationName,
// // .find((station) => station.stationName == doc.id); // dispatcherName: currStationData.dispatcherName,
// occupiedFrom: Date.now(),
// });
// }
// });
// // if (docData.currentDispatcherName != "") { // stationAPIData
// // if ( // .filter(
// // !APIStationData || // (stationData) =>
// // APIStationData.dispatcherName != docData.currentDispatcherName // !previousOnlineStations.find(
// // ) { // (prevStation) => prevStation.stationName === stationData.stationName
// // docRef.update({ // )
// // currentDispatcherName: !APIStationData // )
// // ? "" // .forEach((stationData) => {
// // : APIStationData.dispatcherName, // previousOnlineStations.push({
// // occupiedFrom: !APIStationData ? 0 : Date.now(), // stationName: stationData.stationName,
// // }); // dispatcherName: stationData.dispatcherName,
// occupiedFrom: Date.now(),
// });
// });
// // docRef.collection("dispatcherHistory").add({ // const stationsDoc = db.collection("stations").doc("previous");
// // currentDispatcherName: docData.currentDispatcherName,
// // occupiedFrom: docData.occupiedFrom, // stationsDoc.set({ previousOnlineStations });
// // occupiedTo: Date.now(),
// // }); // res.status(200);
// // } // });
// // } else if (APIStationData) {
// // docRef.update({ // // // const scheduledUpdate = functions.pubsub
// // currentDispatcherName: APIStationData.dispatcherName, // // // .schedule("0 * * * *")
// // occupiedFrom: Date.now(), // // // .onRun(async (context) => {
// // }); // // // let stationData: {
// // } // // // stationName: string;
// // }); // // // dispatcherName: string;
// // }); // // // isOnline: boolean;
// // // region: string;
// // // }[];
// // // try {
// // // stationData = await (
// // // await axios.get(
// // // "https://api.td2.info.pl:9640/?method=getStationsOnline"
// // // )
// // // ).data.message;
// // // } catch (error) {
// // // return;
// // // }
// // // const historyRef = db.collection("history");
// // // stationData.forEach(async (station) => {
// // // const docRef = historyRef.doc(station.stationName);
// // // const docSnapshot = await docRef.get();
// // // if (!docSnapshot.exists) {
// // // docRef.set({
// // // occupiedFrom: Date.now(),
// // // currentDispatcherName: station.dispatcherName,
// // // });
// // // return;
// // // }
// // // });
// // // const snapshot = await historyRef.get();
// // // snapshot.forEach(async (doc) => {
// // // const docData = doc.data();
// // // const docRef = historyRef.doc(doc.id);
// // // const APIStationData = stationData
// // // .filter((station) => station.isOnline && station.region === "eu")
// // // .find((station) => station.stationName == doc.id);
// // // if (docData.currentDispatcherName != "") {
// // // if (
// // // !APIStationData ||
// // // APIStationData.dispatcherName != docData.currentDispatcherName
// // // ) {
// // // docRef.update({
// // // currentDispatcherName: !APIStationData
// // // ? ""
// // // : APIStationData.dispatcherName,
// // // occupiedFrom: !APIStationData ? 0 : Date.now(),
// // // });
// // // docRef.collection("dispatcherHistory").add({
// // // currentDispatcherName: docData.currentDispatcherName,
// // // occupiedFrom: docData.occupiedFrom,
// // // occupiedTo: Date.now(),
// // // });
// // // }
// // // } else if (APIStationData) {
// // // docRef.update({
// // // currentDispatcherName: APIStationData.dispatcherName,
// // // occupiedFrom: Date.now(),
// // // });
// // // }
// // // });
// // // });
-5
View File
@@ -53,8 +53,6 @@ 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 },
}) })
@@ -69,9 +67,6 @@ export default class App extends Vue {
async mounted() { async mounted() {
this.initStations(); this.initStations();
// const getData = firebase.functions.httpsCallable("getHistoryData");
// getData().then((res) => console.log(res.data));
} }
} }
</script> </script>
@@ -222,6 +222,14 @@ export default class StationCard extends styleMixin {
-moz-user-select: none; -moz-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
&-exit {
img {
width: 1.5em;
}
cursor: pointer;
}
&-content { &-content {
display: grid; display: grid;
grid-template-areas: "main main" "icons icons" "dispatcher hours" "users spawns" "history history"; grid-template-areas: "main main" "icons icons" "dispatcher hours" "users spawns" "history history";
+10 -5
View File
@@ -102,9 +102,9 @@
class="track no-catenary" class="track no-catenary"
:title="'Liczba niezelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.noCatenary" :title="'Liczba niezelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.noCatenary"
>{{station.routes.twoWay.noCatenary}}</span> >{{station.routes.twoWay.noCatenary}}</span>
</td>
<td class="item-tracks oneway"> <span class="separator"></span>
<span <span
v-if="station.routes && station.routes.oneWay.catenary > 0" v-if="station.routes && station.routes.oneWay.catenary > 0"
class="track catenary" class="track catenary"
@@ -117,6 +117,8 @@
:title="'Liczba niezelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.noCatenary" :title="'Liczba niezelektryfikowanych szlaków jednotorowych: ' + station.routes.oneWay.noCatenary"
>{{station.routes.oneWay.noCatenary}}</span> >{{station.routes.oneWay.noCatenary}}</span>
</td> </td>
<!-- <td class="item-tracks oneway"></td> -->
</tr> </tr>
</table> </table>
</div> </div>
@@ -147,14 +149,13 @@ export default class StationTable extends styleMixin {
headTitles: string[][] = [ headTitles: string[][] = [
["Stacja"], ["Stacja"],
["Wymagany poz.", "dyżurnego"], ["Min. poziom", "dyżurnego"],
["Status"], ["Status"],
["Dyżurny"], ["Dyżurny"],
["Poziom", "dyżurnego"], ["Poziom", "dyżurnego"],
["Maszyniści"], ["Maszyniści"],
["Informacje", "ogólne"], ["Informacje", "ogólne"],
["Szlaki", "dwutorowe"], ["Szlaki", "2tor | 1tor"],
["Szlaki", "jednotorowe"],
]; ];
changeSorter(index: number) { changeSorter(index: number) {
@@ -215,6 +216,10 @@ export default class StationTable extends styleMixin {
@import "../../styles/variables.scss"; @import "../../styles/variables.scss";
@import "../../styles/global.scss"; @import "../../styles/global.scss";
.separator {
border-left: 3px solid #b3b3b3;
}
.table { .table {
&-wrapper { &-wrapper {
overflow: auto; overflow: auto;