Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use opentmi-addon as base class #23

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const mongoose = require('mongoose');
const moment = require('moment');
const _ = require('lodash');
const dns = require('dns');
const logger = require('./../../../tools/logger');
const eventBus = require('./../../../tools/eventBus');
const Result = mongoose.model('Result');

class DefaultGuiController {
constructor(server, io) {
constructor({server, io, logger, eventBus, mongoose}) {
this.Result = mongoose.model('Result');
this._io = io;
this._server = server;
this.logger = logger
this.visitors = {
'connected': {
count: 0,
Expand Down Expand Up @@ -51,7 +49,7 @@ class DefaultGuiController {
}
onNewVisitor(meta, data) {
this.visitors.connected.count++;
logger.info('new arrival: '+data.ip);
this.logger.info('new arrival: '+data.ip);
if (!this.visitors.connected.clients[ data.ip ]) {
this.visitors.connected.clients[ data.ip ] = {count: 0};
}
Expand Down
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const express = require('express');
const logger = require('../../tools/logger');

const {Addon} = require('opentmi-addon');
const Controller = require('./controllers');

class AddonDefaultGui {
constructor(app, server, io) {
class AddonDefaultGui extends Addon {
constructor(...args) {
// Defined variables
super(...args);
this.router = express.Router();
this.staticPath = { prefix: '/', folder: '/public/' };

// Own variables
this.app = app;
this.server = server;
this.io = io;
}

// Default implementation of register
register() {
logger.warn('registering instance of default-gui class');
this._controller = new Controller(this.server, this.io);
this.logger.warn('registering instance of default-gui class');
this._controller = new Controller({
server: this.server,
io: this.io,
logger: this.logger,
eventBus: this.eventBus,
mongoose: this.mongoose
});
this.router.get('/api/v0/gui/visitors', this._controller.getVisitors.bind(this._controller));
this.router.get('/api/v0/gui/stats/results/today', this._controller.getTodayResults.bind(this._controller));
this.io.on('connection', this._controller.ioConnection.bind(this._controller));
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
},
"devDependencies": {},
"dependencies": {
"winston": "*",
"nconf": "*",
"lodash": "*"
"lodash": "^4.17.15",
"nconf": "^0.10.0",
"moment": "^2.24.0",
"mongoose": "^5.9.4",
"express": "^4.17.1",
"opentmi-addon": "^0.2.0"
}
}