@iankibetsh/shframework 4.0.2 → 4.0.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.
Files changed (3) hide show
  1. package/dist/library.js +204 -186
  2. package/dist/library.mjs +204 -186
  3. package/package.json +1 -1
package/dist/library.js CHANGED
@@ -5,12 +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 bootstrap = require('bootstrap');
8
9
  var NProgress = require('nprogress');
9
10
  var vue = require('vue');
10
11
  var _ = require('lodash');
11
12
  var vueRouter = require('vue-router');
12
13
  var pinia = require('pinia');
13
- var bootstrap = require('bootstrap');
14
14
 
15
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
16
 
@@ -44,221 +44,238 @@ var ShStorage = {
44
44
  removeItem
45
45
  };
46
46
 
47
- function swalSuccess (message) {
48
- Swal__default["default"].fire('Success!', message, 'success');
47
+ function swalSuccess(message){
48
+ Swal__default["default"].fire('Success!', message, 'success');
49
49
  }
50
- function swalError (message) {
51
- Swal__default["default"].fire('Error!', message, 'error');
50
+
51
+ function swalError(message){
52
+ Swal__default["default"].fire('Error!', message, 'error');
52
53
  }
53
54
 
54
- function swalHttpError (reason) {
55
- let error = '';
56
- if (typeof reason !== 'undefined') {
57
- if (typeof reason.response !== 'undefined') {
58
- let reasonString = '';
59
- if (typeof reason.response.data === 'string') {
60
- reasonString = reason.response.data;
61
- } else {
62
- reasonString = JSON.stringify(reason.response.data);
63
- }
64
- error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
65
- } else {
66
- if (typeof reason !== 'string') {
67
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
68
- } else {
69
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
70
- }
71
- }
72
- } else {
73
- if (typeof reason !== 'string') {
74
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
55
+ function swalHttpError(reason){
56
+ let error = '';
57
+ if (typeof reason !== 'undefined') {
58
+ if (typeof reason.response !== 'undefined') {
59
+ let reasonString = '';
60
+ if (typeof reason.response.data === 'string') {
61
+ reasonString = reason.response.data;
62
+ } else {
63
+ reasonString = JSON.stringify(reason.response.data);
64
+ }
65
+ error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
66
+ } else {
67
+ if (typeof reason !== 'string') {
68
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
69
+ } else {
70
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
71
+ }
72
+ }
75
73
  } else {
76
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
74
+ if (typeof reason !== 'string') {
75
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
76
+ } else {
77
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
78
+ }
77
79
  }
78
- }
79
- Swal__default["default"].fire('Error!', error, 'error');
80
+ Swal__default["default"].fire('Error!', error, 'error');
80
81
  }
81
82
 
82
- function runSilentRequest (url) {
83
- return shApis.doPost(url)
83
+ function runSilentRequest(url){
84
+ return shApis.doPost(url)
84
85
  }
85
86
 
86
- function setTabCounts (url) {
87
- shApis.doGet(url).then(res => {
88
- Object.keys(res.data).forEach(key => {
89
- const elem = document.getElementById(key);
90
- if (elem === null) {
91
- return
92
- }
93
- if (typeof elem !== 'undefined') {
94
- let txt = elem.innerHTML;
95
- txt = txt.split('<i class="d-none"></i>')[0];
96
- if (parseInt(res.data[key]) > 0) {
97
- elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
98
- }
99
- }
100
- // document.getElementById(key).innerHTML res.data[key]
87
+ function setTabCounts(url){
88
+ shApis.doGet(url).then(res => {
89
+ Object.keys(res.data).forEach(key => {
90
+ const elem = document.getElementById(key);
91
+ if (elem === null) {
92
+ return
93
+ }
94
+ if (typeof elem !== 'undefined') {
95
+ let txt = elem.innerHTML;
96
+ txt = txt.split('<i class="d-none"></i>')[0];
97
+ if (parseInt(res.data[key]) > 0) {
98
+ elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
99
+ }
100
+ }
101
+ // document.getElementById(key).innerHTML res.data[key]
102
+ });
101
103
  });
102
- });
103
104
  }
104
- function formatHttpCatchError (reason) {
105
- console.log(reason);
106
- let error = '';
107
- if (typeof reason !== 'undefined') {
108
- if (typeof reason.response !== 'undefined') {
109
- alert('here');
110
- let reasonString = '';
111
- if (typeof reason.response.data === 'string') {
112
- reasonString = reason.response.data;
113
- } else {
114
- reasonString = JSON.stringify(reason.response.data);
115
- }
116
- error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
117
- } else {
118
- if (typeof reason !== 'string') {
119
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
120
- } else {
121
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
122
- }
123
- }
124
- } else {
125
- if (typeof reason !== 'string') {
126
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
105
+
106
+ function formatHttpCatchError(reason){
107
+ console.log(reason);
108
+ let error = '';
109
+ if (typeof reason !== 'undefined') {
110
+ if (typeof reason.response !== 'undefined') {
111
+ alert('here');
112
+ let reasonString = '';
113
+ if (typeof reason.response.data === 'string') {
114
+ reasonString = reason.response.data;
115
+ } else {
116
+ reasonString = JSON.stringify(reason.response.data);
117
+ }
118
+ error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
119
+ } else {
120
+ if (typeof reason !== 'string') {
121
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
122
+ } else {
123
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
124
+ }
125
+ }
127
126
  } else {
128
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
127
+ if (typeof reason !== 'string') {
128
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
129
+ } else {
130
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
131
+ }
129
132
  }
130
- }
131
- return error
133
+ return error
132
134
  }
133
- function getMenuCount (url) {
134
- shApis.doGet(url).then(res => {
135
- console.log(res);
136
- });
135
+
136
+ function getMenuCount(url){
137
+ shApis.doGet(url).then(res => {
138
+ console.log(res);
139
+ });
137
140
  }
138
141
 
139
- const signOutUser = ()=>{
140
- const loginUrl = getShConfig('loginUrl','auth/login');
141
- const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
142
- console.log(loginUrl,logoutApiEndPoint);
143
- shApis.doPost(logoutApiEndPoint).then(res=>{
144
- ShStorage.removeItem('access_token');
145
- ShStorage.removeItem('user');
146
- ShStorage.removeItem('last_activity');
147
- window.location.href = loginUrl;
148
- }).catch(ex=>{
149
- ShStorage.removeItem('access_token');
150
- ShStorage.removeItem('user');
151
- ShStorage.removeItem('last_activity');
152
- window.location.href = loginUrl;
153
- });
142
+ const signOutUser = () => {
143
+ const loginUrl = getShConfig('loginUrl', 'auth/login');
144
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint', 'auth/logout');
145
+ console.log(loginUrl, logoutApiEndPoint);
146
+ shApis.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
+ });
154
157
  };
155
158
 
156
159
 
160
+ function getShConfig(key = null, def = ''){
157
161
 
158
- function getShConfig(key = null,def = '') {
159
-
160
- const config = ShStorage.getItem('ShConfig') ?? {};
161
- if(key) {
162
- return config[key] ?? def
163
- }
164
- return config
165
- }
166
- function showToast (message, toastType, config) {
167
- const mixinConfig = {
168
- toast: true,
169
- position: 'top-end',
170
- showConfirmButton: false,
171
- customClass: {
172
- popup: 'colored-toast'
173
- },
174
- iconColor: 'white',
175
- timer: 2000,
176
- timerProgressBar: true,
177
- didOpen: (toast) => {
178
- toast.addEventListener('mouseenter', Swal__default["default"].stopTimer);
179
- toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
162
+ const config = ShStorage.getItem('ShConfig') ?? {};
163
+ if (key) {
164
+ return config[key] ?? def
180
165
  }
181
- };
182
- if (!toastType) {
183
- toastType = 'success';
184
- }
185
- if(config){
186
- Object.keys(config).map(key=>mixinConfig[key] = config[key]);
187
- }
188
- console.log(mixinConfig);
189
- const Toast = Swal__default["default"].mixin(mixinConfig);
190
- // Toast.mixin({
191
- // position: 'top'
192
- // })
193
- Toast.fire({
194
- icon: toastType,
195
- title: message,
196
- postion: 'bottom'
197
- });
166
+ return config
198
167
  }
199
168
 
200
- async function runPlainRequest (url, message, title, data) {
201
- if (typeof title === 'undefined') {
202
- title = null;
203
- }
204
- return Swal__default["default"].fire({
205
- title: title !== null ? title : 'Are you sure?',
206
- html: message,
207
- showCancelButton: true,
208
- confirmButtonColor: '#32c787',
209
- cancelButtonText: 'No, cancel',
210
- confirmButtonText: 'Yes, Proceed!',
211
- reverseButtons: true,
212
- showLoaderOnConfirm: true,
213
- preConfirm: () => {
214
- return shApis.doPost(url, data).then(function (response) {
215
- return {
216
- response: response.data,
217
- success: true
169
+ function showToast(message, toastType, config){
170
+ const mixinConfig = {
171
+ toast: true,
172
+ position: 'top-end',
173
+ showConfirmButton: false,
174
+ customClass: {
175
+ popup: 'colored-toast'
176
+ },
177
+ iconColor: 'white',
178
+ timer: 2000,
179
+ timerProgressBar: true,
180
+ didOpen: (toast) => {
181
+ toast.addEventListener('mouseenter', Swal__default["default"].stopTimer);
182
+ toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
218
183
  }
219
- })
220
- .catch(error => {
221
- return {
222
- success: false,
223
- error: error
224
- }
225
- })
226
- },
227
- allowOutsideClick: () => !Swal__default["default"].isLoading()
228
- })
184
+ };
185
+ if (!toastType) {
186
+ toastType = 'success';
187
+ }
188
+ if (config) {
189
+ Object.keys(config).map(key => mixinConfig[key] = config[key]);
190
+ }
191
+ console.log(mixinConfig);
192
+ const Toast = Swal__default["default"].mixin(mixinConfig);
193
+ // Toast.mixin({
194
+ // position: 'top'
195
+ // })
196
+ Toast.fire({
197
+ icon: toastType,
198
+ title: message,
199
+ postion: 'bottom'
200
+ });
229
201
  }
230
202
 
231
- function formatDate(date, format) {
232
- if (!format) {
233
- format = 'lll';
234
- }
235
- return moment__default["default"](date).format(format)
203
+ async function runPlainRequest(url, message, title, data){
204
+ if (typeof title === 'undefined') {
205
+ title = null;
206
+ }
207
+ return Swal__default["default"].fire({
208
+ title: title !== null ? title : 'Are you sure?',
209
+ html: message,
210
+ showCancelButton: true,
211
+ confirmButtonColor: '#32c787',
212
+ cancelButtonText: 'No, cancel',
213
+ confirmButtonText: 'Yes, Proceed!',
214
+ reverseButtons: true,
215
+ showLoaderOnConfirm: true,
216
+ preConfirm: () => {
217
+ return shApis.doPost(url, data).then(function (response){
218
+ return {
219
+ response: response.data,
220
+ success: true
221
+ }
222
+ })
223
+ .catch(error => {
224
+ return {
225
+ success: false,
226
+ error: error
227
+ }
228
+ })
229
+ },
230
+ allowOutsideClick: () => !Swal__default["default"].isLoading()
231
+ })
236
232
  }
237
- function formatNumber(amount,decimalPoints = 0){
238
- return numberFormat(amount,decimalPoints)
233
+
234
+ function formatDate(date, format){
235
+ if (!format) {
236
+ format = 'lll';
237
+ }
238
+ return moment__default["default"](date).format(format)
239
239
  }
240
- function numberFormat(amount,decimalPoints = 0) {
241
- let formatted = parseFloat(amount).toFixed(decimalPoints);
242
- formatted = new Intl.NumberFormat().format(formatted);
243
- const formattedArr = formatted.split('.');
244
- return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
240
+
241
+ function formatNumber(amount, decimalPoints = 0){
242
+ return numberFormat(amount, decimalPoints)
245
243
  }
246
244
 
245
+ function numberFormat(amount, decimalPoints = 0){
246
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
247
+ formatted = new Intl.NumberFormat().format(formatted);
248
+ const formattedArr = formatted.split('.');
249
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] + '.' + (formattedArr[1] || '0').padEnd(decimalPoints, 0)
250
+ }
251
+
252
+ const showModal = modalId => {
253
+ const modal = new bootstrap.Modal(document.getElementById(modalId));
254
+ modal.show();
255
+ };
256
+
257
+ const hideModal = modalId => {
258
+ const modal = new bootstrap.Modal(document.getElementById(modalId));
259
+ modal.hide();
260
+ };
261
+
247
262
  var shRepo = {
248
- swalSuccess,
249
- swalError,
250
- runPlainRequest,
251
- getMenuCount,
252
- setTabCounts,
253
- getShConfig,
254
- showToast,
255
- runSilentRequest,
256
- swalHttpError,
257
- formatHttpCatchError,
258
- formatDate,
259
- numberFormat,
260
- formatNumber,
261
- signOutUser
263
+ swalSuccess,
264
+ swalError,
265
+ runPlainRequest,
266
+ getMenuCount,
267
+ setTabCounts,
268
+ getShConfig,
269
+ showToast,
270
+ runSilentRequest,
271
+ swalHttpError,
272
+ formatHttpCatchError,
273
+ formatDate,
274
+ numberFormat,
275
+ formatNumber,
276
+ signOutUser,
277
+ showModal,
278
+ hideModal
262
279
  };
263
280
 
264
281
  startSession();
@@ -3114,7 +3131,7 @@ const getFieldComponent = (fieldObj)=>{
3114
3131
  if(fieldObj.component){
3115
3132
  return fieldObj.component
3116
3133
  }
3117
- const field = fieldObj.field;
3134
+ const field = fieldObj.field ?? fieldObj.name;
3118
3135
  const defaultTextareas = ['message', 'meta_description', 'comment', 'call_response', 'comments', 'description'];
3119
3136
  const defaultNumbers = ['age'];
3120
3137
  const passwords = ['password','password_confirmation','pin'];
@@ -3266,6 +3283,7 @@ vue.onMounted((ev)=>{
3266
3283
  props.fields && props.fields.map(field=>{
3267
3284
  if(typeof field === 'object') {
3268
3285
  const fieldObj = {...field};
3286
+ fieldObj.field = fieldObj.field ?? fieldObj.name;
3269
3287
  // fieldObj.label && getLabel(fieldObj.field)
3270
3288
  fieldObj.helper = fieldObj.helperText ?? fieldObj.helper;
3271
3289
  // !fieldObj.helper && fieldObj.helperText ? fieldObj.helper = fieldObj.helperText : fieldObj.helper = getHelperText(fieldObj.field)
package/dist/library.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import Axios from 'axios';
2
2
  import moment from 'moment';
3
3
  import Swal from 'sweetalert2';
4
+ import { Modal, Offcanvas } from 'bootstrap';
4
5
  import NProgress from 'nprogress';
5
6
  import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, ref, onMounted, unref, normalizeClass, resolveComponent, createBlock, resolveDynamicComponent, watch, inject, mergeProps, normalizeStyle, renderSlot, createVNode, normalizeProps, guardReactiveProps, withCtx, createStaticVNode, vModelCheckbox, shallowRef, pushScopeId, popScopeId, markRaw, computed, isRef } from 'vue';
6
7
  import _ from 'lodash';
7
8
  import { useRoute, useRouter } from 'vue-router';
8
9
  import { defineStore, storeToRefs } from 'pinia';
9
- import { Modal, Offcanvas } from 'bootstrap';
10
10
 
11
11
  function setItem (key, value) {
12
12
  let toStore = value;
@@ -32,221 +32,238 @@ var ShStorage = {
32
32
  removeItem
33
33
  };
34
34
 
35
- function swalSuccess (message) {
36
- Swal.fire('Success!', message, 'success');
35
+ function swalSuccess(message){
36
+ Swal.fire('Success!', message, 'success');
37
37
  }
38
- function swalError (message) {
39
- Swal.fire('Error!', message, 'error');
38
+
39
+ function swalError(message){
40
+ Swal.fire('Error!', message, 'error');
40
41
  }
41
42
 
42
- function swalHttpError (reason) {
43
- let error = '';
44
- if (typeof reason !== 'undefined') {
45
- if (typeof reason.response !== 'undefined') {
46
- let reasonString = '';
47
- if (typeof reason.response.data === 'string') {
48
- reasonString = reason.response.data;
49
- } else {
50
- reasonString = JSON.stringify(reason.response.data);
51
- }
52
- error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
53
- } else {
54
- if (typeof reason !== 'string') {
55
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
56
- } else {
57
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
58
- }
59
- }
60
- } else {
61
- if (typeof reason !== 'string') {
62
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
43
+ function swalHttpError(reason){
44
+ let error = '';
45
+ if (typeof reason !== 'undefined') {
46
+ if (typeof reason.response !== 'undefined') {
47
+ let reasonString = '';
48
+ if (typeof reason.response.data === 'string') {
49
+ reasonString = reason.response.data;
50
+ } else {
51
+ reasonString = JSON.stringify(reason.response.data);
52
+ }
53
+ error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
54
+ } else {
55
+ if (typeof reason !== 'string') {
56
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
57
+ } else {
58
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
59
+ }
60
+ }
63
61
  } else {
64
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
62
+ if (typeof reason !== 'string') {
63
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
64
+ } else {
65
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
66
+ }
65
67
  }
66
- }
67
- Swal.fire('Error!', error, 'error');
68
+ Swal.fire('Error!', error, 'error');
68
69
  }
69
70
 
70
- function runSilentRequest (url) {
71
- return shApis.doPost(url)
71
+ function runSilentRequest(url){
72
+ return shApis.doPost(url)
72
73
  }
73
74
 
74
- function setTabCounts (url) {
75
- shApis.doGet(url).then(res => {
76
- Object.keys(res.data).forEach(key => {
77
- const elem = document.getElementById(key);
78
- if (elem === null) {
79
- return
80
- }
81
- if (typeof elem !== 'undefined') {
82
- let txt = elem.innerHTML;
83
- txt = txt.split('<i class="d-none"></i>')[0];
84
- if (parseInt(res.data[key]) > 0) {
85
- elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
86
- }
87
- }
88
- // document.getElementById(key).innerHTML res.data[key]
75
+ function setTabCounts(url){
76
+ shApis.doGet(url).then(res => {
77
+ Object.keys(res.data).forEach(key => {
78
+ const elem = document.getElementById(key);
79
+ if (elem === null) {
80
+ return
81
+ }
82
+ if (typeof elem !== 'undefined') {
83
+ let txt = elem.innerHTML;
84
+ txt = txt.split('<i class="d-none"></i>')[0];
85
+ if (parseInt(res.data[key]) > 0) {
86
+ elem.innerHTML = txt + '<i class="d-none"></i><sup class="rounded-circle p-1 bg-info text-white">' + res.data[key] + '</sup>';
87
+ }
88
+ }
89
+ // document.getElementById(key).innerHTML res.data[key]
90
+ });
89
91
  });
90
- });
91
92
  }
92
- function formatHttpCatchError (reason) {
93
- console.log(reason);
94
- let error = '';
95
- if (typeof reason !== 'undefined') {
96
- if (typeof reason.response !== 'undefined') {
97
- alert('here');
98
- let reasonString = '';
99
- if (typeof reason.response.data === 'string') {
100
- reasonString = reason.response.data;
101
- } else {
102
- reasonString = JSON.stringify(reason.response.data);
103
- }
104
- error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
105
- } else {
106
- if (typeof reason !== 'string') {
107
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
108
- } else {
109
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
110
- }
111
- }
112
- } else {
113
- if (typeof reason !== 'string') {
114
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
93
+
94
+ function formatHttpCatchError(reason){
95
+ console.log(reason);
96
+ let error = '';
97
+ if (typeof reason !== 'undefined') {
98
+ if (typeof reason.response !== 'undefined') {
99
+ alert('here');
100
+ let reasonString = '';
101
+ if (typeof reason.response.data === 'string') {
102
+ reasonString = reason.response.data;
103
+ } else {
104
+ reasonString = JSON.stringify(reason.response.data);
105
+ }
106
+ error = reason.response.status + ': ' + reason.response.statusText + '<br/>' + reasonString;
107
+ } else {
108
+ if (typeof reason !== 'string') {
109
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
110
+ } else {
111
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
112
+ }
113
+ }
115
114
  } else {
116
- error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
115
+ if (typeof reason !== 'string') {
116
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
117
+ } else {
118
+ error = 'A Unexpected script error occurred<br/>' + JSON.stringify(reason);
119
+ }
117
120
  }
118
- }
119
- return error
121
+ return error
120
122
  }
121
- function getMenuCount (url) {
122
- shApis.doGet(url).then(res => {
123
- console.log(res);
124
- });
123
+
124
+ function getMenuCount(url){
125
+ shApis.doGet(url).then(res => {
126
+ console.log(res);
127
+ });
125
128
  }
126
129
 
127
- const signOutUser = ()=>{
128
- const loginUrl = getShConfig('loginUrl','auth/login');
129
- const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
130
- console.log(loginUrl,logoutApiEndPoint);
131
- shApis.doPost(logoutApiEndPoint).then(res=>{
132
- ShStorage.removeItem('access_token');
133
- ShStorage.removeItem('user');
134
- ShStorage.removeItem('last_activity');
135
- window.location.href = loginUrl;
136
- }).catch(ex=>{
137
- ShStorage.removeItem('access_token');
138
- ShStorage.removeItem('user');
139
- ShStorage.removeItem('last_activity');
140
- window.location.href = loginUrl;
141
- });
130
+ const signOutUser = () => {
131
+ const loginUrl = getShConfig('loginUrl', 'auth/login');
132
+ const logoutApiEndPoint = getShConfig('logoutApiEndpoint', 'auth/logout');
133
+ console.log(loginUrl, logoutApiEndPoint);
134
+ shApis.doPost(logoutApiEndPoint).then(res => {
135
+ ShStorage.removeItem('access_token');
136
+ ShStorage.removeItem('user');
137
+ ShStorage.removeItem('last_activity');
138
+ window.location.href = loginUrl;
139
+ }).catch(ex => {
140
+ ShStorage.removeItem('access_token');
141
+ ShStorage.removeItem('user');
142
+ ShStorage.removeItem('last_activity');
143
+ window.location.href = loginUrl;
144
+ });
142
145
  };
143
146
 
144
147
 
148
+ function getShConfig(key = null, def = ''){
145
149
 
146
- function getShConfig(key = null,def = '') {
147
-
148
- const config = ShStorage.getItem('ShConfig') ?? {};
149
- if(key) {
150
- return config[key] ?? def
151
- }
152
- return config
153
- }
154
- function showToast (message, toastType, config) {
155
- const mixinConfig = {
156
- toast: true,
157
- position: 'top-end',
158
- showConfirmButton: false,
159
- customClass: {
160
- popup: 'colored-toast'
161
- },
162
- iconColor: 'white',
163
- timer: 2000,
164
- timerProgressBar: true,
165
- didOpen: (toast) => {
166
- toast.addEventListener('mouseenter', Swal.stopTimer);
167
- toast.addEventListener('mouseleave', Swal.resumeTimer);
150
+ const config = ShStorage.getItem('ShConfig') ?? {};
151
+ if (key) {
152
+ return config[key] ?? def
168
153
  }
169
- };
170
- if (!toastType) {
171
- toastType = 'success';
172
- }
173
- if(config){
174
- Object.keys(config).map(key=>mixinConfig[key] = config[key]);
175
- }
176
- console.log(mixinConfig);
177
- const Toast = Swal.mixin(mixinConfig);
178
- // Toast.mixin({
179
- // position: 'top'
180
- // })
181
- Toast.fire({
182
- icon: toastType,
183
- title: message,
184
- postion: 'bottom'
185
- });
154
+ return config
186
155
  }
187
156
 
188
- async function runPlainRequest (url, message, title, data) {
189
- if (typeof title === 'undefined') {
190
- title = null;
191
- }
192
- return Swal.fire({
193
- title: title !== null ? title : 'Are you sure?',
194
- html: message,
195
- showCancelButton: true,
196
- confirmButtonColor: '#32c787',
197
- cancelButtonText: 'No, cancel',
198
- confirmButtonText: 'Yes, Proceed!',
199
- reverseButtons: true,
200
- showLoaderOnConfirm: true,
201
- preConfirm: () => {
202
- return shApis.doPost(url, data).then(function (response) {
203
- return {
204
- response: response.data,
205
- success: true
157
+ function showToast(message, toastType, config){
158
+ const mixinConfig = {
159
+ toast: true,
160
+ position: 'top-end',
161
+ showConfirmButton: false,
162
+ customClass: {
163
+ popup: 'colored-toast'
164
+ },
165
+ iconColor: 'white',
166
+ timer: 2000,
167
+ timerProgressBar: true,
168
+ didOpen: (toast) => {
169
+ toast.addEventListener('mouseenter', Swal.stopTimer);
170
+ toast.addEventListener('mouseleave', Swal.resumeTimer);
206
171
  }
207
- })
208
- .catch(error => {
209
- return {
210
- success: false,
211
- error: error
212
- }
213
- })
214
- },
215
- allowOutsideClick: () => !Swal.isLoading()
216
- })
172
+ };
173
+ if (!toastType) {
174
+ toastType = 'success';
175
+ }
176
+ if (config) {
177
+ Object.keys(config).map(key => mixinConfig[key] = config[key]);
178
+ }
179
+ console.log(mixinConfig);
180
+ const Toast = Swal.mixin(mixinConfig);
181
+ // Toast.mixin({
182
+ // position: 'top'
183
+ // })
184
+ Toast.fire({
185
+ icon: toastType,
186
+ title: message,
187
+ postion: 'bottom'
188
+ });
217
189
  }
218
190
 
219
- function formatDate(date, format) {
220
- if (!format) {
221
- format = 'lll';
222
- }
223
- return moment(date).format(format)
191
+ async function runPlainRequest(url, message, title, data){
192
+ if (typeof title === 'undefined') {
193
+ title = null;
194
+ }
195
+ return Swal.fire({
196
+ title: title !== null ? title : 'Are you sure?',
197
+ html: message,
198
+ showCancelButton: true,
199
+ confirmButtonColor: '#32c787',
200
+ cancelButtonText: 'No, cancel',
201
+ confirmButtonText: 'Yes, Proceed!',
202
+ reverseButtons: true,
203
+ showLoaderOnConfirm: true,
204
+ preConfirm: () => {
205
+ return shApis.doPost(url, data).then(function (response){
206
+ return {
207
+ response: response.data,
208
+ success: true
209
+ }
210
+ })
211
+ .catch(error => {
212
+ return {
213
+ success: false,
214
+ error: error
215
+ }
216
+ })
217
+ },
218
+ allowOutsideClick: () => !Swal.isLoading()
219
+ })
224
220
  }
225
- function formatNumber(amount,decimalPoints = 0){
226
- return numberFormat(amount,decimalPoints)
221
+
222
+ function formatDate(date, format){
223
+ if (!format) {
224
+ format = 'lll';
225
+ }
226
+ return moment(date).format(format)
227
227
  }
228
- function numberFormat(amount,decimalPoints = 0) {
229
- let formatted = parseFloat(amount).toFixed(decimalPoints);
230
- formatted = new Intl.NumberFormat().format(formatted);
231
- const formattedArr = formatted.split('.');
232
- return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] +'.' + (formattedArr[1] || '0').padEnd(decimalPoints,0)
228
+
229
+ function formatNumber(amount, decimalPoints = 0){
230
+ return numberFormat(amount, decimalPoints)
233
231
  }
234
232
 
233
+ function numberFormat(amount, decimalPoints = 0){
234
+ let formatted = parseFloat(amount).toFixed(decimalPoints);
235
+ formatted = new Intl.NumberFormat().format(formatted);
236
+ const formattedArr = formatted.split('.');
237
+ return decimalPoints === 0 ? formattedArr[0] : formattedArr[0] + '.' + (formattedArr[1] || '0').padEnd(decimalPoints, 0)
238
+ }
239
+
240
+ const showModal = modalId => {
241
+ const modal = new Modal(document.getElementById(modalId));
242
+ modal.show();
243
+ };
244
+
245
+ const hideModal = modalId => {
246
+ const modal = new Modal(document.getElementById(modalId));
247
+ modal.hide();
248
+ };
249
+
235
250
  var shRepo = {
236
- swalSuccess,
237
- swalError,
238
- runPlainRequest,
239
- getMenuCount,
240
- setTabCounts,
241
- getShConfig,
242
- showToast,
243
- runSilentRequest,
244
- swalHttpError,
245
- formatHttpCatchError,
246
- formatDate,
247
- numberFormat,
248
- formatNumber,
249
- signOutUser
251
+ swalSuccess,
252
+ swalError,
253
+ runPlainRequest,
254
+ getMenuCount,
255
+ setTabCounts,
256
+ getShConfig,
257
+ showToast,
258
+ runSilentRequest,
259
+ swalHttpError,
260
+ formatHttpCatchError,
261
+ formatDate,
262
+ numberFormat,
263
+ formatNumber,
264
+ signOutUser,
265
+ showModal,
266
+ hideModal
250
267
  };
251
268
 
252
269
  startSession();
@@ -3102,7 +3119,7 @@ const getFieldComponent = (fieldObj)=>{
3102
3119
  if(fieldObj.component){
3103
3120
  return fieldObj.component
3104
3121
  }
3105
- const field = fieldObj.field;
3122
+ const field = fieldObj.field ?? fieldObj.name;
3106
3123
  const defaultTextareas = ['message', 'meta_description', 'comment', 'call_response', 'comments', 'description'];
3107
3124
  const defaultNumbers = ['age'];
3108
3125
  const passwords = ['password','password_confirmation','pin'];
@@ -3254,6 +3271,7 @@ onMounted((ev)=>{
3254
3271
  props.fields && props.fields.map(field=>{
3255
3272
  if(typeof field === 'object') {
3256
3273
  const fieldObj = {...field};
3274
+ fieldObj.field = fieldObj.field ?? fieldObj.name;
3257
3275
  // fieldObj.label && getLabel(fieldObj.field)
3258
3276
  fieldObj.helper = fieldObj.helperText ?? fieldObj.helper;
3259
3277
  // !fieldObj.helper && fieldObj.helperText ? fieldObj.helper = fieldObj.helperText : fieldObj.helper = getHelperText(fieldObj.field)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",