@iankibetsh/shframework 1.1.7 → 1.1.9

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/dist/library.js CHANGED
@@ -209,6 +209,15 @@ function formatDate(date, format) {
209
209
  }
210
210
  return moment__default["default"](date).format(format)
211
211
  }
212
+ function formatNumber(amount,decimalPoints = 0){
213
+ return numberFormat(amount,decimalPoints)
214
+ }
215
+ function numberFormat(amount,decimalPoints = 0) {
216
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
217
+ formatted = new Intl.NumberFormat().format(formatted);
218
+ const formattedArr = formatted.split('.');
219
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
220
+ }
212
221
 
213
222
  var shRepo = {
214
223
  swalSuccess,
@@ -221,7 +230,9 @@ var shRepo = {
221
230
  runSilentRequest,
222
231
  swalHttpError,
223
232
  formatHttpCatchError,
224
- formatDate
233
+ formatDate,
234
+ numberFormat,
235
+ formatNumber
225
236
  };
226
237
 
227
238
  startSession();
@@ -232,10 +243,16 @@ function logoutUser(){
232
243
  ShStorage.removeItem('access_token');
233
244
  ShStorage.removeItem('user');
234
245
  ShStorage.removeItem('last_activity');
246
+ if(window.shInterval){
247
+ clearInterval(window.shInterval);
248
+ }
235
249
  window.location.href = loginUrl;
236
250
  }).catch(ex=>{
237
251
  ShStorage.removeItem('access_token');
238
252
  ShStorage.removeItem('user');
253
+ if(window.shInterval){
254
+ clearInterval(window.shInterval);
255
+ }
239
256
  window.location.href = loginUrl;
240
257
  });
241
258
  ShStorage.getItem('user');
@@ -248,18 +265,15 @@ const checkSession = function (isCheking) {
248
265
  const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
249
266
  if(pastMinutes >= timeout) {
250
267
  const gracePeriod = pastSeconds - (timeout * 60);
251
- if (gracePeriod >= 30 ) {
268
+ if (gracePeriod >= 60 ) {
252
269
  logoutUser();
253
270
  }
254
271
  else {
255
272
  if (!window.ShConfirmation)
256
273
  {
257
- window.ShConfirmation = shSwalLogout();
274
+ window.ShConfirmation = shSwalLogout(30);
258
275
  }
259
276
  }
260
- } else {
261
- console.log(pastSeconds);
262
- console.log(pastMinutes);
263
277
  }
264
278
  }else {
265
279
  if (window.shInterval) {
@@ -267,23 +281,35 @@ const checkSession = function (isCheking) {
267
281
  }
268
282
  }
269
283
  };
270
-
271
- async function shSwalLogout () {
284
+ async function shSwalLogout (seconds = 30) {
285
+ let timerInterval;
272
286
  return Swal__default["default"].fire({
273
287
  title: 'Your session is about to Expire!',
274
- html: 'You will be logout due to inactivity!',
288
+ html: 'You will be logged out in <strong></strong> seconds due to inactivity!',
275
289
  showCancelButton: true,
276
290
  cancelButtonColor: '#32c787',
277
291
  confirmButtonColor: '#000',
278
292
  cancelButtonText: 'Stay signed in',
279
293
  confirmButtonText: 'Sign out now!',
280
- timer: 100000,
294
+ timer: seconds * 1000,
281
295
  allowOutsideClick: false,
282
296
  reverseButtons: true,
283
297
  showLoaderOnConfirm: true,
298
+ didOpen(popup) {
299
+ timerInterval = setInterval(() => {
300
+ Swal__default["default"].getHtmlContainer().querySelector('strong')
301
+ .textContent = (Swal__default["default"].getTimerLeft() / 1000)
302
+ .toFixed(0);
303
+ }, 100);
304
+ },
305
+ willClose: () => {
306
+ clearInterval(timerInterval);
307
+ }
284
308
  }).then((result) => {
285
309
  if (result.isConfirmed) {
286
310
  logoutUser();
311
+ } else if(result.dismiss === 'timer'){
312
+ logoutUser();
287
313
  } else {
288
314
  window.ShConfirmation = null;
289
315
  clearInterval(window.shInterval);
package/dist/library.mjs CHANGED
@@ -197,6 +197,15 @@ function formatDate(date, format) {
197
197
  }
198
198
  return moment(date).format(format)
199
199
  }
200
+ function formatNumber(amount,decimalPoints = 0){
201
+ return numberFormat(amount,decimalPoints)
202
+ }
203
+ function numberFormat(amount,decimalPoints = 0) {
204
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
205
+ formatted = new Intl.NumberFormat().format(formatted);
206
+ const formattedArr = formatted.split('.');
207
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
208
+ }
200
209
 
201
210
  var shRepo = {
202
211
  swalSuccess,
@@ -209,7 +218,9 @@ var shRepo = {
209
218
  runSilentRequest,
210
219
  swalHttpError,
211
220
  formatHttpCatchError,
212
- formatDate
221
+ formatDate,
222
+ numberFormat,
223
+ formatNumber
213
224
  };
214
225
 
215
226
  startSession();
@@ -220,10 +231,16 @@ function logoutUser(){
220
231
  ShStorage.removeItem('access_token');
221
232
  ShStorage.removeItem('user');
222
233
  ShStorage.removeItem('last_activity');
234
+ if(window.shInterval){
235
+ clearInterval(window.shInterval);
236
+ }
223
237
  window.location.href = loginUrl;
224
238
  }).catch(ex=>{
225
239
  ShStorage.removeItem('access_token');
226
240
  ShStorage.removeItem('user');
241
+ if(window.shInterval){
242
+ clearInterval(window.shInterval);
243
+ }
227
244
  window.location.href = loginUrl;
228
245
  });
229
246
  ShStorage.getItem('user');
@@ -236,18 +253,15 @@ const checkSession = function (isCheking) {
236
253
  const pastSeconds = moment().diff(last_activity, 'seconds');
237
254
  if(pastMinutes >= timeout) {
238
255
  const gracePeriod = pastSeconds - (timeout * 60);
239
- if (gracePeriod >= 30 ) {
256
+ if (gracePeriod >= 60 ) {
240
257
  logoutUser();
241
258
  }
242
259
  else {
243
260
  if (!window.ShConfirmation)
244
261
  {
245
- window.ShConfirmation = shSwalLogout();
262
+ window.ShConfirmation = shSwalLogout(30);
246
263
  }
247
264
  }
248
- } else {
249
- console.log(pastSeconds);
250
- console.log(pastMinutes);
251
265
  }
252
266
  }else {
253
267
  if (window.shInterval) {
@@ -255,23 +269,35 @@ const checkSession = function (isCheking) {
255
269
  }
256
270
  }
257
271
  };
258
-
259
- async function shSwalLogout () {
272
+ async function shSwalLogout (seconds = 30) {
273
+ let timerInterval;
260
274
  return Swal.fire({
261
275
  title: 'Your session is about to Expire!',
262
- html: 'You will be logout due to inactivity!',
276
+ html: 'You will be logged out in <strong></strong> seconds due to inactivity!',
263
277
  showCancelButton: true,
264
278
  cancelButtonColor: '#32c787',
265
279
  confirmButtonColor: '#000',
266
280
  cancelButtonText: 'Stay signed in',
267
281
  confirmButtonText: 'Sign out now!',
268
- timer: 100000,
282
+ timer: seconds * 1000,
269
283
  allowOutsideClick: false,
270
284
  reverseButtons: true,
271
285
  showLoaderOnConfirm: true,
286
+ didOpen(popup) {
287
+ timerInterval = setInterval(() => {
288
+ Swal.getHtmlContainer().querySelector('strong')
289
+ .textContent = (Swal.getTimerLeft() / 1000)
290
+ .toFixed(0);
291
+ }, 100);
292
+ },
293
+ willClose: () => {
294
+ clearInterval(timerInterval);
295
+ }
272
296
  }).then((result) => {
273
297
  if (result.isConfirmed) {
274
298
  logoutUser();
299
+ } else if(result.dismiss === 'timer'){
300
+ logoutUser();
275
301
  } else {
276
302
  window.ShConfirmation = null;
277
303
  clearInterval(window.shInterval);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",