From f0df6d3acf8296d786c71ffb2696f120eda4d1a4 Mon Sep 17 00:00:00 2001 From: Polyrayan <32355939+Polyrayan@users.noreply.github.com> Date: Sun, 26 Jul 2020 11:58:00 +0200 Subject: [PATCH 01/46] detournement partie 1 --- Style.js | 65 ++++++++ .../main/java/com/smtp/smtp/Navigation.java | 21 +++ components/Map/DetournementCard.js | 140 ++++++++++++++++++ components/Map/MapAdmin.js | 2 +- components/Map/MapTest.js | 128 ++++++++-------- components/Map/TruckMarker.js | 89 +++++++++-- components/globalHelper/axios.js | 24 ++- 7 files changed, 386 insertions(+), 83 deletions(-) create mode 100644 components/Map/DetournementCard.js diff --git a/Style.js b/Style.js index cfe0507..9362726 100644 --- a/Style.js +++ b/Style.js @@ -1,3 +1,8 @@ +import { Dimensions} from "react-native"; + +const { width, height } = Dimensions.get("window"); +const CARD_HEIGHT = 220; +const CARD_WIDTH = width * 0.8; export default { container:{ @@ -113,4 +118,64 @@ export default { marginBottom: 15, }, + // Marker Custom + bubble : { + flexDirection : 'column', + alignSelf: "flex-start", + backgroundColor : '#fff', + borderColor: "#cccccc", + width: 150, + }, + + arrow: { + backgroundColor: "transparent", + borderColor : "transparent", + borderTopColor : "#fff", + borderWidth: 16, + alignSelf: 'center', + marginTop : -32, + }, + + arrowBorder: { + backgroundColor: "transparent", + borderColor : "transparent", + borderTopColor : "#007a87", + borderWidth: 16, + alignSelf: 'center', + marginTop : -0.5, + }, + + name : { + fontSize: 16, + marginBottom: 5, + }, + + card: { + flexDirection : "row", + position : "absolute", + backgroundColor: "#FFF", + borderRadius : 5, + marginHorizontal: 10, + shadowColor: "#000", + shadowRadius: 5, + shadowOpacity: 0.3, + bottom: 5, + left: width*0.07, + right: 0, + height: CARD_HEIGHT, + width: CARD_WIDTH, + overflow: "hidden", + }, + textContent: { + flex: 2, + padding: 10, + }, + cardTitle: { + fontSize: 12, + fontWeight: "bold", + }, + cardDescription: { + fontSize: 12, + color: "#444", + }, } diff --git a/android/app/src/main/java/com/smtp/smtp/Navigation.java b/android/app/src/main/java/com/smtp/smtp/Navigation.java index 99f9e8b..530d249 100644 --- a/android/app/src/main/java/com/smtp/smtp/Navigation.java +++ b/android/app/src/main/java/com/smtp/smtp/Navigation.java @@ -333,6 +333,7 @@ public void onSuccess(Location loc) { mSocket.on("chantier/user/sentCoordinates", onUserSentCoordinates); mSocket.on("chantier/connect/success", onConnectToChantierSuccess); mSocket.on("chantier/user/disconnected", onUserDisconnected); + mSocket.on("chantier/detournement",onDetournement); mSocket.connect(); connectToChantier(); @@ -357,6 +358,7 @@ protected void onDestroy() { mSocket.off("chantier/user/sentCoordinates", onUserSentCoordinates); mSocket.off("chantier/connect/success", onConnectToChantierSuccess); mSocket.off("chantier/user/disconnected", onUserDisconnected); + mSocket.off("chantier/detournement", onUserDisconnected); navigationView.onDestroy(); } @@ -1042,4 +1044,23 @@ private void connectToChantier() { } modifyTimeDiffTruckAheadIfNecessary(); }); + + private Emitter.Listener onDetournement = args -> runOnUiThread(() -> { + JSONObject data = (JSONObject) args[0]; + String userIdToMove; + try { + userIdToMove = data.getString("userId"); + if (userIdToMove.equals(userId)) { + connectedToChantier = false; + mSocket.emit("chantier/disconnect"); + chantierId = data.getString("userId"); + + } + + } catch (JSONException e) { + Log.e(TAG, e.getMessage()); + return; + } + modifyTimeDiffTruckAheadIfNecessary(); + }); } diff --git a/components/Map/DetournementCard.js b/components/Map/DetournementCard.js new file mode 100644 index 0000000..51b596b --- /dev/null +++ b/components/Map/DetournementCard.js @@ -0,0 +1,140 @@ +import React from "react"; +import {Text, View, Button, AsyncStorage } from "react-native"; +import Style from "../../Style"; +import Config from "react-native-config"; +import axios from "axios"; +import CustomPicker from "../CustomPicker"; +import io from "socket.io-client"; + +export default class DetournementCard extends React.Component { + constructor(props) { + super(props); + this.socket = io(Config.API_URL); + this.handlePickerChange = this.handlePickerChange.bind(this); + this.state = { + chantier : null, + nom : "", + prenom : "", + origin : null, + destination : null, + chantiers : [], + pickerSelected : null, + } + }; + + async componentDidMount() { + this.setState({ chantier : await this.getChantier(this.props.user.chantierId)}) + await this.getCamionneurInfo(); + await this.getChantiersExceptCurrent(); + + } + + async getChantier(chantierId){ + const token = await AsyncStorage.getItem('token'); + let url = Config.API_URL+ "chantiers/"+ chantierId; + return await axios({ + method : 'get', + url : url, + headers: {'Authorization': 'Bearer ' + token}, + }) + .then( response => { + if(response.status != 200){ + alert(response.status); + return response.status; + } + console.log(response.status); + return response.data; + }) + .catch(function (error) { + alert(error) + console.log(error); + }); + } + + handlePickerChange(value){ + console.log("value picker : "+value) + this.setState({pickerSelected : this.state.chantiers[value]}) + console.log(" picker : "+ JSON.stringify(this.state.pickerSelected)) + } + + async getChantiersExceptCurrent(){ + let res = [] + let index = 0 + console.log("CHANTIERS2 : "+ JSON.stringify(this.props.chantiers)) + for (let i = 0; i < this.props.chantiers.length ; i++){ + if(this.props.chantiers[i].id !== this.props.user.chantierId){ + res[index] = this.props.chantiers[i] + index++ + } + } + console.log("RES : "+ res) + await this.setState({pickerSelected : res[0]}); + await this.setState({chantiers : res}) + + } + + async sendDetournement(){ + let chargementLong = this.state.pickerSelected.chargement.longitude; + let chargementLat = this.state.pickerSelected.chargement.latitude; + let dechargementLong = this.state.pickerSelected.dechargement.longitude; + let dechargementLat = this.state.pickerSelected.dechargement.latitude; + let chantierId = this.state.pickerSelected.id; + let userId = this.props.user.userId; + let etat = this.props.user.etat; + let obj = { + "chantierId" : chantierId, + "userId" : userId, + "origin" : [chargementLat,chargementLong], + "destination" : [dechargementLat,dechargementLong], + "etat" : etat + } + await this.socket.emit("chantier/detournement",obj) + } + + + async getCamionneurInfo(){ + const token = await AsyncStorage.getItem('token'); + axios({ + method: 'get', + url: Config.API_URL + "camionneurs/" +this.props.user.userId, + headers: {'Authorization': 'Bearer ' + token}, + }) + .then( response => { + if(response.status != 200){ + console.log(response.status); + } + console.log(response.status) + this.setState({ + nom: response.data.nom, + prenom : response.data.prenom + }); + }) + .catch(function (error) { + console.log(error); + }) + } + + render() { + if(this.props.showDetournementCard && this.state.chantiers.length > 0){ + let selected = this.state.pickerSelected.nom + let pickerData = this.state.chantiers.map(item => item.nom) + return( + + + { this.state.prenom + " " + this.state.nom } + { this.state.chantier ? this.state.chantier.nom : "null" } + + +