@fleetbase/ember-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +32 -0
  3. package/addon/adapters/application.js +155 -0
  4. package/addon/adapters/user.js +19 -0
  5. package/addon/authenticators/fleetbase.js +72 -0
  6. package/addon/decorators/fetch-from.js +55 -0
  7. package/addon/decorators/from-store.js +56 -0
  8. package/addon/decorators/is-equal.js +15 -0
  9. package/addon/exports/host-services.js +18 -0
  10. package/addon/exports/services.js +18 -0
  11. package/addon/initializers/local-storage-adapter.js +21 -0
  12. package/addon/serializers/application.js +87 -0
  13. package/addon/services/app-cache.js +59 -0
  14. package/addon/services/crud.js +226 -0
  15. package/addon/services/current-user.js +259 -0
  16. package/addon/services/fetch.js +648 -0
  17. package/addon/services/filters.js +183 -0
  18. package/addon/services/loader.js +136 -0
  19. package/addon/services/notifications.js +32 -0
  20. package/addon/services/session.js +221 -0
  21. package/addon/services/theme.js +200 -0
  22. package/addon/services/url-search-params.js +92 -0
  23. package/addon/transforms/array.js +29 -0
  24. package/addon/transforms/object.js +11 -0
  25. package/addon/transforms/raw.js +11 -0
  26. package/addon/utils/api-url.js +11 -0
  27. package/addon/utils/apply-column-filters.js +3 -0
  28. package/addon/utils/auto-serialize.js +100 -0
  29. package/addon/utils/calculate-percentage.js +3 -0
  30. package/addon/utils/close-sidebar.js +7 -0
  31. package/addon/utils/console-url.js +56 -0
  32. package/addon/utils/copy-to-clipboard.js +35 -0
  33. package/addon/utils/corslite.js +95 -0
  34. package/addon/utils/download.js +157 -0
  35. package/addon/utils/env.js +3 -0
  36. package/addon/utils/extract-coordinates.js +35 -0
  37. package/addon/utils/extract-latitude.js +28 -0
  38. package/addon/utils/extract-longitude.js +28 -0
  39. package/addon/utils/find-closest-waypoint.js +20 -0
  40. package/addon/utils/first.js +10 -0
  41. package/addon/utils/frontend-url.js +30 -0
  42. package/addon/utils/generate-slug.js +11 -0
  43. package/addon/utils/generate-uuid.js +3 -0
  44. package/addon/utils/get-length-units.js +44 -0
  45. package/addon/utils/get-meta-field-types.js +3 -0
  46. package/addon/utils/get-mime-type.js +25 -0
  47. package/addon/utils/get-model-name.js +45 -0
  48. package/addon/utils/get-permission-action.js +47 -0
  49. package/addon/utils/get-permission-resource.js +16 -0
  50. package/addon/utils/get-pod-methods.js +7 -0
  51. package/addon/utils/get-routing-host.js +44 -0
  52. package/addon/utils/get-service-name.js +21 -0
  53. package/addon/utils/get-user-options.js +21 -0
  54. package/addon/utils/get-weight-units.js +32 -0
  55. package/addon/utils/get-with-default.js +6 -0
  56. package/addon/utils/group-api-events.js +20 -0
  57. package/addon/utils/group-by.js +26 -0
  58. package/addon/utils/has-extension.js +11 -0
  59. package/addon/utils/has-json-structure.js +10 -0
  60. package/addon/utils/hason-structure.js +3 -0
  61. package/addon/utils/haversine.js +59 -0
  62. package/addon/utils/humanize.js +16 -0
  63. package/addon/utils/is-electron.js +18 -0
  64. package/addon/utils/is-email.js +5 -0
  65. package/addon/utils/is-function.js +3 -0
  66. package/addon/utils/is-image-file.js +3 -0
  67. package/addon/utils/is-iterable.js +7 -0
  68. package/addon/utils/is-json.js +9 -0
  69. package/addon/utils/is-latitude.js +3 -0
  70. package/addon/utils/is-letter.js +3 -0
  71. package/addon/utils/is-longitude.js +3 -0
  72. package/addon/utils/is-model.js +6 -0
  73. package/addon/utils/is-not-empty.js +5 -0
  74. package/addon/utils/is-not-model.js +5 -0
  75. package/addon/utils/is-numeric.js +3 -0
  76. package/addon/utils/is-object.js +3 -0
  77. package/addon/utils/is-proxy.js +5 -0
  78. package/addon/utils/is-relation-missing.js +21 -0
  79. package/addon/utils/is-valid-coordinates.js +38 -0
  80. package/addon/utils/is-video-file.js +3 -0
  81. package/addon/utils/is-waypoint-record.js +5 -0
  82. package/addon/utils/ison.js +3 -0
  83. package/addon/utils/isset.js +10 -0
  84. package/addon/utils/last.js +23 -0
  85. package/addon/utils/lazy-load-script.js +25 -0
  86. package/addon/utils/leaflet-icon.js +13 -0
  87. package/addon/utils/leaflet-points-from-coordinates.js +3 -0
  88. package/addon/utils/load-engines.js +37 -0
  89. package/addon/utils/load-extensions.js +8 -0
  90. package/addon/utils/macros/group-by.js +28 -0
  91. package/addon/utils/make-dataset.js +57 -0
  92. package/addon/utils/map-engines.js +30 -0
  93. package/addon/utils/mock-response.js +15 -0
  94. package/addon/utils/numbers-only.js +11 -0
  95. package/addon/utils/past-tense.js +40 -0
  96. package/addon/utils/path-to-route.js +10 -0
  97. package/addon/utils/polyline.js +161 -0
  98. package/addon/utils/range.js +19 -0
  99. package/addon/utils/refresh-route.js +3 -0
  100. package/addon/utils/replace-table-row.js +17 -0
  101. package/addon/utils/reverse-point.js +3 -0
  102. package/addon/utils/serialize/normalize-polymorphic-type-within-hash.js +27 -0
  103. package/addon/utils/serialize/normalize-polymorphic-type.js +13 -0
  104. package/addon/utils/serialize/normalize-relations-with-hash.js +32 -0
  105. package/addon/utils/set-column-filter-options.js +3 -0
  106. package/addon/utils/strip-html.js +3 -0
  107. package/addon/utils/to-leaflet-bounds.js +6 -0
  108. package/addon/utils/to-model.js +18 -0
  109. package/addon/utils/waypoint-label.js +3 -0
  110. package/addon/utils/with-default-value.js +5 -0
  111. package/addon/utils/words.js +5 -0
  112. package/app/adapters/user.js +1 -0
  113. package/app/authenticators/fleetbase.js +1 -0
  114. package/app/decorators/fetch-from.js +1 -0
  115. package/app/decorators/from-store.js +1 -0
  116. package/app/decorators/is-equal.js +1 -0
  117. package/app/exports/host-services.js +1 -0
  118. package/app/exports/services.js +1 -0
  119. package/app/initializers/local-storage-adapter.js +1 -0
  120. package/app/serializers/application.js +1 -0
  121. package/app/services/app-cache.js +1 -0
  122. package/app/services/crud.js +1 -0
  123. package/app/services/current-user.js +1 -0
  124. package/app/services/fetch.js +1 -0
  125. package/app/services/filters.js +1 -0
  126. package/app/services/loader.js +1 -0
  127. package/app/services/notifications.js +1 -0
  128. package/app/services/session.js +1 -0
  129. package/app/services/theme.js +1 -0
  130. package/app/services/url-search-params.js +1 -0
  131. package/app/storages/local-cache.js +12 -0
  132. package/app/storages/user-options.js +12 -0
  133. package/app/transforms/array.js +1 -0
  134. package/app/transforms/object.js +1 -0
  135. package/app/transforms/raw.js +1 -0
  136. package/app/utils/api-url.js +1 -0
  137. package/app/utils/apply-column-filters.js +1 -0
  138. package/app/utils/auto-serialize.js +1 -0
  139. package/app/utils/calculate-percentage.js +1 -0
  140. package/app/utils/close-sidebar.js +1 -0
  141. package/app/utils/console-url.js +1 -0
  142. package/app/utils/copy-to-clipboard.js +1 -0
  143. package/app/utils/corslite.js +1 -0
  144. package/app/utils/download.js +1 -0
  145. package/app/utils/env.js +1 -0
  146. package/app/utils/extract-coordinates.js +1 -0
  147. package/app/utils/extract-latitude.js +1 -0
  148. package/app/utils/extract-longitude.js +1 -0
  149. package/app/utils/find-closest-waypoint.js +1 -0
  150. package/app/utils/first.js +1 -0
  151. package/app/utils/frontend-url.js +1 -0
  152. package/app/utils/generate-slug.js +1 -0
  153. package/app/utils/generate-uuid.js +1 -0
  154. package/app/utils/get-length-units.js +1 -0
  155. package/app/utils/get-meta-field-types.js +1 -0
  156. package/app/utils/get-mime-type.js +1 -0
  157. package/app/utils/get-model-name.js +1 -0
  158. package/app/utils/get-permission-action.js +1 -0
  159. package/app/utils/get-permission-resource.js +1 -0
  160. package/app/utils/get-pod-methods.js +1 -0
  161. package/app/utils/get-routing-host.js +1 -0
  162. package/app/utils/get-service-name.js +1 -0
  163. package/app/utils/get-user-options.js +1 -0
  164. package/app/utils/get-weight-units.js +1 -0
  165. package/app/utils/get-with-default.js +1 -0
  166. package/app/utils/group-api-events.js +1 -0
  167. package/app/utils/group-by.js +1 -0
  168. package/app/utils/has-extension.js +1 -0
  169. package/app/utils/has-json-structure.js +1 -0
  170. package/app/utils/hason-structure.js +1 -0
  171. package/app/utils/haversine.js +1 -0
  172. package/app/utils/humanize.js +1 -0
  173. package/app/utils/is-electron.js +1 -0
  174. package/app/utils/is-email.js +1 -0
  175. package/app/utils/is-function.js +1 -0
  176. package/app/utils/is-image-file.js +1 -0
  177. package/app/utils/is-iterable.js +1 -0
  178. package/app/utils/is-latitude.js +1 -0
  179. package/app/utils/is-letter.js +1 -0
  180. package/app/utils/is-longitude.js +1 -0
  181. package/app/utils/is-model.js +1 -0
  182. package/app/utils/is-not-empty.js +1 -0
  183. package/app/utils/is-not-model.js +1 -0
  184. package/app/utils/is-numeric.js +1 -0
  185. package/app/utils/is-object.js +1 -0
  186. package/app/utils/is-proxy.js +1 -0
  187. package/app/utils/is-relation-missing.js +1 -0
  188. package/app/utils/is-valid-coordinates.js +1 -0
  189. package/app/utils/is-video-file.js +1 -0
  190. package/app/utils/is-waypoint-record.js +1 -0
  191. package/app/utils/ison.js +1 -0
  192. package/app/utils/isset.js +1 -0
  193. package/app/utils/last.js +1 -0
  194. package/app/utils/lazy-load-script.js +1 -0
  195. package/app/utils/leaflet-icon.js +1 -0
  196. package/app/utils/leaflet-points-from-coordinates.js +1 -0
  197. package/app/utils/load-engines.js +1 -0
  198. package/app/utils/load-extensions.js +1 -0
  199. package/app/utils/macros/group-by.js +1 -0
  200. package/app/utils/make-dataset.js +1 -0
  201. package/app/utils/map-engines.js +1 -0
  202. package/app/utils/mock-response.js +1 -0
  203. package/app/utils/numbers-only.js +1 -0
  204. package/app/utils/past-tense.js +1 -0
  205. package/app/utils/path-to-route.js +1 -0
  206. package/app/utils/polyline.js +1 -0
  207. package/app/utils/range.js +1 -0
  208. package/app/utils/refresh-route.js +1 -0
  209. package/app/utils/replace-table-row.js +1 -0
  210. package/app/utils/reverse-point.js +1 -0
  211. package/app/utils/serialize/normalize-polymorphic-type-within-hash.js +1 -0
  212. package/app/utils/serialize/normalize-polymorphic-type.js +1 -0
  213. package/app/utils/serialize/normalize-relations-with-hash.js +1 -0
  214. package/app/utils/set-column-filter-options.js +1 -0
  215. package/app/utils/strip-html.js +1 -0
  216. package/app/utils/to-leaflet-bounds.js +1 -0
  217. package/app/utils/to-model.js +1 -0
  218. package/app/utils/waypoint-label.js +1 -0
  219. package/app/utils/with-default-value.js +1 -0
  220. package/app/utils/words.js +1 -0
  221. package/config/environment.js +5 -0
  222. package/index.js +26 -0
  223. package/package.json +117 -0
  224. package/pnpm-lock.yaml +12750 -0
@@ -0,0 +1,157 @@
1
+ export default function download(data, strFileName, strMimeType) {
2
+ var self = window, // this script is only for browsers anyway...
3
+ defaultMime = 'application/octet-stream', // this default mime also triggers iframe downloads
4
+ mimeType = strMimeType || defaultMime,
5
+ payload = data,
6
+ url = !strFileName && !strMimeType && payload,
7
+ anchor = document.createElement('a'),
8
+ toString = function (a) {
9
+ return String(a);
10
+ },
11
+ myBlob = self.Blob || self.MozBlob || self.WebKitBlob || toString,
12
+ fileName = strFileName || 'download',
13
+ blob,
14
+ reader;
15
+ myBlob = myBlob.call ? myBlob.bind(self) : Blob;
16
+
17
+ if (String(this) === 'true') {
18
+ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
19
+ payload = [payload, mimeType];
20
+ mimeType = payload[0];
21
+ payload = payload[1];
22
+ }
23
+
24
+ if (url && url.length < 2048) {
25
+ // if no filename and no mime, assume a url was passed as the only argument
26
+ fileName = url.split('/').pop().split('?')[0];
27
+ anchor.href = url; // assign href prop to temp anchor
28
+ if (anchor.href.indexOf(url) !== -1) {
29
+ // if the browser determines that it's a potentially valid url path:
30
+ var ajax = new XMLHttpRequest();
31
+ ajax.open('GET', url, true);
32
+ ajax.responseType = 'blob';
33
+ ajax.onload = function (e) {
34
+ download(e.target.response, fileName, defaultMime);
35
+ };
36
+ setTimeout(function () {
37
+ ajax.send();
38
+ }, 0); // allows setting custom ajax headers using the return:
39
+ return ajax;
40
+ } // end if valid url?
41
+ } // end if url?
42
+
43
+ //go ahead and download dataURLs right away
44
+ if (/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)) {
45
+ if (payload.length > 1024 * 1024 * 1.999 && myBlob !== toString) {
46
+ payload = dataUrlToBlob(payload);
47
+ mimeType = payload.type || defaultMime;
48
+ } else {
49
+ return navigator.msSaveBlob // IE10 can't do a[download], only Blobs:
50
+ ? navigator.msSaveBlob(dataUrlToBlob(payload), fileName)
51
+ : saver(payload); // everyone else can save dataURLs un-processed
52
+ }
53
+ } else {
54
+ //not data url, is it a string with special needs?
55
+ if (/([\x80-\xff])/.test(payload)) {
56
+ var i = 0,
57
+ tempUiArr = new Uint8Array(payload.length),
58
+ mx = tempUiArr.length;
59
+ for (i; i < mx; ++i) tempUiArr[i] = payload.charCodeAt(i);
60
+ payload = new myBlob([tempUiArr], { type: mimeType });
61
+ }
62
+ }
63
+ blob = payload instanceof myBlob ? payload : new myBlob([payload], { type: mimeType });
64
+
65
+ function dataUrlToBlob(strUrl) {
66
+ var parts = strUrl.split(/[:;,]/),
67
+ type = parts[1],
68
+ indexDecoder = strUrl.indexOf('charset') > 0 ? 3 : 2,
69
+ decoder = parts[indexDecoder] == 'base64' ? atob : decodeURIComponent,
70
+ binData = decoder(parts.pop()),
71
+ mx = binData.length,
72
+ i = 0,
73
+ uiArr = new Uint8Array(mx);
74
+
75
+ for (i; i < mx; ++i) uiArr[i] = binData.charCodeAt(i);
76
+
77
+ return new myBlob([uiArr], { type: type });
78
+ }
79
+
80
+ function saver(url, winMode) {
81
+ if ('download' in anchor) {
82
+ //html5 A[download]
83
+ anchor.href = url;
84
+ anchor.setAttribute('download', fileName);
85
+ anchor.className = 'download-js-link';
86
+ anchor.innerHTML = 'downloading...';
87
+ anchor.style.display = 'none';
88
+ anchor.addEventListener('click', function (e) {
89
+ e.stopPropagation();
90
+ this.removeEventListener('click', arguments.callee);
91
+ });
92
+ document.body.appendChild(anchor);
93
+ setTimeout(function () {
94
+ anchor.click();
95
+ document.body.removeChild(anchor);
96
+ if (winMode === true) {
97
+ setTimeout(function () {
98
+ self.URL.revokeObjectURL(anchor.href);
99
+ }, 250);
100
+ }
101
+ }, 66);
102
+ return true;
103
+ }
104
+
105
+ // handle non-a[download] safari as best we can:
106
+ if (/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
107
+ if (/^data:/.test(url)) url = 'data:' + url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
108
+ if (!window.open(url)) {
109
+ // popup blocked, offer direct download:
110
+ if (confirm('Displaying New Document\n\nUse Save As... to download, then click back to return to this page.')) {
111
+ location.href = url;
112
+ }
113
+ }
114
+ return true;
115
+ }
116
+
117
+ //do iframe dataURL download (old ch+FF):
118
+ var f = document.createElement('iframe');
119
+ document.body.appendChild(f);
120
+
121
+ if (!winMode && /^data:/.test(url)) {
122
+ // force a mime that will download:
123
+ url = 'data:' + url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
124
+ }
125
+ f.src = url;
126
+ setTimeout(function () {
127
+ document.body.removeChild(f);
128
+ }, 333);
129
+ } //end saver
130
+
131
+ if (navigator.msSaveBlob) {
132
+ // IE10+ : (has Blob, but not a[download] or URL)
133
+ return navigator.msSaveBlob(blob, fileName);
134
+ }
135
+
136
+ if (self.URL) {
137
+ // simple fast and modern way using Blob and URL:
138
+ saver(self.URL.createObjectURL(blob), true);
139
+ } else {
140
+ // handle non-Blob()+non-URL browsers:
141
+ if (typeof blob === 'string' || blob.constructor === toString) {
142
+ try {
143
+ return saver('data:' + mimeType + ';base64,' + self.btoa(blob));
144
+ } catch (y) {
145
+ return saver('data:' + mimeType + ',' + encodeURIComponent(blob));
146
+ }
147
+ }
148
+
149
+ // Blob but not URL support:
150
+ reader = new FileReader();
151
+ reader.onload = function (e) {
152
+ saver(this.result);
153
+ };
154
+ reader.readAsDataURL(blob);
155
+ }
156
+ return true;
157
+ }
@@ -0,0 +1,3 @@
1
+ export default function env(variable, defaultValue = null) {
2
+ return process.env[variable] !== undefined ? process.env[variable] : defaultValue;
3
+ }
@@ -0,0 +1,35 @@
1
+ import isLatitude from './is-latitude';
2
+ import isLongitude from './is-longitude';
3
+
4
+ export default function extractCoordinates(coordinates = [], format = 'latlng') {
5
+ let latitude = null,
6
+ longitude = null;
7
+
8
+ for (let i = 0; i < coordinates.length; i++) {
9
+ let coord = coordinates[i];
10
+
11
+ if (isLatitude(coord) && latitude === null) {
12
+ latitude = coord;
13
+ continue;
14
+ }
15
+
16
+ if (isLongitude(coord) && longitude === null) {
17
+ longitude = coord;
18
+ continue;
19
+ }
20
+ }
21
+
22
+ if (latitude === null) {
23
+ latitude = 0;
24
+ }
25
+
26
+ if (longitude === null) {
27
+ latitude = 0;
28
+ }
29
+
30
+ if (format === 'lnglat') {
31
+ return [longitude, latitude];
32
+ }
33
+
34
+ return [latitude, longitude];
35
+ }
@@ -0,0 +1,28 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import extractCoordinates from './extract-coordinates';
3
+ import Terraformer from 'terraformer';
4
+ import { isArray } from '@ember/array';
5
+
6
+ export default function extractLatitude(position) {
7
+ let latitude, longitude;
8
+
9
+ if (!position) {
10
+ return 0;
11
+ }
12
+
13
+ if (position instanceof Terraformer.Point || isArray(position.coordinates)) {
14
+ [latitude, longitude] = extractCoordinates(position.coordinates);
15
+
16
+ return latitude;
17
+ }
18
+
19
+ if (typeof position === 'object') {
20
+ let latitude = position['lat'] || position['latitude'] || position['x'];
21
+
22
+ return latitude;
23
+ }
24
+
25
+ [latitude, longitude] = extractCoordinates(position);
26
+
27
+ return latitude;
28
+ }
@@ -0,0 +1,28 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import extractCoordinates from './extract-coordinates';
3
+ import Terraformer from 'terraformer';
4
+ import { isArray } from '@ember/array';
5
+
6
+ export default function extractLongitude(position) {
7
+ let latitude, longitude;
8
+
9
+ if (!position) {
10
+ return 0;
11
+ }
12
+
13
+ if (position instanceof Terraformer.Point || isArray(position.coordinates)) {
14
+ [latitude, longitude] = extractCoordinates(position.coordinates);
15
+
16
+ return longitude;
17
+ }
18
+
19
+ if (typeof position === 'object') {
20
+ let longitude = position['lng'] || position['longitude'] || position['lon'] || position['y'];
21
+
22
+ return longitude;
23
+ }
24
+
25
+ [latitude, longitude] = extractCoordinates(position);
26
+
27
+ return longitude;
28
+ }
@@ -0,0 +1,20 @@
1
+ import haversine from './haversine';
2
+ import { get } from '@ember/object';
3
+
4
+ export default function findClosestWaypoint(latitude, longitude, waypoints = []) {
5
+ let distances = [];
6
+
7
+ for (let i = 0; i < waypoints.length; i++) {
8
+ let waypoint = waypoints.objectAt(i);
9
+ let distance = haversine({ latitude, longitude }, waypoint.place.get('latitudelongitude'));
10
+
11
+ distances.pushObject({
12
+ distance,
13
+ waypoint,
14
+ });
15
+ }
16
+
17
+ distances = distances.sortBy('distance');
18
+
19
+ return get(distances, 'firstObject.waypoint');
20
+ }
@@ -0,0 +1,10 @@
1
+ import { isArray } from '@ember/array';
2
+
3
+ export default function first(arr, n = 1) {
4
+ if (!isArray(arr) || arr.length === 0 || n <= 0) {
5
+ return null;
6
+ }
7
+
8
+ n = Math.min(n, arr.length);
9
+ return n > 1 ? arr.slice(0, n) : arr[0];
10
+ }
@@ -0,0 +1,30 @@
1
+ import config from '@fleetbase/console/config/environment';
2
+ import { isBlank } from '@ember/utils';
3
+
4
+ const queryString = (params) =>
5
+ Object.keys(params)
6
+ .map((key) => `${key}=${params[key]}`)
7
+ .join('&');
8
+
9
+ export default function frontendUrl(path = '', queryParams = {}) {
10
+ let url = 'https://';
11
+ let urlParams = !isBlank(queryParams) ? queryString(queryParams) : '';
12
+
13
+ if (['qa', 'staging'].includes(config.environment)) {
14
+ url += `${config.environment}.`;
15
+ }
16
+
17
+ if (['local', 'development'].includes(config.environment)) {
18
+ url += 'fleetbase.dev';
19
+ } else {
20
+ url += 'fleetbase.io';
21
+ }
22
+
23
+ url += `/${path}`;
24
+
25
+ if (urlParams) {
26
+ url += `?${urlParams}`;
27
+ }
28
+
29
+ return url;
30
+ }
@@ -0,0 +1,11 @@
1
+ export default function generateSlug(length = 12) {
2
+ const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
3
+ let slug = '';
4
+
5
+ for (let i = 0; i < length; i++) {
6
+ const index = Math.floor(Math.random() * chars.length);
7
+ slug += chars[index];
8
+ }
9
+
10
+ return slug;
11
+ }
@@ -0,0 +1,3 @@
1
+ export default function generateUuid() {
2
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) => (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16));
3
+ }
@@ -0,0 +1,44 @@
1
+ export default function getLengthUnits() {
2
+ return [
3
+ {
4
+ name: 'Meter',
5
+ value: 'm',
6
+ },
7
+ {
8
+ name: 'Millimeter',
9
+ value: 'mm',
10
+ },
11
+ {
12
+ name: 'Centimeter',
13
+ value: 'cm',
14
+ },
15
+ {
16
+ name: 'Decimeter',
17
+ value: 'dm',
18
+ },
19
+ {
20
+ name: 'Kilometer',
21
+ value: 'km',
22
+ },
23
+ {
24
+ name: 'Inch',
25
+ value: 'in',
26
+ },
27
+ {
28
+ name: 'Foot',
29
+ value: 'ft',
30
+ },
31
+ {
32
+ name: 'Yard',
33
+ value: 'yd',
34
+ },
35
+ {
36
+ name: 'Astonomical Unit',
37
+ value: 'AE',
38
+ },
39
+ {
40
+ name: 'Light Year',
41
+ value: 'lj',
42
+ },
43
+ ];
44
+ }
@@ -0,0 +1,3 @@
1
+ export default function getMetaFieldTypes() {
2
+ return true;
3
+ }
@@ -0,0 +1,25 @@
1
+ export default function getMimeType(fileName) {
2
+ const map = {
3
+ pdf: 'application/pdf',
4
+ zip: 'application/zip',
5
+ doc: 'application/msword',
6
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
7
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
8
+ png: 'image/png',
9
+ jpeg: 'image/jpg',
10
+ jpg: 'image/jpg',
11
+ csv: 'text/csv',
12
+ };
13
+
14
+ const extensions = Object.keys(map);
15
+
16
+ for (let index = 0; index < extensions.length; index++) {
17
+ const ext = extensions.objectAt(index);
18
+
19
+ if (fileName.endsWith(ext)) {
20
+ return ext;
21
+ }
22
+ }
23
+
24
+ return null;
25
+ }
@@ -0,0 +1,45 @@
1
+ import { get } from '@ember/object';
2
+ import { isArray } from '@ember/array';
3
+ import { isBlank } from '@ember/utils';
4
+ import { w, capitalize } from '@ember/string';
5
+ import isModel from './is-model';
6
+ import humanize from './humanize';
7
+
8
+ export default function getModelName(model, fallback = null, options = {}) {
9
+ let modelName;
10
+
11
+ if (isArray(fallback)) {
12
+ for (let i = 0; i < fallback.length; i++) {
13
+ const defaultValue = fallback.objectAt(i);
14
+
15
+ if (!isBlank(defaultValue)) {
16
+ modelName = defaultValue;
17
+ break;
18
+ }
19
+ }
20
+ } else {
21
+ modelName = fallback;
22
+ }
23
+
24
+ if (isModel(model)) {
25
+ modelName = get(model, 'constructor.modelName') ?? get(model, '_internalModel.modelName') ?? fallback;
26
+ }
27
+
28
+ if (options.humanize === true) {
29
+ modelName = humanize(modelName);
30
+ }
31
+
32
+ if (options.lowercase === true) {
33
+ modelName = modelName.toLowerCase();
34
+ }
35
+
36
+ if (options.capitalize === true) {
37
+ modelName = capitalize(modelName);
38
+ }
39
+
40
+ if (options.capitalizeWords === true) {
41
+ modelName = w(modelName).map(capitalize).join(' ');
42
+ }
43
+
44
+ return modelName;
45
+ }
@@ -0,0 +1,47 @@
1
+ import { classify } from '@ember/string';
2
+
3
+ export default function getPermissionAction(permissionName) {
4
+ const permissionNameParts = permissionName.split(':');
5
+ const fullActionName = permissionNameParts.lastObject;
6
+ const actions = [
7
+ 'create',
8
+ 'update',
9
+ 'delete',
10
+ 'deactivate',
11
+ 'get',
12
+ 'list',
13
+ 'cancel',
14
+ 'optimize',
15
+ 'roll',
16
+ 'export',
17
+ 'batch_delete',
18
+ 'batch_cancel',
19
+ 'notify',
20
+ 'assign_vehicle',
21
+ 'assign_order_to',
22
+ 'dispatch_order_to',
23
+ 'dispatch',
24
+ 'assign',
25
+ 'attach',
26
+ 'sub_contract',
27
+ 'create_order_for',
28
+ ];
29
+
30
+ if (permissionName.startsWith('auth')) {
31
+ return fullActionName;
32
+ }
33
+
34
+ if (fullActionName === '*') {
35
+ return 'All';
36
+ }
37
+
38
+ for (let i = 0; i < actions.length; i++) {
39
+ const action = actions.objectAt(i);
40
+
41
+ if (fullActionName.toLowerCase().startsWith(classify(action).toLowerCase())) {
42
+ return classify(action);
43
+ }
44
+ }
45
+
46
+ return 'N/A';
47
+ }
@@ -0,0 +1,16 @@
1
+ import getPermissionAction from './get-permission-action';
2
+ import { classify } from '@ember/string';
3
+ import { singularize } from 'ember-inflector';
4
+
5
+ export default function getPermissionResource(permissionName = '') {
6
+ if (permissionName.startsWith('auth')) {
7
+ return 'N/A';
8
+ }
9
+
10
+ const permissionNameParts = permissionName.split(':');
11
+ const fullActionName = permissionNameParts.lastObject;
12
+ const actionName = getPermissionAction(permissionName);
13
+ const resourceName = fullActionName.replace(actionName, '');
14
+
15
+ return singularize(classify(resourceName));
16
+ }
@@ -0,0 +1,7 @@
1
+ export default function getPodMethods() {
2
+ return [
3
+ { name: 'None', value: null },
4
+ { name: 'QR Code Scan', value: 'scan' },
5
+ { name: 'Signature', value: 'signature' },
6
+ ];
7
+ }
@@ -0,0 +1,44 @@
1
+ import { get } from '@ember/object';
2
+ import { isArray } from '@ember/array';
3
+ import { isBlank } from '@ember/utils';
4
+ // import { getOwner } from '@ember/application';
5
+ import config from '@fleetbase/console/config/environment';
6
+
7
+ const isRoutingInCountry = (country, payload, waypoints = []) => {
8
+ // const owner = getOwner(this);
9
+ // const currentUser = owner.lookup(`service:current-user`);
10
+ // const whois = currentUser.getOption('whois');
11
+
12
+ if (isBlank(payload)) {
13
+ payload = {};
14
+ }
15
+
16
+ let countryCode = null;
17
+
18
+ if (get(payload, 'pickup.country') === country || get(payload, 'dropoff.country') === country) {
19
+ countryCode = country;
20
+ }
21
+
22
+ if (isArray(waypoints) && !isBlank(waypoints?.firstObject) && get(waypoints?.firstObject, 'place.country') === country) {
23
+ countryCode = country;
24
+ }
25
+
26
+ return countryCode === country;
27
+ };
28
+
29
+ export { isRoutingInCountry };
30
+
31
+ export default function getRoutingHost(payload, waypoints = []) {
32
+ const isRoutingInCanada = isRoutingInCountry('CA', payload, waypoints);
33
+ const isRoutingInUSA = isRoutingInCountry('US', payload, waypoints);
34
+
35
+ if (isRoutingInCanada && typeof config.osrm?.servers?.ca === 'string') {
36
+ return config.osrm.servers.ca;
37
+ }
38
+
39
+ if (isRoutingInUSA && typeof config.osrm?.servers?.us === 'string') {
40
+ return config.osrm.servers.us;
41
+ }
42
+
43
+ return config.osrm.host;
44
+ }
@@ -0,0 +1,21 @@
1
+ // import { classify } from '@ember/string';
2
+
3
+ export default function getServiceName(serviceName) {
4
+ if (serviceName.toLowerCase().startsWith('fleet')) {
5
+ return 'Fleet Ops';
6
+ }
7
+
8
+ if (serviceName.toLowerCase().startsWith('iam') || serviceName.toLowerCase().startsWith('identity')) {
9
+ return 'IAM';
10
+ }
11
+
12
+ if (serviceName.toLowerCase().startsWith('auth')) {
13
+ return 'Auth';
14
+ }
15
+
16
+ if (serviceName === 'developers' || serviceName.toLowerCase().startsWith('developers')) {
17
+ return 'Developers Console';
18
+ }
19
+
20
+ return 'N/A';
21
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Retrieves user options from local storage.
3
+ *
4
+ * Attempts to read the user options stored in local storage as a JSON string under the key
5
+ * USER_OPTIONS_STORAGE_KEY. If the JSON parsing fails, an empty object is returned.
6
+ *
7
+ * @returns {Object} The user options as an object, or an empty object if no valid user options were found.
8
+ * @throws Will not throw an error, even if JSON parsing fails. Errors are silently caught and ignored.
9
+ */
10
+ export default function getUserOptions() {
11
+ const USER_OPTIONS_STORAGE_KEY = '@fleetbase/storage:user-options';
12
+
13
+ try {
14
+ const storedValue = window.localStorage.getItem(USER_OPTIONS_STORAGE_KEY);
15
+ return storedValue ? JSON.parse(storedValue) : {};
16
+ } catch (error) {
17
+ // For debugging purposes, you can log the error (optional)
18
+ // console.error('Failed to parse user options from local storage:', error);
19
+ return {};
20
+ }
21
+ }
@@ -0,0 +1,32 @@
1
+ export default function getWeightUnits() {
2
+ return [
3
+ {
4
+ name: 'Grams',
5
+ value: 'g',
6
+ },
7
+ {
8
+ name: 'Kilograms',
9
+ value: 'kg',
10
+ },
11
+ {
12
+ name: 'Grain',
13
+ value: 'gr',
14
+ },
15
+ {
16
+ name: 'Dram',
17
+ value: 'dr',
18
+ },
19
+ {
20
+ name: 'Ounce',
21
+ value: 'oz',
22
+ },
23
+ {
24
+ name: 'Pound',
25
+ value: 'lb',
26
+ },
27
+ {
28
+ name: 'Tonne',
29
+ value: 't',
30
+ },
31
+ ];
32
+ }
@@ -0,0 +1,6 @@
1
+ import { get } from '@ember/object';
2
+
3
+ export default function getWithDefault(obj, key, defaultValue) {
4
+ let value = get(obj, key);
5
+ return value === undefined ? defaultValue : value;
6
+ }