Skip to content

Modular logistics and supply chain operating system (LSOS)

fixed up chat models, serializers

Ronald A. Richardsoncc4e28cd0035
diff --git a/console/app/models/chat-attachment.js b/console/app/models/chat-attachment.js
index 2dd664e8..fc4e99a3 100644
--- a/console/app/models/chat-attachment.js
+++ b/console/app/models/chat-attachment.js
@@ -18,5 +18,5 @@ export default class ChatAttachment extends Model {
/** @dates */
@attr('date') created_at;
-
+ @attr('date') updated_at;
}
diff --git a/console/app/models/chat-channel.js b/console/app/models/chat-channel.js
index c3721336..76379141 100644
--- a/console/app/models/chat-channel.js
+++ b/console/app/models/chat-channel.js
@@ -1,6 +1,6 @@
-import Model, { attr, hasMany } from '@ember-data/model';
+import Model, { attr, hasMany, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
-import { format, formatDistanceToNow } from 'date-fns';
+import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class ChatChannel extends Model {
/** @ids */
@@ -13,15 +13,15 @@ export default class ChatChannel extends Model {
@attr('array') meta;
/** @relationships */
- @hasMany('chat-participant', { async: true }) participants;
- @hasMany('chat-message', { async: true }) messages;
+ @hasMany('chat-participant', { async: false }) participants;
+ @hasMany('chat-message', { async: false }) messages;
@hasMany('chat-attachment', { async: true }) attachments;
@hasMany('chat-presence', { async: true }) presences;
+ @belongsTo('chat-message', { async: false }) lastMessage;
/** @dates */
@attr('date') created_at;
@attr('date') updated_at;
- @attr('date') deleted_at;
/** @computed */
@computed('updated_at') get updatedAgo() {
diff --git a/console/app/models/chat-message.js b/console/app/models/chat-message.js
index 75565cf6..9cfb9475 100644
--- a/console/app/models/chat-message.js
+++ b/console/app/models/chat-message.js
@@ -1,16 +1,52 @@
import Model, { attr, belongsTo } from '@ember-data/model';
+import { computed } from '@ember/object';
+import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class ChatMessage extends Model {
- /** @attributes */
- @attr('string') content;
+ /** @ids */
+ @attr('string') chat_channel_uuid;
+ @attr('string') sender_uuid;
- /** @relationships */
- @belongsTo('user', { async: true }) sender;
- @belongsTo('chat-channel', { async: true }) chatChannel;
+ /** @attributes */
+ @attr('string') content;
- /** @dates */
- @attr('date') created_at;
- @attr('date') updated_at;
- @attr('date') deleted_at;
-}
+ /** @relationships */
+ @belongsTo('chat-participant', { async: false }) sender;
+
+ /** @dates */
+ @attr('date') created_at;
+ @attr('date') updated_at;
+
+ /** @computed */
+ @computed('updated_at') get updatedAgo() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.updated_at, { addSuffix: true });
+ }
+
+ @computed('updated_at') get updatedAt() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+ return formatDate(this.updated_at, 'PP HH:mm');
+ }
+
+ @computed('created_at') get createdAgo() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.created_at, { addSuffix: true });
+ }
+
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDate(this.created_at, 'PP HH:mm');
+ }
+}
diff --git a/console/app/models/chat-participant.js b/console/app/models/chat-participant.js
index d4a324ab..b73b4599 100644
--- a/console/app/models/chat-participant.js
+++ b/console/app/models/chat-participant.js
@@ -1,12 +1,57 @@
-import Model, { belongsTo } from '@ember-data/model';
+import Model, { attr, belongsTo } from '@ember-data/model';
+import { computed } from '@ember/object';
+import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class ChatParticipant extends Model {
- /** @relationships */
- @belongsTo('user', { async: true }) user;
- @belongsTo('chat-channel', { async: true }) chatChannel;
-
- /** @dates */
- @attr('date') created_at;
- @attr('date') updated_at;
- @attr('date') deleted_at;
-}
\ No newline at end of file
+ /** @ids */
+ @attr('string') user_uuid;
+ @attr('string') chat_channel_uuid;
+
+ /** @attributes */
+ @attr('string') name;
+ @attr('string') username;
+ @attr('string') phone;
+ @attr('string') email;
+ @attr('string') avatar_url;
+
+ /** @relationships */
+ @belongsTo('user', { async: true }) user;
+ @belongsTo('chat-channel', { async: true }) chatChannel;
+
+ /** @dates */
+ @attr('date') created_at;
+ @attr('date') updated_at;
+
+ /** @computed */
+ @computed('updated_at') get updatedAgo() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.updated_at);
+ }
+
+ @computed('updated_at') get updatedAt() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+
+ return formatDate(this.updated_at, 'PP HH:mm');
+ }
+
+ @computed('created_at') get createdAgo() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.created_at);
+ }
+
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+
+ return formatDate(this.created_at, 'PP HH:mm');
+ }
+}
diff --git a/console/app/models/chat-presence.js b/console/app/models/chat-presence.js
index 54024e67..ff3082d7 100644
--- a/console/app/models/chat-presence.js
+++ b/console/app/models/chat-presence.js
@@ -1,16 +1,16 @@
import Model, { attr, belongsTo } from '@ember-data/model';
export default class ChatPresence extends Model {
- /** @attributes */
- @attr('date') lastSeenAt;
- @attr('boolean') isOnline;
+ /** @ids */
+ /** @attributes */
+ @attr('boolean') is_online;
- /** @relationships */
- @belongsTo('user', { async: true }) user;
- @belongsTo('chat-channel', { async: true }) chatChannel;
+ /** @relationships */
+ @belongsTo('user', { async: true }) user;
+ @belongsTo('chat-channel', { async: true }) chatChannel;
- /** @dates */
- @attr('date') created_at;
- @attr('date') updated_at;
- @attr('date') deleted_at;
-}
\ No newline at end of file
+ /** @dates */
+ @attr('date') created_at;
+ @attr('date') updated_at;
+ @attr('date') last_seen_at;
+}
diff --git a/console/app/models/chat-receipt.js b/console/app/models/chat-receipt.js
index a13a0d91..4cae7c74 100644
--- a/console/app/models/chat-receipt.js
+++ b/console/app/models/chat-receipt.js
@@ -1,15 +1,16 @@
import Model, { attr, belongsTo } from '@ember-data/model';
export default class ChatReceipt extends Model {
- /** @attributes */
- @attr('date') readAt;
+ /** @ids */
+ /** @attributes */
- /** @relationships */
- @belongsTo('user', { async: true }) user;
- @belongsTo('chat-message', { async: true }) chatMessage;
-
- /** @dates */
- @attr('date') created_at;
- @attr('date') updated_at;
- @attr('date') deleted_at;
-}
\ No newline at end of file
+ /** @relationships */
+ @belongsTo('user', { async: true }) user;
+ @belongsTo('chat-message', { async: true }) chatMessage;
+
+ /** @dates */
+ @attr('date') created_at;
+ @attr('date') updated_at;
+ @attr('date') deleted_at;
+ @attr('date') read_at;
+}
diff --git a/console/app/serializers/chat-channel.js b/console/app/serializers/chat-channel.js
new file mode 100644
index 00000000..a3cb2791
--- /dev/null
+++ b/console/app/serializers/chat-channel.js
@@ -0,0 +1,16 @@
+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
+import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
+
+export default class ChatChannelSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
+ /**
+ * Embedded relationship attributes
+ *
+ * @var {Object}
+ */
+ get attrs() {
+ return {
+ participants: { embedded: 'always' },
+ messages: { embedded: 'always' },
+ };
+ }
+}
diff --git a/console/app/serializers/chat-message.js b/console/app/serializers/chat-message.js
new file mode 100644
index 00000000..b52075ef
--- /dev/null
+++ b/console/app/serializers/chat-message.js
@@ -0,0 +1,15 @@
+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
+import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
+
+export default class ChatMessageSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
+ /**
+ * Embedded relationship attributes
+ *
+ * @var {Object}
+ */
+ get attrs() {
+ return {
+ sender: { embedded: 'always' },
+ };
+ }
+}
diff --git a/console/app/serializers/chat-participant.js b/console/app/serializers/chat-participant.js
new file mode 100644
index 00000000..a3bb665d
--- /dev/null
+++ b/console/app/serializers/chat-participant.js
@@ -0,0 +1,3 @@
+import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
+
+export default class ChatParticipantSerializer extends ApplicationSerializer {}
diff --git a/console/app/templates/console.hbs b/console/app/templates/console.hbs
index f1553cf6..8116d9e9 100644
--- a/console/app/templates/console.hbs
+++ b/console/app/templates/console.hbs
@@ -14,10 +14,5 @@
</Layout::Main>
<Layout::MobileNavbar @brand={{@model}} @user={{this.user}} @organizations={{this.organizations}} @menuItems={{this.universe.headerMenuItems}} @extensions={{this.extensions}} @onAction={{this.onAction}} />
</Layout::Container>
-
-{{!-- Add Locale Selector to Header --}}
-<EmberWormhole @to="view-header-actions">
- <LocaleSelector class="mr-0.5" />
-</EmberWormhole>
<ChatContainer />
<ConsoleWormhole />
diff --git a/console/tests/unit/serializers/chat-channel-test.js b/console/tests/unit/serializers/chat-channel-test.js
new file mode 100644
index 00000000..bca3631b
--- /dev/null
+++ b/console/tests/unit/serializers/chat-channel-test.js
@@ -0,0 +1,24 @@
+import { module, test } from 'qunit';
+
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Serializer | chat channel', function (hooks) {
+ setupTest(hooks);
+
+ // Replace this with your real tests.
+ test('it exists', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let serializer = store.serializerFor('chat-channel');
+
+ assert.ok(serializer);
+ });
+
+ test('it serializes records', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let record = store.createRecord('chat-channel', {});
+
+ let serializedRecord = record.serialize();
+
+ assert.ok(serializedRecord);
+ });
+});
diff --git a/console/tests/unit/serializers/chat-message-test.js b/console/tests/unit/serializers/chat-message-test.js
new file mode 100644
index 00000000..acddf7cc
--- /dev/null
+++ b/console/tests/unit/serializers/chat-message-test.js
@@ -0,0 +1,24 @@
+import { module, test } from 'qunit';
+
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Serializer | chat message', function (hooks) {
+ setupTest(hooks);
+
+ // Replace this with your real tests.
+ test('it exists', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let serializer = store.serializerFor('chat-message');
+
+ assert.ok(serializer);
+ });
+
+ test('it serializes records', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let record = store.createRecord('chat-message', {});
+
+ let serializedRecord = record.serialize();
+
+ assert.ok(serializedRecord);
+ });
+});
diff --git a/console/tests/unit/serializers/chat-participant-test.js b/console/tests/unit/serializers/chat-participant-test.js
new file mode 100644
index 00000000..acce6dd3
--- /dev/null
+++ b/console/tests/unit/serializers/chat-participant-test.js
@@ -0,0 +1,24 @@
+import { module, test } from 'qunit';
+
+import { setupTest } from '@fleetbase/console/tests/helpers';
+
+module('Unit | Serializer | chat participant', function (hooks) {
+ setupTest(hooks);
+
+ // Replace this with your real tests.
+ test('it exists', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let serializer = store.serializerFor('chat-participant');
+
+ assert.ok(serializer);
+ });
+
+ test('it serializes records', function (assert) {
+ let store = this.owner.lookup('service:store');
+ let record = store.createRecord('chat-participant', {});
+
+ let serializedRecord = record.serialize();
+
+ assert.ok(serializedRecord);
+ });
+});