From fd03bd21bc4a7b0b8a2fff2598019fbed4acec71 Mon Sep 17 00:00:00 2001 From: Joao Victor Date: Fri, 20 May 2022 12:00:28 -0300 Subject: [PATCH] improvement: chat and user-list export file name date string --- .../chat/chat-dropdown/component.jsx | 9 +++------ .../ui/components/user-list/service.js | 8 +++----- .../imports/utils/string-utils.js | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/bigbluebutton-html5/imports/ui/components/chat/chat-dropdown/component.jsx b/bigbluebutton-html5/imports/ui/components/chat/chat-dropdown/component.jsx index c0ded217d0..6593dc6325 100755 --- a/bigbluebutton-html5/imports/ui/components/chat/chat-dropdown/component.jsx +++ b/bigbluebutton-html5/imports/ui/components/chat/chat-dropdown/component.jsx @@ -4,7 +4,7 @@ import { withModalMounter } from '/imports/ui/components/common/modal/service'; import _ from 'lodash'; import BBBMenu from "/imports/ui/components/common/menu/component"; import Button from '/imports/ui/components/common/button/component'; - +import { getDateString } from '/imports/utils/string-utils'; import { alertScreenReader } from '/imports/utils/dom-utils'; import ChatService from '../service'; @@ -76,13 +76,10 @@ class ChatDropdown extends PureComponent { onClick: () => { const link = document.createElement('a'); const mimeType = 'text/plain'; - const date = new Date(); - const time = `${date.getHours()}-${date.getMinutes()}`; - const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}_${time}`; - link.setAttribute('download', `bbb-${meetingName}[public-chat]_${dateString}.txt`); + link.setAttribute('download', `bbb-${meetingName}[public-chat]_${getDateString()}.txt`); link.setAttribute( 'href', - `data: ${mimeType} ;charset=utf-8,` + `data: ${mimeType};charset=utf-8,` + `${encodeURIComponent(ChatService.exportChat(timeWindowsValues, intl))}`, ); link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })); diff --git a/bigbluebutton-html5/imports/ui/components/user-list/service.js b/bigbluebutton-html5/imports/ui/components/user-list/service.js index 8a48c3754a..f4c1734b3b 100755 --- a/bigbluebutton-html5/imports/ui/components/user-list/service.js +++ b/bigbluebutton-html5/imports/ui/components/user-list/service.js @@ -14,6 +14,7 @@ import VideoService from '/imports/ui/components/video-provider/service'; import logger from '/imports/startup/client/logger'; import WhiteboardService from '/imports/ui/components/whiteboard/service'; import { Session } from 'meteor/session'; +import { getDateString } from '/imports/utils/string-utils'; const CHAT_CONFIG = Meteor.settings.public.chat; const PUBLIC_CHAT_ID = CHAT_CONFIG.public_id; @@ -662,13 +663,10 @@ export const getUserNamesLink = (docTitle, fnSortedLabel, lnSortedLabel) => { const link = document.createElement('a'); const meeting = Meetings.findOne({ meetingId: Auth.meetingID }, { fields: { 'meetingProp.name': 1 } }); - const date = new Date(); - const time = `${date.getHours()}-${date.getMinutes()}`; - const dateString = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}_${time}`; - link.setAttribute('download', `bbb-${meeting.meetingProp.name}[users-list]_${dateString}.txt`); + link.setAttribute('download', `bbb-${meeting.meetingProp.name}[users-list]_${getDateString()}.txt`); link.setAttribute( 'href', - `data: ${mimeType} ;charset=utf-16,${encodeURIComponent(namesListsString)}`, + `data: ${mimeType};charset=utf-16,${encodeURIComponent(namesListsString)}`, ); return link; }; diff --git a/bigbluebutton-html5/imports/utils/string-utils.js b/bigbluebutton-html5/imports/utils/string-utils.js index c44a9a0a38..2484dd0923 100644 --- a/bigbluebutton-html5/imports/utils/string-utils.js +++ b/bigbluebutton-html5/imports/utils/string-utils.js @@ -1,3 +1,20 @@ export const capitalizeFirstLetter = (s = '') => s.charAt(0).toUpperCase() + s.slice(1); -export default { capitalizeFirstLetter }; \ No newline at end of file +/** + * Returns a string in the format 'Year-Month-Day_Hour-Minutes'. + * @param {Date} [date] - The Date object. + */ +export const getDateString = (date = new Date()) => { + const hours = date.getHours().toString().padStart(2, 0); + const minutes = date.getMinutes().toString().padStart(2, 0); + const month = (date.getMonth() + 1).toString().padStart(2, 0); + const dayOfMonth = date.getDate().toString().padStart(2, 0); + const time = `${hours}-${minutes}`; + const dateString = `${date.getFullYear()}-${month}-${dayOfMonth}_${time}`; + return dateString; +}; + +export default { + capitalizeFirstLetter, + getDateString, +};