@osimatic/helpers-js 1.1.20 → 1.1.22
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/date_time.js +27 -0
- package/package.json +1 -1
- package/package.json.bak +0 -15
- package/paging.js.bak +0 -258
package/date_time.js
CHANGED
|
@@ -240,17 +240,37 @@ class DateTime {
|
|
|
240
240
|
return (jsDate1.getFullYear() == jsDate2.getFullYear() && jsDate1.getMonth() == jsDate2.getMonth() && jsDate1.getDate() == jsDate2.getDate());
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
static isDateInThePast(jsDate) {
|
|
244
|
+
jsDate.setHours(0);
|
|
245
|
+
jsDate.setMinutes(0);
|
|
246
|
+
jsDate.setSeconds(0);
|
|
247
|
+
jsDate.setMilliseconds(0);
|
|
248
|
+
let today = new Date();
|
|
249
|
+
today.setHours(0);
|
|
250
|
+
today.setMinutes(0);
|
|
251
|
+
today.setSeconds(0);
|
|
252
|
+
today.setMilliseconds(0);
|
|
253
|
+
return jsDate.getTime() < today.getTime();
|
|
254
|
+
}
|
|
255
|
+
|
|
243
256
|
static isDateInTheFuture(jsDate) {
|
|
244
257
|
jsDate.setHours(0);
|
|
245
258
|
jsDate.setMinutes(0);
|
|
246
259
|
jsDate.setSeconds(0);
|
|
260
|
+
jsDate.setMilliseconds(0);
|
|
247
261
|
let today = new Date();
|
|
248
262
|
today.setHours(0);
|
|
249
263
|
today.setMinutes(0);
|
|
250
264
|
today.setSeconds(0);
|
|
265
|
+
today.setMilliseconds(0);
|
|
251
266
|
return jsDate.getTime() > today.getTime();
|
|
252
267
|
}
|
|
253
268
|
|
|
269
|
+
static isDateTimeInThePast(jsDateTime) {
|
|
270
|
+
let today = new Date();
|
|
271
|
+
return jsDateTime < today;
|
|
272
|
+
}
|
|
273
|
+
|
|
254
274
|
static isDateTimeInTheFuture(jsDateTime) {
|
|
255
275
|
let today = new Date();
|
|
256
276
|
return jsDateTime > today;
|
|
@@ -354,6 +374,13 @@ class TimestampUnix {
|
|
|
354
374
|
return DateTime.getNbDayBetweenTwo(this.parse(timestamp1), this.parse(timestamp2), asPeriod, timeZone);
|
|
355
375
|
}
|
|
356
376
|
|
|
377
|
+
static isDateInThePast(timestamp) {
|
|
378
|
+
return DateTime.isDateInThePast(this.parse(timestamp));
|
|
379
|
+
}
|
|
380
|
+
static isDateTimeInThePast(timestamp) {
|
|
381
|
+
return DateTime.isDateTimeInThePast(this.parse(timestamp));
|
|
382
|
+
}
|
|
383
|
+
|
|
357
384
|
static isDateInTheFuture(timestamp) {
|
|
358
385
|
return DateTime.isDateInTheFuture(this.parse(timestamp));
|
|
359
386
|
}
|
package/package.json
CHANGED
package/package.json.bak
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@osimatic/helpers-js",
|
|
3
|
-
"version": "1.1.7",
|
|
4
|
-
"main": "main.js",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
-
},
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"description": "",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"ilib": "^14.16.0"
|
|
14
|
-
}
|
|
15
|
-
}
|
package/paging.js.bak
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
// Fonction commune de pagination
|
|
2
|
-
//Bootstrap class pagination https://getbootstrap.com/docs/3.3/components/#pagination
|
|
3
|
-
|
|
4
|
-
class Pagination {
|
|
5
|
-
static paginateCards(div, nbItemsPerPage, doublePagination) {
|
|
6
|
-
Pagination.paginate(div, div.find('.pagination_item'), nbItemsPerPage, undefined, doublePagination);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
static paginateTable(table, select, doublePagination) {
|
|
10
|
-
Pagination.paginate(table, table.find('tbody tr:not(.hide)'), parseInt(table.data('max_rows')), select, doublePagination);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
static paginate(div, items, nbItemsPerPage, select, doublePagination) {
|
|
14
|
-
let maxItems = nbItemsPerPage;
|
|
15
|
-
|
|
16
|
-
if (typeof div == 'undefined' || !div.length) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (typeof select != 'undefined' && select.length) {
|
|
21
|
-
if (!select.children().length) {
|
|
22
|
-
select.append('<option value="0">'+labelDisplayAll+'</option>');
|
|
23
|
-
let nbRowsList = select.data('nb_rows_list') ? select.data('nb_rows_list').split(',') : [5, 10, 25, 50];
|
|
24
|
-
$.each(nbRowsList, function(idx, nbRows) {
|
|
25
|
-
select.append('<option value="'+nbRows+'">'+nbRows+'</option>');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (select.data('default_nb_rows')) {
|
|
29
|
-
select.val(select.data('default_nb_rows'))
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
maxItems = parseInt(select.val());
|
|
34
|
-
|
|
35
|
-
select.change(update);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (doublePagination) {
|
|
39
|
-
Pagination.initPaginationDiv(div, $('ul.pagination'), true, true); //top
|
|
40
|
-
Pagination.initPaginationDiv(div, $('ul.pagination'), false, true); //bottom
|
|
41
|
-
} else {
|
|
42
|
-
Pagination.initPaginationDiv(div, $('ul.pagination'), false, false); //bottom
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
Pagination.initPaginationItems(items, maxItems, doublePagination);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static initPaginationDiv(div, ulDiv, onTop, doublePagination) {
|
|
49
|
-
if (!ulDiv.length || doublePagination) {
|
|
50
|
-
ulDiv = $('<ul class="pagination"></ul>');
|
|
51
|
-
if (div.find('.pagination_links').length) {
|
|
52
|
-
(onTop ? div.find('.pagination_links').prepend(ulDiv) : div.find('.pagination_links').append(ulDiv))
|
|
53
|
-
} else {
|
|
54
|
-
(onTop ? div.before(ulDiv) : div.after(ulDiv));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static initPaginationItems(items, maxItems, doublePagination) {
|
|
60
|
-
const paginationUl = $('ul.pagination');
|
|
61
|
-
|
|
62
|
-
let totalItems = items.length;
|
|
63
|
-
|
|
64
|
-
let lineNum = 0;
|
|
65
|
-
items.each(function () {
|
|
66
|
-
lineNum++;
|
|
67
|
-
if (0 === maxItems || lineNum <= maxItems) {
|
|
68
|
-
$(this).show();
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
$(this).hide();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
paginationUl.each((index, ul) => $(ul).find('li').remove());
|
|
76
|
-
|
|
77
|
-
if (0 === maxItems || totalItems < maxItems) {
|
|
78
|
-
paginationUl.each((index, ul) => $(ul).addClass('hide'));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let nbPages = Math.ceil(totalItems/maxItems);
|
|
83
|
-
for (let i=1; i <= nbPages; i++) {
|
|
84
|
-
paginationUl.each((index, ul) => $(ul).append('<li class="page-item" data-page="'+i+'"><a href="#" class="page-link">'+i+'<span class="sr-only">(current)</span></a></li>').show());
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
paginationUl.each((index, ul) => $(ul).removeClass('hide'));
|
|
88
|
-
paginationUl.each((index, ul) => $(ul).find('li:first-child').addClass('active'));
|
|
89
|
-
paginationUl.each((index, ul) => $(ul).find('li').click(function () {
|
|
90
|
-
paginationUl.each((index, ul) => $(ul).find('li').removeClass('active'));
|
|
91
|
-
|
|
92
|
-
let pageNum = $(this).data('page');
|
|
93
|
-
let trIndex = 0;
|
|
94
|
-
|
|
95
|
-
if (doublePagination) {
|
|
96
|
-
$('li[data-page="' + pageNum + '"]').each((index, li) => $(li).addClass('active'));
|
|
97
|
-
} else {
|
|
98
|
-
$(this).addClass('active');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
items.each(function () {
|
|
102
|
-
trIndex++;
|
|
103
|
-
if (trIndex > (maxItems*pageNum) || trIndex <= ((maxItems*pageNum)-maxItems)) {
|
|
104
|
-
$(this).hide();
|
|
105
|
-
}
|
|
106
|
-
else{
|
|
107
|
-
$(this).show();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
}));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
class Navigation {
|
|
117
|
-
static activateTab(a) {
|
|
118
|
-
//console.log(a);
|
|
119
|
-
//a.click();
|
|
120
|
-
let ulNav = a.closest('.nav');
|
|
121
|
-
let tabContent = ulNav.parent().find('.tab-content');
|
|
122
|
-
|
|
123
|
-
// déselection éventuel des onglets
|
|
124
|
-
ulNav.find('a.nav-link').each(function(idx, navLink) {
|
|
125
|
-
$(navLink).removeClass('active');
|
|
126
|
-
let id = $(navLink).attr('href');
|
|
127
|
-
if (id.substr(0, 1) === '#') {
|
|
128
|
-
tabContent.find(id).removeClass('active').removeClass('show');
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// sélection de l'onglet correspondant au navLink passé en paramètre
|
|
133
|
-
a.addClass('active');
|
|
134
|
-
tabContent.find(a.attr('href')).addClass('active').addClass('show');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
module.exports = { Pagination, Navigation };
|
|
139
|
-
|
|
140
|
-
// deprecated
|
|
141
|
-
/*
|
|
142
|
-
function paginationAsList(nbResultatsTotal, nbResultatsParPage, urlPage, nomParamPage) {
|
|
143
|
-
var currentUrl = urlPage || window.location.href;
|
|
144
|
-
var afficherLienFirstLastPage = true;
|
|
145
|
-
var afficherLienPagePrecedenteSuivante = true;
|
|
146
|
-
var emptyStringIfOnlyOnePage = true;
|
|
147
|
-
var nbLiensPageDebutFin = 3;
|
|
148
|
-
var nbLiensPageAvantApresPageCourante = 2;
|
|
149
|
-
var strEntreLiensPageDebutFinEtAvantApresPageCourante = '…';
|
|
150
|
-
nomParamPage = nomParamPage || 'page';
|
|
151
|
-
|
|
152
|
-
// Si le nombre de résultat total est inférieur au nombre d'affichage par page, il n'y a qu'une seule page.
|
|
153
|
-
if (nbResultatsTotal < nbResultatsParPage && emptyStringIfOnlyOnePage) {
|
|
154
|
-
return '';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Initialisation du nombre de pages
|
|
158
|
-
var nbPages = Math.ceil(nbResultatsTotal/nbResultatsParPage);
|
|
159
|
-
|
|
160
|
-
// Initialisation du numéro de la page courante
|
|
161
|
-
//var query = window.location.search.substring(1).query.split("&");
|
|
162
|
-
|
|
163
|
-
var url = new URL(currentUrl);
|
|
164
|
-
var params = url.searchParams;
|
|
165
|
-
|
|
166
|
-
var numPageCourante = 1;
|
|
167
|
-
if (typeof params.get(nomParamPage) != 'undefined' && params.get(nomParamPage) != null) {
|
|
168
|
-
numPageCourante = parseInt(params.get(nomParamPage));
|
|
169
|
-
}
|
|
170
|
-
if (numPageCourante < 0) {
|
|
171
|
-
numPageCourante = 1;
|
|
172
|
-
}
|
|
173
|
-
if (numPageCourante > nbPages) {
|
|
174
|
-
numPageCourante = nbPages;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
var strPagination = '<ul class="pagination">';
|
|
178
|
-
|
|
179
|
-
// Lien pour la première page
|
|
180
|
-
if (afficherLienFirstLastPage) {
|
|
181
|
-
var strLienFirstPage = '<<';
|
|
182
|
-
if (numPageCourante > 1) {
|
|
183
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, 1, currentUrl)+'">'+strLienFirstPage+'</a></li>';
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienFirstPage+'</a></li>';
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Lien pour la page précédente
|
|
191
|
-
if (afficherLienPagePrecedenteSuivante) {
|
|
192
|
-
var strLienPagePrecedente = '<';
|
|
193
|
-
if (numPageCourante > 1) {
|
|
194
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante - 1), currentUrl)+'">'+strLienPagePrecedente+'</a></li>';
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPagePrecedente+'</a></li>';
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
var strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = false;
|
|
202
|
-
var strEntreLiensPageFinEtApresPageCouranteDejaAffiche = false;
|
|
203
|
-
|
|
204
|
-
for (var numPage=1; numPage<=nbPages; numPage++) {
|
|
205
|
-
if (numPage < numPageCourante) {
|
|
206
|
-
if (numPage <= nbLiensPageDebutFin || numPage >= (numPageCourante-nbLiensPageAvantApresPageCourante)) {
|
|
207
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
if (!strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche) {
|
|
211
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
|
|
212
|
-
strEntreLiensPageDebutEtAvantPageCouranteDejaAffiche = true;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else if (numPage > numPageCourante) {
|
|
217
|
-
if (numPage >= (nbPages-(nbLiensPageDebutFin-1)) || numPage <= (numPageCourante+nbLiensPageAvantApresPageCourante)) {
|
|
218
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, numPage, currentUrl)+'">'+numPage+'</a></li>';
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
if (!strEntreLiensPageFinEtApresPageCouranteDejaAffiche) {
|
|
222
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strEntreLiensPageDebutFinEtAvantApresPageCourante+'</a></li>';
|
|
223
|
-
strEntreLiensPageFinEtApresPageCouranteDejaAffiche = true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
strPagination += '<li class="page-item active"><a class="page-link" href="#">'+numPage+'</a></li>';
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Lien pour la page suivante
|
|
233
|
-
if (afficherLienPagePrecedenteSuivante) {
|
|
234
|
-
var strLienPageSuivante = '>';
|
|
235
|
-
if (numPageCourante < nbPages) {
|
|
236
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, (numPageCourante + 1), currentUrl)+'">'+strLienPageSuivante+'</a></li>';
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienPageSuivante+'</a></li>';
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Lien pour la dernière page
|
|
244
|
-
if (afficherLienFirstLastPage) {
|
|
245
|
-
var strLienLastPage = '>>';
|
|
246
|
-
if (numPageCourante < nbPages) {
|
|
247
|
-
strPagination += '<li class="page-item"><a class="page-link" href="'+UrlAndQueryString.setParamOfUrl(nomParamPage, nbPages, currentUrl)+'">'+strLienLastPage+'</a></li>';
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
strPagination += '<li class="page-item disabled"><a class="page-link" href="#">'+strLienLastPage+'</a></li>';
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
strPagination += '</ul>';
|
|
255
|
-
|
|
256
|
-
return strPagination;
|
|
257
|
-
}
|
|
258
|
-
*/
|