Skip to content

Modular logistics and supply chain operating system (LSOS)

created Organizations page for admin

TemuulenBM50bfe55583c5
diff --git a/console/app/controllers/console/admin/organization-users.js b/console/app/controllers/console/admin/organization-users.js
deleted file mode 100644
index bad97a35..00000000
--- a/console/app/controllers/console/admin/organization-users.js
+++ /dev/null
@@ -1,18 +0,0 @@
-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/index.js
similarity index 66%
rename from console/app/controllers/console/admin/organizations.js
rename to console/app/controllers/console/admin/organizations/index.js
index cdec7bb3..aafd7a60 100644
--- a/console/app/controllers/console/admin/organizations.js
+++ b/console/app/controllers/console/admin/organizations/index.js
@@ -46,6 +46,27 @@ export default class ConsoleAdminOrganizationsController extends Controller {
*/
@tracked limit = 20;
+ /**
+ * Array to store the fetched companies.
+ *
+ * @var {Array}
+ */
+ @tracked companies = [];
+
+ /**
+ * The filterable param `name`
+ *
+ * @var {String}
+ */
+ @tracked name;
+
+ /**
+ * Queryable parameters for this controller's model
+ *
+ * @var {Array}
+ */
+ queryParams = ['name', 'page', 'limit'];
+
/**
* Constructor for ConsoleAdminOrganizationsController.
* Invokes the getAllCompanies method to fetch all companies.
@@ -56,6 +77,21 @@ export default class ConsoleAdminOrganizationsController extends Controller {
constructor() {
super(...arguments);
this.getAllCompanies();
+ this.columns = [
+ {
+ label: 'Name',
+ valuePath: 'name',
+ },
+ {
+ label: 'Country',
+ valuePath: 'country_name',
+ },
+ {
+ label: 'Created At',
+ valuePath: 'createdAt',
+ },
+
+ ];
}
/**
@@ -64,7 +100,7 @@ export default class ConsoleAdminOrganizationsController extends Controller {
* @method getAllCompanies
*/
getAllCompanies() {
- this.store.findAll('company').then((companies) => {
+ this.store.findAll('company', { page: this.page, limit: this.limit }).then((companies) => {
this.set('companies', companies);
});
}
@@ -76,6 +112,6 @@ export default class ConsoleAdminOrganizationsController extends Controller {
* @param {Object} company - The selected company.
*/
@action goToCompany(company) {
- this.router.transitionTo('console.admin.organization-users', company.id);
+ this.router.transitionTo('console.admin.organizations.users', company.id);
}
}
diff --git a/console/app/controllers/console/admin/organizations/users.js b/console/app/controllers/console/admin/organizations/users.js
new file mode 100644
index 00000000..2e0aae07
--- /dev/null
+++ b/console/app/controllers/console/admin/organizations/users.js
@@ -0,0 +1,89 @@
+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;
+
+ /**
+ * 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: 'Name',
+ valuePath: 'name',
+ },
+ {
+ label: 'Phone',
+ valuePath: 'phone',
+ },
+ {
+ label: 'Email',
+ valuePath: 'email',
+ },
+ {
+ label: 'Status',
+ valuePath: 'status',
+ },
+ ];
+ }
+}
diff --git a/console/app/router.js b/console/app/router.js
index 3ccde312..464fa24c 100644
--- a/console/app/router.js
+++ b/console/app/router.js
@@ -49,8 +49,30 @@ Router.map(function () {
this.route('notifications');
this.route('two-fa-settings');
this.route('virtual', { path: '/:slug/:view' });
- this.route('organizations');
- this.route('organization-users', { path: '/:company_id' });
+ this.route('organizations', function () {
+ this.route('index', { path: '/' });
+ this.route('users', { path: '/:company_id' });
+ });
+ });
+
+ this.mount('@fleetbase/dev-engine', {
+ as: 'developers',
+ path: 'developers',
+ });
+
+ this.mount('@fleetbase/iam-engine', {
+ as: 'iam',
+ path: 'iam',
+ });
+
+ this.mount('@fleetbase/fleetops-engine', {
+ as: 'fleet-ops',
+ path: 'fleet-ops',
+ });
+
+ 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.js
deleted file mode 100644
index 66933df9..00000000
--- a/console/app/routes/console/admin/organization-users.js
+++ /dev/null
@@ -1,35 +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 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/index.js
similarity index 100%
rename from console/app/routes/console/admin/organizations.js
rename to console/app/routes/console/admin/organizations/index.js
diff --git a/console/app/routes/console/admin/organizations/users.js b/console/app/routes/console/admin/organizations/users.js
new file mode 100644
index 00000000..d474d0f5
--- /dev/null
+++ b/console/app/routes/console/admin/organizations/users.js
@@ -0,0 +1,56 @@
+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();
+ }
+
+ /**
+ * Sets up the controller with the company ID.
+ *
+ * @method setupController
+ * @param {Controller} controller - The controller for this route.
+ * @param {Array} model - An array containing the users associated with the company.
+ */
+ setupController(controller, model) {
+ super.setupController(controller, model);
+ controller.companyId = model.company_id;
+ }
+}
diff --git a/console/app/templates/console/admin/organization-users.hbs b/console/app/templates/console/admin/organization-users.hbs
deleted file mode 100644
index 60b8796e..00000000
--- a/console/app/templates/console/admin/organization-users.hbs
+++ /dev/null
@@ -1,27 +0,0 @@
-<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 file
diff --git a/console/app/templates/console/admin/organizations.hbs b/console/app/templates/console/admin/organizations.hbs
deleted file mode 100644
index 82695657..00000000
--- a/console/app/templates/console/admin/organizations.hbs
+++ /dev/null
@@ -1,27 +0,0 @@
-<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 file
diff --git a/console/app/templates/console/admin/organizations/index.hbs b/console/app/templates/console/admin/organizations/index.hbs
new file mode 100644
index 00000000..a57f4fc9
--- /dev/null
+++ b/console/app/templates/console/admin/organizations/index.hbs
@@ -0,0 +1,19 @@
+<Layout::Section::Header @title="Organizations" @searchQuery={{this.query}} @onSearch={{perform this.search}} />
+
+<Layout::Section::Body>
+ <Table
+ @rows={{this.companies}}
+ @columns={{this.columns}}
+ @selectable={{true}}
+ @canSelectAll={{true}}
+ @onSetup={{fn (mut this.table)}}
+ @pagination={{true}}
+ @paginationMeta={{this.companies}}
+ @page={{this.page}}
+ @onPageChange={{fn (mut this.page)}}
+ @tfootVerticalOffset="53"
+ @tfootVerticalOffsetElements=".next-view-section-subheader"
+ @onRowClick={{fn this.goToCompany}}
+ />
+</Layout::Section::Body>
+{{outlet}}
\ 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
new file mode 100644
index 00000000..614881ad
--- /dev/null
+++ b/console/app/templates/console/admin/organizations/users.hbs
@@ -0,0 +1,18 @@
+<Layout::Section::Header @title='Users' @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/router.map.js b/console/router.map.js
index 1f08753b..3ccde312 100644
--- a/console/router.map.js
+++ b/console/router.map.js
@@ -49,6 +49,8 @@ Router.map(function () {
this.route('notifications');
this.route('two-fa-settings');
this.route('virtual', { path: '/:slug/:view' });
+ this.route('organizations');
+ this.route('organization-users', { path: '/:company_id' });
});
});
this.route('install');