Skip to content

Commit

Permalink
Merge pull request #1 from jgrantprog1993/glitch
Browse files Browse the repository at this point in the history
๐Ÿ‘†๐ŸŒผ Updated with Glitch
  • Loading branch information
jgrantprog1993 authored Aug 18, 2021
2 parents d7fbaa4 + ff8b82e commit a99a7ac
Show file tree
Hide file tree
Showing 24 changed files with 3,431 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .gitignore
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

8 changes: 7 additions & 1 deletion README.md
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.

15 changes: 15 additions & 0 deletions controllers/about.js
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;
34 changes: 34 additions & 0 deletions controllers/dashboard.js
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;
67 changes: 67 additions & 0 deletions models/json-store.js
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;
53 changes: 53 additions & 0 deletions models/station-store.js
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;
53 changes: 53 additions & 0 deletions models/station-store.json
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
}
]

}
]
}

Loading

0 comments on commit a99a7ac

Please sign in to comment.