@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,20 @@
1
+ import { isArray } from '@ember/array';
2
+
3
+ export default function groupApiEvents(webhookEvents = []) {
4
+ const groups = {};
5
+
6
+ if (isArray(webhookEvents)) {
7
+ for (let i = 0; i < webhookEvents.length; i++) {
8
+ const event = webhookEvents[i];
9
+ const eventResource = event.split('.')[0];
10
+ if (!groups[eventResource]) {
11
+ groups[eventResource] = [];
12
+ }
13
+ if (event.includes(eventResource)) {
14
+ groups[eventResource].push(event);
15
+ }
16
+ }
17
+ }
18
+
19
+ return groups;
20
+ }
@@ -0,0 +1,26 @@
1
+ import { get } from '@ember/object';
2
+
3
+ export default function groupBy(arr, key) {
4
+ let grouped = {};
5
+ let _key;
6
+
7
+ for (let i = 0; i < arr.length; i++) {
8
+ const item = arr.objectAt(i);
9
+
10
+ if (typeof key === 'string') {
11
+ _key = get(item, key);
12
+ }
13
+
14
+ if (typeof key === 'function') {
15
+ _key = key(item, i);
16
+ }
17
+
18
+ if (!grouped[_key]) {
19
+ grouped[_key] = [];
20
+ }
21
+
22
+ grouped[_key].pushObject(item);
23
+ }
24
+
25
+ return grouped;
26
+ }
@@ -0,0 +1,11 @@
1
+ export default function hasExtension(pkg) {
2
+ let has = true;
3
+
4
+ try {
5
+ require(pkg);
6
+ } catch {
7
+ has = false;
8
+ }
9
+
10
+ return has;
11
+ }
@@ -0,0 +1,10 @@
1
+ export default function hasJsonStructure(str) {
2
+ if (typeof str !== 'string') return false;
3
+ try {
4
+ const result = JSON.parse(str);
5
+ const type = Object.prototype.toString.call(result);
6
+ return type === '[object Object]' || type === '[object Array]';
7
+ } catch (err) {
8
+ return false;
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ export default function hasonStructure() {
2
+ return true;
3
+ }
@@ -0,0 +1,59 @@
1
+ var haversine = (function () {
2
+ var RADII = {
3
+ km: 6371,
4
+ mile: 3960,
5
+ meter: 6371000,
6
+ nmi: 3440,
7
+ };
8
+
9
+ // convert to radians
10
+ var toRad = function (num) {
11
+ return (num * Math.PI) / 180;
12
+ };
13
+
14
+ // convert coordinates to standard format based on the passed format option
15
+ var convertCoordinates = function (format, coordinates) {
16
+ switch (format) {
17
+ case '[lat,lon]':
18
+ return { latitude: coordinates[0], longitude: coordinates[1] };
19
+ case '[lon,lat]':
20
+ return { latitude: coordinates[1], longitude: coordinates[0] };
21
+ case '{lon,lat}':
22
+ return { latitude: coordinates.lat, longitude: coordinates.lon };
23
+ case '{lat,lng}':
24
+ return { latitude: coordinates.lat, longitude: coordinates.lng };
25
+ case 'geojson':
26
+ return {
27
+ latitude: coordinates.geometry.coordinates[1],
28
+ longitude: coordinates.geometry.coordinates[0],
29
+ };
30
+ default:
31
+ return coordinates;
32
+ }
33
+ };
34
+
35
+ return function haversine(startCoordinates, endCoordinates, options) {
36
+ options = options || {};
37
+
38
+ var R = options.unit in RADII ? RADII[options.unit] : RADII.km;
39
+
40
+ var start = convertCoordinates(options.format, startCoordinates);
41
+ var end = convertCoordinates(options.format, endCoordinates);
42
+
43
+ var dLat = toRad(end.latitude - start.latitude);
44
+ var dLon = toRad(end.longitude - start.longitude);
45
+ var lat1 = toRad(start.latitude);
46
+ var lat2 = toRad(end.latitude);
47
+
48
+ var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
49
+ var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
50
+
51
+ if (options.threshold) {
52
+ return options.threshold > R * c;
53
+ }
54
+
55
+ return R * c;
56
+ };
57
+ })();
58
+
59
+ export default haversine;
@@ -0,0 +1,16 @@
1
+ import { humanize as humanizeString } from 'ember-cli-string-helpers/helpers/humanize';
2
+
3
+ export default function humanize(string) {
4
+ const uppercase = ['api', 'vat', 'id', 'uuid', 'sku', 'ean', 'upc', 'erp', 'tms', 'wms', 'ltl', 'ftl', 'lcl', 'fcl', 'rfid', 'jot', 'roi', 'eta', 'pod', 'asn', 'oem', 'ddp', 'fob'];
5
+
6
+ return humanizeString([string])
7
+ .split(' ')
8
+ .map((word) => {
9
+ if (uppercase.includes(word.toLowerCase())) {
10
+ return word.toUpperCase();
11
+ }
12
+
13
+ return word;
14
+ })
15
+ .join(' ');
16
+ }
@@ -0,0 +1,18 @@
1
+ export default function isElectron() {
2
+ // Renderer process
3
+ if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
4
+ return true;
5
+ }
6
+
7
+ // Main process
8
+ if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
9
+ return true;
10
+ }
11
+
12
+ // Detect the user agent when the `nodeIntegration` option is set to true
13
+ if (typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0) {
14
+ return true;
15
+ }
16
+
17
+ return false;
18
+ }
@@ -0,0 +1,5 @@
1
+ export default function isEmail(email) {
2
+ const pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
3
+
4
+ return pattern.test(email);
5
+ }
@@ -0,0 +1,3 @@
1
+ export default function isFunction() {
2
+ return true;
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function isImageFile(type) {
2
+ return /image|jpg|jpeg|png|gif|webp/i.test(type);
3
+ }
@@ -0,0 +1,7 @@
1
+ export default function isIterable(obj) {
2
+ if (obj == null) {
3
+ return false;
4
+ }
5
+
6
+ return typeof obj[Symbol.iterator] === 'function';
7
+ }
@@ -0,0 +1,9 @@
1
+ export default function isJson(str) {
2
+ if (typeof str !== 'string') return false;
3
+ try {
4
+ JSON.parse(str);
5
+ } catch (e) {
6
+ return false;
7
+ }
8
+ return true;
9
+ }
@@ -0,0 +1,3 @@
1
+ export default function isLatitude(coordinate) {
2
+ return isFinite(coordinate) && Math.abs(coordinate) <= 90;
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function isLetter(l) {
2
+ return l.length === 1 && l.match(/[a-z]/i);
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function isLongitude(coordinate) {
2
+ return isFinite(coordinate) && Math.abs(coordinate) <= 180;
3
+ }
@@ -0,0 +1,6 @@
1
+ import Model from '@ember-data/model';
2
+ import ObjectProxy from '@ember/object/proxy';
3
+
4
+ export default function isModel(mixed) {
5
+ return mixed instanceof Model || mixed instanceof ObjectProxy;
6
+ }
@@ -0,0 +1,5 @@
1
+ import { isEmpty } from '@ember/utils';
2
+
3
+ export default function isNotEmpty(...params) {
4
+ return !isEmpty(...params);
5
+ }
@@ -0,0 +1,5 @@
1
+ import isModel from './is-model';
2
+
3
+ export default function isNotModel(model) {
4
+ return !isModel(model);
5
+ }
@@ -0,0 +1,3 @@
1
+ export default function isNumeric(n) {
2
+ return !isNaN(parseFloat(n)) && isFinite(n);
3
+ }
@@ -0,0 +1,3 @@
1
+ export default function isObject(obj) {
2
+ return typeof obj === 'object';
3
+ }
@@ -0,0 +1,5 @@
1
+ import ObjectProxy from '@ember/object/proxy';
2
+
3
+ export default function isProxy(subject) {
4
+ return subject instanceof ObjectProxy;
5
+ }
@@ -0,0 +1,21 @@
1
+ import isset from './isset';
2
+ import isModel from './is-model';
3
+ import { underscore } from '@ember/string';
4
+
5
+ export default function isRelationMissing(model, relation, options = {}) {
6
+ if (!isModel(model)) {
7
+ return false;
8
+ }
9
+
10
+ relation = underscore(relation);
11
+
12
+ const isMissingRelation = isset(model, `${relation}_uuid`) && !isset(model, ``);
13
+ const isNotMissingPolymorphicType = isset(model, `${relation}_type`);
14
+
15
+ if (isset(options, 'polymorphic') && options.polymorphic === true) {
16
+ // no relation is set, so false
17
+ return isNotMissingPolymorphicType && isset(model, `${relation}_uuid`);
18
+ }
19
+
20
+ return isMissingRelation;
21
+ }
@@ -0,0 +1,38 @@
1
+ import { isArray } from '@ember/array';
2
+ import isLatitude from './is-latitude';
3
+ import isLongitude from './is-longitude';
4
+ import isObject from './is-object';
5
+
6
+ /**
7
+ * Validates coordinates
8
+ *
9
+ * ```
10
+ * isValidCoordinates([0, 0]);
11
+ * isValidCoordinates({lat: 0, lng: 0});
12
+ * isValidCoordinates({latitude: 0, longitude: 0});
13
+ * isValidCoordinates(0, 0);
14
+ * ```
15
+ *
16
+ * @param {Array|Object|Integer} latitude
17
+ * @param {Array|Object|Integer} longitude
18
+ */
19
+ export default function isValidCoordinates(latitude, longitude = null) {
20
+ let testLatitude, testLongitude;
21
+
22
+ if (isArray(latitude) && longitude === null) {
23
+ testLatitude = latitude[0];
24
+ testLongitude = latitude[1];
25
+ }
26
+
27
+ if (!isArray(latitude) && isObject(latitude) && longitude === null) {
28
+ testLatitude = latitude.lat || latitude.latitude;
29
+ testLongitude = latitude.lng || latitude.longitude;
30
+ }
31
+
32
+ if (longitude !== null) {
33
+ testLatitude = latitude;
34
+ testLongitude = longitude;
35
+ }
36
+
37
+ return isLatitude(testLatitude) && isLongitude(testLongitude);
38
+ }
@@ -0,0 +1,3 @@
1
+ export default function isVideoFile(type) {
2
+ return /video|mp4|mov|wmv|avi|flv/i.test(type);
3
+ }
@@ -0,0 +1,5 @@
1
+ import WaypointModel from '../models/waypoint';
2
+
3
+ export default function isWaypointRecord(record) {
4
+ return record instanceof WaypointModel;
5
+ }
@@ -0,0 +1,3 @@
1
+ export default function ison() {
2
+ return true;
3
+ }
@@ -0,0 +1,10 @@
1
+ import { isBlank } from '@ember/utils';
2
+ import { get } from '@ember/object';
3
+
4
+ export default function isset(target, key = null) {
5
+ if (key === null) {
6
+ return !isBlank(target);
7
+ }
8
+
9
+ return !isBlank(get(target, key));
10
+ }
@@ -0,0 +1,23 @@
1
+ import { isArray } from '@ember/array';
2
+
3
+ const isNumber = (value) => typeof value === 'number' && isFinite(value);
4
+
5
+ export default function last(arr, n = 1) {
6
+ if (!isArray(arr) || arr.length === 0) {
7
+ return null;
8
+ }
9
+
10
+ n = isNumber(n) ? +n : 1;
11
+
12
+ if (n === 1) {
13
+ return arr[arr.length - 1];
14
+ }
15
+
16
+ let res = new Array(n);
17
+
18
+ while (n--) {
19
+ res[n] = arr[--len];
20
+ }
21
+
22
+ return res;
23
+ }
@@ -0,0 +1,25 @@
1
+ import { guidFor } from '@ember/object/internals';
2
+
3
+ export default function lazyLoadScript(path) {
4
+ return new Promise(function (resolve, reject) {
5
+ const id = guidFor(path);
6
+
7
+ if (document.getElementById(id)) {
8
+ return resolve();
9
+ }
10
+
11
+ const element = document.createElement('script');
12
+ element.id = id;
13
+ element.src = path;
14
+
15
+ element.addEventListener('load', function () {
16
+ resolve();
17
+ });
18
+
19
+ element.addEventListener('error', function () {
20
+ reject(`Failed to load script (${path})`);
21
+ });
22
+
23
+ document.getElementsByTagName('head')[0].appendChild(element);
24
+ });
25
+ }
@@ -0,0 +1,13 @@
1
+ /* global L */
2
+
3
+ /**
4
+ * Represents an icon to provide when creating a marker.
5
+ * More information about its possible options [here](https://leafletjs.com/reference-1.7.1.html#icon-option).
6
+ *
7
+ * @function leafletIcon
8
+ * @param {Object} options the Icon options object
9
+ * @return {Icon}
10
+ */
11
+ export default function leafletIcon(options = {}) {
12
+ return L.icon(options);
13
+ }
@@ -0,0 +1,3 @@
1
+ export default function leafletPointsFromCoordinates() {
2
+ return true;
3
+ }
@@ -0,0 +1,37 @@
1
+ import { dasherize } from '@ember/string';
2
+ import hostServices from '../exports/host-services';
3
+
4
+ export default async function loadEngines(appInstance, withServices = []) {
5
+ return new Promise((resolve, reject) => {
6
+ return fetch('extensions.json')
7
+ .then((resp) => resp.json())
8
+ .then((extensions) => {
9
+ const engines = {};
10
+ const externalRoutes = {
11
+ console: 'console.home',
12
+ extensions: 'console.extensions',
13
+ };
14
+
15
+ for (let i = 0; i < extensions.length; i++) {
16
+ const extension = extensions[i];
17
+ const path = dasherize(extension.extension);
18
+
19
+ externalRoutes[path] = `console.${path}`;
20
+ }
21
+
22
+ for (let i = 0; i < extensions.length; i++) {
23
+ const extension = extensions[i];
24
+
25
+ engines[extension.name] = {
26
+ dependencies: {
27
+ services: [...hostServices, ...withServices],
28
+ externalRoutes,
29
+ },
30
+ };
31
+ }
32
+
33
+ resolve(engines);
34
+ })
35
+ .catch(reject);
36
+ });
37
+ }
@@ -0,0 +1,8 @@
1
+ export default async function loadExtensions() {
2
+ return new Promise((resolve, reject) => {
3
+ return fetch('/extensions.json')
4
+ .then((resp) => resp.json())
5
+ .then(resolve)
6
+ .catch(reject);
7
+ });
8
+ }
@@ -0,0 +1,28 @@
1
+ import { A } from '@ember/array';
2
+ import { computed, get } from '@ember/object';
3
+ import { isPresent } from '@ember/utils';
4
+
5
+ export default function groupBy(collection, property) {
6
+ let dependentKey = collection + '.@each.' + property;
7
+
8
+ return computed(dependentKey, function () {
9
+ let groups = A();
10
+ let items = get(this, collection);
11
+
12
+ if (items) {
13
+ items.forEach(function (item) {
14
+ let value = get(item, property);
15
+ let group = groups.findBy('value', value);
16
+
17
+ if (isPresent(group)) {
18
+ group.items.push(item);
19
+ } else {
20
+ group = { property: property, value: value, items: [item] };
21
+ groups.push(group);
22
+ }
23
+ });
24
+ }
25
+
26
+ return groups;
27
+ }).readOnly();
28
+ }
@@ -0,0 +1,57 @@
1
+ import groupBy from './group-by';
2
+ import { _range } from './range';
3
+ import { format, startOfMonth, endOfMonth, startOfDay, sub, addDays } from 'date-fns';
4
+
5
+ function randomInt(min, max) {
6
+ min = Math.ceil(min);
7
+ max = Math.floor(max);
8
+ return Math.floor(Math.random() * (max - min) + min);
9
+ }
10
+
11
+ function randomDateThisMonth() {
12
+ const now = new Date();
13
+ const startDate = startOfMonth(now);
14
+ const endDate = endOfMonth(now);
15
+ const diffInDays = (endDate - startDate) / (1000 * 60 * 60 * 24);
16
+ return addDays(startDate, randomInt(0, diffInDays));
17
+ }
18
+
19
+ function makeMockDataset(start, end, dateProperty = 'created_at') {
20
+ const data = _range(start, end).map(() => {
21
+ return {
22
+ created_at: randomDateThisMonth(),
23
+ };
24
+ });
25
+ const grouped = groupBy(data, (record) => {
26
+ return format(new Date(record[dateProperty]), 'MMMM, dd yyyy');
27
+ });
28
+ const dataset = [];
29
+
30
+ for (let day in grouped) {
31
+ dataset.pushObject({
32
+ t: new Date(`${day} 00:00:00`),
33
+ y: grouped[day].length,
34
+ });
35
+ }
36
+
37
+ return dataset.sortBy('t');
38
+ }
39
+
40
+ export { makeMockDataset, randomInt, randomDateThisMonth, _range as range };
41
+
42
+ export default function makeDataset(recordArray, filter = Boolean, dateProperty = 'created_at') {
43
+ const filteredData = recordArray.filter(filter);
44
+ const grouped = groupBy(filteredData, (record) => {
45
+ return format(new Date(record[dateProperty]), 'MMMM, dd yyyy');
46
+ });
47
+ const dataset = [];
48
+
49
+ for (let day in grouped) {
50
+ dataset.pushObject({
51
+ t: new Date(`${day} 00:00:00`),
52
+ y: grouped[day].length,
53
+ });
54
+ }
55
+
56
+ return dataset.sortBy('t');
57
+ }
@@ -0,0 +1,30 @@
1
+ import { dasherize } from '@ember/string';
2
+ import hostServices from '../exports/host-services';
3
+
4
+ export default function mapEngines(extensions, withServices = []) {
5
+ const engines = {};
6
+ const externalRoutes = {
7
+ console: 'console.home',
8
+ extensions: 'console.extensions',
9
+ };
10
+
11
+ for (let i = 0; i < extensions.length; i++) {
12
+ const extension = extensions[i];
13
+ const path = dasherize(extension.extension);
14
+
15
+ externalRoutes[path] = `console.${path}`;
16
+ }
17
+
18
+ for (let i = 0; i < extensions.length; i++) {
19
+ const extension = extensions[i];
20
+
21
+ engines[extension.name] = {
22
+ dependencies: {
23
+ services: [...hostServices, ...withServices],
24
+ externalRoutes,
25
+ },
26
+ };
27
+ }
28
+
29
+ return engines;
30
+ }
@@ -0,0 +1,15 @@
1
+ export default function mockResponse() {
2
+ const response = [];
3
+ response.meta = {
4
+ current_page: 1,
5
+ from: 1,
6
+ last_page: 1,
7
+ per_page: 25,
8
+ to: 1,
9
+ total: 1,
10
+ };
11
+
12
+ return new Promise((resolve) => {
13
+ resolve(response);
14
+ });
15
+ }
@@ -0,0 +1,11 @@
1
+ export default function numbersOnly(string, keepDecimals = false) {
2
+ if (typeof string !== 'string') {
3
+ return string;
4
+ }
5
+
6
+ if (keepDecimals === true) {
7
+ return string.replace(/[^0-9.]+/g, '');
8
+ }
9
+
10
+ return string.replace(/\D+/g, '');
11
+ }
@@ -0,0 +1,40 @@
1
+ export default function pastTense(verb) {
2
+ const exceptions = {
3
+ are: 'were',
4
+ eat: 'ate',
5
+ go: 'went',
6
+ have: 'had',
7
+ inherit: 'inherited',
8
+ is: 'was',
9
+ run: 'ran',
10
+ sit: 'sat',
11
+ visit: 'visited',
12
+ };
13
+
14
+ if (exceptions[verb]) {
15
+ return exceptions[verb];
16
+ }
17
+
18
+ if (/e$/i.test(verb)) {
19
+ return verb + 'd';
20
+ }
21
+
22
+ if (/[aeiou]c/i.test(verb)) {
23
+ return verb + 'ked';
24
+ }
25
+
26
+ // for american english only
27
+ if (/el$/i.test(verb)) {
28
+ return verb + 'ed';
29
+ }
30
+
31
+ if (/[aeio][aeiou][dlmnprst]$/.test(verb)) {
32
+ return verb + 'ed';
33
+ }
34
+
35
+ if (/[aeiou][bdglmnprst]$/i.test(verb)) {
36
+ return verb.replace(/(.+[aeiou])([bdglmnprst])/, '$1$2$2ed');
37
+ }
38
+
39
+ return verb + 'ed';
40
+ }