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
Refactor user model retrieval
TemuulenBM6cd062575332
diff --git a/console/app/controllers/console/admin/organization-users.js b/console/app/controllers/console/admin/organization-users.jsnew file mode 100644index 00000000..bad97a35--- /dev/null+++ b/console/app/controllers/console/admin/organization-users.js@@ -0,0 +1,18 @@+import Controller from '@ember/controller';+import { tracked } from '@glimmer/tracking';++export default class ConsoleAdminOrganizationUsersController extends Controller {+ /**+ * 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;+}diff --git a/console/app/controllers/console/admin/organizations.js b/console/app/controllers/console/admin/organizations.jsnew file mode 100644index 00000000..cdec7bb3--- /dev/null+++ b/console/app/controllers/console/admin/organizations.js@@ -0,0 +1,81 @@+import Controller from '@ember/controller';+import { inject as service } from '@ember/service';+import { action } from '@ember/object';+import { tracked } from '@glimmer/tracking';++/**+ * Controller for managing organizations in the admin console.+ *+ * @class ConsoleAdminOrganizationsController+ * @extends Controller+ */+export default class ConsoleAdminOrganizationsController extends Controller {+ /**+ * The Ember Data service for interacting with the store.+ *+ * @property {Service} store+ * @type {Object}+ */+ @service store;+ /**+ * The Ember Router service for handling transitions between routes.+ *+ * @property {Service} router+ * @type {Object}+ */+ @service router;++ /**+ * Inject the `filters` service+ *+ * @var {Service}+ */+ @service filters;++ /**+ * 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;++ /**+ * Constructor for ConsoleAdminOrganizationsController.+ * Invokes the getAllCompanies method to fetch all companies.+ *+ * @constructor+ * @method constructor+ */+ constructor() {+ super(...arguments);+ this.getAllCompanies();+ }++ /**+ * Fetches all companies from the store and sets the 'companies' property.+ *+ * @method getAllCompanies+ */+ getAllCompanies() {+ this.store.findAll('company').then((companies) => {+ this.set('companies', companies);+ });+ }++ /**+ * Navigates to the organization-users route for the selected company.+ *+ * @method goToCompany+ * @param {Object} company - The selected company.+ */+ @action goToCompany(company) {+ this.router.transitionTo('console.admin.organization-users', company.id);+ }+}diff --git a/console/app/controllers/console/admin/organizations/index.js b/console/app/controllers/console/admin/organizations/index.jsdeleted file mode 100644index 9d3b7baa..00000000--- a/console/app/controllers/console/admin/organizations/index.js+++ /dev/null@@ -1,3 +0,0 @@-import Controller from '@ember/controller';--export default class ConsoleAdminOrganizationsIndexController extends Controller {}diff --git a/console/app/models/company-user.js b/console/app/models/company-user.jsnew file mode 100644index 00000000..b7e202d1--- /dev/null+++ b/console/app/models/company-user.js@@ -0,0 +1,48 @@+import Model, { attr, belongsTo } from '@ember-data/model';+import { computed } from '@ember/object';+import { format, formatDistanceToNow } from 'date-fns';++export default class CompanyUserModel extends Model {+ /** @ids */+ @attr('string') uuid;+ @attr('string') public_id;+ @attr('string') user_uuid;++ /** @relationships */+ @belongsTo('user') user;+ @belongsTo('company') company;++ /** @attributes */+ @attr('string') status;++ /** @dates */+ @attr('date') deleted_at;+ @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/router.js b/console/app/router.jsindex 20bfa9b5..1606eb7b 100644--- a/console/app/router.js+++ b/console/app/router.js@@ -49,12 +49,28 @@ Router.map(function () {this.route('notifications');this.route('two-fa-settings');this.route('virtual', { path: '/:slug/:view' });- this.route('organizations', function () {});+ this.route('organizations');+ this.route('organization-users', { path: '/:company_id' });+ });++ this.mount('@fleetbase/dev-engine', {+ as: 'developers',+ path: 'developers'});this.mount('@fleetbase/fleetops-engine', {as: 'fleet-ops',- path: 'fleet-ops',+ path: 'fleet-ops'+ });++ this.mount('@fleetbase/iam-engine', {+ as: 'iam',+ path: 'iam'+ });++ this.mount('@fleetbase/storefront-engine', {+ as: 'storefront',+ path: 'storefront'});});this.route('install');diff --git a/console/app/routes/console/admin/organization-users.js b/console/app/routes/console/admin/organization-users.jsnew file mode 100644index 00000000..66933df9--- /dev/null+++ b/console/app/routes/console/admin/organization-users.js@@ -0,0 +1,35 @@+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 store;++ /**+ * 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) {+ console.log('params', params);+ let companyId = params.company_id;+ console.log('companyId', companyId);+ // let users = this.store.findAll('user');+ let users = this.store.query('user', { company_id: companyId });+ console.log('users', users.toArray());+ return { users };+ }+}diff --git a/console/app/routes/console/admin/organizations.js b/console/app/routes/console/admin/organizations.jsnew file mode 100644index 00000000..61ce321c--- /dev/null+++ b/console/app/routes/console/admin/organizations.js@@ -0,0 +1,9 @@+import Route from '@ember/routing/route';++export default class ConsoleAdminOrganizationsRoute extends Route {+ queryParams = {+ page: { refreshModel: true },+ limit: { refreshModel: true },+ name: { refreshModel: true },+ };+}diff --git a/console/app/routes/console/admin/organizations/index.js b/console/app/routes/console/admin/organizations/index.jsdeleted file mode 100644index 8b9afd9a..00000000--- a/console/app/routes/console/admin/organizations/index.js+++ /dev/null@@ -1,10 +0,0 @@-import Route from '@ember/routing/route';-import { inject as service } from '@ember/service';--export default class ConsoleAdminOrganizationsIndexRoute extends Route {- @service store;-- async model() {- return this.store.findAll('company');- }-}diff --git a/console/app/templates/console/admin/organization-users.hbs b/console/app/templates/console/admin/organization-users.hbsnew file mode 100644index 00000000..60b8796e--- /dev/null+++ b/console/app/templates/console/admin/organization-users.hbs@@ -0,0 +1,27 @@+<Layout::Section::Header @title="Organization Users" @searchQuery={{this.query}} @onSearch={{perform this.search}} />++<Layout::Section::Body class="h-full w-full">+ <div class="max-h-[calc(100vh-10rem)] h-full w-full overflow-y-scroll">+ <div class="h-full w-full">+ {{#each @model.users as |user|}}+ <div class="flex flex-row justify-between px-4 py-3 text-black dark:text-white border-b dark:border-gray-800 border-gray-200 text-sm hover:opacity-60">+ <li>+ {{user.name}}+ </li>+ </div>+ {{/each}}+ </div>+ </div>+</Layout::Section::Body>++<div class="fixed bottom-0 w-full">+ <Layout::Section::Footer>+ <Pagination+ @meta={{@model.users}}+ @currentPage={{this.page}}+ @onPageChange={{fn (mut this.page)}}+ @tfootVerticalOffset="53"+ @tfootVerticalOffsetElements=".next-view-section-subheader"+ />+ </Layout::Section::Footer>+</div>\ No newline at end of filediff --git a/console/app/templates/console/admin/organizations.hbs b/console/app/templates/console/admin/organizations.hbsnew file mode 100644index 00000000..82695657--- /dev/null+++ b/console/app/templates/console/admin/organizations.hbs@@ -0,0 +1,27 @@+<Layout::Section::Header @title="Organizations" @searchQuery={{this.query}} @onSearch={{perform this.search}}/>++<Layout::Section::Body class="h-full w-full">+ <div class="max-h-[calc(100vh-10rem)] h-full w-full overflow-y-scroll">+ <div class="h-full w-full">+ {{#each this.companies as |company|}}+ <div class="flex flex-row justify-between px-4 py-3 text-black dark:text-white border-b dark:border-gray-800 border-gray-200 text-sm hover:opacity-60">+ <li {{on "click" (fn this.goToCompany company)}}>+ {{company.name}}+ </li>+ </div>+ {{/each}}+ </div>+ </div>+</Layout::Section::Body>++<div class="fixed bottom-0 w-full">+ <Layout::Section::Footer>+ <Pagination+ @meta={{this.companies}}+ @currentPage={{this.page}}+ @onPageChange={{fn (mut this.page)}}+ @tfootVerticalOffset="53"+ @tfootVerticalOffsetElements=".next-view-section-subheader"+ />+ </Layout::Section::Footer>+</div>\ No newline at end of filediff --git a/console/app/templates/console/admin/organizations/index.hbs b/console/app/templates/console/admin/organizations/index.hbsdeleted file mode 100644index 4c5f1e17..00000000--- a/console/app/templates/console/admin/organizations/index.hbs+++ /dev/null@@ -1,27 +0,0 @@-{{page-title "Organizations"}}--<Layout::Section::Header @title={{"Organizations"}} />--<Layout::Section::Body class="h-full w-full">- <div class="max-h-[calc(100vh-10rem)] h-full w-full overflow-y-scroll">- <div class="h-full w-full">- Hello World- </div>- </div>-</Layout::Section::Body>--<div class="fixed bottom-0 w-full">- <Layout::Section::Footer>- {{#if @model.meta}}- <Pagination- @meta={{@model.meta}}- @currentPage={{this.page}}- @onPageChange={{fn (mut this.page)}}- @tfootVerticalOffset="53"- @tfootVerticalOffsetElements=".next-view-section-subheader"- />- {{else}}- Loading...- {{/if}}- </Layout::Section::Footer>-</div>\ No newline at end of filediff --git a/console/tests/unit/controllers/console/admin/organizations/index-test.js b/console/tests/unit/controllers/console/admin/organization-users-test.jssimilarity index 74%rename from console/tests/unit/controllers/console/admin/organizations/index-test.jsrename to console/tests/unit/controllers/console/admin/organization-users-test.jsindex 9bd5a391..d77222ef 100644--- a/console/tests/unit/controllers/console/admin/organizations/index-test.js+++ b/console/tests/unit/controllers/console/admin/organization-users-test.js@@ -1,12 +1,12 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';-module('Unit | Controller | console/admin/organizations/index', function (hooks) {+module('Unit | Controller | console/admin/organization-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');+ let controller = this.owner.lookup('controller:console/admin/organization-users');assert.ok(controller);});});diff --git a/console/tests/unit/controllers/console/admin/organizations-test.js b/console/tests/unit/controllers/console/admin/organizations-test.jsnew file mode 100644index 00000000..5d4b9a18--- /dev/null+++ b/console/tests/unit/controllers/console/admin/organizations-test.js@@ -0,0 +1,12 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Controller | console/admin/organizations', 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');+ assert.ok(controller);+ });+});diff --git a/console/tests/unit/models/company-user-test.js b/console/tests/unit/models/company-user-test.jsnew file mode 100644index 00000000..bcc5b081--- /dev/null+++ b/console/tests/unit/models/company-user-test.js@@ -0,0 +1,14 @@+import { module, test } from 'qunit';++import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Model | company user', function (hooks) {+ setupTest(hooks);++ // Replace this with your real tests.+ test('it exists', function (assert) {+ let store = this.owner.lookup('service:store');+ let model = store.createRecord('company-user', {});+ assert.ok(model);+ });+});diff --git a/console/tests/unit/routes/console/admin/organizations/index-test.js b/console/tests/unit/routes/console/admin/organization-users-test.jssimilarity index 73%rename from console/tests/unit/routes/console/admin/organizations/index-test.jsrename to console/tests/unit/routes/console/admin/organization-users-test.jsindex f78a08ac..57ca78f5 100644--- a/console/tests/unit/routes/console/admin/organizations/index-test.js+++ b/console/tests/unit/routes/console/admin/organization-users-test.js@@ -1,11 +1,11 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';-module('Unit | Route | console/admin/organizations/index', function (hooks) {+module('Unit | Route | console/admin/organization-users', function (hooks) {setupTest(hooks);test('it exists', function (assert) {- let route = this.owner.lookup('route:console/admin/organizations/index');+ let route = this.owner.lookup('route:console/admin/organization-users');assert.ok(route);});});diff --git a/console/tests/unit/routes/console/admin/organizations-test.js b/console/tests/unit/routes/console/admin/organizations-test.jsnew file mode 100644index 00000000..c70e4306--- /dev/null+++ b/console/tests/unit/routes/console/admin/organizations-test.js@@ -0,0 +1,11 @@+import { module, test } from 'qunit';+import { setupTest } from '@fleetbase/console/tests/helpers';++module('Unit | Route | console/admin/organizations', function (hooks) {+ setupTest(hooks);++ test('it exists', function (assert) {+ let route = this.owner.lookup('route:console/admin/organizations');+ assert.ok(route);+ });+});