Skip to content

Modular logistics and supply chain operating system (LSOS)

patches for dashboard and organizations/users

Ronald A. Richardson948ba4aa6dae
diff --git a/console/app/components/dashboard.hbs b/console/app/components/dashboard.hbs
index 802ed556..30762aba 100644
--- a/console/app/components/dashboard.hbs
+++ b/console/app/components/dashboard.hbs
@@ -1,17 +1,15 @@
<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="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">
<DropdownButton
class="h-10"
- @text={{if this.dashboard.currentDashboard.name this.dashboard.currentDashboard.name "Select Dashboard"}}
+ @text={{if this.dashboard.currentDashboard.name this.dashboard.currentDashboard.name (t "component.dashboard.select-dashboard")}}
@textClass="text-sm mr-2"
- @buttonClass="flex-row-reverse"
+ @buttonClass="flex-row-reverse w-44 justify-between"
@icon="caret-down"
@iconClass="mr-0i"
@size="sm"
@@ -23,17 +21,23 @@
<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 class="flex-1 flex flex-row items-center">
+ <div class="w-6">
+ <FaIcon @icon="desktop" />
+ </div>
+ <span>{{dashboard.name}}</span>
+ </div>
+ <div>
+ {{#if (eq this.dashboard.currentDashboard.id dashboard.id)}}
+ <FaIcon @icon="check" class="text-green-500" />
+ {{/if}}
</div>
- <span>{{dashboard.name}}</span>
</a>
{{/each}}
</div>
</div>
</DropdownButton>
</div>
- {{! 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|>
@@ -43,28 +47,28 @@
<div class="w-6">
<FaIcon @icon="add" />
</div>
- <span>Create new Dashboard</span>
+ <span>{{t "component.dashboard.create-new-dashboard"}}</span>
</a>
- {{#unless (eq this.dashboard.currentDashboard.owner_uuid "system")}}
+ {{#unless (eq this.dashboard.currentDashboard.user_uuid "system")}}
<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 layout</span>
+ <span>{{t "component.dashboard.edit-layout"}}</span>
</a>
<a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.onAddingWidget true)}}>
<div class="w-6">
<FaIcon @icon="add" />
</div>
- <span>Add widgets</span>
+ <span>{{t "component.dashboard.add-widgets"}}</span>
</a>
<a href="javascript:;" class="next-dd-item" {{on "click" (dropdown-fn dd this.deleteDashboard this.dashboard.currentDashboard)}}>
<div class="w-6">
<FaIcon @icon="trash" />
</div>
- <span>Delete dashboard</span>
+ <span>{{t "component.dashboard.delete-dashboard"}}</span>
</a>
{{/unless}}
diff --git a/console/app/components/dashboard.js b/console/app/components/dashboard.js
index 7bb0a2c8..5ec624bc 100644
--- a/console/app/components/dashboard.js
+++ b/console/app/components/dashboard.js
@@ -1,6 +1,6 @@
+import Component from '@glimmer/component';
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';
diff --git a/console/app/components/dashboard/count.hbs b/console/app/components/dashboard/count.hbs
index 9458e91e..8e37aa8b 100644
--- a/console/app/components/dashboard/count.hbs
+++ b/console/app/components/dashboard/count.hbs
@@ -1,6 +1,6 @@
-<div class="dashboard-component-count lg:col-span-2 h-full">
- <h3 class="text-sm dark:text-gray-100 text-black mb-4">{{@options.title}}</h3>
- <h1 class="text-3xl font-bold dark:text-gray-100 text-black mb-4">
- {{this.displayValue}}
+<div class="dashboard-component-count lg:col-span-2 h-full {{@options.wrapperClass}}">
+ <h3 class="text-sm dark:text-gray-100 text-black mb-4 {{@options.titleClass}}">{{this.title}}</h3>
+ <h1 class="text-3xl font-bold dark:text-gray-100 text-black {{@options.valueClass}}">
+ {{this.value}}
</h1>
</div>
\ No newline at end of file
diff --git a/console/app/components/dashboard/count.js b/console/app/components/dashboard/count.js
index c1af1cb9..84e86ca2 100644
--- a/console/app/components/dashboard/count.js
+++ b/console/app/components/dashboard/count.js
@@ -1,5 +1,5 @@
import Component from '@glimmer/component';
-import { computed } from '@ember/object';
+import { tracked } from '@glimmer/tracking';
import formatCurrency from '@fleetbase/ember-ui/utils/format-currency';
import formatMeters from '@fleetbase/ember-ui/utils/format-meters';
import formatBytes from '@fleetbase/ember-ui/utils/format-bytes';
@@ -7,11 +7,40 @@ import formatDuration from '@fleetbase/ember-ui/utils/format-duration';
import formatDate from '@fleetbase/ember-ui/utils/format-date';
export default class DashboardCountComponent extends Component {
- @computed('args.options.{currency,dateFormat,format,value}') get displayValue() {
- let format = this.args.options?.format;
- let currency = this.args.options?.currency;
- let dateFormat = this.args.options?.dateFormat;
- let value = this.args.options?.value;
+ /**
+ * The title of the metric count.
+ *
+ * @memberof WidgetKeyMetricsCountComponent
+ */
+ @tracked title;
+
+ /**
+ * The value to render
+ *
+ * @memberof WidgetKeyMetricsCountComponent
+ */
+ @tracked value;
+
+ /**
+ * Creates an instance of WidgetKeyMetricsCountComponent.
+ * @param {EngineInstance} owner
+ * @param {Object} { options }
+ * @memberof WidgetKeyMetricsCountComponent
+ */
+ constructor(owner, { options, title }) {
+ super(...arguments);
+ this.title = title;
+ this.createRenderValueFromOptions(options);
+ }
+
+ /**
+ * Creates the value to render using the options provided.
+ *
+ * @param {Object} [options={}]
+ * @memberof WidgetKeyMetricsCountComponent
+ */
+ createRenderValueFromOptions(options = {}) {
+ let { format, currency, dateFormat, value } = options;
switch (format) {
case 'money':
@@ -38,6 +67,6 @@ export default class DashboardCountComponent extends Component {
break;
}
- return value;
+ this.value = value;
}
}
diff --git a/console/app/components/dashboard/create.js b/console/app/components/dashboard/create.js
index fe988c80..05d2a3a5 100644
--- a/console/app/components/dashboard/create.js
+++ b/console/app/components/dashboard/create.js
@@ -17,12 +17,6 @@ export default class DashboardCreateComponent extends Component {
}
@action onChangeGrid(event) {
- console.log('Grid Stack event: ', event);
- console.log(
- 'dashboard: ',
- this.args.dashboard.widgets.map((widget) => widget.serialize())
- );
-
const updatedWidgets = [];
event.detail.forEach((currentWidgetEvent, index) => {
@@ -37,8 +31,9 @@ export default class DashboardCreateComponent extends Component {
}
const { id, x, y, w, h } = currentWidgetEvent;
- changedWidget.grid_options = { x, y, w, h };
- const response = changedWidget.updatePosition({ id, x, y, h, w });
+ const response = changedWidget.updateProperties({
+ grid_options: { x, y, w, h },
+ });
if (response) {
updatedWidgets.push(changedWidget);
}
diff --git a/console/app/components/dashboard/metric.js b/console/app/components/dashboard/metric.js
index f0c17146..77dc6c8a 100644
--- a/console/app/components/dashboard/metric.js
+++ b/console/app/components/dashboard/metric.js
@@ -13,7 +13,6 @@ export default class MetricComponent extends Component {
constructor() {
super(...arguments);
- console.log('Dashboard in Metric: ', this.args.options);
this.loadDashboard.perform();
}
diff --git a/console/app/components/dashboard/widget-panel.hbs b/console/app/components/dashboard/widget-panel.hbs
index 070cc0e9..e6e7969c 100644
--- a/console/app/components/dashboard/widget-panel.hbs
+++ b/console/app/components/dashboard/widget-panel.hbs
@@ -1,24 +1,23 @@
<Overlay @isOpen={{@isOpen}} @onLoad={{this.setOverlayContext}} @position="right" @noBackdrop={{true}} @fullHeight={{true}} @width={{or this.width @width "400px"}}>
- <Overlay::Header @title={{"Select widgets"}} @hideStatusDot={{true}} @titleWrapperClass="leading-5">
+ <Overlay::Header @title={{t "component.dashboard-widget-panel.select-widgets"}} @hideStatusDot={{true}} @titleWrapperClass="leading-5">
<div class="flex flex-1 justify-end">
- <Button @type="default" @icon="times" @helpText={{"Close and Save"}} @onClick={{this.onPressClose}} />
+ <Button @type="default" @icon="times" @helpText={{t "component.dashboard-widget-panel.close-and-save"}} @onClick={{this.onPressClose}} />
</div>
</Overlay::Header>
- <Overlay::Body @wrapperClass="new-service-rate-overlay-body px-4 space-y-4 pt-4" @increaseInnerBodyHeightBy={{1000}}>
+ <Overlay::Body @wrapperClass="new-service-rate-overlay-body px-4 space-y-4 pt-4">
<div class="grid grid-cols-1 gap-4 text-xs dark:text-gray-100">
{{#each this.availableWidgets as |widget|}}
<div
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 flex-row items-center leading-6 mb-2">
+ <div class="flex flex-row items-center leading-6 mb-2.5">
<div class="w-8 flex items-center justify-start">
- <FaIcon @icon={{widget.icon}} class="text-2xl text-gray-600 dark:text-gray-300" />
+ <FaIcon @icon={{widget.icon}} class="text-lg 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
+ {{t "component.dashboard-widget-panel.widget-name" widgetName=widget.name}}
</p>
</div>
<div>
@@ -27,6 +26,6 @@
</div>
{{/each}}
</div>
-
+ <Spacer @height="300px" />
</Overlay::Body>
</Overlay>
\ No newline at end of file
diff --git a/console/app/components/dashboard/widget-panel.js b/console/app/components/dashboard/widget-panel.js
index 2a5b68a7..1ba5830b 100644
--- a/console/app/components/dashboard/widget-panel.js
+++ b/console/app/components/dashboard/widget-panel.js
@@ -18,8 +18,6 @@ export default class DashboardWidgetPanelComponent extends Component {
this.availableWidgets = this.universe.getDashboardWidgets();
this.dashboard = dashboard;
-
- console.log(this.availableWidgets, this.dashboard);
}
/**
@@ -37,7 +35,11 @@ export default class DashboardWidgetPanelComponent extends Component {
}
@action addWidgetToDashboard(widget) {
- console.log('Adding widget to dashboard: ', widget);
+ // If widget is a component definition/class
+ if (typeof widget.component === 'function') {
+ widget.component = widget.component.name;
+ }
+
this.args.dashboard.addWidget(widget).catch((error) => {
this.notifications.serverError(error);
});
@@ -50,7 +52,9 @@ export default class DashboardWidgetPanelComponent extends Component {
*/
@action onPressClose() {
this.isOpen = false;
- console.log(this.args);
- this.args.onClose();
+
+ if (typeof this.args.onClose === 'function') {
+ this.args.onClose();
+ }
}
}
diff --git a/console/app/controllers/console/admin/organizations/index.js b/console/app/controllers/console/admin/organizations/index.js
index 58567544..704885af 100644
--- a/console/app/controllers/console/admin/organizations/index.js
+++ b/console/app/controllers/console/admin/organizations/index.js
@@ -2,6 +2,7 @@ import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
+import { task } from 'ember-concurrency';
/**
* Controller for managing organizations in the admin console.
@@ -55,11 +56,11 @@ export default class ConsoleAdminOrganizationsController extends Controller {
@tracked limit = 20;
/**
- * Array to store the fetched companies.
+ * The filterable param `sort`
*
- * @var {Array}
+ * @var {String|Array}
*/
- @tracked companies = [];
+ @tracked sort = '-created_at';
/**
* The filterable param `name`
@@ -75,56 +76,58 @@ export default class ConsoleAdminOrganizationsController extends Controller {
*/
@tracked country;
+ /**
+ * Array to store the fetched companies.
+ *
+ * @var {Array}
+ */
+ @tracked companies = [];
+
/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
- queryParams = ['name', 'page', 'limit'];
+ queryParams = ['name', 'page', 'limit', 'sort'];
/**
- * Constructor for ConsoleAdminOrganizationsController.
- * Invokes the getAllCompanies method to fetch all companies.
+ * Columns for organization
*
- * @constructor
- * @method constructor
+ * @memberof ConsoleAdminOrganizationsController
*/
- constructor() {
- super(...arguments);
- this.getAllCompanies();
- this.columns = [
- {
- label: this.intl.t('common.name'),
- valuePath: 'name',
- resizable: true,
- sortable: true,
- filterable: true,
- filterComponent: 'filter/string',
- },
- {
- label: this.intl.t('common.country'),
- valuePath: 'country_name',
- resizable: true,
- sortable: true,
- filterable: true,
- filterComponent: 'filter/string',
- },
- {
- label: this.intl.t('common.created-at'),
- valuePath: 'createdAt',
- },
- ];
- }
+ columns = [
+ {
+ label: this.intl.t('common.name'),
+ valuePath: 'name',
+ resizable: true,
+ sortable: true,
+ filterable: true,
+ filterComponent: 'filter/string',
+ },
+ {
+ label: this.intl.t('console.admin.organizations.index.phone-column'),
+ valuePath: 'phone',
+ resizable: true,
+ sortable: true,
+ filterable: true,
+ filterComponent: 'filter/string',
+ },
+ {
+ label: this.intl.t('common.created-at'),
+ valuePath: 'createdAt',
+ },
+ ];
/**
- * Fetches all companies from the store and sets the 'companies' property.
+ * `search` is a task that performs a search query on the 'company' model in the store.
*
- * @method getAllCompanies
+ * @method search
+ * @param {string} query - The search query.
+ * @returns {Promise} A promise that resolves with the search results.
+ * @public
*/
- getAllCompanies() {
- this.store.findAll('company', { page: this.page, limit: this.limit }).then((companies) => {
- this.set('companies', companies);
- });
+ @task({ restartable: true }) *search(event) {
+ this.companies = yield this.store.query('company', { query: event.target.value });
}
/**
@@ -134,6 +137,6 @@ export default class ConsoleAdminOrganizationsController extends Controller {
* @param {Object} company - The selected company.
*/
@action goToCompany(company) {
- this.router.transitionTo('console.admin.organizations.users', company.id);
+ this.router.transitionTo('console.admin.organizations.index.users', company.public_id);
}
}
diff --git a/console/app/controllers/console/admin/organizations/index/users.js b/console/app/controllers/console/admin/organizations/index/users.js
new file mode 100644
index 00000000..b82a199e
--- /dev/null
+++ b/console/app/controllers/console/admin/organizations/index/users.js
@@ -0,0 +1,132 @@
+import Controller from '@ember/controller';
+import { tracked } from '@glimmer/tracking';
+import { inject as service } from '@ember/service';
+import { action } from '@ember/object';
+import { task } from 'ember-concurrency';
+
+export default class ConsoleAdminOrganizationsIndexUsersController extends Controller {
+ /**
+ * Inject the `filters` service
+ *
+ * @var {Service}
+ */
+ @service filters;
+
+ /**
+ * Inject the `intl` service
+ *
+ * @var {Service}
+ */
+ @service intl;
+
+ /**
+ * Inject the `router` service
+ *
+ * @var {Service}
+ */
+ @service router;
+
+ /**
+ * The current page of data being viewed
+ *
+ * @var {Integer}
+ */
+ @tracked nestedPage = 1;
+
+ /**
+ * The maximum number of items to show per page
+ *
+ * @var {Integer}
+ */
+ @tracked nestedLimit = 20;
+
+ /**
+ * The filterable param `sort`
+ *
+ * @var {Array|String}
+ */
+ @tracked nestedSort = '-created_at';
+
+ /**
+ * The filterable param `sort`
+ *
+ * @var {String}
+ */
+ @tracked nestedQuery;
+
+ /**
+ * The company loaded.
+ *
+ * @memberof ConsoleAdminOrganizationsIndexUsersController
+ */
+ @tracked company;
+
+ /**
+ * Queryable parameters for this controller's model
+ *
+ * @var {Array}
+ */
+ queryParams = ['nestedPage', 'nestedLimit', 'nestedSort', 'nestedQuery'];
+
+ /**
+ * Columns to render to the table.
+ *
+ * @memberof ConsoleAdminOrganizationsIndexUsersController
+ */
+ columns = [
+ {
+ label: this.intl.t('common.name'),
+ valuePath: 'name',
+ },
+ {
+ label: this.intl.t('common.phone-number'),
+ valuePath: 'phone',
+ },
+ {
+ label: this.intl.t('common.email'),
+ valuePath: 'email',
+ },
+ {
+ label: this.intl.t('common.status'),
+ valuePath: 'status',
+ cellComponent: 'table/cell/status',
+ },
+ ];
+
+ /**
+ * Set the overlay component context object.
+ *
+ * @param {Object} contextApi
+ * @memberof ConsoleAdminOrganizationsIndexUsersController
+ */
+ @action setOverlayContext(contextApi) {
+ this.contextApi = contextApi;
+ }
+
+ /**
+ * Handle closing the overlay.
+ *
+ * @return {Promise<Transition>}
+ * @memberof ConsoleAdminOrganizationsIndexUsersController
+ */
+ @action onPressClose() {
+ if (this.contextApi && typeof this.contextApi.close === 'function') {
+ this.contextApi.close();
+ }
+
+ return this.router.transitionTo('console.admin.organizations.index');
+ }
+
+ /**
+ * `search` is a task that performs a search query on the 'company' model in the store.
+ *
+ * @method search
+ * @param {string} query - The search query.
+ * @returns {Promise} A promise that resolves with the search results.
+ * @public
+ */
+ @task({ restartable: true }) *search(event) {
+ this.nestedQuery = event.target.value;
+ // this.companies = yield this.fetch.get(`companies/${this.company.public_id}/users`, { query: event.target.value });
+ }
+}
diff --git a/console/app/controllers/console/admin/organizations/users.js b/console/app/controllers/console/admin/organizations/users.js
deleted file mode 100644
index 6b74c23d..00000000
--- a/console/app/controllers/console/admin/organizations/users.js
+++ /dev/null
@@ -1,97 +0,0 @@
-import Controller from '@ember/controller';
-import { inject as service } from '@ember/service';
-import { tracked } from '@glimmer/tracking';
-
-export default class ConsoleAdminOrganizationUsersController extends Controller {
- /**
- * Inject the `filters` service
- *
- * @var {Service}
- */
- @service filters;
-
- /**
- * Inject the `intl` service
- *
- * @var {Service}
- */
- @service intl;
-
- /**
- * The current page of data being viewed
- *
- * @var {Integer}
- */
- @tracked page = 1;
-
- /**
- * The maximum number of items to show per page
- *
- * @var {Integer}
- */
- @tracked limit = 20;
-
- /**
- * The filterable param `name`
- *
- * @var {String}
- */
- @tracked name;
-
- /**
- * The filterable param `email`
- *
- * @var {String}
- */
- @tracked email;
-
- /**
- * The filterable param `phone`
- *
- * @var {String}
- */
- @tracked phone;
-
- /**
- * The filterable param `email`
- *
- * @var {Array|String}
- */
- @tracked type;
-
- /**
- * The filterable param `sort`
- *
- * @var {Array|String}
- */
- @tracked sort;
-
- /**
- * Queryable parameters for this controller's model
- *
- * @var {Array}
- */
- queryParams = ['page', 'limit', 'sort', 'query', 'name', 'email', 'phone', 'status'];
-
- constructor() {
- super(...arguments);
- this.columns = [
- {
- label: this.intl.t('common.name'),
- valuePath: 'name',
- },
- {
- label: this.intl.t('common.phone-number'),
- valuePath: 'phone',
- },
- {
- label: this.intl.t('common.email'),
- valuePath: 'email',
- },
- {
- label: this.intl.t('common.status'),
- valuePath: 'status',
- },
- ];
- }
-}
diff --git a/console/app/models/dashboard-widget.js b/console/app/models/dashboard-widget.js
index 6f02552a..eb0f23e6 100644
--- a/console/app/models/dashboard-widget.js
+++ b/console/app/models/dashboard-widget.js
@@ -5,7 +5,6 @@ import { getOwner } from '@ember/application';
export default class DashboardWidgetModel extends Model {
/** @ids */
- @attr('string') uuid;
@attr('string') dashboard_uuid;
/** @relationships */
@@ -46,9 +45,15 @@ export default class DashboardWidgetModel extends Model {
return format(this.created_at, 'PP');
}
- updatePosition() {
- this.save().then((response) => {
- console.log('Widget updated successfully.', response);
- });
+ /**
+ * Update the dashboard widget properties on the server
+ *
+ * @param {Object} [properties={}]
+ * @return {Promise<DashboardWidgetModel>}
+ * @memberof DashboardWidgetModel
+ */
+ updateProperties(properties = {}) {
+ this.setProperties(properties);
+ return this.save();
}
}
diff --git a/console/app/models/dashboard.js b/console/app/models/dashboard.js
index 2defac09..2a20e9b8 100644
--- a/console/app/models/dashboard.js
+++ b/console/app/models/dashboard.js
@@ -5,7 +5,8 @@ import { getOwner } from '@ember/application';
export default class DashboardModel extends Model {
/** @ids */
- @attr('string') owner_uuid;
+ @attr('string') company_uuid;
+ @attr('string') user_uuid;
/** @relationships */
@hasMany('dashboard-widget', { async: false }) widgets;
@@ -47,11 +48,8 @@ export default class DashboardModel extends Model {
addWidget(widget) {
const owner = getOwner(this);
const store = owner.lookup('service:store');
+ const widgetRecord = store.createRecord('dashboard-widget', { ...widget, dashboard: this });
- const widgetRecord = store.createRecord('dashboard-widget', widget);
-
- widgetRecord.dashboard = this;
- console.log(widgetRecord);
return new Promise((resolve, reject) => {
widgetRecord
.save()
@@ -69,7 +67,6 @@ export default class DashboardModel extends Model {
removeWidget(widget) {
const owner = getOwner(this);
const store = owner.lookup('service:store');
-
const widgetRecord = store.peekRecord('dashboard-widget', widget);
if (widgetRecord) {
diff --git a/console/app/routes/console/admin/organizations/index.js b/console/app/routes/console/admin/organizations/index.js
index da1a9005..87c73d01 100644
--- a/console/app/routes/console/admin/organizations/index.js
+++ b/console/app/routes/console/admin/organizations/index.js
@@ -1,21 +1,7 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
-import { task } from 'ember-concurrency';
-/**
- * `ConsoleAdminOrganizationsRoute` is a Route that handles the logic for the admin organizations console.
- *
- * @class ConsoleAdminOrganizationsRoute
- * @extends Route
- * @public
- */
export default class ConsoleAdminOrganizationsRoute extends Route {
- /**
- * `store` is a service that provides methods for querying and manipulating the application's data store.
- *
- * @service store
- * @public
- */
@service store;
queryParams = {
@@ -27,31 +13,12 @@ export default class ConsoleAdminOrganizationsRoute extends Route {
country: { refreshModel: true },
};
- /**
- * `search` is a task that performs a search query on the 'company' model in the store.
- *
- * @method search
- * @param {string} query - The search query.
- * @returns {Promise} A promise that resolves with the search results.
- * @public
- */
- search = task(function* (query) {
- try {
- return yield this.store.query('company', { query });
- } catch (error) {
- console.error('An error occurred during the search:', error);
- }
- }).restartable();
-
- /**
- * `model` is a method that queries the 'company' model in the store with the provided parameters.
- *
- * @method model
- * @param {Object} params - The query parameters.
- * @returns {Promise} A promise that resolves with the query results.
- * @public
- */
model(params) {
return this.store.query('company', params);
}
+
+ setupController(controller, model) {
+ super.setupController(controller, model);
+ controller.companies = model;
+ }
}
diff --git a/console/app/routes/console/admin/organizations/index/users.js b/console/app/routes/console/admin/organizations/index/users.js
new file mode 100644
index 00000000..f056b38d
--- /dev/null
+++ b/console/app/routes/console/admin/organizations/index/users.js
@@ -0,0 +1,50 @@
+import Route from '@ember/routing/route';
+import ArrayProxy from '@ember/array/proxy';
+import { inject as service } from '@ember/service';
+import { isArray } from '@ember/array';
+
+export default class ConsoleAdminOrganizationsIndexUsersRoute extends Route {
+ @service fetch;
+ @service store;
+
+ queryParams = {
+ nestedPage: { refreshModel: true },
+ nestedLimit: { refreshModel: true },
+ nestedSort: { refreshModel: true },
+ nestedQuery: { refreshModel: true },
+ };
+
+ model(params) {
+ this.companyId = params.public_id;
+
+ return this.fetch
+ .get(`companies/${this.companyId}/users`, {
+ page: params.nestedPage,
+ limit: params.nestedLimit,
+ sort: params.nestedSort,
+ query: params.nestedQuery,
+ paginate: 1,
+ })
+ .then(this.transformResults.bind(this));
+ }
+
+ transformResults({ users, meta }) {
+ if (isArray(users)) {
+ users = users.map((user) => this.fetch.jsonToModel(user, 'user'));
+ }
+
+ return ArrayProxy.create({ content: users, meta });
+ }
+
+ setupController(controller) {
+ super.setupController(...arguments);
+ controller.company = this.getCompany();
+ }
+
+ getCompany() {
+ const companies = this.store.peekAll('company');
+ return companies.find((company) => {
+ return this.companyId === company.public_id || this.companyId === company.id;
+ });
+ }
+}
diff --git a/console/app/routes/console/admin/organizations/users.js b/console/app/routes/console/admin/organizations/users.js
deleted file mode 100644
index 1b979cfc..00000000
--- a/console/app/routes/console/admin/organizations/users.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import Route from '@ember/routing/route';
-import { inject as service } from '@ember/service';
-
-/**
- * Route for displaying and managing users associated with a specific organization in the admin console.
- *
- * @class ConsoleAdminOrganizationUsersRoute
- * @extends Route
- */
-export default class ConsoleAdminOrganizationUsersRoute extends Route {
- /**
- * Ember Data service for interacting with the store.
- *
- * @property {Service} store
- * @type {Object}
- */
- @service fetch;
-
- queryParams = {
- page: { refreshModel: true },
- limit: { refreshModel: true },
- sort: { refreshModel: true },
- query: { refreshModel: true },
- status: { refreshModel: true },
- name: { refreshModel: true },
- phone: { refreshModel: true },
- email: { refreshModel: true },
- createdAt: { refreshModel: true },
- updatedAt: { refreshModel: true },
- };
-
- /**
- * Fetches users based on the company ID.
- *
- * @param {Object} params - The parameters passed to the model hook.
- * @param {string} params.company_id - The ID of the company.
- * @returns {Object} An object containing the users associated with the company.
- */
- async model(params) {
- const id = params.company_id;
- const users = await this.fetch.get(`companies/${id}/users`);
- return users.toArray();
- }
-}
diff --git a/console/app/serializers/comment.js b/console/app/serializers/comment.js
index 691b2b66..a7cfe26c 100644
--- a/console/app/serializers/comment.js
+++ b/console/app/serializers/comment.js
@@ -18,10 +18,10 @@ export default class CommentSerializer extends ApplicationSerializer.extend(Embe
serializeAttribute(snapshot, json, key, attributes) {
if (key === 'editable') {
return;
- }
+ }
super.serializeAttribute(...arguments);
- }
+ }
serializeHasMany(snapshot, json, relationship) {
let key = relationship.key;
diff --git a/console/app/services/dashboard.js b/console/app/services/dashboard.js
index 20d5ebaa..23dfc07a 100644
--- a/console/app/services/dashboard.js
+++ b/console/app/services/dashboard.js
@@ -1,121 +1,208 @@
-// app/services/dashboard.js
import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency-decorators';
import { action } from '@ember/object';
-
+import { isArray } from '@ember/array';
+
+/**
+ * Service for managing dashboards, including loading, creating, and deleting dashboards, as well as managing the current dashboard and widget states.
+ * Utilizes Ember services such as `store`, `fetch`, `notifications`, and `universe` for data management and user interaction.
+ *
+ * @extends Service
+ */
export default class DashboardService extends Service {
+ /**
+ * Ember Data store service for managing model data.
+ * @type {Service}
+ */
@service store;
+
+ /**
+ * Fetch service for making network requests.
+ * @type {Service}
+ */
@service fetch;
+
+ /**
+ * Notifications service for displaying user notifications.
+ * @type {Service}
+ */
@service notifications;
+
+ /**
+ * Universe service for accessing global application state or utility methods.
+ * @type {Service}
+ */
@service universe;
+ /**
+ * Internationalization service.
+ * @type {Service}
+ */
+ @service intl;
+
+ /**
+ * Tracked array of available dashboards.
+ * @type {Array}
+ */
@tracked dashboards = [];
+
+ /**
+ * Tracked property representing the currently selected dashboard.
+ * @type {Object}
+ */
@tracked currentDashboard;
+
+ /**
+ * Tracked boolean indicating if the dashboard is in editing mode.
+ * @type {boolean}
+ */
@tracked isEditingDashboard = false;
+
+ /**
+ * Tracked boolean indicating if a widget is being added.
+ * @type {boolean}
+ */
@tracked isAddingWidget = false;
+ /**
+ * Task for loading dashboards from the store. It sets the current dashboard and checks if adding widget is necessary.
+ */
@task *loadDashboards() {
- try {
- const dashboards = yield this.store.findAll('dashboard');
+ const dashboards = yield this.store.findAll('dashboard');
+
+ if (isArray(dashboards)) {
this.dashboards = dashboards.toArray();
+ this.dashboards.unshiftObject(this._createDefaultDashboard());
- if (dashboards.some((dashboard) => dashboard.owner_uuid !== 'system')) {
- this.dashboards.unshiftObject(this._createDefaultDashboard());
- }
// Set the current dashboard
this.currentDashboard = this.dashboards.find((dashboard) => dashboard.is_default) || this.dashboards[0];
- if (this.currentDashboard?.widgets?.length === 0) {
+ if (this.currentDashboard && this.currentDashboard.widgets.length === 0) {
this.onAddingWidget(true);
}
- } catch (error) {
- console.error('Error loading dashboards:', error);
}
}
+ /**
+ * Task for selecting a dashboard. Handles dashboard switching and updates the current dashboard.
+ * @param {Object} dashboard - The dashboard object to select.
+ */
@task *selectDashboard(dashboard) {
- try {
- if (dashboard.owner_uuid === 'system') {
- this.currentDashboard = dashboard;
- return;
- }
- const response = yield this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id });
- this.store.pushPayload(response);
- const selectedDashboardId = response.uuid;
- this.currentDashboard = this.store.peekRecord('dashboard', selectedDashboardId);
+ if (dashboard.user_uuid === 'system') {
+ this.currentDashboard = dashboard;
+ yield this.fetch.post('dashboards/reset-default');
+ return;
+ }
- if (this.currentDashboard?.widgets?.length === 0) {
+ const currentDashboard = yield this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id }, { normalizeToEmberData: true }).catch((error) => {
+ this.notifications.serverError(error);
+ });
+
+ if (currentDashboard) {
+ this.currentDashboard = currentDashboard;
+
+ if (this.currentDashboard && this.currentDashboard.widgets.length === 0) {
this.onChangeEdit(true);
}
- } catch (error) {
- this.notifications.error(`Error switching dashboard: ${error}`);
}
}
+ /**
+ * Task for creating a new dashboard. It handles dashboard creation, success notification, and dashboard selection.
+ * @param {string} name - Name of the new dashboard.
+ * @param {Object} [options={}] - Optional configuration options.
+ */
@task *createDashboard(name, options = {}) {
try {
- const newDashboard = this.store.createRecord('dashboard', { name, is_default: true });
- const response = yield newDashboard.save();
-
- if (typeof options.successNotification === 'function') {
- this.notifications.success(options.successNotification(response));
- } else {
- this.notifications.success(options.successNotification || `${response.name} created.`);
- }
-
- this.selectDashboard.perform(response);
- this.isEditingDashboard = true;
- } catch (error) {
- this.notifications.serverError(error);
- }
+ const dashboardRecord = this.store.createRecord('dashboard', { name, is_default: true });
+ const dashboard = yield dashboardRecord.save().catch((error) => {
+ this.notifications.serverError(error);
+ });
+ } catch (error) {}
+
+ this.notifications.success(this.intl.t('services.dashboard-service.create-dashboard-success-notification', { dashboardName: dashboard.name }));
+ this.selectDashboard.perform(dashboard);
+ this.dashboards.pushObject(dashboard);
+ this.isEditingDashboard = true;
}
+ /**
+ * Task for deleting a dashboard. Handles dashboard deletion and success notification.
+ * @param {Object} dashboard - The dashboard object to delete.
+ * @param {Object} [options={}] - Optional configuration options.
+ */
@task *deleteDashboard(dashboard, options = {}) {
try {
- yield dashboard.destroyRecord();
- this.notifications.success(options.successNotification || `${dashboard.name} has been deleted.`);
- this.loadDashboards.perform();
- } catch (error) {
- this.notifications.serverError(error);
- if (options.onError) {
- options.onError(error, dashboard);
- }
- } finally {
- if (options.callback) {
- options.callback(this.currentDashboard);
- }
+ yield dashboard.destroyRecord().catch((error) => {
+ this.notification.serverError(error);
+
+ if (typeof options.onError === 'function') {
+ options.onError(error, dashboard);
+ }
+ });
+ } catch (error) {}
+
+ this.notifications.success(this.intl.t('services.dashboard-service.delete-dashboard-success-notification', { dashboardName: dashboard.name }));
+ this.loadDashboards.perform();
+
+ if (typeof options.callback === 'function') {
+ options.callback(this.currentDashboard);
}
}
+ /**
+ * Task for setting the current dashboard.
+ * @param {Object} dashboard - The dashboard object to set as current.
+ */
@task *setCurrentDashboard(dashboard) {
try {
- const response = yield this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id });
- this.currentDashboard = response;
- } catch (error) {
- this.notifications.error(`Error setting current dashboard: ${error}`);
- }
+ const currentDashboard = yield this.fetch.post('dashboards/switch', { dashboard_uuid: dashboard.id }, { normalizeToEmberData: true }).catch((error) => {
+ this.notifications.serverError(error);
+ });
+
+ this.currentDashboard = currentDashboard;
+ } catch (error) {}
}
+ /**
+ * Action to toggle dashboard editing state.
+ * @param {boolean} [state=true] - State to set for editing.
+ */
@action onChangeEdit(state = true) {
this.isEditingDashboard = state;
}
+ /**
+ * Action to toggle the state of adding a widget.
+ * @param {boolean} [state=true] - State to set for adding a widget.
+ */
@action onAddingWidget(state = true) {
this.isAddingWidget = state;
}
+ /**
+ * Creates a default dashboard with predefined widgets.
+ * @private
+ * @returns {Object} The default dashboard object.
+ */
_createDefaultDashboard() {
const defaultDashboard = this.store.createRecord('dashboard', {
+ id: 'system',
name: 'Default Dashboard',
is_default: false,
- owner_uuid: 'system',
+ user_uuid: 'system',
widgets: this._createDefaultDashboardWidgets(),
});
return defaultDashboard;
}
+ /**
+ * Creates default widgets for the default dashboard.
+ * @private
+ * @returns {Array} An array of default dashboard widgets.
+ */
_createDefaultDashboardWidgets() {
const widgets = this.universe.getDefaultDashboardWidgets().map((defaultWidget) => {
return this.store.createRecord('dashboard-widget', defaultWidget);
diff --git a/console/app/styles/console.css b/console/app/styles/console.css
index 4d152e0b..e318d92b 100644
--- a/console/app/styles/console.css
+++ b/console/app/styles/console.css
@@ -23,3 +23,29 @@ body[data-theme='dark'] .two-fa-enforcement-alert button#two-fa-setup-button.btn
padding-left: 1rem;
padding-top: 0.2rem;
}
+
+/** move to ember-ui later */
+.fleetbase-pagination-meta-info-wrapper.within-layout-section-header {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ justify-content: right;
+ flex: 1;
+}
+
+.without-padding {
+ padding-left: 0 !important;
+ padding-right: 0 !important;
+ padding-top: 0 !important;
+ padding-bottom: 0 !important;
+}
+
+.without-padding-y {
+ padding-top: 0 !important;
+ padding-bottom: 0 !important;
+}
+
+.without-padding-x {
+ padding-left: 0 !important;
+ padding-right: 0 !important;
+}
diff --git a/console/app/templates/console/admin/organizations/index.hbs b/console/app/templates/console/admin/organizations/index.hbs
index 27d453e0..ba9dc601 100644
--- a/console/app/templates/console/admin/organizations/index.hbs
+++ b/console/app/templates/console/admin/organizations/index.hbs
@@ -1,3 +1,4 @@
+{{page-title (t "console.admin.organizations.index.title")}}
<Layout::Section::Header @title={{t "console.admin.organizations.index.title"}} @searchQuery={{this.query}} @onSearch={{perform this.search}} />
<Layout::Section::Body>
diff --git a/console/app/templates/console/admin/organizations/index/users.hbs b/console/app/templates/console/admin/organizations/index/users.hbs
new file mode 100644
index 00000000..74287f3e
--- /dev/null
+++ b/console/app/templates/console/admin/organizations/index/users.hbs
@@ -0,0 +1,18 @@
+{{page-title (t "common.users")}}
+<Overlay @isOpen={{@isOpen}} @onLoad={{this.setOverlayContext}} @position="right" @noBackdrop={{true}} @fullHeight={{true}} @width={{or this.width @width "600px"}}>
+ <Overlay::Header @title={{concat this.company.name " - " (t "common.users")}} @hideStatusDot={{true}} @titleWrapperClass="leading-5">
+ <div class="flex flex-1 justify-end">
+ <Button @type="default" @icon="times" @helpText={{t "common.close-and-save"}} @onClick={{this.onPressClose}} />
+ </div>
+ </Overlay::Header>
+
+ <Overlay::Body class="without-padding">
+ <Layout::Section::Header @title={{t "console.admin.organizations.users.title"}} @searchQuery={{this.nestedQuery}} @onSearch={{perform this.search}}>
+ <Pagination @meta={{@model.meta}} @page={{this.nestedPage}} @onPageChange={{fn (mut this.nestedPage)}} @metaInfoClass="hidden" @metaInfoWrapperClass="within-layout-section-header" />
+ </Layout::Section::Header>
+
+ <Layout::Section::Body>
+ <Table @rows={{@model}} @columns={{this.columns}} @selectable={{true}} @canSelectAll={{true}} @onSetup={{fn (mut this.table)}} />
+ </Layout::Section::Body>
+ </Overlay::Body>
+</Overlay>
\ No newline at end of file
diff --git a/console/app/templates/console/admin/organizations/users.hbs b/console/app/templates/console/admin/organizations/users.hbs
deleted file mode 100644
index 3469185e..00000000
--- a/console/app/templates/console/admin/organizations/users.hbs
+++ /dev/null
@@ -1,18 +0,0 @@
-<Layout::Section::Header @title={{t "console.admin.organizations.users.title"}} @searchQuery={{this.query}} @onSearch={{perform this.search}} />
-
-<Layout::Section::Body>
- <Table
- @rows={{@model}}
- @columns={{this.columns}}
- @selectable={{true}}
- @canSelectAll={{true}}
- @onSetup={{fn (mut this.table)}}
- @pagination={{true}}
- @paginationMeta={{@model}}
- @page={{this.page}}
- @onPageChange={{fn (mut this.page)}}
- @tfootVerticalOffset="53"
- @tfootVerticalOffsetElements=".next-view-section-subheader"
- />
-</Layout::Section::Body>
-{{outlet}}
\ No newline at end of file
diff --git a/console/tests/unit/controllers/console/admin/organizations/index/users-test.js b/console/tests/unit/controllers/console/admin/organizations/index/users-test.js
new file mode 100644
index 00000000..14c36738
--- /dev/null
+++ b/console/tests/unit/controllers/console/admin/organizations/index/users-test.js
@@ -0,0 +1,12 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Controller | console/admin/organizations/index/users', function (hooks) {
+ setupTest(hooks);
+
+ // TODO: Replace this with your real tests.
+ test('it exists', function (assert) {
+ let controller = this.owner.lookup('controller:console/admin/organizations/index/users');
+ assert.ok(controller);
+ });
+});
diff --git a/console/tests/unit/routes/console/admin/organizations/index/users-test.js b/console/tests/unit/routes/console/admin/organizations/index/users-test.js
new file mode 100644
index 00000000..dfd4d32f
--- /dev/null
+++ b/console/tests/unit/routes/console/admin/organizations/index/users-test.js
@@ -0,0 +1,11 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Route | console/admin/organizations/index/users', function (hooks) {
+ setupTest(hooks);
+
+ test('it exists', function (assert) {
+ let route = this.owner.lookup('route:console/admin/organizations/index/users');
+ assert.ok(route);
+ });
+});
diff --git a/console/translations/en-us.yaml b/console/translations/en-us.yaml
index d8d1393b..0749a1e4 100644
--- a/console/translations/en-us.yaml
+++ b/console/translations/en-us.yaml
@@ -53,6 +53,8 @@ common:
country: Country
phone-number: Phone
status: Status
+ close-and-save: Close and Save
+ users: Users
component:
file:
dropdown-label: File actions
@@ -85,6 +87,21 @@ component:
comment-reply-placeholder: Input your reply...
comment-input-empty-notification: You cannot publish empty comments...
comment-min-length-notification: Comment must be atleast 2 characters
+ dashboard:
+ select-dashboard: Select Dashboard
+ create-new-dashboard: Create new Dashboard
+ edit-layout: Edit layout
+ add-widgets: Add widgets
+ delete-dashboard: Delete dashboard
+ dashboard-widget-panel:
+ widget-name: >-
+ {widgetName} Widget
+ select-widgets: Select Widgets
+ close-and-save: Close and Save
+services:
+ dashboard-service:
+ create-dashboard-success-notification: New dashboard `{dashboardName}` created succesfully.
+ delete-dashboard-success-notification: Dashboard `{dashboardName}` was deleted.
auth:
verification:
header-title: Account Verification
@@ -190,6 +207,8 @@ console:
organizations:
index:
title: Organizations
+ phone-column: Phone
+ email-column: Email
users:
title: Users
settings: