@osimatic/helpers-js 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +1 -0
- package/changelog.txt +4 -1
- package/flash_message.js +1 -2
- package/form_helper.js +20 -0
- package/google_maps.js +1 -1
- package/index.js +19 -14
- package/number.js +10 -0
- package/open_street_map.js +132 -0
- package/package.json +1 -1
- package/string.js +7 -2
- package/util.js +1 -1
package/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm install @osimatic/helpers-js
|
package/changelog.txt
CHANGED
|
@@ -4,7 +4,7 @@ copierTexte(str) -> str.copyToClipboard()
|
|
|
4
4
|
truncateString(str, ...) -> str.truncateString(...)
|
|
5
5
|
|
|
6
6
|
NumberValue.isNumeric(str) -> str.isNumeric()
|
|
7
|
-
NumberValue.format(number, nbDecimal, locale) -> number.format(nbDecimal, locale)
|
|
7
|
+
NumberValue.format(number, nbDecimal, locale) -> number.format(nbDecimal, locale) OU Number.format(number, nbDecimal, locale)
|
|
8
8
|
NumberValue.formatCurrency(montant, currency, nbDecimal, locale) -> montant.formatCurrency(currency, nbDecimal, locale)
|
|
9
9
|
NumberValue.formatPercent(number, nbDecimal, locale) -> number.formatPercent(nbDecimal, locale)
|
|
10
10
|
NumberValue.random(min, max) -> Number.random(min, max)
|
|
@@ -23,3 +23,6 @@ renameKeysByCallback(...) -> Object.renameKeysByCallback(...)
|
|
|
23
23
|
getValuesByKeyInArrayOfArrays(...) -> Array.getValuesByKeyInArrayOfArrays(...)
|
|
24
24
|
getValuesByKeyInArrayOfArrays(array, ...) -> array.getValuesByKeyInArrayOfArrays(...)
|
|
25
25
|
|
|
26
|
+
hasGetUserMedia() -> non remplacé
|
|
27
|
+
|
|
28
|
+
paginationAsList(...) -> Pagination.paginate(...)
|
package/flash_message.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
class FlashMessage {
|
|
2
|
-
|
|
3
2
|
static displayRequestFailure(status, exception, modal) {
|
|
4
3
|
console.log('request failure. Status: ', status, ' Exception: ', exception);
|
|
5
|
-
this.display('danger', "Une erreur s'est produite.", false, modal);
|
|
4
|
+
this.display('danger', typeof labelErrorOccured != 'undefined' ? labelErrorOccured : "Une erreur s'est produite.", false, modal);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
static displaySuccess(message, reload, modal) {
|
package/form_helper.js
CHANGED
|
@@ -161,6 +161,26 @@ class FormHelper {
|
|
|
161
161
|
// Messages
|
|
162
162
|
// ------------------------------------------------------------
|
|
163
163
|
|
|
164
|
+
static extractErrorKeyOfJson(json, onlyIfUniqueError) {
|
|
165
|
+
if (typeof json == 'undefined' || json == null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (typeof json.error != 'undefined') {
|
|
170
|
+
return json.error;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (typeof onlyIfUniqueError != 'undefined' && onlyIfUniqueError && !json.length || json.length > 1) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (typeof json[0] != 'undefined' && typeof json[0].error != 'undefined') {
|
|
178
|
+
return json[0].error;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
|
|
164
184
|
static hideFormErrors(form) {
|
|
165
185
|
form.find('div.form_errors').remove();
|
|
166
186
|
return form;
|
package/google_maps.js
CHANGED
|
@@ -19,7 +19,7 @@ class GoogleMap {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
static getUrl(latitude, longitude) {
|
|
22
|
-
return '
|
|
22
|
+
return 'https://maps.google.com/?q='+latitude+','+longitude+'';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
static getUrlFromCoordinates(locationCoordinates) {
|
package/index.js
CHANGED
|
@@ -10,33 +10,38 @@ const { HTTPRequest, Cookie, UrlAndQueryString } = require('./network');
|
|
|
10
10
|
const { IBAN } = require('./bank');
|
|
11
11
|
const { AudioMedia } = require('./media');
|
|
12
12
|
const { PersonName, Email, TelephoneNumber } = require('./contact_details');
|
|
13
|
-
const { CountDown } = require('./count_down');
|
|
14
|
-
const { DataTable } = require('./data_table');
|
|
15
13
|
const { DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod } = require('./date_time');
|
|
16
|
-
const { DetailsSubArray } = require('./details_sub_array');
|
|
17
14
|
const { Duration } = require('./duration');
|
|
18
15
|
const { File, CSV, Img } = require('./file');
|
|
19
|
-
const { FlashMessage } = require('./flash_message');
|
|
20
16
|
const { FormHelper } = require('./form_helper');
|
|
21
|
-
const { GoogleMap } = require('./google_maps');
|
|
22
|
-
const { ImportFromCsv } = require('./import_from_csv');
|
|
23
|
-
const { JwtToken, JwtSession } = require('./jwt');
|
|
24
|
-
const { ListBox } = require('./list_box');
|
|
25
17
|
const { Country, PostalAddress, Location } = require('./location');
|
|
26
18
|
const { SocialNetwork } = require('./social_network');
|
|
27
|
-
const { NumberValue } = require('./number');
|
|
28
19
|
const { sleep, refresh } = require('./util');
|
|
29
20
|
const { chr, ord, trim, empty } = require('./php.min');
|
|
21
|
+
|
|
22
|
+
// exports plugins "maison"
|
|
23
|
+
const { DataTable } = require('./data_table');
|
|
30
24
|
const { Pagination, activateTab } = require('./paging');
|
|
25
|
+
const { FlashMessage } = require('./flash_message');
|
|
26
|
+
const { CountDown } = require('./count_down');
|
|
27
|
+
const { DetailsSubArray } = require('./details_sub_array');
|
|
28
|
+
const { ImportFromCsv } = require('./import_from_csv');
|
|
29
|
+
const { JwtToken, JwtSession } = require('./jwt');
|
|
30
|
+
const { ListBox } = require('./list_box');
|
|
31
|
+
|
|
32
|
+
// exports surcouche lib externe
|
|
31
33
|
const { GoogleCharts } = require('./google_charts');
|
|
32
34
|
const { GoogleRecaptcha } = require('./google_recaptcha');
|
|
35
|
+
const { GoogleMap } = require('./google_maps');
|
|
36
|
+
const { OpenStreetMap } = require('./open_street_map');
|
|
37
|
+
|
|
38
|
+
// deprecated
|
|
39
|
+
const { NumberValue } = require('./number');
|
|
33
40
|
|
|
34
41
|
module.exports = {
|
|
35
42
|
Array, Object, Number, String,
|
|
36
|
-
HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber,
|
|
37
|
-
|
|
38
|
-
FlashMessage, FormHelper, GoogleMap, ImportFromCsv, JwtToken, JwtSession, ListBox, Country, PostalAddress,
|
|
39
|
-
Location, SocialNetwork, NumberValue, Pagination,
|
|
43
|
+
HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber, DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, Location, SocialNetwork, NumberValue,
|
|
44
|
+
DataTable, Pagination, FlashMessage, CountDown, DetailsSubArray, ImportFromCsv, JwtToken, JwtSession, ListBox,
|
|
40
45
|
sleep, refresh, chr, ord, trim, empty,
|
|
41
|
-
GoogleCharts, GoogleRecaptcha
|
|
46
|
+
GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|
|
42
47
|
};
|
package/number.js
CHANGED
|
@@ -71,6 +71,16 @@ Number.prototype.format = Number.prototype.format || function(nbDecimal, locale)
|
|
|
71
71
|
}).format(this);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
if (!Number.format) {
|
|
75
|
+
Number.format = function(number, nbDecimal, locale) {
|
|
76
|
+
nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
|
|
77
|
+
return new Intl.NumberFormat(locale, {
|
|
78
|
+
minimumFractionDigits: nbDecimal,
|
|
79
|
+
maximumFractionDigits: nbDecimal
|
|
80
|
+
}).format(number);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
/**
|
|
75
85
|
* Number.prototype.format(n, x, s, c)
|
|
76
86
|
*
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://leafletjs.com/
|
|
3
|
+
* https://switch2osm.org/the-basics/
|
|
4
|
+
* https://www.openstreetmap.org/help
|
|
5
|
+
*/
|
|
6
|
+
class OpenStreetMap {
|
|
7
|
+
|
|
8
|
+
constructor(mapId, options) {
|
|
9
|
+
/*let [lat, lng] = button.data('coordinates').split(',');
|
|
10
|
+
let map = L.map('modal_map_canvas2').setView([lat, lng], 17);
|
|
11
|
+
|
|
12
|
+
L.marker([lat, lng], {
|
|
13
|
+
icon: L.icon({iconUrl: getIconOfMapMarker(button.data('type_marker'))}),
|
|
14
|
+
title: popoverContent.title
|
|
15
|
+
//popupopen: setTimeout(displayEmployeesAndCompaniesAndTasks, 250)
|
|
16
|
+
}).addTo(map)
|
|
17
|
+
.bindPopup(popoverContent.content)
|
|
18
|
+
//.openPopup()
|
|
19
|
+
;*/
|
|
20
|
+
|
|
21
|
+
this.markers = [];
|
|
22
|
+
this.locations = [];
|
|
23
|
+
this.mapId = mapId;
|
|
24
|
+
|
|
25
|
+
if (!$('#'+mapId).length) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.map = L.map(mapId, options || {});
|
|
30
|
+
|
|
31
|
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
32
|
+
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
33
|
+
}).addTo(this.map);
|
|
34
|
+
|
|
35
|
+
this.centerOnFrance();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static getUrl(latitude, longitude) {
|
|
39
|
+
return 'https://www.openstreetmap.org/?mlat='+latitude+'&mlon='+longitude+'#map=17/'+latitude+'/'+longitude+'&layers=N';
|
|
40
|
+
//return 'https://www.openstreetmap.org/#map=17/'+latitude+'/'+longitude+'';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getUrlFromCoordinates(locationCoordinates) {
|
|
44
|
+
locationCoordinates = locationCoordinates.split(',');
|
|
45
|
+
return this.getUrl(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setZoom(zoom) {
|
|
49
|
+
this.map.setZoom(zoom);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
deleteMarkers() {
|
|
53
|
+
this.locations = [];
|
|
54
|
+
|
|
55
|
+
//this.markers.forEach(marker => marker.setMap(null));
|
|
56
|
+
|
|
57
|
+
this.markers.length = 0;
|
|
58
|
+
this.markers = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addMarkers(listLocations, icon) {
|
|
62
|
+
if (listLocations.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
listLocations.forEach(location => this.addMarker(location, icon));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
addMarker(coordinates, options) {
|
|
70
|
+
let locationCoordinates = coordinates.split(',');
|
|
71
|
+
let latitude = parseFloat(locationCoordinates[0]);
|
|
72
|
+
let longitude = parseFloat(locationCoordinates[1]);
|
|
73
|
+
|
|
74
|
+
let marker = L.marker([latitude, longitude], {
|
|
75
|
+
icon: L.icon({
|
|
76
|
+
iconUrl: options['icon'],
|
|
77
|
+
iconSize: [22, 32],
|
|
78
|
+
}),
|
|
79
|
+
title: options['title'],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
//marker.on('click', () => {
|
|
83
|
+
marker.on('popupopen', () => {
|
|
84
|
+
console.log('popupopen');
|
|
85
|
+
if (typeof options['on_click'] == 'function') {
|
|
86
|
+
options['on_click']();
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
});
|
|
90
|
+
marker.addTo(this.map);
|
|
91
|
+
marker.bindPopup(options['popup_content']);
|
|
92
|
+
|
|
93
|
+
this.markers.push(marker);
|
|
94
|
+
this.locations.push([latitude, longitude]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
centerOnFrance() {
|
|
98
|
+
this.map.setView([46.52863469527167, 2.43896484375], 6);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
centerOnMarkers() {
|
|
102
|
+
this.map.invalidateSize(false);
|
|
103
|
+
|
|
104
|
+
if (this.locations.length === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.map.fitBounds(new L.LatLngBounds(this.locations));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
connectMarkers() {
|
|
112
|
+
if (this.locations.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let prevLocation = null;
|
|
117
|
+
let listLineCoordinates = [];
|
|
118
|
+
this.locations.forEach(location => {
|
|
119
|
+
if (prevLocation != null) {
|
|
120
|
+
listLineCoordinates.push([prevLocation, location]);
|
|
121
|
+
}
|
|
122
|
+
prevLocation = location;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
listLineCoordinates.forEach(line => {
|
|
126
|
+
L.polyline(line, {color: '#728bec'}).addTo(this.map);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { OpenStreetMap };
|
package/package.json
CHANGED
package/string.js
CHANGED
|
@@ -93,12 +93,17 @@ String.prototype.escapeHtml = String.prototype.escapeHtml || function() {
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
String.prototype.normalizeBreaks = String.prototype.normalizeBreaks || function(breaktype) {
|
|
96
|
-
|
|
96
|
+
// 20/01/2022 : modifié car ne fonctionnait pas pour les string en provenance de textarea, enregistrée en bd puis réaffiché depuis bd
|
|
97
|
+
//return this.replace(/$/mg, breaktype).replace(new RegExp('/'+breaktype.escapeRegExp()+'$/'), '');
|
|
98
|
+
return this.replace(/(?:\r\n|\r|\n)/g, breaktype);
|
|
99
|
+
//return this.replace('/(\r\n|\r|\n)/ms', breaktype);
|
|
97
100
|
//return this.replace('/(?:\r\n|\r|\n)/g', breaktype);
|
|
98
101
|
//console.log(breaktype);
|
|
99
102
|
//return this.replace(new RegExp('\r?\n','g'), breaktype);
|
|
100
103
|
};
|
|
101
|
-
|
|
104
|
+
String.prototype.escapeRegExp = String.prototype.escapeRegExp || function() {
|
|
105
|
+
return this.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
106
|
+
};
|
|
102
107
|
String.prototype.format = String.prototype.format || function() {
|
|
103
108
|
var args = arguments;
|
|
104
109
|
return this.replace(/{(\d+)}/g, (match, number) => (typeof args[number] != 'undefined' ? args[number] : match));
|
package/util.js
CHANGED