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
Add dashboard and dashboard widget serializers
Turtuvshin5d43df0e1bf8
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbsindex a25281e0..23f96d9d 100644--- a/console/app/components/dashboard.hbs+++ b/console/app/components/dashboard.hbs@@ -1,10 +1,10 @@<div class="fleetbase-dashboard-grid flex items-center justify-between mx-2"><div class="left-section">- <!-- Dashboard Title Text -->+ {{!-- Dashboard Title Text --}}<h1 class="text-lg font-bold">{{this.currentDashboard.name}}</h1></div><div class="right-section ml-4 flex items-center">- <!-- Select Dropdown -->+ {{!-- Select Dropdown --}}<div class="fleetbase-model-select fleetbase-power-select ember-model-select h-10"><PowerSelect@options={{this.dashboards}}@@ -17,7 +17,7 @@{{smart-humanize dashboard.name}}</PowerSelect></div>- <!-- Button -->+ {{!-- Button --}}<div class="ml-2 relative h-10"><DropdownButton class="h-10" @icon="ellipsis-h" @size="sm" @iconPrefix="fas" @triggerClass="hidden md:flex" as |dd|>@@ -29,18 +29,12 @@</div><span>Create new Dashboard</span></a>- <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onChangeEdit)}}>+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onChangeEdit true)}}><div class="w-6"><FaIcon @icon="edit" /></div><span>Edit dashboard</span></a>- <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.openWidgetSelector)}}>- <div class="w-6">- <FaIcon @icon="grip" />- </div>- <span>Add widgets</span>- </a><a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.deleteDashboard this.currentDashboard)}}><div class="w-6">@@ -52,15 +46,15 @@</div></DropdownButton></div>- {{#if this.isEditDashboard}}+ {{#if this.isEditingDashboard}}<div class="ml-2 h-10">- <Button @type="magic" @icon="save" @helpText={{"Save Dashboard"}} @onClick={{this.onChangeEdit}} class="h-10" />+ <Button @type="magic" @icon="save" @helpText={{"Save Dashboard"}} @onClick={{fn this.onChangeEdit false}} class="h-10" /></div>{{/if}}</div></div>-<Dashboard::Create @isEdit={{this.isEditDashboard}} @dashboard={{this.currentDashboard}} />-{{#if this.isSelectingWidgets}}- <Dashboard::WidgetPanel @isOpen={{this.isSelectingWidgets}} @onLoad={{this.setWidgetSelectorPanelContext}} @dashboard={{this.currentDashboard}} @onClose={{this.closeWidgetSelector}} />+<Dashboard::Create @isEdit={{this.isEditingDashboard}} @dashboard={{this.currentDashboard}} />+{{#if this.isEditingDashboard}}+ <Dashboard::WidgetPanel @isOpen={{this.isEditingDashboard}} @onLoad={{this.setWidgetSelectorPanelContext}} @dashboard={{this.currentDashboard}} @onClose={{fn this.onChangeEdit false}} />{{/if}}\ No newline at end of filediff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.jsindex 455f6d8a..50531427 100644--- a/console/app/components/dashboard.js+++ b/console/app/components/dashboard.js@@ -11,8 +11,7 @@ export default class DashboardComponent extends Component {@tracked dashboards = [];@tracked currentDashboard;- @tracked isSelectingWidgets = false;- @tracked isEditDashboard = false;+ @tracked isEditingDashboard = false;constructor() {super(...arguments);@@ -25,10 +24,7 @@ export default class DashboardComponent extends Component {this.dashboards = yield this.store.findAll('dashboard');if (this.dashboards.length > 0) {- const currentDashboard = this.dashboards[0];-- currentDashboard.widgets = yield this.store.query('dashboard-widget', { dashboard_uuid: currentDashboard.uuid });- this.currentDashboard = currentDashboard;+ this.currentDashboard = this.dashboards[0];console.log('Current Dashboard: ', this.currentDashboard);}@@ -46,16 +42,8 @@ export default class DashboardComponent extends Component {console.log('widgetSelectorContext', widgetSelectorContext);}- @action openWidgetSelector() {- this.isSelectingWidgets = true;- }-- @action closeWidgetSelector() {- this.isSelectingWidgets = false;- }-- @action onChangeEdit() {- this.isEditDashboard = !this.isEditDashboard;+ @action onChangeEdit(state = true) {+ this.isEditingDashboard = state;}@action createDashboard(dashboard, options = {}) {@@ -64,6 +52,8 @@ export default class DashboardComponent extends Component {acceptButtonText: 'Save Changes',confirm: (modal, done) => {modal.startLoading();++ // Get the name from the modal optionsconst { name } = modal.getOptions();const newDashboard = this.store.createRecord('dashboard', { name });@@ -71,8 +61,11 @@ export default class DashboardComponent extends Component {newDashboard.save().then((response) => {+ this.currentDashboard = response;+ this.isEditingDashboard = true;if (typeof options.successNotification === 'function') {this.notifications.success(options.successNotification(response));+ this.notifications.warning;} else {this.notifications.success(options.successNotification || `${response.name} created.`);}@@ -89,6 +82,10 @@ export default class DashboardComponent extends Component {}@action deleteDashboard(dashboard, options = {}) {+ if (this.dashboards.length === 1) {+ this.notifications.error('You cannot delete the last dashboard.');+ return;+ }this.modalsManager.confirm({title: `Are you sure to delete this ${dashboard.name}?`,confirm: (modal) => {@@ -105,6 +102,7 @@ export default class DashboardComponent extends Component {if (typeof options.onSuccess === 'function') {options.onSuccess(model);}+ this.currentDashboard = this.dashboards[0];}).catch((error) => {this.notifications.serverError(error);diff --git a/console/app/components/dashboard/create.hbs b/console/app/components/dashboard/create.hbsindex 3505f002..a6340040 100644--- a/console/app/components/dashboard/create.hbs+++ b/console/app/components/dashboard/create.hbs@@ -5,7 +5,7 @@{{component widget.component options=widget.options}}{{#if this.args.isEdit}}<div class="absolute top-2 right-2">- <Button @type="default" @icon="trash" @onClick={{fn this.removeWidget widget}} />+ <Button @type="default" @icon="trash" @helpText={{"Remove widget from the dashboard"}} @onClick={{fn this.removeWidget widget}} /></div>{{/if}}</GridStackItem>diff --git a/console/app/components/dashboard/widget-panel.hbs b/console/app/components/dashboard/widget-panel.hbsindex 9adfb8b4..7f85dd3d 100644--- a/console/app/components/dashboard/widget-panel.hbs+++ b/console/app/components/dashboard/widget-panel.hbs@@ -1,8 +1,7 @@<Overlay @isOpen={{@isOpen}} @onLoad={{this.setOverlayContext}} @position="right" @noBackdrop={{true}} @fullHeight={{true}} @width={{or this.width @width "400px"}}>- <Overlay::Header @title={{"Add widgets"}} @hideStatusDot={{true}} @titleWrapperClass="leading-5">+ <Overlay::Header @title={{"Select widgets"}} @hideStatusDot={{true}} @titleWrapperClass="leading-5"><div class="flex flex-1 justify-end">- <Button @icon={{"save"}} @type="primary" @text={{"Save Dashboard"}} @onClick={{this.save}} @wrapperClass="mr-2" />- <Button @type="default" @icon="times" @helpText={{"Add new widgets to Dashbord"}} @onClick={{this.onPressClose}} />+ <Button @type="default" @icon="times" @helpText={{"Close and Save"}} @onClick={{this.onPressClose}} /></div></Overlay::Header>diff --git a/console/app/serializers/dashboard-widget.js b/console/app/serializers/dashboard-widget.jsnew file mode 100644index 00000000..cc65efb9--- /dev/null+++ b/console/app/serializers/dashboard-widget.js@@ -0,0 +1,3 @@+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';++export default class DashboardWidgetSerializer extends ApplicationSerializer {}diff --git a/console/app/serializers/dashboard.js b/console/app/serializers/dashboard.jsnew file mode 100644index 00000000..7a2f908f--- /dev/null+++ b/console/app/serializers/dashboard.js@@ -0,0 +1,18 @@+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';+import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';++export default class DashboardSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {+ attrs = {+ widgets: { embedded: 'always' },+ };++ serializeHasMany(snapshot, json, relationship) {+ let key = relationship.key;++ if (key === 'widgets') {+ return;+ }++ return super.serializeHasMany(...arguments);+ }+}diff --git a/console/tests/unit/serializers/dashboard-test.js b/console/tests/unit/serializers/dashboard-test.jsnew file mode 100644index 00000000..ed417ef2--- /dev/null+++ b/console/tests/unit/serializers/dashboard-test.js@@ -0,0 +1,24 @@+import { module, test } from 'qunit';++import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Serializer | dashboard', function (hooks) {+ setupTest(hooks);++ // Replace this with your real tests.+ test('it exists', function (assert) {+ let store = this.owner.lookup('service:store');+ let serializer = store.serializerFor('dashboard');++ assert.ok(serializer);+ });++ test('it serializes records', function (assert) {+ let store = this.owner.lookup('service:store');+ let record = store.createRecord('dashboard', {});++ let serializedRecord = record.serialize();++ assert.ok(serializedRecord);+ });+});diff --git a/console/tests/unit/serializers/dashboard-widget-test.js b/console/tests/unit/serializers/dashboard-widget-test.jsnew file mode 100644index 00000000..f0cee1fb--- /dev/null+++ b/console/tests/unit/serializers/dashboard-widget-test.js@@ -0,0 +1,24 @@+import { module, test } from 'qunit';++import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Serializer | dashboard widget', function (hooks) {+ setupTest(hooks);++ // Replace this with your real tests.+ test('it exists', function (assert) {+ let store = this.owner.lookup('service:store');+ let serializer = store.serializerFor('dashboard-widget');++ assert.ok(serializer);+ });++ test('it serializes records', function (assert) {+ let store = this.owner.lookup('service:store');+ let record = store.createRecord('dashboard-widget', {});++ let serializedRecord = record.serialize();++ assert.ok(serializedRecord);+ });+});