Skip to content

Commit

Permalink
view.js, notifications-controller.js, translate-service.js: linting, …
Browse files Browse the repository at this point in the history
…minor cleanup, consistency
  • Loading branch information
jamesj-genesys committed Jul 12, 2024
1 parent 4b02633 commit 2658f6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
15 changes: 7 additions & 8 deletions docs/scripts/notifications-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ let subscriptionMap = {
/**
* Callback function for notications event-handling.
* It will reference the subscriptionMap to determine what function to run
* @param {Object} event
* @param {Object} event
*/
function onSocketMessage(event){
function onSocketMessage(event) {
let data = JSON.parse(event.data);

subscriptionMap[data.topicName](data);
}

Expand All @@ -31,7 +30,7 @@ export default {
* Creation of the channel. If called multiple times,
* the last one will be the active one.
*/
createChannel(){
createChannel() {
return notificationsApi.postNotificationsChannels()
.then(data => {
console.log('---- Created Notifications Channel ----');
Expand All @@ -48,14 +47,14 @@ export default {
* @param {String} topic PureCloud notification topic string
* @param {Function} callback callback function to fire when the event occurs
*/
addSubscription(topic, callback){
let body = [{'id': topic}]
addSubscription(topic, callback) {
let body = [{ id: topic }];

return notificationsApi.postNotificationsChannelSubscriptions(
channel.id, body)
.then((data) => {
.then(() => {
subscriptionMap[topic] = callback;
console.log(`Added subscription to ${topic}`);
});
}
}
};
8 changes: 4 additions & 4 deletions docs/scripts/translate-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ const languageCodeMapping = {
'ja': 'ja',
'zh-cn': 'zh',
'zh-tw': 'zh-TW'
}
};

export default {
translateText(text, language, callback){
translateText(text, language, callback) {
let language_code = languageCodeMapping[language] ?
languageCodeMapping[language] : language;

let data = {
raw_text: text,
source_language: 'auto',
target_language: language_code
}
};

fetch(config.translateServiceURI,
{
Expand All @@ -50,4 +50,4 @@ export default {
})
.catch(e => console.error(e));
}
}
};
76 changes: 38 additions & 38 deletions docs/scripts/view.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/**
* This script is focused on the HTML / displaying of data to the page
*/
function updateScroll(){
function updateScroll() {
let div = document.getElementById('agent-assist');
div.scrollTop = div.scrollHeight;
}

/**
* Clear DIV of previous search results
*/
function clearSearchResults(){
let searchContainer = document.getElementById("search-result-container");
function clearSearchResults() {
let searchContainer = document.getElementById('search-result-container');

while (searchContainer.childNodes.length > 1) {
while(searchContainer.childNodes.length > 1) {
searchContainer.removeChild(searchContainer.lastChild);
}
}

/**
* Convert the html content of the canned response to plain text
*/
function htmlToPlain(rawHtml){
function htmlToPlain(rawHtml) {
let finalText = rawHtml;
finalText = finalText.replace(/<\/div>/ig, '\n');
finalText = finalText.replace(/<\/li>/ig, '\n');
finalText = finalText.replace(/<li>/ig, ' * ');
finalText = finalText.replace(/<\/ul>/ig, '\n');
finalText = finalText.replace(/<\/p>/ig, '\n');
finalText = finalText.replace(/<br\s*[\/]?>/gi, "\n");
finalText = finalText.replace(/<br\s*[/]?>/gi, '\n');
finalText = finalText.replace(/<[^>]+>/ig, '');

return finalText;
Expand All @@ -39,7 +39,7 @@ export default {
* @param {String} sender sender name to be displayed
* @param {String} message chat message to be displayed
*/
addChatMessage(sender, message, purpose){
addChatMessage(sender, message, purpose) {
let chatMsg = document.createElement('p');
chatMsg.textContent = sender + ': ' + message;

Expand All @@ -53,22 +53,22 @@ export default {

/**
* Display list of libraries
* @param {String} libraryId
* @param {String} libraryName
* @param {String} libraryId
* @param {String} libraryName
*/
displayLibraries(libraryId, libraryName){
displayLibraries(libraryId, libraryName) {
let libContainer = document.createElement('button');
libContainer.textContent = libraryName;
libContainer.id = 'library-' + libraryId;
libContainer.className = 'collapsible';
libContainer.addEventListener('click', function() {
this.classList.toggle('active');
let content = this.nextElementSibling;
if (content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
let content = this.nextElementSibling;
if(content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
});
document.getElementById('libraries-container').appendChild(libContainer);

Expand All @@ -80,9 +80,9 @@ export default {

/**
* Display responses and group by libraries
* @param {Object} response
* @param {Object} response
*/
displayResponses(response, doResponseSubstitution){
displayResponses(response, doResponseSubstitution) {
let responseId = response.id;

// Collapsible response name
Expand All @@ -92,12 +92,12 @@ export default {
responseButton.className = 'collapsible';
responseButton.addEventListener('click', function() {
this.classList.toggle('active');
let content = this.nextElementSibling;
if (content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
let content = this.nextElementSibling;
if(content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
});
document.getElementById('responses-container-' + response.libraries[0].id).appendChild(responseButton);

Expand All @@ -109,7 +109,7 @@ export default {
responseText.addEventListener('click', function() {
let text = htmlToPlain(response.texts[0].content);
doResponseSubstitution(text, responseId)
.then((finalText) => {
.then(finalText => {
document.getElementById('message-textarea').value = finalText;
})
.catch(e => console.error(e));
Expand All @@ -119,9 +119,9 @@ export default {

/**
* Displays all search results in a DIV
* @param {object} results
* @param {object} results
*/
displaySearchResults(results, doResponseSubstitution){
displaySearchResults(results, doResponseSubstitution) {
let responseId = results.id;

// Collapsible response name
Expand All @@ -131,12 +131,12 @@ export default {
responseButton.className = 'collapsible';
responseButton.addEventListener('click', function() {
this.classList.toggle('active');
let content = this.nextElementSibling;
if (content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
let content = this.nextElementSibling;
if(content.style.display === 'block') {
content.style.display = 'none';
} else {
content.style.display = 'block';
}
});
document.getElementById('search-result-container').appendChild(responseButton);

Expand All @@ -148,7 +148,7 @@ export default {
responseText.addEventListener('click', function() {
let text = htmlToPlain(results.texts[0].content);
doResponseSubstitution(text, responseId)
.then((finalText) => {
.then(finalText => {
document.getElementById('message-textarea').value = finalText;
})
.catch(e => console.error(e));
Expand All @@ -159,11 +159,11 @@ export default {
/**
* This toggles between showing Canned Responses or Search Results
*/
toggleDIVs(){
toggleDIVs() {
let cannedDIV = document.getElementById('libraries-container');
let searchDIV = document.getElementById('search-result-container');

if(cannedDIV.style.display === 'block'){
if(cannedDIV.style.display === 'block') {
cannedDIV.style.display = 'none';
searchDIV.style.display = 'block';
} else {
Expand All @@ -172,7 +172,7 @@ export default {
}

// Clear DIV of previous search results
let searchContainer = document.getElementById("search-result-container");
let searchContainer = document.getElementById('search-result-container');
if(searchContainer.children.length > 1) clearSearchResults();
}
}
};

0 comments on commit 2658f6d

Please sign in to comment.