From 0ae7fddab5a3159eb19abcc78783f6121066e9be Mon Sep 17 00:00:00 2001 From: Daniel <nieltansah@gmail.com> Date: Thu, 23 Nov 2017 20:54:56 +0700 Subject: [PATCH] WebApp: Modify chat_driver and order_driver --- .../src/main/webapp/WEB-INF/chat_driver.jsp | 34 +++++++++++++++---- .../src/main/webapp/WEB-INF/order_driver.jsp | 23 +++++++++++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp index f7449b1..515f8bc 100644 --- a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp +++ b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/chat_driver.jsp @@ -61,24 +61,46 @@ <%@ include file="/component/footer.html" %> +<script src="js/converse.js"></script> +<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script> <script> window.onload = toggleActive("nav-order"); </script> <script> angular.module('chatApp', []) - .controller('ChatController', function ($scope) { - $scope.chatList = []; + .service('ConverseService', converse) + .controller('ChatController', function ($scope, ConverseService) { + let account = new ConverseService.User(1) + + $scope.chatList = [] + + // Initialize Firebase. + account.initAsync() + .then(function () { + console.log('Chat service is initialized.') + }) + .catch(function (e) { + console.log(e) + }) + + account.onchat = function (msg) { + $scope.chatList.push({ + from: 'them', + text: msg + }) + $scope.$apply() + } $scope.addChat = function () { if ($scope.chatText.length !== 0) { $scope.chatList.push({ from: 'me', text: this.chatText - }); + }) } - $scope.chatText = ''; - }; - }); + $scope.chatText = '' + } + }) </script> diff --git a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/order_driver.jsp b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/order_driver.jsp index 88b192f..d7e3fa1 100644 --- a/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/order_driver.jsp +++ b/TugasBesar2_2017/WebApp/src/main/webapp/WEB-INF/order_driver.jsp @@ -3,7 +3,7 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<div ng-app= "" class="container"> +<div ng-app= "chatApp" class="container"> <div class="wrapper row"> <div> <div class="page-title row txt-center height-fit float-container"> @@ -24,9 +24,28 @@ </div> </div> +<script> + angular.module('chatApp', []) + .controller('ChatController', function ($scope, $http) { + $scope.chatList = [] + + $scope.addChat = function () { + if ($scope.chatText.length !== 0) { + $scope.chatList.push({ + from: 'me', + text: this.chatText + }) + } + + $scope.chatText = '' + } + }) +</script> + + <%@include file="/component/footer.html" %> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script> - window.onload = toggleActive("nav-order"); + window.onload = toggleActive("nav-order") </script> -- GitLab