* Convert MenuModule to ES6 style class

* Convert modules that are MenuModule subclasses to ES6 style classes
* Convert mixins to ES6 style
* Various cleanup
This commit is contained in:
Bryan Ashby
2017-01-25 22:18:05 -07:00
parent 1c03c3021a
commit 99ab60bf77
26 changed files with 2214 additions and 2418 deletions

View File

@@ -18,66 +18,67 @@ exports.moduleInfo = {
packageName : 'codes.l33t.enigma.whosonline'
};
exports.getModule = WhosOnlineModule;
const MciCodeIds = {
const MciViewIds = {
OnlineList : 1,
};
function WhosOnlineModule(options) {
MenuModule.call(this, options);
}
exports.getModule = class WhosOnlineModule extends MenuModule {
constructor(options) {
super(options);
}
require('util').inherits(WhosOnlineModule, MenuModule);
WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
const self = this;
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
async.series(
[
function callParentMciReady(callback) {
return WhosOnlineModule.super_.prototype.mciReady.call(self, mciData, callback);
},
function loadFromConfig(callback) {
const loadOpts = {
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
return vc.loadFromMenuConfig(loadOpts, callback);
},
function populateList(callback) {
const onlineListView = vc.getView(MciCodeIds.OnlineList);
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
onlineListView.setItems(_.map(onlineList, oe => {
if(oe.authenticated) {
oe.timeOn = _.capitalize(oe.timeOn.humanize());
} else {
[ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
oe[m] = otherUnknown;
});
oe.userName = nonAuthUser;
}
return stringFormat(listFormat, oe);
}));
onlineListView.focusItems = onlineListView.items;
onlineListView.redraw();
return callback(null);
}
],
function complete(err) {
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if(err) {
self.client.log.error( { error : err.message }, 'Error loading who\'s online');
return cb(err);
}
return cb(err);
}
);
const self = this;
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
async.series(
[
function loadFromConfig(callback) {
const loadOpts = {
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
return vc.loadFromMenuConfig(loadOpts, callback);
},
function populateList(callback) {
const onlineListView = vc.getView(MciViewIds.OnlineList);
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
onlineListView.setItems(_.map(onlineList, oe => {
if(oe.authenticated) {
oe.timeOn = _.capitalize(oe.timeOn.humanize());
} else {
[ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
oe[m] = otherUnknown;
});
oe.userName = nonAuthUser;
}
return stringFormat(listFormat, oe);
}));
onlineListView.focusItems = onlineListView.items;
onlineListView.redraw();
return callback(null);
}
],
function complete(err) {
if(err) {
self.client.log.error( { error : err.message }, 'Error loading who\'s online');
}
return cb(err);
}
);
});
}
};