@iankibetsh/shframework 1.0.9 → 1.1.2

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,6 +63,21 @@
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
+
66
81
  :root {
67
82
  --ck-z-default: 10555 !important;
68
83
  --ck-z-modal: calc(var(--ck-z-default) + 999) !important;
@@ -87,18 +102,3 @@
87
102
  .sh-forgot-link, .sh-register-link{
88
103
  cursor: pointer;
89
104
  }
90
-
91
- .sh-selected-item{
92
- line-height: unset!important;
93
- }
94
- .sh-suggestion-input{
95
- padding: 0.375rem 0.75rem;
96
- }
97
- .sh-suggest{
98
- margin-bottom: 1rem;
99
- }
100
- .sh-suggest-control::after{
101
- margin-top: auto;
102
- margin-bottom: auto;
103
- margin-right: 0.255em;
104
- }
package/dist/library.js CHANGED
@@ -8,8 +8,6 @@ var vue = require('vue');
8
8
  var NProgress = require('nprogress');
9
9
  var Editor = require('@tinymce/tinymce-vue');
10
10
  var Swal = require('sweetalert2');
11
- var ShConfirmAction = require('@/lib/components/ShConfirmAction.vue');
12
- var ShSilentAction = require('@/lib/components/ShSilentAction.vue');
13
11
  var pinia = require('pinia');
14
12
  var vueRouter = require('vue-router');
15
13
 
@@ -20,8 +18,6 @@ var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
20
18
  var NProgress__default = /*#__PURE__*/_interopDefaultLegacy(NProgress);
21
19
  var Editor__default = /*#__PURE__*/_interopDefaultLegacy(Editor);
22
20
  var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
23
- var ShConfirmAction__default = /*#__PURE__*/_interopDefaultLegacy(ShConfirmAction);
24
- var ShSilentAction__default = /*#__PURE__*/_interopDefaultLegacy(ShSilentAction);
25
21
 
26
22
  function setItem (key, value) {
27
23
  let toStore = value;
@@ -43,30 +39,59 @@ var ShStorage = {
43
39
  removeItem
44
40
  };
45
41
 
42
+ function logoutUser(){
43
+ // let logoutUrl = inject()
44
+ const logoutApiEndpoint = vue.inject('logoutApiEndpoint','auth/logout');
45
+ shApis.doPost(logoutApiEndpoint).then(res=>{
46
+ ShStorage.removeItem('access_token');
47
+ ShStorage.removeItem('user');
48
+ // const loginUrl = inject('loginUrl','/login')
49
+ window.location.href = '/login';
50
+ }).catch(ex=>{
51
+ vue.inject('loginUrl','/login');
52
+ ShStorage.removeItem('access_token');
53
+ ShStorage.removeItem('user');
54
+ window.location.href = '/login';
55
+ });
56
+ JSON.parse(ShStorage.getItem('user'));
57
+ }
46
58
  const checkSession = function (isCheking) {
47
59
  let timeout = vue.inject('sessionTimeout');
48
60
  if(!timeout){
49
61
  timeout = 30;
62
+ } else {
63
+ timeout = parseFloat(timeout);
50
64
  }
51
- const sessionStart = ShStorage.getItem('session_start');
52
- const started = moment__default["default"](sessionStart);
53
- if(!sessionStart){
54
- ShStorage.removeItem('access_token');
55
- ShStorage.removeItem('user');
56
- return false
57
- }
58
- const pastMinutes = moment__default["default"]().diff(started, 'minutes');
59
- if(pastMinutes >= timeout) {
60
- ShStorage.removeItem('user');
61
- ShStorage.removeItem('access_token');
62
- return false
65
+ if(window.shLogoutTimeout){
66
+ clearTimeout(window.shLogoutTimeout);
63
67
  }
64
- if (isCheking) {
65
- return true
68
+
69
+ if(ShStorage.getItem('access_token')){
70
+ const timeOutSession = setTimeout(()=>{
71
+ logoutUser();
72
+ }, timeout * 60 * 1000);
73
+ window.shLogoutTimeout = timeOutSession;
66
74
  }
67
- const timeNow = moment__default["default"]().toISOString();
68
- ShStorage.setItem('session_start', timeNow);
69
- return true
75
+
76
+ // const sessionStart = ShStorage.getItem('session_start')
77
+ // const started = moment(sessionStart)
78
+ // if(!sessionStart){
79
+ // ShStorage.removeItem('access_token')
80
+ // ShStorage.removeItem('user')
81
+ // return false
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
70
95
  };
71
96
 
72
97
  let apiUrl = undefined.VITE_APP_API_URL;
@@ -3113,7 +3138,158 @@ var shRepo = {
3113
3138
  formatDate
3114
3139
  };
3115
3140
 
3141
+ const _hoisted_1$6 = /*#__PURE__*/vue.createElementVNode("span", {
3142
+ class: "spinner-border spinner-border-sm me-1",
3143
+ role: "status",
3144
+ "aria-hidden": "true"
3145
+ }, null, -1 /* HOISTED */);
3146
+
3147
+
3116
3148
  var script$7 = {
3149
+ __name: 'ShConfirmAction',
3150
+ props: {
3151
+ data: Object,
3152
+ title: String,
3153
+ message: String,
3154
+ url: {
3155
+ type: String,
3156
+ required: true
3157
+ },
3158
+ loadingMessage: {
3159
+ type: String,
3160
+ default: 'Processing'
3161
+ }
3162
+ },
3163
+ emits: ['actionSuccessful', 'actionFailed','actionCanceled'],
3164
+ setup(__props, { emit }) {
3165
+
3166
+ const props = __props;
3167
+
3168
+
3169
+ const processing = vue.ref(false);
3170
+
3171
+
3172
+ function runAction () {
3173
+ processing.value = true;
3174
+ shRepo.runPlainRequest(props.url, props.message, props.title, props.data).then(res => {
3175
+ if(res.isConfirmed){
3176
+ const value = res.value;
3177
+ if(value.status){
3178
+ emit('actionSuccessful', res);
3179
+ processing.value = false;
3180
+ } else {
3181
+ emit('actionFailed', value);
3182
+ processing.value = false;
3183
+ }
3184
+ } else {
3185
+ emit('actionCanceled');
3186
+ processing.value = false;
3187
+ }
3188
+ }).catch(ex => {
3189
+ emit('actionFailed', ex);
3190
+ processing.value = false;
3191
+ });
3192
+ }
3193
+
3194
+ return (_ctx, _cache) => {
3195
+ return (vue.openBlock(), vue.createElementBlock("a", {
3196
+ class: vue.normalizeClass(processing.value ? 'disabled':''),
3197
+ onClick: runAction
3198
+ }, [
3199
+ (processing.value)
3200
+ ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
3201
+ _hoisted_1$6,
3202
+ vue.createElementVNode("span", null, vue.toDisplayString(__props.loadingMessage), 1 /* TEXT */)
3203
+ ], 64 /* STABLE_FRAGMENT */))
3204
+ : vue.createCommentVNode("v-if", true),
3205
+ (!processing.value)
3206
+ ? vue.renderSlot(_ctx.$slots, "default", { key: 1 })
3207
+ : vue.createCommentVNode("v-if", true)
3208
+ ], 2 /* CLASS */))
3209
+ }
3210
+ }
3211
+
3212
+ };
3213
+
3214
+ script$7.__file = "src/lib/components/ShConfirmAction.vue";
3215
+
3216
+ const _hoisted_1$5 = /*#__PURE__*/vue.createElementVNode("span", {
3217
+ class: "spinner-border spinner-border-sm me-1",
3218
+ role: "status",
3219
+ "aria-hidden": "true"
3220
+ }, null, -1 /* HOISTED */);
3221
+
3222
+ var script$6 = {
3223
+ __name: 'ShSilentAction',
3224
+ props: {
3225
+ data: Object,
3226
+ loadingMessage: {
3227
+ type: String,
3228
+ default: 'Processing'
3229
+ },
3230
+ method: {
3231
+ type: String,
3232
+ default: 'POST'
3233
+ },
3234
+ url: {
3235
+ type: String,
3236
+ required: true
3237
+ }
3238
+ },
3239
+ emits: ['actionSuccessful','actionFailed'],
3240
+ setup(__props, { emit }) {
3241
+
3242
+ const props = __props;
3243
+
3244
+
3245
+ const processing = vue.ref(false);
3246
+
3247
+
3248
+ function runAction(){
3249
+ processing.value = true;
3250
+ if(props.method === 'POST'){
3251
+ shApis.doPost(props.url,props.data).then(res=>{
3252
+ emit('actionSuccessful',res);
3253
+ processing.value = false;
3254
+ }).catch(reason=>{
3255
+ emit('actionFailed', reason);
3256
+ processing.value = false;
3257
+ });
3258
+ }
3259
+ if(props.method === 'GET'){
3260
+ shApis.doGet(props.url,props.data).then(res=>{
3261
+ emit('actionSuccessful',res);
3262
+ processing.value = false;
3263
+ }).catch(reason=>{
3264
+ emit('actionFailed', reason);
3265
+ processing.value = false;
3266
+ });
3267
+ }
3268
+ }
3269
+
3270
+ return (_ctx, _cache) => {
3271
+ return (vue.openBlock(), vue.createElementBlock("a", {
3272
+ class: vue.normalizeClass(processing.value ? 'disabled':''),
3273
+ onClick: runAction
3274
+ }, [
3275
+ (processing.value)
3276
+ ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
3277
+ _hoisted_1$5,
3278
+ vue.createElementVNode("span", null, vue.toDisplayString(__props.loadingMessage), 1 /* TEXT */)
3279
+ ], 64 /* STABLE_FRAGMENT */))
3280
+ : vue.createCommentVNode("v-if", true),
3281
+ (!processing.value)
3282
+ ? vue.renderSlot(_ctx.$slots, "default", { key: 1 })
3283
+ : vue.createCommentVNode("v-if", true)
3284
+ ], 2 /* CLASS */))
3285
+ }
3286
+ }
3287
+
3288
+ };
3289
+
3290
+ script$6.__file = "src/lib/components/ShSilentAction.vue";
3291
+
3292
+ var script$5 = {
3117
3293
  name: 'sh-table',
3118
3294
  props: ['endPoint', 'headers', 'pageCount', 'actions', 'hideCount', 'hideLoadMore', 'links', 'reload', 'hideSearch', 'sharedData', 'searchPlaceholder', 'event', 'displayMore', 'displayMoreBtnClass', 'moreDetailsColumns', 'moreDetailsFields', 'hasDownload', 'downloadFields', 'tableHover', 'hideIds'],
3119
3295
  inject: ['channel'],
@@ -3344,8 +3520,8 @@ var script$7 = {
3344
3520
  this.reloadData();
3345
3521
  },
3346
3522
  components: {
3347
- ShSilentAction: ShSilentAction__default["default"],
3348
- ShConfirmAction: ShConfirmAction__default["default"],
3523
+ ShSilentAction: script$6,
3524
+ ShConfirmAction: script$7,
3349
3525
  ShCanvas: script$9,
3350
3526
  pagination: script$8
3351
3527
  },
@@ -3365,7 +3541,7 @@ var script$7 = {
3365
3541
  }
3366
3542
  };
3367
3543
 
3368
- const _hoisted_1$6 = { class: "auto-table mt-2" };
3544
+ const _hoisted_1$4 = { class: "auto-table mt-2" };
3369
3545
  const _hoisted_2$4 = {
3370
3546
  key: 0,
3371
3547
  class: "col-md-4 mb-2"
@@ -3527,7 +3703,7 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
3527
3703
  const _component_pagination = vue.resolveComponent("pagination");
3528
3704
  const _component_sh_canvas = vue.resolveComponent("sh-canvas");
3529
3705
 
3530
- return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$6, [
3706
+ return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$4, [
3531
3707
  ($props.hasDownload)
3532
3708
  ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$4, [
3533
3709
  vue.createElementVNode("button", {
@@ -3975,10 +4151,10 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
3975
4151
  ]))
3976
4152
  }
3977
4153
 
3978
- script$7.render = render$1;
3979
- script$7.__file = "src/lib/components/ShTable.vue";
4154
+ script$5.render = render$1;
4155
+ script$5.__file = "src/lib/components/ShTable.vue";
3980
4156
 
3981
- var script$6 = {
4157
+ var script$4 = {
3982
4158
  name: 'ShTabs',
3983
4159
  props: ['tabs', 'baseUrl', 'sharedData', 'tabCounts', 'responsive','classOne','classTwo','classes'],
3984
4160
  data () {
@@ -4099,10 +4275,10 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
4099
4275
  ], 64 /* STABLE_FRAGMENT */))
4100
4276
  }
4101
4277
 
4102
- script$6.render = render;
4103
- script$6.__file = "src/lib/components/ShTabs.vue";
4278
+ script$4.render = render;
4279
+ script$4.__file = "src/lib/components/ShTabs.vue";
4104
4280
 
4105
- const _hoisted_1$5 = {
4281
+ const _hoisted_1$3 = {
4106
4282
  class: "nav nav-tabs",
4107
4283
  role: "tablist"
4108
4284
  };
@@ -4113,7 +4289,7 @@ const _hoisted_2$3 = {
4113
4289
  const _hoisted_3$3 = ["onClick"];
4114
4290
  const _hoisted_4$3 = { class: "tab-content" };
4115
4291
 
4116
- var script$5 = {
4292
+ var script$3 = {
4117
4293
  __name: 'ShDynamicTabs',
4118
4294
  props: ['tabs','data'],
4119
4295
  setup(__props) {
@@ -4138,7 +4314,7 @@ function setTab(tab){
4138
4314
 
4139
4315
  return (_ctx, _cache) => {
4140
4316
  return (vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
4141
- vue.createElementVNode("ul", _hoisted_1$5, [
4317
+ vue.createElementVNode("ul", _hoisted_1$3, [
4142
4318
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(tabs), (tab) => {
4143
4319
  return (vue.openBlock(), vue.createElementBlock("li", _hoisted_2$3, [
4144
4320
  vue.createElementVNode("button", {
@@ -4159,158 +4335,7 @@ return (_ctx, _cache) => {
4159
4335
 
4160
4336
  };
4161
4337
 
4162
- script$5.__file = "src/lib/components/ShDynamicTabs.vue";
4163
-
4164
- const _hoisted_1$4 = /*#__PURE__*/vue.createElementVNode("span", {
4165
- class: "spinner-border spinner-border-sm me-1",
4166
- role: "status",
4167
- "aria-hidden": "true"
4168
- }, null, -1 /* HOISTED */);
4169
-
4170
- var script$4 = {
4171
- __name: 'ShSilentAction',
4172
- props: {
4173
- data: Object,
4174
- loadingMessage: {
4175
- type: String,
4176
- default: 'Processing'
4177
- },
4178
- method: {
4179
- type: String,
4180
- default: 'POST'
4181
- },
4182
- url: {
4183
- type: String,
4184
- required: true
4185
- }
4186
- },
4187
- emits: ['actionSuccessful','actionFailed'],
4188
- setup(__props, { emit }) {
4189
-
4190
- const props = __props;
4191
-
4192
-
4193
- const processing = vue.ref(false);
4194
-
4195
-
4196
- function runAction(){
4197
- processing.value = true;
4198
- if(props.method === 'POST'){
4199
- shApis.doPost(props.url,props.data).then(res=>{
4200
- emit('actionSuccessful',res);
4201
- processing.value = false;
4202
- }).catch(reason=>{
4203
- emit('actionFailed', reason);
4204
- processing.value = false;
4205
- });
4206
- }
4207
- if(props.method === 'GET'){
4208
- shApis.doGet(props.url,props.data).then(res=>{
4209
- emit('actionSuccessful',res);
4210
- processing.value = false;
4211
- }).catch(reason=>{
4212
- emit('actionFailed', reason);
4213
- processing.value = false;
4214
- });
4215
- }
4216
- }
4217
-
4218
- return (_ctx, _cache) => {
4219
- return (vue.openBlock(), vue.createElementBlock("a", {
4220
- class: vue.normalizeClass(processing.value ? 'disabled':''),
4221
- onClick: runAction
4222
- }, [
4223
- (processing.value)
4224
- ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
4225
- _hoisted_1$4,
4226
- vue.createElementVNode("span", null, vue.toDisplayString(__props.loadingMessage), 1 /* TEXT */)
4227
- ], 64 /* STABLE_FRAGMENT */))
4228
- : vue.createCommentVNode("v-if", true),
4229
- (!processing.value)
4230
- ? vue.renderSlot(_ctx.$slots, "default", { key: 1 })
4231
- : vue.createCommentVNode("v-if", true)
4232
- ], 2 /* CLASS */))
4233
- }
4234
- }
4235
-
4236
- };
4237
-
4238
- script$4.__file = "src/lib/components/ShSilentAction.vue";
4239
-
4240
- const _hoisted_1$3 = /*#__PURE__*/vue.createElementVNode("span", {
4241
- class: "spinner-border spinner-border-sm me-1",
4242
- role: "status",
4243
- "aria-hidden": "true"
4244
- }, null, -1 /* HOISTED */);
4245
-
4246
-
4247
- var script$3 = {
4248
- __name: 'ShConfirmAction',
4249
- props: {
4250
- data: Object,
4251
- title: String,
4252
- message: String,
4253
- url: {
4254
- type: String,
4255
- required: true
4256
- },
4257
- loadingMessage: {
4258
- type: String,
4259
- default: 'Processing'
4260
- }
4261
- },
4262
- emits: ['actionSuccessful', 'actionFailed','actionCanceled'],
4263
- setup(__props, { emit }) {
4264
-
4265
- const props = __props;
4266
-
4267
-
4268
- const processing = vue.ref(false);
4269
-
4270
-
4271
- function runAction () {
4272
- processing.value = true;
4273
- shRepo.runPlainRequest(props.url, props.message, props.title, props.data).then(res => {
4274
- if(res.isConfirmed){
4275
- const value = res.value;
4276
- if(value.status){
4277
- emit('actionSuccessful', res);
4278
- processing.value = false;
4279
- } else {
4280
- emit('actionFailed', value);
4281
- processing.value = false;
4282
- }
4283
- } else {
4284
- emit('actionCanceled');
4285
- processing.value = false;
4286
- }
4287
- }).catch(ex => {
4288
- emit('actionFailed', ex);
4289
- processing.value = false;
4290
- });
4291
- }
4292
-
4293
- return (_ctx, _cache) => {
4294
- return (vue.openBlock(), vue.createElementBlock("a", {
4295
- class: vue.normalizeClass(processing.value ? 'disabled':''),
4296
- onClick: runAction
4297
- }, [
4298
- (processing.value)
4299
- ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
4300
- _hoisted_1$3,
4301
- vue.createElementVNode("span", null, vue.toDisplayString(__props.loadingMessage), 1 /* TEXT */)
4302
- ], 64 /* STABLE_FRAGMENT */))
4303
- : vue.createCommentVNode("v-if", true),
4304
- (!processing.value)
4305
- ? vue.renderSlot(_ctx.$slots, "default", { key: 1 })
4306
- : vue.createCommentVNode("v-if", true)
4307
- ], 2 /* CLASS */))
4308
- }
4309
- }
4310
-
4311
- };
4312
-
4313
- script$3.__file = "src/lib/components/ShConfirmAction.vue";
4338
+ script$3.__file = "src/lib/components/ShDynamicTabs.vue";
4314
4339
 
4315
4340
  const useUserStore = pinia.defineStore('user-store', {
4316
4341
  state: () => ({
@@ -4438,7 +4463,7 @@ return (_ctx, _cache) => {
4438
4463
  _hoisted_5$2,
4439
4464
  vue.createTextVNode(" ADD DEPARTMENT")
4440
4465
  ], 512 /* NEED_PATCH */),
4441
- vue.createVNode(script$7, {
4466
+ vue.createVNode(script$5, {
4442
4467
  headers: ['id','name','description', 'created_at'],
4443
4468
  "end-point": "admin/departments/list",
4444
4469
  actions: {
@@ -4589,7 +4614,7 @@ return (_ctx, _cache) => {
4589
4614
  vue.createElementVNode("div", _hoisted_2$1, [
4590
4615
  _hoisted_3$1,
4591
4616
  vue.createElementVNode("h5", null, "Department #" + vue.toDisplayString(vue.unref(department).id) + " - " + vue.toDisplayString(vue.unref(department).name) + " Allowed Modules", 1 /* TEXT */),
4592
- vue.createVNode(script$7, {
4617
+ vue.createVNode(script$5, {
4593
4618
  actions: {
4594
4619
  label: 'Actions',
4595
4620
  actions: [
@@ -4811,6 +4836,8 @@ const ShFrontend = {
4811
4836
  const registerEndpoint = options.registerEndpoint ?? 'auth/register';
4812
4837
  const registerTitle = options.registerTitle ?? 'Create a new account';
4813
4838
  const registerSubTitle = options.registerSubTitle ?? `It's quick and easy`;
4839
+ const logoutApiEndpoint = options.logoutApiEndpoint ?? `auth/logout`;
4840
+ const loginUrl = options.loginUrl ?? `/login`;
4814
4841
  const redirectLogin = options.redirectLogin ?? `/`;
4815
4842
  const redirectRegister = options.redirectRegister ?? `/`;
4816
4843
  const registrationFields = options.registrationFields ?? ['name','email','phone','password','password_confirmation'];
@@ -4822,6 +4849,8 @@ const ShFrontend = {
4822
4849
  app.provide('registerSubTitle', registerSubTitle);
4823
4850
  app.provide('redirectLogin', redirectLogin);
4824
4851
  app.provide('redirectRegister', redirectRegister);
4852
+ app.provide('logoutApiEndpoint', logoutApiEndpoint);
4853
+ app.provide('loginUrl', loginUrl);
4825
4854
  window.swalPosition = swalPosition;
4826
4855
  if(options.router) {
4827
4856
  options.router.addRoute({
@@ -4841,17 +4870,17 @@ const ShFrontend = {
4841
4870
  };
4842
4871
 
4843
4872
  exports.ShCanvas = script$9;
4844
- exports.ShConfirmAction = script$3;
4873
+ exports.ShConfirmAction = script$7;
4845
4874
  exports.ShDropDownForm = script$c;
4846
- exports.ShDynamicTabs = script$5;
4875
+ exports.ShDynamicTabs = script$3;
4847
4876
  exports.ShForm = script$d;
4848
4877
  exports.ShFrontend = ShFrontend;
4849
4878
  exports.ShModal = script$b;
4850
4879
  exports.ShModalForm = script$a;
4851
4880
  exports.ShPhone = script$g;
4852
- exports.ShSilentAction = script$4;
4853
- exports.ShTable = script$7;
4854
- exports.ShTabs = script$6;
4881
+ exports.ShSilentAction = script$6;
4882
+ exports.ShTable = script$5;
4883
+ exports.ShTabs = script$4;
4855
4884
  exports.shApis = shApis;
4856
4885
  exports.shRepo = shRepo;
4857
4886
  exports.shStorage = ShStorage;
package/dist/library.mjs CHANGED
@@ -4,8 +4,6 @@ import { inject, openBlock, createElementBlock, createElementVNode, createTextVN
4
4
  import NProgress from 'nprogress';
5
5
  import Editor from '@tinymce/tinymce-vue';
6
6
  import Swal from 'sweetalert2';
7
- import ShConfirmAction from '@/lib/components/ShConfirmAction.vue';
8
- import ShSilentAction from '@/lib/components/ShSilentAction.vue';
9
7
  import { defineStore, storeToRefs } from 'pinia';
10
8
  import { useRoute, useRouter } from 'vue-router';
11
9
 
@@ -29,30 +27,59 @@ var ShStorage = {
29
27
  removeItem
30
28
  };
31
29
 
30
+ function logoutUser(){
31
+ // let logoutUrl = inject()
32
+ const logoutApiEndpoint = inject('logoutApiEndpoint','auth/logout');
33
+ shApis.doPost(logoutApiEndpoint).then(res=>{
34
+ ShStorage.removeItem('access_token');
35
+ ShStorage.removeItem('user');
36
+ // const loginUrl = inject('loginUrl','/login')
37
+ window.location.href = '/login';
38
+ }).catch(ex=>{
39
+ inject('loginUrl','/login');
40
+ ShStorage.removeItem('access_token');
41
+ ShStorage.removeItem('user');
42
+ window.location.href = '/login';
43
+ });
44
+ JSON.parse(ShStorage.getItem('user'));
45
+ }
32
46
  const checkSession = function (isCheking) {
33
47
  let timeout = inject('sessionTimeout');
34
48
  if(!timeout){
35
49
  timeout = 30;
50
+ } else {
51
+ timeout = parseFloat(timeout);
36
52
  }
37
- const sessionStart = ShStorage.getItem('session_start');
38
- const started = moment(sessionStart);
39
- if(!sessionStart){
40
- ShStorage.removeItem('access_token');
41
- ShStorage.removeItem('user');
42
- return false
43
- }
44
- const pastMinutes = moment().diff(started, 'minutes');
45
- if(pastMinutes >= timeout) {
46
- ShStorage.removeItem('user');
47
- ShStorage.removeItem('access_token');
48
- return false
53
+ if(window.shLogoutTimeout){
54
+ clearTimeout(window.shLogoutTimeout);
49
55
  }
50
- if (isCheking) {
51
- return true
56
+
57
+ if(ShStorage.getItem('access_token')){
58
+ const timeOutSession = setTimeout(()=>{
59
+ logoutUser();
60
+ }, timeout * 60 * 1000);
61
+ window.shLogoutTimeout = timeOutSession;
52
62
  }
53
- const timeNow = moment().toISOString();
54
- ShStorage.setItem('session_start', timeNow);
55
- return true
63
+
64
+ // const sessionStart = ShStorage.getItem('session_start')
65
+ // const started = moment(sessionStart)
66
+ // if(!sessionStart){
67
+ // ShStorage.removeItem('access_token')
68
+ // ShStorage.removeItem('user')
69
+ // return false
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
56
83
  };
57
84
 
58
85
  let apiUrl = import.meta.env.VITE_APP_API_URL;
@@ -3099,7 +3126,158 @@ var shRepo = {
3099
3126
  formatDate
3100
3127
  };
3101
3128
 
3129
+ const _hoisted_1$6 = /*#__PURE__*/createElementVNode("span", {
3130
+ class: "spinner-border spinner-border-sm me-1",
3131
+ role: "status",
3132
+ "aria-hidden": "true"
3133
+ }, null, -1 /* HOISTED */);
3134
+
3135
+
3102
3136
  var script$7 = {
3137
+ __name: 'ShConfirmAction',
3138
+ props: {
3139
+ data: Object,
3140
+ title: String,
3141
+ message: String,
3142
+ url: {
3143
+ type: String,
3144
+ required: true
3145
+ },
3146
+ loadingMessage: {
3147
+ type: String,
3148
+ default: 'Processing'
3149
+ }
3150
+ },
3151
+ emits: ['actionSuccessful', 'actionFailed','actionCanceled'],
3152
+ setup(__props, { emit }) {
3153
+
3154
+ const props = __props;
3155
+
3156
+
3157
+ const processing = ref(false);
3158
+
3159
+
3160
+ function runAction () {
3161
+ processing.value = true;
3162
+ shRepo.runPlainRequest(props.url, props.message, props.title, props.data).then(res => {
3163
+ if(res.isConfirmed){
3164
+ const value = res.value;
3165
+ if(value.status){
3166
+ emit('actionSuccessful', res);
3167
+ processing.value = false;
3168
+ } else {
3169
+ emit('actionFailed', value);
3170
+ processing.value = false;
3171
+ }
3172
+ } else {
3173
+ emit('actionCanceled');
3174
+ processing.value = false;
3175
+ }
3176
+ }).catch(ex => {
3177
+ emit('actionFailed', ex);
3178
+ processing.value = false;
3179
+ });
3180
+ }
3181
+
3182
+ return (_ctx, _cache) => {
3183
+ return (openBlock(), createElementBlock("a", {
3184
+ class: normalizeClass(processing.value ? 'disabled':''),
3185
+ onClick: runAction
3186
+ }, [
3187
+ (processing.value)
3188
+ ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
3189
+ _hoisted_1$6,
3190
+ createElementVNode("span", null, toDisplayString(__props.loadingMessage), 1 /* TEXT */)
3191
+ ], 64 /* STABLE_FRAGMENT */))
3192
+ : createCommentVNode("v-if", true),
3193
+ (!processing.value)
3194
+ ? renderSlot(_ctx.$slots, "default", { key: 1 })
3195
+ : createCommentVNode("v-if", true)
3196
+ ], 2 /* CLASS */))
3197
+ }
3198
+ }
3199
+
3200
+ };
3201
+
3202
+ script$7.__file = "src/lib/components/ShConfirmAction.vue";
3203
+
3204
+ const _hoisted_1$5 = /*#__PURE__*/createElementVNode("span", {
3205
+ class: "spinner-border spinner-border-sm me-1",
3206
+ role: "status",
3207
+ "aria-hidden": "true"
3208
+ }, null, -1 /* HOISTED */);
3209
+
3210
+ var script$6 = {
3211
+ __name: 'ShSilentAction',
3212
+ props: {
3213
+ data: Object,
3214
+ loadingMessage: {
3215
+ type: String,
3216
+ default: 'Processing'
3217
+ },
3218
+ method: {
3219
+ type: String,
3220
+ default: 'POST'
3221
+ },
3222
+ url: {
3223
+ type: String,
3224
+ required: true
3225
+ }
3226
+ },
3227
+ emits: ['actionSuccessful','actionFailed'],
3228
+ setup(__props, { emit }) {
3229
+
3230
+ const props = __props;
3231
+
3232
+
3233
+ const processing = ref(false);
3234
+
3235
+
3236
+ function runAction(){
3237
+ processing.value = true;
3238
+ if(props.method === 'POST'){
3239
+ shApis.doPost(props.url,props.data).then(res=>{
3240
+ emit('actionSuccessful',res);
3241
+ processing.value = false;
3242
+ }).catch(reason=>{
3243
+ emit('actionFailed', reason);
3244
+ processing.value = false;
3245
+ });
3246
+ }
3247
+ if(props.method === 'GET'){
3248
+ shApis.doGet(props.url,props.data).then(res=>{
3249
+ emit('actionSuccessful',res);
3250
+ processing.value = false;
3251
+ }).catch(reason=>{
3252
+ emit('actionFailed', reason);
3253
+ processing.value = false;
3254
+ });
3255
+ }
3256
+ }
3257
+
3258
+ return (_ctx, _cache) => {
3259
+ return (openBlock(), createElementBlock("a", {
3260
+ class: normalizeClass(processing.value ? 'disabled':''),
3261
+ onClick: runAction
3262
+ }, [
3263
+ (processing.value)
3264
+ ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
3265
+ _hoisted_1$5,
3266
+ createElementVNode("span", null, toDisplayString(__props.loadingMessage), 1 /* TEXT */)
3267
+ ], 64 /* STABLE_FRAGMENT */))
3268
+ : createCommentVNode("v-if", true),
3269
+ (!processing.value)
3270
+ ? renderSlot(_ctx.$slots, "default", { key: 1 })
3271
+ : createCommentVNode("v-if", true)
3272
+ ], 2 /* CLASS */))
3273
+ }
3274
+ }
3275
+
3276
+ };
3277
+
3278
+ script$6.__file = "src/lib/components/ShSilentAction.vue";
3279
+
3280
+ var script$5 = {
3103
3281
  name: 'sh-table',
3104
3282
  props: ['endPoint', 'headers', 'pageCount', 'actions', 'hideCount', 'hideLoadMore', 'links', 'reload', 'hideSearch', 'sharedData', 'searchPlaceholder', 'event', 'displayMore', 'displayMoreBtnClass', 'moreDetailsColumns', 'moreDetailsFields', 'hasDownload', 'downloadFields', 'tableHover', 'hideIds'],
3105
3283
  inject: ['channel'],
@@ -3330,8 +3508,8 @@ var script$7 = {
3330
3508
  this.reloadData();
3331
3509
  },
3332
3510
  components: {
3333
- ShSilentAction,
3334
- ShConfirmAction,
3511
+ ShSilentAction: script$6,
3512
+ ShConfirmAction: script$7,
3335
3513
  ShCanvas: script$9,
3336
3514
  pagination: script$8
3337
3515
  },
@@ -3351,7 +3529,7 @@ var script$7 = {
3351
3529
  }
3352
3530
  };
3353
3531
 
3354
- const _hoisted_1$6 = { class: "auto-table mt-2" };
3532
+ const _hoisted_1$4 = { class: "auto-table mt-2" };
3355
3533
  const _hoisted_2$4 = {
3356
3534
  key: 0,
3357
3535
  class: "col-md-4 mb-2"
@@ -3513,7 +3691,7 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
3513
3691
  const _component_pagination = resolveComponent("pagination");
3514
3692
  const _component_sh_canvas = resolveComponent("sh-canvas");
3515
3693
 
3516
- return (openBlock(), createElementBlock("div", _hoisted_1$6, [
3694
+ return (openBlock(), createElementBlock("div", _hoisted_1$4, [
3517
3695
  ($props.hasDownload)
3518
3696
  ? (openBlock(), createElementBlock("div", _hoisted_2$4, [
3519
3697
  createElementVNode("button", {
@@ -3961,10 +4139,10 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
3961
4139
  ]))
3962
4140
  }
3963
4141
 
3964
- script$7.render = render$1;
3965
- script$7.__file = "src/lib/components/ShTable.vue";
4142
+ script$5.render = render$1;
4143
+ script$5.__file = "src/lib/components/ShTable.vue";
3966
4144
 
3967
- var script$6 = {
4145
+ var script$4 = {
3968
4146
  name: 'ShTabs',
3969
4147
  props: ['tabs', 'baseUrl', 'sharedData', 'tabCounts', 'responsive','classOne','classTwo','classes'],
3970
4148
  data () {
@@ -4085,10 +4263,10 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
4085
4263
  ], 64 /* STABLE_FRAGMENT */))
4086
4264
  }
4087
4265
 
4088
- script$6.render = render;
4089
- script$6.__file = "src/lib/components/ShTabs.vue";
4266
+ script$4.render = render;
4267
+ script$4.__file = "src/lib/components/ShTabs.vue";
4090
4268
 
4091
- const _hoisted_1$5 = {
4269
+ const _hoisted_1$3 = {
4092
4270
  class: "nav nav-tabs",
4093
4271
  role: "tablist"
4094
4272
  };
@@ -4099,7 +4277,7 @@ const _hoisted_2$3 = {
4099
4277
  const _hoisted_3$3 = ["onClick"];
4100
4278
  const _hoisted_4$3 = { class: "tab-content" };
4101
4279
 
4102
- var script$5 = {
4280
+ var script$3 = {
4103
4281
  __name: 'ShDynamicTabs',
4104
4282
  props: ['tabs','data'],
4105
4283
  setup(__props) {
@@ -4124,7 +4302,7 @@ function setTab(tab){
4124
4302
 
4125
4303
  return (_ctx, _cache) => {
4126
4304
  return (openBlock(), createElementBlock(Fragment, null, [
4127
- createElementVNode("ul", _hoisted_1$5, [
4305
+ createElementVNode("ul", _hoisted_1$3, [
4128
4306
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(tabs), (tab) => {
4129
4307
  return (openBlock(), createElementBlock("li", _hoisted_2$3, [
4130
4308
  createElementVNode("button", {
@@ -4145,158 +4323,7 @@ return (_ctx, _cache) => {
4145
4323
 
4146
4324
  };
4147
4325
 
4148
- script$5.__file = "src/lib/components/ShDynamicTabs.vue";
4149
-
4150
- const _hoisted_1$4 = /*#__PURE__*/createElementVNode("span", {
4151
- class: "spinner-border spinner-border-sm me-1",
4152
- role: "status",
4153
- "aria-hidden": "true"
4154
- }, null, -1 /* HOISTED */);
4155
-
4156
- var script$4 = {
4157
- __name: 'ShSilentAction',
4158
- props: {
4159
- data: Object,
4160
- loadingMessage: {
4161
- type: String,
4162
- default: 'Processing'
4163
- },
4164
- method: {
4165
- type: String,
4166
- default: 'POST'
4167
- },
4168
- url: {
4169
- type: String,
4170
- required: true
4171
- }
4172
- },
4173
- emits: ['actionSuccessful','actionFailed'],
4174
- setup(__props, { emit }) {
4175
-
4176
- const props = __props;
4177
-
4178
-
4179
- const processing = ref(false);
4180
-
4181
-
4182
- function runAction(){
4183
- processing.value = true;
4184
- if(props.method === 'POST'){
4185
- shApis.doPost(props.url,props.data).then(res=>{
4186
- emit('actionSuccessful',res);
4187
- processing.value = false;
4188
- }).catch(reason=>{
4189
- emit('actionFailed', reason);
4190
- processing.value = false;
4191
- });
4192
- }
4193
- if(props.method === 'GET'){
4194
- shApis.doGet(props.url,props.data).then(res=>{
4195
- emit('actionSuccessful',res);
4196
- processing.value = false;
4197
- }).catch(reason=>{
4198
- emit('actionFailed', reason);
4199
- processing.value = false;
4200
- });
4201
- }
4202
- }
4203
-
4204
- return (_ctx, _cache) => {
4205
- return (openBlock(), createElementBlock("a", {
4206
- class: normalizeClass(processing.value ? 'disabled':''),
4207
- onClick: runAction
4208
- }, [
4209
- (processing.value)
4210
- ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
4211
- _hoisted_1$4,
4212
- createElementVNode("span", null, toDisplayString(__props.loadingMessage), 1 /* TEXT */)
4213
- ], 64 /* STABLE_FRAGMENT */))
4214
- : createCommentVNode("v-if", true),
4215
- (!processing.value)
4216
- ? renderSlot(_ctx.$slots, "default", { key: 1 })
4217
- : createCommentVNode("v-if", true)
4218
- ], 2 /* CLASS */))
4219
- }
4220
- }
4221
-
4222
- };
4223
-
4224
- script$4.__file = "src/lib/components/ShSilentAction.vue";
4225
-
4226
- const _hoisted_1$3 = /*#__PURE__*/createElementVNode("span", {
4227
- class: "spinner-border spinner-border-sm me-1",
4228
- role: "status",
4229
- "aria-hidden": "true"
4230
- }, null, -1 /* HOISTED */);
4231
-
4232
-
4233
- var script$3 = {
4234
- __name: 'ShConfirmAction',
4235
- props: {
4236
- data: Object,
4237
- title: String,
4238
- message: String,
4239
- url: {
4240
- type: String,
4241
- required: true
4242
- },
4243
- loadingMessage: {
4244
- type: String,
4245
- default: 'Processing'
4246
- }
4247
- },
4248
- emits: ['actionSuccessful', 'actionFailed','actionCanceled'],
4249
- setup(__props, { emit }) {
4250
-
4251
- const props = __props;
4252
-
4253
-
4254
- const processing = ref(false);
4255
-
4256
-
4257
- function runAction () {
4258
- processing.value = true;
4259
- shRepo.runPlainRequest(props.url, props.message, props.title, props.data).then(res => {
4260
- if(res.isConfirmed){
4261
- const value = res.value;
4262
- if(value.status){
4263
- emit('actionSuccessful', res);
4264
- processing.value = false;
4265
- } else {
4266
- emit('actionFailed', value);
4267
- processing.value = false;
4268
- }
4269
- } else {
4270
- emit('actionCanceled');
4271
- processing.value = false;
4272
- }
4273
- }).catch(ex => {
4274
- emit('actionFailed', ex);
4275
- processing.value = false;
4276
- });
4277
- }
4278
-
4279
- return (_ctx, _cache) => {
4280
- return (openBlock(), createElementBlock("a", {
4281
- class: normalizeClass(processing.value ? 'disabled':''),
4282
- onClick: runAction
4283
- }, [
4284
- (processing.value)
4285
- ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
4286
- _hoisted_1$3,
4287
- createElementVNode("span", null, toDisplayString(__props.loadingMessage), 1 /* TEXT */)
4288
- ], 64 /* STABLE_FRAGMENT */))
4289
- : createCommentVNode("v-if", true),
4290
- (!processing.value)
4291
- ? renderSlot(_ctx.$slots, "default", { key: 1 })
4292
- : createCommentVNode("v-if", true)
4293
- ], 2 /* CLASS */))
4294
- }
4295
- }
4296
-
4297
- };
4298
-
4299
- script$3.__file = "src/lib/components/ShConfirmAction.vue";
4326
+ script$3.__file = "src/lib/components/ShDynamicTabs.vue";
4300
4327
 
4301
4328
  const useUserStore = defineStore('user-store', {
4302
4329
  state: () => ({
@@ -4424,7 +4451,7 @@ return (_ctx, _cache) => {
4424
4451
  _hoisted_5$2,
4425
4452
  createTextVNode(" ADD DEPARTMENT")
4426
4453
  ], 512 /* NEED_PATCH */),
4427
- createVNode(script$7, {
4454
+ createVNode(script$5, {
4428
4455
  headers: ['id','name','description', 'created_at'],
4429
4456
  "end-point": "admin/departments/list",
4430
4457
  actions: {
@@ -4575,7 +4602,7 @@ return (_ctx, _cache) => {
4575
4602
  createElementVNode("div", _hoisted_2$1, [
4576
4603
  _hoisted_3$1,
4577
4604
  createElementVNode("h5", null, "Department #" + toDisplayString(unref(department).id) + " - " + toDisplayString(unref(department).name) + " Allowed Modules", 1 /* TEXT */),
4578
- createVNode(script$7, {
4605
+ createVNode(script$5, {
4579
4606
  actions: {
4580
4607
  label: 'Actions',
4581
4608
  actions: [
@@ -4797,6 +4824,8 @@ const ShFrontend = {
4797
4824
  const registerEndpoint = options.registerEndpoint ?? 'auth/register';
4798
4825
  const registerTitle = options.registerTitle ?? 'Create a new account';
4799
4826
  const registerSubTitle = options.registerSubTitle ?? `It's quick and easy`;
4827
+ const logoutApiEndpoint = options.logoutApiEndpoint ?? `auth/logout`;
4828
+ const loginUrl = options.loginUrl ?? `/login`;
4800
4829
  const redirectLogin = options.redirectLogin ?? `/`;
4801
4830
  const redirectRegister = options.redirectRegister ?? `/`;
4802
4831
  const registrationFields = options.registrationFields ?? ['name','email','phone','password','password_confirmation'];
@@ -4808,6 +4837,8 @@ const ShFrontend = {
4808
4837
  app.provide('registerSubTitle', registerSubTitle);
4809
4838
  app.provide('redirectLogin', redirectLogin);
4810
4839
  app.provide('redirectRegister', redirectRegister);
4840
+ app.provide('logoutApiEndpoint', logoutApiEndpoint);
4841
+ app.provide('loginUrl', loginUrl);
4811
4842
  window.swalPosition = swalPosition;
4812
4843
  if(options.router) {
4813
4844
  options.router.addRoute({
@@ -4826,4 +4857,4 @@ const ShFrontend = {
4826
4857
  }
4827
4858
  };
4828
4859
 
4829
- export { script$9 as ShCanvas, script$3 as ShConfirmAction, script$c as ShDropDownForm, script$5 as ShDynamicTabs, script$d as ShForm, ShFrontend, script$b as ShModal, script$a as ShModalForm, script$g as ShPhone, script$4 as ShSilentAction, script$7 as ShTable, script$6 as ShTabs, shApis, shRepo, ShStorage as shStorage, useUserStore };
4860
+ export { script$9 as ShCanvas, script$7 as ShConfirmAction, script$c as ShDropDownForm, script$3 as ShDynamicTabs, script$d as ShForm, ShFrontend, script$b as ShModal, script$a as ShModalForm, script$g as ShPhone, script$6 as ShSilentAction, script$5 as ShTable, script$4 as ShTabs, shApis, shRepo, ShStorage as shStorage, useUserStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "1.0.9",
3
+ "version": "1.1.2",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",