2015-10-18 05:32:35 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var userDb = require('../core/database.js').dbs.user;
|
2015-10-18 17:48:08 +00:00
|
|
|
var getUserList = require('../core/user.js').getUserList;
|
2015-10-18 05:32:35 +00:00
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
|
|
|
|
var moment = require('moment');
|
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
/*
|
2015-10-19 03:24:13 +00:00
|
|
|
Available listFormat/focusListFormat object members:
|
|
|
|
|
|
|
|
userId : User ID
|
|
|
|
userName : User name/handle
|
|
|
|
lastLoginTs : Last login timestamp
|
|
|
|
status : Status: active | inactive
|
|
|
|
location : Location
|
|
|
|
affiliation : Affils
|
|
|
|
note : User note
|
2015-10-18 05:32:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'User List',
|
|
|
|
desc : 'Lists all system users',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = UserListModule;
|
|
|
|
|
2015-10-18 17:48:08 +00:00
|
|
|
var MciCodeIds = {
|
|
|
|
UserList : 1,
|
|
|
|
};
|
|
|
|
|
2015-10-18 05:32:35 +00:00
|
|
|
function UserListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(UserListModule, MenuModule);
|
|
|
|
|
|
|
|
UserListModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
var self = this;
|
|
|
|
var vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
|
|
|
|
2015-10-18 17:48:08 +00:00
|
|
|
var userList = [];
|
|
|
|
|
|
|
|
var USER_LIST_OPTS = {
|
|
|
|
properties : [ 'location', 'affiliation', 'last_login_timestamp' ],
|
|
|
|
};
|
|
|
|
|
2015-10-18 05:32:35 +00:00
|
|
|
async.series(
|
|
|
|
[
|
2015-10-18 17:48:08 +00:00
|
|
|
// :TODO: These two functions repeated all over -- need DRY
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
UserListModule.super_.prototype.mciReady.call(self, mciData, callback);
|
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
var loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
},
|
|
|
|
function fetchUserList(callback) {
|
|
|
|
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
|
|
|
getUserList(USER_LIST_OPTS, function got(err, ul) {
|
|
|
|
userList = ul;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function populateList(callback) {
|
|
|
|
var userListView = vc.getView(MciCodeIds.UserList);
|
2015-10-18 05:32:35 +00:00
|
|
|
|
2015-10-18 17:48:08 +00:00
|
|
|
var listFormat = self.menuConfig.config.listFormat || '{userName} - {affils}';
|
|
|
|
var focusListFormat = self.menuConfig.config.focusListFormat || listFormat; // :TODO: default changed color!
|
|
|
|
var dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DD';
|
|
|
|
|
|
|
|
function getUserFmtObj(ue) {
|
|
|
|
return {
|
|
|
|
userId : ue.userId,
|
|
|
|
userName : ue.userName,
|
|
|
|
affils : ue.affiliation,
|
2015-12-22 01:21:43 +00:00
|
|
|
location : ue.location,
|
2015-10-18 17:48:08 +00:00
|
|
|
// :TODO: the rest!
|
|
|
|
note : ue.note || '',
|
|
|
|
lastLoginTs : moment(ue.last_login_timestamp).format(dateTimeFormat),
|
2015-12-22 01:21:43 +00:00
|
|
|
};
|
2015-10-18 17:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
userListView.setItems(_.map(userList, function formatUserEntry(ue) {
|
|
|
|
return listFormat.format(getUserFmtObj(ue));
|
|
|
|
}));
|
|
|
|
|
|
|
|
userListView.setFocusItems(_.map(userList, function formatUserEntry(ue) {
|
|
|
|
return focusListFormat.format(getUserFmtObj(ue));
|
|
|
|
}));
|
|
|
|
|
|
|
|
userListView.redraw();
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
2015-10-18 05:32:35 +00:00
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.error( { error : err.toString() }, 'Error loading user list');
|
|
|
|
}
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|