Skip to content

Modular logistics and supply chain operating system (LSOS)

Added notification tray component

Temuulen Bayanmunkh4fb2dec8c3ae
diff --git a/console/app/controllers/console/notifications.js b/console/app/controllers/console/notifications.js
new file mode 100644
index 00000000..4e6ff41f
--- /dev/null
+++ b/console/app/controllers/console/notifications.js
@@ -0,0 +1,10 @@
+import Controller from '@ember/controller';
+
+export default class ConsoleNotificationsController extends Controller {
+ changePage(newPage) {
+ // You can fetch a new page of notifications using the store.query method
+ this.store.query('notification', { page: newPage }).then((newNotifications) => {
+ this.set('model', newNotifications);
+ });
+ }
+}
diff --git a/console/app/models/notification.js b/console/app/models/notification.js
new file mode 100644
index 00000000..6de87091
--- /dev/null
+++ b/console/app/models/notification.js
@@ -0,0 +1,25 @@
+import Model, { attr } from '@ember-data/model';
+import { computed } from '@ember/object';
+import { format, formatDistanceToNow } from 'date-fns';
+
+export default class NotificationModel extends Model {
+ @attr('string') notifiable_id;
+ @attr('string') notifiable_type;
+
+ /** @attributes */
+ @attr('string') type;
+ @attr('raw') data;
+
+ /** @dates */
+ @attr('date') read_at;
+ @attr('date') created_at;
+
+ /** @computed */
+ @computed('created_at') get createdAgo() {
+ return formatDistanceToNow(this.created_at);
+ }
+
+ @computed('created_at') get createdAt() {
+ return format(this.created_at, 'PPP p');
+ }
+}
diff --git a/console/app/router.js b/console/app/router.js
index b193b3e5..aa36b0bc 100644
--- a/console/app/router.js
+++ b/console/app/router.js
@@ -46,23 +46,24 @@ 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'
+ path: 'fleet-ops',
});
this.mount('@fleetbase/iam-engine', {
as: 'iam',
- path: 'iam'
+ path: 'iam',
});
this.mount('@fleetbase/storefront-engine', {
as: 'storefront',
- path: 'storefront'
+ path: 'storefront',
});
+ this.route('notifications');
});
this.route('install');
});
diff --git a/console/app/routes/console/notifications.js b/console/app/routes/console/notifications.js
new file mode 100644
index 00000000..ca866c1c
--- /dev/null
+++ b/console/app/routes/console/notifications.js
@@ -0,0 +1,8 @@
+import Route from '@ember/routing/route';
+
+export default class ConsoleNotificationsRoute extends Route {
+ async model(params) {
+ // Query the notification model using the store service
+ return this.store.query('notification', params);
+ }
+}
diff --git a/console/app/serializers/notification.js b/console/app/serializers/notification.js
new file mode 100644
index 00000000..5f80c052
--- /dev/null
+++ b/console/app/serializers/notification.js
@@ -0,0 +1,5 @@
+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
+
+export default class NotificationSerializer extends ApplicationSerializer {
+ primaryKey = 'id';
+}
diff --git a/console/app/templates/console/notifications.hbs b/console/app/templates/console/notifications.hbs
new file mode 100644
index 00000000..7898e2c1
--- /dev/null
+++ b/console/app/templates/console/notifications.hbs
@@ -0,0 +1,13 @@
+<h1>View All Notifications</h1>
+
+{{#each this.model as |notification|}}
+ {{! Render each notification }}
+ <div class="notification-item">
+ <h3>{{notification.data.subject}}</h3>
+ <p>{{notification.data.message}}</p>
+ <span>Received: {{notification.createdAgo}}</span>
+ </div>
+{{/each}}
+
+{{! Render the pagination component }}
+<Pagination @totalPages={{this.model.meta.totalPages}} @currentPage={{this.model.meta.page}} @onChangePage={{this.changePage}} />
\ No newline at end of file