Skip to content

Commit

Permalink
add filesize and modified date to file-to-array-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
meirish committed Sep 27, 2019
1 parent 363bedf commit ecdc3d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions ui/app/components/file-to-array-buffer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import Component from '@ember/component';
import filesize from 'filesize';

export default Component.extend({
classNames: ['box', 'is-fullwidth', 'is-marginless', 'is-shadowless'],
onChange: () => {},
file: null,
fileName: null,
fileSize: null,
fileLastModified: null,

/*
* @public
Expand All @@ -24,7 +27,7 @@ export default Component.extend({

readFile(file) {
const reader = new FileReader();
reader.onload = () => this.send('onChange', reader.result, file.name);
reader.onload = () => this.send('onChange', reader.result, file);
reader.readAsArrayBuffer(file);
},

Expand All @@ -41,10 +44,14 @@ export default Component.extend({
clearFile() {
this.send('onChange');
},
onChange(file, filename) {
this.set('file', file);
this.set('fileName', filename);
this.onChange(file, filename);
onChange(fileAsBytes, fileMeta) {
let { name, size, lastModifiedDate } = fileMeta || {};
let fileSize = size ? filesize(size) : null;
this.set('file', fileAsBytes);
this.set('fileName', name);
this.set('fileSize', fileSize);
this.set('fileLastModified', lastModifiedDate);
this.onChange(fileAsBytes, name);
},
},
});
7 changes: 6 additions & 1 deletion ui/app/templates/components/file-to-array-buffer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
</label>
</div>
</div>
{{#if @fileName}}
{{#if this.fileName}}
<p class="help has-text-grey">
This file is {{this.fileSize}} and was created on {{date-format this.fileLastModified 'MMM DD, YYYY hh:mm:ss A'}}.
</p>
{{/if}}
{{#if @fileHelpText}}
<p class="help has-text-grey">
{{@fileHelpText}}
</p>
Expand Down

0 comments on commit ecdc3d5

Please sign in to comment.