Newer
Older
<%@ page import="utility.CookieChecker" %>
<%@ page import="utility.CookiesMap" %>
<%@ page import="java.util.Map" %><%--
Created by IntelliJ IDEA.
User: fajar
Date: 23/11/17
Time: 0:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
if (!CookieChecker.check(request.getCookies())) {
response.sendRedirect("index.jsp");
}
Map<String, String> cook = CookiesMap.getCookiesMap(request.getCookies());
%>
<html ng-app="app">
<head>
<title>Find Order</title>
<link rel="stylesheet" href="css/master.css">
<link rel="icon" href="img/gojek.png">
<script src="js/master.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/chatfordriver.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script>
<script>
</script>
<div class="order">
<%@ include file = "navbar.jsp" %>
<script type="text/javascript">chooseNavbar(0);</script>
<h1>LOOKING FOR AN ORDER</h1>
<br/><br/><br/><br/>
<div class="btn-wrapper" ng-hide="find">
<button class="green-button" data-ng-click="findOrder();">FIND ORDER</button>
</div>
<div class="btn-wrapper" ng-show="cancelFind">
<h5>Finding Order....</h5>
<br>
<br>
<button class="red-button" data-ng-click="cancelFindOrder();">CANCEL</button>
</div>
<div ng-show="chat" >
<div class="chat-box" >
<div ng-repeat="msg in msgs" class="{{msg.pos}}">
{{msg.text}}
</div>
</div>
<div class="chat-form">
<form class="" id="chat-text-input">
<input type="text" class="chat-input" ng-model="cht" name="chatmessage" placeholder="message"/>
<button type="submit" class="green-button" data-ng-click="submit(cht); cht = '';" name="send">SEND</button>
</form>
</div>
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<script>
var app = angular.module("app", []);
app.controller("maincontrol", ($scope, $http, $window) => {
$scope.msgs = [];
$scope.find = false;
$scope.cancelFind = false;
$scope.chat = false;
$scope.custId = null;
$scope.userId = <%=cook.get("id")%>;
$http.get("http://localhost:3000/driver/available").then((response) => {
console.log(response);
if (response.data.data.indexOf($scope.userId) != -1) {
enableChat();
$scope.find = true;
$scope.cancelFind = true;
}
}).catch((err) => {
console.log(err);
});
$scope.submit = (cht) =>{
if (cht.length != 0) {
var config = {
headers: {
'Content-Type': 'application/json'
}
}
var body = {
customer: $scope.custId,
driver: $scope.userId,
chat: {
sender: $scope.userId,
title : "pesan",
message: cht
}
}
$http.post('http://localhost:3000/chat/send', body, config)
.then((success) => {
$scope.msgs.push({pos: "bubble-right", text: cht});
})
.catch((err) => {
console.log(err);
});
}
}
$scope.findOrder = () => {
var config = {
headers : {
"Content-Type" : "application/json"
}
}
var body = {
userId : $scope.userId
}
$http.post("http://localhost:3000/driver/available", body, config).then((res) => {
if (res.data.status == 200){
enableChat();
$scope.find = true;
$scope.cancelFind = true;
} else {
console.log("cant add to available driver");
}
})
.catch((err) => {
console.log(err);
})
}
$scope.inOrder = () => {
$scope.chat =
$http.get('http://localhost:3000/chat?customer='+$scope.custId+'&driver='+$scope.userId).then( (res) => {
for(var i = 0;i < res.data.content.length;i++){
if (res.data.content[i].sender == res.data.customer) {
$scope.msgs.push({pos: "bubble-right", msg: res.data.content[i].message});
} else {
$scope.msgs.push({pos: "bubble-left", msg: res.data.content[i].message});
}
}
}, (err) =>{
console.error(err);
});
}
$scope.cancelFindOrder = () => {
var config = {
headers :{
"Content-Type" : "application/json"
}
}
var body = {
"userId" : $scope.userId
}
$http.post("http://localhost:3000/driver/delete", body, config).then((res) => {
console.log(res);
if (res.data.status == 200) {
$scope.find = false;
$scope.cancelFind = false;
} else {
alert("error");
}
})
}
$scope.sendTokenToServer = (utoken) => {
var config = {
headers : {
"Content-Type" : "application/json"
}
}
var body ={
userId : parseInt($scope.userId),
token : utoken
}
$http.post("http://localhost:3000/user/save", body, config).then((response) => {
if (response.status == 200){
console.log("Send Token Success");
} else {
console.log("Send Token Error");
}
}, (err) => {
console.log(err);
})
}
$scope.insertMsg = (payload) => {
$scope.msgs.push({pos : "bubble-left", text : payload.notification.body});
console.log("HEHEH");
}
})
</script>