@fleetbase/ember-core 0.2.0 → 0.2.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.
@@ -546,16 +546,24 @@ export default class FetchService extends Service {
546
546
  .then((response) => response.json())
547
547
  .catch((error) => {
548
548
  this.notifications.serverError(error, 'File upload failed.');
549
+
550
+ if (typeof errorCallback === 'function') {
551
+ errorCallback(error);
552
+ }
549
553
  });
550
554
 
551
- const model = this.store.push(this.store.normalize('file', upload.file));
552
- set(file, 'model', model);
555
+ if (upload) {
556
+ const model = this.store.push(this.store.normalize('file', upload.file));
557
+ set(file, 'model', model);
558
+
559
+ if (typeof callback === 'function') {
560
+ callback(model);
561
+ }
553
562
 
554
- if (typeof callback === 'function') {
555
- callback(model);
563
+ return model;
556
564
  }
557
565
 
558
- return model;
566
+ return null;
559
567
  } catch (error) {
560
568
  queue.remove(file);
561
569
  this.notifications.serverError(error, 'File upload failed.');
@@ -16,7 +16,11 @@ export default class NotificationsService extends EmberNotificationsService {
16
16
  return this.error(errorMessage, options);
17
17
  }
18
18
 
19
- return this.error(error ?? fallbackMessage, options);
19
+ if (typeof error === 'string') {
20
+ return this.error(error, options);
21
+ }
22
+
23
+ return this.error(fallbackMessage, options);
20
24
  }
21
25
 
22
26
  invoke(type, message, ...params) {
@@ -29,6 +29,10 @@ export default class UniverseService extends Service.extend(Evented) {
29
29
  menuItems: A([]),
30
30
  menuPanels: A([]),
31
31
  };
32
+ @tracked dashboardWidgets = {
33
+ defaultWidgets: A([]),
34
+ widgets: A([]),
35
+ };
32
36
 
33
37
  /**
34
38
  * Computed property that returns all administrative menu items.
@@ -656,6 +660,103 @@ export default class UniverseService extends Service.extend(Evented) {
656
660
  this.registerMenuPanel('settings', title, items, options);
657
661
  }
658
662
 
663
+ /**
664
+ * Registers a new dashboard widget in the universe service.
665
+ *
666
+ * @method registerDashboardWidgets
667
+ * @public
668
+ * @memberof UniverseService
669
+ * @param {Object} widget - The widget object containing name, component, gridOptions, and options.
670
+ * @property {String} name - The name of the widget.
671
+ * @property {String} icon - The iron of the widget.
672
+ * @property {Function} component - The component associated with the widget.
673
+ * @property {Object} gridOptions - The grid options for the widget.
674
+ * @property {Object} options - Additional options for the widget.
675
+ */
676
+ registerDashboardWidgets(widget) {
677
+ if (isArray(widget)) {
678
+ widget.forEach((w) => this.registerDashboardWidgets(w));
679
+ return;
680
+ }
681
+
682
+ const newWidget = this._createDashboardWidget(widget);
683
+ this.dashboardWidgets.widgets.pushObject(newWidget);
684
+ this.trigger('widget.registered', newWidget);
685
+ }
686
+
687
+ /**
688
+ * Retrieves the widgets registered in the universe service.
689
+ *
690
+ * @method getDashboardWidgets
691
+ * @public
692
+ * @memberof UniverseService
693
+ * @returns {Array} An array of registered widgets
694
+ */
695
+ getDashboardWidgets() {
696
+ return this.dashboardWidgets.widgets;
697
+ }
698
+
699
+ /**
700
+ * Registers a new dashboard widget in the universe service.
701
+ *
702
+ * @method registerDefaultDashboardWidgets
703
+ * @public
704
+ * @memberof UniverseService
705
+ * @param {Object} widget - The widget object containing name, component, gridOptions, and options.
706
+ * @property {String} name - The name of the widget.
707
+ * @property {String} icon - The iron of the widget.
708
+ * @property {Function} component - The component associated with the widget.
709
+ * @property {Object} gridOptions - The grid options for the widget.
710
+ * @property {Object} options - Additional options for the widget.
711
+ */
712
+ registerDefaultDashboardWidgets(widget) {
713
+ if (isArray(widget)) {
714
+ widget.forEach((w) => this.registerDefaultDashboardWidgets(w));
715
+ return;
716
+ }
717
+
718
+ const newWidget = this._createDashboardWidget(widget);
719
+ this.dashboardWidgets.defaultWidgets.pushObject(newWidget);
720
+ this.trigger('widget.registered', newWidget);
721
+ }
722
+
723
+ /**
724
+ * Retrieves the widgets registered in the universe service.
725
+ *
726
+ * @method getDefaultDashboardWidgets
727
+ * @public
728
+ * @memberof UniverseService
729
+ * @returns {Array} An array of registered widgets
730
+ */
731
+ getDefaultDashboardWidgets() {
732
+ return this.dashboardWidgets.defaultWidgets;
733
+ }
734
+
735
+ /**
736
+ * Creates a dashboard widget object
737
+ *
738
+ * @param {Object} widget
739
+ * @return {Widgetobject}
740
+ * @memberof UniverseService
741
+ */
742
+ _createDashboardWidget(widget) {
743
+ // Extract properties from the widget object
744
+ const { did, name, description, icon, component, grid_options, options } = widget;
745
+
746
+ // Create a new widget object with the extracted properties
747
+ const newWidget = {
748
+ did,
749
+ name,
750
+ description,
751
+ icon,
752
+ component,
753
+ grid_options,
754
+ options,
755
+ };
756
+
757
+ return newWidget;
758
+ }
759
+
659
760
  /**
660
761
  * Registers a new settings menu item.
661
762
  *
@@ -759,6 +860,12 @@ export default class UniverseService extends Service.extend(Evented) {
759
860
  const index = this._getOption(options, 'index', 0);
760
861
  const onClick = this._getOption(options, 'onClick', null);
761
862
  const section = this._getOption(options, 'section', null);
863
+ const iconSize = this._getOption(options, 'iconSize', null);
864
+ const iconClass = this._getOption(options, 'iconClass', null);
865
+ const itemClass = this._getOption(options, 'class', null);
866
+ const inlineClass = this._getOption(options, 'inlineClass', null);
867
+ const wrapperClass = this._getOption(options, 'wrapperClass', null);
868
+ const overwriteWrapperClass = this._getOption(options, 'overwriteWrapperClass', false);
762
869
 
763
870
  // dasherize route segments
764
871
  if (typeof route === 'string') {
@@ -784,6 +891,12 @@ export default class UniverseService extends Service.extend(Evented) {
784
891
  index,
785
892
  section,
786
893
  onClick,
894
+ iconSize,
895
+ iconClass,
896
+ class: itemClass,
897
+ inlineClass,
898
+ wrapperClass,
899
+ overwriteWrapperClass,
787
900
  };
788
901
 
789
902
  return menuItem;
@@ -1,10 +1,16 @@
1
- export default function getResourceNameFromTransition(transition) {
1
+ import humanize from './humanize';
2
+
3
+ export default function getResourceNameFromTransition(transition, options = {}) {
2
4
  const { to } = transition;
3
5
 
4
6
  if (typeof to.name === 'string') {
5
7
  let routePathSegments = to.name.split('.');
6
8
  let resourceName = routePathSegments[3];
7
9
 
10
+ if (options.humanize === true) {
11
+ return humanize(resourceName);
12
+ }
13
+
8
14
  return resourceName;
9
15
  }
10
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
5
5
  "keywords": [
6
6
  "fleetbase-core",