Skip to content

Commit d84da25

Browse files
committed
Upgrade example app aassets & add error handling
1 parent 6069b76 commit d84da25

6 files changed

Lines changed: 49 additions & 28 deletions

File tree

examples/django_example/django_example/static/css/bootstrap.css

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/django_example/django_example/static/css/bootstrap.css.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/django_example/django_example/static/js/bootstrap.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/django_example/django_example/static/js/bootstrap.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/django_example/django_example/templates/app.html

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,23 @@
1111

1212
{% include 'nav.html' %}
1313

14-
<div class="container">
14+
<div class="container mt-3 pt-3">
1515

16-
<div class="jumbotron mt-1">
17-
<h1 class="jumbotron-heading text-xs-center">Django ChatterBot Example</h1>
18-
<p class="lead text-xs-center">
16+
<div class="jumbotron mt-3">
17+
<h1 class="jumbotron-heading text-center">Django ChatterBot Example</h1>
18+
<p class="lead text-center">
1919
This is a web app that allows you to talk to ChatterBot.
2020
</p>
2121

2222
<hr class="my-2">
2323

2424
<div class="row">
25-
<div class="col-xs-6 offset-xs-3">
26-
<ul class="list-group chat-log js-chat-log">
27-
</ul>
25+
<div class="col-lg-6 offset-lg-3">
26+
<div class="list-group chat-log js-chat-log"></div>
2827

29-
<div class="input-group input-group-lg mt-1">
28+
<div class="input-group input-group-lg mt-2">
3029
<input type="text" class="form-control js-text" placeholder="Type something to begin..."/>
31-
<span class="input-group-btn">
30+
<div class="input-group-append">
3231
<button class="btn btn-primary js-say">Submit</button>
3332
</span>
3433
</div>
@@ -65,10 +64,12 @@ <h1 class="jumbotron-heading text-xs-center">Django ChatterBot Example</h1>
6564
var $sayButton = $('.js-say');
6665

6766
function createRow(text) {
68-
var $row = $('<li class="list-group-item"></li>');
67+
var $row = $('<div class="list-group-item"></div>');
6968

70-
$row.text(text);
69+
$row.html(text);
7170
$chatlog.append($row);
71+
72+
return $row;
7273
}
7374

7475
function submitInput() {
@@ -79,6 +80,20 @@ <h1 class="jumbotron-heading text-xs-center">Django ChatterBot Example</h1>
7980
// Display the user's input on the web page
8081
createRow(inputData.text);
8182

83+
// Clear the input field
84+
$input.val('');
85+
86+
// Add a loading indicator
87+
var $loadingRow = createRow(
88+
`
89+
<div class="d-flex justify-content-center">
90+
<div class="spinner-border text-success" role="status">
91+
<span class="sr-only">Loading...</span>
92+
</div>
93+
</div>
94+
`
95+
);
96+
8297
var $submit = $.ajax({
8398
type: 'POST',
8499
url: chatterbotUrl,
@@ -87,19 +102,22 @@ <h1 class="jumbotron-heading text-xs-center">Django ChatterBot Example</h1>
87102
});
88103

89104
$submit.done(function(statement) {
90-
createRow(statement.text);
91105

92-
// Clear the input field
93-
$input.val('');
106+
// RReplace the loading indicator with the bot's response
107+
$loadingRow.html('');
108+
$loadingRow.text(statement.text);
94109

95110
// Scroll to the bottom of the chat interface
96111
$chatlog[0].scrollTop = $chatlog[0].scrollHeight;
97112
});
98113

99114
$submit.fail(function(jqXHR, textStatus, errorThrown) {
100115
// Handle the error
116+
117+
$loadingRow.html('An error occurred while processing your request. Check console for details.');
118+
$loadingRow.addClass('list-group-item-danger');
119+
101120
console.error('Error:', textStatus, errorThrown);
102-
alert('An error occurred while processing your request. Check console for details.');
103121
});
104122
}
105123

examples/django_example/django_example/templates/nav.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{% load static %}
22

3-
<nav class="navbar navbar-dark bg-inverse navbar-full">
3+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
44

55
<a class="navbar-brand" href="{% url 'main' %}">
66
<img src="{% static 'img/chatterbot.png' %}" width="30" height="30" class="d-inline-block align-top" alt="ChatterBot">
77
ChatterBot
88
</a>
99

10-
<ul class="nav navbar-nav">
10+
<ul class="navbar-nav">
1111
<li class="nav-item">
1212
<a class="nav-link" href="https://docs.chatterbot.us">Documentation</a>
1313
</li>
@@ -16,7 +16,7 @@
1616
</li>
1717
</ul>
1818

19-
<ul class="nav navbar-nav float-xs-right">
19+
<ul class="navbar-nav ml-auto">
2020
<li class="nav-item">
2121
<a class="nav-link" href="{% url 'chatterbot' %}">API</a>
2222
</li>

0 commit comments

Comments
 (0)