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
fixed grid item change events
Turtuvshind1a77c95d049
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbsindex 077717e5..8b1ab009 100644--- a/console/app/components/dashboard.hbs+++ b/console/app/components/dashboard.hbs@@ -6,10 +6,19 @@<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|>- {{smart-humanize dashboard.name}}- </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|>++ <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|}}@@ -65,7 +74,12 @@<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}} />+ <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/create.hbs b/console/app/components/dashboard/create.hbsindex 3b07a154..486a9eb8 100644--- a/console/app/components/dashboard/create.hbs+++ b/console/app/components/dashboard/create.hbs@@ -1,7 +1,7 @@<div class="fleetbase-dashboard-grid" ...attributes><GridStack @options={{this.gridOptions}} @onChange={{this.onChangeGrid}}>{{#each @dashboard.widgets as |widget|}}- <GridStackItem @options={{widget.grid_options}} class="relative">+ <GridStackItem @options={{spread-widget-options (hash id=widget.uuid options=widget.grid_options)}} class="relative">{{component widget.component options=widget.options}}{{#if @isEdit}}<div class="absolute top-2 right-2">diff --git a/console/app/components/dashboard/create.js b/console/app/components/dashboard/create.jsindex 5e19d147..40c71bb6 100644--- a/console/app/components/dashboard/create.js+++ b/console/app/components/dashboard/create.js@@ -2,19 +2,13 @@ import { action, computed } from '@ember/object';import Component from '@glimmer/component';import { tracked } from '@glimmer/tracking';+import { merge } from '@ember/object/internals';import { inject as service } from '@ember/service';export default class DashboardCreateComponent extends Component {- @tracked dashboard;-@service notifications;constructor(owner, args) {super(...arguments);-- const { dashboard } = args;- // Access the dashboard property from the arguments- this.dashboard = dashboard || this.args.dashboard;- console.log('Dashboard in Create: ', this.args.dashboard, args, dashboard);}@action@@ -22,12 +16,12 @@ export default class DashboardCreateComponent extends Component {this.shouldFloat = !this.shouldFloat;}- @action onQueryParamsChanged(changedParams) {- this.reloadDashboard.perform(changedParams);- }-@action onChangeGrid(event) {console.log('Grid Stack event: ', event);+ console.log(+ 'dashboard: ',+ this.args.dashboard.widgets.map((widget) => widget.serialize())+ );}@action removeWidget(widget) {diff --git a/console/app/helpers/spread-widget-options.js b/console/app/helpers/spread-widget-options.jsnew file mode 100644index 00000000..2a815ad2--- /dev/null+++ b/console/app/helpers/spread-widget-options.js@@ -0,0 +1,6 @@+import { helper } from '@ember/component/helper';++export default helper(function spreadWidgetOptions([params]) {+ const { id, options } = params;+ return { id, ...options };+});diff --git a/console/app/instance-initializers/initialize-widgets.js b/console/app/instance-initializers/initialize-widgets.jsindex 67c4f977..6900ac82 100644--- a/console/app/instance-initializers/initialize-widgets.js+++ b/console/app/instance-initializers/initialize-widgets.js@@ -24,7 +24,7 @@ export function initialize(application) {options: {title: 'Github Card',},- }+ },];universe.registerDefaultDashboardWidgets(defaultWidgets);diff --git a/console/app/models/dashboard-widget.js b/console/app/models/dashboard-widget.jsindex 08e6ee44..9214a2a5 100644--- a/console/app/models/dashboard-widget.js+++ b/console/app/models/dashboard-widget.js@@ -4,6 +4,7 @@ import { format, formatDistanceToNow } from 'date-fns';export default class DashboardWidgetModel extends Model {/** @ids */+ @attr('string') uuid;@attr('string') dashboard_uuid;/** @relationships */@@ -14,7 +15,7 @@ export default class DashboardWidgetModel extends Model {@attr('string') component;@attr('object') grid_options;@attr('object') options;-+/** @dates */@attr('date') created_at;@attr('date') updated_at;diff --git a/console/app/models/dashboard.js b/console/app/models/dashboard.jsindex 45d3a059..3c98ed58 100644--- a/console/app/models/dashboard.js+++ b/console/app/models/dashboard.js@@ -14,34 +14,34 @@ export default class DashboardModel extends Model {@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');- }+ /** @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) {@@ -66,23 +66,38 @@ export default class DashboardModel extends Model {});}- removeWidget(widget) {+ /** @methods */+ addWidget(widget) {const owner = getOwner(this);const store = owner.lookup('service:store');- const widgetRecord = store.peekRecord('dashboard-widget', widget);+ const widgetRecord = store.createRecord('dashboard-widget', widget);++ widgetRecord.dashboard = this;+ console.log(widgetRecord);+ return new Promise((resolve, reject) => {+ widgetRecord+ .save()+ .then((widgetRecord) => {+ this.widgets.pushObject(widgetRecord);+ resolve(widgetRecord);+ })+ .catch((error) => {+ store.unloadRecord(widgetRecord);+ reject(error);+ });+ });+ }++ updateWidget(widget) {+ const owner = getOwner(this);+ const store = owner.lookup('service:store');+ const widgetRecord = store.findRecord('dashboard-widget', widget.id);if (widgetRecord) {- return new Promise((resolve, reject) => {- widgetRecord- .destroyRecord()- .then(() => {- this.widgets.removeObject(widgetRecord);- resolve();- })- .catch((error) => {- reject(error);- });+ widgetRecord.set('grid_options', widget.grid_options);+ widgetRecord.save().then((post) => {+ console.log('Post updated successfully.');});}}diff --git a/console/app/services/dashboard.js b/console/app/services/dashboard.jsindex bfe6acc2..2a56e1a2 100644--- a/console/app/services/dashboard.js+++ b/console/app/services/dashboard.js@@ -14,6 +14,7 @@ export default class DashboardService extends Service {@tracked dashboards = [];@tracked currentDashboard;@tracked isEditingDashboard = false;+ @tracked isAddingWidget = false;@task *loadDashboards() {try {@@ -98,11 +99,15 @@ export default class DashboardService extends Service {this.isEditingDashboard = state;}+ @action onAddingWidget(state = true) {+ this.isAddingWidget = state;+ }+_createDefaultDashboard() {const defaultDashboard = this.store.createRecord('dashboard', {name: 'Default Dashboard',is_default: false,- widgets: this._createDefaultDashboardWidgets()+ widgets: this._createDefaultDashboardWidgets(),});return defaultDashboard;diff --git a/console/tests/integration/helpers/spread-widget-options-test.js b/console/tests/integration/helpers/spread-widget-options-test.jsnew file mode 100644index 00000000..e9a197e9--- /dev/null+++ b/console/tests/integration/helpers/spread-widget-options-test.js@@ -0,0 +1,17 @@+import { module, test } from 'qunit';+import { setupRenderingTest } from '@fleetbase/console/tests/helpers';+import { render } from '@ember/test-helpers';+import { hbs } from 'ember-cli-htmlbars';++module('Integration | Helper | spread-widget-options', function (hooks) {+ setupRenderingTest(hooks);++ // TODO: Replace this with your real tests.+ test('it renders', async function (assert) {+ this.set('inputValue', '1234');++ await render(hbs`{{spread-widget-options this.inputValue}}`);++ assert.dom().hasText('1234');+ });+});