Skip to content

Modular logistics and supply chain operating system (LSOS)

create dashboard

Turtuvshin8d5e6496466d
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbs
index 49c19c1c..3342d2ad 100644
--- a/console/app/components/dashboard.hbs
+++ b/console/app/components/dashboard.hbs
@@ -20,9 +20,33 @@
<!-- Button -->
<div class="ml-4 relative">
-
- <Button @type="magic" @icon="edit" @helpText={{"Edit Dashboard"}} @onClick={{this.onChangeEdit}} />
- <Button @type="magic" @icon="add" @helpText={{"Add new widgets to Dashboard"}} @onClick={{this.openWidgetSelector}} />
+ <DropdownButton @icon="ellipsis-h" @size="sm" @iconPrefix="fas" @triggerClass="mr-2 hidden md:flex" as |dd|>
+ <div class="next-dd-menu mt-1 mx-0" aria-labelledby="user-menu">
+ <div class="p-1">
+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.createDashboard)}}>
+ <div class="w-6">
+ <FaIcon @icon="add" />
+ </div>
+ <span>Create new Dashboard</span>
+ </a>
+ <a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onChangeEdit)}}>
+ <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>
+ </div>
+ </div>
+ </DropdownButton>
+ </div>
+ <div class="ml-4">
+ <Button @type="magic" @icon="save" @helpText={{"Save Dashboard"}} @onClick={{this.onChangeEdit}} />
</div>
</div>
</div>
diff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.js
index 25a0f3a9..5e3c67d0 100644
--- a/console/app/components/dashboard.js
+++ b/console/app/components/dashboard.js
@@ -1,12 +1,14 @@
-import Component from '@glimmer/component';
-import loadExtensions from '@fleetbase/ember-core/utils/load-extensions';
-import { inject as service } from '@ember/service';
import { action } from '@ember/object';
+import { inject as service } from '@ember/service';
+import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency-decorators';
export default class DashboardComponent extends Component {
@service store;
+ @service notifications;
+ @service modalsManager;
+
@tracked dashboards = [];
@tracked currentDashboard;
@tracked isSelectingWidgets = false;
@@ -55,4 +57,34 @@ export default class DashboardComponent extends Component {
@action onChangeEdit() {
this.isEditDashboard = !this.isEditDashboard;
}
+
+ @action createDashboard(dashboard, options = {}) {
+ this.modalsManager.show('modals/create-dashboard', {
+ title: `Create a new dashboard`,
+ acceptButtonText: 'Save Changes',
+ confirm: (modal, done) => {
+ modal.startLoading();
+ const { name } = modal.getOptions();
+
+ const newDashboard = this.store.createRecord('dashboard', { name });
+
+ newDashboard
+ .save()
+ .then((response) => {
+ if (typeof options.successNotification === 'function') {
+ this.notifications.success(options.successNotification(response));
+ } else {
+ this.notifications.success(options.successNotification || `${response.name} created.`);
+ }
+
+ done();
+ })
+ .catch((error) => {
+ modal.stopLoading();
+ this.notifications.serverError(error);
+ });
+ },
+ ...options,
+ });
+ }
}
diff --git a/console/app/components/dashboard/create.hbs b/console/app/components/dashboard/create.hbs
index 5247458e..21e380e2 100644
--- a/console/app/components/dashboard/create.hbs
+++ b/console/app/components/dashboard/create.hbs
@@ -7,11 +7,11 @@
{{#each this.args.dashboard.widgets as |widget index|}}
<GridStackItem @options={{widget.grid_options}} class="relative">
{{component widget.component options=widget.options}}
- {{!-- {{#if this.isEdit}} --}}
- <div class="absolute top-0 right-0">
- <Button @type="default" @icon="trash" @onClick={{fn this.removeWidget widget}} />
- </div>
- {{!-- {{/if}} --}}
+ {{#if this.args.isEdit}}
+ <div class="absolute top-2 right-2">
+ <Button @type="default" @icon="trash" @onClick={{fn this.removeWidget widget}} />
+ </div>
+ {{/if}}
</GridStackItem>
{{/each}}
</GridStack>
diff --git a/console/app/components/dashboard/create.js b/console/app/components/dashboard/create.js
index 9b34b2cc..b3990571 100644
--- a/console/app/components/dashboard/create.js
+++ b/console/app/components/dashboard/create.js
@@ -27,12 +27,7 @@ export default class DashboardCreateComponent extends Component {
console.log('Grid Stack event: ', event);
}
- @action onDragToDashboard(event) {
- console.log('Grid Stack drag event: ', event);
- }
-
@action removeWidget(widget) {
- console.log('Removing widget: ', widget);
this.args.dashboard.removeWidget(widget.id);
}
}
diff --git a/console/app/components/modals/create-dashboard.hbs b/console/app/components/modals/create-dashboard.hbs
new file mode 100644
index 00000000..9f5c4223
--- /dev/null
+++ b/console/app/components/modals/create-dashboard.hbs
@@ -0,0 +1,5 @@
+<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
+ <div class="modal-body-container">
+ <InputGroup @name="Dashboard name" @value={{@options.name}} @helpText="Enter the name of your dashboard" />
+ </div>
+</Modal::Default>
\ No newline at end of file