@alihbuzaid/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
48 lines (41 loc) • 1.4 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import getWithDefault from '@fleetbase/ember-core/utils/get-with-default';
export default class ChatWindowAttachmentComponent extends Component {
chatAttachment;
icon;
constructor(owner, { record }) {
super(...arguments);
this.chatAttachment = record;
this.icon = this.getIcon(record);
}
download() {
return this.chatAttachment.download();
}
getExtension(chatAttachment) {
const filename = chatAttachment.filename;
const extensionMatch = filename.match(/\.(.+)$/);
return extensionMatch ? extensionMatch[1] : null;
}
getIcon(chatAttachment) {
this.extension = this.getExtension(chatAttachment);
return getWithDefault(
{
xlsx: 'file-excel',
xls: 'file-excel',
xlsb: 'file-excel',
xlsm: 'file-excel',
csv: 'file-spreadsheet',
tsv: 'file-spreadsheet',
docx: 'file-word',
docm: 'file-word',
pdf: 'file-pdf',
ppt: 'file-powerpoint',
pptx: 'file-powerpoint',
},
this.extension,
'file-alt'
);
}
}