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
Patches and improved styling for notification page
Ronald A. Richardson91904c383625
diff --git a/console/app/controllers/console/notifications.js b/console/app/controllers/console/notifications.jsindex d0f55d16..bf75e00f 100644--- a/console/app/controllers/console/notifications.js+++ b/console/app/controllers/console/notifications.js@@ -7,7 +7,6 @@ import { inject as service } from '@ember/service';* Controller for managing notifications.*/export default class NotificationsController extends Controller {- // Inject the store service to fetch notifications@service socket;@service store;@service fetch;@@ -43,8 +42,24 @@ export default class NotificationsController extends Controller {*/@tracked sort = '-created_at';+ /**+ * The selected notifications.+ *+ * @tracked+ * @var {Array}+ * @memberof NotificationsController+ */@tracked selected = [];+ constructor() {+ super(...arguments);++ // listen for received notifications+ this.universe.on('notification.received', () => {+ this.router.refresh();+ });+ }+/*** Action to select or deselect a notification.*@@ -82,13 +97,15 @@ export default class NotificationsController extends Controller {* Action to mark selected notifications as read.*/@action read() {+ const unreadSelectedNotifications = this.selected.filter((notification) => notification.unread);+return this.fetch.put('notifications/mark-as-read', {- notifications: this.selected.map(({ id }) => id),+ notifications: unreadSelectedNotifications.map(({ id }) => id),}).then(() => {- this.notifications.success(`${this.selected.length} notifications marked as read`);- this.universe.trigger('notifications.read', [...this.selected]);+ this.notifications.success(`${unreadSelectedNotifications.length} notifications marked as read`);+ this.universe.trigger('notifications.read', [...unreadSelectedNotifications]);this.selected.clear();return this.router.refresh();@@ -108,64 +125,10 @@ export default class NotificationsController extends Controller {this.selected = this.model.toArray();}}- @tracked selectedNotifications = [];-- @tracked allNotifications = [];-- constructor() {- super(...arguments);- this.fetchAllNotifications();- }-- /**- * Fetch all notifications and store them in the `allNotifications` property.- */- async fetchAllNotifications() {- try {- const allNotifications = await this.store.findAll('notification');- this.allNotifications = allNotifications.toArray();- } catch (error) {- console.error('Failed to fetch all notifications:', error);- }- }-- /**- * Action to select or deselect a notification from the list of all notifications.- *- * @param {Object} notification - The notification to select or deselect.- */- @action onSelectNotification(notification) {- if (this.selectedNotifications.includes(notification)) {- this.selectedNotifications.removeObject(notification);- } else {- this.selectedNotifications.pushObject(notification);- }- }-- /**- * Action to select all notifications from the list of all notifications.- */- @action selectAllNotifications() {- if (this.selectedNotifications.length === this.model.length) {- this.selectNotifications.clear();- } else {- this.selectedNotifications = this.allNotifications.slice();- }- }- /**- * Action to toggle the selection of a notification and mark it as read if it's not already read.- *- * @param {Object} notification - The notification to select or deselect.- */- @action toggleCheckbox(notification) {- if (this.selected.includes(notification)) {- this.selected.removeObject(notification);- } else {- this.selected.pushObject(notification);- if (!notification.read_at) {- this.read();- }- }+ @action markNotificationAsRead(notification) {+ return notification.markAsRead().then(() => {+ this.notifications.info('Notification marked as read.');+ });}}diff --git a/console/app/models/notification.js b/console/app/models/notification.jsindex 174594f4..5b786051 100644--- a/console/app/models/notification.js+++ b/console/app/models/notification.js@@ -1,5 +1,6 @@import Model, { attr } from '@ember-data/model';-import { computed } from '@ember/object';+import { computed, action } from '@ember/object';+import { getOwner } from '@ember/application';import { format, formatDistanceToNow } from 'date-fns';export default class NotificationModel extends Model {@@ -23,4 +24,30 @@ export default class NotificationModel extends Model {@computed('created_at') get createdAt() {return format(this.created_at, 'PPP p');}++ @computed('read_at') get readAt() {+ return format(this.read_at, 'PPP p');+ }++ @computed('read_at') get isRead() {+ return this.read_at instanceof Date;+ }++ @computed('read_at') get read() {+ return this.read_at instanceof Date;+ }++ @computed('read') get unread() {+ return !this.isRead;+ }++ /** @actions */+ markAsRead() {+ if (this.isRead) {+ return;+ }++ this.read_at = new Date();+ return this.save();+ }}diff --git a/console/app/router.js b/console/app/router.jsindex 4e69ecee..4525995e 100644--- a/console/app/router.js+++ b/console/app/router.js@@ -47,22 +47,27 @@ Router.map(function () {this.mount('@fleetbase/dev-engine', {as: 'developers',- path: 'developers',+ path: 'developers'+ });++ this.mount('@fleetbase/fleetops-engine', {+ as: 'fleet-ops',+ path: 'fleet-ops'+ });++ this.mount('@fleetbase/flespi-engine', {+ as: 'flespi',+ path: 'flespi'});this.mount('@fleetbase/iam-engine', {as: 'iam',- path: 'iam',+ path: 'iam'});this.mount('@fleetbase/storefront-engine', {as: 'storefront',- path: 'storefront',- });-- this.mount('@fleetbase/fleetops-engine', {- as: 'fleet-ops',- path: 'fleet-ops',+ path: 'storefront'});});this.route('install');diff --git a/console/app/routes/console/notifications.js b/console/app/routes/console/notifications.jsindex 93c52b38..d1b354b9 100644--- a/console/app/routes/console/notifications.js+++ b/console/app/routes/console/notifications.js@@ -6,8 +6,6 @@ import { inject as service } from '@ember/service';*/export default class ConsoleNotificationsRoute extends Route {@service store;- @service socket;- @service currentUser;queryParams = {page: { refreshModel: true },@@ -26,69 +24,4 @@ export default class ConsoleNotificationsRoute extends Route {model(params = {}) {return this.store.query('notification', params);}-- /**- * Activate the route and set up event listeners for incoming notifications.- */- activate() {- this.listenForNotificationFrom(`user.${this.currentUser.id}`);- this.listenForNotificationFrom(`company.${this.currentUser.companyId}`);- }-- /**- * Listen for notifications from a specified channel.- *- * @param {string} channelId - The ID of the channel to listen for notifications from.- */- async listenForNotificationFrom(channelId) {- console.log('listenForNotificationFrom()', ...arguments);- // setup socket- const socket = this.socket.instance();-- // Listen for socket connection errors- (async () => {- // eslint-disable-next-line no-unused-vars- for await (let event of socket.listener('error')) {- console.log('[socket error]', event);- }- })();-- // Listen for socket connection- (async () => {- // eslint-disable-next-line no-unused-vars- for await (let event of socket.listener('connect')) {- console.log('[socket connected]', event);- }- })();-- // Listen for socket connection aborted- (async () => {- // eslint-disable-next-line no-unused-vars- for await (let event of socket.listener('connectAbort')) {- console.log('[socket connectAborted]', event);- }- })();-- // listen on the specified channel- const channel = socket.subscribe(channelId);-- // listen to the channel for events- await channel.listener('subscribe').once();-- console.log('subscribed to ', channelId);-- // get incoming data and trigger the onReceivedNotification method- (async () => {- for await (let incomingNotification of channel) {- this.onReceivedNotification(incomingNotification);- }- })();- }-- /**- * Method called when a notification is received. It triggers a route refresh.- */- onReceivedNotification() {- this.refresh();- }}diff --git a/console/app/templates/console/notifications.hbs b/console/app/templates/console/notifications.hbsindex f0fbdf1e..d922334e 100644--- a/console/app/templates/console/notifications.hbs+++ b/console/app/templates/console/notifications.hbs@@ -4,32 +4,34 @@<Button @icon="trash" @type="danger" @text="Delete" {{on "click" this.delete}} /></Layout::Section::Header>-<Layout::Section::Body class="h-full w-full px-2">- <div class="max-h-[calc(100vh-10rem)] h-full w-full overflow-y-scroll px-1">- <div class="space-y-1 p-1 h-full w-full">- {{#each @model as |notification|}}- <div- class="p-4 rounded-md text-black dark:text-white text-sm hover:shadow-xl transition-transform transform hover:scale-101- {{if notification.read_at 'bg-white dark:bg-gray-900' 'bg-gray-100 dark:bg-gray-800'}}"- {{on "click" (fn this.toggleCheckbox notification)}}- >- <div class="flex flex-row items-center">- <div class="mr-4">- <Checkbox @value={{includes notification this.selected}} @onToggle={{fn this.selectNotification notification}} class="border-2" />+<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 as |notification index|}}+ <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 {{if notification.read_at 'bg-gray-100 dark:bg-gray-900' 'bg-white dark:bg-gray-800'}}">+ <div class="flex flex-row flex-1">+ <div class="flex items-center justify-center mr-6">+ <Checkbox @value={{includes notification this.selected}} @onToggle={{fn this.selectNotification notification}} /></div>- <div class="flex-1">- <div class="flex flex-row items-center">- <div class="mr-2">- {{#if notification.read_at}}- <FaIcon @icon="envelope-open" class="text-blue-300" />- {{else}}- <FaIcon @icon="envelope" class="text-blue-500" />- {{/if}}+ <a href="javascript:;" class="flex-1 flex flex-row" {{on "click" (fn this.markNotificationAsRead notification)}}>+ <div class="mr-4 flex items-center justify-center">+ {{#if notification.read_at}}+ <FaIcon @icon="envelope-open" class="text-gray-200" />+ {{else}}+ <FaIcon @icon="envelope" class="text-gray-200" />+ {{/if}}+ </div>+ <div class="flex flex-col">+ <div class="flex flex-row space-x-2">+ <h1 class="text-sm font-semibold antialiased leading-4">{{notification.data.subject}}</h1>+ <div class="text-xs antialiased text-gray-900 dark:text-gray-200">- {{notification.data.message}}</div></div>- <h1 class="text-base font-semibold">{{notification.data.subject}}</h1>+ <div class="text-gray-300 text-xs antialiased mt-1">Received: {{notification.createdAgo}}</div></div>- <p class="mt-2">{{notification.data.message}}</p>- <span class="text-gray-300 text-sm">Received: {{notification.createdAgo}}</span>+ </a>+ <div>+ <FaIcon @icon="clock" class="text-gray-400 dark:text-gray-700" @size="sm" />+ <span class="text-gray-400 dark:text-gray-600 text-xs">{{notification.createdAt}}</span></div></div></div>@@ -44,12 +46,6 @@<div class="fixed bottom-0 w-full"><Layout::Section::Footer>- <Pagination- @meta={{@model.meta}}- @currentPage={{this.page}}- @onPageChange={{fn (mut this.page)}}- @tfootVerticalOffset="53"- @tfootVerticalOffsetElements=".next-view-section-subheader"- />+ <Pagination @meta={{@model.meta}} @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