@iankibetsh/shframework 1.1.8 → 1.2.1

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.
@@ -63,21 +63,6 @@
63
63
  color: white;
64
64
  }
65
65
 
66
- .sh-selected-item{
67
- line-height: unset!important;
68
- }
69
- .sh-suggestion-input{
70
- padding: 0.375rem 0.75rem;
71
- }
72
- .sh-suggest{
73
- margin-bottom: 1rem;
74
- }
75
- .sh-suggest-control::after{
76
- margin-top: auto;
77
- margin-bottom: auto;
78
- margin-right: 0.255em;
79
- }
80
-
81
66
  :root {
82
67
  --ck-z-default: 10555 !important;
83
68
  --ck-z-modal: calc(var(--ck-z-default) + 999) !important;
@@ -99,6 +84,21 @@
99
84
  }
100
85
  }
101
86
 
87
+ .sh-selected-item{
88
+ line-height: unset!important;
89
+ }
90
+ .sh-suggestion-input{
91
+ padding: 0.375rem 0.75rem;
92
+ }
93
+ .sh-suggest{
94
+ margin-bottom: 1rem;
95
+ }
96
+ .sh-suggest-control::after{
97
+ margin-top: auto;
98
+ margin-bottom: auto;
99
+ margin-right: 0.255em;
100
+ }
101
+
102
102
  .sh-forgot-link, .sh-register-link{
103
103
  cursor: pointer;
104
104
  }
package/dist/library.js CHANGED
@@ -5,10 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var Axios = require('axios');
6
6
  var moment = require('moment');
7
7
  var Swal = require('sweetalert2');
8
+ var shApis$1 = require('@/lib/repo/helpers/ShApis.js');
8
9
  var vue = require('vue');
9
10
  var NProgress = require('nprogress');
10
11
  var Editor = require('@tinymce/tinymce-vue');
11
12
  var pinia = require('pinia');
13
+ var shRepo$1 = require('@/lib/repo/helpers/ShRepo.js');
12
14
  var vueRouter = require('vue-router');
13
15
 
14
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -16,8 +18,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
18
  var Axios__default = /*#__PURE__*/_interopDefaultLegacy(Axios);
17
19
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
18
20
  var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
21
+ var shApis__default = /*#__PURE__*/_interopDefaultLegacy(shApis$1);
19
22
  var NProgress__default = /*#__PURE__*/_interopDefaultLegacy(NProgress);
20
23
  var Editor__default = /*#__PURE__*/_interopDefaultLegacy(Editor);
24
+ var shRepo__default = /*#__PURE__*/_interopDefaultLegacy(shRepo$1);
21
25
 
22
26
  function setItem (key, value) {
23
27
  let toStore = value;
@@ -135,6 +139,23 @@ function getMenuCount (url) {
135
139
  });
136
140
  }
137
141
 
142
+ const signOutUser = ()=>{
143
+ const loginUrl = getShConfig('loginUrl','auth/login');
144
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
145
+ console.log(loginUrl,logoutApiEndPoint);
146
+ shApis__default["default"].doPost(logoutApiEndPoint).then(res=>{
147
+ ShStorage.removeItem('access_token');
148
+ ShStorage.removeItem('user');
149
+ ShStorage.removeItem('last_activity');
150
+ window.location.href = loginUrl;
151
+ }).catch(ex=>{
152
+ ShStorage.removeItem('access_token');
153
+ ShStorage.removeItem('user');
154
+ ShStorage.removeItem('last_activity');
155
+ window.location.href = loginUrl;
156
+ });
157
+ };
158
+
138
159
 
139
160
  const Toast = Swal__default["default"].mixin({
140
161
  toast: true,
@@ -151,9 +172,11 @@ const Toast = Swal__default["default"].mixin({
151
172
  toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
152
173
  }
153
174
  });
154
- function getConfig() {
175
+ function getShConfig(key = null,def = '') {
155
176
  const config = ShStorage.getItem('ShConfig');
156
- console.log(config);
177
+ if(key) {
178
+ return config[key] ?? def
179
+ }
157
180
  return config
158
181
  }
159
182
  function showToast (message, toastType, position) {
@@ -209,6 +232,15 @@ function formatDate(date, format) {
209
232
  }
210
233
  return moment__default["default"](date).format(format)
211
234
  }
235
+ function formatNumber(amount,decimalPoints = 0){
236
+ return numberFormat(amount,decimalPoints)
237
+ }
238
+ function numberFormat(amount,decimalPoints = 0) {
239
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
240
+ formatted = new Intl.NumberFormat().format(formatted);
241
+ const formattedArr = formatted.split('.');
242
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
243
+ }
212
244
 
213
245
  var shRepo = {
214
246
  swalSuccess,
@@ -216,29 +248,32 @@ var shRepo = {
216
248
  runPlainRequest,
217
249
  getMenuCount,
218
250
  setTabCounts,
219
- getConfig,
251
+ getShConfig,
220
252
  showToast,
221
253
  runSilentRequest,
222
254
  swalHttpError,
223
255
  formatHttpCatchError,
224
- formatDate
256
+ formatDate,
257
+ numberFormat,
258
+ formatNumber,
259
+ signOutUser
225
260
  };
226
261
 
227
262
  startSession();
228
263
  function logoutUser(){
229
- const loginUrl = shRepo.getConfig().loginUrl;
230
- const logoutApiEndpoint = vue.inject('logoutApiEndpoint','auth/logout');
231
- shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
232
- ShStorage.removeItem('access_token');
233
- ShStorage.removeItem('user');
234
- ShStorage.removeItem('last_activity');
235
- window.location.href = loginUrl;
236
- }).catch(ex=>{
237
- ShStorage.removeItem('access_token');
238
- ShStorage.removeItem('user');
239
- window.location.href = loginUrl;
240
- });
241
- ShStorage.getItem('user');
264
+ if(!sessionRestored()){
265
+ shRepo.signOutUser();
266
+ } else {
267
+ console.log('session has been restored in another tab');
268
+ }
269
+ }
270
+ function sessionRestored(){
271
+ const timeout = ShStorage.getItem('sessionTimeout') * 60;
272
+ const last_activity = ShStorage.getItem('last_activity');
273
+ const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
274
+ if(!ShStorage.getItem('access_token'))
275
+ return false
276
+ return pastSeconds < timeout
242
277
  }
243
278
  const checkSession = function (isCheking) {
244
279
  const timeout = ShStorage.getItem('sessionTimeout');
@@ -248,13 +283,13 @@ const checkSession = function (isCheking) {
248
283
  const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
249
284
  if(pastMinutes >= timeout) {
250
285
  const gracePeriod = pastSeconds - (timeout * 60);
251
- if (gracePeriod >= 30 ) {
286
+ if (gracePeriod >= 60 ) {
252
287
  logoutUser();
253
288
  }
254
289
  else {
255
290
  if (!window.ShConfirmation)
256
291
  {
257
- window.ShConfirmation = shSwalLogout();
292
+ window.ShConfirmation = shSwalLogout(30);
258
293
  }
259
294
  }
260
295
  }
@@ -264,23 +299,39 @@ const checkSession = function (isCheking) {
264
299
  }
265
300
  }
266
301
  };
267
-
268
- async function shSwalLogout () {
302
+ async function shSwalLogout (seconds = 30) {
303
+ let timerInterval;
269
304
  return Swal__default["default"].fire({
270
305
  title: 'Your session is about to Expire!',
271
- html: 'You will be logout due to inactivity!',
306
+ html: 'You will be logged out in <strong></strong> seconds due to inactivity!',
272
307
  showCancelButton: true,
273
308
  cancelButtonColor: '#32c787',
274
309
  confirmButtonColor: '#000',
275
310
  cancelButtonText: 'Stay signed in',
276
311
  confirmButtonText: 'Sign out now!',
277
- timer: 100000,
312
+ timer: seconds * 1000,
278
313
  allowOutsideClick: false,
279
314
  reverseButtons: true,
280
315
  showLoaderOnConfirm: true,
316
+ didOpen(popup) {
317
+ timerInterval = setInterval(() => {
318
+ // if(sessionRestored() && ShStorage.getItem('access_token')){
319
+ // console.log('swal closed by session restored')
320
+ // Swal.close()
321
+ // }
322
+ Swal__default["default"].getHtmlContainer().querySelector('strong')
323
+ .textContent = (Swal__default["default"].getTimerLeft() / 1000)
324
+ .toFixed(0);
325
+ }, 100);
326
+ },
327
+ willClose: () => {
328
+ clearInterval(timerInterval);
329
+ }
281
330
  }).then((result) => {
282
331
  if (result.isConfirmed) {
283
332
  logoutUser();
333
+ } else if(result.dismiss === 'timer'){
334
+ logoutUser();
284
335
  } else {
285
336
  window.ShConfirmation = null;
286
337
  clearInterval(window.shInterval);
@@ -4469,6 +4520,9 @@ const useUserStore = pinia.defineStore('user-store', {
4469
4520
  user = res.data;
4470
4521
  }
4471
4522
  ShStorage.setItem('user',user);
4523
+ user.signOut = this.signOut;
4524
+ user.logout = this.signOut;
4525
+ user.logOut = this.signOut;
4472
4526
  user.isAllowedTo = function (slug) {
4473
4527
  if(!slug){
4474
4528
  return true
@@ -4505,9 +4559,7 @@ const useUserStore = pinia.defineStore('user-store', {
4505
4559
  ShStorage.setItem('session_start',timeNow);
4506
4560
  },
4507
4561
  signOut () {
4508
- ShStorage.setItem('user',null);
4509
- ShStorage.setItem('access_token',null);
4510
- this.user = null;
4562
+ shRepo__default["default"].signOutUser();
4511
4563
  },
4512
4564
  logOut () {
4513
4565
  this.signOut();
package/dist/library.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  import Axios from 'axios';
2
2
  import moment from 'moment';
3
3
  import Swal from 'sweetalert2';
4
- import { inject, openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, watch, pushScopeId, popScopeId } from 'vue';
4
+ import shApis$1 from '@/lib/repo/helpers/ShApis.js';
5
+ import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, inject, watch, pushScopeId, popScopeId } from 'vue';
5
6
  import NProgress from 'nprogress';
6
7
  import Editor from '@tinymce/tinymce-vue';
7
8
  import { defineStore, storeToRefs } from 'pinia';
9
+ import shRepo$1 from '@/lib/repo/helpers/ShRepo.js';
8
10
  import { useRoute, useRouter } from 'vue-router';
9
11
 
10
12
  function setItem (key, value) {
@@ -123,6 +125,23 @@ function getMenuCount (url) {
123
125
  });
124
126
  }
125
127
 
128
+ const signOutUser = ()=>{
129
+ const loginUrl = getShConfig('loginUrl','auth/login');
130
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
131
+ console.log(loginUrl,logoutApiEndPoint);
132
+ shApis$1.doPost(logoutApiEndPoint).then(res=>{
133
+ ShStorage.removeItem('access_token');
134
+ ShStorage.removeItem('user');
135
+ ShStorage.removeItem('last_activity');
136
+ window.location.href = loginUrl;
137
+ }).catch(ex=>{
138
+ ShStorage.removeItem('access_token');
139
+ ShStorage.removeItem('user');
140
+ ShStorage.removeItem('last_activity');
141
+ window.location.href = loginUrl;
142
+ });
143
+ };
144
+
126
145
 
127
146
  const Toast = Swal.mixin({
128
147
  toast: true,
@@ -139,9 +158,11 @@ const Toast = Swal.mixin({
139
158
  toast.addEventListener('mouseleave', Swal.resumeTimer);
140
159
  }
141
160
  });
142
- function getConfig() {
161
+ function getShConfig(key = null,def = '') {
143
162
  const config = ShStorage.getItem('ShConfig');
144
- console.log(config);
163
+ if(key) {
164
+ return config[key] ?? def
165
+ }
145
166
  return config
146
167
  }
147
168
  function showToast (message, toastType, position) {
@@ -197,6 +218,15 @@ function formatDate(date, format) {
197
218
  }
198
219
  return moment(date).format(format)
199
220
  }
221
+ function formatNumber(amount,decimalPoints = 0){
222
+ return numberFormat(amount,decimalPoints)
223
+ }
224
+ function numberFormat(amount,decimalPoints = 0) {
225
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
226
+ formatted = new Intl.NumberFormat().format(formatted);
227
+ const formattedArr = formatted.split('.');
228
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
229
+ }
200
230
 
201
231
  var shRepo = {
202
232
  swalSuccess,
@@ -204,29 +234,32 @@ var shRepo = {
204
234
  runPlainRequest,
205
235
  getMenuCount,
206
236
  setTabCounts,
207
- getConfig,
237
+ getShConfig,
208
238
  showToast,
209
239
  runSilentRequest,
210
240
  swalHttpError,
211
241
  formatHttpCatchError,
212
- formatDate
242
+ formatDate,
243
+ numberFormat,
244
+ formatNumber,
245
+ signOutUser
213
246
  };
214
247
 
215
248
  startSession();
216
249
  function logoutUser(){
217
- const loginUrl = shRepo.getConfig().loginUrl;
218
- const logoutApiEndpoint = inject('logoutApiEndpoint','auth/logout');
219
- shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
220
- ShStorage.removeItem('access_token');
221
- ShStorage.removeItem('user');
222
- ShStorage.removeItem('last_activity');
223
- window.location.href = loginUrl;
224
- }).catch(ex=>{
225
- ShStorage.removeItem('access_token');
226
- ShStorage.removeItem('user');
227
- window.location.href = loginUrl;
228
- });
229
- ShStorage.getItem('user');
250
+ if(!sessionRestored()){
251
+ shRepo.signOutUser();
252
+ } else {
253
+ console.log('session has been restored in another tab');
254
+ }
255
+ }
256
+ function sessionRestored(){
257
+ const timeout = ShStorage.getItem('sessionTimeout') * 60;
258
+ const last_activity = ShStorage.getItem('last_activity');
259
+ const pastSeconds = moment().diff(last_activity, 'seconds');
260
+ if(!ShStorage.getItem('access_token'))
261
+ return false
262
+ return pastSeconds < timeout
230
263
  }
231
264
  const checkSession = function (isCheking) {
232
265
  const timeout = ShStorage.getItem('sessionTimeout');
@@ -236,13 +269,13 @@ const checkSession = function (isCheking) {
236
269
  const pastSeconds = moment().diff(last_activity, 'seconds');
237
270
  if(pastMinutes >= timeout) {
238
271
  const gracePeriod = pastSeconds - (timeout * 60);
239
- if (gracePeriod >= 30 ) {
272
+ if (gracePeriod >= 60 ) {
240
273
  logoutUser();
241
274
  }
242
275
  else {
243
276
  if (!window.ShConfirmation)
244
277
  {
245
- window.ShConfirmation = shSwalLogout();
278
+ window.ShConfirmation = shSwalLogout(30);
246
279
  }
247
280
  }
248
281
  }
@@ -252,23 +285,39 @@ const checkSession = function (isCheking) {
252
285
  }
253
286
  }
254
287
  };
255
-
256
- async function shSwalLogout () {
288
+ async function shSwalLogout (seconds = 30) {
289
+ let timerInterval;
257
290
  return Swal.fire({
258
291
  title: 'Your session is about to Expire!',
259
- html: 'You will be logout due to inactivity!',
292
+ html: 'You will be logged out in <strong></strong> seconds due to inactivity!',
260
293
  showCancelButton: true,
261
294
  cancelButtonColor: '#32c787',
262
295
  confirmButtonColor: '#000',
263
296
  cancelButtonText: 'Stay signed in',
264
297
  confirmButtonText: 'Sign out now!',
265
- timer: 100000,
298
+ timer: seconds * 1000,
266
299
  allowOutsideClick: false,
267
300
  reverseButtons: true,
268
301
  showLoaderOnConfirm: true,
302
+ didOpen(popup) {
303
+ timerInterval = setInterval(() => {
304
+ // if(sessionRestored() && ShStorage.getItem('access_token')){
305
+ // console.log('swal closed by session restored')
306
+ // Swal.close()
307
+ // }
308
+ Swal.getHtmlContainer().querySelector('strong')
309
+ .textContent = (Swal.getTimerLeft() / 1000)
310
+ .toFixed(0);
311
+ }, 100);
312
+ },
313
+ willClose: () => {
314
+ clearInterval(timerInterval);
315
+ }
269
316
  }).then((result) => {
270
317
  if (result.isConfirmed) {
271
318
  logoutUser();
319
+ } else if(result.dismiss === 'timer'){
320
+ logoutUser();
272
321
  } else {
273
322
  window.ShConfirmation = null;
274
323
  clearInterval(window.shInterval);
@@ -4457,6 +4506,9 @@ const useUserStore = defineStore('user-store', {
4457
4506
  user = res.data;
4458
4507
  }
4459
4508
  ShStorage.setItem('user',user);
4509
+ user.signOut = this.signOut;
4510
+ user.logout = this.signOut;
4511
+ user.logOut = this.signOut;
4460
4512
  user.isAllowedTo = function (slug) {
4461
4513
  if(!slug){
4462
4514
  return true
@@ -4493,9 +4545,7 @@ const useUserStore = defineStore('user-store', {
4493
4545
  ShStorage.setItem('session_start',timeNow);
4494
4546
  },
4495
4547
  signOut () {
4496
- ShStorage.setItem('user',null);
4497
- ShStorage.setItem('access_token',null);
4498
- this.user = null;
4548
+ shRepo$1.signOutUser();
4499
4549
  },
4500
4550
  logOut () {
4501
4551
  this.signOut();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "1.1.8",
3
+ "version": "1.2.1",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",