Commit 2719cba8 authored by Bastien Zigmann's avatar Bastien Zigmann Committed by Vincent Dubois

Ajout d'une checkbox pour pouvoir suivre un node et être notifié lors de sa prochaine mise à jour

parent ca843d6a
This diff is collapsed.
/// <reference path="typings/tsd.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
class MyNotification{
class MyNotification {
options = {timeout:4000, position:"bottomleft"};
options = { timeout: 4000, position: "bottomleft" };
notif;
box;
constructor(map:L.Map){
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
......@@ -20,42 +20,68 @@ class MyNotification{
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
ClicPositionOFF: "Reprise de la geolocalisation", //DONE
Modification: "Le fonctionnement a changé, nous n'utilisons plus les notes pour déclarer les objets mais le tag FIXME",
AjoutSinglePrefNOK: "Echec de l'ajout de la préférence",
AjoutSinglePrefOK: "Ajout de la préférence éffectué",
ChangementsTrouve: "Les éléments suivants ont été modifiés : "
};
}
ConnectionOK(){
ConnectionOK() {
this.box.show(this.notif.ConnectionOK);
}
ConnectionNOK(){
ConnectionNOK() {
this.box.show(this.notif.ConnectionNOK);
}
DisconnectionOK(){
DisconnectionOK() {
this.box.show(this.notif.DisconnectionOK);
}
DisconnectionNOK(){
DisconnectionNOK() {
this.box.show(this.notif.DisconnectionNOK);
}
ValidatedOK(){
ValidatedOK() {
this.box.show(this.notif.ValidatedOK);
}
ValidatedNOK(){
}
ValidatedNOK() {
this.box.show(this.notif.ValidatedNOK);
}
LocalisationNOK(){
LocalisationNOK() {
this.box.show(this.notif.LocalisationNOK);
}
AutoServerChanged(){
AutoServerChanged() {
this.box.show(this.notif.AutoServerChanged);
}
ServerChanged(){
ServerChanged() {
this.box.show(this.notif.ServerChanged);
}
ClicPositionON(){
ClicPositionON() {
this.box.show(this.notif.ClicPositionON);
}
ClicPositionOFF(){
ClicPositionOFF() {
this.box.show(this.notif.ClicPositionOFF);
}
Modification(){
this.box.options.timeout = 10000;
this.box.show(this.notif.Modification);
this.box.options.timeout = 4000;
}
ChangementsTrouve(changes: string[] | number[]) {
if (changes.length === 0) {}
else {
let text = this.notif.ChangementsTrouve;
for (let i = 0; i < changes.length; i++) {
text += `<a style='color: blue; ' href="https://www.openstreetmap.org/edit?node=${changes[i]}" target="_blank"> ${changes[i]} </a>`;
}
this.box.options.timeout += changes.length * 1000;
this.box.show(text);
this.box.options.timeout = 4000;
}
}
AjoutSinglePrefNOK(){
this.box.show(this.notif.AjoutSinglePrefNOK);
}
AjoutSinglePrefOK(){
this.box.show(this.notif.AjoutSinglePrefOK)
}
}
\ No newline at end of file
/// <reference path="typings/tsd.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
declare function osmAuth(any): any;
/// <reference path="myTypings/OauthOsm.d.ts" />
/**
*
* Gerer les requete pour OSM
*
* @class OauthOsm
*/
class OauthOsm {
//_oauth: any;
_token: {
key?: string;
secret?: string;
};
get _useSession() { return true }
_baseUrl = "";
_devApi = false;
/**
* Url pour effectuer les requetes
*
* @type {string}
* @memberof OauthOsm
*/
_baseUrl: string;
_storage_token_key_name = "OauthOsm-key";
_storage_token_secret_name = "OauthOsm-secret";
/**
* Utiliser le serveur OSM de dev
*
* @type {boolean}
* @memberof OauthOsm
*/
_devApi: boolean = false;
_connected = false;
/**
* Savoir si l'utilisateur est connecté
*
* @type {boolean}
* @memberof OauthOsm
*/
_connected: boolean = false;
/**
* Savoir si l'utilisateur est connecté
*
* @readonly
* @memberof OauthOsm
*/
get isConnected() { return this._connected };
/**
* Creates an instance of OauthOsm.
* @memberof OauthOsm
*/
constructor() {
/**@private */
this._token = {
key: null,
secret: null
};
this._loadToken();
// vérifier la connection
// Vérifier si l'utilisateur était déjà connecté
this.getUserDetails();
this._baseUrl = window.location.href + 'auth/';
}
static get apiRequest() {
/**
* Template des requêtes qui peuvent être envoyées
*
* @readonly
* @static
* @type {IDictionary<OauthOsm.ApiRequest>}
* @memberof OauthOsm
*/
static get apiRequest(): IDictionary<OauthOsm.ApiRequest> {
return {
// http://wiki.openstreetmap.org/wiki/API_v0.6
GetServerCapabilities: {
......@@ -81,13 +97,40 @@ class OauthOsm {
need_connection: true
},
// online=true
GetUserPreference: {
GetUserPreferences: {
method: 'GET',
url: '/',
request: 'GetUserPreferences',
params: {},
need_connection: true
},
// online=true
UpdateUserPreferences: {
method: 'POST',
url: '/',
request: 'UpdateUserPreferences',
params: {
content: JSON.stringify({
preferences: {
preference: [ //enlever ça pour nettoyer les preferences
//{ '@attributes': {k:'', v:''} }
]
}
}),
},
need_connection: true
},
// online=true
UpdateSingleUserPreference: {
method: 'POST',
url: '/',
request: 'UpdateSingleUserPreference',
params: {
key:"",
value:""
},
need_connection: true
},
GetUserId: {
method: 'GET',
url: '/',
......@@ -312,44 +355,14 @@ class OauthOsm {
};
}
_saveToken() {
if (!this._useSession) {
(this._token.key && localSave(this._storage_token_key_name, this._token.key));
(this._token.secret && localSave(this._storage_token_secret_name, this._token.secret));
}
}
/**
* Charge le token sauvegardé si existant.
*
* Si le stockage local est fonctionnel
* mais que le token est stocké dans un cookie,
* sauvegarde en utilisant la meilleur fonctionnalité
*
* Envoyer une requete a OSM
*
* @memberOf OauthOsm
*/
_loadToken() {
if (!this._useSession) {
let options = { systemUsed: "" };
this._token.key = localLoad(this._storage_token_key_name, options) || this._token.key;
this._token.secret = localLoad(this._storage_token_secret_name) || this._token.secret;
if (this.isTokenReady() && options.systemUsed !== "localStorage") {
this._saveToken();
}
}
}
/**
* Envoyer une requete listée dans OpenStreetMap._apiRequest
* @private
*
* @param {OauthOsm.apiRequest} apiRequest
*
* @return {Promise} Pour gérer les callbacks
* @param {OauthOsm.ApiRequest} apiRequest
* @returns
* @memberof OauthOsm
*/
_sendRequest(apiRequest) {
_sendRequest(apiRequest: OauthOsm.ApiRequest): JQueryPromise<{}> {
let deferred = $.Deferred();
if (typeof apiRequest !== 'object' || apiRequest.url === undefined || apiRequest.method === undefined) {
deferred.reject({
......@@ -364,10 +377,6 @@ class OauthOsm {
command: apiRequest.request,
options: apiRequest.params
};
if (!this._useSession) {
data['oauth_token'] = this._token.key;
data['access_secret'] = this._token.secret;
}
let url = this._baseUrl;
if (this._devApi) {
url += '?devMode=true';
......@@ -433,53 +442,8 @@ class OauthOsm {
$(this).triggerHandler("connected");
deferred.resolveWith(this);
} else {
/*let success = (data, textStatus, jqXHR) => {
//ouvrir la nouvelle fenetre + prépartion pour la réception du token
let windowConnect = window.open(data);
$(windowConnect).one('osmConnected', (e) => {
windowConnect.close();
this._token.key = e.data.key;
this._token.secret = e.data.secret;
this._saveToken();
$(this).triggerHandler("connected");
deferred.resolveWith(this);
});
};
let error = (...args) => {
//console.trace('myGeocropping',args);
deferred.rejectWith(this, args);
};
let request = $.ajax({
url: `${this._baseUrl}index.php`,
success: success,
error: error,
dataType: "text"
});*/
let url = this._baseUrl;
if (this._devApi) {
url += '?devMode=true';
}
let windowConnect = window.open(`${this._baseUrl}index.php${this._devApi ? '?devMode=true' : ''}`, '_self');
/*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);
}
}*/
window.open(`${this._baseUrl}index.php${this._devApi ? '?devMode=true' : '?devMode=false'}`, '_self');
}
return deferred.promise();
}
/**
......@@ -488,90 +452,25 @@ class OauthOsm {
*/
disconnect() {
let deferred = $.Deferred();
if (this._useSession) {
// detruire la session
$.ajax({
method: 'GET',
url: './auth/',
data: {
action: 'logout'
},
success: (data) => {
deferred.resolveWith(this);
this._connected = false;
$(this).trigger("disconnected");
},
error: (err) => {
deferred.rejectWith(this);
}
});
} else {
this._deleteTokens();
deferred.resolveWith(this);
$(this).trigger("disconnected");
}
return deferred.promise();
}
/**
* Vérifier si le token existe
*
* Test si l'utilisateur est connecté
* @public
*
* @return {JQueryXHR|Bool}
*/
/*isConnected() {
let deferred = $.Deferred();
if (this._useSession) {
$.ajax({
method: 'GET',
url: './auth/',
data: {
action: 'is_connected'
},
success: (data) => {
if (data.connected == 'true') {
deferred.resolveWith(this);
} else {
deferred.rejectWith(this);
}
},
error: () => {
deferred.rejectWith(this);
}
})
} else {
if (this.isTokenReady()) {
//tester le token
// detruire la session
$.ajax({
method: 'GET',
url: './auth/',
data: {
action: 'logout'
},
success: (data) => {
deferred.resolveWith(this);
} else {
this._connected = false;
$(this).trigger("disconnected");
},
error: (err) => {
deferred.rejectWith(this);
}
}
});
return deferred.promise();
}*/
/**
* Vérifier si le token existe.
* @public
*
* @return {Bool}
*/
isTokenReady(): boolean {
return (this._token.key !== null && this._token.secret !== null);
}
/**
* Remove token
* @private
*
*/
_deleteTokens() {
this._token.key = null;
this._token.secret = null;
localDelete(this._storage_token_key_name);
localDelete(this._storage_token_secret_name);
}
}
/**
......@@ -709,10 +608,10 @@ function localLoad(name: string, options: { useLocalStorageOrCookie?: boolean, u
/**
* Delete data on browser storage
*
* @param {any} name
* @param {string} name
* @param {{ useLocalStorage?: boolean, useCookie?: boolean, cookie?: { path?: string } }} [options={}]
*/
function localDelete(name, options: { useLocalStorage?: boolean, useCookie?: boolean, cookie?: { path?: string } } = {}) {
function localDelete(name: string, options: { useLocalStorage?: boolean, useCookie?: boolean, cookie?: { path?: string } } = {}) {
"use strict";
// Test of value type
......@@ -733,67 +632,3 @@ function localDelete(name, options: { useLocalStorage?: boolean, useCookie?: boo
deleteCookie(name, options.cookie.path);
}
}
function parseText(sValue) {
"use strict";
if (/^\s*$/.test(sValue)) {
return null;
}
if (/^(?:true|false)$/i.test(sValue)) {
return sValue.toLowerCase() === "true";
}
if (isFinite(sValue)) {
return parseFloat(sValue);
}
if (isFinite(Date.parse(sValue))) {
return new Date(sValue);
}
return sValue;
}
function getJXONTree(oXMLParent) {
"use strict";
let vResult = /* put here the default value for empty nodes! */ null,
nLength = 0,
sCollectedTxt = "",
oAttrib;
if (oXMLParent.hasAttributes && oXMLParent.hasAttributes()) {
vResult = {};
for (nLength; nLength < oXMLParent.attributes.length; nLength++) {
oAttrib = oXMLParent.attributes.item(nLength);
vResult["@" + oAttrib.name.toLowerCase()] = parseText(oAttrib.value.trim());
}
}
if (oXMLParent.hasChildNodes()) {
for (let oNode, sProp, vContent, nItem = 0; nItem < oXMLParent.childNodes.length; nItem++) {
oNode = oXMLParent.childNodes.item(nItem);
if (oNode.nodeType === 4) {
sCollectedTxt += oNode.nodeValue;
} /* nodeType is "CDATASection" (4) */
else if (oNode.nodeType === 3) {
sCollectedTxt += oNode.nodeValue.trim();
} /* nodeType is "Text" (3) */
else if (oNode.nodeType === 1 && !oNode.prefix) { /* nodeType is "Element" (1) */
if (nLength === 0) {
vResult = {};
}
sProp = oNode.nodeName.toLowerCase();
vContent = getJXONTree(oNode);
if (vResult.hasOwnProperty(sProp)) {
if (vResult[sProp].constructor !== Array) {
vResult[sProp] = [vResult[sProp]];
}
vResult[sProp].push(vContent);
} else {
vResult[sProp] = vContent;
nLength++;
}
}
}
}
if (sCollectedTxt) {
nLength > 0 ? vResult.keyValue = parseText(sCollectedTxt) : vResult = parseText(sCollectedTxt);
}
/* if (nLength > 0) { Object.freeze(vResult); } */
return vResult;
}
\ No newline at end of file
/// <reference path="typings/tsd.d.ts" />
/// <reference path="myTypings/tsd.d.ts" />
/**
* Ouvre le menu de droite si le il est fermé et inversement
*
*/
function toggleRightMenu() {
let actualRight = $('body')[0].offsetWidth - $('.side-nav.fit-right')[0].offsetLeft;
if (actualRight !== 0)
......@@ -9,6 +13,10 @@ function toggleRightMenu() {
openRightMenu();
}
/**
* Ouvre le menu de gauche si le il est fermé et inversement
*
*/
function toggleLeftMenu() {
if ($('.side-nav.fit-left').position().left + $('.side-nav.fit-left').width() !== 0)
closeLeftMenu();
......@@ -16,9 +24,18 @@ function toggleLeftMenu() {
openLeftMenu();
}
/**
* Fermer le menu de gauche
*
*/
function closeLeftMenu() {
openLeftMenu(0);
}
/**
* Ouvre le menu de gauche
*
* @param {number} [width] Largeur du menu
*/
function openLeftMenu(width?: number) {
(width === undefined) && (width = $('.side-nav.fit-left').width());
if (width === 0)
......@@ -29,9 +46,18 @@ function openLeftMenu(width?: number) {
}
$('#mapArea').css('left', width);
}
/**
* Fermer le menu de droite
*
*/
function closeRightMenu() {
openRightMenu(0);
}
/**
* Ouvre le menu de gauche
*
* @param {number} [width] Largeur du menu
*/
function openRightMenu(width?: number) {
(width === undefined) && (width = $('.side-nav.fit-right').width());
if (width === 0)
......@@ -42,17 +68,22 @@ function openRightMenu(width?: number) {
}
$('#mapArea').css('right', width);
}
let geocropping = new Geocropping();
$(document).ready(() => {
let geocropping = new Geocropping();
$(document).ready(() => {
let $geocropping = $(geocropping);
// Ajouter les serveur Overpass dans le menu déroulant
for (var key in geocropping._app_server_interpreter_list) {
$('#urlInterpreter').append(`<option value="${key}">${key}</option>`);
}
}
////////
// EVENTS
// Si le serveur Overpass est changé par Geocropping.ts
$geocropping.on('urlInterpreterUpdated', (e, index) => {
$('#urlInterpreter').val(index);
});
$('#userAction #login').click(() => {
......@@ -62,16 +93,19 @@ $(document).ready(() => {
geocropping.userDisconnect();
});
// Checkbox pour se déplacer sur la carte au clic