@iankibetsh/shframework 1.1.2 → 1.1.4
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/dist/library.mjs.css +15 -15
- package/dist/library.js +276 -225
- package/dist/library.mjs +275 -224
- package/package.json +1 -1
|
@@ -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
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var Axios = require('axios');
|
|
6
6
|
var moment = require('moment');
|
|
7
|
+
var Swal = require('sweetalert2');
|
|
7
8
|
var vue = require('vue');
|
|
8
9
|
var NProgress = require('nprogress');
|
|
9
10
|
var Editor = require('@tinymce/tinymce-vue');
|
|
10
|
-
var Swal = require('sweetalert2');
|
|
11
11
|
var pinia = require('pinia');
|
|
12
12
|
var vueRouter = require('vue-router');
|
|
13
13
|
|
|
@@ -15,9 +15,9 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
15
15
|
|
|
16
16
|
var Axios__default = /*#__PURE__*/_interopDefaultLegacy(Axios);
|
|
17
17
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
18
|
+
var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
|
|
18
19
|
var NProgress__default = /*#__PURE__*/_interopDefaultLegacy(NProgress);
|
|
19
20
|
var Editor__default = /*#__PURE__*/_interopDefaultLegacy(Editor);
|
|
20
|
-
var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
|
|
21
21
|
|
|
22
22
|
function setItem (key, value) {
|
|
23
23
|
let toStore = value;
|
|
@@ -28,7 +28,11 @@ function setItem (key, value) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function getItem (key) {
|
|
31
|
-
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(localStorage.getItem(key))
|
|
33
|
+
} catch (err) {
|
|
34
|
+
return localStorage.getItem(key)
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
function removeItem (key) {
|
|
34
38
|
return localStorage.removeItem(key)
|
|
@@ -39,59 +43,271 @@ var ShStorage = {
|
|
|
39
43
|
removeItem
|
|
40
44
|
};
|
|
41
45
|
|
|
46
|
+
function swalSuccess (message) {
|
|
47
|
+
Swal__default["default"].fire('Success!', message, 'success');
|
|
48
|
+
}
|
|
49
|
+
function swalError (message) {
|
|
50
|
+
Swal__default["default"].fire('Error!', message, 'error');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function swalHttpError (reason) {
|
|
54
|
+
let error = '';
|
|
55
|
+
if (typeof reason !== 'undefined') {
|
|
56
|
+
if (typeof reason.response !== 'undefined') {
|
|
57
|
+
let reasonString = '';
|
|
58
|
+
if (typeof reason.response.data === 'string') {
|
|
59
|
+
reasonString = reason.response.data;
|
|
60
|
+
} else {
|
|
61
|
+
reasonString = JSON.stringify(reason.response.data);
|
|
62
|
+
}
|
|
63
|
+
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
64
|
+
} else {
|
|
65
|
+
if (typeof reason !== 'string') {
|
|
66
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
67
|
+
} else {
|
|
68
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (typeof reason !== 'string') {
|
|
73
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
74
|
+
} else {
|
|
75
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
Swal__default["default"].fire('Error!', error, 'error');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function runSilentRequest (url) {
|
|
82
|
+
return shApis.doPost(url)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function setTabCounts (url) {
|
|
86
|
+
shApis.doGet(url).then(res => {
|
|
87
|
+
Object.keys(res.data).forEach(key => {
|
|
88
|
+
const elem = document.getElementById(key);
|
|
89
|
+
if (elem === null) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
if (typeof elem !== 'undefined') {
|
|
93
|
+
let txt = elem.innerHTML;
|
|
94
|
+
txt = txt.split('<i class="d-none"></i>')[0];
|
|
95
|
+
if (parseInt(res.data[key]) > 0) {
|
|
96
|
+
elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// document.getElementById(key).innerHTML res.data[key]
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function formatHttpCatchError (reason) {
|
|
104
|
+
console.log(reason);
|
|
105
|
+
let error = '';
|
|
106
|
+
if (typeof reason !== 'undefined') {
|
|
107
|
+
if (typeof reason.response !== 'undefined') {
|
|
108
|
+
alert('here');
|
|
109
|
+
let reasonString = '';
|
|
110
|
+
if (typeof reason.response.data === 'string') {
|
|
111
|
+
reasonString = reason.response.data;
|
|
112
|
+
} else {
|
|
113
|
+
reasonString = JSON.stringify(reason.response.data);
|
|
114
|
+
}
|
|
115
|
+
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
116
|
+
} else {
|
|
117
|
+
if (typeof reason !== 'string') {
|
|
118
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
119
|
+
} else {
|
|
120
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
if (typeof reason !== 'string') {
|
|
125
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
126
|
+
} else {
|
|
127
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return error
|
|
131
|
+
}
|
|
132
|
+
function getMenuCount (url) {
|
|
133
|
+
shApis.doGet(url).then(res => {
|
|
134
|
+
console.log(res);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const Toast = Swal__default["default"].mixin({
|
|
140
|
+
toast: true,
|
|
141
|
+
position: 'top-end',
|
|
142
|
+
showConfirmButton: false,
|
|
143
|
+
customClass: {
|
|
144
|
+
popup: 'colored-toast'
|
|
145
|
+
},
|
|
146
|
+
iconColor: 'white',
|
|
147
|
+
timer: 2000,
|
|
148
|
+
timerProgressBar: true,
|
|
149
|
+
didOpen: (toast) => {
|
|
150
|
+
toast.addEventListener('mouseenter', Swal__default["default"].stopTimer);
|
|
151
|
+
toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
function getConfig() {
|
|
155
|
+
const config = ShStorage.getItem('ShConfig');
|
|
156
|
+
console.log(config);
|
|
157
|
+
return config
|
|
158
|
+
}
|
|
159
|
+
function showToast (message, toastType, position) {
|
|
160
|
+
if (!toastType) {
|
|
161
|
+
toastType = 'success';
|
|
162
|
+
}
|
|
163
|
+
if(!position){
|
|
164
|
+
position = window.swalPosition;
|
|
165
|
+
}
|
|
166
|
+
Toast.mixin({
|
|
167
|
+
position: position
|
|
168
|
+
});
|
|
169
|
+
Toast.fire({
|
|
170
|
+
icon: toastType,
|
|
171
|
+
title: message
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function runPlainRequest (url, message, title, data) {
|
|
176
|
+
if (typeof title === 'undefined') {
|
|
177
|
+
title = null;
|
|
178
|
+
}
|
|
179
|
+
return Swal__default["default"].fire({
|
|
180
|
+
title: title !== null ? title : 'Are you sure?',
|
|
181
|
+
html: message,
|
|
182
|
+
showCancelButton: true,
|
|
183
|
+
confirmButtonColor: '#32c787',
|
|
184
|
+
cancelButtonText: 'No, cancel',
|
|
185
|
+
confirmButtonText: 'Yes, Proceed!',
|
|
186
|
+
reverseButtons: true,
|
|
187
|
+
showLoaderOnConfirm: true,
|
|
188
|
+
preConfirm: () => {
|
|
189
|
+
return shApis.doPost(url, data).then(function (response) {
|
|
190
|
+
return {
|
|
191
|
+
response: response.data,
|
|
192
|
+
success: true
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
.catch(error => {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
error: error
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
},
|
|
202
|
+
allowOutsideClick: () => !Swal__default["default"].isLoading()
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function formatDate(date, format) {
|
|
207
|
+
if (!format) {
|
|
208
|
+
format = 'lll';
|
|
209
|
+
}
|
|
210
|
+
return moment__default["default"](date).format(format)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
var shRepo = {
|
|
214
|
+
swalSuccess,
|
|
215
|
+
swalError,
|
|
216
|
+
runPlainRequest,
|
|
217
|
+
getMenuCount,
|
|
218
|
+
setTabCounts,
|
|
219
|
+
getConfig,
|
|
220
|
+
showToast,
|
|
221
|
+
runSilentRequest,
|
|
222
|
+
swalHttpError,
|
|
223
|
+
formatHttpCatchError,
|
|
224
|
+
formatDate
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
startSession();
|
|
42
228
|
function logoutUser(){
|
|
43
|
-
|
|
229
|
+
const loginUrl = shRepo.getConfig().loginUrl;
|
|
44
230
|
const logoutApiEndpoint = vue.inject('logoutApiEndpoint','auth/logout');
|
|
45
|
-
shApis.doPost(logoutApiEndpoint).then(res=>{
|
|
231
|
+
shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
|
|
46
232
|
ShStorage.removeItem('access_token');
|
|
47
233
|
ShStorage.removeItem('user');
|
|
48
|
-
|
|
49
|
-
window.location.href =
|
|
234
|
+
ShStorage.removeItem('last_activity');
|
|
235
|
+
window.location.href = loginUrl;
|
|
50
236
|
}).catch(ex=>{
|
|
51
|
-
vue.inject('loginUrl','/login');
|
|
52
237
|
ShStorage.removeItem('access_token');
|
|
53
238
|
ShStorage.removeItem('user');
|
|
54
|
-
window.location.href =
|
|
239
|
+
window.location.href = loginUrl;
|
|
55
240
|
});
|
|
56
|
-
|
|
241
|
+
ShStorage.getItem('user');
|
|
57
242
|
}
|
|
58
243
|
const checkSession = function (isCheking) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
244
|
+
const timeout = ShStorage.getItem('sessionTimeout');
|
|
245
|
+
const last_activity = ShStorage.getItem('last_activity');
|
|
246
|
+
if (ShStorage.getItem('access_token')) {
|
|
247
|
+
const pastMinutes = moment__default["default"]().diff(last_activity, 'minutes');
|
|
248
|
+
const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
|
|
249
|
+
if(pastMinutes >= timeout) {
|
|
250
|
+
const gracePeriod = pastSeconds - (timeout * 60);
|
|
251
|
+
if (gracePeriod >= 30 ) {
|
|
252
|
+
logoutUser();
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (!window.ShConfirmation)
|
|
256
|
+
{
|
|
257
|
+
window.ShConfirmation = shSwalLogout();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
console.log(pastSeconds);
|
|
262
|
+
console.log(pastMinutes);
|
|
263
|
+
}
|
|
264
|
+
}else {
|
|
265
|
+
if (window.shInterval) {
|
|
266
|
+
clearInterval(window.shInterval);
|
|
267
|
+
}
|
|
67
268
|
}
|
|
269
|
+
};
|
|
68
270
|
|
|
69
|
-
|
|
70
|
-
|
|
271
|
+
async function shSwalLogout () {
|
|
272
|
+
return Swal__default["default"].fire({
|
|
273
|
+
title: 'Your session is about to Expire!',
|
|
274
|
+
html: 'You will be logout due to inactivity!',
|
|
275
|
+
showCancelButton: true,
|
|
276
|
+
cancelButtonColor: '#32c787',
|
|
277
|
+
confirmButtonColor: '#000',
|
|
278
|
+
cancelButtonText: 'Stay signed in',
|
|
279
|
+
confirmButtonText: 'Sign out now!',
|
|
280
|
+
timer: 100000,
|
|
281
|
+
allowOutsideClick: false,
|
|
282
|
+
reverseButtons: true,
|
|
283
|
+
showLoaderOnConfirm: true,
|
|
284
|
+
}).then((result) => {
|
|
285
|
+
if (result.isConfirmed) {
|
|
71
286
|
logoutUser();
|
|
72
|
-
}
|
|
73
|
-
|
|
287
|
+
} else if (result.isDenied) {
|
|
288
|
+
updateSession();
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
function startSession () {
|
|
293
|
+
const timeNow = moment__default["default"]().toISOString();
|
|
294
|
+
const accessToken = ShStorage.getItem('access_token');
|
|
295
|
+
if (accessToken) {
|
|
296
|
+
ShStorage.setItem('last_activity', timeNow);
|
|
297
|
+
const timout = ShStorage.getItem('sessionTimeout');
|
|
298
|
+
const interval = (timout * 60 *1000) / 3;
|
|
299
|
+
window.shInterval = setInterval(()=>{
|
|
300
|
+
checkSession();
|
|
301
|
+
},interval);
|
|
74
302
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// const pastMinutes = moment().diff(started, 'minutes')
|
|
84
|
-
// if(pastMinutes >= timeout) {
|
|
85
|
-
// ShStorage.removeItem('user')
|
|
86
|
-
// ShStorage.removeItem('access_token')
|
|
87
|
-
// return false
|
|
88
|
-
// }
|
|
89
|
-
// if (isCheking) {
|
|
90
|
-
// return true
|
|
91
|
-
// }
|
|
92
|
-
// const timeNow = moment().toISOString()
|
|
93
|
-
// ShStorage.setItem('session_start', timeNow)
|
|
94
|
-
// return true
|
|
303
|
+
}
|
|
304
|
+
const updateSession = () =>{
|
|
305
|
+
if(!window.shInterval) {
|
|
306
|
+
startSession();
|
|
307
|
+
}
|
|
308
|
+
const timeNow = moment__default["default"]().toISOString();
|
|
309
|
+
ShStorage.setItem('last_activity', timeNow);
|
|
310
|
+
window.ShConfirmation = null;
|
|
95
311
|
};
|
|
96
312
|
|
|
97
313
|
let apiUrl = undefined.VITE_APP_API_URL;
|
|
@@ -107,7 +323,7 @@ const axios = Axios__default["default"].create({
|
|
|
107
323
|
baseURL: apiUrl
|
|
108
324
|
});
|
|
109
325
|
function doGet (endPoint, data) {
|
|
110
|
-
|
|
326
|
+
updateSession();
|
|
111
327
|
return axios.get(endPoint, {
|
|
112
328
|
params: data,
|
|
113
329
|
crossOrigin: true,
|
|
@@ -118,7 +334,7 @@ function doGet (endPoint, data) {
|
|
|
118
334
|
})
|
|
119
335
|
}
|
|
120
336
|
function doPost (endPoint, data) {
|
|
121
|
-
|
|
337
|
+
updateSession();
|
|
122
338
|
return axios.post(endPoint,
|
|
123
339
|
data,
|
|
124
340
|
{
|
|
@@ -2964,180 +3180,6 @@ function render$2(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2964
3180
|
script$8.render = render$2;
|
|
2965
3181
|
script$8.__file = "src/lib/components/list_templates/Pagination.vue";
|
|
2966
3182
|
|
|
2967
|
-
function swalSuccess (message) {
|
|
2968
|
-
Swal__default["default"].fire('Success!', message, 'success');
|
|
2969
|
-
}
|
|
2970
|
-
function swalError (message) {
|
|
2971
|
-
Swal__default["default"].fire('Error!', message, 'error');
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
function swalHttpError (reason) {
|
|
2975
|
-
let error = '';
|
|
2976
|
-
if (typeof reason !== 'undefined') {
|
|
2977
|
-
if (typeof reason.response !== 'undefined') {
|
|
2978
|
-
let reasonString = '';
|
|
2979
|
-
if (typeof reason.response.data === 'string') {
|
|
2980
|
-
reasonString = reason.response.data;
|
|
2981
|
-
} else {
|
|
2982
|
-
reasonString = JSON.stringify(reason.response.data);
|
|
2983
|
-
}
|
|
2984
|
-
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
2985
|
-
} else {
|
|
2986
|
-
if (typeof reason !== 'string') {
|
|
2987
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2988
|
-
} else {
|
|
2989
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
} else {
|
|
2993
|
-
if (typeof reason !== 'string') {
|
|
2994
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2995
|
-
} else {
|
|
2996
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2997
|
-
}
|
|
2998
|
-
}
|
|
2999
|
-
Swal__default["default"].fire('Error!', error, 'error');
|
|
3000
|
-
}
|
|
3001
|
-
|
|
3002
|
-
function runSilentRequest (url) {
|
|
3003
|
-
return shApis.doPost(url)
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
function setTabCounts (url) {
|
|
3007
|
-
shApis.doGet(url).then(res => {
|
|
3008
|
-
Object.keys(res.data).forEach(key => {
|
|
3009
|
-
const elem = document.getElementById(key);
|
|
3010
|
-
if (elem === null) {
|
|
3011
|
-
return
|
|
3012
|
-
}
|
|
3013
|
-
if (typeof elem !== 'undefined') {
|
|
3014
|
-
let txt = elem.innerHTML;
|
|
3015
|
-
txt = txt.split('<i class="d-none"></i>')[0];
|
|
3016
|
-
if (parseInt(res.data[key]) > 0) {
|
|
3017
|
-
elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
|
|
3018
|
-
}
|
|
3019
|
-
}
|
|
3020
|
-
// document.getElementById(key).innerHTML res.data[key]
|
|
3021
|
-
});
|
|
3022
|
-
});
|
|
3023
|
-
}
|
|
3024
|
-
function formatHttpCatchError (reason) {
|
|
3025
|
-
console.log(reason);
|
|
3026
|
-
let error = '';
|
|
3027
|
-
if (typeof reason !== 'undefined') {
|
|
3028
|
-
if (typeof reason.response !== 'undefined') {
|
|
3029
|
-
alert('here');
|
|
3030
|
-
let reasonString = '';
|
|
3031
|
-
if (typeof reason.response.data === 'string') {
|
|
3032
|
-
reasonString = reason.response.data;
|
|
3033
|
-
} else {
|
|
3034
|
-
reasonString = JSON.stringify(reason.response.data);
|
|
3035
|
-
}
|
|
3036
|
-
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
3037
|
-
} else {
|
|
3038
|
-
if (typeof reason !== 'string') {
|
|
3039
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3040
|
-
} else {
|
|
3041
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
} else {
|
|
3045
|
-
if (typeof reason !== 'string') {
|
|
3046
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3047
|
-
} else {
|
|
3048
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3049
|
-
}
|
|
3050
|
-
}
|
|
3051
|
-
return error
|
|
3052
|
-
}
|
|
3053
|
-
function getMenuCount (url) {
|
|
3054
|
-
shApis.doGet(url).then(res => {
|
|
3055
|
-
console.log(res);
|
|
3056
|
-
});
|
|
3057
|
-
}
|
|
3058
|
-
|
|
3059
|
-
const Toast = Swal__default["default"].mixin({
|
|
3060
|
-
toast: true,
|
|
3061
|
-
position: 'top-end',
|
|
3062
|
-
showConfirmButton: false,
|
|
3063
|
-
customClass: {
|
|
3064
|
-
popup: 'colored-toast'
|
|
3065
|
-
},
|
|
3066
|
-
iconColor: 'white',
|
|
3067
|
-
timer: 2000,
|
|
3068
|
-
timerProgressBar: true,
|
|
3069
|
-
didOpen: (toast) => {
|
|
3070
|
-
toast.addEventListener('mouseenter', Swal__default["default"].stopTimer);
|
|
3071
|
-
toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
|
|
3072
|
-
}
|
|
3073
|
-
});
|
|
3074
|
-
function showToast (message, toastType, position) {
|
|
3075
|
-
if (!toastType) {
|
|
3076
|
-
toastType = 'success';
|
|
3077
|
-
}
|
|
3078
|
-
if(!position){
|
|
3079
|
-
position = window.swalPosition;
|
|
3080
|
-
}
|
|
3081
|
-
Toast.mixin({
|
|
3082
|
-
position: position
|
|
3083
|
-
});
|
|
3084
|
-
Toast.fire({
|
|
3085
|
-
icon: toastType,
|
|
3086
|
-
title: message
|
|
3087
|
-
});
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
async function runPlainRequest (url, message, title, data) {
|
|
3091
|
-
if (typeof title === 'undefined') {
|
|
3092
|
-
title = null;
|
|
3093
|
-
}
|
|
3094
|
-
return Swal__default["default"].fire({
|
|
3095
|
-
title: title !== null ? title : 'Are you sure?',
|
|
3096
|
-
html: message,
|
|
3097
|
-
showCancelButton: true,
|
|
3098
|
-
confirmButtonColor: '#32c787',
|
|
3099
|
-
cancelButtonText: 'No, cancel',
|
|
3100
|
-
confirmButtonText: 'Yes, Proceed!',
|
|
3101
|
-
reverseButtons: true,
|
|
3102
|
-
showLoaderOnConfirm: true,
|
|
3103
|
-
preConfirm: () => {
|
|
3104
|
-
return shApis.doPost(url, data).then(function (response) {
|
|
3105
|
-
return {
|
|
3106
|
-
response: response.data,
|
|
3107
|
-
success: true
|
|
3108
|
-
}
|
|
3109
|
-
})
|
|
3110
|
-
.catch(error => {
|
|
3111
|
-
return {
|
|
3112
|
-
success: false,
|
|
3113
|
-
error: error
|
|
3114
|
-
}
|
|
3115
|
-
})
|
|
3116
|
-
},
|
|
3117
|
-
allowOutsideClick: () => !Swal__default["default"].isLoading()
|
|
3118
|
-
})
|
|
3119
|
-
}
|
|
3120
|
-
|
|
3121
|
-
function formatDate(date, format) {
|
|
3122
|
-
if (!format) {
|
|
3123
|
-
format = 'lll';
|
|
3124
|
-
}
|
|
3125
|
-
return moment__default["default"](date).format(format)
|
|
3126
|
-
}
|
|
3127
|
-
|
|
3128
|
-
var shRepo = {
|
|
3129
|
-
swalSuccess,
|
|
3130
|
-
swalError,
|
|
3131
|
-
runPlainRequest,
|
|
3132
|
-
getMenuCount,
|
|
3133
|
-
setTabCounts,
|
|
3134
|
-
showToast,
|
|
3135
|
-
runSilentRequest,
|
|
3136
|
-
swalHttpError,
|
|
3137
|
-
formatHttpCatchError,
|
|
3138
|
-
formatDate
|
|
3139
|
-
};
|
|
3140
|
-
|
|
3141
3183
|
const _hoisted_1$6 = /*#__PURE__*/vue.createElementVNode("span", {
|
|
3142
3184
|
class: "spinner-border spinner-border-sm me-1",
|
|
3143
3185
|
role: "status",
|
|
@@ -4347,13 +4389,18 @@ const useUserStore = pinia.defineStore('user-store', {
|
|
|
4347
4389
|
}),
|
|
4348
4390
|
actions: {
|
|
4349
4391
|
setUser (){
|
|
4350
|
-
|
|
4392
|
+
let user = null;
|
|
4393
|
+
try {
|
|
4394
|
+
user = ShStorage.getItem('user') ? ShStorage.getItem('user') : null;
|
|
4395
|
+
} catch (error) {
|
|
4396
|
+
user= null;
|
|
4397
|
+
}
|
|
4351
4398
|
if (user) {
|
|
4352
4399
|
user.isAllowedTo = function (slug) {
|
|
4353
4400
|
if (this.permissions) {
|
|
4354
4401
|
let permissions = [];
|
|
4355
4402
|
if (typeof this.permissions === 'string') {
|
|
4356
|
-
permissions =
|
|
4403
|
+
permissions = this.permissions;
|
|
4357
4404
|
} else {
|
|
4358
4405
|
permissions = this.permissions;
|
|
4359
4406
|
}
|
|
@@ -4364,13 +4411,16 @@ const useUserStore = pinia.defineStore('user-store', {
|
|
|
4364
4411
|
}
|
|
4365
4412
|
this.user = user;
|
|
4366
4413
|
shApis.doGet('auth/user').then(res => {
|
|
4367
|
-
|
|
4368
|
-
|
|
4414
|
+
let user = res.data.user;
|
|
4415
|
+
if (typeof(user) === 'undefined') {
|
|
4416
|
+
user = res.data;
|
|
4417
|
+
}
|
|
4418
|
+
ShStorage.setItem('user',user);
|
|
4369
4419
|
user.isAllowedTo = function (slug) {
|
|
4370
4420
|
if (this.permissions) {
|
|
4371
4421
|
let permissions = [];
|
|
4372
4422
|
if (typeof this.permissions === 'string') {
|
|
4373
|
-
permissions =
|
|
4423
|
+
permissions = this.permissions;
|
|
4374
4424
|
} else {
|
|
4375
4425
|
permissions = this.permissions;
|
|
4376
4426
|
}
|
|
@@ -4390,7 +4440,7 @@ const useUserStore = pinia.defineStore('user-store', {
|
|
|
4390
4440
|
});
|
|
4391
4441
|
if (this.user) {
|
|
4392
4442
|
if (typeof this.user.permissions === 'string') {
|
|
4393
|
-
this.permissions =
|
|
4443
|
+
this.permissions = this.user.permissions;
|
|
4394
4444
|
} else {
|
|
4395
4445
|
this.permissions = this.user.permissions;
|
|
4396
4446
|
}
|
|
@@ -4571,7 +4621,7 @@ function viewPermissions(rModule) {
|
|
|
4571
4621
|
modulePermissions.value = res.data.permissions;
|
|
4572
4622
|
module.value = rModule;
|
|
4573
4623
|
if (rModule.permissions) {
|
|
4574
|
-
selectedPermissions.value =
|
|
4624
|
+
selectedPermissions.value = rModule.permissions;
|
|
4575
4625
|
}
|
|
4576
4626
|
console.log(module.value);
|
|
4577
4627
|
}).catch(ex => {
|
|
@@ -4827,6 +4877,7 @@ script.__file = "src/lib/components/core/auth/ShAuth.vue";
|
|
|
4827
4877
|
|
|
4828
4878
|
const ShFrontend = {
|
|
4829
4879
|
install: (app, options) => {
|
|
4880
|
+
ShStorage.setItem('ShConfig',options);
|
|
4830
4881
|
if(options.sessionTimeout){
|
|
4831
4882
|
app.provide('sessionTimeout',options.sessionTimeout);
|
|
4832
4883
|
ShStorage.setItem('sessionTimeout',options.sessionTimeout);
|
package/dist/library.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Axios from 'axios';
|
|
2
2
|
import moment from 'moment';
|
|
3
|
+
import Swal from 'sweetalert2';
|
|
3
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, createStaticVNode, mergeProps, shallowRef, computed, isRef, vModelCheckbox, watch, pushScopeId, popScopeId } from 'vue';
|
|
4
5
|
import NProgress from 'nprogress';
|
|
5
6
|
import Editor from '@tinymce/tinymce-vue';
|
|
6
|
-
import Swal from 'sweetalert2';
|
|
7
7
|
import { defineStore, storeToRefs } from 'pinia';
|
|
8
8
|
import { useRoute, useRouter } from 'vue-router';
|
|
9
9
|
|
|
@@ -16,7 +16,11 @@ function setItem (key, value) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function getItem (key) {
|
|
19
|
-
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(localStorage.getItem(key))
|
|
21
|
+
} catch (err) {
|
|
22
|
+
return localStorage.getItem(key)
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
function removeItem (key) {
|
|
22
26
|
return localStorage.removeItem(key)
|
|
@@ -27,59 +31,271 @@ var ShStorage = {
|
|
|
27
31
|
removeItem
|
|
28
32
|
};
|
|
29
33
|
|
|
34
|
+
function swalSuccess (message) {
|
|
35
|
+
Swal.fire('Success!', message, 'success');
|
|
36
|
+
}
|
|
37
|
+
function swalError (message) {
|
|
38
|
+
Swal.fire('Error!', message, 'error');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function swalHttpError (reason) {
|
|
42
|
+
let error = '';
|
|
43
|
+
if (typeof reason !== 'undefined') {
|
|
44
|
+
if (typeof reason.response !== 'undefined') {
|
|
45
|
+
let reasonString = '';
|
|
46
|
+
if (typeof reason.response.data === 'string') {
|
|
47
|
+
reasonString = reason.response.data;
|
|
48
|
+
} else {
|
|
49
|
+
reasonString = JSON.stringify(reason.response.data);
|
|
50
|
+
}
|
|
51
|
+
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
52
|
+
} else {
|
|
53
|
+
if (typeof reason !== 'string') {
|
|
54
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
55
|
+
} else {
|
|
56
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
if (typeof reason !== 'string') {
|
|
61
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
62
|
+
} else {
|
|
63
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
Swal.fire('Error!', error, 'error');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function runSilentRequest (url) {
|
|
70
|
+
return shApis.doPost(url)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function setTabCounts (url) {
|
|
74
|
+
shApis.doGet(url).then(res => {
|
|
75
|
+
Object.keys(res.data).forEach(key => {
|
|
76
|
+
const elem = document.getElementById(key);
|
|
77
|
+
if (elem === null) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
if (typeof elem !== 'undefined') {
|
|
81
|
+
let txt = elem.innerHTML;
|
|
82
|
+
txt = txt.split('<i class="d-none"></i>')[0];
|
|
83
|
+
if (parseInt(res.data[key]) > 0) {
|
|
84
|
+
elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// document.getElementById(key).innerHTML res.data[key]
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function formatHttpCatchError (reason) {
|
|
92
|
+
console.log(reason);
|
|
93
|
+
let error = '';
|
|
94
|
+
if (typeof reason !== 'undefined') {
|
|
95
|
+
if (typeof reason.response !== 'undefined') {
|
|
96
|
+
alert('here');
|
|
97
|
+
let reasonString = '';
|
|
98
|
+
if (typeof reason.response.data === 'string') {
|
|
99
|
+
reasonString = reason.response.data;
|
|
100
|
+
} else {
|
|
101
|
+
reasonString = JSON.stringify(reason.response.data);
|
|
102
|
+
}
|
|
103
|
+
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
104
|
+
} else {
|
|
105
|
+
if (typeof reason !== 'string') {
|
|
106
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
107
|
+
} else {
|
|
108
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
if (typeof reason !== 'string') {
|
|
113
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
114
|
+
} else {
|
|
115
|
+
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return error
|
|
119
|
+
}
|
|
120
|
+
function getMenuCount (url) {
|
|
121
|
+
shApis.doGet(url).then(res => {
|
|
122
|
+
console.log(res);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const Toast = Swal.mixin({
|
|
128
|
+
toast: true,
|
|
129
|
+
position: 'top-end',
|
|
130
|
+
showConfirmButton: false,
|
|
131
|
+
customClass: {
|
|
132
|
+
popup: 'colored-toast'
|
|
133
|
+
},
|
|
134
|
+
iconColor: 'white',
|
|
135
|
+
timer: 2000,
|
|
136
|
+
timerProgressBar: true,
|
|
137
|
+
didOpen: (toast) => {
|
|
138
|
+
toast.addEventListener('mouseenter', Swal.stopTimer);
|
|
139
|
+
toast.addEventListener('mouseleave', Swal.resumeTimer);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
function getConfig() {
|
|
143
|
+
const config = ShStorage.getItem('ShConfig');
|
|
144
|
+
console.log(config);
|
|
145
|
+
return config
|
|
146
|
+
}
|
|
147
|
+
function showToast (message, toastType, position) {
|
|
148
|
+
if (!toastType) {
|
|
149
|
+
toastType = 'success';
|
|
150
|
+
}
|
|
151
|
+
if(!position){
|
|
152
|
+
position = window.swalPosition;
|
|
153
|
+
}
|
|
154
|
+
Toast.mixin({
|
|
155
|
+
position: position
|
|
156
|
+
});
|
|
157
|
+
Toast.fire({
|
|
158
|
+
icon: toastType,
|
|
159
|
+
title: message
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function runPlainRequest (url, message, title, data) {
|
|
164
|
+
if (typeof title === 'undefined') {
|
|
165
|
+
title = null;
|
|
166
|
+
}
|
|
167
|
+
return Swal.fire({
|
|
168
|
+
title: title !== null ? title : 'Are you sure?',
|
|
169
|
+
html: message,
|
|
170
|
+
showCancelButton: true,
|
|
171
|
+
confirmButtonColor: '#32c787',
|
|
172
|
+
cancelButtonText: 'No, cancel',
|
|
173
|
+
confirmButtonText: 'Yes, Proceed!',
|
|
174
|
+
reverseButtons: true,
|
|
175
|
+
showLoaderOnConfirm: true,
|
|
176
|
+
preConfirm: () => {
|
|
177
|
+
return shApis.doPost(url, data).then(function (response) {
|
|
178
|
+
return {
|
|
179
|
+
response: response.data,
|
|
180
|
+
success: true
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
.catch(error => {
|
|
184
|
+
return {
|
|
185
|
+
success: false,
|
|
186
|
+
error: error
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
},
|
|
190
|
+
allowOutsideClick: () => !Swal.isLoading()
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function formatDate(date, format) {
|
|
195
|
+
if (!format) {
|
|
196
|
+
format = 'lll';
|
|
197
|
+
}
|
|
198
|
+
return moment(date).format(format)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var shRepo = {
|
|
202
|
+
swalSuccess,
|
|
203
|
+
swalError,
|
|
204
|
+
runPlainRequest,
|
|
205
|
+
getMenuCount,
|
|
206
|
+
setTabCounts,
|
|
207
|
+
getConfig,
|
|
208
|
+
showToast,
|
|
209
|
+
runSilentRequest,
|
|
210
|
+
swalHttpError,
|
|
211
|
+
formatHttpCatchError,
|
|
212
|
+
formatDate
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
startSession();
|
|
30
216
|
function logoutUser(){
|
|
31
|
-
|
|
217
|
+
const loginUrl = shRepo.getConfig().loginUrl;
|
|
32
218
|
const logoutApiEndpoint = inject('logoutApiEndpoint','auth/logout');
|
|
33
|
-
shApis.doPost(logoutApiEndpoint).then(res=>{
|
|
219
|
+
shApis.doPost(logoutApiEndpoint ?? 'auth/logout').then(res=>{
|
|
34
220
|
ShStorage.removeItem('access_token');
|
|
35
221
|
ShStorage.removeItem('user');
|
|
36
|
-
|
|
37
|
-
window.location.href =
|
|
222
|
+
ShStorage.removeItem('last_activity');
|
|
223
|
+
window.location.href = loginUrl;
|
|
38
224
|
}).catch(ex=>{
|
|
39
|
-
inject('loginUrl','/login');
|
|
40
225
|
ShStorage.removeItem('access_token');
|
|
41
226
|
ShStorage.removeItem('user');
|
|
42
|
-
window.location.href =
|
|
227
|
+
window.location.href = loginUrl;
|
|
43
228
|
});
|
|
44
|
-
|
|
229
|
+
ShStorage.getItem('user');
|
|
45
230
|
}
|
|
46
231
|
const checkSession = function (isCheking) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
232
|
+
const timeout = ShStorage.getItem('sessionTimeout');
|
|
233
|
+
const last_activity = ShStorage.getItem('last_activity');
|
|
234
|
+
if (ShStorage.getItem('access_token')) {
|
|
235
|
+
const pastMinutes = moment().diff(last_activity, 'minutes');
|
|
236
|
+
const pastSeconds = moment().diff(last_activity, 'seconds');
|
|
237
|
+
if(pastMinutes >= timeout) {
|
|
238
|
+
const gracePeriod = pastSeconds - (timeout * 60);
|
|
239
|
+
if (gracePeriod >= 30 ) {
|
|
240
|
+
logoutUser();
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
if (!window.ShConfirmation)
|
|
244
|
+
{
|
|
245
|
+
window.ShConfirmation = shSwalLogout();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
console.log(pastSeconds);
|
|
250
|
+
console.log(pastMinutes);
|
|
251
|
+
}
|
|
252
|
+
}else {
|
|
253
|
+
if (window.shInterval) {
|
|
254
|
+
clearInterval(window.shInterval);
|
|
255
|
+
}
|
|
55
256
|
}
|
|
257
|
+
};
|
|
56
258
|
|
|
57
|
-
|
|
58
|
-
|
|
259
|
+
async function shSwalLogout () {
|
|
260
|
+
return Swal.fire({
|
|
261
|
+
title: 'Your session is about to Expire!',
|
|
262
|
+
html: 'You will be logout due to inactivity!',
|
|
263
|
+
showCancelButton: true,
|
|
264
|
+
cancelButtonColor: '#32c787',
|
|
265
|
+
confirmButtonColor: '#000',
|
|
266
|
+
cancelButtonText: 'Stay signed in',
|
|
267
|
+
confirmButtonText: 'Sign out now!',
|
|
268
|
+
timer: 100000,
|
|
269
|
+
allowOutsideClick: false,
|
|
270
|
+
reverseButtons: true,
|
|
271
|
+
showLoaderOnConfirm: true,
|
|
272
|
+
}).then((result) => {
|
|
273
|
+
if (result.isConfirmed) {
|
|
59
274
|
logoutUser();
|
|
60
|
-
}
|
|
61
|
-
|
|
275
|
+
} else if (result.isDenied) {
|
|
276
|
+
updateSession();
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
function startSession () {
|
|
281
|
+
const timeNow = moment().toISOString();
|
|
282
|
+
const accessToken = ShStorage.getItem('access_token');
|
|
283
|
+
if (accessToken) {
|
|
284
|
+
ShStorage.setItem('last_activity', timeNow);
|
|
285
|
+
const timout = ShStorage.getItem('sessionTimeout');
|
|
286
|
+
const interval = (timout * 60 *1000) / 3;
|
|
287
|
+
window.shInterval = setInterval(()=>{
|
|
288
|
+
checkSession();
|
|
289
|
+
},interval);
|
|
62
290
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// const pastMinutes = moment().diff(started, 'minutes')
|
|
72
|
-
// if(pastMinutes >= timeout) {
|
|
73
|
-
// ShStorage.removeItem('user')
|
|
74
|
-
// ShStorage.removeItem('access_token')
|
|
75
|
-
// return false
|
|
76
|
-
// }
|
|
77
|
-
// if (isCheking) {
|
|
78
|
-
// return true
|
|
79
|
-
// }
|
|
80
|
-
// const timeNow = moment().toISOString()
|
|
81
|
-
// ShStorage.setItem('session_start', timeNow)
|
|
82
|
-
// return true
|
|
291
|
+
}
|
|
292
|
+
const updateSession = () =>{
|
|
293
|
+
if(!window.shInterval) {
|
|
294
|
+
startSession();
|
|
295
|
+
}
|
|
296
|
+
const timeNow = moment().toISOString();
|
|
297
|
+
ShStorage.setItem('last_activity', timeNow);
|
|
298
|
+
window.ShConfirmation = null;
|
|
83
299
|
};
|
|
84
300
|
|
|
85
301
|
let apiUrl = import.meta.env.VITE_APP_API_URL;
|
|
@@ -95,7 +311,7 @@ const axios = Axios.create({
|
|
|
95
311
|
baseURL: apiUrl
|
|
96
312
|
});
|
|
97
313
|
function doGet (endPoint, data) {
|
|
98
|
-
|
|
314
|
+
updateSession();
|
|
99
315
|
return axios.get(endPoint, {
|
|
100
316
|
params: data,
|
|
101
317
|
crossOrigin: true,
|
|
@@ -106,7 +322,7 @@ function doGet (endPoint, data) {
|
|
|
106
322
|
})
|
|
107
323
|
}
|
|
108
324
|
function doPost (endPoint, data) {
|
|
109
|
-
|
|
325
|
+
updateSession();
|
|
110
326
|
return axios.post(endPoint,
|
|
111
327
|
data,
|
|
112
328
|
{
|
|
@@ -2952,180 +3168,6 @@ function render$2(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
2952
3168
|
script$8.render = render$2;
|
|
2953
3169
|
script$8.__file = "src/lib/components/list_templates/Pagination.vue";
|
|
2954
3170
|
|
|
2955
|
-
function swalSuccess (message) {
|
|
2956
|
-
Swal.fire('Success!', message, 'success');
|
|
2957
|
-
}
|
|
2958
|
-
function swalError (message) {
|
|
2959
|
-
Swal.fire('Error!', message, 'error');
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2962
|
-
function swalHttpError (reason) {
|
|
2963
|
-
let error = '';
|
|
2964
|
-
if (typeof reason !== 'undefined') {
|
|
2965
|
-
if (typeof reason.response !== 'undefined') {
|
|
2966
|
-
let reasonString = '';
|
|
2967
|
-
if (typeof reason.response.data === 'string') {
|
|
2968
|
-
reasonString = reason.response.data;
|
|
2969
|
-
} else {
|
|
2970
|
-
reasonString = JSON.stringify(reason.response.data);
|
|
2971
|
-
}
|
|
2972
|
-
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
2973
|
-
} else {
|
|
2974
|
-
if (typeof reason !== 'string') {
|
|
2975
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2976
|
-
} else {
|
|
2977
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
} else {
|
|
2981
|
-
if (typeof reason !== 'string') {
|
|
2982
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2983
|
-
} else {
|
|
2984
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
2985
|
-
}
|
|
2986
|
-
}
|
|
2987
|
-
Swal.fire('Error!', error, 'error');
|
|
2988
|
-
}
|
|
2989
|
-
|
|
2990
|
-
function runSilentRequest (url) {
|
|
2991
|
-
return shApis.doPost(url)
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
function setTabCounts (url) {
|
|
2995
|
-
shApis.doGet(url).then(res => {
|
|
2996
|
-
Object.keys(res.data).forEach(key => {
|
|
2997
|
-
const elem = document.getElementById(key);
|
|
2998
|
-
if (elem === null) {
|
|
2999
|
-
return
|
|
3000
|
-
}
|
|
3001
|
-
if (typeof elem !== 'undefined') {
|
|
3002
|
-
let txt = elem.innerHTML;
|
|
3003
|
-
txt = txt.split('<i class="d-none"></i>')[0];
|
|
3004
|
-
if (parseInt(res.data[key]) > 0) {
|
|
3005
|
-
elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
// document.getElementById(key).innerHTML res.data[key]
|
|
3009
|
-
});
|
|
3010
|
-
});
|
|
3011
|
-
}
|
|
3012
|
-
function formatHttpCatchError (reason) {
|
|
3013
|
-
console.log(reason);
|
|
3014
|
-
let error = '';
|
|
3015
|
-
if (typeof reason !== 'undefined') {
|
|
3016
|
-
if (typeof reason.response !== 'undefined') {
|
|
3017
|
-
alert('here');
|
|
3018
|
-
let reasonString = '';
|
|
3019
|
-
if (typeof reason.response.data === 'string') {
|
|
3020
|
-
reasonString = reason.response.data;
|
|
3021
|
-
} else {
|
|
3022
|
-
reasonString = JSON.stringify(reason.response.data);
|
|
3023
|
-
}
|
|
3024
|
-
error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
|
|
3025
|
-
} else {
|
|
3026
|
-
if (typeof reason !== 'string') {
|
|
3027
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3028
|
-
} else {
|
|
3029
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
} else {
|
|
3033
|
-
if (typeof reason !== 'string') {
|
|
3034
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3035
|
-
} else {
|
|
3036
|
-
error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
|
|
3037
|
-
}
|
|
3038
|
-
}
|
|
3039
|
-
return error
|
|
3040
|
-
}
|
|
3041
|
-
function getMenuCount (url) {
|
|
3042
|
-
shApis.doGet(url).then(res => {
|
|
3043
|
-
console.log(res);
|
|
3044
|
-
});
|
|
3045
|
-
}
|
|
3046
|
-
|
|
3047
|
-
const Toast = Swal.mixin({
|
|
3048
|
-
toast: true,
|
|
3049
|
-
position: 'top-end',
|
|
3050
|
-
showConfirmButton: false,
|
|
3051
|
-
customClass: {
|
|
3052
|
-
popup: 'colored-toast'
|
|
3053
|
-
},
|
|
3054
|
-
iconColor: 'white',
|
|
3055
|
-
timer: 2000,
|
|
3056
|
-
timerProgressBar: true,
|
|
3057
|
-
didOpen: (toast) => {
|
|
3058
|
-
toast.addEventListener('mouseenter', Swal.stopTimer);
|
|
3059
|
-
toast.addEventListener('mouseleave', Swal.resumeTimer);
|
|
3060
|
-
}
|
|
3061
|
-
});
|
|
3062
|
-
function showToast (message, toastType, position) {
|
|
3063
|
-
if (!toastType) {
|
|
3064
|
-
toastType = 'success';
|
|
3065
|
-
}
|
|
3066
|
-
if(!position){
|
|
3067
|
-
position = window.swalPosition;
|
|
3068
|
-
}
|
|
3069
|
-
Toast.mixin({
|
|
3070
|
-
position: position
|
|
3071
|
-
});
|
|
3072
|
-
Toast.fire({
|
|
3073
|
-
icon: toastType,
|
|
3074
|
-
title: message
|
|
3075
|
-
});
|
|
3076
|
-
}
|
|
3077
|
-
|
|
3078
|
-
async function runPlainRequest (url, message, title, data) {
|
|
3079
|
-
if (typeof title === 'undefined') {
|
|
3080
|
-
title = null;
|
|
3081
|
-
}
|
|
3082
|
-
return Swal.fire({
|
|
3083
|
-
title: title !== null ? title : 'Are you sure?',
|
|
3084
|
-
html: message,
|
|
3085
|
-
showCancelButton: true,
|
|
3086
|
-
confirmButtonColor: '#32c787',
|
|
3087
|
-
cancelButtonText: 'No, cancel',
|
|
3088
|
-
confirmButtonText: 'Yes, Proceed!',
|
|
3089
|
-
reverseButtons: true,
|
|
3090
|
-
showLoaderOnConfirm: true,
|
|
3091
|
-
preConfirm: () => {
|
|
3092
|
-
return shApis.doPost(url, data).then(function (response) {
|
|
3093
|
-
return {
|
|
3094
|
-
response: response.data,
|
|
3095
|
-
success: true
|
|
3096
|
-
}
|
|
3097
|
-
})
|
|
3098
|
-
.catch(error => {
|
|
3099
|
-
return {
|
|
3100
|
-
success: false,
|
|
3101
|
-
error: error
|
|
3102
|
-
}
|
|
3103
|
-
})
|
|
3104
|
-
},
|
|
3105
|
-
allowOutsideClick: () => !Swal.isLoading()
|
|
3106
|
-
})
|
|
3107
|
-
}
|
|
3108
|
-
|
|
3109
|
-
function formatDate(date, format) {
|
|
3110
|
-
if (!format) {
|
|
3111
|
-
format = 'lll';
|
|
3112
|
-
}
|
|
3113
|
-
return moment(date).format(format)
|
|
3114
|
-
}
|
|
3115
|
-
|
|
3116
|
-
var shRepo = {
|
|
3117
|
-
swalSuccess,
|
|
3118
|
-
swalError,
|
|
3119
|
-
runPlainRequest,
|
|
3120
|
-
getMenuCount,
|
|
3121
|
-
setTabCounts,
|
|
3122
|
-
showToast,
|
|
3123
|
-
runSilentRequest,
|
|
3124
|
-
swalHttpError,
|
|
3125
|
-
formatHttpCatchError,
|
|
3126
|
-
formatDate
|
|
3127
|
-
};
|
|
3128
|
-
|
|
3129
3171
|
const _hoisted_1$6 = /*#__PURE__*/createElementVNode("span", {
|
|
3130
3172
|
class: "spinner-border spinner-border-sm me-1",
|
|
3131
3173
|
role: "status",
|
|
@@ -4335,13 +4377,18 @@ const useUserStore = defineStore('user-store', {
|
|
|
4335
4377
|
}),
|
|
4336
4378
|
actions: {
|
|
4337
4379
|
setUser (){
|
|
4338
|
-
|
|
4380
|
+
let user = null;
|
|
4381
|
+
try {
|
|
4382
|
+
user = ShStorage.getItem('user') ? ShStorage.getItem('user') : null;
|
|
4383
|
+
} catch (error) {
|
|
4384
|
+
user= null;
|
|
4385
|
+
}
|
|
4339
4386
|
if (user) {
|
|
4340
4387
|
user.isAllowedTo = function (slug) {
|
|
4341
4388
|
if (this.permissions) {
|
|
4342
4389
|
let permissions = [];
|
|
4343
4390
|
if (typeof this.permissions === 'string') {
|
|
4344
|
-
permissions =
|
|
4391
|
+
permissions = this.permissions;
|
|
4345
4392
|
} else {
|
|
4346
4393
|
permissions = this.permissions;
|
|
4347
4394
|
}
|
|
@@ -4352,13 +4399,16 @@ const useUserStore = defineStore('user-store', {
|
|
|
4352
4399
|
}
|
|
4353
4400
|
this.user = user;
|
|
4354
4401
|
shApis.doGet('auth/user').then(res => {
|
|
4355
|
-
|
|
4356
|
-
|
|
4402
|
+
let user = res.data.user;
|
|
4403
|
+
if (typeof(user) === 'undefined') {
|
|
4404
|
+
user = res.data;
|
|
4405
|
+
}
|
|
4406
|
+
ShStorage.setItem('user',user);
|
|
4357
4407
|
user.isAllowedTo = function (slug) {
|
|
4358
4408
|
if (this.permissions) {
|
|
4359
4409
|
let permissions = [];
|
|
4360
4410
|
if (typeof this.permissions === 'string') {
|
|
4361
|
-
permissions =
|
|
4411
|
+
permissions = this.permissions;
|
|
4362
4412
|
} else {
|
|
4363
4413
|
permissions = this.permissions;
|
|
4364
4414
|
}
|
|
@@ -4378,7 +4428,7 @@ const useUserStore = defineStore('user-store', {
|
|
|
4378
4428
|
});
|
|
4379
4429
|
if (this.user) {
|
|
4380
4430
|
if (typeof this.user.permissions === 'string') {
|
|
4381
|
-
this.permissions =
|
|
4431
|
+
this.permissions = this.user.permissions;
|
|
4382
4432
|
} else {
|
|
4383
4433
|
this.permissions = this.user.permissions;
|
|
4384
4434
|
}
|
|
@@ -4559,7 +4609,7 @@ function viewPermissions(rModule) {
|
|
|
4559
4609
|
modulePermissions.value = res.data.permissions;
|
|
4560
4610
|
module.value = rModule;
|
|
4561
4611
|
if (rModule.permissions) {
|
|
4562
|
-
selectedPermissions.value =
|
|
4612
|
+
selectedPermissions.value = rModule.permissions;
|
|
4563
4613
|
}
|
|
4564
4614
|
console.log(module.value);
|
|
4565
4615
|
}).catch(ex => {
|
|
@@ -4815,6 +4865,7 @@ script.__file = "src/lib/components/core/auth/ShAuth.vue";
|
|
|
4815
4865
|
|
|
4816
4866
|
const ShFrontend = {
|
|
4817
4867
|
install: (app, options) => {
|
|
4868
|
+
ShStorage.setItem('ShConfig',options);
|
|
4818
4869
|
if(options.sessionTimeout){
|
|
4819
4870
|
app.provide('sessionTimeout',options.sessionTimeout);
|
|
4820
4871
|
ShStorage.setItem('sessionTimeout',options.sessionTimeout);
|