-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jgrantprog1993/glitch
๐๐ผ Updated with Glitch
- Loading branch information
Showing
24 changed files
with
3,431 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
.idea | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# WeatherTop_v2 | ||
Welcome to the Glitch Template | ||
============================== | ||
|
||
A starter project for learning Glitch. | ||
|
||
This is an Express.js project, designed to work well with the Glitch development environment. It includes basic express setup, templating, routing, JSON based model and session support. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
const logger = require("../utils/logger"); | ||
|
||
const about = { | ||
index(request, response) { | ||
logger.info("about rendering"); | ||
const viewData = { | ||
title: "About WeatherTop v2", | ||
}; | ||
response.render("about", viewData); | ||
}, | ||
}; | ||
|
||
module.exports = about; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
|
||
const logger = require("../utils/logger"); | ||
const stationStore = require('../models/station-store'); | ||
const readingComp = require('../utils/reading-Comp'); | ||
|
||
const dashboard = { | ||
index(request, response) { | ||
|
||
logger.info('dashboard rendering'); | ||
const stations = stationStore.getAllStations(); | ||
|
||
for (let i=0; i<stations.length; i++) | ||
{ | ||
let station = stations[i]; | ||
if (station.readings.length > 0) | ||
{ | ||
readingComp.getReadingComp(station); | ||
} | ||
} | ||
|
||
const viewData = | ||
{ | ||
title: 'Station Dashboard', | ||
stations: stationStore.getAllStations(), | ||
}; | ||
|
||
// logger.info('about to render', stationStore.getAllStations()); | ||
response.render('dashboard', viewData); | ||
}, | ||
|
||
}; | ||
|
||
module.exports = dashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use strict"; | ||
|
||
const low = require("lowdb"); | ||
const FileSync = require("lowdb/adapters/FileSync"); | ||
|
||
class JsonStore { | ||
constructor(file, defaults) { | ||
const adapter = new FileSync(file); | ||
this.db = low(adapter); | ||
this.db.defaults(defaults).value(); | ||
} | ||
|
||
save() { | ||
this.db.write(); | ||
} | ||
|
||
add(collection, obj) { | ||
this.db | ||
.get(collection) | ||
.push(obj) | ||
.last() | ||
.value(); | ||
} | ||
|
||
remove(collection, obj) { | ||
this.db | ||
.get(collection) | ||
.remove(obj) | ||
.value(); | ||
} | ||
|
||
removeAll(collection) { | ||
this.db | ||
.get(collection) | ||
.remove() | ||
.value(); | ||
} | ||
|
||
findAll(collection) { | ||
return this.db.get(collection).value(); | ||
} | ||
|
||
findOneBy(collection, filter) { | ||
const results = this.db | ||
.get(collection) | ||
.filter(filter) | ||
.value(); | ||
return results[0]; | ||
} | ||
|
||
findByIds(collection, ids) { | ||
return this.db | ||
.get(collection) | ||
.keyBy("id") | ||
.at(ids) | ||
.value(); | ||
} | ||
|
||
findBy(collection, filter) { | ||
return this.db | ||
.get(collection) | ||
.filter(filter) | ||
.value(); | ||
} | ||
} | ||
|
||
module.exports = JsonStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const JsonStore = require('./json-store'); | ||
|
||
const stationStore = { | ||
|
||
store: new JsonStore('./models/station-store.json', { stationCollection: [] }), | ||
collection: 'stationCollection', | ||
|
||
getAllStations() { | ||
return this.store.findAll(this.collection); | ||
}, | ||
|
||
getStation(id) { | ||
return this.store.findOneBy(this.collection, { id: id }); | ||
}, | ||
|
||
addStation(station) { | ||
this.store.add(this.collection, station); | ||
this.store.save(); | ||
}, | ||
|
||
removeStation(id) { | ||
const station = this.getStation(id); | ||
this.store.remove(this.collection, station); | ||
this.store.save(); | ||
}, | ||
|
||
removeAllStations() { | ||
this.store.removeAll(this.collection); | ||
this.store.save(); | ||
}, | ||
|
||
addReading(id, reading) { | ||
const station = this.getStation(id); | ||
station.readings.push(reading); | ||
this.store.save(); | ||
}, | ||
|
||
removeReading(id, readingId) { | ||
const station = this.getStation(id); | ||
const readings = station.readings; | ||
_.remove(readings, { id: readingId}); | ||
this.store.save(); | ||
}, | ||
|
||
getUserStations(userid) { | ||
return this.store.findBy(this.collection, { userid: userid }); | ||
}, | ||
}; | ||
|
||
module.exports = stationStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"stationCollection": [ | ||
{ | ||
"ID": "01", | ||
"name": "Tramore", | ||
"readings": [ | ||
{ | ||
"id": "02", | ||
"code": "800", | ||
"temperature": 0.5, | ||
"windSpeed": 2, | ||
"pressure": 1002 | ||
}, | ||
{ | ||
"id": "03", | ||
"code": "600", | ||
"temperature": 6, | ||
"windSpeed": 2, | ||
"pressure": 1004 | ||
}, | ||
{ | ||
"id": "04", | ||
"code": "700", | ||
"temperature": 8, | ||
"windSpeed": 4, | ||
"pressure": 1004 | ||
} | ||
] | ||
}, | ||
{ | ||
"ID": "05", | ||
"name": "Dunmore", | ||
"readings": [ | ||
{ | ||
"id": "06", | ||
"code": "700", | ||
"temperature": 8, | ||
"windSpeed": 1, | ||
"pressure": 999 | ||
}, | ||
{ | ||
"id": "07", | ||
"code": "200", | ||
"temperature": 0.5, | ||
"windSpeed": 3.5, | ||
"pressure": 1000 | ||
} | ||
] | ||
|
||
} | ||
] | ||
} | ||
|
Oops, something went wrong.