add lists sorted by first and last name to saved user names

This commit is contained in:
KDSBrowne 2020-08-29 02:17:04 +00:00
parent 1b2d0f9f15
commit e4000110bb

View File

@ -486,17 +486,59 @@ const requestUserInformation = (userId) => {
makeCall('requestUserInformation', userId); makeCall('requestUserInformation', userId);
}; };
export const getUserNamesLink = () => { const sortUsersByFirstName = (a, b) => {
const aName = a.firstName.toLowerCase();
const bName = b.firstName.toLowerCase();
if (aName < bName) return -1;
if (aName > bName) return 1;
return 0;
};
const sortUsersByLastName = (a, b) => {
if (a.lastName && !b.lastName) return -1;
if (!a.lastName && b.lastName) return 1;
const aName = a.lastName.toLowerCase();
const bName = b.lastName.toLowerCase();
if (aName < bName) return -1;
if (aName > bName) return 1;
return 0;
};
export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel) => {
const mimeType = 'text/plain'; const mimeType = 'text/plain';
const userNamesObj = getUsers(); const userNamesObj = getUsers()
const userNameListString = userNamesObj .map((u) => {
.map(u => u.name) const name = u.sortName.split(' ');
.join('\r\n'); return ({
firstName: name[0],
middleNames: name.length > 2 ? name.slice(1, name.length - 1) : null,
lastName: name.length > 1 ? name[name.length - 1] : null,
});
});
const getUsernameString = (user) => {
const { firstName, middleNames, lastName } = user;
return `${firstName || ''} ${middleNames && middleNames.length > 0 ? middleNames.join(' ') : ''} ${lastName || ''}`;
};
const namesByFirstName = userNamesObj.sort(sortUsersByFirstName)
.map(u => getUsernameString(u)).join('\r\n');
const namesByLastName = userNamesObj.sort(sortUsersByLastName)
.map(u => getUsernameString(u)).join('\r\n');
const namesListsString = `List of users in meeting XXX at Date:time
\r\n\r\nSorted by first name:\r\n${namesByFirstName}
\r\n\r\nSorted by last name:\r\n${namesByLastName}`
.replace(/ {2}/g, ' ');
const link = document.createElement('a'); const link = document.createElement('a');
link.setAttribute('download', `save-users-list-${Date.now()}.txt`); link.setAttribute('download', `save-users-list-${Date.now()}.txt`);
link.setAttribute( link.setAttribute(
'href', 'href',
`data: ${mimeType} ;charset=utf-16,${encodeURIComponent(userNameListString)}`, `data: ${mimeType} ;charset=utf-16,${encodeURIComponent(namesListsString)}`,
); );
return link; return link;
}; };