github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/image-file.js (about) 1 import Component from '@ember/component'; 2 import { computed } from '@ember/object'; 3 import { 4 classNames, 5 tagName, 6 attributeBindings, 7 } from '@ember-decorators/component'; 8 import classic from 'ember-classic-decorator'; 9 10 @classic 11 @tagName('figure') 12 @classNames('image-file') 13 @attributeBindings('data-test-image-file') 14 export default class ImageFile extends Component { 15 'data-test-image-file' = true; 16 17 src = null; 18 alt = null; 19 size = null; 20 21 // Set by updateImageMeta 22 width = 0; 23 height = 0; 24 25 @computed('src') 26 get fileName() { 27 if (!this.src) return undefined; 28 return this.src.includes('/') ? this.src.match(/^.*\/(.*)$/)[1] : this.src; 29 } 30 31 updateImageMeta(event) { 32 const img = event.target; 33 this.setProperties({ 34 width: img.naturalWidth, 35 height: img.naturalHeight, 36 }); 37 } 38 }