From 520a1083dc33b81056da24ea3c13c6f072078707 Mon Sep 17 00:00:00 2001 From: Spythere Date: Mon, 24 Aug 2020 19:45:52 +0200 Subject: [PATCH] =?UTF-8?q?Zmiany=20w=20wygl=C4=85dzie=20tabelki,=20po?= =?UTF-8?q?=C5=82=C4=85czenie=20kolumn=20ze=20szlakami?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/src/index.ts | 377 +++++++++++-------- src/App.vue | 5 - src/components/StationsView/StationCard.vue | 8 + src/components/StationsView/StationTable.vue | 15 +- 4 files changed, 246 insertions(+), 159 deletions(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index af33bd1..5062425 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -1,175 +1,254 @@ -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"; -import stationJSONList from "./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 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 - .schedule("*/5 * * * *") - .onRun(async () => { - try { - stationAPIData = await (await axios.get(API_URL)).data.message; - } catch (error) { - return; - } +// exports.updateHistory = functions.pubsub +// .schedule("*/5 * * * *") +// .onRun(async (context) => { +// try { +// stationAPIData = await (await axios.get(API_URL)).data.message; +// } catch (error) { +// return; +// } - // 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(); +// // 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(); - previousOnlineStations.push({ - stationName: station.stationName, - dispatcherName: station.dispatcherName, - occupiedFrom, - }); - }); +// previousOnlineStations.push({ +// stationName: station.stationName, +// dispatcherName: station.dispatcherName, +// occupiedFrom, +// }); +// }); - return; - } +// return; +// } - // When array with previous stations isn't empty - previousOnlineStations.forEach((prevStation) => { - const currStationData = stationAPIData.find( - (currStation) => currStation.stationName === prevStation.stationName - ); +// // When array with previous stations isn't empty +// previousOnlineStations.forEach((prevStation) => { +// const currStationData = stationAPIData.find( +// (currStation) => currStation.stationName === prevStation.stationName +// ); - // 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 - ); +// // 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({ - stationName: currStationData.stationName, - dispatcherName: currStationData.dispatcherName, - occupiedFrom: Date.now(), - }); - } - }); +// previousOnlineStations.push({ +// stationName: currStationData.stationName, +// dispatcherName: currStationData.dispatcherName, +// occupiedFrom: Date.now(), +// }); +// } +// }); - stationAPIData - .filter( - (stationData) => - !previousOnlineStations.find( - (prevStation) => prevStation.stationName === stationData.stationName - ) - ) - .forEach((stationData) => { - previousOnlineStations.push({ - stationName: stationData.stationName, - dispatcherName: stationData.dispatcherName, - occupiedFrom: Date.now(), - }); - }); - }); +// stationAPIData +// .filter( +// (stationData) => +// !previousOnlineStations.find( +// (prevStation) => prevStation.stationName === stationData.stationName +// ) +// ) +// .forEach((stationData) => { +// previousOnlineStations.push({ +// stationName: stationData.stationName, +// dispatcherName: stationData.dispatcherName, +// occupiedFrom: Date.now(), +// }); +// }); -exports.getHistoryData = functions.https.onCall((data, context) => { - return { previousOnlineStations }; -}); +// const stationsDoc = db.collection("stations").doc("previous"); -// // const scheduledUpdate = functions.pubsub -// // .schedule("0 * * * *") -// // .onRun(async (context) => { -// // let stationData: { -// // stationName: string; -// // dispatcherName: string; -// // isOnline: boolean; -// // region: string; -// // }[]; +// stationsDoc.set({ previousOnlineStations }); +// }); -// // try { -// // stationData = await ( -// // await axios.get( -// // "https://api.td2.info.pl:9640/?method=getStationsOnline" -// // ) -// // ).data.message; -// // } catch (error) { -// // return; -// // } +// exports.test = functions.https.onRequest(async (req, res) => { +// try { +// stationAPIData = await (await axios.get(API_URL)).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) => { -// // const docRef = historyRef.doc(station.stationName); -// // const docSnapshot = await docRef.get(); +// previousOnlineStations.push({ +// stationName: station.stationName, +// dispatcherName: station.dispatcherName, +// occupiedFrom, +// }); +// }); -// // if (!docSnapshot.exists) { -// // docRef.set({ -// // occupiedFrom: Date.now(), -// // currentDispatcherName: station.dispatcherName, -// // }); -// // return; -// // } -// // }); +// 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) => { -// // const docData = doc.data(); -// // const docRef = historyRef.doc(doc.id); +// // 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 +// ); -// // const APIStationData = stationData -// // .filter((station) => station.isOnline && station.region === "eu") -// // .find((station) => station.stationName == doc.id); +// previousOnlineStations.push({ +// stationName: currStationData.stationName, +// dispatcherName: currStationData.dispatcherName, +// occupiedFrom: Date.now(), +// }); +// } +// }); -// // if (docData.currentDispatcherName != "") { -// // if ( -// // !APIStationData || -// // APIStationData.dispatcherName != docData.currentDispatcherName -// // ) { -// // docRef.update({ -// // currentDispatcherName: !APIStationData -// // ? "" -// // : APIStationData.dispatcherName, -// // occupiedFrom: !APIStationData ? 0 : Date.now(), -// // }); +// stationAPIData +// .filter( +// (stationData) => +// !previousOnlineStations.find( +// (prevStation) => prevStation.stationName === stationData.stationName +// ) +// ) +// .forEach((stationData) => { +// previousOnlineStations.push({ +// stationName: stationData.stationName, +// dispatcherName: stationData.dispatcherName, +// occupiedFrom: 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(), -// // }); -// // } -// // }); -// // }); +// const stationsDoc = db.collection("stations").doc("previous"); + +// stationsDoc.set({ previousOnlineStations }); + +// res.status(200); +// }); + +// // // const scheduledUpdate = functions.pubsub +// // // .schedule("0 * * * *") +// // // .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(), +// // // }); +// // // } +// // // }); +// // // }); diff --git a/src/App.vue b/src/App.vue index 03b0f9b..9104bbc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -53,8 +53,6 @@ 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 }, }) @@ -69,9 +67,6 @@ export default class App extends Vue { async mounted() { this.initStations(); - - // const getData = firebase.functions.httpsCallable("getHistoryData"); - // getData().then((res) => console.log(res.data)); } } diff --git a/src/components/StationsView/StationCard.vue b/src/components/StationsView/StationCard.vue index 235e8b0..207e0a8 100644 --- a/src/components/StationsView/StationCard.vue +++ b/src/components/StationsView/StationCard.vue @@ -222,6 +222,14 @@ export default class StationCard extends styleMixin { -moz-user-select: none; -webkit-user-select: none; + &-exit { + img { + width: 1.5em; + } + + cursor: pointer; + } + &-content { display: grid; grid-template-areas: "main main" "icons icons" "dispatcher hours" "users spawns" "history history"; diff --git a/src/components/StationsView/StationTable.vue b/src/components/StationsView/StationTable.vue index 0eb71b5..57f8629 100644 --- a/src/components/StationsView/StationTable.vue +++ b/src/components/StationsView/StationTable.vue @@ -102,9 +102,9 @@ class="track no-catenary" :title="'Liczba niezelektryfikowanych szlaków dwutorowych: ' + station.routes.twoWay.noCatenary" >{{station.routes.twoWay.noCatenary}} - - + + {{station.routes.oneWay.noCatenary}} + + @@ -147,14 +149,13 @@ export default class StationTable extends styleMixin { headTitles: string[][] = [ ["Stacja"], - ["Wymagany poz.", "dyżurnego"], + ["Min. poziom", "dyżurnego"], ["Status"], ["Dyżurny"], ["Poziom", "dyżurnego"], ["Maszyniści"], ["Informacje", "ogólne"], - ["Szlaki", "dwutorowe"], - ["Szlaki", "jednotorowe"], + ["Szlaki", "2tor | 1tor"], ]; changeSorter(index: number) { @@ -215,6 +216,10 @@ export default class StationTable extends styleMixin { @import "../../styles/variables.scss"; @import "../../styles/global.scss"; +.separator { + border-left: 3px solid #b3b3b3; +} + .table { &-wrapper { overflow: auto;