diff --git a/ChatService/app/models/driver.js b/ChatService/app/models/driver.js index 96dee7b83d72487fc70c4441b714b6098be24b55..6e4e70d86317acfa48c92c39a76262abfb5d5d3b 100644 --- a/ChatService/app/models/driver.js +++ b/ChatService/app/models/driver.js @@ -3,9 +3,7 @@ var mongoose = require("mongoose"); var driverSchema = new mongoose.Schema({ idDriver : Number, status: String, - pref: [{ - type: String - }] + pref: [] }); module.exports = mongoose.model("Driver", driverSchema); \ No newline at end of file diff --git a/ChatService/app/routes.js b/ChatService/app/routes.js index eadf841d36f5a78b0bc25543a5578f169e936016..8eb5ef61351ac561c71d57ae9c1b9433066a899e 100644 --- a/ChatService/app/routes.js +++ b/ChatService/app/routes.js @@ -11,6 +11,9 @@ module.exports = function(app) { var fs = require('fs'); function sendMessages(to, title, message) { + console.log(to); + console.log(title); + console.log(message); // Build the post string from an object var post_data = JSON.stringify({ "notification": { @@ -84,6 +87,7 @@ module.exports = function(app) { // driver want to find order app.post('/findorder', function(req, res){ + console.log(req); Driver.findOne({"idDriver" : req.body.id}, function(err, foundDriver){ if (err){ var response = {"status" : 503, "message" : "Database error detected"}; @@ -99,6 +103,7 @@ module.exports = function(app) { }); } else { foundDriver["status"] = "available"; + foundDriver["pref"] = req.body.pref; foundDriver.save(); var response = {"status" : 200, "message" : "Driver status has changed to available"}; res.json(response); @@ -131,17 +136,18 @@ module.exports = function(app) { // user select certain driver app.post('/selectdriver', function(req, res){ + console.log(req.body); Driver.findOne({"idDriver" : req.body.id, "status" : "available"}, function(err, foundDriver){ if (!err && foundDriver){ FcmToken.findOne({"id" : req.body.id}, function(err1, tokenDriver){ if (!err1 && tokenDriver) { foundDriver["status"] = "acceptorder"; foundDriver.save(); + sendMessages(tokenDriver.token, "order", req.body.from); var response = {"status" : 200, "message" : "Driver has accepted an order"}; - sendMessages(tokenDriver.token, "order", "you get an order"); res.json(response); }else{ - var response = {"status" : 503, "message" : "Database error detected"}; + var response = {"status" : 503, "message" : "Database error detected null"}; res.json(response); } }); @@ -157,6 +163,7 @@ module.exports = function(app) { app.post('/finishorder', function(req, res){ Driver.findOne({"idDriver" : req.body.id, "status" : "acceptorder"}, function(err, foundDriver){ if (!err && foundDriver){ + sendMessages(foundDriver.token, "finish","_____FINISH_____") foundDriver.remove(); var response = {"status" : 200, "message" : "Driver has finished the order"}; res.json(response); @@ -229,9 +236,28 @@ module.exports = function(app) { var idDriver = Number (req.query.idDriver); Chat.findOne({"idUser" : idUser, "idDriver" : idDriver}, function(err, chat){ if(err){ + console.log(err); res.json({"error" : "yes"}); } else { - res.json(chat.history); + if (!chat){ + Chat.create({"idUser" : idUser, "idDriver" : idDriver, "history": []}, function(err, newChat){ + if(err){ + console.log(err); + res.json([]); + } + else { + res.json([]); + } + }); + } else{ + console.log(chat); + if (chat){ + res.json(chat.history); + } else { + res.json([]); + } + + } } }); }); @@ -260,7 +286,7 @@ module.exports = function(app) { } else { if (!chat){ - Chat.create({'idUser' : senderId.id, 'idDriver' : receiverId}, function(err4, newChat){ + Chat.create({'idUser' : senderId.id, 'idDriver' : receiverId, 'history': []}, function(err4, newChat){ if (err4){ var response = {"status" : 503, "message" : "Database error detected 4"}; res.json(response); @@ -315,7 +341,7 @@ module.exports = function(app) { } else { if (!chat){ - Chat.create({'idUser' : receiverId, 'idDriver' : senderId.id}, function(err4, newChat){ + Chat.create({'idUser' : receiverId, 'idDriver' : senderId.id, 'history': []}, function(err4, newChat){ if (err4){ var response = {"status" : 503, "message" : "Database error detected 4"}; res.json(response); diff --git a/ChatService/public/.firebaserc b/ChatService/public/.firebaserc deleted file mode 100644 index 1ac6bc9d80d3e4c6237423fd68f641a43bdea14d..0000000000000000000000000000000000000000 --- a/ChatService/public/.firebaserc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "projects": { - "kia": "chatservice-kia" - } -} \ No newline at end of file diff --git a/ChatService/public/.gitignore b/ChatService/public/.gitignore deleted file mode 100644 index 273c1665e010a0d82a052ecac6739cf044ce857c..0000000000000000000000000000000000000000 --- a/ChatService/public/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.firebaserc \ No newline at end of file diff --git a/ChatService/public/README.md b/ChatService/public/README.md deleted file mode 100644 index b3fe28deca62148291b5b3b3e35bce47c6468960..0000000000000000000000000000000000000000 --- a/ChatService/public/README.md +++ /dev/null @@ -1,102 +0,0 @@ -Firebase Cloud Messaging Quickstart -=================================== - -The Firebase Cloud Messaging quickstart demonstrates how to: -- Request permission to send app notifications to the user. -- Receive FCM messages using the Firebase Cloud Messaging JavaScript SDK. - -Introduction ------------- - -[Read more about Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) - -Getting Started ---------------- - -1. Create your project on the [Firebase Console](https://console.firebase.google.com). -1. You must have the [Firebase CLI](https://firebase.google.com/docs/cli/) installed. If you don't have it install it with `npm install -g firebase-tools` and then configure it with `firebase login`. -1. On the command line run `firebase use --add` and select the Firebase project you have created. -1. On the command line run `firebase serve -p 8081` using the Firebase CLI tool to launch a local server. -1. Open [http://localhost:8081](http://localhost:8081) in your browser. -4. Click **REQUEST PERMISSION** button to request permission for the app to send notifications to the browser. -5. Use the generated Instance ID token (IID Token) to send an HTTP request to FCM that delivers the message to the web application, inserting appropriate values for [`YOUR-SERVER-KEY`](https://console.firebase.google.com/project/_/settings/cloudmessaging) and `YOUR-IID-TOKEN`. - -### HTTP -``` -POST /fcm/send HTTP/1.1 -Host: fcm.googleapis.com -Authorization: key=YOUR-SERVER-KEY -Content-Type: application/json - -{ - "notification": { - "title": "Portugal vs. Denmark", - "body": "5 to 1", - "icon": "firebase-logo.png", - "click_action": "http://localhost:8081" - }, - "to": "YOUR-IID-TOKEN" -} -``` - -### Fetch -```js -var key = 'YOUR-SERVER-KEY'; -var to = 'YOUR-IID-TOKEN'; -var notification = { - 'title': 'Portugal vs. Denmark', - 'body': '5 to 1', - 'icon': 'firebase-logo.png', - 'click_action': 'http://localhost:8081' -}; - -fetch('https://fcm.googleapis.com/fcm/send', { - 'method': 'POST', - 'headers': { - 'Authorization': 'key=' + key, - 'Content-Type': 'application/json' - }, - 'body': JSON.stringify({ - 'notification': notification, - 'to': to - }) -}).then(function(response) { - console.log(response); -}).catch(function(error) { - console.error(error); -}) -``` - -### cURL -``` -curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{ - "notification": { - "title": "Portugal vs. Denmark", - "body": "5 to 1", - "icon": "firebase-logo.png", - "click_action": "http://localhost:8081" - }, - "to": "YOUR-IID-TOKEN" -}' "https://fcm.googleapis.com/fcm/send" -``` - -### App focus -When the app has the browser focus, the received message is handled through -the `onMessage` callback in `index.html`. When the app does not have browser -focus then the `setBackgroundMessageHandler` callback in `firebase-messaging-sw.js` -is where the received message is handled. - -The browser gives your app focus when both: - -1. Your app is running in the currently selected browser tab. -2. The browser tab's window currently has focus, as defined by the operating system. - -Support -------- - -https://firebase.google.com/support/ - -License -------- - -© Google, 2016. Licensed under an [Apache-2](../LICENSE) license. diff --git a/ChatService/public/chat.html b/ChatService/public/chat.html deleted file mode 100644 index fd7fdb8c47b095f62329d2593fe2e57d546eee30..0000000000000000000000000000000000000000 --- a/ChatService/public/chat.html +++ /dev/null @@ -1,52 +0,0 @@ -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> -<link rel="stylesheet" href="chatstyle.css"> -<script src="//cdn.bootcss.com/angular.js/1.4.3/angular.min.js"></script> -<div class="container"> - <div class="row"> - - <div class="col-sm-8"> - <div class="chatbody"> - <div class="panel panel-primary"> - <div class="panel-body msg_container_base"> - - <div class="row msg_container base_sent"> - <div class="col-md-10 col-xs-10"> - <div class="messages msg_sent"> - <p>that mongodb thing looks good, huh? - tiny master db, and huge document store</p> - <time datetime="2009-11-13T20:00">Timothy • 51 min</time> - </div> - </div> - <div class="col-md-2 col-xs-2 avatar"> - <!-- <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive "> --> - </div> - </div> - - <div class="row msg_container base_receive"> - <div class="col-md-2 col-xs-2 avatar"> - <!-- <img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive "> --> - </div> - <div class="col-md-10 col-xs-10"> - <div class="messages msg_receive"> - <p>that mongodb thing looks good, huh? - tiny master db, and huge document store</p> - <time datetime="2009-11-13T20:00">Timothy • 51 min</time> - </div> - </div> - </div> - - </div> - - <div class="panel-footer"> - <div class="input-group"> - <input id="btn-input" type="text" class="form-control input-sm chat_input" placeholder="Write your message here..." style="width:85%" /> - <span class="input-group-btn"> - <button class="btn btn-primary btn-sm" id="btn-chat"><i class="fa fa-send fa-1x" aria-hidden="true"></i></button> - </span> - </div> - </div> - </div> - - </div> - </div> -</div> \ No newline at end of file diff --git a/ChatService/public/firebase-logo.png b/ChatService/public/firebase-logo.png deleted file mode 100644 index c498b958bb02961ead9bb0f2637ac2f6248af02d..0000000000000000000000000000000000000000 Binary files a/ChatService/public/firebase-logo.png and /dev/null differ diff --git a/ChatService/public/firebase-messaging-sw.js b/ChatService/public/firebase-messaging-sw.js deleted file mode 100644 index d05db758f230a15bf4ec9d17f7d834da6ef65321..0000000000000000000000000000000000000000 --- a/ChatService/public/firebase-messaging-sw.js +++ /dev/null @@ -1,50 +0,0 @@ -// Import and configure the Firebase SDK -// These scripts are made available when the app is served or deployed on Firebase Hosting -// If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup -importScripts('/__/firebase/3.9.0/firebase-app.js'); -importScripts('/__/firebase/3.9.0/firebase-messaging.js'); -importScripts('/__/firebase/init.js'); - -const messaging = firebase.messaging(); - -/** - * Here is is the code snippet to initialize Firebase Messaging in the Service - * Worker when your app is not hosted on Firebase Hosting. - - // [START initialize_firebase_in_sw] - // Give the service worker access to Firebase Messaging. - // Note that you can only use Firebase Messaging here, other Firebase libraries - // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js'); - - // Initialize the Firebase app in the service worker by passing in the - // messagingSenderId. - firebase.initializeApp({ - 'messagingSenderId': 'YOUR-SENDER-ID' - }); - - // Retrieve an instance of Firebase Messaging so that it can handle background - // messages. - const messaging = firebase.messaging(); - // [END initialize_firebase_in_sw] - **/ - - -// If you would like to customize notifications that are received in the -// background (Web app is closed or not in browser focus) then you should -// implement this optional method. -// [START background_handler] -messaging.setBackgroundMessageHandler(function(payload) { - console.log('[firebase-messaging-sw.js] Received background message ', payload); - // Customize notification here - const notificationTitle = 'Background Message Title'; - const notificationOptions = { - body: 'Background Message body.', - icon: '/firebase-logo.png' - }; - - return self.registration.showNotification(notificationTitle, - notificationOptions); -}); -// [END background_handler] diff --git a/ChatService/public/firebase.json b/ChatService/public/firebase.json deleted file mode 100644 index c2053b724f8b3a32e67f0608b133202838a9e87a..0000000000000000000000000000000000000000 --- a/ChatService/public/firebase.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "hosting": { - "public": "./", - "ignore": [ - "firebase.json" - ] - } -} diff --git a/ChatService/public/index.html b/ChatService/public/index.html deleted file mode 100644 index ae7d8ab98e961ef40c70124c44cae8e3b78f33eb..0000000000000000000000000000000000000000 --- a/ChatService/public/index.html +++ /dev/null @@ -1,143 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <meta charset=utf-8 /> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Firebase Cloud Messaging Example</title> - - <!-- Material Design Theming --> - <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css"> - <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> - <script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script> - <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> - <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> - <link rel="stylesheet" href="style/chatstyle.css"> - <script src="//cdn.bootcss.com/angular.js/1.4.3/angular.min.js"></script> - <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> - <link rel="manifest" href="/manifest.json"> -</head> -<body style="width: 510px; height: 500px; margin: 0 auto;"> - <div class="container"> - <div class="row"> - <div class="col-sm-8"> - <div class="chatbody"> - <div class="panel panel-primary"> - <div class="panel-body msg_container_base"> - <div class="row msg_container base_sent"> - <div class="col-md-10 col-xs-10"> - <div class="messages msg_sent"> - <p>that mongodb thing looks good, huh? - tiny master db, and huge document store</p> - </div> - </div> - </div> - - <div class="row msg_container base_receive"> - <div class="col-md-10 col-xs-10"> - <div class="messages msg_receive"> - <p>that mongodb thing looks good, huh? - tiny master db, and huge document store</p> - </div> - </div> - </div> - </div> - <div class="panel-footer"> - <div class="input-group"> - <input id="btn-input" type="text" class="form-control input-sm chat_input" placeholder="Write your message here..." style="width:85%" /> - <span class="input-group-btn"> - <button class="btn btn-primary btn-sm" id="btn-chat"><i class="fa fa-send fa-1x" aria-hidden="true"></i></button> - </span> - </div> - </div> - </div> - </div> - </div> - </div> - -<!-- Import and configure the Firebase SDK --> -<!-- These scripts are made available when the app is served or deployed on Firebase Hosting --> -<!-- If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup --> -<script src="/__/firebase/3.9.0/firebase-app.js"></script> -<script src="/__/firebase/3.9.0/firebase-messaging.js"></script> -<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script> -<script> - // Initialize Firebase - // TODO: Replace with your project's customized code snippet - var config = { - apiKey: "AIzaSyAAjgP3DHtLCHGBgP5XDud8HTKkyw_0-vU", - authDomain: "chatservice-kia.firebaseapp.com", - databaseURL: "https://chatservice-kia.firebaseio.com", - projectId: "chatservice-kia", - storageBucket: "chatservice-kia.appspot.com", - messagingSenderId: "616813324575" - }; - firebase.initializeApp(config); -</script> -<script> - // [START get_messaging_object] - // Retrieve Firebase Messaging object. - const messaging = firebase.messaging(); - // [END get_messaging_object] - messaging.requestPermission() - .then(function() { - console.log('Notification permission granted.'); - }) - .catch(function(err) { - console.log('Unable to get permission to notify.', err); - }); - - messaging.getToken() - .then(function(currentToken) { - if (currentToken) { - console.log(currentToken); - } else { - console.log('No Instance ID token available. Request permission to generate one.'); - } - }) - .catch(function(err) { - console.log('An error occurred while retrieving token. ', err); - }); - - // [START refresh_token] - // Callback fired if Instance ID token is updated. - messaging.onTokenRefresh(function() { - messaging.getToken() - .then(function(refreshedToken) { - console.log('Token refreshed.'); - // Indicate that the new Instance ID token has not yet been sent to the app server. - }) - .catch(function(err) { - console.log('Unable to retrieve refreshed token ', err); - }); - }); - // [END refresh_token] - - // [START receive_message] - // Handle incoming messages. Called when: - // - a message is received while the app has focus - // - the user clicks on an app notification created by a sevice worker - // `messaging.setBackgroundMessageHandler` handler. - messaging.onMessage(function(payload) { - console.log("Message received. ", payload); - // [START_EXCLUDE] - // Update the UI to include the received message. - appendMessage(payload); - // [END_EXCLUDE] - }); - // [END receive_message] - - // Add a message to the messages element. - function appendMessage(payload) { - const messagesElement = document.querySelector('#messages'); - const dataHeaderELement = document.createElement('h5'); - const dataElement = document.createElement('pre'); - dataElement.style = 'overflow-x:hidden;' - dataHeaderELement.textContent = 'Received message:'; - dataElement.textContent = JSON.stringify(payload, null, 2); - messagesElement.appendChild(dataHeaderELement); - messagesElement.appendChild(dataElement); - } - -</script> -</body> -</html> diff --git a/ChatService/public/manifest.json b/ChatService/public/manifest.json deleted file mode 100644 index 10b861e181d5c1f7af8fa483ca379220aca0d358..0000000000000000000000000000000000000000 --- a/ChatService/public/manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "//_comment1": "Some browsers will use this to enable push notifications.", - "//_comment2": "It is the same for all projects, this is not your project's sender ID", - "gcm_sender_id": "103953800507" -} diff --git a/ChatService/public/script/firebase_init.js b/ChatService/public/script/firebase_init.js deleted file mode 100644 index 30417063dadccda746bb6313df7c3efb3c509205..0000000000000000000000000000000000000000 --- a/ChatService/public/script/firebase_init.js +++ /dev/null @@ -1,9 +0,0 @@ -// Initialize Firebase -var config = { - apiKey: "AIzaSyAAjgP3DHtLCHGBgP5XDud8HTKkyw_0-vU", - authDomain: "chatservice-kia.firebaseapp.com", - databaseURL: "https://chatservice-kia.firebaseio.com", - projectId: "chatservice-kia", - storageBucket: "chatservice-kia.appspot.com", - messagingSenderId: "616813324575" -}; \ No newline at end of file diff --git a/ChatService/public/style/chatstyle.css b/ChatService/public/style/chatstyle.css deleted file mode 100644 index 809d5d07dd09c8cb23759c77dc2e24f236b12171..0000000000000000000000000000000000000000 --- a/ChatService/public/style/chatstyle.css +++ /dev/null @@ -1,165 +0,0 @@ -.chatperson{ - display: block; - border-bottom: 1px solid #eee; - width: 100%; - display: flex; - align-items: center; - white-space: nowrap; - overflow: hidden; - margin-bottom: 15px; - padding: 4px; -} -.chatperson:hover{ - text-decoration: none; - border-bottom: 1px solid orange; -} -.namechat { - display: inline-block; - vertical-align: middle; -} -.chatperson .chatimg img{ - width: 40px; - height: 40px; - background-image: url('http://i.imgur.com/JqEuJ6t.png'); -} -.chatperson .pname{ - font-size: 18px; - padding-left: 5px; -} -.chatperson .lastmsg{ - font-size: 12px; - padding-left: 5px; - color: #ccc; -} - -body{ - height:400px; - position: fixed; - bottom: 0; -} -.col-md-2, .col-md-10{ - padding:0; -} -.panel{ - margin-bottom: 0px; -} -.chat-window{ - bottom:0; - position:fixed; - float:right; - margin-left:10px; -} -.chat-window > div > .panel{ - border-radius: 5px 5px 0 0; -} -.icon_minim{ - padding:2px 10px; -} -.msg_container_base{ - background: #e5e5e5; - margin: 0; - padding: 0 10px 10px; - max-height:300px; - overflow-x:hidden; -} -.top-bar { - background: #666; - color: white; - padding: 10px; - position: relative; - overflow: hidden; -} -.msg_receive{ - padding-left:0; - margin-left:0; -} -.msg_sent{ - padding-bottom:20px !important; - margin-right:0; -} -.messages { - background: white; - padding: 10px; - border-radius: 2px; - box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); - max-width:100%; -} -.messages > p { - font-size: 13px; - margin: 0 0 0.2rem 0; - } -.messages > time { - font-size: 11px; - color: #ccc; -} -.msg_container { - padding: 10px; - overflow: hidden; - display: flex; -} -img { - display: block; - width: 100%; -} -.avatar { - position: relative; - width:50px; -} -.base_receive > .avatar:after { - content: ""; - position: absolute; - top: 0; - right: 0; - width: 0; - height: 0; - border: 5px solid #FFF; - border-left-color: rgba(0, 0, 0, 0); - border-bottom-color: rgba(0, 0, 0, 0); -} - -.base_sent { - justify-content: flex-end; - align-items: flex-end; -} -.base_sent > .avatar:after { - content: ""; - position: absolute; - bottom: 0; - left: 0; - width: 0; - height: 0; - border: 5px solid white; - border-right-color: transparent; - border-top-color: transparent; - box-shadow: 1px 1px 2px rgba(black, 0.2); // not quite perfect but close -} - -.msg_sent > time{ - float: right; -} - - - -.msg_container_base::-webkit-scrollbar-track -{ - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); - background-color: #F5F5F5; -} - -.msg_container_base::-webkit-scrollbar -{ - width: 12px; - background-color: #F5F5F5; -} - -.msg_container_base::-webkit-scrollbar-thumb -{ - -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); - background-color: #555; -} - -.btn-group.dropup{ - position:fixed; - left:0px; - bottom:0; -} \ No newline at end of file diff --git a/ChatService/public/style/main.css b/ChatService/public/style/main.css deleted file mode 100644 index 77515e7fa5c99ce7245ed9f7ce0125fe53ea8c5e..0000000000000000000000000000000000000000 --- a/ChatService/public/style/main.css +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2015 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -html, body { - font-family: 'Roboto', 'Helvetica', sans-serif; -} -a { - text-decoration: none; -} -li a { - text-decoration: underline; - color: #0288d1; -} -.mdl-grid { - max-width: 1024px; - margin: auto; -} -.mdl-layout__header-row { - padding: 0; -} -.quickstart-user-details-container { - margin-top: 20px; - line-height: 25px; -} -#quickstart-sign-in-status { - font-weight: bold; -} -pre { - overflow-x: scroll; - line-height: 18px; -} -code { - white-space: pre-wrap; - word-break: break-all; -} -h3 { - background: url('/firebase-logo.png') no-repeat; - background-size: 40px; - padding-left: 50px; - color: white; -} diff --git a/PrOjek/ojek-cmpt/src/main/java/com/jauharteam/ojek/ojek/LocationService.java b/PrOjek/ojek-cmpt/src/main/java/com/jauharteam/ojek/ojek/LocationService.java index 5d746877a3aee26059703ea246d7713a3226ad4f..e6ea34ca6c9915d78aeb2ed0e304d8fcd926af99 100644 --- a/PrOjek/ojek-cmpt/src/main/java/com/jauharteam/ojek/ojek/LocationService.java +++ b/PrOjek/ojek-cmpt/src/main/java/com/jauharteam/ojek/ojek/LocationService.java @@ -22,9 +22,6 @@ public interface LocationService { @WebMethod public Location[] getAllLocation(String token); - @WebMethod - public Location[] getAllLocation(Integer id); - @WebMethod public Boolean editLocation(String token, Location pastLocation, Location newLocation); diff --git a/PrOjek/ojek/src/main/java/com/jauharteam/ojek/ojek/location/LocationServiceImpl.java b/PrOjek/ojek/src/main/java/com/jauharteam/ojek/ojek/location/LocationServiceImpl.java index e1dd72ed645491c672663a722e1f39f79725393e..711cbd814c21fffc922ef8f3d5d96abf89a3dd30 100644 --- a/PrOjek/ojek/src/main/java/com/jauharteam/ojek/ojek/location/LocationServiceImpl.java +++ b/PrOjek/ojek/src/main/java/com/jauharteam/ojek/ojek/location/LocationServiceImpl.java @@ -66,15 +66,6 @@ public class LocationServiceImpl implements LocationService { return new Location[0]; } - @Override - public Location[] getAllLocation(Integer id) { - if(id){ - ArrayList<Location> locations = locationDAO.getAllLocation(user.getId()); - return locations.toArray(new Location[locations.size()]); - } - return new Location[0]; - } - @Override public Boolean editLocation(String token, Location pastLocation, Location newLocation) { if(getIdentityService().isTokenValid(token)) { diff --git a/PrOjek/webapp/src/main/webapp/firebase-messaging-sw.js b/PrOjek/webapp/src/main/webapp/firebase-messaging-sw.js new file mode 100644 index 0000000000000000000000000000000000000000..66087ce4176c0fa5eba7d34ce54162572a7993d9 --- /dev/null +++ b/PrOjek/webapp/src/main/webapp/firebase-messaging-sw.js @@ -0,0 +1,21 @@ +// Import and configure the Firebase SDK +// These scripts are made available when the app is served or deployed on Firebase Hosting +// If you do not want to serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup +// Give the service worker access to Firebase Messaging. +// Note that you can only use Firebase Messaging here, other Firebase libraries +// are not available in the service worker. +importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js'); +importScripts('https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js'); + +// Initialize the Firebase app in the service worker by passing in the +// Initialize Firebase +var config = { + apiKey: "AIzaSyAAjgP3DHtLCHGBgP5XDud8HTKkyw_0-vU", + authDomain: "chatservice-kia.firebaseapp.com", + databaseURL: "https://chatservice-kia.firebaseio.com", + projectId: "chatservice-kia", + storageBucket: "chatservice-kia.appspot.com", + messagingSenderId: "616813324575" +}; +firebase.initializeApp(config); +const messaging = firebase.messaging(); diff --git a/PrOjek/webapp/src/main/webapp/resources/css/chat.css b/PrOjek/webapp/src/main/webapp/resources/css/chat.css new file mode 100644 index 0000000000000000000000000000000000000000..1219598495afb3d24d8e036d5a282fcb5541f7f5 --- /dev/null +++ b/PrOjek/webapp/src/main/webapp/resources/css/chat.css @@ -0,0 +1,87 @@ +.def_page { + position: static; + margin-top: 10px; + margin-left: auto; + margin-right: auto; + padding-left: 0; + padding-right: 0; + width: 600px; +} + +.chat-box { + margin-top: 20px; + border-style: solid; + border-width: 1px; + width: 100%; + height: 200px; + overflow: auto; +} +.chat-input { + border-style: solid; + border-width: 1px; + border-top: none; + width: 100%; + height: 40px; +} +.sendermessage { + border-style: solid; + border-width: 1px; + border-radius: 10px; + width: 200px; + height: auto; + padding: 5px; + margin: 5px; + margin-left: 200px; + background-color: #7FA6F5; + float: right; +} +.receivemessage { + border-style: solid; + border-width: 1px; + border-radius: 10px; + width: 200px; + height: auto; + padding: 5px; + margin: 5px; + margin-right: 200px; + background-color: #EAEAEA; + float: left; +} +#send-message-driver { + background: #36B54B; + border-style: solid; + border-width: 1px; + border-radius: 10px; + border-color: black; + float: right; + height: 30px; + width: 120px; + margin: 5px; +} +#send-message-user { + background: #36B54B; + border-style: solid; + border-width: 1px; + border-radius: 10px; + border-color: black; + float: right; + height: 30px; + width: 120px; + margin: 5px; +} +#message-content-driver { + margin-left: 5px; + width: 70%; + height: 35px; + border: none; + border-color: transparent; + outline: none; +} +#message-content-user { + margin-left: 5px; + width: 70%; + height: 35px; + border: none; + border-color: transparent; + outline: none; +} \ No newline at end of file diff --git a/PrOjek/webapp/src/main/webapp/resources/js/edit_location.js b/PrOjek/webapp/src/main/webapp/resources/js/edit_location.js index 55898acf083c1c54d3cde31e85eff87b71a66da4..369d4228162dfb060ac3ac3e0b5c439403910727 100644 --- a/PrOjek/webapp/src/main/webapp/resources/js/edit_location.js +++ b/PrOjek/webapp/src/main/webapp/resources/js/edit_location.js @@ -1,7 +1,7 @@ function deleteLocation(id, pref, locId){ var delElmt = document.getElementById("row-"+pref); // var locId = delElmt.getElementsByClassName('location-name')[0].textContent; - var url = '/soapservlet'; + var url = '/webapp/soapservlet'; console.log(locId) postAjax(url, {id: id, name: "delete-location", loc_id: locId}, function(data){ console.log(data); diff --git a/PrOjek/webapp/src/main/webapp/resources/js/order.js b/PrOjek/webapp/src/main/webapp/resources/js/order.js index ccb42dde7cf456a47243942f03c1aa387e035138..8d9c0f6ed33fe0e324a7e337d7a3c802eb24e3e8 100644 --- a/PrOjek/webapp/src/main/webapp/resources/js/order.js +++ b/PrOjek/webapp/src/main/webapp/resources/js/order.js @@ -38,11 +38,23 @@ function nextToSelectDriver() { document.getElementById("tab-"+next).classList.add("button-progress-now"); } -function nextToCompleteOrder(){ +function nextToChatDriver(){ var prev = 'select-driver'; + var next = 'chat-order'; + document.getElementById(prev).style.display = 'none'; + document.getElementById(next).style.display = 'block'; + document.getElementById("tab-"+prev).classList.remove("button-progress-now"); + document.getElementById("tab-"+next).classList.add("button-progress-now"); +} + +function nextToCompleteOrder(){ + var prev = 'chat-order'; var next = 'complete-order'; document.getElementById(prev).style.display = 'none'; document.getElementById(next).style.display = 'block'; + $.post("http://localhost:3000/finishorder",{id:idDriver},function(data){ + console.log(data); + }); document.getElementById("tab-"+prev).classList.remove("button-progress-now"); document.getElementById("tab-"+next).classList.add("button-progress-now"); } @@ -52,7 +64,7 @@ function nextToWaitingForOrder() { var next = 'wait-order'; document.getElementById(prev).style.display = 'none'; document.getElementById(next).style.display = 'block'; - $.post('http://localhost:3000/findorder',{id:idCustomer}); + $.post('http://localhost:3000/findorder',{id:idCustomer, pref:lokasi}); } function backToFindOrder() { @@ -110,13 +122,13 @@ function openOrder(step) { tablinks[i].className = tablinks[i].className.replace("form-order-default", "form-order"); } active=document.getElementById(step); - active.className=document.getElementById(step).className.replace("form-order","form-order-default"); - taborder = document.getElementsByClassName("taborder"); - for (i = 0; i < taborder.length; i++) { - taborder[i].className=taborder[i].className.replace("button-progress-now","button-plain"); - } + active.className=document.getElementById(step).className.replace("form-order","form-order-default"); + taborder = document.getElementsByClassName("taborder"); + for (i = 0; i < taborder.length; i++) { + taborder[i].className=taborder[i].className.replace("button-progress-now","button-plain"); + } tabchosen = document.getElementById("tab-"+step); - tabchosen.className=tabchosen.className.replace("button-plain","button-progress-now"); + tabchosen.className=tabchosen.className.replace("button-plain","button-progress-now"); } function grabDriver(){ @@ -124,43 +136,48 @@ function grabDriver(){ destination = document.getElementById('destination').value; // var url = "/soapservlet"; var url = "http://localhost:3000/availabledriver"; + var createElement = document.getElementById('other-driver'); + var addRow = ""; $.get(url,function(data){ console.log(data); for (var driver in data){ + console.log(data[driver].id); console.log(data[driver].status); - }; + for (var listlokasi in data[driver].pref){ + var namalokasi = data[driver].pref[listlokasi].lokasi; + console.log(data[driver].pref[listlokasi].lokasi); + if (pickingpoint.localeCompare(namalokasi)==0 || destination.localeCompare(namalokasi)==0) { + $.post("http://localhost:8080/webapp/soapservlet",{name:"get-driver-by-id", iddriver:data[driver].idDriver}, function(data1){ + console.log(data1); + console.log(data1['id']); + prefdetail = data1; + addRow += "<div class='row'>"; + addRow += "<div class='col-4'>"; + addRow += "<div class='picture driver-picture'>"; + addRow += "<img src='" + prefdetail['profpicurl'] + "'>"; + addRow += "</div>"; + addRow += "</div>"; + addRow += "<div class='col-8 driver-detail'>"; + addRow += "<div class='driver-name'>"; + addRow += prefdetail['name']; + addRow += "</div>"; + addRow += "<div class='driver-rating'>"; + addRow += "<span style='color:orange'>☆</span><span class='rating'>" + prefdetail['rating'] + "</span>(" + prefdetail['votes'] + " votes)"; + addRow += "</div>"; + addRow += "<div class='row'>"; + addRow += "<a href='#' class='button button-success right' id='" + prefdetail['id'] + "' onclick='selectDriver(this)'>I CH0OSE YOU!</a>"; + addRow += "</div></div></div>"; + console.log(addRow); + createElement.innerHTML += addRow; + }); + break; + } + } + } }); - // var createElement = document.getElementById('other-driver'); - // var addRow = ""; - // if (driversdetail.hasOwnProperty('answer')) { - // addRow += "<div id='no-other-driver'>Nothing to display :(</div>"; - // } else { - // if (driversdetail.length > 0) { - // for (var i = 0; i < driversdetail.length; i++) { - // addRow += "<div class='row'>"; - // addRow += "<div class='col-4'>"; - // addRow += "<div class='picture driver-picture'>"; - // addRow += "<img src='" + driversdetail[i]['profile_pic_url'] + "'>"; - // addRow += "</div>"; - // addRow += "</div>"; - // addRow += "<div class='col-8 driver-detail'>"; - // addRow += "<div class='driver-name'>"; - // addRow += driversdetail[i]['name']; - // addRow += "</div>"; - // addRow += "<div class='driver-rating'>"; - // addRow += "<span style='color:orange'>☆</span><span class='rating'>" + driversdetail[i]['rating'] + "</span>(" + driversdetail[i]['votes'] + " votes)"; - // addRow += "</div>"; - // addRow += "<div class='row'>"; - // addRow += "<a href='#' class='button button-success right' id='" + driversdetail[i]['id'] + "' onclick='selectDriver(this)'>I CH0OSE YOU!</a>"; - // addRow += "</div></div></div>"; - // } - // } else { - // addRow += "<div id='no-other-driver'>Nothing to display :(</div>"; - // } - // } - // }); - // createElement.innerHTML = addRow; - nextToSelectDriver(); + createElement.innerHTML = addRow; + console.log(addRow); + nextToSelectDriver(); } document.getElementById('pickingpoint').onkeyup = function(event){ @@ -207,9 +224,34 @@ document.getElementById('destination').onkeyup = function(event){ } function selectDriver(element){ - idDriver = element.id + idDriver = element.id; + id_driver = idDriver; + openOrder('chat-order'); + console.log(idDriver); + document.getElementById('modalverifyorder').style.display = "block"; + $.post("http://localhost:3000/selectdriver",{id:idDriver, from:idCustomer},function(data){ + console.log(data); + }); + nextToChatDriver(); +} + +// USER +function finishOrder(){ + var url= "/webapp/soapservlet"; console.log(idDriver) - document.getElementById('modalverifyorder').style.display = "block"; + postAjax(url, {name: "get-driver-by-id", iddriver:idDriver}, function(data){ + console.log(data); + var elementdriverpict = document.getElementById('driver-pict').getElementsByTagName('img')[0]; + var elementdriveruname = document.getElementById('driver-username'); + var elementdrivername = document.getElementById('driver-fullname'); + var driverdetail = JSON.parse(data); + console.log(driverdetail) + elementdriverpict.src = driverdetail['profpicUrl']; + elementdriveruname.innerHTML = '@'+driverdetail['username']; + elementdrivername.innerHTML = driverdetail['name']; + nextToCompleteOrder(); + }); + openOrder("complete-order"); } // When the user clicks on <span> (x), close the modal document.getElementById("no-order").onclick = function() { @@ -217,21 +259,7 @@ document.getElementById("no-order").onclick = function() { } document.getElementById("yes-order").onclick = function() { document.getElementById('modalverifyorder').style.display = "none"; - var url= "/soapservlet"; - console.log(idDriver) - postAjax(url, {name: "get-driver-by-id", iddriver:idDriver}, function(data){ - console.log(data); - var elementdriverpict = document.getElementById('driver-pict').getElementsByTagName('img')[0]; - var elementdriveruname = document.getElementById('driver-username'); - var elementdrivername = document.getElementById('driver-fullname'); - var driverdetail = JSON.parse(data); - console.log(driverdetail) - elementdriverpict.src = driverdetail['profpicUrl']; - elementdriveruname.innerHTML = '@'+driverdetail['username']; - elementdrivername.innerHTML = driverdetail['name']; - nextToCompleteOrder(); - }); - openOrder("complete-order"); + } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { @@ -239,27 +267,28 @@ window.onclick = function(event) { document.getElementById('modalverifyorder').style.display = "none"; } } + document.getElementById('submit-order').onclick = function(){ - var url = "/soapservlet"; - if(rating> 0){ - comment = document.getElementById('comment-area').value; - postAjax(url, {name: "submit-order", iddriver:idDriver, idcust:idCustomer, dest:destination, loc:pickingpoint, rate:rating, comm:comment}, function(data){ - console.log(data) - if(data == "ok"){ - document.getElementById('modalsubmit').style.display = "block"; - } else { - document.getElementById('warning-msg-submit').innerHTML = '<span class="closebtn" onclick="this.parentElement.style.display = "none";">×</span>Sorry, an error occured!'; - document.getElementById('warning-msg-submit').style.display = 'block'; - } - }); - } else { - document.getElementById('warning-msg-submit').innerHTML = '<span class="closebtn" onclick="this.parentElement.style.display = "none";">×</span>Please enter rating for our driver'; - document.getElementById('warning-msg-submit').style.display = 'block'; - } + var url = "/soapservlet"; + if(rating> 0){ + comment = document.getElementById('comment-area').value; + postAjax(url, {name: "submit-order", iddriver:idDriver, idcust:idCustomer, dest:destination, loc:pickingpoint, rate:rating, comm:comment}, function(data){ + console.log(data) + if(data == "ok"){ + document.getElementById('modalsubmit').style.display = "block"; + } else { + document.getElementById('warning-msg-submit').innerHTML = '<span class="closebtn" onclick="this.parentElement.style.display = "none";">×</span>Sorry, an error occured!'; + document.getElementById('warning-msg-submit').style.display = 'block'; + } + }); + } else { + document.getElementById('warning-msg-submit').innerHTML = '<span class="closebtn" onclick="this.parentElement.style.display = "none";">×</span>Please enter rating for our driver'; + document.getElementById('warning-msg-submit').style.display = 'block'; + } } // When the user clicks on OK, close the modal document.getElementById("verifysubmit").onclick = function() { document.getElementById('modalsubmit').style.display = "none"; - window.location = "order"; + window.location = "order"; } \ No newline at end of file diff --git a/PrOjek/webapp/src/main/webapp/views/edit_location.jsp b/PrOjek/webapp/src/main/webapp/views/edit_location.jsp index 96401722966918b33f54614397e31803051150d6..ce10c8a80e86f59e94bdc9cf0e89e11a3b28f1e3 100644 --- a/PrOjek/webapp/src/main/webapp/views/edit_location.jsp +++ b/PrOjek/webapp/src/main/webapp/views/edit_location.jsp @@ -29,7 +29,7 @@ %> <% int prefNum = location.getPrefNum(); %> <tr id='row-<%= prefNum %>'> - <form action="/soapservlet" method="post" accept-charset="utf-8"> + <form action="/webapp/soapservlet" method="post" accept-charset="utf-8"> <input type="text" name="name" value="edit-location" hidden> <td class='number'> <input type='text' id="pref-row-<%= prefNum %>" class='input-standard input-standard-v2' name="pref-<%= prefNum %>" value="<%= prefNum %>" style="display:none;"> @@ -67,7 +67,7 @@ </div> <div class="row margin-top"> <h3>Add New Location : </h3> - <form action="/soapservlet" method="POST" accept-charset="utf-8"> + <form action="/webapp/soapservlet" method="POST" accept-charset="utf-8"> <input name="name" type="hidden" value="add-location"> <label class="col-10"> <input class="input-standard input-standard-v2" autocorrect="off" autocomplete="off" type="text" id="location" name="location" list="suggestLoc"> diff --git a/PrOjek/webapp/src/main/webapp/views/order_view.jsp b/PrOjek/webapp/src/main/webapp/views/order_view.jsp index 5d1d3e2d5969b96274d3fc70ffd2a4776cc3d318..024009f404397de0c8b1398b2f979db30e74cd10 100644 --- a/PrOjek/webapp/src/main/webapp/views/order_view.jsp +++ b/PrOjek/webapp/src/main/webapp/views/order_view.jsp @@ -1,10 +1,13 @@ <%@ page import="java.util.Date" %> <%@ page import="com.jauharteam.ojek.ojek.UserService" %> +<%@ page import="com.jauharteam.ojek.ojek.LocationService" %> <%@ page import="com.ojek.common.User" %> +<%@ page import="com.ojek.common.Location" %> <% - String accessToken = (String) request.getAttribute("accessToken"); - UserService userService = (UserService) request.getAttribute("userService"); - User user = userService.getUser(accessToken); + String accessToken = (String) request.getAttribute("accessToken"); + UserService userService = (UserService) request.getAttribute("userService"); + LocationService locationService = (LocationService) request.getAttribute("locationService"); + User user = userService.getUser(accessToken); %> <link rel="stylesheet" href="./resources/css/chat.css"> <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script> @@ -164,20 +167,26 @@ </div> </div> </form> - - <div class="chat-form" ng-app="chatbox" ng-controller="controller"> - <div class="chat-box" schroll-bottom="chat"> - <div ng-repeat="pesan in chat"> - <p ng-if="pesan.type==2" class="sendermessage">{{pesan.message}}</p> - <p ng-if="pesan.type==1" class="receivemessage">{{pesan.message}}</p> + <div id="chat-order" style="display: none;"> + <div class="chat-form" ng-app="chatbox" ng-controller="controller"> + <div class="chat-box" schroll-bottom="chat"> + <div ng-repeat="pesan in chat"> + <p ng-if="pesan.type==2" class="sendermessage">{{pesan.message}}</p> + <p ng-if="pesan.type==1" class="receivemessage">{{pesan.message}}</p> + </div> + </div> + <div class="chat-input"> + <form ng-submit="submit()"> + <input type="text" name="chattext" ng-model="pesan" id="message-content-user"> + <input type="submit" name="send" value="Kirim" id="send-message-user"> + </form> </div> </div> - <div class="chat-input"> - <form ng-submit="submit()"> - <input type="text" name="chattext" ng-model="pesan" id="message-content"> - <input type="submit" name="send" value="Kirim" id="send-message"> - </form> - </div> + <div> + <div class="col-4"></div> + <div class="col-4 button button-fail" style="margin:10px auto" onclick="finishOrder()">CLOSE</div> + <div class="col-4"></div> + </div> </div> <div id="modalsubmit" class="modalview"> @@ -213,8 +222,8 @@ }); }); } - var id_driver = 1; - var id_customer = 2; + var id_driver = 30; + var id_customer = <%= user.getId() %>; var token = ''; // Chatbox module for angular chat var chatbox1 = angular.module('chatbox', ['firebase']); @@ -233,30 +242,32 @@ } }) .controller('controller', function ($scope, $http, $window) { + $scope.show = false; $scope.chat = []; + $http({ - method: "GET", - url: "http://localhost:3000/chathistory", - params: {idUser : id_customer, idDriver : id_driver} - }).then(function mySuccess(response) { - console.log(response.data); - $scope.rawchat = response.data; - for (var i = 0; i < $scope.rawchat.length; i++) { - var obj = $scope.rawchat[i]; - var msg = new Object(); - msg.message = obj.message; - if (obj.from == id_driver) { - msg.type = 1; - } - else if (obj.from == id_customer) { - msg.type = 2; - } - $scope.chat.push(msg); + method: "GET", + url: "http://localhost:3000/chathistory", + params: {idUser : id_customer, idDriver : id_driver} + }).then(function mySuccess(response) { + console.log(response.data); + $scope.rawchat = response.data; + for (var i = 0; i < $scope.rawchat.length; i++) { + var obj = $scope.rawchat[i]; + var msg = new Object(); + msg.message = obj.message; + if (obj.from == id_driver) { + msg.type = 1; } - }, function myError(response) { - console.log(response.statusText); - $scope.chat = response.statusText; - }); + else if (obj.from == id_customer) { + msg.type = 2; + } + $scope.chat.push(msg); + } + }, function myError(response) { + console.log(response.statusText); + $scope.chat = response.statusText; + }); //Request Permission for Notifications messaging.requestPermission() .then(function () { @@ -281,7 +292,7 @@ }).catch(function (err) { console.log('request error', err); }); - }) + }) .catch(function (err) { console.log('Unable to get permission to notify', err); }); @@ -305,7 +316,7 @@ }).then(function (response) { if (response.data.status == 200) { console.log("Pesan dikirim"); - $('input#message-content').val(''); + $('input#message-content-user').val(''); } else { console.log("Pesan gagal dikirim"); alert('Error: ' + response.data.message); @@ -353,21 +364,23 @@ <h4>Got an Order</h4> </div> <div class="row align-center"> - <h5>Name here</h5> + <h5>Dery</h5> </div> </div> - <div class="chat-form" ng-app="chatbox" ng-controller="controller"> - <div class="chat-box" schroll-bottom="chat"> - <div ng-repeat="pesan in chat"> - <p ng-if="pesan.type==2" class="sendermessage">{{pesan.message}}</p> - <p ng-if="pesan.type==1" class="receivemessage">{{pesan.message}}</p> + <div id="chat-driver" style="display: none"> + <div class="chat-form" ng-app="chatbox" ng-controller="controller"> + <div class="chat-box" schroll-bottom="chat"> + <div ng-repeat="pesan in chat"> + <p ng-if="pesan.type==2" class="sendermessage">{{pesan.message}}</p> + <p ng-if="pesan.type==1" class="receivemessage">{{pesan.message}}</p> + </div> + </div> + <div class="chat-input"> + <form ng-submit="submit()"> + <input type="text" name="chattext" ng-model="pesan" id="message-content-driver"> + <input type="submit" name="send" value="Kirim" id="send-message-driver"> + </form> </div> - </div> - <div class="chat-input"> - <form ng-submit="submit()"> - <input type="text" name="chattext" ng-model="pesan" id="message-content"> - <input type="submit" name="send" value="Kirim" id="send-message"> - </form> </div> </div> </div> @@ -394,7 +407,7 @@ }); }); } - var id_driver = 1; + var id_driver = <%= user.getId() %>; var id_customer = 2; var token = ''; // Chatbox module for angular chat @@ -414,30 +427,9 @@ } }) .controller('controller', function ($scope, $http, $window) { + $scope.show = false; $scope.chat = []; - $http({ - method: "GET", - url: "http://localhost:3000/chathistory", - params: {idUser : id_customer, idDriver : id_driver} - }).then(function mySuccess(response) { - console.log("success" + response.data); - $scope.rawchat = response.data; - for (var i = 0; i < $scope.rawchat.length; i++) { - var obj = $scope.rawchat[i]; - var msg = new Object(); - msg.message = obj.message; - if (obj.from == id_customer) { - msg.type = 1; - } - else if (obj.from == id_driver) { - msg.type = 2; - } - $scope.chat.push(msg); - } - }, function myError(response) { - console.log("error" + response.statusText); - $scope.chat = response.statusText; - }); + //Request Permission for Notifications messaging.requestPermission() .then(function () { @@ -486,7 +478,7 @@ }).then(function (response) { if (response.data.status == 200) { console.log("Pesan dikirim"); - $('input#message-content').val(''); + $('input#message-content-driver').val(''); } else { console.log("Pesan gagal dikirim"); alert('Error: ' + response.data.message); @@ -503,20 +495,46 @@ var msg = new Object(); msg.type = 1; msg.message = payload.data.message; - if (msg.message == "xxxxxx") { + msg.title = payload.notification.title; + console.log(msg.message); + console.log(msg.title); + if (msg.title == "order" || msg.message == "_____ORDER_____") { + // nextToChatDriver(); + id_customer = msg.message; + nextToGotAnOrder(); + console.log("pindah"); + $http({ + method: "GET", + url: "http://localhost:3000/chathistory", + params: {idUser : id_customer, idDriver : id_driver} + }).then(function mySuccess(response) { + console.log("success" + response.data); + $scope.rawchat = response.data; + for (var i = 0; i < $scope.rawchat.length; i++) { + var obj = $scope.rawchat[i]; + var msg = new Object(); + msg.message = obj.message; + if (obj.from == id_customer) { + msg.type = 1; + } + else if (obj.from == id_driver) { + msg.type = 2; + } + $scope.chat.push(msg); + document.getElementById("chat-driver").style.display = "block"; + } + }, function myError(response) { + console.log("error" + response.statusText); + $scope.chat = response.statusText; + }); + } + else if (msg.title == "finish" || msg.message == "_____FINISH_____") { + // nextToChatDriver(); var user = { - "username": "adyanf", + "username": "adyanf" }; - // Use AJAX to post the object to our adduser service - $.ajax({ - type: 'POST', - data: user, - url: 'http://localhost:3000/users/delete', - dataType: 'JSON' - }); - for (var i = 0; i < 100; i++) { - //Nothing - } + backToFindOrder(); + console.log("selesai"); check = true; } if (check == true) { @@ -532,6 +550,19 @@ <script> var idCustomer = <%= user.getId() %> + +var lokasi = [] +<% + Location [] locations = locationService.getAllLocation(accessToken); + for(int i = 0; i < locations.length; i++){ +%> + lokasi.push({"lokasi":"<%= locations[i].getLocation() %>"}) + console.log("<%= locations[i].getLocation() %>"); +<% + } +%> +console.log(lokasi) + </script> <% long ts = (new Date()).getTime(); //Used to prevent JS/CSS caching %> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>