Skip to content

Modular logistics and supply chain operating system (LSOS)

several improvements and fixes to chat models, serializers, and fixes to download function on file based models, and updated default api url in config

Ronald A. Richardsoned1609ccf418
diff --git a/api/config/app.php b/api/config/app.php
index 7d739759..c8cb2158 100644
--- a/api/config/app.php
+++ b/api/config/app.php
@@ -52,7 +52,7 @@ return [
|
*/
- 'url' => env('APP_URL', 'http://localhost'),
+ 'url' => env('APP_URL', 'http://localhost:8000'),
'asset_url' => env('ASSET_URL', null),
diff --git a/console/app/controllers/console.js b/console/app/controllers/console.js
index 2e573aa6..e0e85590 100644
--- a/console/app/controllers/console.js
+++ b/console/app/controllers/console.js
@@ -174,6 +174,7 @@ export default class ConsoleController extends Controller {
@action setSidebarContext(sidebarContext) {
this.sidebarContext = sidebarContext;
this.universe.sidebarContext = sidebarContext;
+ this.universe.trigger('sidebarContext.available', sidebarContext);
if (this.hiddenSidebarRoutes.includes(this.router.currentRouteName)) {
this.sidebarContext.hideNow();
diff --git a/console/app/models/chat-attachment.js b/console/app/models/chat-attachment.js
index c058cf3d..7c3ecfdc 100644
--- a/console/app/models/chat-attachment.js
+++ b/console/app/models/chat-attachment.js
@@ -2,6 +2,8 @@ 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';
+import isVideoFile from '@fleetbase/ember-core/utils/is-video-file';
+import isImageFile from '@fleetbase/ember-core/utils/is-image-file';
export default class ChatAttachment extends Model {
/** @ids */
@@ -20,6 +22,8 @@ export default class ChatAttachment extends Model {
@attr('string') sender_uuid;
@attr('string') file_uuid;
@attr('string') url;
+ @attr('string') filename;
+ @attr('string') content_type;
/** @dates */
@attr('date') created_at;
@@ -58,6 +62,14 @@ export default class ChatAttachment extends Model {
return formatDate(this.created_at, 'PP HH:mm');
}
+ @computed('content_type') get isVideo() {
+ return isVideoFile(this.content_type);
+ }
+
+ @computed('content_type') get isImage() {
+ return isImageFile(this.content_type);
+ }
+
/** @methods */
downloadFromApi() {
window.open(ENV.api.host + '/' + ENV.api.namespace + '/files/download?file=' + this.file_uuid, '_self');
@@ -65,8 +77,8 @@ export default class ChatAttachment extends Model {
download() {
const owner = getOwner(this);
- const fetch = owner.lookup(`service:store`);
+ const fetch = owner.lookup('service:fetch');
- return fetch.download('files/download', { file: this.file_uuid });
+ return fetch.download('files/download', { file: this.file_uuid }, { fileName: this.filename, mimeType: this.content_type });
}
}
diff --git a/console/app/models/chat-log.js b/console/app/models/chat-log.js
index 6436eb50..a842a21e 100644
--- a/console/app/models/chat-log.js
+++ b/console/app/models/chat-log.js
@@ -1,6 +1,5 @@
-import Model, { belongsTo } from '@ember-data/model';
+import Model, { attr, belongsTo } from '@ember-data/model';
import { computed } from '@ember/object';
-import { getOwner } from '@ember/application';
import { format, formatDistanceToNow, isValid as isValidDate } from 'date-fns';
export default class ChatLogModel extends Model {
@@ -26,7 +25,7 @@ export default class ChatLogModel extends Model {
return null;
}
- return formatDistanceToNow(this.updated_at);
+ return formatDistanceToNow(this.updated_at, { addSuffix: true });
}
@computed('updated_at') get updatedAt() {
@@ -42,7 +41,7 @@ export default class ChatLogModel extends Model {
return null;
}
- return formatDistanceToNow(this.created_at);
+ return formatDistanceToNow(this.created_at, { addSuffix: true });
}
@computed('created_at') get createdAt() {
diff --git a/console/app/models/chat-message.js b/console/app/models/chat-message.js
index 50928f13..320fb6d3 100644
--- a/console/app/models/chat-message.js
+++ b/console/app/models/chat-message.js
@@ -9,6 +9,7 @@ export default class ChatMessage extends Model {
/** @attributes */
@attr('string') content;
+ @attr('array') attachment_files;
/** @relationships */
@belongsTo('chat-participant', { async: false }) sender;
diff --git a/console/app/models/chat-participant.js b/console/app/models/chat-participant.js
index b73b4599..ce0e28bf 100644
--- a/console/app/models/chat-participant.js
+++ b/console/app/models/chat-participant.js
@@ -13,12 +13,14 @@ export default class ChatParticipant extends Model {
@attr('string') phone;
@attr('string') email;
@attr('string') avatar_url;
+ @attr('boolean') is_online;
/** @relationships */
@belongsTo('user', { async: true }) user;
@belongsTo('chat-channel', { async: true }) chatChannel;
/** @dates */
+ @attr('date') last_seen_at;
@attr('date') created_at;
@attr('date') updated_at;
@@ -54,4 +56,20 @@ export default class ChatParticipant extends Model {
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);
+ }
+
+ @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/file.js b/console/app/models/file.js
index 5b6e99be..4742d8aa 100644
--- a/console/app/models/file.js
+++ b/console/app/models/file.js
@@ -69,8 +69,8 @@ export default class FileModel extends Model {
download() {
const owner = getOwner(this);
- const fetch = owner.lookup(`service:store`);
+ const fetch = owner.lookup('service:fetch');
- return fetch.download('files/download', { file: this.id });
+ return fetch.download('files/download', { file: this.id }, { fileName: this.original_filename, mimeType: this.content_type });
}
}
diff --git a/console/app/serializers/chat-channel.js b/console/app/serializers/chat-channel.js
index 9ee32fab..c00a2701 100644
--- a/console/app/serializers/chat-channel.js
+++ b/console/app/serializers/chat-channel.js
@@ -1,5 +1,8 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
+import { getOwner } from '@ember/application';
+import { underscore } from '@ember/string';
+import { isArray } from '@ember/array';
export default class ChatChannelSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
/**
@@ -14,4 +17,36 @@ export default class ChatChannelSerializer extends ApplicationSerializer.extend(
last_message: { embedded: 'always' },
};
}
+
+ normalize(typeClass, hash) {
+ if (isArray(hash.feed)) {
+ hash.feed = this.serializeFeed(hash.feed);
+ }
+
+ return super.normalize(...arguments);
+ }
+
+ serializeFeed(feed = []) {
+ return feed.map((item) => this.serializeItem(item)).sortBy('created_at');
+ }
+
+ serializeItem(item) {
+ switch (item.type) {
+ case 'message':
+ return { ...item, record: this.serializeItemType('chat-message', item.data) };
+ case 'log':
+ return { ...item, record: this.serializeItemType('chat-log', item.data) };
+ case 'attachment':
+ return { ...item, record: this.serializeItemType('chat-attachment', item.data) };
+ default:
+ return null;
+ }
+ }
+
+ serializeItemType(modelType, data) {
+ const owner = getOwner(this);
+ const store = owner.lookup('service:store');
+ const normalized = store.normalize(modelType, data);
+ return store.push(normalized);
+ }
}