Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
fix(build): Update linter and contributing file (#25)
Browse files Browse the repository at this point in the history
* Updated to be inline with other demos

* Removed eslint errors

* Removed eslint errors

* Fixed link in readme
  • Loading branch information
richieverma authored and germanattanasio committed May 17, 2018
1 parent 875151a commit 7d4fcc2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 73 deletions.
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Questions

If you are having difficulties running the app or have a question about the service, please ask a question on [dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson) or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).

# Issues

If you encounter an issue with this sample app, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible somebody has encountered this issue already.


# Pull Requests

If you want to contribute to the repository, here's a quick guide:

1. Fork the repo
1. Develop your code changes
1. Ensure `eslint` is happy: `npm run lint`
1. Ensure the tests pass: `npm test`
1. Commit your changes
1. Push to your fork and submit a pull request
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests
var watson = require('watson-developer-cloud');

var toneDetection = require('./addons/tone_detection.js'); // required for tone
// detection
var toneDetection = require('./addons/tone_detection.js'); // required for tone detection
var maintainToneHistory = false;

// The following requires are needed for logging purposes
Expand Down
2 changes: 1 addition & 1 deletion casper-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require('dotenv').config({silent: true});

if (!fs.existsSync('./.env')) {
console.log('Skip integration tests since .env does not exist');
return
return;
}

var server = require('./server');
Expand Down
10 changes: 5 additions & 5 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ div {
line-height: 1.25rem;
}

.disclaimer-message .base-h6 {
padding: 5px;
}

#view-change-button {
display: inline-block;
position: absolute;
Expand Down Expand Up @@ -44,7 +48,7 @@ div {
}

#contentParent {
height: 100%;
height: 92%;
}

.responsive-columns-wrapper {
Expand Down Expand Up @@ -429,7 +433,3 @@ html{
font-weight: normal;
font-style: normal;
}

.gdprDescription {
font-size: 14px;
}
13 changes: 8 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
<div id="contentParent" class="responsive-columns-wrapper">
<div id="chat-column-holder"
class="responsive-column content-column">
<div class="gdprDescription">
*This system is for demonstration purposes only and is not intended to process Personal Data.
No Personal Data is to be entered into this system as it may not have the necessary controls
in place to meet the requirements of the General Data Protection Regulation (EU) 2016/679.
</div>
<div class="chat-column">
<label class="appDescription">This is a simple
conversation to demonstrate how a user's emotional tone can be
Expand All @@ -50,6 +45,14 @@
</div>
</div>

<div class="disclaimer-message">
<h6 class="base-h6">
* This system is for demonstration purposes only and is not intended to process Personal Data. No Personal Data is to be entered
into this system as it may not have the necessary controls in place to meet the requirements of the General Data Protection
Regulation (EU) 2016/679.
</h6>
</div>

<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
23 changes: 11 additions & 12 deletions public/js/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var ConversationPanel = (function() {
/**
* getMealType determines what meal a user of the app might have eaten most
* recently. It uses the client's browser time.
*
*
* @returns {string} a string indicating the meal the user most likely ate
* recently - breakfast, lunch, dinner
*/
Expand Down Expand Up @@ -110,17 +110,17 @@ var ConversationPanel = (function() {
input.classList.add('underline');
var txtNode = document.createTextNode(input.value);
[ 'font-size', 'font-style', 'font-weight', 'font-family',
'line-height', 'text-transform', 'letter-spacing' ]
.forEach(function(index) {
dummy.style[index] = window.getComputedStyle(input, null)
.getPropertyValue(index);
});
'line-height', 'text-transform', 'letter-spacing' ]
.forEach(function(index) {
dummy.style[index] = window.getComputedStyle(input, null)
.getPropertyValue(index);
});
dummy.textContent = txtNode.textContent;

var padding = 0;
var htmlElem = document.getElementsByTagName('html')[0];
var currentFontSize = parseInt(window.getComputedStyle(htmlElem, null)
.getPropertyValue('font-size'), 10);
.getPropertyValue('font-size'), 10);
if (currentFontSize) {
padding = Math.floor((currentFontSize - minFontSize)
/ (maxFontSize - minFontSize) * (maxPadding - minPadding)
Expand Down Expand Up @@ -154,9 +154,8 @@ var ConversationPanel = (function() {
var messageDivs = buildMessageDomElements(newPayload, isUser);
var chatBoxElement = document.querySelector(settings.selectors.chatBox);
var previousLatest = chatBoxElement
.querySelectorAll((isUser ? settings.selectors.fromUser
: settings.selectors.fromWatson)
+ settings.selectors.latest);
.querySelectorAll((isUser ? settings.selectors.fromUser
: settings.selectors.fromWatson) + settings.selectors.latest);
// Previous "latest" message is no longer the most recent
if (previousLatest) {
Common.listForEach(previousLatest, function(element) {
Expand Down Expand Up @@ -195,7 +194,7 @@ var ConversationPanel = (function() {
// Constructs new DOM element from a message payload
function buildMessageDomElements(newPayload, isUser) {
var textArray = isUser ? newPayload.input.text : newPayload.output.text;
emotionClass = 'top';
var emotionClass = 'top';

if (Object.prototype.toString.call(textArray) !== '[object Array]') {
textArray = [ textArray ];
Expand All @@ -213,7 +212,7 @@ var ConversationPanel = (function() {
'tagName': 'div',
// AW - change colour of watson tag
'classNames': [ (isUser ? 'from-user' : 'from-watson'), 'latest',
((messageArray.length === 0) ? emotionClass : 'sub') ],
((messageArray.length === 0) ? emotionClass : 'sub') ],
'children': [ {
// <div class='message-inner'>
'tagName': 'div',
Expand Down
96 changes: 48 additions & 48 deletions public/js/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var PayloadPanel = (function() {
// full width (regardless of screen size)
function togglePanel(event, element) {
var payloadColumn = document
.querySelector(settings.selectors.payloadColumn);
.querySelector(settings.selectors.payloadColumn);
if (element.classList.contains('full')) {
element.classList.remove('full');
payloadColumn.classList.remove('full');
Expand Down Expand Up @@ -68,8 +68,8 @@ var PayloadPanel = (function() {
// Create new payload DOM element
var payloadDiv = buildPayloadDomElement(isRequest);
var payloadElement = document
.querySelector(isRequest ? settings.selectors.payloadRequest
: settings.selectors.payloadResponse);
.querySelector(isRequest ? settings.selectors.payloadRequest
: settings.selectors.payloadResponse);
// Clear out payload holder element
while (payloadElement.lastChild) {
payloadElement.removeChild(payloadElement.lastChild);
Expand All @@ -80,7 +80,7 @@ var PayloadPanel = (function() {
// exist)
// or to hide (otherwise)
var payloadInitial = document
.querySelector(settings.selectors.payloadInitial);
.querySelector(settings.selectors.payloadInitial);
if (Api.getRequestPayload() || Api.getResponsePayload()) {
payloadInitial.classList.add('hide');
}
Expand All @@ -103,36 +103,36 @@ var PayloadPanel = (function() {
// Constructs new DOM element to use in displaying the payload
function buildPayloadDomElement(isRequest) {
var payloadPrettyString = jsonPrettyPrint(isRequest ? Api
.getRequestPayload() : Api.getResponsePayload());
.getRequestPayload() : Api.getResponsePayload());

var payloadJson = {
'tagName': 'div',
'children': [
{
// <div class='header-text'>
'tagName': 'div',
'text': isRequest ? 'User input (request payload)'
: 'Response from Watson Conversation (response payload)',
'classNames': [ 'header-text' ]
},
{
// <div class='code-line responsive-columns-wrapper'>
'tagName': 'div',
'classNames': [ 'code-line', 'responsive-columns-wrapper' ],
'children': [
{
// <div class='line-numbers'>
'tagName': 'pre',
'text': createLineNumberString((payloadPrettyString
.match(/\n/g) || []).length + 1),
'classNames': [ 'line-numbers' ]
}, {
// <div class='payload-text responsive-column'>
'tagName': 'pre',
'classNames': [ 'payload-text', 'responsive-column' ],
'html': payloadPrettyString
} ]
} ]
{
// <div class='header-text'>
'tagName': 'div',
'text': isRequest ? 'User input (request payload)'
: 'Response from Watson Conversation (response payload)',
'classNames': [ 'header-text' ]
},
{
// <div class='code-line responsive-columns-wrapper'>
'tagName': 'div',
'classNames': [ 'code-line', 'responsive-columns-wrapper' ],
'children': [
{
// <div class='line-numbers'>
'tagName': 'pre',
'text': createLineNumberString((payloadPrettyString
.match(/\n/g) || []).length + 1),
'classNames': [ 'line-numbers' ]
}, {
// <div class='payload-text responsive-column'>
'tagName': 'pre',
'classNames': [ 'payload-text', 'responsive-column' ],
'html': payloadPrettyString
} ]
} ]
};

return Common.buildDomElement(payloadJson);
Expand All @@ -146,25 +146,25 @@ var PayloadPanel = (function() {
var convert = JSON.stringify(json, null, 2);

convert = convert.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(
/>/g, '&gt;');
/>/g, '&gt;');
convert = convert
.replace(
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
function(match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
.replace(
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, // eslint-disable-line no-useless-escape
function(match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
return convert;
}

Expand Down

0 comments on commit 7d4fcc2

Please sign in to comment.