Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
updated dashboard ui/ux and updated universe method names in implementation
Ronald A. Richardson9d49730d52c0
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbsindex e3257881..077717e5 100644--- a/console/app/components/dashboard.hbs+++ b/console/app/components/dashboard.hbs@@ -1,21 +1,28 @@-<div class="fleetbase-dashboard-grid flex items-center justify-between mx-2">+<div class="fleetbase-dashboard-grid flex items-center justify-between mb-4 mt-6 px-14"><div class="left-section">{{! Dashboard Title Text }}<h1 class="text-lg font-bold">{{this.dashboard.currentDashboard.name}}</h1></div>- <div class="right-section ml-4 flex items-center">+ <div class="fleetbase-dashboard-actions right-section ml-4 flex items-center">{{! Select Dropdown }}<div class="fleetbase-model-select fleetbase-power-select ember-model-select h-10">- <PowerSelect- @options={{this.dashboard.dashboards}}- @selected={{this.dashboard.currentDashboard}}- @onChange={{this.selectDashboard}}- @placeholder="Select Dashboard"- @triggerClass="form-select form-input"- as |dashboard|- >+ {{!-- <PowerSelect @options={{this.dashboard.dashboards}} @selected={{this.dashboard.currentDashboard}} @onChange={{this.selectDashboard}} @placeholder="Select Dashboard" @triggerClass="form-select form-input" as |dashboard|>{{smart-humanize dashboard.name}}- </PowerSelect>+ </PowerSelect> --}}+ <DropdownButton class="h-10" @text="Select Dashboard" @textClass="text-sm mr-2" @buttonClass="flex-row-reverse" @icon="caret-down" @iconClass="mr-0i" @size="sm" @iconPrefix="fas" @triggerClass="hidden md:flex" as |dd|>+ <div class="next-dd-menu mt-1 mx-0" aria-labelledby="user-menu">+ <div class="p-1">+ {{#each this.dashboard.dashboards as |dashboard|}}+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.selectDashboard dashboard)}}>+ <div class="w-6">+ <FaIcon @icon="desktop" />+ </div>+ <span>{{dashboard.name}}</span>+ </a>+ {{/each}}+ </div>+ </div>+ </DropdownButton></div>{{! Button }}@@ -54,12 +61,11 @@</div></div>-<Dashboard::Create @isEdit={{this.dashboard.isEditingDashboard}} @dashboard={{this.dashboard.currentDashboard}} />-{{#if this.dashboard.isEditingDashboard}}- <Dashboard::WidgetPanel- @isOpen={{this.dashboard.isEditingDashboard}}- @onLoad={{this.setWidgetSelectorPanelContext}}- @dashboard={{this.dashboard.currentDashboard}}- @onClose={{fn this.onChangeEdit false}}- />-{{/if}}\ No newline at end of file+<div class="px-10">+ <Dashboard::Create @isEdit={{this.dashboard.isEditingDashboard}} @dashboard={{this.dashboard.currentDashboard}} />+ {{#if this.dashboard.isEditingDashboard}}+ <EmberWormhole @to="console-home-wormhole">+ <Dashboard::WidgetPanel @isOpen={{this.dashboard.isEditingDashboard}} @onLoad={{this.setWidgetSelectorPanelContext}} @dashboard={{this.dashboard.currentDashboard}} @onClose={{fn this.onChangeEdit false}} />+ </EmberWormhole>+ {{/if}}+</div>\ No newline at end of filediff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.jsindex baaf45a8..0684637d 100644--- a/console/app/components/dashboard.js+++ b/console/app/components/dashboard.js@@ -13,7 +13,6 @@ export default class DashboardComponent extends Component {constructor() {super(...arguments);-this.loadDashboards.perform();}@@ -52,9 +51,9 @@ export default class DashboardComponent extends Component {@action deleteDashboard(dashboard, options = {}) {if (this.dashboard.dashboards?.length === 1) {- this.notifications.error('You cannot delete the last dashboard.');- return;+ return this.notifications.error('You cannot delete the last dashboard.');}+this.modalsManager.confirm({title: `Are you sure to delete this ${dashboard.name}?`,confirm: async (modal, done) => {diff --git a/console/app/components/dashboard/create.hbs b/console/app/components/dashboard/create.hbsindex 0db85942..3b07a154 100644--- a/console/app/components/dashboard/create.hbs+++ b/console/app/components/dashboard/create.hbs@@ -1,9 +1,9 @@<div class="fleetbase-dashboard-grid" ...attributes><GridStack @options={{this.gridOptions}} @onChange={{this.onChangeGrid}}>- {{#each this.args.dashboard.widgets as |widget index|}}+ {{#each @dashboard.widgets as |widget|}}<GridStackItem @options={{widget.grid_options}} class="relative">{{component widget.component options=widget.options}}- {{#if this.args.isEdit}}+ {{#if @isEdit}}<div class="absolute top-2 right-2"><Button @type="default" @icon="trash" @helpText={{"Remove widget from the dashboard"}} @onClick={{fn this.removeWidget widget}} /></div>diff --git a/console/app/components/dashboard/widget-panel.hbs b/console/app/components/dashboard/widget-panel.hbsindex ea598475..070cc0e9 100644--- a/console/app/components/dashboard/widget-panel.hbs+++ b/console/app/components/dashboard/widget-panel.hbs@@ -6,19 +6,24 @@</Overlay::Header><Overlay::Body @wrapperClass="new-service-rate-overlay-body px-4 space-y-4 pt-4" @increaseInnerBodyHeightBy={{1000}}>- <div class="grid grid-cols-2 gap-4 text-xs dark:text-gray-100">+ <div class="grid grid-cols-1 gap-4 text-xs dark:text-gray-100">{{#each this.availableWidgets as |widget|}}<div- class="flex flex-col items-center justify-center rounded-lg border border-gray-300 bg-white dark:border-gray-700 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 transition-all duration-300 ease-in-out shadow-md p-4 cursor-pointer"+ class="rounded-lg border border-gray-300 bg-white dark:border-gray-700 dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 transition-all duration-300 ease-in-out shadow-md px-4 py-2 cursor-pointer"{{on "click" (fn this.addWidgetToDashboard widget)}}>- <div class="flex items-center mb-2">- <FaIcon @icon={{widget.icon}} class="text-2xl text-gray-600 dark:text-gray-300 mr-2" />- <p class="text-sm font-semibold dark:text-gray-100 text-gray-800">+ <div class="flex flex-row items-center leading-6 mb-2">+ <div class="w-8 flex items-center justify-start">+ <FaIcon @icon={{widget.icon}} class="text-2xl text-gray-600 dark:text-gray-300" />+ </div>+ <p class="text-sm truncate font-semibold dark:text-gray-100 text-gray-800">{{widget.name}}widget</p></div>+ <div>+ <p class="text-xs dark:text-gray-100 text-gray-800">{{widget.description}}</p>+ </div></div>{{/each}}</div>diff --git a/console/app/components/dashboard/widget-panel.js b/console/app/components/dashboard/widget-panel.jsindex 87a17fb6..3b04558a 100644--- a/console/app/components/dashboard/widget-panel.js+++ b/console/app/components/dashboard/widget-panel.js@@ -9,13 +9,14 @@ export default class DashboardWidgetPanelComponent extends Component {@tracked dashboard;@tracked isOpen = true;@service notifications;+/*** Constructs the component and applies initial state.*/constructor(owner, { dashboard }) {super(...arguments);- this.availableWidgets = this.universe.getWidgets();+ this.availableWidgets = this.universe.getDashboardWidgets();this.dashboard = dashboard;console.log(this.availableWidgets, this.dashboard);diff --git a/console/app/instance-initializers/initialize-widgets.js b/console/app/instance-initializers/initialize-widgets.jsindex a9de81ac..67c4f977 100644--- a/console/app/instance-initializers/initialize-widgets.js+++ b/console/app/instance-initializers/initialize-widgets.js@@ -2,10 +2,11 @@ import { faGithub } from '@fortawesome/free-brands-svg-icons';export function initialize(application) {const universe = application.lookup('service:universe');-- const availableWidgets = [+ const defaultWidgets = [{+ did: 'fleetbase-blog',name: 'Fleetbase Blog',+ description: 'Lists latest news and events from the Fleetbase official team.',icon: 'newspaper',component: 'fleetbase-blog',grid_options: { w: 8, h: 9 },@@ -14,47 +15,20 @@ export function initialize(application) {},},{+ did: 'github-card',name: 'Github Card',+ description: 'Displays current Github stats from the official Fleetbase repo.',icon: faGithub,component: 'github-card',grid_options: { w: 4, h: 8 },options: {title: 'Github Card',},- },- {- name: 'Fleet-Ops Metrics',- icon: 'route',- component: 'dashboard/metric',- grid_options: { w: 12, h: 12 },- options: {- title: 'Fleet-Ops Metrics',- endpoint: 'int/v1/fleet-ops/dashboard',- },- },- {- name: 'IAM Metrics',- icon: 'shield-halved',- component: 'dashboard/metric',- grid_options: { w: 12, h: 7 },- options: {- title: 'IAM Metrics',- endpoint: 'int/v1/metrics/iam-dashboard',- },- },- {- name: 'Storefront Metrics',- icon: 'store',- component: 'dashboard/metric',- grid_options: { w: 12, h: 8 },- options: {- title: 'Storefront Metrics',- endpoint: 'storefront/int/v1/dashboard',- },- },+ }];- universe.registerWidgets(availableWidgets);+ universe.registerDefaultDashboardWidgets(defaultWidgets);+ universe.registerDashboardWidgets(defaultWidgets);}export default {diff --git a/console/app/models/dashboard-widget.js b/console/app/models/dashboard-widget.jsindex a97a2dc1..08e6ee44 100644--- a/console/app/models/dashboard-widget.js+++ b/console/app/models/dashboard-widget.js@@ -1,10 +1,46 @@import Model, { attr, belongsTo } from '@ember-data/model';+import { computed } from '@ember/object';+import { format, formatDistanceToNow } from 'date-fns';export default class DashboardWidgetModel extends Model {+ /** @ids */+ @attr('string') dashboard_uuid;++ /** @relationships */+ @belongsTo('dashboard') dashboard;++ /** @attributes */@attr('string') name;@attr('string') component;@attr('object') grid_options;@attr('object') options;- @belongsTo('dashboard') dashboard;- @attr('string') dashboard_uuid;++ /** @dates */+ @attr('date') created_at;+ @attr('date') updated_at;++ /** @computed */+ @computed('updated_at') get updatedAgo() {+ return formatDistanceToNow(this.updated_at);+ }++ @computed('updated_at') get updatedAt() {+ return format(this.updated_at, 'PPP p');+ }++ @computed('updated_at') get updatedAtShort() {+ return format(this.updated_at, 'PP');+ }++ @computed('created_at') get createdAgo() {+ return formatDistanceToNow(this.created_at);+ }++ @computed('created_at') get createdAt() {+ return format(this.created_at, 'PPP p');+ }++ @computed('created_at') get createdAtShort() {+ return format(this.created_at, 'PP');+ }}diff --git a/console/app/models/dashboard.js b/console/app/models/dashboard.jsindex 3350af83..45d3a059 100644--- a/console/app/models/dashboard.js+++ b/console/app/models/dashboard.js@@ -1,13 +1,49 @@import Model, { attr, hasMany } from '@ember-data/model';+import { computed } from '@ember/object';+import { format, formatDistanceToNow } from 'date-fns';import { getOwner } from '@ember/application';export default class DashboardModel extends Model {- @attr('string') uuid;- @attr('boolean') is_default;- @attr('string') name;+ /** @ids */@attr('string') owner_uuid;- @hasMany('dashboard-widget') widgets;+ /** @relationships */+ @hasMany('dashboard-widget', { async: false }) widgets;++ /** @attributes */+ @attr('string') name;+ @attr('boolean') is_default;++ /** @dates */+ @attr('date') created_at;+ @attr('date') updated_at;++ /** @computed */+ @computed('updated_at') get updatedAgo() {+ return formatDistanceToNow(this.updated_at);+ }++ @computed('updated_at') get updatedAt() {+ return format(this.updated_at, 'PPP p');+ }++ @computed('updated_at') get updatedAtShort() {+ return format(this.updated_at, 'PP');+ }++ @computed('created_at') get createdAgo() {+ return formatDistanceToNow(this.created_at);+ }++ @computed('created_at') get createdAt() {+ return format(this.created_at, 'PPP p');+ }++ @computed('created_at') get createdAtShort() {+ return format(this.created_at, 'PP');+ }++ /** @methods */addWidget(widget) {const owner = getOwner(this);const store = owner.lookup('service:store');diff --git a/console/app/services/dashboard.js b/console/app/services/dashboard.jsindex 941c69cc..bfe6acc2 100644--- a/console/app/services/dashboard.js+++ b/console/app/services/dashboard.js@@ -9,6 +9,7 @@ export default class DashboardService extends Service {@service store;@service fetch;@service notifications;+ @service universe;@tracked dashboards = [];@tracked currentDashboard;@@ -16,14 +17,15 @@ export default class DashboardService extends Service {@task *loadDashboards() {try {- this.dashboards = yield this.store.findAll('dashboard');+ const dashboards = yield this.store.findAll('dashboard');- if (this.dashboards.length > 0) {- this.currentDashboard = this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];+ this.dashboards = dashboards.toArray();+ this.dashboards.unshiftObject(this._createDefaultDashboard());- if (this.currentDashboard?.widgets?.length === 0) {- this.onChangeEdit(true);- }+ // Set the current dashboard+ this.currentDashboard = this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];+ if (this.currentDashboard?.widgets?.length === 0) {+ this.onChangeEdit(true);}} catch (error) {console.error('Error loading dashboards:', error);@@ -95,4 +97,22 @@ export default class DashboardService extends Service {@action onChangeEdit(state = true) {this.isEditingDashboard = state;}++ _createDefaultDashboard() {+ const defaultDashboard = this.store.createRecord('dashboard', {+ name: 'Default Dashboard',+ is_default: false,+ widgets: this._createDefaultDashboardWidgets()+ });++ return defaultDashboard;+ }++ _createDefaultDashboardWidgets() {+ const widgets = this.universe.getDefaultDashboardWidgets().map((defaultWidget) => {+ return this.store.createRecord('dashboard-widget', defaultWidget);+ });++ return widgets;+ }}diff --git a/console/app/templates/console.hbs b/console/app/templates/console.hbsindex 64c2532c..7da8a9de 100644--- a/console/app/templates/console.hbs+++ b/console/app/templates/console.hbs@@ -18,4 +18,5 @@{{!-- Add Locale Selector to Header --}}<EmberWormhole @to="view-header-actions"><LocaleSelector class="mr-0.5" />-</EmberWormhole>\ No newline at end of file+</EmberWormhole>+<div id="console-wormhole" />\ No newline at end of filediff --git a/console/app/templates/console/home.hbs b/console/app/templates/console/home.hbsindex ab93c671..a1177a6d 100644--- a/console/app/templates/console/home.hbs+++ b/console/app/templates/console/home.hbs@@ -1,8 +1,7 @@{{page-title "Dashboard"}}-<Layout::Section::Body class="overflow-y-scroll h-full pt-6">- <div class="console-home-container mx-auto h-screen space-y-4">- <TwoFaEnforcementAlert />- <Dashboard @sidebar={{this.sidebarContext}} />- <Spacer @height="300px" />- </div>-</Layout::Section::Body>\ No newline at end of file+<Layout::Section::Body class="overflow-y-scroll h-full">+ <TwoFaEnforcementAlert />+ <Dashboard @sidebar={{this.sidebarContext}} />+ <Spacer @height="300px" />+</Layout::Section::Body>+<div id="console-home-wormhole" />\ No newline at end of file