2015-10-18 05:32:35 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
const getUserList = require('../core/user.js').getUserList;
|
|
|
|
const ViewController = require('../core/view_controller.js').ViewController;
|
2016-09-05 03:36:26 +00:00
|
|
|
const stringFormat = require('../core/string_format.js');
|
2015-10-18 05:32:35 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const moment = require('moment');
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-10-18 05:32:35 +00:00
|
|
|
|
|
|
|
/*
|
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',
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2015-10-18 17:48:08 +00:00
|
|
|
UserList : 1,
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class UserListModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
}
|
2015-10-18 17:48:08 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2015-10-18 05:32:35 +00:00
|
|
|
if(err) {
|
2017-01-26 05:18:05 +00:00
|
|
|
return cb(err);
|
2015-10-18 05:32:35 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
|
|
|
|
|
|
|
let userList = [];
|
|
|
|
|
|
|
|
const USER_LIST_OPTS = {
|
|
|
|
properties : [ 'location', 'affiliation', 'last_login_timestamp' ],
|
|
|
|
};
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
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(MciViewIds.UserList);
|
|
|
|
|
|
|
|
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,
|
|
|
|
location : ue.location,
|
|
|
|
// :TODO: the rest!
|
|
|
|
note : ue.note || '',
|
|
|
|
lastLoginTs : moment(ue.last_login_timestamp).format(dateTimeFormat),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
userListView.setItems(_.map(userList, function formatUserEntry(ue) {
|
|
|
|
return stringFormat(listFormat, getUserFmtObj(ue));
|
|
|
|
}));
|
|
|
|
|
|
|
|
userListView.setFocusItems(_.map(userList, function formatUserEntry(ue) {
|
|
|
|
return stringFormat(focusListFormat, getUserFmtObj(ue));
|
|
|
|
}));
|
|
|
|
|
|
|
|
userListView.redraw();
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.error( { error : err.toString() }, 'Error loading user list');
|
|
|
|
}
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|