@osimatic/helpers-js 1.4.26 → 1.4.28
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/index.js +2 -2
- package/multiple_action_in_table.js +27 -11
- package/number.js +26 -1
- package/package.json +1 -1
- package/tests/number.test.js +45 -0
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ const { HexColor, RgbColor } = require('./draw');
|
|
|
21
21
|
const { SocialNetwork } = require('./social_network');
|
|
22
22
|
const { sleep, refresh } = require('./util');
|
|
23
23
|
const { chr, ord, trim, empty } = require('./php.min');
|
|
24
|
-
const { NumberFormatter } = require('./number');
|
|
24
|
+
const { NumberFormatter, Rating } = require('./number');
|
|
25
25
|
const { Password } = require('./user');
|
|
26
26
|
|
|
27
27
|
// exports plugins "maison"
|
|
@@ -52,7 +52,7 @@ const { WebSocket } = require('./web_socket');
|
|
|
52
52
|
|
|
53
53
|
module.exports = {
|
|
54
54
|
Array, Object, Number, String,
|
|
55
|
-
HTTPClient, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, VideoMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, DatePeriod, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, Polygon, HexColor, RgbColor, SocialNetwork, NumberFormatter, Password,
|
|
55
|
+
HTTPClient, Cookie, UrlAndQueryString, IBAN, BankCard, AudioMedia, VideoMedia, UserMedia, PersonName, Email, TelephoneNumber, DateTime, DatePeriod, TimestampUnix, SqlDate, SqlTime, SqlDateTime, Duration, File, CSV, Img, FormHelper, Country, PostalAddress, GeographicCoordinates, Polygon, HexColor, RgbColor, SocialNetwork, NumberFormatter, Rating, Password,
|
|
56
56
|
Browser, DataTable, Pagination, Navigation, DetailsSubArray, SelectAll, MultipleActionInTable, MultipleActionInDivList, MultiFilesInput, EditValue, FormDate, InputPeriod, ShoppingCart, FlashMessage, CountDown, ImportFromCsv, JwtToken, JwtSession, ApiTokenSession, ListBox, WebRTC, WebSocket, EventBus,
|
|
57
57
|
sleep, refresh, chr, ord, trim, empty,
|
|
58
58
|
Chartjs, GoogleCharts, GoogleRecaptcha, GoogleMap, OpenStreetMap
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
|
|
2
2
|
class MultipleActionInTable {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
// Ajoute les colonnes select (thead th + tbody td) dans le DOM.
|
|
5
|
+
// Idempotent : sans effet si les colonnes existent déjà.
|
|
6
|
+
// Doit être appelé AVANT l'initialisation DataTable.
|
|
7
|
+
static initCols(table, cellCssClass = 'select') {
|
|
8
|
+
if (!table.hasClass('table-action_multiple')) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (MultipleActionInTable.getDivBtn(table) == null) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (table.find('thead tr th[data-key="select"]').length === 0) {
|
|
16
|
+
table.find('thead tr').prepend($('<th class="' + cellCssClass + '" data-key="select"></th>'));
|
|
17
|
+
}
|
|
18
|
+
table.find('tbody tr:not(.no_items)').each(function(idx, tr) {
|
|
19
|
+
if ($(tr).find('td.select').length === 0) {
|
|
20
|
+
$(tr).prepend($('<td class="select"><input type="checkbox" class="action_multiple_checkbox" name="' + $(tr).data('action_multiple_input_name') + '" value="' + $(tr).data('action_multiple_item_id') + '"></td>'));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Initialise les colonnes (via initCols) puis branche les event handlers.
|
|
26
|
+
// Peut être appelé après l'initialisation DataTable.
|
|
27
|
+
static init(table, cellCssClass = 'select') {
|
|
5
28
|
if (!table.hasClass('table-action_multiple')) {
|
|
6
29
|
return;
|
|
7
30
|
}
|
|
@@ -11,21 +34,14 @@ class MultipleActionInTable {
|
|
|
11
34
|
return;
|
|
12
35
|
}
|
|
13
36
|
|
|
37
|
+
MultipleActionInTable.initCols(table, cellCssClass);
|
|
38
|
+
|
|
14
39
|
if (!divBtn.hasClass('action_multiple_buttons_initialized')) {
|
|
15
40
|
divBtn.prepend($('<img src="'+ROOT_PATH+DOSSIER_IMAGES+'arrow_ltr.png" alt="" /> '));
|
|
16
41
|
divBtn.append($('<br/><br/>'));
|
|
17
42
|
divBtn.addClass('action_multiple_buttons_initialized');
|
|
18
43
|
}
|
|
19
44
|
|
|
20
|
-
if (table.find('thead tr th[data-key="select"]').length === 0) {
|
|
21
|
-
table.find('thead tr').prepend($('<th class="'+cellCssClass+'" data-key="select"></th>'));
|
|
22
|
-
}
|
|
23
|
-
table.find('tbody tr:not(.no_items)').each(function(idx, tr) {
|
|
24
|
-
if ($(tr).find('td.select').length === 0) {
|
|
25
|
-
$(tr).prepend($('<td class="select"><input type="checkbox" class="action_multiple_checkbox" name="'+$(tr).data('action_multiple_input_name')+'" value="'+$(tr).data('action_multiple_item_id')+'"></td>'));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
45
|
let firstTh = table.find('thead tr th').first();
|
|
30
46
|
if (firstTh.find('input').length === 0) {
|
|
31
47
|
firstTh.html('<input type="checkbox" class="action_multiple_check_all" />');
|
package/number.js
CHANGED
|
@@ -96,4 +96,29 @@ if (!Number.random) {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
class Rating {
|
|
100
|
+
static display(rating, maxRating = 5, imgOn = '★', imgOff = '☆', imgHalf = null) {
|
|
101
|
+
if (rating == null) {
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const fullStars = Math.floor(rating);
|
|
106
|
+
const decimal = rating - fullStars;
|
|
107
|
+
|
|
108
|
+
let totalFull = fullStars;
|
|
109
|
+
let showHalf = false;
|
|
110
|
+
|
|
111
|
+
if (imgHalf !== null && decimal >= 0.25 && decimal < 0.75) {
|
|
112
|
+
showHalf = true;
|
|
113
|
+
}
|
|
114
|
+
else if (decimal >= (imgHalf !== null ? 0.75 : 0.5)) {
|
|
115
|
+
totalFull++;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return imgOn.repeat(totalFull)
|
|
119
|
+
+ (showHalf ? imgHalf : '')
|
|
120
|
+
+ imgOff.repeat(maxRating - totalFull - (showHalf ? 1 : 0));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { NumberFormatter, Rating };
|
package/package.json
CHANGED
package/tests/number.test.js
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
require('../number');
|
|
2
|
+
const { Rating } = require('../number');
|
|
3
|
+
|
|
4
|
+
describe('Rating', () => {
|
|
5
|
+
describe('display', () => {
|
|
6
|
+
test('should return empty string for null rating', () => {
|
|
7
|
+
expect(Rating.display(null)).toBe('');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('should display full stars only', () => {
|
|
11
|
+
expect(Rating.display(3, 5)).toBe('★★★☆☆');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should round up at 0.5', () => {
|
|
15
|
+
expect(Rating.display(3.5, 5)).toBe('★★★★☆');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should round down below 0.5', () => {
|
|
19
|
+
expect(Rating.display(3.4, 5)).toBe('★★★☆☆');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('should display max rating', () => {
|
|
23
|
+
expect(Rating.display(5, 5)).toBe('★★★★★');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should display zero rating', () => {
|
|
27
|
+
expect(Rating.display(0, 5)).toBe('☆☆☆☆☆');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should show half star when imgHalf provided and decimal in [0.25, 0.75)', () => {
|
|
31
|
+
expect(Rating.display(3.5, 5, '★', '☆', '½')).toBe('★★★½☆');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('should round up with imgHalf when decimal >= 0.75', () => {
|
|
35
|
+
expect(Rating.display(3.8, 5, '★', '☆', '½')).toBe('★★★★☆');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('should round down with imgHalf when decimal < 0.25', () => {
|
|
39
|
+
expect(Rating.display(3.1, 5, '★', '☆', '½')).toBe('★★★☆☆');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should support custom image strings', () => {
|
|
43
|
+
expect(Rating.display(2, 3, '[on]', '[off]')).toBe('[on][on][off]');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
2
47
|
|
|
3
48
|
describe('NumberFormatter', () => {
|
|
4
49
|
const { NumberFormatter } = require('../number');
|