Skip to content

Modular logistics and supply chain operating system (LSOS)

improvements to chat models and serializers

Ronald A. Richardson82ae99eb84a6
diff --git a/console/app/models/chat-attachment.js b/console/app/models/chat-attachment.js
index fc4e99a3..c058cf3d 100644
--- a/console/app/models/chat-attachment.js
+++ b/console/app/models/chat-attachment.js
@@ -1,10 +1,14 @@
import Model, { attr, belongsTo } from '@ember-data/model';
+import { getOwner } from '@ember/application';
+import { computed } from '@ember/object';
+import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class ChatAttachment extends Model {
/** @ids */
@attr('string') chat_channel_uuid;
@attr('string') sender_uuid;
@attr('string') file_uuid;
+ @attr('string') chat_message_uuid;
/** @relationships */
@belongsTo('user', { async: true }) sender;
@@ -15,8 +19,54 @@ export default class ChatAttachment extends Model {
@attr('string') chat_channel_uuid;
@attr('string') sender_uuid;
@attr('string') file_uuid;
+ @attr('string') url;
/** @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');
+ }
+
+ /** @methods */
+ downloadFromApi() {
+ window.open(ENV.api.host + '/' + ENV.api.namespace + '/files/download?file=' + this.file_uuid, '_self');
+ }
+
+ download() {
+ const owner = getOwner(this);
+ const fetch = owner.lookup(`service:store`);
+
+ return fetch.download('files/download', { file: this.file_uuid });
+ }
}
diff --git a/console/app/models/chat-message.js b/console/app/models/chat-message.js
index 9cfb9475..50928f13 100644
--- a/console/app/models/chat-message.js
+++ b/console/app/models/chat-message.js
@@ -1,4 +1,4 @@
-import Model, { attr, belongsTo } from '@ember-data/model';
+import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
@@ -12,6 +12,7 @@ export default class ChatMessage extends Model {
/** @relationships */
@belongsTo('chat-participant', { async: false }) sender;
+ @hasMany('chat-attachment', { async: false }) attachments;
/** @dates */
@attr('date') created_at;
diff --git a/console/app/models/chat-presence.js b/console/app/models/chat-presence.js
index ff3082d7..1646d51b 100644
--- a/console/app/models/chat-presence.js
+++ b/console/app/models/chat-presence.js
@@ -1,16 +1,70 @@
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 ChatPresence extends Model {
/** @ids */
+ @attr('string') participant_uuid;
+ @attr('string') chat_channel_uuid;
+
/** @attributes */
@attr('boolean') is_online;
/** @relationships */
- @belongsTo('user', { async: true }) user;
+ @belongsTo('chat-participant', { async: true }) participant;
@belongsTo('chat-channel', { async: true }) chatChannel;
/** @dates */
@attr('date') created_at;
@attr('date') updated_at;
@attr('date') last_seen_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');
+ }
+
+ @computed('last_seen_at') get lastSeenAgo() {
+ if (!isValidDate(this.last_seen_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.last_seen_at, { addSuffix: true });
+ }
+
+ @computed('last_seen_at') get lastSeenAt() {
+ if (!isValidDate(this.last_seen_at)) {
+ return null;
+ }
+
+ return formatDate(this.last_seen_at, 'PP HH:mm');
+ }
}
diff --git a/console/app/models/chat-receipt.js b/console/app/models/chat-receipt.js
index 4cae7c74..ea95ae61 100644
--- a/console/app/models/chat-receipt.js
+++ b/console/app/models/chat-receipt.js
@@ -1,16 +1,67 @@
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 ChatReceipt extends Model {
/** @ids */
- /** @attributes */
+ @attr('string') participant_uuid;
+ @attr('string') chat_channel_uuid;
/** @relationships */
- @belongsTo('user', { async: true }) user;
+ @belongsTo('chat-participant', { async: true }) participant;
@belongsTo('chat-message', { async: true }) chatMessage;
/** @dates */
@attr('date') created_at;
@attr('date') updated_at;
- @attr('date') deleted_at;
@attr('date') read_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');
+ }
+
+ @computed('read_at') get readAgo() {
+ if (!isValidDate(this.read_at)) {
+ return null;
+ }
+
+ return formatDistanceToNow(this.read_at, { addSuffix: true });
+ }
+
+ @computed('read_at') get readAt() {
+ if (!isValidDate(this.read_at)) {
+ return null;
+ }
+
+ return formatDate(this.read_at, 'PP HH:mm');
+ }
}
diff --git a/console/app/serializers/chat-message.js b/console/app/serializers/chat-message.js
index b52075ef..7f305638 100644
--- a/console/app/serializers/chat-message.js
+++ b/console/app/serializers/chat-message.js
@@ -10,6 +10,7 @@ export default class ChatMessageSerializer extends ApplicationSerializer.extend(
get attrs() {
return {
sender: { embedded: 'always' },
+ attachments: { embedded: 'always' },
};
}
}