Merge pull request #16 from 0hAodha/conor

Implement Firebase emulator
This commit is contained in:
2023-02-23 14:40:05 +00:00
committed by GitHub
13 changed files with 1558 additions and 707 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
dist/favicon.ico vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

4
dist/index.html vendored
View File

@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Irish Rail Tracker</title>
<script type="module" crossorigin src="/assets/index-383d0d29.js"></script>
<link rel="stylesheet" href="/assets/index-9a76eada.css">
<script type="module" crossorigin src="/assets/index-f45376ca.js"></script>
<link rel="stylesheet" href="/assets/index-24f118f5.css">
</head>
<body>
<div id="app"></div>

View File

@ -18,5 +18,20 @@
"firebase-debug.*.log"
]
}
]
],
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 5002
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
},
"singleProjectMode": true
}
}

View File

@ -18,14 +18,13 @@ exports.getLiveTrainData = functions.https.onRequest((request, response) => {
// fetch the "liveTrainData" collection
admin.firestore().collection('liveTrainData').get().then((snapshot) => {
if (snapshot.empty) {
response.send("Error fetching data from the database");
response.send({data: "Error fetching data from the database"});
return;
}
// iterate through each of the collection's documents
snapshot.forEach(doc => {
jsonData.push(doc.data());
});
// response.send(jsonData);
response.json({data: jsonData});
})
});
@ -56,21 +55,25 @@ exports.postLiveTrainData = functions.https.onRequest((request, response) => {
batchDelete.commit().then(function() {
// batch write all train JSON objects to the "liveTrainData" collection
var batchWrite = db.batch();
jsonData.forEach((doc) => {
// set the train's code as the document ID
var docID = db.collection('liveTrainData').doc(doc["TrainCode"][0]);
batchWrite.set(docID, doc);
// ignore trains with longitudes or latitudes equal zero
if (!(doc["TrainLongitude"] == 0 || doc["TrainLatitude"] == 0)) {
// set the train's code as the document ID
var docID = db.collection('liveTrainData').doc(doc["TrainCode"][0]);
batchWrite.set(docID, doc);
}
});
batchWrite.commit().then(function () {
response.send("Successfully fetched and uploaded data from Irish Rail");
response.send({data: "Successfully fetched and uploaded data from Irish Rail"});
});
})
})
})
})
.catch((error) => {;
response.send("Error fetching data from the IrishRail API");
response.send({data: "Error fetching data from the IrishRail API"});
})
});
})

View File

@ -9,7 +9,8 @@
"axios": "^1.3.3",
"firebase": "^9.17.1",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0"
"firebase-functions": "^4.2.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"firebase-functions-test": "^3.0.0"
@ -6051,6 +6052,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
@ -6718,6 +6724,26 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/xml2js": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
"integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
"dependencies": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
"engines": {
"node": ">=4.0"
}
},
"node_modules/xmlcreate": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz",

View File

@ -16,7 +16,8 @@
"axios": "^1.3.3",
"firebase": "^9.17.1",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0"
"firebase-functions": "^4.2.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"firebase-functions-test": "^3.0.0"

949
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@
},
"dependencies": {
"axios": "^1.3.1",
"firebase": "^9.17.1",
"ol": "^7.2.2",
"vue": "^3.2.45",
"vue-loading-overlay": "^6.0.3",

View File

@ -44,7 +44,7 @@
import { ref } from 'vue';
import {fromLonLat, toLonLat} from 'ol/proj.js';
import app from '../api/firebase';
import { getFunctions, httpsCallable } from "firebase/functions";
import { getFunctions, httpsCallable, connectFunctionsEmulator } from "firebase/functions";
export default {
name: "MapsOverlay",
@ -77,9 +77,10 @@ export default {
},
created() {
// initial request of fata
// initial request of data
console.log("jere")
this.getLiveTrainData()
// request new data every 60 seconds
// window.setInterval(this.getLiveTrainData, 60000);
},
@ -88,8 +89,10 @@ export default {
// fetch live train data from the Firestore database
getLiveTrainData() {
const functions = getFunctions(app);
if (window.location.hostname === '127.0.0.1') {
connectFunctionsEmulator(functions, "localhost", 5001);
}
const getData = httpsCallable(functions, 'getLiveTrainData');
let loader = this.$loading.show({
loader: 'dots',
container: this.$refs.container,
@ -97,14 +100,18 @@ export default {
});
getData().then((response) => {
this.dbLiveTrainData = response.data;
// create an array of coordinates and hashmap with the key-values {index: JSON obj}
for(var i=0; i<this.dbLiveTrainData.length; i++) {
this.coordinates[i] = ref(fromLonLat([this.dbLiveTrainData[i]["TrainLongitude"][0], this.dbLiveTrainData[i]["TrainLatitude"][0]]))
this.allDataMap[i] = this.dbLiveTrainData[i];
try {
this.dbLiveTrainData = response.data;
// create an array of coordinates and hashmap with the key-values {index: JSON obj}
for(var i=0; i<this.dbLiveTrainData.length; i++) {
this.coordinates[i] = ref(fromLonLat([this.dbLiveTrainData[i]["TrainLongitude"][0], this.dbLiveTrainData[i]["TrainLatitude"][0]]))
this.allDataMap[i] = this.dbLiveTrainData[i];
}
loader.hide();
}
catch (error) {
loader.hide();
}
loader.hide();
})
},
@ -123,6 +130,9 @@ export default {
// ---------------- TESTING ----------------
postLiveTrainData() {
const functions = getFunctions(app);
if (window.location.hostname === '127.0.0.1') {
connectFunctionsEmulator(functions, "localhost", 5001);
}
const postData = httpsCallable(functions, 'postLiveTrainData');
postData().then((response) => {