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
Latest updates for notification tray and page
TemuulenBMa8b2042d853e
diff --git a/console/app/controllers/console/notifications.js b/console/app/controllers/console/notifications.jsindex 30cb2476..d0f55d16 100644--- a/console/app/controllers/console/notifications.js+++ b/console/app/controllers/console/notifications.js@@ -3,6 +3,9 @@ import { tracked } from '@glimmer/tracking';import { action } from '@ember/object';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;@@ -42,6 +45,11 @@ export default class NotificationsController extends Controller {@tracked selected = [];+ /**+ * Action to select or deselect a notification.+ *+ * @param {Object} notification - The notification to select or deselect.+ */@action selectNotification(notification) {if (this.selected.includes(notification)) {this.selected.removeObject(notification);@@ -50,6 +58,9 @@ export default class NotificationsController extends Controller {}}+ /**+ * Action to delete selected notifications.+ */@action delete() {return this.fetch.delete('notifications/bulk-delete', {@@ -67,6 +78,9 @@ export default class NotificationsController extends Controller {});}+ /**+ * Action to mark selected notifications as read.+ */@action read() {return this.fetch.put('notifications/mark-as-read', {@@ -84,10 +98,16 @@ export default class NotificationsController extends Controller {});}+ /**+ * Action to select all notifications.+ */@action selectAll() {- this.selected = this.model.toArray();+ if (this.selected.length === this.model.length) {+ this.selected.clear();+ } else {+ this.selected = this.model.toArray();+ }}-@tracked selectedNotifications = [];@tracked allNotifications = [];@@ -97,6 +117,9 @@ export default class NotificationsController extends Controller {this.fetchAllNotifications();}+ /**+ * Fetch all notifications and store them in the `allNotifications` property.+ */async fetchAllNotifications() {try {const allNotifications = await this.store.findAll('notification');@@ -106,6 +129,11 @@ export default class NotificationsController extends Controller {}}+ /**+ * 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);@@ -114,6 +142,9 @@ export default class NotificationsController extends Controller {}}+ /**+ * Action to select all notifications from the list of all notifications.+ */@action selectAllNotifications() {if (this.selectedNotifications.length === this.model.length) {this.selectNotifications.clear();@@ -122,6 +153,11 @@ export default class NotificationsController extends Controller {}}+ /**+ * 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);diff --git a/console/app/routes/console/notifications.js b/console/app/routes/console/notifications.jsindex 546125b7..93c52b38 100644--- a/console/app/routes/console/notifications.js+++ b/console/app/routes/console/notifications.js@@ -1,6 +1,9 @@import Route from '@ember/routing/route';import { inject as service } from '@ember/service';+/**+ * Route for managing console notifications.+ */export default class ConsoleNotificationsRoute extends Route {@service store;@service socket;@@ -14,26 +17,67 @@ export default class ConsoleNotificationsRoute extends Route {created_at: { refreshModel: true },};+ /**+ * Fetch the model data based on the specified parameters.+ *+ * @param {Object} params - Query parameters for fetching notifications.+ * @returns {Promise} - A promise that resolves with the notification data.+ */model(params = {}) {return this.store.query('notification', params);}- afterModel() {+ /**+ * 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 socketconst socket = this.socket.instance();- // listen on company channel+ // 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 channelconst channel = socket.subscribe(channelId);- // listen to channel for events+ // listen to the channel for eventsawait channel.listener('subscribe').once();- // get incoming data and console out+ console.log('subscribed to ', channelId);++ // get incoming data and trigger the onReceivedNotification method(async () => {for await (let incomingNotification of channel) {this.onReceivedNotification(incomingNotification);@@ -41,6 +85,9 @@ export default class ConsoleNotificationsRoute extends Route {})();}+ /**+ * 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 83682d05..f0fbdf1e 100644--- a/console/app/templates/console/notifications.hbs+++ b/console/app/templates/console/notifications.hbs@@ -4,13 +4,13 @@<Button @icon="trash" @type="danger" @text="Delete" {{on "click" this.delete}} /></Layout::Section::Header>-<Layout::Section::Body class="h-full w-full">+<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|}}<divclass="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-200 dark:bg-gray-800'}}"+ {{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">@@ -21,9 +21,9 @@<div class="flex flex-row items-center"><div class="mr-2">{{#if notification.read_at}}- <FaIcon @icon="envelope-open" class="text-purple-400 dark:text-blue-300" />+ <FaIcon @icon="envelope-open" class="text-blue-300" />{{else}}- <FaIcon @icon="envelope" class="text-purple-600 dark:text-blue-500" />+ <FaIcon @icon="envelope" class="text-blue-500" />{{/if}}</div><h1 class="text-base font-semibold">{{notification.data.subject}}</h1>