Commit 6c19af58 authored by Bastien Zigmann's avatar Bastien Zigmann

Notifications opérationnelles

parent c6b4b08c
/// <reference path="typings/tsd.d.ts" />
/// <reference path="typings/MyNotification.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
/**
......@@ -65,6 +66,8 @@ class Geocropping {
/** True if position on clic is actived */
_app_click_position_actived = false;
notify: MyNotification;
/*
* STYLE SETTINGS
......@@ -167,30 +170,43 @@ class Geocropping {
/**
* Attach events
*/
$(this._osm).on("requestError", (data) => {
let $osm = $(this._osm);
$osm.on("requestError", (data) => {
console.error('requestError', data);
$(this).trigger('requestError', [data]);
});
$(this._osm).on('disconnected', () => {
$osm.on('disconnected', () => {
$(this).trigger('userDisconnected');
this._user = Geocropping.DEFAULT.USER;
});
$(this._osm).on('connected', () => {
$osm.on('connected', () => {
$(this).trigger('userConnected');
//console.trace('myGeocropping', 'connected');
this.notify.ConnectionOK();
this.updateUserDetails();
});
}
connect() {
this._osm.connect();
let promise = this._osm.connect();
promise.then(() => { this.notify.ConnectionOK() }, () => { this.notify.ConnectionNOK() });
return this;
}
userDisconnect() {
let promise = this._osm.disconnect();
promise.then(() => { this.notify.DisconnectionOK() }, () => { this.notify.DisconnectionNOK() });
return promise;
}
get isConnected() {
return this._osm.isConnected;
}
updateUserDetails() {
this._osm.getUserDetails().then(
(data: any) => {
......@@ -216,14 +232,6 @@ class Geocropping {
return this;
}
userDisconnect() {
return this._osm.disconnect();
}
get isConnected() {
return this._osm.isConnected;
}
getUserDetails() {
return this._user.id !== -1 ? this._user : null;
}
......@@ -280,16 +288,15 @@ class Geocropping {
//tapTolerence : 15,
//touchZoom: false
//bounceAtZoomLimits : true,
//
}).fitWorld();
this.notify = new MyNotification(geocropping._map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: this._map_maxZoom
}).addTo(this._map);
// Affecter les events dans la popup qui vient de s'ouvrir
this._map.on('popupopen', (popupEvent: L.PopupEvent) => {
let feature = (popupEvent.popup as any)._source.feature;
......@@ -571,17 +578,22 @@ class Geocropping {
this._osm._sendRequest(req).then(e => {
elementChanged();
// OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
this.notify.ValidatedOK();
}, e => {
// ERR CloseChangeset
this.notify.ValidatedNOK();
})
}, e => {
// ERR UpdateElement
this.notify.ValidatedNOK();
})
}, e => {
// ERR CreateChangeset
this.notify.ValidatedNOK();
})
}, e => {
// ERR GetElementId
this.notify.ValidatedNOK();
});
});
......@@ -712,9 +724,11 @@ class Geocropping {
setClickPosition(active: Boolean) {
if (active) {
this._app_click_position_actived = true;
this.notify.ClicPositionON();
this._map.on('click', this._locationFoundClickFunction()).setMaxBounds(null);
} else {
this._app_click_position_actived = false;
this.notify.ClicPositionOFF();
this._map.off('click', this._locationFoundClickFunction());
}
}
......@@ -773,7 +787,9 @@ class Geocropping {
}
_locationError(options, data) {
alert(data.message);
// alert(data.message);
console.log(data.message);
this.notify.LocalisationNOK();
if (options.forceWatch === true) { // relancer la géolocalisation
setTimeout(() => {
this._map.locate(options);
......@@ -899,6 +915,7 @@ class Geocropping {
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
this.notify.AutoServerChanged();
if (this._app_server_interpreter_index === this._app_server_interpreter_list.length - 1) {
this._app_server_interpreter_index = 0;
} else {
......
/// <reference path="typings/tsd.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
class MyNotification{
options = {timeout:4000, position:"bottomleft"};
notif;
box;
constructor(map:L.Map){
this.box = (L.control as any).messagebox(this.options).addTo(map);
this.notif = {
ConnectionOK: "Connexion au compte OSM réussie", //DONE
ConnectionNOK: "Echec de la connexion au compte OSM", //DONE BUT NOT TESTED
DisconnectionOK: "Déconnexion d'OSM réussie", //DONE
DisconnectionNOK: "Echec de la deconnexion du compte OSM", //DONE BUT NOT TESTED
ValidatedOK: "Element validé", //DONE
ValidatedNOK: "Echec de la validation de l'élement", //DONE BUT NOT TESTED
LocalisationNOK: "Echec de la localisation", //DONE
AutoServerChanged: "Problème de connexion avec le server, changement automatique", //DONE BUT NOT TESTED
ServerChanged: "Changement de server éffectué", //DONE
ClicPositionON: "Arrêt de la geolocalisation, position au clic.", //DONE
ClicPositionOFF: "Reprise de la geolocalisation" //DONE
};
}
ConnectionOK(){
this.box.show(this.notif.ConnectionOK);
}
ConnectionNOK(){
this.box.show(this.notif.ConnectionNOK);
}
DisconnectionOK(){
this.box.show(this.notif.DisconnectionOK);
}
DisconnectionNOK(){
this.box.show(this.notif.DisconnectionNOK);
}
ValidatedOK(){
this.box.show(this.notif.ValidatedOK);
}
ValidatedNOK(){
this.box.show(this.notif.ValidatedNOK);
}
LocalisationNOK(){
this.box.show(this.notif.LocalisationNOK);
}
AutoServerChanged(){
this.box.show(this.notif.AutoServerChanged);
}
ServerChanged(){
this.box.show(this.notif.ServerChanged);
}
ClicPositionON(){
this.box.show(this.notif.ClicPositionON);
}
ClicPositionOFF(){
this.box.show(this.notif.ClicPositionOFF);
}
}
\ No newline at end of file
......@@ -462,18 +462,20 @@ class OauthOsm {
url += '?devMode=true';
}
let windowConnect = window.open(`${this._baseUrl}index.php${this._devApi ? '?devMode=true' : ''}`, '_self');
if (windowConnect !== null && !this._useSession) {
$(windowConnect).on('osmConnected', (e) => {
windowConnect.close();
this._token.key = e.data.key;
this._token.secret = e.data.secret;
this._saveToken();
$(this).triggerHandler("connected");
deferred.resolveWith(this);
});
} else {
deferred.rejectWith(this);
}
/*if (!this._useSession) {
if (windowConnect !== null) {
$(windowConnect).on('osmConnected', (e) => {
windowConnect.close();
this._token.key = e.data.key;
this._token.secret = e.data.secret;
this._saveToken();
$(this).triggerHandler("connected");
deferred.resolveWith(this);
});
} else {
deferred.rejectWith(this);
}
}*/
}
return deferred.promise();
......
......@@ -80,6 +80,7 @@ $(document).ready(() => {
$('#menu #urlInterpreter').change(function (e) {
geocropping._app_server_interpreter_index = geocropping._app_server_interpreter_list.indexOf(this.value);
geocropping.notify.ServerChanged();
});
let userConnected = () => {
......
/// <reference path="tsd.d.ts" />
/// <reference path="MyNotification.d.ts" />
/// <reference path="../myTypings/tsd.d.ts" />
/// <reference types="leaflet" />
/// <reference types="jquery" />
......@@ -42,6 +43,7 @@ declare class Geocropping {
_app_time_locate_interval: number;
/** True if position on clic is actived */
_app_click_position_actived: boolean;
notify: MyNotification;
_style_alert: L.PathOptions;
_style_warning: L.PathOptions;
_style_ok: L.PathOptions;
......@@ -50,9 +52,9 @@ declare class Geocropping {
static readonly DEFAULT: Geocropping.DEFAULT;
constructor();
connect(): this;
updateUserDetails(): this;
userDisconnect(): JQueryPromise<{}>;
readonly isConnected: boolean;
updateUserDetails(): this;
getUserDetails(): Geocropping.USER;
isMapCreated(): boolean;
createMap(map: any): boolean;
......
/// <reference path="tsd.d.ts" />
/// <reference path="../myTypings/tsd.d.ts" />
/// <reference types="leaflet" />
declare class MyNotification {
options: {
timeout: number;
};
notif: any;
box: any;
constructor(map: L.Map);
ConnectionOK(): void;
ConnectionNOK(): void;
DisconnectionOK(): void;
DisconnectionNOK(): void;
ValidatedOK(): void;
ValidatedNOK(): void;
LocalisationNOK(): void;
AutoServerChanged(): void;
ServerChanged(): void;
ClicPositionON(): void;
ClicPositionOFF(): void;
}
/// <reference path="tsd.d.ts" />
/// <reference path="../myTypings/tsd.d.ts" />
/// <reference types="leaflet" />
declare class MyNotification {
options: {
timeout: number;
};
notif: any;
box: any;
constructor(map: L.Map);
ConnectionOK(): void;
ConnectionNOK(): void;
DisconnectionOK(): void;
DisconnectionNOK(): void;
ValidatedOK(): void;
ValidatedNOK(): void;
LocalisationNOK(): void;
AutoServerChanged(): void;
ServerChanged(): void;
ClicPositionON(): void;
ClicPositionOFF(): void;
}
......@@ -18,17 +18,21 @@ class Geocropping
if ($type === 'DEV') {
// DEV
$this->authUrl = 'https://master.apis.dev.openstreetmap.org';
$this->apiUrl = 'https://master.apis.dev.openstreetmap.org';
$this->oauth_consumer_key = ''; // récupéré sur osm
$this->oauth_secret = ''; // récupéré sur osm
} elseif ($type === 'PROD') {
$this->apiUrl = 'https://master.apis.dev.openstreetmap.org';
$this->oauth_consumer_key = 'iUOtp4VHumguYofpEF77sb0KemjNQj58KXP66hyz'; // récupéré sur osm
$this->oauth_secret = 'gIe6ExiFr7DR5XYy25ozPnFUaF92ZeuRyEYVeu9s'; // récupéré sur osm
}
elseif ($type === 'PROD') {
// PROD
$this->authUrl = 'https://www.openstreetmap.org';
$this->apiUrl = 'https://www.openstreetmap.org';
$this->oauth_consumer_key = ''; // récupéré sur osm
$this->oauth_secret = ''; // récupéré sur osm
$this->oauth_consumer_key = 'QGGYLkKz7Vt2yNgkWeE6adWNpDoBMYrUcFGwO217'; // récupéré sur osm
$this->oauth_secret = 'QhY0iqyTK7hLCRfF0ygbgOPPqteWh2pR10EeoYRA'; // récupéré sur osm
}
$this->oauthConsumer = new OAuthConsumer($this->oauth_consumer_key, $this->oauth_secret);
......@@ -38,6 +42,7 @@ class Geocropping
// non utilisé avec les session
public function encrypteTokenValue($tokenValue)
{
return openssl_encrypt($tokenValue, "AES-128-ECB", $this->oauthConsumer->key);
......@@ -45,6 +50,7 @@ class Geocropping
// non utilisé avec les session
public function decrypteTokenValue($tokenValue)
{
$tokenValue = str_replace(' ', '+', $tokenValue);
......@@ -59,6 +65,7 @@ class Geocropping
$str = file_get_contents($req->to_url());
//var_dump(json_encode($http_response_header));
if ($str != false) {
parse_str($str, $data);
$this->oauthRequestToken->key = $data['oauth_token'];
......@@ -94,12 +101,15 @@ class Geocropping
///print_r(openssl_get_cipher_methods());
function __toString()
{
$req_secret = $this->oauthRequestToken->secret;// ? $this->encrypteTokenValue($this->oauthRequestToken->secret) : NULL;
$access_secret = $this->oauthAccessToken->secret;// ? $this->encrypteTokenValue($this->oauthAccessToken->secret) : NULL;
return json_encode([
'oauth_request_token' => [
'key' => $this->oauthRequestToken->key,
......@@ -143,7 +153,7 @@ class Geocropping
$headers['Content-Type'] = 'application/json';
$str = simplexml_load_string($str);
}
return [res => [body => $str, headers => $headers], req => [body => $content, header=>$options['http']['header'], url=> $url]];
return [res => [body => $str, headers => $headers], req => [body => $content, header => $options['http']['header'], url => $url]];
}
static function getMime($data)
......@@ -177,11 +187,13 @@ class Geocropping
}
// http://wiki.openstreetmap.org/wiki/API_v0.6
switch ($command) {
/////////
/// GET
case 'GetServerCapabilities' :
$url = '/api/capabilities';
return $this->requestAPI($url, null, $options, 'GET');
......@@ -222,10 +234,12 @@ class Geocropping
$query = $options['query'] ? $options['query'] : 'hello';
$limit = $options['limit'] ? $options['limit'] : '100';// 1 -> 10000
$closed = $options['closed'] ? $options['closed'] : '7';// Specifies the number of days a bug needs to be closed to no longer be returned
// A value of 0 means only open bugs are returned.
// A value of -1 means all bugs are returned.
$format = $options['format'] ? '.' . $options['format'] : '';
$url = '/api/0.6/notes/search' . $format . '?q=' . $query . '&limit=' . $limit . '&closed=' . $closed;
......@@ -243,6 +257,7 @@ class Geocropping
$id = $options['id'] ? $options['id'] : '1';
$type = strtolower($options['type']);// [node|way|relation]
if (!preg_match('/^(node|way|relations)$/', $type)) {
$type = 'node';
}
......@@ -252,6 +267,7 @@ class Geocropping
$id = $options['id'] ? $options['id'] : '1';
$type = strtolower($options['type']);// [node|way|relation]
if (!preg_match('/^(node|way|relations)$/', $type)) {
$type = 'node';
}
......@@ -261,6 +277,7 @@ class Geocropping
$id = $options['id'] ? $options['id'] : '1';
$type = strtolower($options['type']);// [node|way|relation]
if (!preg_match('/^(node|way|relations)$/', $type)) {
$type = 'node';
}
......@@ -268,12 +285,14 @@ class Geocropping
return $this->requestAPI($url, null, $options, 'GET');
case 'GetElementsId' : // ?
$id = $options['ids'] ? $options['ids'] : ['100', '102'];
if (is_array($id)) {
$id = implode(',', $id);
}
$type = strtolower($options['type']);// [node|way|relation]
if (!preg_match('/^(nodes|ways|relations)$/', $type)) {
$type = 'nodes';
}
......@@ -283,6 +302,7 @@ class Geocropping
$id = $options['id'] ? $options['id'] : '100';
$type = strtolower($options['type']);// [node|way|relation]
if (!preg_match('/^(node|way|relations)$/', $type)) {
$type = 'node';
}
......@@ -290,14 +310,17 @@ class Geocropping
return $this->requestAPI($url, null, $options, 'GET');
case 'GetNodeIdWays' : // ?
$id = $options['id'] ? $options['id'] : '1';
$url = '/api/0.6/ways/' . $id . '/ways';
return $this->requestAPI($url, null, $options, 'GET');
case 'GetElementIdFull' :// ?
$id = $options['id'] ? $options['id'] : '1';
$type = strtolower($options['type']);// [way|relation]
if (!preg_match('/^(way|relations)$/', $type)) {
$type = 'way';
}
......@@ -308,6 +331,7 @@ class Geocropping
/// POST
case 'CreateNote' :
$lat = $options['lat'];
$lon = $options['lon'];
......@@ -336,11 +360,13 @@ class Geocropping
/////////
/// PUT
case 'CreateChangeset' :
$element = $options['element'];
unset($options['element']);
// pour éviter le problème sur le format des données
if (!is_string($element)) {
$element = json_encode($element);
}
......@@ -349,6 +375,7 @@ class Geocropping
if (isset($element['changeset'])) {
if (!is_array($element['changeset']['tag'])) { // si un tableau de tag n'est pas présent, en créer un
$element['changeset']['tag'] = [];
}
$element['changeset']['tag'][] = ['@attributes' => ['k' => 'created_by', 'v' => 'Geocropping']];
......@@ -369,6 +396,7 @@ class Geocropping
// pour éviter le problème sur le format des données
if (!is_string($element)) {
$element = json_encode($element);
}
......@@ -377,8 +405,10 @@ class Geocropping
if (isset($element['changeset'])) {
if (!is_array($element['changeset']['tag'])) { // si un tableau de tag n'est pas présent, en créer un
if (is_object($element['changeset']['tag'])) { // Mais si un tag est présent
$element['changeset']['tag'] = [$element['changeset']['tag']];
}
else {
......@@ -411,6 +441,7 @@ class Geocropping
// pour éviter le problème sur le format des données
if (!is_string($element)) {
$element = json_encode($element);
}
......@@ -430,6 +461,7 @@ class Geocropping
// pour éviter le problème sur le format des données
if (!is_string($before)) {
$before = json_encode($before);
}
......@@ -473,6 +505,7 @@ class Geocropping
/// DELETE
default :
http_response_code(400);
return 'Invalide Command: ' . $command;
......
......@@ -45,6 +45,7 @@ if (empty($_SERVER['HTTPS'])) {
<script src="js/leaflet.pattern.js"></script>
<script src="js/fr.js"></script>
<script src="js/OauthOsm.js"></script>
<script src="js/MyNotification.js"></script>
<script src="js/Geocropping.js"></script>
<script src="js/index.js"></script>
<script src="js/leaflet-messagebox.js"></script>
......
"use strict";
/// <reference path="typings/tsd.d.ts" />
/// <reference path="typings/MyNotification.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
/**
*
......@@ -99,17 +100,19 @@ var Geocropping = (function () {
/**
* Attach events
*/
$(this._osm).on("requestError", function (data) {
var $osm = $(this._osm);
$osm.on("requestError", function (data) {
console.error('requestError', data);
$(_this).trigger('requestError', [data]);
});
$(this._osm).on('disconnected', function () {
$osm.on('disconnected', function () {
$(_this).trigger('userDisconnected');
_this._user = Geocropping.DEFAULT.USER;
});
$(this._osm).on('connected', function () {
$osm.on('connected', function () {
$(_this).trigger('userConnected');
//console.trace('myGeocropping', 'connected');
_this.notify.ConnectionOK();
_this.updateUserDetails();
});
}
......@@ -156,9 +159,24 @@ var Geocropping = (function () {
configurable: true
});
Geocropping.prototype.connect = function () {
this._osm.connect();
var _this = this;
var promise = this._osm.connect();
promise.then(function () { _this.notify.ConnectionOK(); }, function () { _this.notify.ConnectionNOK(); });
return this;
};
Geocropping.prototype.userDisconnect = function () {
var _this = this;
var promise = this._osm.disconnect();
promise.then(function () { _this.notify.DisconnectionOK(); }, function () { _this.notify.DisconnectionNOK(); });
return promise;
};
Object.defineProperty(Geocropping.prototype, "isConnected", {
get: function () {
return this._osm.isConnected;
},
enumerable: true,
configurable: true
});
Geocropping.prototype.updateUserDetails = function () {
var _this = this;
this._osm.getUserDetails().then(function (data) {
......@@ -182,16 +200,6 @@ var Geocropping = (function () {
});
return this;
};
Geocropping.prototype.userDisconnect = function () {
return this._osm.disconnect();
};
Object.defineProperty(Geocropping.prototype, "isConnected", {
get: function () {
return this._osm.isConnected;
},
enumerable: true,
configurable: true
});
Geocropping.prototype.getUserDetails = function () {
return this._user.id !== -1 ? this._user : null;
};
......@@ -235,6 +243,7 @@ var Geocropping = (function () {
//easeLinearity : 0.2,
worldCopyJump: true,
}).fitWorld();
this.notify = new MyNotification(geocropping._map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: this._map_maxZoom
......@@ -470,17 +479,22 @@ var Geocropping = (function () {
_this._osm._sendRequest(req).then(function (e) {
elementChanged();
// OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
_this.notify.ValidatedOK();
}, function (e) {
// ERR CloseChangeset
_this.notify.ValidatedNOK();
});
}, function (e) {
// ERR UpdateElement
_this.notify.ValidatedNOK();
});
}, function (e) {
// ERR CreateChangeset
_this.notify.ValidatedNOK();
});
}, function (e) {
// ERR GetElementId
_this.notify.ValidatedNOK();
});
});
popupEvent.popup._source.setStyle($.extend({}, _this._style_selected, { fill: (feature.geometry.type !== "LineString") }));
......@@ -597,10 +611,12 @@ var Geocropping = (function () {
Geocropping.prototype.setClickPosition = function (active) {
if (active) {
this._app_click_position_actived = true;
this.notify.ClicPositionON();
this._map.on('click', this._locationFoundClickFunction()).setMaxBounds(null);
}
else {
this._app_click_position_actived = false;
this.notify.ClicPositionOFF();
this._map.off('click', this._locationFoundClickFunction());
}
};
......@@ -659,7 +675,9 @@ var Geocropping = (function () {
};
Geocropping.prototype._locationError = function (options, data) {
var _this = this;
alert(data.message);
// alert(data.message);
console.log(data.message);
this.notify.LocalisationNOK();
if (options.forceWatch === true) {
setTimeout(function () {
_this._map.locate(options);
......@@ -776,6 +794,7 @@ var Geocropping = (function () {
},
error: function (jqXHR, textStatus, errorThrown) {